Add --help and --version long options.
authorGuy Harris <guy@alum.mit.edu>
Fri, 20 Jun 2014 19:18:48 +0000 (12:18 -0700)
committerGuy Harris <guy@alum.mit.edu>
Fri, 20 Jun 2014 19:19:47 +0000 (19:19 +0000)
Also, make the convention for long-only options be that their
case-statement values start at 128, so they avoid colliding with any
ASCII code points, including control characters.

Make the tables of long options "static const" while we're at it, and
get rid of unnecessary casts.

Change-Id: I55702a85e9bc078b1cd0f2803ebb68a710405bab
Reviewed-on: https://code.wireshark.org/review/2491
Reviewed-by: Guy Harris <guy@alum.mit.edu>
capture_opts.h
dumpcap.c
tshark.c
ui/qt/main.cpp

index f9bdf89eb67aa95d48e52a0e53037c84f30e8885..a48635d68b3c1f40aac7e8b2d6ab1ef4bd9af16d 100644 (file)
 extern "C" {
 #endif /* __cplusplus */
 
-/* Attention:
-   for tshark, we're using a leading - in the optstring to prevent getopt()
-   from permuting the argv[] entries, in this case, unknown argv[] entries
-   will be returned as parameters to a dummy-option 1
-   in short: we must not use 1 here */
-
-/* this does not clash with tshark's -2 option which returns '2' */
-#define LONGOPT_NUM_CAP_COMMENT 2
+/*
+ * Long options.
+ * We do not currently have long options corresponding to all short
+ * options; we should probably pick appropriate option names for them.
+ *
+ * For long options with no corresponding short options, we define values
+ * outside the range of ASCII graphic characters, make that the last
+ * component of the entry for the long option, and have a case for that
+ * option in the switch statement.
+ *
+ * NOTE:
+ * for tshark, we're using a leading - in the optstring to prevent getopt()
+ * from permuting the argv[] entries, in this case, unknown argv[] entries
+ * will be returned as parameters to a dummy-option 1.
+ * In short: we must not use 1 here, which is another reason to use
+ * values outside the range of ASCII graphic characters.
+ */
+#define LONGOPT_NUM_CAP_COMMENT 128
 
+/*
+ * Non-capture long-only options should start here, to avoid collision
+ * with capture options.
+ */
+#define MIN_NON_CAPTURE_LONGOPT 129
 
 #ifdef HAVE_PCAP_REMOTE
 /* Type of capture source */
index 2ceed867a84d091cfe8064db05fd4a6e038da8d4..1a94d9fceb5aa2e9544d10c59a088fd9df7abfec 100644 (file)
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -4176,8 +4176,10 @@ main(int argc, char *argv[])
     GString          *comp_info_str;
     GString          *runtime_info_str;
     int               opt;
-    struct option     long_options[] = {
+    static const struct option long_options[] = {
         {(char *)"capture-comment", required_argument, NULL, LONGOPT_NUM_CAP_COMMENT },
+        {(char *)"help", no_argument, NULL, 'h'},
+        {(char *)"version", no_argument, NULL, 'v'},
         {0, 0, 0, 0 }
     };
 
@@ -4525,8 +4527,8 @@ main(int argc, char *argv[])
     global_capture_opts.saving_to_file      = TRUE;
     global_capture_opts.has_ring_num_files  = TRUE;
 
-       /* Pass on capture_child mode for capture_opts */
-       global_capture_opts.capture_child = capture_child;
+    /* Pass on capture_child mode for capture_opts */
+    global_capture_opts.capture_child = capture_child;
 
     /* Now get our args */
     while ((opt = getopt_long(argc, argv, OPTSTRING, long_options, NULL)) != -1) {
index 539792cd74c4ad6c4b9648240578caa6bd0e43be..c50d28a3536d68d8a7f0021b3d322ab86b6bd66f 100644 (file)
--- a/tshark.c
+++ b/tshark.c
@@ -922,8 +922,10 @@ main(int argc, char *argv[])
   GString             *runtime_info_str;
   char                *init_progfile_dir_error;
   int                  opt;
-  struct option     long_options[] = {
+  static const struct option long_options[] = {
     {(char *)"capture-comment", required_argument, NULL, LONGOPT_NUM_CAP_COMMENT },
+    {(char *)"help", no_argument, NULL, 'h'},
+    {(char *)"version", no_argument, NULL, 'v'},
     {0, 0, 0, 0 }
   };
   gboolean             arg_error = FALSE;
index 871d0e92a07bb3b883a25ba87b5facb8d61a633d..c91937e846dab368ae52835c6df71f3ca977fec6 100644 (file)
@@ -516,8 +516,10 @@ int main(int argc, char *argv[])
 #endif
 
 #define OPTSTRING "a:b:" OPTSTRING_B "c:C:Df:g:Hhi:" OPTSTRING_I "jJ:kK:lLm:nN:o:P:pQr:R:Ss:t:u:vw:X:y:z:"
-    struct option     long_options[] = {
-        {(char *)"read-file", required_argument, NULL, (int)'r' },
+    static const struct option long_options[] = {
+        {(char *)"help", no_argument, NULL, 'h'},
+        {(char *)"read-file", required_argument, NULL, 'r' },
+        {(char *)"version", no_argument, NULL, 'v'},
         {0, 0, 0, 0 }
     };
     static const char optstring[] = OPTSTRING;