]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Make config_parse_commandline table-driven for its list of cmdline args
authorNick Mathewson <nickm@torproject.org>
Sun, 25 Aug 2013 17:07:31 +0000 (13:07 -0400)
committerNick Mathewson <nickm@torproject.org>
Fri, 13 Sep 2013 16:36:40 +0000 (12:36 -0400)
src/or/config.c

index e6adcc494410a44cbaa862c5ad2d9643cdbf0806..cda769db8c1bfcc48bbfd6b32bba6a04d5ab3bd0 100644 (file)
@@ -1791,6 +1791,28 @@ options_act(const or_options_t *old_options)
   return 0;
 }
 
+static const struct {
+  const char *name;
+  int takes_argument;
+} CMDLINE_ONLY_OPTIONS[] = {
+  { "-f",                     1 },
+  { "--defaults-torrc",       1 },
+  { "--hash-password",        1 },
+  { "--list-fingerprint",     0 },
+  { "--verify-config",        0 },
+  { "--ignore-missing-torrc", 0 },
+  { "--quiet",                0 },
+  { "--hush",                 0 },
+  { "--version",              0 },
+  { "-h",                     0 },
+  { "--help",                 0 },
+  { "--list-torrc-options",   0 },
+  { "--digests",              0 },
+  { "--nt-service",           0 },
+  { "-nt-service",            0 },
+  { NULL, 0 },
+};
+
 /** Helper: Read a list of configuration options from the command line.  If
  * successful, or if ignore_errors is set, put them in *<b>result</b>, put the
  * commandline-only options in *<b>cmdline_result</b>, and return 0;
@@ -1816,27 +1838,14 @@ config_parse_commandline(int argc, char **argv, int ignore_errors,
     unsigned command = CONFIG_LINE_NORMAL;
     int want_arg = 1;
     int is_cmdline = 0;
+    int j;
 
-    if (!strcmp(argv[i],"-f") ||
-        !strcmp(argv[i],"--defaults-torrc") ||
-        !strcmp(argv[i],"--hash-password")) {
-      is_cmdline = 1;
-    } else if (!strcmp(argv[i],"--list-fingerprint") ||
-               !strcmp(argv[i],"--verify-config") ||
-               !strcmp(argv[i],"--ignore-missing-torrc") ||
-               !strcmp(argv[i],"--quiet") ||
-               !strcmp(argv[i],"--hush") ||
-               !strcmp(argv[i],"--version") ||
-               !strcmp(argv[i],"-h") ||
-               !strcmp(argv[i],"--help") ||
-               !strcmp(argv[i],"--list-torrc-options") ||
-               !strcmp(argv[i],"--digests")) {
-      is_cmdline = 1;
-      want_arg = 0;
-    } else if (!strcmp(argv[i],"--nt-service") ||
-               !strcmp(argv[i],"-nt-service")) {
-      is_cmdline = 1;
-      want_arg = 0;
+    for (j = 0; CMDLINE_ONLY_OPTIONS[j].name != NULL; ++j) {
+      if (!strcmp(argv[i], CMDLINE_ONLY_OPTIONS[j].name)) {
+        is_cmdline = 1;
+        want_arg = CMDLINE_ONLY_OPTIONS[j].takes_argument;
+        break;
+      }
     }
 
     s = argv[i];