2005-01-11 Mike Kestner <mkestner@novell.com>

* glib/Argv.cs : add automatic progname handling.
	* gdk/Global.custom : kill obsolete warnings by using GLib.Argv.

svn path=/trunk/gtk-sharp/; revision=38729
This commit is contained in:
Mike Kestner 2005-01-11 20:49:50 +00:00
parent 903543cdb4
commit b6b39dbbfe
4 changed files with 51 additions and 13 deletions

View File

@ -1,3 +1,8 @@
2005-01-11 Mike Kestner <mkestner@novell.com>
* glib/Argv.cs : add automatic progname handling.
* gdk/Global.custom : kill obsolete warnings by using GLib.Argv.
2005-01-11 Mike Kestner <mkestner@novell.com> 2005-01-11 Mike Kestner <mkestner@novell.com>
* gdk/Gdk.metadata : kill Colors since its methods are deprecated * gdk/Gdk.metadata : kill Colors since its methods are deprecated

View File

@ -73,5 +73,21 @@
<remarks /> <remarks />
</Docs> </Docs>
</Member> </Member>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public Argv (string [] args, bool add_program_name);" />
<MemberType>Constructor</MemberType>
<ReturnValue />
<Parameters>
<Parameter Name="args" Type="System.String[]" />
<Parameter Name="add_program_name" Type="System.Boolean" />
</Parameters>
<Docs>
<summary>Public constructor</summary>
<param name="args">a <see cref="T:System.String" /></param>
<param name="add_program_name">a <see cref="T:System.Boolean" /></param>
<returns>a <see cref="T:GLib.Argv" /></returns>
<remarks>If <paramref name="add_program_name"/> is <see langword="true"/>, the native argv will also contain a leading string containing the program name reported in the first element of the array returned by <see cref="M:System.Environment.GetCommandLineArgs"/>.</remarks>
</Docs>
</Member>
</Members> </Members>
</Type> </Type>

View File

@ -141,10 +141,12 @@
public static bool InitCheck (ref string[] argv) public static bool InitCheck (ref string[] argv)
{ {
IntPtr ptr = GLib.Marshaller.ArgvToArrayPtr (argv); GLib.Argv a = new GLib.Argv (argv, true);
int count = argv.Length; IntPtr buf = a.Handle;
bool result = gdk_init_check (ref count, ref ptr); int argc = argv.Length + 1;
argv = GLib.Marshaller.ArrayPtrToArgv (ptr, count);
bool result = gdk_init_check (ref argc, ref buf);
argv = a.GetArgs (argc);
return result; return result;
} }
@ -153,10 +155,12 @@
public static void ParseArgs (ref string[] argv) public static void ParseArgs (ref string[] argv)
{ {
IntPtr ptr = GLib.Marshaller.ArgvToArrayPtr (argv); GLib.Argv a = new GLib.Argv (argv, true);
int count = argv.Length; IntPtr buf = a.Handle;
gdk_parse_args (ref count, ref ptr); int argc = argv.Length + 1;
argv = GLib.Marshaller.ArrayPtrToArgv (ptr, count);
gdk_parse_args (ref argc, ref buf);
argv = a.GetArgs (argc);
} }
[DllImport("libgdk-win32-2.0-0.dll")] [DllImport("libgdk-win32-2.0-0.dll")]

View File

@ -28,6 +28,7 @@ namespace GLib {
IntPtr[] arg_ptrs; IntPtr[] arg_ptrs;
IntPtr handle; IntPtr handle;
bool add_progname = false;
[DllImport("libglib-2.0-0.dll")] [DllImport("libglib-2.0-0.dll")]
static extern IntPtr g_strdup (string str); static extern IntPtr g_strdup (string str);
@ -46,8 +47,18 @@ namespace GLib {
g_free (handle); 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]; arg_ptrs = new IntPtr [args.Length];
for (int i = 0; i < args.Length; i++) for (int i = 0; i < args.Length; i++)
@ -58,7 +69,7 @@ namespace GLib {
for (int i = 0; i < args.Length; i++) for (int i = 0; i < args.Length; i++)
Marshal.WriteIntPtr (handle, i * IntPtr.Size, arg_ptrs [i]); Marshal.WriteIntPtr (handle, i * IntPtr.Size, arg_ptrs [i]);
} }
public IntPtr Handle { public IntPtr Handle {
get { get {
return handle; return handle;
@ -67,10 +78,12 @@ namespace GLib {
public string[] GetArgs (int argc) 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++) for (int i = 0; i < count; i++, idx++)
result [i] = Marshal.PtrToStringAnsi (Marshal.ReadIntPtr (handle, i * IntPtr.Size)); result [i] = Marshal.PtrToStringAnsi (Marshal.ReadIntPtr (handle, idx * IntPtr.Size));
return result; return result;
} }