diff --git a/ChangeLog b/ChangeLog index 28e1d599d..f547b164d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-01-11 Mike Kestner + + * glib/Argv.cs : add automatic progname handling. + * gdk/Global.custom : kill obsolete warnings by using GLib.Argv. + 2005-01-11 Mike Kestner * gdk/Gdk.metadata : kill Colors since its methods are deprecated diff --git a/doc/en/GLib/Argv.xml b/doc/en/GLib/Argv.xml index 9e479914b..ba0c3d319 100644 --- a/doc/en/GLib/Argv.xml +++ b/doc/en/GLib/Argv.xml @@ -73,5 +73,21 @@ + + + Constructor + + + + + + + Public constructor + a + a + a + If is , the native argv will also contain a leading string containing the program name reported in the first element of the array returned by . + + diff --git a/gdk/Global.custom b/gdk/Global.custom index 9a2536b8b..b3ea067d8 100644 --- a/gdk/Global.custom +++ b/gdk/Global.custom @@ -141,10 +141,12 @@ public static bool InitCheck (ref string[] argv) { - IntPtr ptr = GLib.Marshaller.ArgvToArrayPtr (argv); - int count = argv.Length; - bool result = gdk_init_check (ref count, ref ptr); - argv = GLib.Marshaller.ArrayPtrToArgv (ptr, count); + GLib.Argv a = new GLib.Argv (argv, true); + IntPtr buf = a.Handle; + int argc = argv.Length + 1; + + bool result = gdk_init_check (ref argc, ref buf); + argv = a.GetArgs (argc); return result; } @@ -153,10 +155,12 @@ public static void ParseArgs (ref string[] argv) { - IntPtr ptr = GLib.Marshaller.ArgvToArrayPtr (argv); - int count = argv.Length; - gdk_parse_args (ref count, ref ptr); - argv = GLib.Marshaller.ArrayPtrToArgv (ptr, count); + GLib.Argv a = new GLib.Argv (argv, true); + IntPtr buf = a.Handle; + int argc = argv.Length + 1; + + gdk_parse_args (ref argc, ref buf); + argv = a.GetArgs (argc); } [DllImport("libgdk-win32-2.0-0.dll")] diff --git a/glib/Argv.cs b/glib/Argv.cs index 66ca99b79..54303e8dc 100644 --- a/glib/Argv.cs +++ b/glib/Argv.cs @@ -28,6 +28,7 @@ namespace GLib { IntPtr[] arg_ptrs; IntPtr handle; + bool add_progname = false; [DllImport("libglib-2.0-0.dll")] static extern IntPtr g_strdup (string str); @@ -46,8 +47,18 @@ namespace GLib { g_free (handle); } - public Argv (string[] args) + public Argv (string[] args) : this (args, false) {} + + public Argv (string[] args, bool add_program_name) { + add_progname = add_program_name; + if (add_progname) { + string[] full = new string [args.Length + 1]; + full [0] = System.Environment.GetCommandLineArgs ()[0]; + args.CopyTo (full, 1); + args = full; + } + arg_ptrs = new IntPtr [args.Length]; for (int i = 0; i < args.Length; i++) @@ -58,7 +69,7 @@ namespace GLib { for (int i = 0; i < args.Length; i++) Marshal.WriteIntPtr (handle, i * IntPtr.Size, arg_ptrs [i]); } - + public IntPtr Handle { get { return handle; @@ -67,10 +78,12 @@ namespace GLib { public string[] GetArgs (int argc) { - string[] result = new string [argc]; + int count = add_progname ? argc - 1 : argc; + int idx = add_progname ? 1 : 0; + string[] result = new string [count]; - for (int i = 0; i < argc; i++) - result [i] = Marshal.PtrToStringAnsi (Marshal.ReadIntPtr (handle, i * IntPtr.Size)); + for (int i = 0; i < count; i++, idx++) + result [i] = Marshal.PtrToStringAnsi (Marshal.ReadIntPtr (handle, idx * IntPtr.Size)); return result; }