libyasm
file.h
Go to the documentation of this file.
1 
30 #ifndef YASM_FILE_H
31 #define YASM_FILE_H
32 
33 #ifndef YASM_LIB_DECL
34 #define YASM_LIB_DECL
35 #endif
36 
38 typedef struct yasm_scanner {
39  unsigned char *bot;
40  unsigned char *tok;
41  unsigned char *ptr;
42  unsigned char *cur;
43  unsigned char *lim;
44  unsigned char *top;
45  unsigned char *eof;
46 } yasm_scanner;
47 
51 YASM_LIB_DECL
53 
57 YASM_LIB_DECL
58 void yasm_scanner_delete(yasm_scanner *scanner);
59 
69 YASM_LIB_DECL
71  (yasm_scanner *scanner, unsigned char **cursor,
72  size_t (*input_func) (void *d, unsigned char *buf, size_t max),
73  void *input_func_data);
74 
84 YASM_LIB_DECL
85 void yasm_unescape_cstring(unsigned char *str, size_t *len);
86 
94 YASM_LIB_DECL
95 size_t yasm__splitpath_unix(const char *path, /*@out@*/ const char **tail);
96 
104 YASM_LIB_DECL
105 size_t yasm__splitpath_win(const char *path, /*@out@*/ const char **tail);
106 
114 #ifndef yasm__splitpath
115 # if defined (_WIN32) || defined (WIN32) || defined (__MSDOS__) || \
116  defined (__DJGPP__) || defined (__OS2__)
117 # define yasm__splitpath(path, tail) yasm__splitpath_win(path, tail)
118 # else
119 # define yasm__splitpath(path, tail) yasm__splitpath_unix(path, tail)
120 # endif
121 #endif
122 
127 YASM_LIB_DECL
128 /*@only@*/ char *yasm__getcwd(void);
129 
135 YASM_LIB_DECL
136 /*@only@*/ char *yasm__abspath(const char *path);
137 
146 YASM_LIB_DECL
147 char *yasm__combpath_unix(const char *from, const char *to);
148 
157 YASM_LIB_DECL
158 char *yasm__combpath_win(const char *from, const char *to);
159 
169 #ifndef yasm__combpath
170 # if defined (_WIN32) || defined (WIN32) || defined (__MSDOS__) || \
171  defined (__DJGPP__) || defined (__OS2__)
172 # define yasm__combpath(from, to) yasm__combpath_win(from, to)
173 # else
174 # define yasm__combpath(from, to) yasm__combpath_unix(from, to)
175 # endif
176 #endif
177 
184 YASM_LIB_DECL
185 size_t yasm__createpath_common(const char *path, int win);
186 
193 #ifndef yasm__createpath
194 # if defined (_WIN32) || defined (WIN32) || defined (__MSDOS__) || \
195  defined (__DJGPP__) || defined (__OS2__)
196 # define yasm__createpath(path) yasm__createpath_common(path, 1)
197 # else
198 # define yasm__createpath(path) yasm__createpath_common(path, 0)
199 # endif
200 #endif
201 
220 YASM_LIB_DECL
221 /*@null@*/ FILE *yasm_fopen_include
222  (const char *iname, const char *from, const char *mode,
223  /*@null@*/ /*@out@*/ /*@only@*/ char **oname);
224 
227 YASM_LIB_DECL
228 void yasm_delete_include_paths(void);
229 
232 YASM_LIB_DECL
233 const char * yasm_get_include_dir(void **iter);
234 
241 YASM_LIB_DECL
242 void yasm_add_include_path(const char *path);
243 
249 #define YASM_WRITE_8(ptr, val) \
250  *((ptr)++) = (unsigned char)((val) & 0xFF)
251 
258 #define YASM_WRITE_16_L(ptr, val) \
259  do { \
260  *((ptr)++) = (unsigned char)((val) & 0xFF); \
261  *((ptr)++) = (unsigned char)(((val) >> 8) & 0xFF); \
262  } while (0)
263 
270 #define YASM_WRITE_32_L(ptr, val) \
271  do { \
272  *((ptr)++) = (unsigned char)((val) & 0xFF); \
273  *((ptr)++) = (unsigned char)(((val) >> 8) & 0xFF); \
274  *((ptr)++) = (unsigned char)(((val) >> 16) & 0xFF); \
275  *((ptr)++) = (unsigned char)(((val) >> 24) & 0xFF); \
276  } while (0)
277 
284 #define YASM_WRITE_16_B(ptr, val) \
285  do { \
286  *((ptr)++) = (unsigned char)(((val) >> 8) & 0xFF); \
287  *((ptr)++) = (unsigned char)((val) & 0xFF); \
288  } while (0)
289 
296 #define YASM_WRITE_32_B(ptr, val) \
297  do { \
298  *((ptr)++) = (unsigned char)(((val) >> 24) & 0xFF); \
299  *((ptr)++) = (unsigned char)(((val) >> 16) & 0xFF); \
300  *((ptr)++) = (unsigned char)(((val) >> 8) & 0xFF); \
301  *((ptr)++) = (unsigned char)((val) & 0xFF); \
302  } while (0)
303 
304 
310 #define YASM_SAVE_8(ptr, val) \
311  *(ptr) = (unsigned char)((val) & 0xFF)
312 
319 #define YASM_SAVE_16_L(ptr, val) \
320  do { \
321  *(ptr) = (unsigned char)((val) & 0xFF); \
322  *((ptr)+1) = (unsigned char)(((val) >> 8) & 0xFF); \
323  } while (0)
324 
331 #define YASM_SAVE_32_L(ptr, val) \
332  do { \
333  *(ptr) = (unsigned char)((val) & 0xFF); \
334  *((ptr)+1) = (unsigned char)(((val) >> 8) & 0xFF); \
335  *((ptr)+2) = (unsigned char)(((val) >> 16) & 0xFF); \
336  *((ptr)+3) = (unsigned char)(((val) >> 24) & 0xFF); \
337  } while (0)
338 
345 #define YASM_SAVE_16_B(ptr, val) \
346  do { \
347  *(ptr) = (unsigned char)(((val) >> 8) & 0xFF); \
348  *((ptr)+1) = (unsigned char)((val) & 0xFF); \
349  } while (0)
350 
357 #define YASM_SAVE_32_B(ptr, val) \
358  do { \
359  *(ptr) = (unsigned char)(((val) >> 24) & 0xFF); \
360  *((ptr)+1) = (unsigned char)(((val) >> 16) & 0xFF); \
361  *((ptr)+2) = (unsigned char)(((val) >> 8) & 0xFF); \
362  *((ptr)+3) = (unsigned char)((val) & 0xFF); \
363  } while (0)
364 
372 YASM_LIB_DECL
373 size_t yasm_fwrite_16_l(unsigned short val, FILE *f);
374 
382 YASM_LIB_DECL
383 size_t yasm_fwrite_32_l(unsigned long val, FILE *f);
384 
392 YASM_LIB_DECL
393 size_t yasm_fwrite_16_b(unsigned short val, FILE *f);
394 
402 YASM_LIB_DECL
403 size_t yasm_fwrite_32_b(unsigned long val, FILE *f);
404 
410 #define YASM_READ_8(val, ptr) \
411  (val) = *((ptr)++) & 0xFF
412 
419 #define YASM_READ_16_L(val, ptr) \
420  do { \
421  (val) = *((ptr)++) & 0xFF; \
422  (val) |= (*((ptr)++) & 0xFF) << 8; \
423  } while (0)
424 
431 #define YASM_READ_32_L(val, ptr) \
432  do { \
433  (val) = *((ptr)++) & 0xFF; \
434  (val) |= (*((ptr)++) & 0xFF) << 8; \
435  (val) |= (*((ptr)++) & 0xFF) << 16; \
436  (val) |= (*((ptr)++) & 0xFF) << 24; \
437  } while (0)
438 
445 #define YASM_READ_16_B(val, ptr) \
446  do { \
447  (val) = (*((ptr)++) & 0xFF) << 8; \
448  (val) |= *((ptr)++) & 0xFF; \
449  } while (0)
450 
457 #define YASM_READ_32_B(val, ptr) \
458  do { \
459  (val) = (*((ptr)++) & 0xFF) << 24; \
460  (val) |= (*((ptr)++) & 0xFF) << 16; \
461  (val) |= (*((ptr)++) & 0xFF) << 8; \
462  (val) |= *((ptr)++) & 0xFF; \
463  } while (0)
464 
470 #define YASM_LOAD_8(val, ptr) \
471  (val) = *(ptr) & 0xFF
472 
479 #define YASM_LOAD_16_L(val, ptr) \
480  do { \
481  (val) = *(ptr) & 0xFF; \
482  (val) |= (*((ptr)+1) & 0xFF) << 8; \
483  } while (0)
484 
491 #define YASM_LOAD_32_L(val, ptr) \
492  do { \
493  (val) = (unsigned long)(*(ptr) & 0xFF); \
494  (val) |= (unsigned long)((*((ptr)+1) & 0xFF) << 8); \
495  (val) |= (unsigned long)((*((ptr)+2) & 0xFF) << 16); \
496  (val) |= (unsigned long)((*((ptr)+3) & 0xFF) << 24); \
497  } while (0)
498 
505 #define YASM_LOAD_16_B(val, ptr) \
506  do { \
507  (val) = (*(ptr) & 0xFF) << 8; \
508  (val) |= *((ptr)+1) & 0xFF; \
509  } while (0)
510 
517 #define YASM_LOAD_32_B(val, ptr) \
518  do { \
519  (val) = (unsigned long)((*(ptr) & 0xFF) << 24); \
520  (val) |= (unsigned long)((*((ptr)+1) & 0xFF) << 16); \
521  (val) |= (unsigned long)((*((ptr)+2) & 0xFF) << 8); \
522  (val) |= (unsigned long)(*((ptr)+3) & 0xFF); \
523  } while (0)
524 
525 #endif