Add command-line arg for input file format for tshark/wireshark
[metze/wireshark/wip.git] / ui / gtk / main.c
index 48a7d230a363875cc925d324fc7074d8f577316d..b351d5d497cae214fb0618d330e742f33cf26ea2 100644 (file)
@@ -1,6 +1,4 @@
 /* main.c
- *
- * $Id$
  *
  * Wireshark - Network traffic analyzer
  * By Gerald Combs <gerald@wireshark.org>
 #endif
 
 #ifdef _WIN32 /* Needed for console I/O */
-#if _MSC_VER < 1500
-/* AttachConsole() needs this #define! */
-/* But we're not calling it from here any more; do we need this? */
-#define _WIN32_WINNT 0x0501
-#endif
 
 #include <fcntl.h>
 #include <conio.h>
@@ -1168,7 +1161,7 @@ print_usage(gboolean print_ver) {
             "See http://www.wireshark.org for more information.\n"
             "\n"
             "%s",
-            wireshark_svnversion, get_copyright_info());
+            wireshark_gitversion, get_copyright_info());
     } else {
         output = stderr;
     }
@@ -1265,7 +1258,7 @@ show_version(void)
            "%s"
            "\n"
            "%s",
-        wireshark_svnversion, get_copyright_info(), comp_info_str->str,
+        wireshark_gitversion, get_copyright_info(), comp_info_str->str,
         runtime_info_str->str);
 }
 
@@ -1940,8 +1933,8 @@ get_gui_compiled_info(GString *str)
     g_string_append(str, ", ");
 #ifdef HAVE_AIRPCAP
     get_compiled_airpcap_version(str);
-#e  lse
-  g_string_append(str, "without AirPcap");
+#else
+    g_string_append(str, "without AirPcap");
 #endif
 }
 
@@ -2156,6 +2149,7 @@ main(int argc, char *argv[])
     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
@@ -2275,7 +2269,7 @@ main(int argc, char *argv[])
         "%s"
         "\n"
         "%s",
-        wireshark_svnversion, comp_info_str->str, runtime_info_str->str);
+        wireshark_gitversion, comp_info_str->str, runtime_info_str->str);
 
     /* Start windows sockets */
     WSAStartup( MAKEWORD( 1, 1 ), &wsaData );
@@ -2385,26 +2379,26 @@ main(int argc, char *argv[])
         }
     }
 
-  /* Init the "Open file" dialog directory */
-  /* (do this after the path settings are processed) */
+    /* Init the "Open file" dialog directory */
+    /* (do this after the path settings are processed) */
 
-  /* Read the profile dependent (static part) of the recent file. */
-  /* Only the static part of it will be read, as we don't have the gui now to fill the */
-  /* recent lists which is done in the dynamic part. */
-  /* We have to do this already here, so command line parameters can overwrite these values. */
-  recent_read_profile_static(&rf_path, &rf_open_errno);
-  if (rf_path != NULL && rf_open_errno != 0) {
-    simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
-                  "Could not open recent file\n\"%s\": %s.",
-                  rf_path, g_strerror(rf_open_errno));
-  }
+    /* Read the profile dependent (static part) of the recent file. */
+    /* Only the static part of it will be read, as we don't have the gui now to fill the */
+    /* recent lists which is done in the dynamic part. */
+    /* We have to do this already here, so command line parameters can overwrite these values. */
+    recent_read_profile_static(&rf_path, &rf_open_errno);
+    if (rf_path != NULL && rf_open_errno != 0) {
+        simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
+                      "Could not open recent file\n\"%s\": %s.",
+                      rf_path, g_strerror(rf_open_errno));
+    }
 
-  if (recent.gui_fileopen_remembered_dir &&
-      test_for_directory(recent.gui_fileopen_remembered_dir) == EISDIR) {
-    set_last_open_dir(recent.gui_fileopen_remembered_dir);
-  } else {
-    set_last_open_dir(get_persdatafile_dir());
-  }
+    if (recent.gui_fileopen_remembered_dir &&
+        test_for_directory(recent.gui_fileopen_remembered_dir) == EISDIR) {
+        set_last_open_dir(recent.gui_fileopen_remembered_dir);
+    } else {
+        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
@@ -2528,6 +2522,8 @@ main(int argc, char *argv[])
         g_free(init_progfile_dir_error);
     }
 
+    init_open_routines();
+
 #ifdef HAVE_PLUGINS
     /* Register all the plugin types we have. */
     epan_register_plugin_types(); /* Types known to libwireshark */
@@ -2573,7 +2569,7 @@ main(int argc, char *argv[])
 
     prefs_p = read_configuration_files (&gdp_path, &dp_path);
     /* Removed thread code:
-     * http://anonsvn.wireshark.org/viewvc/viewvc.cgi?view=rev&revision=35027
+     * https://code.wireshark.org/review/gitweb?p=wireshark.git;a=commit;h=9e277ae6154fd04bf6a0a34ec5655a73e5a736a3
      */
 
     /* this is to keep tap extensions updating once every 3 seconds */
@@ -3092,8 +3088,11 @@ main(int argc, char *argv[])
                 rfilter_parse_failed = TRUE;
             }
         }
+        if (ex_opt_count("read_format") > 0) {
+            in_file_type = open_info_name_to_type(ex_opt_get_next("read_format"));
+        }
         if (!rfilter_parse_failed) {
-            if (cf_open(&cfile, cf_name, FALSE, &err) == CF_OK) {
+            if (cf_open(&cfile, cf_name, in_file_type, FALSE, &err) == CF_OK) {
                 /* "cf_open()" succeeded, so it closed the previous
                  capture file, and thus destroyed any previous read filter
                  attached to "cf". */
@@ -3686,10 +3685,10 @@ top_level_key_pressed_cb(GtkWidget *w _U_, GdkEventKey *event, gpointer user_dat
     /*
      * A comment in gdkkeysyms.h says that it's autogenerated from
      * freedesktop.org/x.org's keysymdef.h.  Although the GDK docs
-     * don't explicitly say so, isprint() should work as expected
+     * don't explicitly say so, g_ascii_isprint() should work as expected
      * for values < 127.
      */
-    } else if (isascii(event->keyval) && isprint(event->keyval)) {
+    } else if (event->keyval < 256 && g_ascii_isprint(event->keyval)) {
         /* Forward the keypress on to the display filter entry */
         if (main_display_filter_widget && !gtk_widget_is_focus(main_display_filter_widget)) {
             gtk_window_set_focus(GTK_WINDOW(top_level), main_display_filter_widget);