libyasm/file.h File Reference

YASM file helpers. More...

Go to the source code of this file.

Data Structures

struct  yasm_scanner
 Re2c scanner state. More...

Defines

#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_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.

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 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().


Detailed Description

YASM file helpers.

Definition in file file.h.


Define Documentation

#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().

For internal use only.

Parameters:
from from pathname
to to pathname
Returns:
Combined path (newly allocated).

Definition at line 180 of file file.h.

#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().

For internal use only.

Parameters:
path pathname
tail (returned) base filename
Returns:
Length of head (directory).

Definition at line 124 of file file.h.

#define YASM_LOAD_16_B ( val,
ptr   ) 

Value:

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.

Note:
Only works properly if ptr is an (unsigned char *).
Parameters:
ptr buffer
val 16-bit value

Definition at line 487 of file file.h.

#define YASM_LOAD_16_L ( val,
ptr   ) 

Value:

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.

Note:
Only works properly if ptr is an (unsigned char *).
Parameters:
ptr buffer
val 16-bit value

Definition at line 461 of file file.h.

#define YASM_LOAD_32_B ( val,
ptr   ) 

Value:

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.

Note:
Only works properly if ptr is an (unsigned char *).
Parameters:
ptr buffer
val 32-bit value

Definition at line 499 of file file.h.

#define YASM_LOAD_32_L ( val,
ptr   ) 

Value:

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.

Note:
Only works properly if ptr is an (unsigned char *).
Parameters:
ptr buffer
val 32-bit value

Definition at line 473 of file file.h.

#define YASM_LOAD_8 ( val,
ptr   )     (val) = *(ptr) & 0xFF

Read an 8-bit value from a buffer.

Does not increment buffer pointer.

Note:
Only works properly if ptr is an (unsigned char *).
Parameters:
ptr buffer
val 8-bit value

Definition at line 452 of file file.h.

#define YASM_READ_16_B ( val,
ptr   ) 

Value:

do {                                    \
            (val) = (*((ptr)++) & 0xFF) << 8;   \
            (val) |= *((ptr)++) & 0xFF;         \
        } while (0)
Read a 16-bit value from a buffer in big endian, incrementing buffer pointer.

Note:
Only works properly if ptr is an (unsigned char *).
Parameters:
ptr buffer
val 16-bit value

Definition at line 427 of file file.h.

#define YASM_READ_16_L ( val,
ptr   ) 

Value:

do {                                    \
            (val) = *((ptr)++) & 0xFF;          \
            (val) |= (*((ptr)++) & 0xFF) << 8;  \
        } while (0)
Read a 16-bit value from a buffer in little endian, incrementing buffer pointer.

Note:
Only works properly if ptr is an (unsigned char *).
Parameters:
ptr buffer
val 16-bit value

Definition at line 401 of file file.h.

#define YASM_READ_32_B ( val,
ptr   ) 

Value:

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.

Note:
Only works properly if ptr is an (unsigned char *).
Parameters:
ptr buffer
val 32-bit value

Definition at line 439 of file file.h.

#define YASM_READ_32_L ( val,
ptr   ) 

Value:

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.

Note:
Only works properly if ptr is an (unsigned char *).
Parameters:
ptr buffer
val 32-bit value

Definition at line 413 of file file.h.

#define YASM_READ_8 ( val,
ptr   )     (val) = *((ptr)++) & 0xFF

Read an 8-bit value from a buffer, incrementing buffer pointer.

Note:
Only works properly if ptr is an (unsigned char *).
Parameters:
ptr buffer
val 8-bit value

Definition at line 392 of file file.h.

#define YASM_SAVE_16_B ( ptr,
val   ) 

Value:

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.

Note:
Only works properly if ptr is an (unsigned char *).
Parameters:
ptr buffer
val 16-bit value

Definition at line 327 of file file.h.

#define YASM_SAVE_16_L ( ptr,
val   ) 

Value:

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.

Note:
Only works properly if ptr is an (unsigned char *).
Parameters:
ptr buffer
val 16-bit value

Definition at line 301 of file file.h.

#define YASM_SAVE_32_B ( ptr,
val   ) 

Value:

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.

Note:
Only works properly if ptr is an (unsigned char *).
Parameters:
ptr buffer
val 32-bit value

Definition at line 339 of file file.h.

#define YASM_SAVE_32_L ( ptr,
val   ) 

Value:

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.

Note:
Only works properly if ptr is an (unsigned char *).
Parameters:
ptr buffer
val 32-bit value

Definition at line 313 of file file.h.

#define YASM_SAVE_8 ( ptr,
val   )     *(ptr) = (unsigned char)((val) & 0xFF)

Write an 8-bit value to a buffer.

Does not increment buffer pointer.

Note:
Only works properly if ptr is an (unsigned char *).
Parameters:
ptr buffer
val 8-bit value

Definition at line 292 of file file.h.

#define YASM_WRITE_16_B ( ptr,
val   ) 

Value:

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.

Note:
Only works properly if ptr is an (unsigned char *).
Parameters:
ptr buffer
val 16-bit value

Definition at line 266 of file file.h.

#define YASM_WRITE_16_L ( ptr,
val   ) 

Value:

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.

Note:
Only works properly if ptr is an (unsigned char *).
Parameters:
ptr buffer
val 16-bit value

Definition at line 240 of file file.h.

#define YASM_WRITE_32_B ( ptr,
val   ) 

Value:

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.

Note:
Only works properly if ptr is an (unsigned char *).
Parameters:
ptr buffer
val 32-bit value

Definition at line 278 of file file.h.

#define YASM_WRITE_32_L ( ptr,
val   ) 

Value:

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.

Note:
Only works properly if ptr is an (unsigned char *).
Parameters:
ptr buffer
val 32-bit value

Definition at line 252 of file file.h.

#define YASM_WRITE_8 ( ptr,
val   )     *((ptr)++) = (unsigned char)((val) & 0xFF)

Write an 8-bit value to a buffer, incrementing buffer pointer.

Note:
Only works properly if ptr is an (unsigned char *).
Parameters:
ptr buffer
val 8-bit value

Definition at line 231 of file file.h.


Function Documentation

YASM_LIB_DECL char* yasm__abspath ( const char *  path  ) 

Convert a relative or absolute pathname into an absolute pathname.

For internal use only.

Parameters:
path pathname
Returns:
Absolute version of path (newly allocated).

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.

For internal use only.

Parameters:
from from pathname
to to pathname
Returns:
Combined path (newly allocated).

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.

For internal use only.

Parameters:
from from pathname
to to pathname
Returns:
Combined path (newly allocated).

YASM_LIB_DECL char* yasm__getcwd ( void   ) 

Get the current working directory.

For internal use only.

Returns:
Current working directory pathname (newly allocated).

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.

For internal use only.

Parameters:
path pathname
tail (returned) base filename
Returns:
Length of head (directory).

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.

For internal use only.

Parameters:
path pathname
tail (returned) base filename
Returns:
Length of head (directory).

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.

Parameters:
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.

Parameters:
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
Returns:
1 if this was the first time this function was called on this scanner state, 0 otherwise.

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.

Parameters:
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.
Returns:
fopen'ed include file, or NULL if not found.

YASM_LIB_DECL size_t yasm_fwrite_16_b ( unsigned short  val,
FILE *  f 
)

Direct-to-file version of YASM_SAVE_16_B().

Note:
Using the macro multiple times with a single fwrite() call will probably be faster than calling this function many times.
Parameters:
val 16-bit value
f file
Returns:
1 if the write was successful, 0 if not (just like fwrite()).

YASM_LIB_DECL size_t yasm_fwrite_16_l ( unsigned short  val,
FILE *  f 
)

Direct-to-file version of YASM_SAVE_16_L().

Note:
Using the macro multiple times with a single fwrite() call will probably be faster than calling this function many times.
Parameters:
val 16-bit value
f file
Returns:
1 if the write was successful, 0 if not (just like fwrite()).

YASM_LIB_DECL size_t yasm_fwrite_32_b ( unsigned long  val,
FILE *  f 
)

Direct-to-file version of YASM_SAVE_32_B().

Note:
Using the macro multiple times with a single fwrite() call will probably be faster than calling this function many times.
Parameters:
val 32-bit value
f file
Returns:
1 if the write was successful, 0 if not (just like fwrite()).

YASM_LIB_DECL size_t yasm_fwrite_32_l ( unsigned long  val,
FILE *  f 
)

Direct-to-file version of YASM_SAVE_32_L().

Note:
Using the macro multiple times with a single fwrite() call will probably be faster than calling this function many times.
Parameters:
val 32-bit value
f file
Returns:
1 if the write was successful, 0 if not (just like fwrite()).

YASM_LIB_DECL void yasm_scanner_delete ( yasm_scanner scanner  ) 

Frees any memory used by scanner state; does not free state itself.

Parameters:
scanner Re2c scanner state

YASM_LIB_DECL void yasm_scanner_initialize ( yasm_scanner scanner  ) 

Initialize scanner state.

Parameters:
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:


Generated on Fri Jul 25 01:23:33 2008 for libyasm by  doxygen 1.5.2