libyasm

libyasm/file.h

Go to the documentation of this file.
00001 
00030 #ifndef YASM_FILE_H
00031 #define YASM_FILE_H
00032 
00033 #ifndef YASM_LIB_DECL
00034 #define YASM_LIB_DECL
00035 #endif
00036 
00038 typedef struct yasm_scanner {
00039     unsigned char *bot;     
00040     unsigned char *tok;     
00041     unsigned char *ptr;     
00042     unsigned char *cur;     
00043     unsigned char *lim;     
00044     unsigned char *top;     
00045     unsigned char *eof;     
00046 } yasm_scanner;
00047 
00051 YASM_LIB_DECL
00052 void yasm_scanner_initialize(yasm_scanner *scanner);
00053 
00057 YASM_LIB_DECL
00058 void yasm_scanner_delete(yasm_scanner *scanner);
00059 
00069 YASM_LIB_DECL
00070 int yasm_fill_helper
00071     (yasm_scanner *scanner, unsigned char **cursor,
00072      size_t (*input_func) (void *d, unsigned char *buf, size_t max),
00073      void *input_func_data);
00074 
00084 YASM_LIB_DECL
00085 void yasm_unescape_cstring(unsigned char *str, size_t *len);
00086 
00094 YASM_LIB_DECL
00095 size_t yasm__splitpath_unix(const char *path, /*@out@*/ const char **tail);
00096 
00104 YASM_LIB_DECL
00105 size_t yasm__splitpath_win(const char *path, /*@out@*/ const char **tail);
00106 
00114 #ifndef yasm__splitpath
00115 # if defined (_WIN32) || defined (WIN32) || defined (__MSDOS__) || \
00116  defined (__DJGPP__) || defined (__OS2__)
00117 #  define yasm__splitpath(path, tail)   yasm__splitpath_win(path, tail)
00118 # else
00119 #  define yasm__splitpath(path, tail)   yasm__splitpath_unix(path, tail)
00120 # endif
00121 #endif
00122 
00127 YASM_LIB_DECL
00128 /*@only@*/ char *yasm__getcwd(void);
00129 
00135 YASM_LIB_DECL
00136 /*@only@*/ char *yasm__abspath(const char *path);
00137 
00146 YASM_LIB_DECL
00147 char *yasm__combpath_unix(const char *from, const char *to);
00148 
00157 YASM_LIB_DECL
00158 char *yasm__combpath_win(const char *from, const char *to);
00159 
00169 #ifndef yasm__combpath
00170 # if defined (_WIN32) || defined (WIN32) || defined (__MSDOS__) || \
00171  defined (__DJGPP__) || defined (__OS2__)
00172 #  define yasm__combpath(from, to)      yasm__combpath_win(from, to)
00173 # else
00174 #  define yasm__combpath(from, to)      yasm__combpath_unix(from, to)
00175 # endif
00176 #endif
00177 
00184 YASM_LIB_DECL
00185 size_t yasm__createpath_common(const char *path, int win);
00186 
00193 #ifndef yasm__createpath
00194 # if defined (_WIN32) || defined (WIN32) || defined (__MSDOS__) || \
00195  defined (__DJGPP__) || defined (__OS2__)
00196 #  define yasm__createpath(path)    yasm__createpath_common(path, 1)
00197 # else
00198 #  define yasm__createpath(path)    yasm__createpath_common(path, 0)
00199 # endif
00200 #endif
00201 
00220 YASM_LIB_DECL
00221 /*@null@*/ FILE *yasm_fopen_include
00222     (const char *iname, const char *from, const char *mode,
00223      /*@null@*/ /*@out@*/ /*@only@*/ char **oname);
00224 
00227 YASM_LIB_DECL
00228 void yasm_delete_include_paths(void);
00229 
00232 YASM_LIB_DECL
00233 const char * yasm_get_include_dir(void **iter);
00234 
00241 YASM_LIB_DECL
00242 void yasm_add_include_path(const char *path);
00243 
00249 #define YASM_WRITE_8(ptr, val)                  \
00250         *((ptr)++) = (unsigned char)((val) & 0xFF)
00251 
00258 #define YASM_WRITE_16_L(ptr, val)               \
00259         do {                                    \
00260             *((ptr)++) = (unsigned char)((val) & 0xFF);         \
00261             *((ptr)++) = (unsigned char)(((val) >> 8) & 0xFF);  \
00262         } while (0)
00263 
00270 #define YASM_WRITE_32_L(ptr, val)               \
00271         do {                                    \
00272             *((ptr)++) = (unsigned char)((val) & 0xFF);         \
00273             *((ptr)++) = (unsigned char)(((val) >> 8) & 0xFF);  \
00274             *((ptr)++) = (unsigned char)(((val) >> 16) & 0xFF); \
00275             *((ptr)++) = (unsigned char)(((val) >> 24) & 0xFF); \
00276         } while (0)
00277 
00284 #define YASM_WRITE_16_B(ptr, val)               \
00285         do {                                    \
00286             *((ptr)++) = (unsigned char)(((val) >> 8) & 0xFF);  \
00287             *((ptr)++) = (unsigned char)((val) & 0xFF);         \
00288         } while (0)
00289 
00296 #define YASM_WRITE_32_B(ptr, val)               \
00297         do {                                    \
00298             *((ptr)++) = (unsigned char)(((val) >> 24) & 0xFF); \
00299             *((ptr)++) = (unsigned char)(((val) >> 16) & 0xFF); \
00300             *((ptr)++) = (unsigned char)(((val) >> 8) & 0xFF);  \
00301             *((ptr)++) = (unsigned char)((val) & 0xFF);         \
00302         } while (0)
00303 
00304 
00310 #define YASM_SAVE_8(ptr, val)                   \
00311         *(ptr) = (unsigned char)((val) & 0xFF)
00312 
00319 #define YASM_SAVE_16_L(ptr, val)                \
00320         do {                                    \
00321             *(ptr) = (unsigned char)((val) & 0xFF);             \
00322             *((ptr)+1) = (unsigned char)(((val) >> 8) & 0xFF);  \
00323         } while (0)
00324 
00331 #define YASM_SAVE_32_L(ptr, val)                \
00332         do {                                    \
00333             *(ptr) = (unsigned char)((val) & 0xFF);             \
00334             *((ptr)+1) = (unsigned char)(((val) >> 8) & 0xFF);  \
00335             *((ptr)+2) = (unsigned char)(((val) >> 16) & 0xFF); \
00336             *((ptr)+3) = (unsigned char)(((val) >> 24) & 0xFF); \
00337         } while (0)
00338 
00345 #define YASM_SAVE_16_B(ptr, val)                \
00346         do {                                    \
00347             *(ptr) = (unsigned char)(((val) >> 8) & 0xFF);      \
00348             *((ptr)+1) = (unsigned char)((val) & 0xFF);         \
00349         } while (0)
00350 
00357 #define YASM_SAVE_32_B(ptr, val)                \
00358         do {                                    \
00359             *(ptr) = (unsigned char)(((val) >> 24) & 0xFF);     \
00360             *((ptr)+1) = (unsigned char)(((val) >> 16) & 0xFF); \
00361             *((ptr)+2) = (unsigned char)(((val) >> 8) & 0xFF);  \
00362             *((ptr)+3) = (unsigned char)((val) & 0xFF);         \
00363         } while (0)
00364 
00372 YASM_LIB_DECL
00373 size_t yasm_fwrite_16_l(unsigned short val, FILE *f);
00374 
00382 YASM_LIB_DECL
00383 size_t yasm_fwrite_32_l(unsigned long val, FILE *f);
00384 
00392 YASM_LIB_DECL
00393 size_t yasm_fwrite_16_b(unsigned short val, FILE *f);
00394 
00402 YASM_LIB_DECL
00403 size_t yasm_fwrite_32_b(unsigned long val, FILE *f);
00404 
00410 #define YASM_READ_8(val, ptr)                   \
00411         (val) = *((ptr)++) & 0xFF
00412 
00419 #define YASM_READ_16_L(val, ptr)                \
00420         do {                                    \
00421             (val) = *((ptr)++) & 0xFF;          \
00422             (val) |= (*((ptr)++) & 0xFF) << 8;  \
00423         } while (0)
00424 
00431 #define YASM_READ_32_L(val, ptr)                \
00432         do {                                    \
00433             (val) = *((ptr)++) & 0xFF;          \
00434             (val) |= (*((ptr)++) & 0xFF) << 8;  \
00435             (val) |= (*((ptr)++) & 0xFF) << 16; \
00436             (val) |= (*((ptr)++) & 0xFF) << 24; \
00437         } while (0)
00438 
00445 #define YASM_READ_16_B(val, ptr)                \
00446         do {                                    \
00447             (val) = (*((ptr)++) & 0xFF) << 8;   \
00448             (val) |= *((ptr)++) & 0xFF;         \
00449         } while (0)
00450 
00457 #define YASM_READ_32_B(val, ptr)                \
00458         do {                                    \
00459             (val) = (*((ptr)++) & 0xFF) << 24;  \
00460             (val) |= (*((ptr)++) & 0xFF) << 16; \
00461             (val) |= (*((ptr)++) & 0xFF) << 8;  \
00462             (val) |= *((ptr)++) & 0xFF;         \
00463         } while (0)
00464 
00470 #define YASM_LOAD_8(val, ptr)                   \
00471         (val) = *(ptr) & 0xFF
00472 
00479 #define YASM_LOAD_16_L(val, ptr)                \
00480         do {                                    \
00481             (val) = *(ptr) & 0xFF;              \
00482             (val) |= (*((ptr)+1) & 0xFF) << 8;  \
00483         } while (0)
00484 
00491 #define YASM_LOAD_32_L(val, ptr)                \
00492         do {                                    \
00493             (val) = (unsigned long)(*(ptr) & 0xFF);                 \
00494             (val) |= (unsigned long)((*((ptr)+1) & 0xFF) << 8);     \
00495             (val) |= (unsigned long)((*((ptr)+2) & 0xFF) << 16);    \
00496             (val) |= (unsigned long)((*((ptr)+3) & 0xFF) << 24);    \
00497         } while (0)
00498 
00505 #define YASM_LOAD_16_B(val, ptr)                \
00506         do {                                    \
00507             (val) = (*(ptr) & 0xFF) << 8;       \
00508             (val) |= *((ptr)+1) & 0xFF;         \
00509         } while (0)
00510 
00517 #define YASM_LOAD_32_B(val, ptr)                \
00518         do {                                    \
00519             (val) = (unsigned long)((*(ptr) & 0xFF) << 24);         \
00520             (val) |= (unsigned long)((*((ptr)+1) & 0xFF) << 16);    \
00521             (val) |= (unsigned long)((*((ptr)+2) & 0xFF) << 8);     \
00522             (val) |= (unsigned long)(*((ptr)+3) & 0xFF);            \
00523         } while (0)
00524 
00525 #endif