soc.2009.vulture: 1fdd1446: Parse command-line. Currently used only ...

gdick at soc.pidgin.im gdick at soc.pidgin.im
Thu May 28 18:30:51 EDT 2009


-----------------------------------------------------------------
Revision: 1fdd144676a5c3cffb21d341f90555eaffd33528
Ancestor: aa95a7163b729677157e4f645f4861101328a7d3
Author: gdick at soc.pidgin.im
Date: 2009-05-28T14:04:05
Branch: im.pidgin.soc.2009.vulture
URL: http://d.pidgin.im/viewmtn/revision/info/1fdd144676a5c3cffb21d341f90555eaffd33528

Added files:
        vulture/cmdline.c vulture/cmdline.h
Modified files:
        vulture/Makefile.mingw vulture/purplemain.c
        vulture/vulture.c

ChangeLog: 

Parse command-line. Currently used only to set custom user directory.

-------------- next part --------------
============================================================
--- vulture/cmdline.c	2d9d341713f2a61529401655cd5e94c22ff2187a
+++ vulture/cmdline.c	2d9d341713f2a61529401655cd5e94c22ff2187a
@@ -0,0 +1,92 @@
+/*
+ * Vulture - Win32 libpurple client
+ *
+ * cmdline.c: Command-line parsing.
+ *
+ * Copyright (C) 2009, Gregor Dick <gdick at soc.pidgin.im>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ */
+
+#include <windows.h>
+#include <glib.h>
+
+#include "vulture.h"
+#include "cmdline.h"
+
+
+/** Command-line options set by VultureParseCommandLine. */
+static gchar *g_szCustomUserDir = NULL;
+
+static GOptionContext *g_lpgopcontext;
+static GOptionEntry g_rggopentry[] =
+{
+	{ "config", 'c', 0, G_OPTION_ARG_STRING, &g_szCustomUserDir, "use DIR for config files", "DIR" },
+	{ NULL, 0, 0, 0, NULL, NULL, NULL }
+};
+
+
+/**
+ * Parses the command-line, populating appropriate global variables. Call this
+ * before querying any of the command-line parameters. Call
+ * VultureCommandLineCleanup to free allocated memory.
+ */
+void VultureParseCommandLine(void)
+{
+	gchar *szCmdLine;
+	LPTSTR szCmdLineT = GetCommandLine();
+	GError *lpgerror;
+	gint iArgc;
+	gchar **rgszArgv;
+
+	/* Get the command-line in UTF-8. */
+#ifdef UNICODE
+	szCmdLine = g_utf16_to_utf8(szCmdLineT, -1, NULL, NULL, NULL);
+#else
+	{
+		gsize cchWritten;
+		szCmdLine = g_locale_to_utf8(szCmdLineT, -1, NULL, &cchWritten, NULL);
+	}
+#endif
+
+	g_shell_parse_argv(szCmdLine, &iArgc, &rgszArgv, &lpgerror);
+	
+	g_lpgopcontext = g_option_context_new("");
+	g_option_context_add_main_entries(g_lpgopcontext, g_rggopentry, NULL);
+	g_option_context_parse(g_lpgopcontext, &iArgc, &rgszArgv, &lpgerror);
+
+	g_strfreev(rgszArgv);
+	g_free(szCmdLine);
+}
+
+
+/**
+ * Frees memory allocated by VultureParseCommandLine. Do not query any
+ * command-line parameters after calling this.
+ */
+void VultureCommandLineCleanup(void)
+{
+	g_option_context_free(g_lpgopcontext);
+}
+
+
+/**
+ * Retrieves the user directory specified on the command-line, or NULL if none
+ * set.
+ */
+gchar* VultureGetCustomUserDir(void)
+{
+	return g_szCustomUserDir;
+}
============================================================
--- vulture/cmdline.h	d3f43991b0f21608e9d694cf67013e999494e915
+++ vulture/cmdline.h	d3f43991b0f21608e9d694cf67013e999494e915
@@ -0,0 +1,32 @@
+/*
+ * Vulture - Win32 libpurple client
+ *
+ * cmdline.h: Command-line parsing.
+ *
+ * Copyright (C) 2009, Gregor Dick <gdick at soc.pidgin.im>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ */
+
+#ifndef _VULTURE_CMDLINE_H_
+#define _VULTURE_CMDLINE_H_
+
+#include <glib.h>
+
+void VultureParseCommandLine(void);
+void VultureCommandLineCleanup(void);
+gchar* VultureGetCustomUserDir(void);
+
+#endif
============================================================
--- vulture/Makefile.mingw	5b6091e29988ea1aee14dbffcf0dee6b08e028ab
+++ vulture/Makefile.mingw	2488db57325c16b139df5b6e27f0d1bec5577caf
@@ -55,7 +55,8 @@ VULTURE_C_SRC =	\
 			blist.c \
 			purplemain.c \
 			purplequeue.c \
-			purpleevloop.c
+			purpleevloop.c \
+			cmdline.c
 
 # VULTURE_RC_SRC = win32/pidgin_dll_rc.rc
 VULTURE_OBJECTS = $(VULTURE_C_SRC:%.c=%.o) $(VULTURE_RC_SRC:%.rc=%.o)
============================================================
--- vulture/purplemain.c	5a750ec1520e2331c64a8f25facc8761c8cf8c96
+++ vulture/purplemain.c	1ec28ecbef8584c2f4769554b9ad6ad0228e1e42
@@ -45,6 +45,7 @@
 #include "purplemain.h"
 #include "purplequeue.h"
 #include "purpleevloop.h"
+#include "cmdline.h"
 
 
 static UINT CALLBACK PurpleThread(void *lpvData);
@@ -138,6 +139,11 @@ static int InitLibpurple(void)
 		NULL, NULL, NULL, NULL
 	};
 
+	gchar *szCustomUserDir;
+
+	if((szCustomUserDir = VultureGetCustomUserDir()))
+		purple_util_set_user_dir(szCustomUserDir);
+
 	VulturePurpleEventLoopSetUIOps();
 	purple_core_set_ui_ops(&coreuiops);
 
============================================================
--- vulture/vulture.c	c5cb303b8b87b8aa843418e4014c77b52bae4c4b
+++ vulture/vulture.c	e06afa6d7612008397238e49370b87fe04126658
@@ -27,6 +27,7 @@
 #include "blist.h"
 #include "purplemain.h"
 #include "purplequeue.h"
+#include "cmdline.h"
 
 
 HINSTANCE g_hInstance;
@@ -50,6 +51,8 @@ int WINAPI WinMain(HINSTANCE hinst, HINS
 
 	g_hInstance = hinst;
 
+	VultureParseCommandLine();
+
 	if(VultureCreateBuddyList(iCmdShow) != 0)
 	{
 		return 1;
@@ -76,5 +79,7 @@ int WINAPI WinMain(HINSTANCE hinst, HINS
 
 	VultureShutDownLibpurple();
 
+	VultureCommandLineCleanup();
+
 	return msg.wParam;
 }


More information about the Commits mailing list