Move the Windows argument list conversion code to a common routine.
authorgerald <gerald@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 24 May 2011 00:07:56 +0000 (00:07 +0000)
committergerald <gerald@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 24 May 2011 00:07:56 +0000 (00:07 +0000)
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@37372 f5534014-38df-0310-8fa8-9805f1628bb7

14 files changed:
Makefile.nmake
capinfos.c
dumpcap.c
editcap.c
gtk/main.c
mergecap.c
randpkt.c
rawshark.c
text2pcap.c
tshark.c
wsutil/Makefile.nmake
wsutil/libwsutil.def
wsutil/unicode-utils.c
wsutil/unicode-utils.h

index 06bc4704af7a8760921de03b91ed2cf0ce61ca61..cbc3522e4b6002de4f8f5235721104f45e1e574f 100644 (file)
@@ -93,7 +93,7 @@ wireshark_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \
 !ENDIF
 
 tshark_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \
-       wsock32.lib user32.lib shell32.lib \
+       wsock32.lib user32.lib \
        $(GLIB_LIBS) \
        wsutil\libwsutil.lib \
        $(GNUTLS_LIBS) \
@@ -113,7 +113,7 @@ tshark_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \
 !ENDIF
 
 rawshark_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \
-       wsock32.lib user32.lib shell32.lib \
+       wsock32.lib user32.lib \
        $(GLIB_LIBS) \
        wsutil\libwsutil.lib \
        $(GNUTLS_LIBS) \
@@ -144,17 +144,17 @@ editcap_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \
        $(GLIB_LIBS)
 
 mergecap_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \
-       wsock32.lib user32.lib shell32.lib \
+       wsock32.lib user32.lib \
        wsutil\libwsutil.lib \
        $(GLIB_LIBS)
 
 text2pcap_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \
-       wsock32.lib user32.lib shell32.lib \
+       wsock32.lib user32.lib \
        wsutil\libwsutil.lib \
        $(GLIB_LIBS)
 
 dumpcap_LIBS= \
-       wsock32.lib user32.lib shell32.lib \
+       wsock32.lib user32.lib \
        wsutil\libwsutil.lib \
        $(GLIB_LIBS) \
        $(GTHREAD_LIBS)
@@ -178,7 +178,7 @@ dftest_LIBS=  wiretap\wiretap-$(WTAP_VERSION).lib \
 !ENDIF
 
 randpkt_LIBS= wiretap\wiretap-$(WTAP_VERSION).lib \
-       user32.lib shell32.lib \
+       user32.lib \
        wsutil\libwsutil.lib \
        $(GLIB_LIBS)
 
index a5c6bd40e023598f28c8553fc631d793069d16e5..88af0b5237d253ccc7cbf734ef66c4f5940b1f7d 100644 (file)
@@ -95,7 +95,7 @@
 #endif
 
 #ifdef _WIN32
-#include <shellapi.h>
+#include <wsutil/unicode-utils.h>
 #endif /* _WIN32 */
 
 #include "svnversion.h"
@@ -847,11 +847,6 @@ main(int argc, char *argv[])
   int    opt;
   int    overall_error_status;
 
-#ifdef _WIN32
-  LPWSTR              *wc_argv;
-  int                  wc_argc, i;
-#endif  /* _WIN32 */
-
   int status = 0;
 #ifdef HAVE_PLUGINS
   char  *init_progfile_dir_error;
@@ -864,13 +859,7 @@ main(int argc, char *argv[])
 #endif
 
 #ifdef _WIN32
-  /* Convert our arg list to UTF-8. */
-  wc_argv = CommandLineToArgvW(GetCommandLineW(), &wc_argc);
-  if (wc_argv && wc_argc == argc) {
-    for (i = 0; i < argc; i++) {
-      argv[i] = g_utf16_to_utf8(wc_argv[i], -1, NULL, NULL, NULL);
-    }
-  } /* XXX else bail because something is horribly, horribly wrong? */
+  arg_list_utf_16to8(argc, argv);
 #endif /* _WIN32 */
 
   /*
@@ -1114,4 +1103,3 @@ main(int argc, char *argv[])
   }
   return overall_error_status;
 }
-
index 17946b6d12c24ebfba6f41ed5b419593e1f20a75..c83a39bc99f02ba4b2dcd9d6aad9395590ac5587 100644 (file)
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -85,7 +85,6 @@
 #include "pcapio.h"
 
 #ifdef _WIN32
-#include <shellapi.h>
 #include "capture-wpcap.h"
 #include <wsutil/unicode-utils.h>
 #endif
@@ -3645,8 +3644,6 @@ main(int argc, char *argv[])
 
 #ifdef _WIN32
     WSADATA              wsaData;
-    LPWSTR              *wc_argv;
-    int                  wc_argc;
 #else
     struct sigaction action, oldaction;
 #endif
@@ -3670,13 +3667,7 @@ main(int argc, char *argv[])
 #endif
 
 #ifdef _WIN32
-    /* Convert our arg list to UTF-8. */
-    wc_argv = CommandLineToArgvW(GetCommandLineW(), &wc_argc);
-    if (wc_argv && wc_argc == argc) {
-        for (i = 0; i < argc; i++) {
-            argv[i] = g_utf16_to_utf8(wc_argv[i], -1, NULL, NULL, NULL);
-        }
-    } /* XXX else bail because something is horribly, horribly wrong? */
+    arg_list_utf_16to8(argc, argv);
 #endif /* _WIN32 */
 
 #ifdef _WIN32
index 3c70c7f14d44c156bef799115b67045bf26aae3c..f8af5e13569da0a5ea8e7731789e2de22eb7cc37 100644 (file)
--- a/editcap.c
+++ b/editcap.c
@@ -49,8 +49,7 @@
 #endif
 
 #ifdef _WIN32
-#include <windows.h>
-#include <shellapi.h>
+#include <wsutil/unicode-utils.h>
 #include <process.h>    /* getpid */
 #ifdef HAVE_WINSOCK2_H
 #include <winsock2.h>
@@ -745,13 +744,13 @@ struct string_elem {
 static gint
 string_compare(gconstpointer a, gconstpointer b)
 {
-    return strcmp(((struct string_elem *)a)->sstr, 
+    return strcmp(((struct string_elem *)a)->sstr,
         ((struct string_elem *)b)->sstr);
-}    
+}
 
 static void
 string_elem_print(gpointer data, gpointer not_used _U_)
-{    
+{
     fprintf(stderr, "    %s - %s\n",
         ((struct string_elem *)data)->sstr,
         ((struct string_elem *)data)->lstr);
@@ -818,11 +817,6 @@ main(int argc, char *argv[])
   gchar *err_info;
   int opt;
 
-#ifdef _WIN32
-  LPWSTR              *wc_argv;
-  int                  wc_argc;
-#endif  /* _WIN32 */
-
   char *p;
   unsigned int snaplen = 0;             /* No limit               */
   int choplen = 0;                      /* No chop                */
@@ -849,13 +843,7 @@ main(int argc, char *argv[])
 #endif
 
 #ifdef _WIN32
-  /* Convert our arg list to UTF-8. */
-  wc_argv = CommandLineToArgvW(GetCommandLineW(), &wc_argc);
-  if (wc_argv && wc_argc == argc) {
-    for (i = 0; i < argc; i++) {
-      argv[i] = g_utf16_to_utf8(wc_argv[i], -1, NULL, NULL, NULL);
-    }
-  } /* XXX else bail because something is horribly, horribly wrong? */
+  arg_list_utf_16to8(argc, argv);
 #endif /* _WIN32 */
 
   /*
index d1ea6a0e8502939f4c7607255145210a6495ed9f..36c915ce0d1b26d67e00cfce0daf155c51b9585d 100644 (file)
 #include "../capture-wpcap.h"
 #include "../capture_wpcap_packet.h"
 #include <tchar.h> /* Needed for Unicode */
+#include <wsutil/unicode-utils.h>
 #include <commctrl.h>
 #include <shellapi.h>
 #endif /* _WIN32 */
@@ -2006,8 +2007,6 @@ main(int argc, char *argv[])
 
 #ifdef _WIN32
   WSADATA             wsaData;
-  LPWSTR              *wc_argv;
-  int                  wc_argc, i;
 #endif  /* _WIN32 */
 
   char                *rf_path;
@@ -2065,13 +2064,7 @@ main(int argc, char *argv[])
   static const char optstring[] = OPTSTRING;
 
 #ifdef _WIN32
-  /* Convert our arg list to UTF-8. */
-  wc_argv = CommandLineToArgvW(GetCommandLineW(), &wc_argc);
-  if (wc_argv && wc_argc == argc) {
-    for (i = 0; i < argc; i++) {
-      argv[i] = g_utf16_to_utf8(wc_argv[i], -1, NULL, NULL, NULL);
-    }
-  } /* XXX else bail because something is horribly, horribly wrong? */
+  arg_list_utf_16to8(argc, argv);
 #endif /* _WIN32 */
 
   /*
index 460f938ba9c383aa88cf4f5fbe09ab0e255863ff..9c658cb4335f3cb88a4bb85acd045cbef9675162 100644 (file)
@@ -42,8 +42,7 @@
 #endif
 
 #ifdef _WIN32
-#include <windows.h>
-#include <shellapi.h>
+#include <wsutil/unicode-utils.h>
 #endif /* _WIN32 */
 
 static int
@@ -149,11 +148,6 @@ main(int argc, char *argv[])
 {
   int          opt;
 
-#ifdef _WIN32
-  LPWSTR              *wc_argv;
-  int                  wc_argc;
-#endif  /* _WIN32 */
-
   gboolean     do_append     = FALSE;
   gboolean     verbose       = FALSE;
   int          in_file_count = 0;
@@ -174,13 +168,7 @@ main(int argc, char *argv[])
   int          count;
 
 #ifdef _WIN32
-  /* Convert our arg list to UTF-8. */
-  wc_argv = CommandLineToArgvW(GetCommandLineW(), &wc_argc);
-  if (wc_argv && wc_argc == argc) {
-    for (i = 0; i < argc; i++) {
-      argv[i] = g_utf16_to_utf8(wc_argv[i], -1, NULL, NULL, NULL);
-    }
-  } /* XXX else bail because something is horribly, horribly wrong? */
+  arg_list_utf_16to8(argc, argv);
 #endif /* _WIN32 */
 
   /* Process the options first */
index a9d157ac52d10a993240d008bd674a394ca274eb..fbd77535c15b016015915f73dc5d9531ade436b7 100644 (file)
--- a/randpkt.c
+++ b/randpkt.c
@@ -51,8 +51,7 @@
 #include "wiretap/wtap.h"
 
 #ifdef _WIN32
-#include <windows.h>
-#include <shellapi.h>
+#include <wsutil/unicode-utils.h>
 #endif /* _WIN32 */
 
 #define array_length(x)        (sizeof x / sizeof x[0])
@@ -508,12 +507,6 @@ main(int argc, char **argv)
 
        int                     opt;
 
-#ifdef _WIN32
-       LPWSTR              *wc_argv;
-       int                  wc_argc;
-#endif  /* _WIN32 */
-       
-
        int                     produce_count = 1000; /* number of pkts to produce */
        int                     produce_type = PKT_ETHERNET;
        char                    *produce_filename = NULL;
@@ -521,13 +514,7 @@ main(int argc, char **argv)
        pkt_example             *example;
 
 #ifdef _WIN32
-       /* Convert our arg list to UTF-8. */
-       wc_argv = CommandLineToArgvW(GetCommandLineW(), &wc_argc);
-       if (wc_argv && wc_argc == argc) {
-               for (i = 0; i < argc; i++) {
-                       argv[i] = g_utf16_to_utf8(wc_argv[i], -1, NULL, NULL, NULL);
-               }
-       } /* XXX else bail because something is horribly, horribly wrong? */
+       arg_list_utf_16to8(argc, argv);
 #endif /* _WIN32 */
 
        while ((opt = getopt(argc, argv, "b:c:ht:")) != -1) {
index 58c31ff172be9074060d1c3ee0fe1887ba63b0f5..3d90e3267927e1eec0448135f0264c9a6a5b0155 100644 (file)
 #include "log.h"
 
 #ifdef _WIN32
-#include <shellapi.h>
+#include <wsutil/unicode-utils.h>
 #endif /* _WIN32 */
 
 /*
@@ -435,8 +435,6 @@ main(int argc, char *argv[])
 
 #ifdef _WIN32
     WSADATA              wsaData;
-    LPWSTR              *wc_argv;
-    int                  wc_argc;
 #endif  /* _WIN32 */
 
     char                *gpf_path, *pf_path;
@@ -460,13 +458,7 @@ main(int argc, char *argv[])
     static const char    optstring[] = OPTSTRING_INIT;
 
 #ifdef _WIN32
-    /* Convert our arg list to UTF-8. */
-    wc_argv = CommandLineToArgvW(GetCommandLineW(), &wc_argc);
-    if (wc_argv && wc_argc == argc) {
-        for (i = 0; i < argc; i++) {
-            argv[i] = g_utf16_to_utf8(wc_argv[i], -1, NULL, NULL, NULL);
-        }
-    } /* XXX else bail because something is horribly, horribly wrong? */
+    arg_list_utf_16to8(argc, argv);
 #endif /* _WIN32 */
 
     /*
index 558ca35ccac9b3f7facfa2be9251f9f2371a03b2..18df1c917b591cd0d8e69d845877484fa52def03 100644 (file)
 #include "svnversion.h"
 
 #ifdef _WIN32
-#include <windows.h>
-#include <shellapi.h>
+#include <wsutil/unicode-utils.h>
 #endif /* _WIN32 */
 
 /*--- Options --------------------------------------------------------------------*/
@@ -1131,19 +1130,9 @@ parse_options (int argc, char *argv[])
 {
     int c;
     char *p;
-#ifdef _WIN32
-    LPWSTR *wc_argv;
-    int wc_argc, i;
-#endif  /* _WIN32 */
 
 #ifdef _WIN32
-    /* Convert our arg list to UTF-8. */
-    wc_argv = CommandLineToArgvW(GetCommandLineW(), &wc_argc);
-    if (wc_argv && wc_argc == argc) {
-       for (i = 0; i < argc; i++) {
-           argv[i] = g_utf16_to_utf8(wc_argv[i], -1, NULL, NULL, NULL);
-       }
-    } /* XXX else bail because something is horribly, horribly wrong? */
+    arg_list_utf_16to8(argc, argv);
 #endif /* _WIN32 */
 
     /* Scan CLI parameters */
index 5db00c8da906969786433150505443b0e91d6865..022384f12829c90d3bef419b881dfef0b56e4dd9 100644 (file)
--- a/tshark.c
+++ b/tshark.c
@@ -96,7 +96,7 @@
 #ifdef _WIN32
 #include "capture-wpcap.h"
 #include "capture_errs.h"
-#include <shellapi.h>
+#include <wsutil/unicode-utils.h>
 #endif /* _WIN32 */
 #include "capture_sync.h"
 #endif /* HAVE_LIBPCAP */
@@ -798,8 +798,6 @@ main(int argc, char *argv[])
 
 #ifdef _WIN32
   WSADATA              wsaData;
-  LPWSTR              *wc_argv;
-  int                  wc_argc, i;
 #endif  /* _WIN32 */
 
   char                *gpf_path, *pf_path;
@@ -854,13 +852,7 @@ main(int argc, char *argv[])
   static const char    optstring[] = OPTSTRING;
 
 #ifdef _WIN32
-  /* Convert our arg list to UTF-8. */
-  wc_argv = CommandLineToArgvW(GetCommandLineW(), &wc_argc);
-  if (wc_argv && wc_argc == argc) {
-    for (i = 0; i < argc; i++) {
-      argv[i] = g_utf16_to_utf8(wc_argv[i], -1, NULL, NULL, NULL);
-    }
-  } /* XXX else bail because something is horribly, horribly wrong? */
+  arg_list_utf_16to8(argc, argv);
 #endif /* _WIN32 */
 
   /*
index 8d4c376b9cdb731bb20279a7ee974d90ae948999..38f5718b5f08760641820dd7eaa4469255b758f2 100644 (file)
@@ -35,7 +35,7 @@ libwsutil.lib: libwsutil.dll
 libwsutil.exp: libwsutil.dll
 
 libwsutil.dll : $(OBJECTS) libwsutil.def ..\image\libwsutil.res
-       $(link) $(dlllflags) $(conlibsdll) \
+       $(link) $(dlllflags) $(conlibsdll) shell32.lib \
                $(LOCAL_LDFLAGS) $(DLL_LDFLAGS) \
                /DEF:libwsutil.def /OUT:libwsutil.dll \
                /IMPLIB:libwsutil.lib \
index 5abb4d2b76109e6356c13f07e69b84df67973593..7aadd7e848109f73188fdf7a7a70fe896863f092 100644 (file)
@@ -66,6 +66,7 @@ type_util_guint64_to_gdouble
 utf_16to8
 utf_8to16
 utf_8to16_snprintf
+arg_list_utf_16to8
 
 ; wsgetopt.c
 getopt
index 80541a57840d598ac530d899b43d766c2c139e1b..567ef180ca9d01b3c59109cac037718a596ac2aa 100644 (file)
@@ -28,6 +28,8 @@
 
 #include "unicode-utils.h"
 
+#include <shellapi.h>
+
 /** @file
  * Unicode utilities (internal interface)
  *
@@ -141,3 +143,17 @@ utf_16to8(const wchar_t *utf16str)
   return utf8buf[idx];
 }
 
+/* Convert our argument list from UTF-16 to UTF-8. */
+void
+arg_list_utf_16to8(int argc, char *argv[]) {
+  LPWSTR              *wc_argv;
+  int                  wc_argc, i;
+
+  /* Convert our arg list to UTF-8. */
+  wc_argv = CommandLineToArgvW(GetCommandLineW(), &wc_argc);
+  if (wc_argv && wc_argc == argc) {
+    for (i = 0; i < argc; i++) {
+      argv[i] = g_utf16_to_utf8(wc_argv[i], -1, NULL, NULL, NULL);
+    }
+  } /* XXX else bail because something is horribly, horribly wrong? */
+}
index f3c423ffd8abe46c465ae42742fac5ef505c4e4a..a03a1727329281a2dbb1cc6994cf30f54cace4bb 100644 (file)
@@ -66,6 +66,18 @@ void utf_8to16_snprintf(TCHAR *utf16buf, gint utf16buf_len, const gchar* fmt, ..
  */
 gchar * utf_16to8(const wchar_t *utf16str);
 
+/** Convert the program argument list from UTF-16 to UTF-8 and
+ * store it in the supplied array. This is intended to be used
+ * to normalize command line arguments at program startup.
+ *
+ * @param argc The number of arguments. You should simply pass the
+ * first argument from main().
+ * @param argv The argument values (vector). You should simply pass
+ * the second argument from main().
+ */
+void arg_list_utf_16to8(int argc, char *argv[]);
+
+
 #endif /* _WIN32 */
 
 #endif /* __UNICODEUTIL_H__ */