X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=blobdiff_plain;f=opts.c;h=c2e019e28a9ff932bf060c93de7412de2050e832;hp=548381a3be634385b989803c63d8e46e0d2ca4fd;hb=160e7cf7eebd7fa173fb739aca00143097a3518b;hpb=7cc7e912e7f2ec3fd72349527e6558d7d6cfe747 diff --git a/opts.c b/opts.c index 548381a..c2e019e 100644 --- a/opts.c +++ b/opts.c @@ -1,7 +1,7 @@ /* * Copyright (C) 2012, 2013 * Wolfgang Bumiller - * Dale Weiler + * Dale Weiler * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -27,7 +27,8 @@ opts_cmd_t opts; /* command lien options */ static void opts_setdefault() { memset(&opts, 0, sizeof(opts_cmd_t)); - + OPTS_OPTION_BOOL(OPTION_CORRECTION) = true; + /* warnings */ opts_set(opts.warn, WARN_UNUSED_VARIABLE, true); opts_set(opts.warn, WARN_USED_UNINITIALIZED, true); @@ -36,7 +37,6 @@ static void opts_setdefault() { opts_set(opts.warn, WARN_FIELD_REDECLARED, true); opts_set(opts.warn, WARN_MISSING_RETURN_VALUES, true); opts_set(opts.warn, WARN_INVALID_PARAMETER_COUNT, true); - opts_set(opts.warn, WARN_LOCAL_SHADOWS, false); opts_set(opts.warn, WARN_LOCAL_CONSTANTS, true); opts_set(opts.warn, WARN_VOID_VARIABLES, true); opts_set(opts.warn, WARN_IMPLICIT_FUNCTION_POINTER, true); @@ -45,35 +45,59 @@ static void opts_setdefault() { opts_set(opts.warn, WARN_EFFECTLESS_STATEMENT, true); opts_set(opts.warn, WARN_END_SYS_FIELDS, true); opts_set(opts.warn, WARN_ASSIGN_FUNCTION_TYPES, true); - opts_set(opts.warn, WARN_PREPROCESSOR, true); + opts_set(opts.warn, WARN_CPP, true); opts_set(opts.warn, WARN_MULTIFILE_IF, true); opts_set(opts.warn, WARN_DOUBLE_DECLARATION, true); opts_set(opts.warn, WARN_CONST_VAR, true); opts_set(opts.warn, WARN_MULTIBYTE_CHARACTER, true); opts_set(opts.warn, WARN_UNKNOWN_PRAGMAS, true); opts_set(opts.warn, WARN_UNREACHABLE_CODE, true); - opts_set(opts.warn, WARN_CPP, true); opts_set(opts.warn, WARN_UNKNOWN_ATTRIBUTE, true); opts_set(opts.warn, WARN_RESERVED_NAMES, true); opts_set(opts.warn, WARN_UNINITIALIZED_CONSTANT, true); - opts_set(opts.warn, WARN_UNINITIALIZED_GLOBAL, false); opts_set(opts.warn, WARN_DEPRECATED, true); opts_set(opts.warn, WARN_PARENTHESIS, true); + /* flags */ opts_set(opts.flags, ADJUST_VECTOR_FIELDS, true); - opts_set(opts.flags, FTEPP, false); - opts_set(opts.flags, FTEPP_PREDEFS, false); opts_set(opts.flags, CORRECT_TERNARY, true); opts_set(opts.flags, BAIL_ON_WERROR, true); - opts_set(opts.flags, ENHANCED_DIAGNOSTICS, true); + opts_set(opts.flags, LEGACY_VECTOR_MATHS, true); + opts_set(opts.flags, DARKPLACES_STRING_TABLE_BUG, true); + +} + +void opts_backup_non_Wall() { + size_t i; + for (i = 0; i <= WARN_DEBUG; ++i) + opts_set(opts.warn_backup, i, OPTS_WARN(i)); +} + +void opts_restore_non_Wall() { + size_t i; + for (i = 0; i <= WARN_DEBUG; ++i) + opts_set(opts.warn, i, OPTS_GENERIC(opts.warn_backup, i)); +} + +void opts_backup_non_Werror_all() { + size_t i; + for (i = 0; i <= WARN_DEBUG; ++i) + opts_set(opts.werror_backup, i, OPTS_WERROR(i)); +} + +void opts_restore_non_Werror_all() { + size_t i; + for (i = 0; i <= WARN_DEBUG; ++i) + opts_set(opts.werror, i, OPTS_GENERIC(opts.werror_backup, i)); } void opts_init(const char *output, int standard, size_t arraysize) { opts_setdefault(); - - opts.output = output; - opts.standard = (opts_std_t)standard; /* C++ ... y u no like me? */ - opts.max_array_size = arraysize; + + OPTS_OPTION_STR(OPTION_OUTPUT) = (char*)output; + OPTS_OPTION_U32(OPTION_STANDARD) = standard; + OPTS_OPTION_U32(OPTION_MAX_ARRAY_SIZE) = arraysize; + OPTS_OPTION_U16(OPTION_MEMDUMPCOLS) = 16; } static bool opts_setflag_all(const char *name, bool on, uint32_t *flags, const opts_flag_def *list, size_t listsize) { @@ -82,17 +106,12 @@ static bool opts_setflag_all(const char *name, bool on, uint32_t *flags, const o for (i = 0; i < listsize; ++i) { if (!strcmp(name, list[i].name)) { longbit lb = list[i].bit; -#if 1 + if (on) flags[lb.idx] |= (1<<(lb.bit)); else flags[lb.idx] &= ~(1<<(lb.bit)); -#else - if (on) - flags[0] |= (1<= opts_opt_oflag[i]); + + if (!level) + opts.optimizeoff = true; } /* @@ -179,7 +195,7 @@ static size_t opts_ini_parse ( char *read_name; char *read_value; - while (file_getline(&line, &linesize, filehandle) != EOF) { + while (fs_file_getline(&line, &linesize, filehandle) != EOF) { parse_beg = line; /* handle BOM */ @@ -243,7 +259,7 @@ static size_t opts_ini_parse ( static bool opts_ini_bool(const char *value) { if (!strcmp(value, "true")) return true; if (!strcmp(value, "false")) return false; - return !!atoi(value); + return !!strtol(value, NULL, 10); } static char *opts_ini_load(const char *section, const char *name, const char *value) { @@ -253,7 +269,7 @@ static char *opts_ini_load(const char *section, const char *name, const char *va /* * undef all of these because they may still be defined like in my * case they where. - */ + */ #undef GMQCC_TYPE_FLAGS #undef GMQCC_TYPE_OPTIMIZATIONS #undef GMQCC_TYPE_WARNS @@ -276,6 +292,15 @@ static char *opts_ini_load(const char *section, const char *name, const char *va } #include "opts.def" + /* Werror-individuals */ + #define GMQCC_TYPE_WARNS + #define GMQCC_DEFINE_FLAG(X) \ + if (!strcmp(section, "errors") && !strcmp(name, #X)) { \ + opts_set(opts.werror, WARN_##X, opts_ini_bool(value)); \ + found = true; \ + } + #include "opts.def" + /* optimizations */ #define GMQCC_TYPE_OPTIMIZATIONS #define GMQCC_DEFINE_FLAG(X,Y) \ @@ -322,14 +347,14 @@ void opts_ini_init(const char *file) { size_t line; FILE *ini; - + if (!file) { /* try ini */ - if (!(ini = file_open((file = "gmqcc.ini"), "r"))) + if (!(ini = fs_file_open((file = "gmqcc.ini"), "r"))) /* try cfg */ - if (!(ini = file_open((file = "gmqcc.cfg"), "r"))) + if (!(ini = fs_file_open((file = "gmqcc.cfg"), "r"))) return; - } else if (!(ini = file_open(file, "r"))) + } else if (!(ini = fs_file_open(file, "r"))) return; con_out("found ini file `%s`\n", file); @@ -340,5 +365,5 @@ void opts_ini_init(const char *file) { vec_free(error); } - file_close(ini); -} + fs_file_close(ini); +}