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


5.14.7 Getting a Preprocessed Output

The functions qsmm_parse_asm_source_* described in Parsing an Assembler Program can automatically call the assembler preprocessor to preprocess a source program text if the QSMM_PARSE_ASM_PREPROCESS flag is passed to those functions. However, sometimes it might be necessary to obtain a preprocessed source text directly. To accomplish this task, the following functions can be used.

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 by argument in_p in the form of a null-terminated string. The function qsmm_preprocess_asm_source_stream preprocesses a source program text read from stream filep.

On success, if out_pp is not NULL, both functions set *out_pp to the pointer to an allocated null-terminated string containing the preprocessed output. If the preprocessor produces the zero-length output, then *out_pp will be set to NULL. If after successful function completion *out_pp is not NULL, then a memory block addressed by *out_pp should be freed by the function free when its content is not needed any longer.

If msglist is not NULL, then messages generated during preprocessing will be written to message list msglist. If cwd_p is not NULL, then cwd_p will be used for the name of current working directory when resolving ‘include’ directives. If cwd_p is NULL, then the actual current working directory will be used when resolving ‘include’ directives. Arguments rez1, rez2, and rez3 are reserved 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 constant INT_MAX. If out_pp is not NULL, and that number is greater than 0 (and less than INT_MAX), then it will be the number of bytes in a string addressed by *out_pp, not counting trailing byte 0. When the functions return INT_MAX, the number of bytes in a string addressed by *out_pp (if out_pp is not NULL) is greater than or equal to INT_MAX. On failure, a negative error code is returned. Currently, the following error codes can be returned.

QSMM_ERR_PRG

At least one error was encountered in the source program text.

QSMM_ERR_ILSEQ

The source program text cannot be converted to a wide string according to the current locale or the preprocessed output cannot be converted to a multibyte string according to the current locale.

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 provided in a file named fln. On success, if out_pp is not NULL, the function sets *out_pp to the pointer to an allocated null-terminated string containing the preprocessed output. If the preprocessor produces the zero-length output, then *out_pp will be set to NULL. If after successful function completion *out_pp is not NULL, then a memory block addressed by *out_pp should be freed by the function free when its content is not needed any longer.

If msglist is not NULL, then messages generated during preprocessing will be written to message list msglist. Arguments rez1, rez2, and rez3 are reserved 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 constant INT_MAX. If out_pp is not NULL, and that number is greater than 0 (and less than INT_MAX), then it will be the number of bytes in a string addressed by *out_pp, not counting trailing byte 0. When the function returns INT_MAX, the number of bytes in a string addressed by *out_pp (if out_pp is not NULL) is greater than or equal to INT_MAX. On failure, a negative error code is returned. Currently, the following error codes can be returned.

QSMM_ERR_LIBC

When accessing file fln, the operating system has returned an error. The variable errno holds the error code.

QSMM_ERR_PRG

At least one error was encountered in the source program text.

QSMM_ERR_ILSEQ

The source program text cannot be converted to a wide string according to the current locale or the preprocessed output cannot be converted to a multibyte string according to the current locale.

QSMM_ERR_NOMEM

There was not enough memory to perform the operation.


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