From 43ffd6fe11aa85ff966e43ce1bdbe655104daed3 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Tue, 3 May 2016 16:34:19 -0700 Subject: [PATCH] Fix the warnings about the unused array of option names --- main.cpp | 58 ++++++++++++++++++++++++----------------------------- options.hpp | 20 ------------------ 2 files changed, 26 insertions(+), 52 deletions(-) diff --git a/main.cpp b/main.cpp index cea972f..efdaf31 100644 --- a/main.cpp +++ b/main.cpp @@ -1689,16 +1689,14 @@ int read_input(std::vector &sources, char *fname, const char *layername, return ret; } -static int int_in(int v, int *a, int len) { - int i; - - for (i = 0; i < len; i++) { - if (a[i] == v) { - return 1; +static bool has_name(struct option *long_options, int *pl) { + for (size_t lo = 0; long_options[lo].name != NULL; lo++) { + if (long_options[lo].flag == pl) { + return true; } } - return 0; + return false; } int main(int argc, char **argv) { @@ -1738,28 +1736,6 @@ int main(int argc, char **argv) { additional[i] = 0; } - { - char dup[256]; - - memset(dup, 0, sizeof(dup)); - for (i = 0; i < sizeof(additional_options) / sizeof(additional_options[0]); i++) { - if (dup[additional_options[i]]) { - fprintf(stderr, "Internal error: reused -a%c\n", additional_options[i]); - exit(EXIT_FAILURE); - } - dup[additional_options[i]] = 1; - } - - memset(dup, 0, sizeof(dup)); - for (i = 0; i < sizeof(prevent_options) / sizeof(prevent_options[0]); i++) { - if (dup[prevent_options[i]]) { - fprintf(stderr, "Internal error: reused -p%c\n", prevent_options[i]); - exit(EXIT_FAILURE); - } - dup[prevent_options[i]] = 1; - } - } - static struct option long_options[] = { {"output", required_argument, 0, 'o'}, @@ -1810,6 +1786,24 @@ int main(int argc, char **argv) { {0, 0, 0, 0}, }; + { + for (size_t lo = 0; long_options[lo].name != NULL; lo++) { + if (long_options[lo].flag != NULL) { + if (*long_options[lo].flag != 0) { + fprintf(stderr, "Internal error: reused %s\n", long_options[lo].name); + exit(EXIT_FAILURE); + } + *long_options[lo].flag = 1; + } + } + + for (size_t lo = 0; long_options[lo].name != NULL; lo++) { + if (long_options[lo].flag != NULL) { + *long_options[lo].flag = 0; + } + } + } + while ((i = getopt_long(argc, argv, "n:l:z:Z:B:d:D:m:o:x:y:r:b:t:g:p:a:XfFqvPL:A:", long_options, NULL)) != -1) { switch (i) { case 0: @@ -1948,7 +1942,7 @@ int main(int argc, char **argv) { case 'p': { char *cp; for (cp = optarg; *cp != '\0'; cp++) { - if (int_in(*cp, prevent_options, sizeof(prevent_options) / sizeof(prevent_options[0]))) { + if (has_name(long_options, &prevent[*cp & 0xFF])) { prevent[*cp & 0xFF] = 1; } else { fprintf(stderr, "%s: Unknown option -p%c\n", argv[0], *cp); @@ -1960,7 +1954,7 @@ int main(int argc, char **argv) { case 'a': { char *cp; for (cp = optarg; *cp != '\0'; cp++) { - if (int_in(*cp, additional_options, sizeof(additional_options) / sizeof(additional_options[0]))) { + if (has_name(long_options, &additional[*cp & 0xFF])) { additional[*cp & 0xFF] = 1; } else { fprintf(stderr, "%s: Unknown option -a%c\n", argv[0], *cp); @@ -1980,7 +1974,7 @@ int main(int argc, char **argv) { default: { int width = 7 + strlen(argv[0]); fprintf(stderr, "Usage: %s", argv[0]); - for (int lo = 0; long_options[lo].name != NULL; lo++) { + for (size_t lo = 0; long_options[lo].name != NULL; lo++) { if (width + strlen(long_options[lo].name) + 9 >= 80) { fprintf(stderr, "\n "); width = 8; diff --git a/options.hpp b/options.hpp index 8e7d130..3928af5 100644 --- a/options.hpp +++ b/options.hpp @@ -1,37 +1,17 @@ -static int additional_options[] = { #define A_COALESCE ((int) 'c') - A_COALESCE, #define A_REVERSE ((int) 'r') - A_REVERSE, #define A_REORDER ((int) 'o') - A_REORDER, #define A_LINE_DROP ((int) 'l') - A_LINE_DROP, #define A_DEBUG_POLYGON ((int) 'd') - A_DEBUG_POLYGON, #define A_POLYGON_DROP ((int) 'p') - A_POLYGON_DROP, #define A_PREFER_RADIX_SORT ((int) 'R') - A_PREFER_RADIX_SORT, -}; -static int prevent_options[] = { #define P_SIMPLIFY ((int) 's') - P_SIMPLIFY, #define P_SIMPLIFY_LOW ((int) 'S') - P_SIMPLIFY_LOW, #define P_FEATURE_LIMIT ((int) 'f') - P_FEATURE_LIMIT, #define P_KILOBYTE_LIMIT ((int) 'k') - P_KILOBYTE_LIMIT, #define P_DYNAMIC_DROP ((int) 'd') - P_DYNAMIC_DROP, #define P_INPUT_ORDER ((int) 'i') - P_INPUT_ORDER, #define P_POLYGON_SPLIT ((int) 'p') - P_POLYGON_SPLIT, #define P_CLIPPING ((int) 'c') - P_CLIPPING, #define P_DUPLICATION ((int) 'D') - P_DUPLICATION, -};