pptoken **output;
} ppmacro;
-typedef struct {
+typedef struct ftepp_s {
lex_file *lex;
int token;
unsigned int errors;
/* Like in parser.c - files keep the previous state so we have one global
* preprocessor. Except here we will want to warn about dangling #ifs.
*/
-static ftepp_t *ftepp;
-
-static bool ftepp_preprocess_done()
+static bool ftepp_preprocess_done(ftepp_t *ftepp)
{
bool retval = true;
if (vec_size(ftepp->conditions)) {
return retval;
}
-bool ftepp_preprocess_file(const char *filename)
+bool ftepp_preprocess_file(ftepp_t *ftepp, const char *filename)
{
ftepp->lex = lex_open(filename);
ftepp->itemname = util_strdup(filename);
}
if (!ftepp_preprocess(ftepp))
return false;
- return ftepp_preprocess_done();
+ return ftepp_preprocess_done(ftepp);
}
-bool ftepp_preprocess_string(const char *name, const char *str)
+bool ftepp_preprocess_string(ftepp_t *ftepp, const char *name, const char *str)
{
ftepp->lex = lex_open_string(str, strlen(str), name);
ftepp->itemname = util_strdup(name);
}
if (!ftepp_preprocess(ftepp))
return false;
- return ftepp_preprocess_done();
+ return ftepp_preprocess_done(ftepp);
}
-void ftepp_add_macro(const char *name, const char *value) {
+void ftepp_add_macro(ftepp_t *ftepp, const char *name, const char *value) {
char *create = NULL;
/* use saner path for empty macros */
if (!value) {
- ftepp_add_define("__builtin__", name);
+ ftepp_add_define(ftepp, "__builtin__", name);
return;
}
vec_upload(create, value, strlen(value));
vec_push (create, 0);
- ftepp_preprocess_string("__builtin__", create);
+ ftepp_preprocess_string(ftepp, "__builtin__", create);
vec_free (create);
}
-bool ftepp_init()
+ftepp_t *ftepp_create()
{
+ ftepp_t *ftepp;
char minor[32];
char major[32];
ftepp = ftepp_new();
if (!ftepp)
- return false;
+ return NULL;
memset(minor, 0, sizeof(minor));
memset(major, 0, sizeof(major));
/* set the right macro based on the selected standard */
- ftepp_add_define(NULL, "GMQCC");
+ ftepp_add_define(ftepp, NULL, "GMQCC");
if (OPTS_OPTION_U32(OPTION_STANDARD) == COMPILER_FTEQCC) {
- ftepp_add_define(NULL, "__STD_FTEQCC__");
+ ftepp_add_define(ftepp, NULL, "__STD_FTEQCC__");
/* 1.00 */
major[0] = '"';
major[1] = '1';
minor[1] = '0';
minor[2] = '"';
} else if (OPTS_OPTION_U32(OPTION_STANDARD) == COMPILER_GMQCC) {
- ftepp_add_define(NULL, "__STD_GMQCC__");
+ ftepp_add_define(ftepp, NULL, "__STD_GMQCC__");
snprintf(major, 32, "\"%d\"", GMQCC_VERSION_MAJOR);
snprintf(minor, 32, "\"%d\"", GMQCC_VERSION_MINOR);
} else if (OPTS_OPTION_U32(OPTION_STANDARD) == COMPILER_QCCX) {
- ftepp_add_define(NULL, "__STD_QCCX__");
+ ftepp_add_define(ftepp, NULL, "__STD_QCCX__");
snprintf(major, 32, "\"%d\"", GMQCC_VERSION_MAJOR);
snprintf(minor, 32, "\"%d\"", GMQCC_VERSION_MINOR);
} else if (OPTS_OPTION_U32(OPTION_STANDARD) == COMPILER_QCC) {
- ftepp_add_define(NULL, "__STD_QCC__");
+ ftepp_add_define(ftepp, NULL, "__STD_QCC__");
/* 1.0 */
major[0] = '"';
major[1] = '1';
minor[2] = '"';
}
- ftepp_add_macro("__STD_VERSION_MINOR__", minor);
- ftepp_add_macro("__STD_VERSION_MAJOR__", major);
+ ftepp_add_macro(ftepp, "__STD_VERSION_MINOR__", minor);
+ ftepp_add_macro(ftepp, "__STD_VERSION_MAJOR__", major);
- return true;
+ return ftepp;
}
-void ftepp_add_define(const char *source, const char *name)
+void ftepp_add_define(ftepp_t *ftepp, const char *source, const char *name)
{
ppmacro *macro;
lex_ctx ctx = { "__builtin__", 0 };
vec_push(ftepp->macros, macro);
}
-const char *ftepp_get()
+const char *ftepp_get(ftepp_t *ftepp)
{
return ftepp->output_string;
}
-void ftepp_flush()
+void ftepp_flush(ftepp_t *ftepp)
{
ftepp_flush_do(ftepp);
}
-void ftepp_finish()
+void ftepp_finish(ftepp_t *ftepp)
{
if (!ftepp)
return;
ftepp_delete(ftepp);
- ftepp = NULL;
}
/*====================== ftepp.c commandline ========================*/
/*===================================================================*/
struct lex_file_s;
+struct ftepp_s;
+
typedef struct {
const char *name;
char *(*func)(struct lex_file_s *);
*/
#define FTEPP_PREDEF_COUNT 8
-bool ftepp_init ();
-bool ftepp_preprocess_file (const char *filename);
-bool ftepp_preprocess_string(const char *name, const char *str);
-void ftepp_finish ();
-const char *ftepp_get ();
-void ftepp_flush ();
-void ftepp_add_define (const char *source, const char *name);
-void ftepp_add_macro (const char *name, const char *value);
+struct ftepp_s *ftepp_create ();
+bool ftepp_preprocess_file (struct ftepp_s *ftepp, const char *filename);
+bool ftepp_preprocess_string(struct ftepp_s *ftepp, const char *name, const char *str);
+void ftepp_finish (struct ftepp_s *ftepp);
+const char *ftepp_get (struct ftepp_s *ftepp);
+void ftepp_flush (struct ftepp_s *ftepp);
+void ftepp_add_define (struct ftepp_s *ftepp, const char *source, const char *name);
+void ftepp_add_macro (struct ftepp_s *ftepp, const char *name, const char *value);
extern const ftepp_predef_t ftepp_predefs[FTEPP_PREDEF_COUNT];
bool progs_src = false;
FILE *outfile = NULL;
struct parser_s *parser = NULL;
+ struct ftepp_s *ftepp = NULL;
app_name = argv[0];
con_init ();
}
if (OPTS_OPTION_BOOL(OPTION_PP_ONLY) || OPTS_FLAG(FTEPP)) {
- if (!ftepp_init()) {
+ if (!(ftepp = ftepp_create())) {
con_err("failed to initialize parser\n");
retval = 1;
goto cleanup;
/* add macros */
if (OPTS_OPTION_BOOL(OPTION_PP_ONLY) || OPTS_FLAG(FTEPP)) {
for (itr = 0; itr < vec_size(ppems); itr++) {
- ftepp_add_macro(ppems[itr].name, ppems[itr].value);
+ ftepp_add_macro(ftepp, ppems[itr].name, ppems[itr].value);
mem_d(ppems[itr].name);
/* can be null */
con_out("Mode: %s\n", (progs_src ? "progs.src" : "manual"));
con_out("There are %lu items to compile:\n", (unsigned long)vec_size(items));
}
+
for (itr = 0; itr < vec_size(items); ++itr) {
if (!OPTS_OPTION_BOOL(OPTION_QUIET) &&
!OPTS_OPTION_BOOL(OPTION_PP_ONLY))
if (OPTS_OPTION_BOOL(OPTION_PP_ONLY)) {
const char *out;
- if (!ftepp_preprocess_file(items[itr].filename)) {
+ if (!ftepp_preprocess_file(ftepp, items[itr].filename)) {
retval = 1;
goto cleanup;
}
- out = ftepp_get();
+ out = ftepp_get(ftepp);
if (out)
fs_file_printf(outfile, "%s", out);
- ftepp_flush();
+ ftepp_flush(ftepp);
}
else {
if (OPTS_FLAG(FTEPP)) {
const char *data;
- if (!ftepp_preprocess_file(items[itr].filename)) {
+ if (!ftepp_preprocess_file(ftepp, items[itr].filename)) {
retval = 1;
goto cleanup;
}
- data = ftepp_get();
+ data = ftepp_get(ftepp);
if (vec_size(data)) {
if (!parser_compile_string(parser, items[itr].filename, data, vec_size(data))) {
retval = 1;
goto cleanup;
}
}
- ftepp_flush();
+ ftepp_flush(ftepp);
}
else {
if (!parser_compile_file(parser, items[itr].filename)) {
}
}
- ftepp_finish();
+ ftepp_finish(ftepp);
if (!OPTS_OPTION_BOOL(OPTION_PP_ONLY)) {
if (!parser_finish(parser, OPTS_OPTION_STR(OPTION_OUTPUT))) {
retval = 1;
cleanup:
util_debug("COM", "cleaning ...\n");
- ftepp_finish();
+ ftepp_finish(ftepp);
con_close();
vec_free(items);
vec_free(ppems);