COMPILER_GMQCC /* this QuakeC */
} opts_std_t;
-typedef union {
- bool B;
- uint16_t U16;
- uint32_t U32;
- char *STR;
+typedef struct {
+ union {
+ bool b;
+ uint16_t u16;
+ uint32_t u32;
+
+ union {
+ char *p;
+ const char *c;
+ } str;
+ } data;
+
+ bool allocated;
} opt_value_t;
#define OPTS_WARN(i) OPTS_GENERIC(opts.warn, (i))
#define OPTS_WERROR(i) OPTS_GENERIC(opts.werror, (i))
#define OPTS_OPTIMIZATION(i) OPTS_GENERIC(opts.optimization, (i))
-#define OPTS_OPTION_BOOL(X) (opts.options[X].B)
-#define OPTS_OPTION_U16(X) (opts.options[X].U16)
-#define OPTS_OPTION_U32(X) (opts.options[X].U32)
-#define OPTS_OPTION_STR(X) (opts.options[X].STR)
+#define OPTS_OPTION_DUPED(X) (opts.options[X].allocated)
+#define OPTS_OPTION_BOOL(X) (opts.options[X].data.b)
+#define OPTS_OPTION_U16(X) (opts.options[X].data.u16)
+#define OPTS_OPTION_U32(X) (opts.options[X].data.u32)
+#define OPTS_OPTION_DUP(X) *(OPTS_OPTION_DUPED(X)=true, &(opts.options[X].data.str.p))
+#define OPTS_OPTION_STR(X) (opts.options[X].data.str.c)
#endif /*! GMQCC_HDR */
int main(int argc, char **argv) {
size_t itr;
int retval = 0;
- bool opts_output_free = false;
bool operators_free = false;
bool progs_src = false;
fs_file_t *outfile = NULL;
item.type = TYPE_QC;
vec_push(items, item);
} else if (!opts_output_wasset) {
- OPTS_OPTION_STR(OPTION_OUTPUT) = util_strdup(line);
- opts_output_free = true;
+ OPTS_OPTION_DUP(OPTION_OUTPUT) = util_strdup(line);
hasline = true;
}
}
if (!OPTS_OPTION_BOOL(OPTION_PP_ONLY))
if(parser) parser_cleanup(parser);
- if (opts_output_free)
- mem_d(OPTS_OPTION_STR(OPTION_OUTPUT));
+
+ /* free allocated option strings */
+ for (itr = 0; itr < OPTION_COUNT; itr++)
+ if (OPTS_OPTION_DUPED(itr))
+ mem_d(OPTS_OPTION_STR(itr));
+
if (operators_free)
mem_d((void*)operators);
static void opts_setdefault(void) {
memset(&opts, 0, sizeof(opts_cmd_t));
OPTS_OPTION_BOOL(OPTION_CORRECTION) = true;
- OPTS_OPTION_STR(OPTION_PROGSRC) = (char*)"progs.src";
+ OPTS_OPTION_STR(OPTION_PROGSRC) = "progs.src";
/* warnings */
opts_set(opts.warn, WARN_UNUSED_VARIABLE, true);
void opts_init(const char *output, int standard, size_t arraysize) {
opts_setdefault();
- OPTS_OPTION_STR(OPTION_OUTPUT) = (char*)output;
+ OPTS_OPTION_STR(OPTION_OUTPUT) = output;
OPTS_OPTION_U32(OPTION_STANDARD) = standard;
OPTS_OPTION_U32(OPTION_MAX_ARRAY_SIZE) = arraysize;
OPTS_OPTION_U16(OPTION_MEMDUMPCOLS) = 16;