00001
00034 #ifndef YASM_FILE_H
00035 #define YASM_FILE_H
00036
00037 #ifndef YASM_LIB_DECL
00038 #define YASM_LIB_DECL
00039 #endif
00040
00042 typedef struct yasm_scanner {
00043 unsigned char *bot;
00044 unsigned char *tok;
00045 unsigned char *ptr;
00046 unsigned char *cur;
00047 unsigned char *lim;
00048 unsigned char *top;
00049 unsigned char *eof;
00050 } yasm_scanner;
00051
00055 YASM_LIB_DECL
00056 void yasm_scanner_initialize(yasm_scanner *scanner);
00057
00061 YASM_LIB_DECL
00062 void yasm_scanner_delete(yasm_scanner *scanner);
00063
00073 YASM_LIB_DECL
00074 int yasm_fill_helper
00075 (yasm_scanner *scanner, unsigned char **cursor,
00076 size_t (*input_func) (void *d, unsigned char *buf, size_t max),
00077 void *input_func_data);
00078
00088 YASM_LIB_DECL
00089 void yasm_unescape_cstring(unsigned char *str, size_t *len);
00090
00098 YASM_LIB_DECL
00099 size_t yasm__splitpath_unix(const char *path, const char **tail);
00100
00108 YASM_LIB_DECL
00109 size_t yasm__splitpath_win(const char *path, const char **tail);
00110
00118 #ifndef yasm__splitpath
00119 # if defined (_WIN32) || defined (WIN32) || defined (__MSDOS__) || \
00120 defined (__DJGPP__) || defined (__OS2__)
00121 # define yasm__splitpath(path, tail) yasm__splitpath_win(path, tail)
00122 # else
00123 # define yasm__splitpath(path, tail) yasm__splitpath_unix(path, tail)
00124 # endif
00125 #endif
00126
00131 YASM_LIB_DECL
00132 char *yasm__getcwd(void);
00133
00139 YASM_LIB_DECL
00140 char *yasm__abspath(const char *path);
00141
00150 YASM_LIB_DECL
00151 char *yasm__combpath_unix(const char *from, const char *to);
00152
00161 YASM_LIB_DECL
00162 char *yasm__combpath_win(const char *from, const char *to);
00163
00173 #ifndef yasm__combpath
00174 # if defined (_WIN32) || defined (WIN32) || defined (__MSDOS__) || \
00175 defined (__DJGPP__) || defined (__OS2__)
00176 # define yasm__combpath(from, to) yasm__combpath_win(from, to)
00177 # else
00178 # define yasm__combpath(from, to) yasm__combpath_unix(from, to)
00179 # endif
00180 #endif
00181
00188 YASM_LIB_DECL
00189 size_t yasm__createpath_common(const char *path, int win);
00190
00197 #ifndef yasm__createpath
00198 # if defined (_WIN32) || defined (WIN32) || defined (__MSDOS__) || \
00199 defined (__DJGPP__) || defined (__OS2__)
00200 # define yasm__createpath(path) yasm__createpath_common(path, 1)
00201 # else
00202 # define yasm__createpath(path) yasm__createpath_common(path, 0)
00203 # endif
00204 #endif
00205
00224 YASM_LIB_DECL
00225 FILE *yasm_fopen_include
00226 (const char *iname, const char *from, const char *mode,
00227 char **oname);
00228
00231 YASM_LIB_DECL
00232 void yasm_delete_include_paths(void);
00233
00236 YASM_LIB_DECL
00237 const char * yasm_get_include_dir(void **iter);
00238
00245 YASM_LIB_DECL
00246 void yasm_add_include_path(const char *path);
00247
00253 #define YASM_WRITE_8(ptr, val) \
00254 *((ptr)++) = (unsigned char)((val) & 0xFF)
00255
00262 #define YASM_WRITE_16_L(ptr, val) \
00263 do { \
00264 *((ptr)++) = (unsigned char)((val) & 0xFF); \
00265 *((ptr)++) = (unsigned char)(((val) >> 8) & 0xFF); \
00266 } while (0)
00267
00274 #define YASM_WRITE_32_L(ptr, val) \
00275 do { \
00276 *((ptr)++) = (unsigned char)((val) & 0xFF); \
00277 *((ptr)++) = (unsigned char)(((val) >> 8) & 0xFF); \
00278 *((ptr)++) = (unsigned char)(((val) >> 16) & 0xFF); \
00279 *((ptr)++) = (unsigned char)(((val) >> 24) & 0xFF); \
00280 } while (0)
00281
00288 #define YASM_WRITE_16_B(ptr, val) \
00289 do { \
00290 *((ptr)++) = (unsigned char)(((val) >> 8) & 0xFF); \
00291 *((ptr)++) = (unsigned char)((val) & 0xFF); \
00292 } while (0)
00293
00300 #define YASM_WRITE_32_B(ptr, val) \
00301 do { \
00302 *((ptr)++) = (unsigned char)(((val) >> 24) & 0xFF); \
00303 *((ptr)++) = (unsigned char)(((val) >> 16) & 0xFF); \
00304 *((ptr)++) = (unsigned char)(((val) >> 8) & 0xFF); \
00305 *((ptr)++) = (unsigned char)((val) & 0xFF); \
00306 } while (0)
00307
00308
00314 #define YASM_SAVE_8(ptr, val) \
00315 *(ptr) = (unsigned char)((val) & 0xFF)
00316
00323 #define YASM_SAVE_16_L(ptr, val) \
00324 do { \
00325 *(ptr) = (unsigned char)((val) & 0xFF); \
00326 *((ptr)+1) = (unsigned char)(((val) >> 8) & 0xFF); \
00327 } while (0)
00328
00335 #define YASM_SAVE_32_L(ptr, val) \
00336 do { \
00337 *(ptr) = (unsigned char)((val) & 0xFF); \
00338 *((ptr)+1) = (unsigned char)(((val) >> 8) & 0xFF); \
00339 *((ptr)+2) = (unsigned char)(((val) >> 16) & 0xFF); \
00340 *((ptr)+3) = (unsigned char)(((val) >> 24) & 0xFF); \
00341 } while (0)
00342
00349 #define YASM_SAVE_16_B(ptr, val) \
00350 do { \
00351 *(ptr) = (unsigned char)(((val) >> 8) & 0xFF); \
00352 *((ptr)+1) = (unsigned char)((val) & 0xFF); \
00353 } while (0)
00354
00361 #define YASM_SAVE_32_B(ptr, val) \
00362 do { \
00363 *(ptr) = (unsigned char)(((val) >> 24) & 0xFF); \
00364 *((ptr)+1) = (unsigned char)(((val) >> 16) & 0xFF); \
00365 *((ptr)+2) = (unsigned char)(((val) >> 8) & 0xFF); \
00366 *((ptr)+3) = (unsigned char)((val) & 0xFF); \
00367 } while (0)
00368
00376 YASM_LIB_DECL
00377 size_t yasm_fwrite_16_l(unsigned short val, FILE *f);
00378
00386 YASM_LIB_DECL
00387 size_t yasm_fwrite_32_l(unsigned long val, FILE *f);
00388
00396 YASM_LIB_DECL
00397 size_t yasm_fwrite_16_b(unsigned short val, FILE *f);
00398
00406 YASM_LIB_DECL
00407 size_t yasm_fwrite_32_b(unsigned long val, FILE *f);
00408
00414 #define YASM_READ_8(val, ptr) \
00415 (val) = *((ptr)++) & 0xFF
00416
00423 #define YASM_READ_16_L(val, ptr) \
00424 do { \
00425 (val) = *((ptr)++) & 0xFF; \
00426 (val) |= (*((ptr)++) & 0xFF) << 8; \
00427 } while (0)
00428
00435 #define YASM_READ_32_L(val, ptr) \
00436 do { \
00437 (val) = *((ptr)++) & 0xFF; \
00438 (val) |= (*((ptr)++) & 0xFF) << 8; \
00439 (val) |= (*((ptr)++) & 0xFF) << 16; \
00440 (val) |= (*((ptr)++) & 0xFF) << 24; \
00441 } while (0)
00442
00449 #define YASM_READ_16_B(val, ptr) \
00450 do { \
00451 (val) = (*((ptr)++) & 0xFF) << 8; \
00452 (val) |= *((ptr)++) & 0xFF; \
00453 } while (0)
00454
00461 #define YASM_READ_32_B(val, ptr) \
00462 do { \
00463 (val) = (*((ptr)++) & 0xFF) << 24; \
00464 (val) |= (*((ptr)++) & 0xFF) << 16; \
00465 (val) |= (*((ptr)++) & 0xFF) << 8; \
00466 (val) |= *((ptr)++) & 0xFF; \
00467 } while (0)
00468
00474 #define YASM_LOAD_8(val, ptr) \
00475 (val) = *(ptr) & 0xFF
00476
00483 #define YASM_LOAD_16_L(val, ptr) \
00484 do { \
00485 (val) = *(ptr) & 0xFF; \
00486 (val) |= (*((ptr)+1) & 0xFF) << 8; \
00487 } while (0)
00488
00495 #define YASM_LOAD_32_L(val, ptr) \
00496 do { \
00497 (val) = (unsigned long)(*(ptr) & 0xFF); \
00498 (val) |= (unsigned long)((*((ptr)+1) & 0xFF) << 8); \
00499 (val) |= (unsigned long)((*((ptr)+2) & 0xFF) << 16); \
00500 (val) |= (unsigned long)((*((ptr)+3) & 0xFF) << 24); \
00501 } while (0)
00502
00509 #define YASM_LOAD_16_B(val, ptr) \
00510 do { \
00511 (val) = (*(ptr) & 0xFF) << 8; \
00512 (val) |= *((ptr)+1) & 0xFF; \
00513 } while (0)
00514
00521 #define YASM_LOAD_32_B(val, ptr) \
00522 do { \
00523 (val) = (unsigned long)((*(ptr) & 0xFF) << 24); \
00524 (val) |= (unsigned long)((*((ptr)+1) & 0xFF) << 16); \
00525 (val) |= (unsigned long)((*((ptr)+2) & 0xFF) << 8); \
00526 (val) |= (unsigned long)(*((ptr)+3) & 0xFF); \
00527 } while (0)
00528
00529 #endif