Previous: , Up: Using the Assembler Preprocessor   [Contents][Index]


5.13.6 Getting Preprocessed Output

The functions qsmm_parse_asm_source_buf, qsmm_parse_asm_source_stream, and qsmm_parse_asm_source_file described in Parsing an Assembler Program can automatically call the assembler preprocessor to preprocess a source program text if they receive the QSMM_PARSE_ASM_PREPROCESS flag. However, sometimes it might be necessary to obtain a preprocessed source text directly. Use the following functions to accomplish this task.

Function: int qsmm_preprocess_asm_source_buf (const char *in_p, const char *cwd_p, int rez1, void *rez2, void *rez3, qsmm_msglist_t msglist, char **out_pp)
Function: int qsmm_preprocess_asm_source_stream (FILE *filep, const char *cwd_p, int rez1, void *rez2, void *rez3, qsmm_msglist_t msglist, char **out_pp)

The function qsmm_preprocess_asm_source_buf preprocesses a source program text provided via the argument in_p as a string. The function qsmm_preprocess_asm_source_stream preprocesses a source program text read from a stream filep.

If out_pp is not NULL, both functions set *out_pp to an allocated string containing preprocessed output. If the preprocessor produces zero-length output, both functions set *out_pp to NULL. If *out_pp is not NULL, free by the function free a memory block addressed by *out_pp after use.

If msglist is not NULL, both functions add to a message list msglist error and note messages generated while preprocessing the source program text. If cwd_p is not NULL, both functions use a string cwd_p as the name of a current working directory when resolving ‘include’ directives. If cwd_p is NULL, both functions use an actual current working directory when resolving ‘include’ directives. The arguments rez1, rez2, and rez3 are for future use and must be equal to 0.

On success, both functions return a non-negative number of bytes in the preprocessed output or INT_MAX if this number is greater than INT_MAX. If out_pp is not NULL, and this number is greater than 0 and less than INT_MAX, it is the length of a string *out_pp. On failure, both functions return a negative error code. Currently, the functions can return the following error codes.

QSMM_ERR_PRG

The source program text has at least one error. If msglist is not NULL, the message list msglist contains at least one error message.

QSMM_ERR_ILSEQ

Unable to convert a multibyte string to a wide string or vice versa according to a current locale, including the inability to convert the source program text to a wide string and the inability to convert the preprocessed output to a multibyte string.

QSMM_ERR_NOMEM

There was not enough memory to perform the operation.

Function: int qsmm_preprocess_asm_source_file (const char *fln, int rez1, void *rez2, void *rez3, qsmm_msglist_t msglist, char **out_pp)

This function preprocesses a source program text read from a file fln. If out_pp is not NULL, the function sets *out_pp to an allocated string containing preprocessed output. If the preprocessor produces zero-length output, the function sets *out_pp to NULL. If *out_pp is not NULL, free by the function free a memory block addressed by *out_pp after use.

If msglist is not NULL, the function adds to a message list msglist error and note messages generated while preprocessing the source program text. The arguments rez1, rez2, and rez3 are for future use and must be equal to 0.

On success, the function returns a non-negative number of bytes in the preprocessed output or INT_MAX if this number is greater than INT_MAX. If out_pp is not NULL, and this number is greater than 0 and less than INT_MAX, it is the length of a string *out_pp. On failure, the function returns a negative error code. Currently, the function can return the following error codes.

QSMM_ERR_LIBC

The operating system reported a file access error. The variable errno holds the error code.

QSMM_ERR_PRG

The source program text has at least one error. If msglist is not NULL, the message list msglist contains at least one error message.

QSMM_ERR_ILSEQ

Unable to convert a multibyte string to a wide string or vice versa according to a current locale, including the inability to convert the source program text to a wide string and the inability to convert the preprocessed output to a multibyte string.

QSMM_ERR_NOMEM

There was not enough memory to perform the operation.


Previous: , Up: Using the Assembler Preprocessor   [Contents][Index]