return ftepp_preprocess_done();
}
+
+void ftepp_add_macro(const char *name, const char *value) {
+ char *create = NULL;
+ vec_upload(create, "#define ", 8);
+ vec_upload(create, name, strlen(name));
+ vec_push (create, ' ');
+ vec_upload(create, value, strlen(value));
+ vec_push (create, 0);
+
+ ftepp_preprocess_string("__builtin__", create);
+ vec_free (create);
+}
+
bool ftepp_init()
{
char minor[32];
char major[32];
- char *verminor = NULL;
- char *vermajor = NULL;
ftepp = ftepp_new();
if (!ftepp)
if (opts.standard == COMPILER_FTEQCC) {
ftepp_add_define(NULL, "__STD_FTEQCC__");
/* 1.00 */
- major[0] = '1';
- minor[0] = '0';
+ major[0] = '"';
+ major[1] = '1';
+ major[2] = '"';
+
+ minor[0] = '"';
+ minor[1] = '0';
+ minor[2] = '"';
} else if (opts.standard == COMPILER_GMQCC) {
ftepp_add_define(NULL, "__STD_GMQCC__");
- sprintf(major, "%d", GMQCC_VERSION_MAJOR);
- sprintf(minor, "%d", GMQCC_VERSION_MINOR);
+ sprintf(major, "\"%d\"", GMQCC_VERSION_MAJOR);
+ sprintf(minor, "\"%d\"", GMQCC_VERSION_MINOR);
} else if (opts.standard == COMPILER_QCC) {
ftepp_add_define(NULL, "__STD_QCC__");
/* 1.0 */
- major[0] = '1';
- minor[0] = '0';
- }
+ major[0] = '"';
+ major[1] = '1';
+ major[2] = '"';
- vec_upload(verminor, "#define __STD_VERSION_MINOR__ \"", 31);
- vec_upload(vermajor, "#define __STD_VERSION_MAJOR__ \"", 31);
- vec_upload(verminor, minor, strlen(minor));
- vec_upload(vermajor, major, strlen(major));
- vec_push (verminor, '"');
- vec_push (vermajor, '"');
- vec_push (verminor, 0);
- vec_push (vermajor, 0);
+ minor[0] = '"';
+ minor[1] = '0';
+ minor[2] = '"';
+ }
- ftepp_preprocess_string("__builtin__", verminor);
- ftepp_preprocess_string("__builtin__", vermajor);
+ ftepp_add_macro("__STD_VERSION_MINOR__", minor);
+ ftepp_add_macro("__STD_VERSION_MAJOR__", major);
- vec_free(verminor);
- vec_free(vermajor);
return true;
}
const oper_info *operators = NULL;
size_t operator_count = 0;
-typedef struct { char *filename; int type; } argitem;
+typedef struct { char *filename; int type; } argitem;
+typedef struct { char *name; char *value; } ppitem;
static argitem *items = NULL;
+static ppitem *ppems = NULL;
#define TYPE_QC 0
#define TYPE_ASM 1
while (!argend && argc > 1) {
char *argarg;
argitem item;
+ ppitem macro;
++argv;
--argc;
options_setflag("LNO", true);
break;
+ case 'D':
+ if (!(argarg = strchr(argv[0] + 2, '='))) {
+ con_out("missing = in -D\n");
+ exit(0);
+ }
+ *argarg='\0'; /* terminate for name */
+ macro.name = util_strdup(argarg);
+ macro.value = util_strdup(argv[0]+2);
+ vec_push(ppems, macro);
+ break;
+
/* handle all -fflags */
case 'f':
util_strtocmd(argv[0]+2, argv[0]+2, strlen(argv[0]+2)+1);
goto cleanup;
}
}
+
if (opts.pp_only || OPTS_FLAG(FTEPP)) {
if (!ftepp_init()) {
con_err("failed to initialize parser\n");
retval = 1;
goto cleanup;
+ } else {
+ size_t i;
+ for (i = 0; i < vec_size(ppems); ++i) {
+ ftepp_add_macro(ppems[i].name, ppems[i].value);
+ mem_d(ppems[i].name);
+ mem_d(ppems[i].value);
+ }
}
}
ftepp_finish();
con_close();
vec_free(items);
+ vec_free(ppems);
if (!opts.pp_only)
parser_cleanup();