[glib] gio-du: Improve test program on Windows
- From: Ryan Lortie <desrt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] gio-du: Improve test program on Windows
- Date: Mon, 16 Sep 2013 18:13:06 +0000 (UTC)
commit 2684dec44786b8463f27ec14547cfafab80c28a1
Author: Chun-wei Fan <fanchunwei src gnome org>
Date: Fri Sep 13 17:42:44 2013 +0800
gio-du: Improve test program on Windows
Make use of __wgetmainargs() on Windows so that we can get wide char
versions of the argv's that are passed in when this test program is being
invoked. This is necessary as one might enter non-ASCII, such as
CJK characters filenames and/or directories to run the test program
against, so that we can process the name(s) and pass the proper
UTF-8-encoded name(s) of the files/directories that is being tested.
https://bugzilla.gnome.org/show_bug.cgi?id=707787
gio/tests/gio-du.c | 78 +++++++++++++++++++++++++++++++++++++--------------
1 files changed, 56 insertions(+), 22 deletions(-)
---
diff --git a/gio/tests/gio-du.c b/gio/tests/gio-du.c
index 12ac12b..b0f1fac 100644
--- a/gio/tests/gio-du.c
+++ b/gio/tests/gio-du.c
@@ -6,6 +6,21 @@ static gint option_format_size;
static gint outstanding_asyncs;
+#ifdef G_OS_WIN32
+typedef struct {
+ int newmode;
+} _startupinfo;
+
+#ifndef _MSC_VER
+
+extern void __wgetmainargs(int *argc,
+ wchar_t ***wargv,
+ wchar_t ***wenviron,
+ int expand_wildcards,
+ _startupinfo *startupinfo);
+#endif
+#endif
+
static void
print_result (const gchar *filename,
guint64 disk_usage,
@@ -75,9 +90,18 @@ main (int argc, char **argv)
GFileMeasureProgressCallback progress = NULL;
GFileMeasureFlags flags = 0;
gint i;
+#ifdef G_OS_WIN32
+ int wargc;
+ wchar_t **wargv, **wenvp;
+ _startupinfo si = { 0 };
+
+ __wgetmainargs (&wargc, &wargv, &wenvp, 0, &si);
+#endif
setlocale (LC_ALL, "");
+
+
for (i = 1; argv[i] && argv[i][0] == '-'; i++)
{
if (g_str_equal (argv[i], "--"))
@@ -112,32 +136,42 @@ main (int argc, char **argv)
return 1;
}
+#ifdef G_OS_WIN32
+ while (wargv[i])
+ {
+ gchar *argv_utf8 = g_utf16_to_utf8 (wargv[i], -1, NULL, NULL, NULL);
+#else
while (argv[i])
- {
- GFile *file = g_file_new_for_commandline_arg (argv[i]);
+ {
+ gchar *argv_utf8 = argv[i];
+#endif
+ GFile *file = g_file_new_for_commandline_arg (argv_utf8);
- if (option_use_async)
- {
- g_file_measure_disk_usage_async (file, flags, G_PRIORITY_DEFAULT, NULL,
- progress, argv[1], async_ready_func, argv[i]);
- outstanding_asyncs++;
- }
- else
- {
- GError *error = NULL;
- guint64 disk_usage;
- guint64 num_dirs;
- guint64 num_files;
-
- g_file_measure_disk_usage (file, flags, NULL, progress, argv[1],
- &disk_usage, &num_dirs, &num_files, &error);
- print_result (argv[i], disk_usage, num_dirs, num_files, error, '\n');
- }
+ if (option_use_async)
+ {
+ g_file_measure_disk_usage_async (file, flags, G_PRIORITY_DEFAULT, NULL,
+ progress, argv[1], async_ready_func, argv_utf8);
+ outstanding_asyncs++;
+ }
+ else
+ {
+ GError *error = NULL;
+ guint64 disk_usage;
+ guint64 num_dirs;
+ guint64 num_files;
+
+ g_file_measure_disk_usage (file, flags, NULL, progress, argv[1],
+ &disk_usage, &num_dirs, &num_files, &error);
+ print_result (argv_utf8, disk_usage, num_dirs, num_files, error, '\n');
+ }
- g_object_unref (file);
+ g_object_unref (file);
+#ifdef G_OS_WIN32
+ g_free (argv_utf8);
+#endif
- i++;
- }
+ i++;
+ }
while (outstanding_asyncs)
g_main_context_iteration (NULL, TRUE);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]