aboutsummaryrefslogtreecommitdiffstats
path: root/wsutil
diff options
context:
space:
mode:
authorgerald <gerald@f5534014-38df-0310-8fa8-9805f1628bb7>2011-05-24 00:07:56 +0000
committergerald <gerald@f5534014-38df-0310-8fa8-9805f1628bb7>2011-05-24 00:07:56 +0000
commitb0470ef1fe28e236a3c2ceb11dedd80e1753f16e (patch)
treedf105f49b2895d2f74db9545ae4235aba0e95562 /wsutil
parent5cb0387b39785c47df9d9d9ef44c36b8096da513 (diff)
Move the Windows argument list conversion code to a common routine.
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@37372 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'wsutil')
-rw-r--r--wsutil/Makefile.nmake2
-rw-r--r--wsutil/libwsutil.def1
-rw-r--r--wsutil/unicode-utils.c16
-rw-r--r--wsutil/unicode-utils.h12
4 files changed, 30 insertions, 1 deletions
diff --git a/wsutil/Makefile.nmake b/wsutil/Makefile.nmake
index 8d4c376b9c..38f5718b5f 100644
--- a/wsutil/Makefile.nmake
+++ b/wsutil/Makefile.nmake
@@ -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 \
diff --git a/wsutil/libwsutil.def b/wsutil/libwsutil.def
index 5abb4d2b76..7aadd7e848 100644
--- a/wsutil/libwsutil.def
+++ b/wsutil/libwsutil.def
@@ -66,6 +66,7 @@ type_util_guint64_to_gdouble
utf_16to8
utf_8to16
utf_8to16_snprintf
+arg_list_utf_16to8
; wsgetopt.c
getopt
diff --git a/wsutil/unicode-utils.c b/wsutil/unicode-utils.c
index 80541a5784..567ef180ca 100644
--- a/wsutil/unicode-utils.c
+++ b/wsutil/unicode-utils.c
@@ -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? */
+}
diff --git a/wsutil/unicode-utils.h b/wsutil/unicode-utils.h
index f3c423ffd8..a03a172732 100644
--- a/wsutil/unicode-utils.h
+++ b/wsutil/unicode-utils.h
@@ -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__ */