|
libyasm
|
YASM file helpers. More...
Go to the source code of this file.
Data Structures | |
| struct | yasm_scanner |
| Re2c scanner state. More... | |
Defines | |
| #define | YASM_LIB_DECL |
| #define | yasm__splitpath(path, tail) yasm__splitpath_unix(path, tail) |
| Split a pathname into head (directory) and tail (base filename) portions. | |
| #define | yasm__combpath(from, to) yasm__combpath_unix(from, to) |
| Build a pathname that is equivalent to accessing the "to" pathname when you're in the directory containing "from". | |
| #define | yasm__createpath(path) yasm__createpath_common(path, 0) |
| Recursively create tree of directories needed for pathname. | |
| #define | YASM_WRITE_8(ptr, val) *((ptr)++) = (unsigned char)((val) & 0xFF) |
| Write an 8-bit value to a buffer, incrementing buffer pointer. | |
| #define | YASM_WRITE_16_L(ptr, val) |
| Write a 16-bit value to a buffer in little endian, incrementing buffer pointer. | |
| #define | YASM_WRITE_32_L(ptr, val) |
| Write a 32-bit value to a buffer in little endian, incrementing buffer pointer. | |
| #define | YASM_WRITE_16_B(ptr, val) |
| Write a 16-bit value to a buffer in big endian, incrementing buffer pointer. | |
| #define | YASM_WRITE_32_B(ptr, val) |
| Write a 32-bit value to a buffer in big endian, incrementing buffer pointer. | |
| #define | YASM_SAVE_8(ptr, val) *(ptr) = (unsigned char)((val) & 0xFF) |
| Write an 8-bit value to a buffer. | |
| #define | YASM_SAVE_16_L(ptr, val) |
| Write a 16-bit value to a buffer in little endian. | |
| #define | YASM_SAVE_32_L(ptr, val) |
| Write a 32-bit value to a buffer in little endian. | |
| #define | YASM_SAVE_16_B(ptr, val) |
| Write a 16-bit value to a buffer in big endian. | |
| #define | YASM_SAVE_32_B(ptr, val) |
| Write a 32-bit value to a buffer in big endian. | |
| #define | YASM_READ_8(val, ptr) (val) = *((ptr)++) & 0xFF |
| Read an 8-bit value from a buffer, incrementing buffer pointer. | |
| #define | YASM_READ_16_L(val, ptr) |
| Read a 16-bit value from a buffer in little endian, incrementing buffer pointer. | |
| #define | YASM_READ_32_L(val, ptr) |
| Read a 32-bit value from a buffer in little endian, incrementing buffer pointer. | |
| #define | YASM_READ_16_B(val, ptr) |
| Read a 16-bit value from a buffer in big endian, incrementing buffer pointer. | |
| #define | YASM_READ_32_B(val, ptr) |
| Read a 32-bit value from a buffer in big endian, incrementing buffer pointer. | |
| #define | YASM_LOAD_8(val, ptr) (val) = *(ptr) & 0xFF |
| Read an 8-bit value from a buffer. | |
| #define | YASM_LOAD_16_L(val, ptr) |
| Read a 16-bit value from a buffer in little endian. | |
| #define | YASM_LOAD_32_L(val, ptr) |
| Read a 32-bit value from a buffer in little endian. | |
| #define | YASM_LOAD_16_B(val, ptr) |
| Read a 16-bit value from a buffer in big endian. | |
| #define | YASM_LOAD_32_B(val, ptr) |
| Read a 32-bit value from a buffer in big endian. | |
Typedefs | |
| typedef struct yasm_scanner | yasm_scanner |
| Re2c scanner state. | |
Functions | |
| YASM_LIB_DECL void | yasm_scanner_initialize (yasm_scanner *scanner) |
| Initialize scanner state. | |
| YASM_LIB_DECL void | yasm_scanner_delete (yasm_scanner *scanner) |
| Frees any memory used by scanner state; does not free state itself. | |
| YASM_LIB_DECL int | yasm_fill_helper (yasm_scanner *scanner, unsigned char **cursor, size_t(*input_func)(void *d, unsigned char *buf, size_t max), void *input_func_data) |
| Fill a scanner state structure with data coming from an input function. | |
| YASM_LIB_DECL void | yasm_unescape_cstring (unsigned char *str, size_t *len) |
| Unescape a string with C-style escapes. | |
| YASM_LIB_DECL size_t | yasm__splitpath_unix (const char *path, const char **tail) |
| Split a UNIX pathname into head (directory) and tail (base filename) portions. | |
| YASM_LIB_DECL size_t | yasm__splitpath_win (const char *path, const char **tail) |
| Split a Windows pathname into head (directory) and tail (base filename) portions. | |
| YASM_LIB_DECL char * | yasm__getcwd (void) |
| Get the current working directory. | |
| YASM_LIB_DECL char * | yasm__abspath (const char *path) |
| Convert a relative or absolute pathname into an absolute pathname. | |
| YASM_LIB_DECL char * | yasm__combpath_unix (const char *from, const char *to) |
| Build a UNIX pathname that is equivalent to accessing the "to" pathname when you're in the directory containing "from". | |
| YASM_LIB_DECL char * | yasm__combpath_win (const char *from, const char *to) |
| Build a Windows pathname that is equivalent to accessing the "to" pathname when you're in the directory containing "from". | |
| YASM_LIB_DECL size_t | yasm__createpath_common (const char *path, int win) |
| Recursively create tree of directories needed for pathname. | |
| YASM_LIB_DECL FILE * | yasm_fopen_include (const char *iname, const char *from, const char *mode, char **oname) |
| Try to find and open an include file, searching through include paths. | |
| YASM_LIB_DECL void | yasm_delete_include_paths (void) |
| Delete any stored include paths added by yasm_add_include_path(). | |
| YASM_LIB_DECL const char * | yasm_get_include_dir (void **iter) |
| Iterate through include paths. | |
| YASM_LIB_DECL void | yasm_add_include_path (const char *path) |
| Add an include path for use by yasm_fopen_include(). | |
| YASM_LIB_DECL size_t | yasm_fwrite_16_l (unsigned short val, FILE *f) |
| Direct-to-file version of YASM_SAVE_16_L(). | |
| YASM_LIB_DECL size_t | yasm_fwrite_32_l (unsigned long val, FILE *f) |
| Direct-to-file version of YASM_SAVE_32_L(). | |
| YASM_LIB_DECL size_t | yasm_fwrite_16_b (unsigned short val, FILE *f) |
| Direct-to-file version of YASM_SAVE_16_B(). | |
| YASM_LIB_DECL size_t | yasm_fwrite_32_b (unsigned long val, FILE *f) |
| Direct-to-file version of YASM_SAVE_32_B(). | |
YASM file helpers.
Definition in file file.h.
| #define yasm__combpath | ( | from, | |
| to | |||
| ) | yasm__combpath_unix(from, to) |
Build a pathname that is equivalent to accessing the "to" pathname when you're in the directory containing "from".
Result is relative if both from and to are relative. Unless otherwise defined, defaults to yasm__combpath_unix().
| from | from pathname |
| to | to pathname |
| #define yasm__createpath | ( | path | ) | yasm__createpath_common(path, 0) |
| #define yasm__splitpath | ( | path, | |
| tail | |||
| ) | yasm__splitpath_unix(path, tail) |
Split a pathname into head (directory) and tail (base filename) portions.
Unless otherwise defined, defaults to yasm__splitpath_unix().
| path | pathname |
| tail | (returned) base filename |
| #define YASM_LOAD_16_B | ( | val, | |
| ptr | |||
| ) |
do { \ (val) = (*(ptr) & 0xFF) << 8; \ (val) |= *((ptr)+1) & 0xFF; \ } while (0)
Read a 16-bit value from a buffer in big endian.
Does not increment buffer pointer.
| ptr | buffer |
| val | 16-bit value |
| #define YASM_LOAD_16_L | ( | val, | |
| ptr | |||
| ) |
do { \ (val) = *(ptr) & 0xFF; \ (val) |= (*((ptr)+1) & 0xFF) << 8; \ } while (0)
Read a 16-bit value from a buffer in little endian.
Does not increment buffer pointer.
| ptr | buffer |
| val | 16-bit value |
| #define YASM_LOAD_32_B | ( | val, | |
| ptr | |||
| ) |
do { \ (val) = (unsigned long)((*(ptr) & 0xFF) << 24); \ (val) |= (unsigned long)((*((ptr)+1) & 0xFF) << 16); \ (val) |= (unsigned long)((*((ptr)+2) & 0xFF) << 8); \ (val) |= (unsigned long)(*((ptr)+3) & 0xFF); \ } while (0)
Read a 32-bit value from a buffer in big endian.
Does not increment buffer pointer.
| ptr | buffer |
| val | 32-bit value |
| #define YASM_LOAD_32_L | ( | val, | |
| ptr | |||
| ) |
do { \ (val) = (unsigned long)(*(ptr) & 0xFF); \ (val) |= (unsigned long)((*((ptr)+1) & 0xFF) << 8); \ (val) |= (unsigned long)((*((ptr)+2) & 0xFF) << 16); \ (val) |= (unsigned long)((*((ptr)+3) & 0xFF) << 24); \ } while (0)
Read a 32-bit value from a buffer in little endian.
Does not increment buffer pointer.
| ptr | buffer |
| val | 32-bit value |
| #define YASM_LOAD_8 | ( | val, | |
| ptr | |||
| ) | (val) = *(ptr) & 0xFF |
| #define YASM_READ_16_B | ( | val, | |
| ptr | |||
| ) |
do { \ (val) = (*((ptr)++) & 0xFF) << 8; \ (val) |= *((ptr)++) & 0xFF; \ } while (0)
Read a 16-bit value from a buffer in big endian, incrementing buffer pointer.
| ptr | buffer |
| val | 16-bit value |
| #define YASM_READ_16_L | ( | val, | |
| ptr | |||
| ) |
do { \ (val) = *((ptr)++) & 0xFF; \ (val) |= (*((ptr)++) & 0xFF) << 8; \ } while (0)
Read a 16-bit value from a buffer in little endian, incrementing buffer pointer.
| ptr | buffer |
| val | 16-bit value |
| #define YASM_READ_32_B | ( | val, | |
| ptr | |||
| ) |
do { \ (val) = (*((ptr)++) & 0xFF) << 24; \ (val) |= (*((ptr)++) & 0xFF) << 16; \ (val) |= (*((ptr)++) & 0xFF) << 8; \ (val) |= *((ptr)++) & 0xFF; \ } while (0)
Read a 32-bit value from a buffer in big endian, incrementing buffer pointer.
| ptr | buffer |
| val | 32-bit value |
| #define YASM_READ_32_L | ( | val, | |
| ptr | |||
| ) |
do { \ (val) = *((ptr)++) & 0xFF; \ (val) |= (*((ptr)++) & 0xFF) << 8; \ (val) |= (*((ptr)++) & 0xFF) << 16; \ (val) |= (*((ptr)++) & 0xFF) << 24; \ } while (0)
Read a 32-bit value from a buffer in little endian, incrementing buffer pointer.
| ptr | buffer |
| val | 32-bit value |
| #define YASM_READ_8 | ( | val, | |
| ptr | |||
| ) | (val) = *((ptr)++) & 0xFF |
| #define YASM_SAVE_16_B | ( | ptr, | |
| val | |||
| ) |
do { \ *(ptr) = (unsigned char)(((val) >> 8) & 0xFF); \ *((ptr)+1) = (unsigned char)((val) & 0xFF); \ } while (0)
Write a 16-bit value to a buffer in big endian.
Does not increment buffer pointer.
| ptr | buffer |
| val | 16-bit value |
| #define YASM_SAVE_16_L | ( | ptr, | |
| val | |||
| ) |
do { \ *(ptr) = (unsigned char)((val) & 0xFF); \ *((ptr)+1) = (unsigned char)(((val) >> 8) & 0xFF); \ } while (0)
Write a 16-bit value to a buffer in little endian.
Does not increment buffer pointer.
| ptr | buffer |
| val | 16-bit value |
| #define YASM_SAVE_32_B | ( | ptr, | |
| val | |||
| ) |
do { \ *(ptr) = (unsigned char)(((val) >> 24) & 0xFF); \ *((ptr)+1) = (unsigned char)(((val) >> 16) & 0xFF); \ *((ptr)+2) = (unsigned char)(((val) >> 8) & 0xFF); \ *((ptr)+3) = (unsigned char)((val) & 0xFF); \ } while (0)
Write a 32-bit value to a buffer in big endian.
Does not increment buffer pointer.
| ptr | buffer |
| val | 32-bit value |
| #define YASM_SAVE_32_L | ( | ptr, | |
| val | |||
| ) |
do { \ *(ptr) = (unsigned char)((val) & 0xFF); \ *((ptr)+1) = (unsigned char)(((val) >> 8) & 0xFF); \ *((ptr)+2) = (unsigned char)(((val) >> 16) & 0xFF); \ *((ptr)+3) = (unsigned char)(((val) >> 24) & 0xFF); \ } while (0)
Write a 32-bit value to a buffer in little endian.
Does not increment buffer pointer.
| ptr | buffer |
| val | 32-bit value |
| #define YASM_SAVE_8 | ( | ptr, | |
| val | |||
| ) | *(ptr) = (unsigned char)((val) & 0xFF) |
| #define YASM_WRITE_16_B | ( | ptr, | |
| val | |||
| ) |
do { \ *((ptr)++) = (unsigned char)(((val) >> 8) & 0xFF); \ *((ptr)++) = (unsigned char)((val) & 0xFF); \ } while (0)
Write a 16-bit value to a buffer in big endian, incrementing buffer pointer.
| ptr | buffer |
| val | 16-bit value |
| #define YASM_WRITE_16_L | ( | ptr, | |
| val | |||
| ) |
do { \ *((ptr)++) = (unsigned char)((val) & 0xFF); \ *((ptr)++) = (unsigned char)(((val) >> 8) & 0xFF); \ } while (0)
Write a 16-bit value to a buffer in little endian, incrementing buffer pointer.
| ptr | buffer |
| val | 16-bit value |
| #define YASM_WRITE_32_B | ( | ptr, | |
| val | |||
| ) |
do { \ *((ptr)++) = (unsigned char)(((val) >> 24) & 0xFF); \ *((ptr)++) = (unsigned char)(((val) >> 16) & 0xFF); \ *((ptr)++) = (unsigned char)(((val) >> 8) & 0xFF); \ *((ptr)++) = (unsigned char)((val) & 0xFF); \ } while (0)
Write a 32-bit value to a buffer in big endian, incrementing buffer pointer.
| ptr | buffer |
| val | 32-bit value |
| #define YASM_WRITE_32_L | ( | ptr, | |
| val | |||
| ) |
do { \ *((ptr)++) = (unsigned char)((val) & 0xFF); \ *((ptr)++) = (unsigned char)(((val) >> 8) & 0xFF); \ *((ptr)++) = (unsigned char)(((val) >> 16) & 0xFF); \ *((ptr)++) = (unsigned char)(((val) >> 24) & 0xFF); \ } while (0)
Write a 32-bit value to a buffer in little endian, incrementing buffer pointer.
| ptr | buffer |
| val | 32-bit value |
| #define YASM_WRITE_8 | ( | ptr, | |
| val | |||
| ) | *((ptr)++) = (unsigned char)((val) & 0xFF) |
| typedef struct yasm_scanner yasm_scanner |
Re2c scanner state.
| YASM_LIB_DECL char* yasm__abspath | ( | const char * | path | ) |
Convert a relative or absolute pathname into an absolute pathname.
| path | pathname |
| YASM_LIB_DECL char* yasm__combpath_unix | ( | const char * | from, |
| const char * | to | ||
| ) |
Build a UNIX pathname that is equivalent to accessing the "to" pathname when you're in the directory containing "from".
Result is relative if both from and to are relative.
| from | from pathname |
| to | to pathname |
| YASM_LIB_DECL char* yasm__combpath_win | ( | const char * | from, |
| const char * | to | ||
| ) |
Build a Windows pathname that is equivalent to accessing the "to" pathname when you're in the directory containing "from".
Result is relative if both from and to are relative.
| from | from pathname |
| to | to pathname |
| YASM_LIB_DECL size_t yasm__createpath_common | ( | const char * | path, |
| int | win | ||
| ) |
Recursively create tree of directories needed for pathname.
| path | pathname |
| win | handle windows paths |
| YASM_LIB_DECL char* yasm__getcwd | ( | void | ) |
Get the current working directory.
| YASM_LIB_DECL size_t yasm__splitpath_unix | ( | const char * | path, |
| const char ** | tail | ||
| ) |
Split a UNIX pathname into head (directory) and tail (base filename) portions.
| path | pathname |
| tail | (returned) base filename |
| YASM_LIB_DECL size_t yasm__splitpath_win | ( | const char * | path, |
| const char ** | tail | ||
| ) |
Split a Windows pathname into head (directory) and tail (base filename) portions.
| path | pathname |
| tail | (returned) base filename |
| YASM_LIB_DECL void yasm_add_include_path | ( | const char * | path | ) |
Add an include path for use by yasm_fopen_include().
If path is relative, it is treated by yasm_fopen_include() as relative to the current working directory.
| path | path to add |
| YASM_LIB_DECL int yasm_fill_helper | ( | yasm_scanner * | scanner, |
| unsigned char ** | cursor, | ||
| size_t(*)(void *d, unsigned char *buf, size_t max) | input_func, | ||
| void * | input_func_data | ||
| ) |
Fill a scanner state structure with data coming from an input function.
| scanner | Re2c scanner state |
| cursor | Re2c scan cursor |
| input_func | Input function to read data; takes buffer and maximum number of bytes, returns number of bytes read. |
| input_func_data | Data to pass as the first parameter to input_func |
| YASM_LIB_DECL FILE* yasm_fopen_include | ( | const char * | iname, |
| const char * | from, | ||
| const char * | mode, | ||
| char ** | oname | ||
| ) |
Try to find and open an include file, searching through include paths.
First iname is looked for relative to the directory containing "from", then it's looked for relative to each of the include paths.
All pathnames may be either absolute or relative; from, oname, and include paths, if relative, are relative from the current working directory.
First match wins; the full pathname (newly allocated) to the opened file is saved into oname, and the fopen'ed FILE * is returned. If not found, NULL is returned.
| iname | file to include |
| from | file doing the including |
| mode | fopen mode string |
| oname | full pathname of included file (may be relative). NULL may be passed if this is unwanted. |
| YASM_LIB_DECL size_t yasm_fwrite_16_b | ( | unsigned short | val, |
| FILE * | f | ||
| ) |
Direct-to-file version of YASM_SAVE_16_B().
| val | 16-bit value |
| f | file |
| YASM_LIB_DECL size_t yasm_fwrite_16_l | ( | unsigned short | val, |
| FILE * | f | ||
| ) |
Direct-to-file version of YASM_SAVE_16_L().
| val | 16-bit value |
| f | file |
| YASM_LIB_DECL size_t yasm_fwrite_32_b | ( | unsigned long | val, |
| FILE * | f | ||
| ) |
Direct-to-file version of YASM_SAVE_32_B().
| val | 32-bit value |
| f | file |
| YASM_LIB_DECL size_t yasm_fwrite_32_l | ( | unsigned long | val, |
| FILE * | f | ||
| ) |
Direct-to-file version of YASM_SAVE_32_L().
| val | 32-bit value |
| f | file |
| YASM_LIB_DECL void yasm_scanner_delete | ( | yasm_scanner * | scanner | ) |
Frees any memory used by scanner state; does not free state itself.
| scanner | Re2c scanner state |
| YASM_LIB_DECL void yasm_scanner_initialize | ( | yasm_scanner * | scanner | ) |
Initialize scanner state.
| scanner | Re2c scanner state |
| YASM_LIB_DECL void yasm_unescape_cstring | ( | unsigned char * | str, |
| size_t * | len | ||
| ) |
Unescape a string with C-style escapes.
Handles b, f, n, r, t, and hex and octal escapes. String is updated in-place. Edge cases:
| str | C-style string (updated in place) |
| len | length of string (updated with new length) |
1.7.3