aboutsummaryrefslogtreecommitdiffstats
path: root/ui/gtk/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'ui/gtk/main.c')
-rw-r--r--ui/gtk/main.c134
1 files changed, 82 insertions, 52 deletions
diff --git a/ui/gtk/main.c b/ui/gtk/main.c
index 17785d6fc8..a7c53c3e2a 100644
--- a/ui/gtk/main.c
+++ b/ui/gtk/main.c
@@ -40,6 +40,10 @@
#include <unistd.h>
#endif
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#endif
+
#ifndef HAVE_GETOPT_LONG
#include "wsutil/wsgetopt.h"
#endif
@@ -2160,14 +2164,21 @@ main(int argc, char *argv[])
guint go_to_packet = 0;
search_direction jump_backwards = SD_FORWARD;
dfilter_t *jump_to_filter = NULL;
- int optind_initial;
unsigned int in_file_type = WTAP_TYPE_AUTO;
#ifdef HAVE_GTKOSXAPPLICATION
GtkosxApplication *theApp;
#endif
#define OPTSTRING OPTSTRING_CAPTURE_COMMON "C:g:Hh" "jJ:kK:lm:nN:o:P:r:R:St:u:vw:X:Y:z:"
-
+ static const struct option long_options[] = {
+ {(char *)"help", no_argument, NULL, 'h'},
+ {(char *)"read-file", required_argument, NULL, 'r' },
+ {(char *)"read-filter", required_argument, NULL, 'R' },
+ {(char *)"display-filter", required_argument, NULL, 'Y' },
+ {(char *)"version", no_argument, NULL, 'v'},
+ LONGOPT_CAPTURE_COMMON
+ {0, 0, 0, 0 }
+ };
static const char optstring[] = OPTSTRING;
cmdarg_err_init(wireshark_cmdarg_err, wireshark_cmdarg_err_cont);
@@ -2281,20 +2292,41 @@ main(int argc, char *argv[])
rf_path, g_strerror(rf_open_errno));
}
- /* "pre-scan" the command line parameters, if we have "console only"
- parameters. We do this so we don't start GTK+ if we're only showing
- command-line help or version information.
-
- XXX - this pre-scan is done before we start GTK+, so we haven't
- run gtk_init() on the arguments. That means that GTK+ arguments
- have not been removed from the argument list; those arguments
- begin with "--", and will be treated as an error by getopt().
-
- We thus ignore errors - *and* set "opterr" to 0 to suppress the
- error messages. */
+ /*
+ * In order to have the -X opts assigned before the wslua machine starts
+ * we need to call getopt_long before epan_init() gets called.
+ *
+ * In addition, we process "console only" parameters (ones where we
+ * send output to the console and exit) here, so we don't start GTK+
+ * if we're only showing command-line help or version information.
+ *
+ * XXX - this pre-scan is done before we start GTK+, so we haven't
+ * run gtk_init() on the arguments. That means that GTK+ arguments
+ * have not been removed from the argument list; those arguments
+ * begin with "--", and will be treated as an error by getopt_long().
+ *
+ * We thus ignore errors - *and* set "opterr" to 0 to suppress the
+ * error messages.
+ *
+ * XXX - should we, instead, first call gtk_parse_args(), without
+ * calling gtk_init(), and then call this?
+ *
+ * In order to handle, for example, -o options, we also need to call it
+ * *after* epan_init() gets called, so that the dissectors have had a
+ * chance to register their preferences, so we have another getopt_long()
+ * call later.
+ *
+ * XXX - can we do this all with one getopt_long() call, saving the
+ * arguments we can't handle until after initializing libwireshark,
+ * and then process them after initializing libwireshark?
+ *
+ * Note that we don't want to initialize libwireshark until after the
+ * GUI is up, as that can take a while, and we want a window of some
+ * sort up to show progress while that's happening.
+ */
opterr = 0;
- optind_initial = optind;
- while ((opt = getopt(argc, argv, optstring)) != -1) {
+
+ while ((opt = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) {
switch (opt) {
case 'C': /* Configuration Profile */
if (profile_exists (optarg, FALSE)) {
@@ -2390,42 +2422,6 @@ main(int argc, char *argv[])
set_last_open_dir(get_persdatafile_dir());
}
- /* Set getopt index back to initial value, so it will start with the
- first command line parameter again. Also reset opterr to 1, so that
- error messages are printed by getopt().
-
- XXX - this seems to work on most platforms, but time will tell.
- The Single UNIX Specification says "The getopt() function need
- not be reentrant", so this isn't guaranteed to work. The Mac
- OS X 10.4[.x] getopt() man page says
-
- In order to use getopt() to evaluate multiple sets of arguments, or to
- evaluate a single set of arguments multiple times, the variable optreset
- must be set to 1 before the second and each additional set of calls to
- getopt(), and the variable optind must be reinitialized.
-
- ...
-
- The optreset variable was added to make it possible to call the getopt()
- function multiple times. This is an extension to the IEEE Std 1003.2
- (``POSIX.2'') specification.
-
- which I think comes from one of the other BSDs.
-
- XXX - if we want to control all the command-line option errors, so
- that we can display them where we choose (e.g., in a window), we'd
- want to leave opterr as 0, and produce our own messages using optopt.
- We'd have to check the value of optopt to see if it's a valid option
- letter, in which case *presumably* the error is "this option requires
- an argument but none was specified", or not a valid option letter,
- in which case *presumably* the error is "this option isn't valid".
- Some versions of getopt() let you supply a option string beginning
- with ':', which means that getopt() will return ':' rather than '?'
- for "this option requires an argument but none was specified", but
- not all do. */
- optind = optind_initial;
- opterr = 1;
-
#if !GLIB_CHECK_VERSION(2,31,0)
g_thread_init(NULL);
#endif
@@ -2546,8 +2542,42 @@ main(int argc, char *argv[])
/*#ifdef HAVE_LIBPCAP
fill_in_local_interfaces();
#endif*/
+ /*
+ * To reset the options parser, set optreset to 1 on platforms that
+ * have optreset (documented in *BSD and OS X, apparently present but
+ * not documented in Solaris - the Illumos repository seems to
+ * suggest that the first Solaris getopt_long(), at least as of 2004,
+ * was based on the NetBSD one, it had optreset) and set optind to 1,
+ * and set optind to 0 otherwise (documented as working in the GNU
+ * getopt_long(). Setting optind to 0 didn't originally work in the
+ * NetBSD one, but that was added later - we don't want to depend on
+ * it if we have optreset).
+ *
+ * Also reset opterr to 1, so that error messages are printed by
+ * getopt_long().
+ *
+ * XXX - if we want to control all the command-line option errors, so
+ * that we can display them where we choose (e.g., in a window), we'd
+ * want to leave opterr as 0, and produce our own messages using optopt.
+ * We'd have to check the value of optopt to see if it's a valid option
+ * letter, in which case *presumably* the error is "this option requires
+ * an argument but none was specified", or not a valid option letter,
+ * in which case *presumably* the error is "this option isn't valid".
+ * Some versions of getopt() let you supply a option string beginning
+ * with ':', which means that getopt() will return ':' rather than '?'
+ * for "this option requires an argument but none was specified", but
+ * not all do. But we're now using getopt_long() - what does it do?
+ */
+#ifdef HAVE_OPTRESET
+ optreset = 1;
+ optind = 1;
+#else
+ optind = 0;
+#endif
+ opterr = 1;
+
/* Now get our args */
- while ((opt = getopt(argc, argv, optstring)) != -1) {
+ while ((opt = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) {
switch (opt) {
/*** capture option specific ***/
case 'a': /* autostop criteria */