+ else
+ {
+ /* it's a QC filename */
+ item.filename = argv[0];
+ item.type = TYPE_QC;
+ vec_push(items, item);
+ }
+ }
+ return true;
+}
+
+/* returns the line number, or -1 on error */
+static bool progs_nextline(char **out, size_t *alen,FILE *src) {
+ int len;
+ char *line;
+ char *start;
+ char *end;
+
+ line = *out;
+ len = util_getline(&line, alen, src);
+ if (len == -1)
+ return false;
+
+ /* start at first non-blank */
+ for (start = line; isspace(*start); ++start) {}
+ /* end at the first non-blank */
+ for (end = start; *end && !isspace(*end); ++end) {}
+
+ *out = line;
+ /* move the actual filename to the beginning */
+ while (start != end) {
+ *line++ = *start++;
+ }
+ *line = 0;
+ return true;
+}
+
+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;
+ FILE *outfile = NULL;
+
+ app_name = argv[0];
+ con_init();
+
+ /* default options / warn flags */
+ options_set(opts_warn, WARN_UNKNOWN_CONTROL_SEQUENCE, true);
+ options_set(opts_warn, WARN_EXTENSIONS, true);
+ options_set(opts_warn, WARN_FIELD_REDECLARED, true);
+ options_set(opts_warn, WARN_TOO_FEW_PARAMETERS, true);
+ options_set(opts_warn, WARN_MISSING_RETURN_VALUES, true);
+ options_set(opts_warn, WARN_USED_UNINITIALIZED, true);
+ options_set(opts_warn, WARN_LOCAL_CONSTANTS, true);
+ options_set(opts_warn, WARN_VOID_VARIABLES, true);
+ options_set(opts_warn, WARN_IMPLICIT_FUNCTION_POINTER, true);
+ options_set(opts_warn, WARN_VARIADIC_FUNCTION, true);
+ options_set(opts_warn, WARN_FRAME_MACROS, true);
+ options_set(opts_warn, WARN_UNUSED_VARIABLE, true);
+ options_set(opts_warn, WARN_EFFECTLESS_STATEMENT, true);
+ options_set(opts_warn, WARN_END_SYS_FIELDS, true);
+ options_set(opts_warn, WARN_ASSIGN_FUNCTION_TYPES, true);
+ options_set(opts_warn, WARN_PREPROCESSOR, true);
+ options_set(opts_warn, WARN_MULTIFILE_IF, true);
+ options_set(opts_warn, WARN_DOUBLE_DECLARATION, true);
+ options_set(opts_warn, WARN_CONST_VAR, true);
+ options_set(opts_warn, WARN_MULTIBYTE_CHARACTER, true);
+
+ options_set(opts_flags, ADJUST_VECTOR_FIELDS, true);
+ options_set(opts_flags, FTEPP, false);
+ options_set(opts_flags, CORRECT_TERNARY, true);
+
+ if (!options_parse(argc, argv)) {
+ return usage();
+ }
+
+ /* the standard decides which set of operators to use */
+ if (opts_standard == COMPILER_GMQCC) {
+ operators = c_operators;
+ operator_count = c_operator_count;
+ } else if (opts_standard == COMPILER_FTEQCC) {
+ operators = fte_operators;
+ operator_count = fte_operator_count;
+ } else {
+ operators = qcc_operators;
+ operator_count = qcc_operator_count;
+ }
+
+ if (operators == fte_operators) {
+ /* fix ternary? */
+ if (OPTS_FLAG(CORRECT_TERNARY)) {
+ oper_info *newops;
+ if (operators[operator_count-2].id != opid1(',') ||
+ operators[operator_count-1].id != opid2(':','?'))
+ {
+ con_err("internal error: operator precedence table wasn't updated correctly!\n");
+ exit(1);
+ }
+ operators_free = true;
+ newops = mem_a(sizeof(operators[0]) * operator_count);
+ memcpy(newops, operators, sizeof(operators[0]) * operator_count);
+ memcpy(&newops[operator_count-2], &operators[operator_count-1], sizeof(newops[0]));
+ memcpy(&newops[operator_count-1], &operators[operator_count-2], sizeof(newops[0]));
+ newops[operator_count-2].prec = newops[operator_count-1].prec+1;
+ operators = newops;
+ }
+ }
+
+ if (opts_dump) {
+ for (itr = 0; itr < COUNT_FLAGS; ++itr) {
+ con_out("Flag %s = %i\n", opts_flag_list[itr].name, OPTS_FLAG(itr));
+ }
+ for (itr = 0; itr < COUNT_WARNINGS; ++itr) {
+ con_out("Warning %s = %i\n", opts_warn_list[itr].name, OPTS_WARN(itr));
+ }
+ con_out("output = %s\n", opts_output);
+ con_out("optimization level = %i\n", (int)opts_O);
+ con_out("standard = %i\n", opts_standard);
+ }
+
+ if (opts_pp_only) {
+ if (opts_output_wasset) {
+ outfile = util_fopen(opts_output, "wb");
+ if (!outfile) {
+ con_err("failed to open `%s` for writing\n", opts_output);
+ retval = 1;
+ goto cleanup;
+ }
+ }
+ else
+ outfile = stdout;