X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=blobdiff_plain;f=opts.c;h=12429a8ac3e637d7b499ed1c358af9aab917b9c1;hp=4d7d9a08debaed3e9fa9d96dac23e973d0b7d907;hb=459356a48dafe7c4b7c6c43a633484508abc7dcc;hpb=c3964cf29d0928b7c1decbd5a4d8dd38c3aff78a diff --git a/opts.c b/opts.c index 4d7d9a0..12429a8 100644 --- a/opts.c +++ b/opts.c @@ -1,7 +1,7 @@ /* - * Copyright (C) 2012 + * Copyright (C) 2012, 2013, 2014 * 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 @@ -21,13 +21,47 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ +#include +#include + #include "gmqcc.h" + +const unsigned int opts_opt_oflag[COUNT_OPTIMIZATIONS+1] = { +# define GMQCC_TYPE_OPTIMIZATIONS +# define GMQCC_DEFINE_FLAG(NAME, MIN_O) MIN_O, +# include "opts.def" + 0 +}; + +const opts_flag_def_t opts_opt_list[COUNT_OPTIMIZATIONS+1] = { +# define GMQCC_TYPE_OPTIMIZATIONS +# define GMQCC_DEFINE_FLAG(NAME, MIN_O) { #NAME, LONGBIT(OPTIM_##NAME) }, +# include "opts.def" + { NULL, LONGBIT(0) } +}; + +const opts_flag_def_t opts_warn_list[COUNT_WARNINGS+1] = { +# define GMQCC_TYPE_WARNS +# define GMQCC_DEFINE_FLAG(X) { #X, LONGBIT(WARN_##X) }, +# include "opts.def" + { NULL, LONGBIT(0) } +}; + +const opts_flag_def_t opts_flag_list[COUNT_FLAGS+1] = { +# define GMQCC_TYPE_FLAGS +# define GMQCC_DEFINE_FLAG(X) { #X, LONGBIT(X) }, +# include "opts.def" + { NULL, LONGBIT(0) } +}; + unsigned int opts_optimizationcount[COUNT_OPTIMIZATIONS]; -opts_cmd_t opts; /* command lien options */ +opts_cmd_t opts; /* command line options */ -static void opts_setdefault() { +static void opts_setdefault(void) { memset(&opts, 0, sizeof(opts_cmd_t)); - + OPTS_OPTION_BOOL(OPTION_CORRECTION) = true; + OPTS_OPTION_STR(OPTION_PROGSRC) = "progs.src"; + /* warnings */ opts_set(opts.warn, WARN_UNUSED_VARIABLE, true); opts_set(opts.warn, WARN_USED_UNINITIALIZED, true); @@ -35,8 +69,7 @@ static void opts_setdefault() { opts_set(opts.warn, WARN_EXTENSIONS, true); opts_set(opts.warn, WARN_FIELD_REDECLARED, true); opts_set(opts.warn, WARN_MISSING_RETURN_VALUES, true); - opts_set(opts.warn, WARN_TOO_FEW_PARAMETERS, true); - opts_set(opts.warn, WARN_LOCAL_SHADOWS, false); + opts_set(opts.warn, WARN_INVALID_PARAMETER_COUNT, true); 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,46 +78,79 @@ 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_DEPRECATED, true); + opts_set(opts.warn, WARN_PARENTHESIS, true); + opts_set(opts.warn, WARN_CONST_OVERWRITE, true); + opts_set(opts.warn, WARN_DIRECTIVE_INMACRO, true); + opts_set(opts.warn, WARN_BUILTINS, true); + opts_set(opts.warn, WARN_INEXACT_COMPARES, true); + /* flags */ opts_set(opts.flags, ADJUST_VECTOR_FIELDS, true); - opts_set(opts.flags, FTEPP, false); opts_set(opts.flags, CORRECT_TERNARY, true); + opts_set(opts.flags, BAIL_ON_WERROR, true); + opts_set(opts.flags, LEGACY_VECTOR_MATHS, true); + opts_set(opts.flags, DARKPLACES_STRING_TABLE_BUG, true); + + /* options */ + OPTS_OPTION_U32(OPTION_STATE_FPS) = 10; +} + +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) = 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) { +static bool opts_setflag_all(const char *name, bool on, uint32_t *flags, const opts_flag_def_t *list, size_t listsize) { size_t i; for (i = 0; i < listsize; ++i) { if (!strcmp(name, list[i].name)) { longbit lb = list[i].bit; -#if 0 + 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; } /* @@ -133,13 +197,13 @@ void opts_setoptimlevel(unsigned int level) { */ static char *opts_ini_rstrip(char *s) { char *p = s + strlen(s); - while(p > s && isspace(*--p)) + while(p > s && util_isspace(*--p)) *p = '\0'; return s; } static char *opts_ini_lskip(const char *s) { - while (*s && isspace(*s)) + while (*s && util_isspace(*s)) s++; return (char*)s; } @@ -147,13 +211,13 @@ static char *opts_ini_lskip(const char *s) { static char *opts_ini_next(const char *s, char c) { bool last = false; while (*s && *s != c && !(last && *s == ';')) - last = !!isspace(*s), s++; + last = !!util_isspace(*s), s++; return (char*)s; } static size_t opts_ini_parse ( - FILE *filehandle, + fs_file_t *filehandle, char *(*loadhandle)(const char *, const char *, const char *), char **errorhandle ) { @@ -170,7 +234,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) != FS_FILE_EOF) { parse_beg = line; /* handle BOM */ @@ -191,7 +255,7 @@ static size_t opts_ini_parse ( /* section found */ if (*(parse_end = opts_ini_next(parse_beg + 1, ']')) == ']') { * parse_end = '\0'; /* terminate bro */ - strncpy(section_data, parse_beg + 1, sizeof(section_data)); + util_strncpy(section_data, parse_beg + 1, sizeof(section_data)); section_data[sizeof(section_data) - 1] = '\0'; *oldname_data = '\0'; } else if (!error) { @@ -212,7 +276,7 @@ static size_t opts_ini_parse ( opts_ini_rstrip(read_value); /* valid name value pair, lets call down to handler */ - strncpy(oldname_data, read_name, sizeof(oldname_data)); + util_strncpy(oldname_data, read_name, sizeof(oldname_data)); oldname_data[sizeof(oldname_data) - 1] ='\0'; if ((*errorhandle = loadhandle(section_data, read_name, read_value)) && !error) @@ -234,7 +298,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) { @@ -244,7 +308,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 @@ -267,6 +331,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) \ @@ -282,16 +355,16 @@ static char *opts_ini_load(const char *section, const char *name, const char *va strcmp(section, "warnings") && strcmp(section, "optimizations")) { - vec_upload(error, "invalid section `", 17); - vec_upload(error, section, strlen(section)); + vec_append(error, 17, "invalid section `"); + vec_append(error, strlen(section), section); vec_push (error, '`'); vec_push (error, '\0'); } else { - vec_upload(error, "invalid variable `", 18); - vec_upload(error, name, strlen(name)); + vec_append(error, 18, "invalid variable `"); + vec_append(error, strlen(name), name); vec_push (error, '`'); - vec_upload(error, " in section: `", 14); - vec_upload(error, section, strlen(section)); + vec_append(error, 14, " in section: `"); + vec_append(error, strlen(section), section); vec_push (error, '`'); vec_push (error, '\0'); } @@ -309,27 +382,26 @@ void opts_ini_init(const char *file) { * gmqcc.ini * gmqcc.cfg */ - char *error; + char *error = NULL; size_t line; - FILE *ini; + fs_file_t *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); if ((line = opts_ini_parse(ini, &opts_ini_load, &error)) != 0) { /* there was a parse error with the ini file */ - con_printmsg(LVL_ERROR, file, line, "error", error); + con_printmsg(LVL_ERROR, file, line, 0 /*TODO: column for ini error*/, "error", error); vec_free(error); } - file_close(ini); -} + fs_file_close(ini); +}