00001 
00002 #ifndef  __JBXL_COMMON_HEADER_
00003 #define  __JBXL_COMMON_HEADER_
00004 
00005 
00015 #ifdef HAVE_CONFIG_H
00016     #include "config.h"
00017 #endif
00018 
00019 
00020 #define _INCLUDE_POSIX_SOURCE
00021 #define __EXTENSIONS__                // for Solaris
00022 
00023 
00024 #ifndef _CRT_SECURE_NO_WARNINGS
00025 #define _CRT_SECURE_NO_WARNINGS       // for Windows
00026 #endif
00027 
00028 
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031 #include <string.h>
00032 
00033 
00034 
00036 
00037 
00038 #ifdef __MINGW32__
00039     #define MINGW32
00040 #elif defined __CYGWIN__
00041     #define CYGWIN
00042 #endif
00043 
00044 
00046 
00047 
00048 #ifdef  WIN32   // for Windows
00049     #include <io.h>
00050     #include <direct.h>
00051 
00052     #ifndef _MFC_APP_
00053         #define _WINSOCKAPI_    // network.h で winsock2.h を読み込むため
00054         #include <windows.h>
00055     #endif
00056 
00057     #define  Intel
00058     #define  scanf       scanf_s 
00059     #define  unlink      _unlink
00060     #define  snprintf    _snprintf
00061     #define  vsnprintf   _vsnprintf
00062     #define  strcasecmp  _stricmp 
00063     #define  strncasecmp _strnicmp
00064 
00065     #define  mkdir(d, m) _mkdir(d)
00066     #define  mode_t      int
00067     #define  bzero(p, n)    ZeroMemory((p), (n))
00068     #define  bcopy(f, t, n) CopyMemory((t), (f), (n))
00069 
00070     
00071     #ifdef   _UNICODE
00072         #ifndef  _ttof
00073             #define  _ttof   _wtof
00074         #endif
00075     #else
00076         #ifndef  _ttof
00077             #define  _ttof   atof
00078         #endif
00079     #endif    // Unicode
00080 
00081     #define  tcscmp      _tcscmp       
00082     #define  tcsncmp     _tcsncmp      
00083     #define  tcsncpy     _tcsncpy      
00084     #define  tcslen      _tcslen       
00085     #define  tunlink     _tunlink      
00086     #define  tfopen      _tfopen       
00087     #define  sntprintf   _sntprintf_s  
00088     #define  ttoi        _ttoi         
00089     #define  ttof        _ttof         
00090     #define  tprintf     _tprintf      
00091     #define  ftprintf    _ftprintf     
00092 
00093     #ifdef _WINDLL               
00094         #define DllExport __declspec(dllexport)
00095         #define DllImport __declspec(dllimport)
00096     #endif
00097 
00098     #ifdef WIN64
00099         #define WIN_DD_NULL   (void*)0xdddddddddddddddd
00100     #else
00101         #define WIN_DD_NULL   (void*)0xdddddddd
00102     #endif
00103 
00104 #endif    // WIN32
00105 
00106 
00107 #ifndef DllExport   
00108     #define DllExport
00109     #define DllImport
00110 #endif
00111 
00112 
00114 
00115 
00116 #ifndef LOG_PERROR
00117     #define LOG_PERROR 0
00118 #endif
00119 
00120 
00122 
00123 
00124 #ifndef  WIN32  
00125     #define  Sleep(t)  usleep((t)*1000)     
00126 #endif
00127 
00128 
00130 
00131 #define  MAXBUFSZ  4194304      
00132 #define  BUFSZ2M   2087152      
00133 #define  HHHBUFSZ  2087152      
00134 #define  BUFSZ1M   1048576      
00135 #define  HHBUFSZ   1048576      
00136 #define  HBUFSZ     524288      
00137 #define  RECVBUFSZ  262144      
00138 #define  LLLBUFSZ   131072      
00139 #define  LLBUFSZ     65536      
00140 #define  LBUFSZ      32768      
00141 #define  BUFSZ       16384      
00142 #define  MBUFSZ       8192      
00143 #define  SBUFSZ       4096      
00144 
00145 #define  LFRAME       2048
00146 #define  LBUF         1024
00147 #define  LMESG         512
00148 #define  LPATH         256
00149 #define  LDATA         256
00150 #define  LNAME         128
00151 #define  L_128         128
00152 #define  LMDATA        128
00153 #define  LPASS         128        
00154 #define  LMNAME         64
00155 #define  LSDATA         64
00156 #define  L_64           64
00157 #define  LGUID          40        
00158 #define  LUUID          36        
00159 #define  L_32           32
00160 #define  LADDR          32
00161 #define  LADDR6        128
00162 #define  LSNAME         32
00163 #define  L_ID           16
00164 #define  L_16           16
00165 #define  L_OCT           8
00166 
00167 #define  LEN_INT        22        
00168 #define  LEN_IPADDR     17        
00169 #define  LEN_IPADDR6    41        
00170 #define  LEN_PORT        7        
00171 #define  LEN_IPPORT     23        
00172 
00173 #define  STRLEN_GUID    36        
00174 
00175 #define  WORK_FILENAME_LEN  16
00176 
00177 
00178 #define  PI          3.1415926535897932385
00179 #define  PI15        4.7123889803846898577
00180 #define  PI2         6.2831853071795864769
00181 #define  PI_DIV2     1.5707963267948966192
00182 #define  PI_DIV2_3   4.7123889803846898577
00183 #define  PI_DIV3     1.0471975511965977462
00184 #define  PI_DIV3_2   2.0943951023931954923
00185 #define  PI_DIV4     0.78539816339744830962
00186 #define  PI_DIV6     0.52359877559829887308
00187 #define  LN_10       2.3025850929940456840
00188 #define  EXP_1       2.71828182845904523536
00189 
00190 #define  DEGREE2RAD  0.0174532925199432957692
00191 #define  RAD2DEGREE  57.2957795130823208768
00192 
00193 #define  SQROOT_05   0.707106781186547524401
00194 #define  SQROOT_2    1.4142135623730950488
00195 #define  SQROOT_3    1.7320508075688772935
00196 #define  SQROOT_5    2.2360679774997896964
00197 #define  SQROOT_7    2.6457513110645905905
00198 
00199 
00200 #define  SINTMAX     2147483647
00201 #define  SINTMIN    -2147483647        // 2147483648 of -2147483648 is over flow from INT MAX 
00202 #define  UINTMAX     4294967295
00203 #define  SWORDMAX         32767
00204 #define  SWORDMIN        -32768
00205 #define  UWORDMAX         65535
00206 
00207 #ifndef RAND_MAX
00208 #ifdef  WIN32   // for Windows    
00209     #define  RAND_MAX  32767
00210 #else
00211     #define  RAND_MAX  2147483647
00212 #endif
00213 #endif
00214 
00215 
00217 
00218 #ifndef  FALSE
00219     #define  FALSE  0
00220 #endif
00221 #ifndef  TRUE
00222     #define  TRUE   1
00223 #endif
00224 
00225 
00226 #define  ON       1
00227 #define  OFF      0
00228 #define  OK       1
00229 #define  NG       0
00230 #define  YES      1
00231 #define  NO       0
00232 
00233 
00234 #ifndef  Max
00235     #define  Max(x, y)  (((x)<(y)) ? (y):(x))
00236 #endif
00237 #ifndef  Min
00238     #define  Min(x, y)  (((x)>(y)) ? (y):(x))
00239 #endif
00240 #ifndef  Sign
00241     #define  Sign(x)    (((x)>=0)  ? (1):(-1))
00242 #endif
00243 
00244 #define  Loop               while(1)
00245 #define  Xabs(x)            (((x)>=0)  ? (x):(-(x)))
00246 #define  getBit(x, n)       ((sByte)((*(x+(n)/8)>>(7+(n)/8*8-(n)))&0x01))
00247 #define  setBit(x, n, i)    ((i)?(*(x+(n)/8)|=(0x80>>((n)-(n)/8*8))):(*((x)+(n)/8)&=~(0x80>>((n)-(n)/8*8))))
00248 #define  checkBit(dat, bit) (((dat)&(bit))==(bit))
00249 #define  maskBit(dat, bit)  ((dat)&(0xff>>(8-(bit))))
00250 
00251 #ifndef  UNUSED
00252     #define  UNUSED(x)      (void)((x))
00253 #endif
00254 
00255 
00256 #define  Frand()    (rand()/((double)RAND_MAX+1.0))                      // 0.0〜x未満 の実数を生成
00257 #define  Drand(x)   ((int)(rand()/((double)RAND_MAX+1.0)*((x)+1)))       // 0〜x までの整数を生成
00258 #define  LDrand(x)  ((long int)(rand()/((double)RAND_MAX+1.0)*((x)+1)))  // 0〜x までの long int を生成
00259 
00260 
00261 #ifndef  WIN32 
00262 #ifndef  Error
00263     #define  Error(s) {perror(s); return -1;}
00264 #endif
00265 #endif
00266 
00267 
00268 
00269 
00270 #define  JBXL_ON         1
00271 #define  JBXL_OFF        0
00272 #define  JBXL_OK         1
00273 #define  JBXL_NG         0
00274 #define  JBXL_YES        1
00275 #define  JBXL_NO         0
00276 #define  JBXL_TRUE       1
00277 #define  JBXL_FALSE      0
00278 
00279 #define  JBXL_Max(x, y)  (((x)<(y)) ? (y):(x))
00280 #define  JBXL_Min(x, y)  (((x)>(y)) ? (y):(x))
00281 #define  JBXL_Sign(x)    (((x)>=0)  ? (1):(-1))
00282 
00283 #define  JBXL_EPS        1.0e-6
00284 
00285 
00286 
00288 
00289 
00290 typedef  unsigned char  uByte;
00291 typedef  char           sByte;
00292 typedef  unsigned short uWord;
00293 typedef  short          sWord;
00294 typedef  unsigned int   uDWord;
00295 typedef  int            sDWord;
00296 
00297 
00298 
00303 typedef struct _parameter32 {
00304     sByte pm[32];
00305 } Parameter32;
00306 
00307 
00308 typedef struct _parameter64 {
00309     sByte pm[64];
00310 } Parameter64;
00311 
00312 
00313 
00314 #endif  // __JBXL_COMMON_HEADER_
00315