Move the Windows argument list conversion code to a common routine.

svn path=/trunk/; revision=37372
This commit is contained in:
Gerald Combs 2011-05-24 00:07:56 +00:00
parent 058fc19f45
commit a24687ce8e
14 changed files with 56 additions and 119 deletions

View 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)

View 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;
}

View File

@ -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

View File

@ -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 */
/*

View File

@ -118,6 +118,7 @@
#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 */
/*

View 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 */

View File

@ -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) {

View File

@ -118,7 +118,7 @@
#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 */
/*

View File

@ -139,8 +139,7 @@
#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 */

View File

@ -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 */
/*

View 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 \

View File

@ -66,6 +66,7 @@ type_util_guint64_to_gdouble
utf_16to8
utf_8to16
utf_8to16_snprintf
arg_list_utf_16to8
; wsgetopt.c
getopt

View 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? */
}

View 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__ */