/*===================================================================*/
/* list of -f flags, like -fdarkplaces-string-table-bug */
enum {
- OVERLAP_LOCALS,
- DP_STRING_TABLE_BUG,
- OMIT_NULLBYTES,
-
- NUM_F_FLAGS
+# define GMQCC_DEFINE_FLAG(X) X,
+# include "flags.def"
+# undef GMQCC_DEFINE_FLAG
+ COUNT_FLAGS
};
static const opt_flag_def opt_flag_list[] = {
- { "overlap-locals", LONGBIT(OVERLAP_LOCALS) },
- { "darkplaces-string-table-bug", LONGBIT(DP_STRING_TABLE_BUG) },
- { "omit-nullbytes", LONGBIT(OMIT_NULLBYTES) }
+# define GMQCC_DEFINE_FLAG(X) { #X, LONGBIT(X) },
+# include "flags.def"
+# undef GMQCC_DEFINE_FLAG
+ { NULL, LONGBIT(0) }
};
-static const size_t opt_flag_list_count = sizeof(opt_flag_list) / sizeof(opt_flag_list[0]);
enum {
- WARN_UNUSED_VARIABLE,
-
- NUM_W_FLAGS
+# define GMQCC_DEFINE_FLAG(X) X,
+# include "warns.def"
+# undef GMQCC_DEFINE_FLAG
+ COUNT_WARNINGS
};
static const opt_flag_def opt_warn_list[] = {
- /* only contains single flags, no groups like 'all' */
- { "unused-variable", LONGBIT(WARN_UNUSED_VARIABLE) }
+# define GMQCC_DEFINE_FLAG(X) { #X, LONGBIT(X) },
+# include "warns.def"
+# undef GMQCC_DEFINE_FLAG
+ { NULL, LONGBIT(0) }
};
-static const size_t opt_warn_list_count = sizeof(opt_warn_list) / sizeof(opt_warn_list[0]);
/* other options: */
extern uint32_t opt_O; /* -Ox */
/*===================================================================*/
#define OPT_FLAG(i) (!! (opt_flags[(i)/32] & (1<< ((i)%32))))
-extern uint32_t opt_flags[1 + (NUM_F_FLAGS / 32)];
+extern uint32_t opt_flags[1 + (COUNT_FLAGS / 32)];
#define OPT_WARN(i) (!! (opt_warn[(i)/32] & (1<< ((i)%32))))
-extern uint32_t opt_warn[1 + (NUM_W_FLAGS / 32)];
+extern uint32_t opt_warn[1 + (COUNT_WARNINGS / 32)];
#endif
*/
#include "gmqcc.h"
-uint32_t opt_flags[1 + (NUM_F_FLAGS / 32)];
-uint32_t opt_warn [1 + (NUM_W_FLAGS / 32)];
+uint32_t opt_flags[1 + (COUNT_FLAGS / 32)];
+uint32_t opt_warn [1 + (COUNT_WARNINGS / 32)];
uint32_t opt_O = 1;
const char *opt_output = "progs.dat";
return -1;
}
+static void strtocmd(char *str)
+{
+ for(; *str; ++str) {
+ if (*str == '-') {
+ *str = '_';
+ continue;
+ }
+ if (isalpha(*str) && !isupper(*str)) {
+ *str += 'A' - 'a';
+ continue;
+ }
+ }
+}
+
+static void strtononcmd(char *buf, const char *str)
+{
+ for(; *str; ++buf, ++str) {
+ if (*str == '_') {
+ *buf = '-';
+ continue;
+ }
+ if (isalpha(*str) && isupper(*str)) {
+ *buf = *str + 'a' - 'A';
+ continue;
+ }
+ *buf = *str;
+ }
+ *buf = 0;
+}
+
static bool options_setflag_all(const char *name, bool on, uint32_t *flags, const opt_flag_def *list, size_t listsize) {
size_t i;
return false;
}
static bool options_setflag(const char *name, bool on) {
- return options_setflag_all(name, on, opt_flags, opt_flag_list, opt_flag_list_count);
+ return options_setflag_all(name, on, opt_flags, opt_flag_list, COUNT_FLAGS);
}
static bool options_setwarn(const char *name, bool on) {
- return options_setflag_all(name, on, opt_warn, opt_warn_list, opt_warn_list_count);
+ return options_setflag_all(name, on, opt_warn, opt_warn_list, COUNT_WARNINGS);
}
static bool options_witharg(int *argc_, char ***argv_, char **out) {
static bool options_parse(int argc, char **argv) {
bool argend = false;
size_t itr;
+ char buffer[1024];
while (!argend && argc > 1) {
char *argarg;
argitem item;
/* handle all -fflags */
case 'f':
- if (!strcmp(argv[0]+2, "help")) {
+ strtocmd(argv[0]+2);
+ if (!strcmp(argv[0]+2, "HELP")) {
printf("Possible flags:\n");
- for (itr = 0; itr < opt_flag_list_count; ++itr)
- printf(" -f%s\n", opt_flag_list[itr].name);
+ for (itr = 0; itr < COUNT_FLAGS; ++itr) {
+ strtononcmd(buffer, opt_flag_list[itr].name);
+ printf(" -f%s\n", buffer);
+ }
exit(0);
}
- else if (!strncmp(argv[0]+2, "no-", 3)) {
+ else if (!strncmp(argv[0]+2, "NO-", 3)) {
if (!options_setflag(argv[0]+5, false)) {
printf("unknown flag: %s\n", argv[0]+2);
return false;
}
break;
case 'W':
- if (!strcmp(argv[0]+2, "help")) {
+ strtocmd(argv[0]+2);
+ if (!strcmp(argv[0]+2, "HELP")) {
printf("Possible warnings:\n");
- for (itr = 0; itr < opt_warn_list_count; ++itr)
- printf(" -W%s\n", opt_warn_list[itr].name);
+ for (itr = 0; itr < COUNT_WARNINGS; ++itr) {
+ strtononcmd(buffer, opt_warn_list[itr].name);
+ printf(" -W%s\n", buffer);
+ }
exit(0);
}
else if (!strcmp(argv[0]+2, "all")) {
return usage();
}
- for (itr = 0; itr < opt_flag_list_count; ++itr) {
+ for (itr = 0; itr < COUNT_FLAGS; ++itr) {
printf("Flag %s = %i\n", opt_flag_list[itr].name, OPT_FLAG(itr));
}
- for (itr = 0; itr < opt_warn_list_count; ++itr) {
+ for (itr = 0; itr < COUNT_WARNINGS; ++itr) {
printf("Warning %s = %i\n", opt_warn_list[itr].name, OPT_WARN(itr));
}
printf("output = %s\n", opt_output);