[PATCH] main.cpp: remove usage of subsurface_command_line_*

Lubomir I. Ivanov neolit123 at gmail.com
Tue Oct 8 02:48:46 UTC 2013


From: "Lubomir I. Ivanov" <neolit123 at gmail.com>

subsurface_command_line_* are now redundant as Qt
should handle the command line argument parsing on Windows
for which these functions where mainly used and where NOP
for other OS.

main.cpp also receives a couple of small changes to use:
QCoreApplication::arguments()
to obtain the list of expanded arguments and parse those
instead.

Signed-off-by: Lubomir I. Ivanov <neolit123 at gmail.com>
---
 linux.c   | 10 ----------
 macos.c   | 10 ----------
 main.cpp  | 15 +++++++--------
 windows.c | 63 ---------------------------------------------------------------
 4 files changed, 7 insertions(+), 91 deletions(-)

diff --git a/linux.c b/linux.c
index 2cee876..9348195 100644
--- a/linux.c
+++ b/linux.c
@@ -23,16 +23,6 @@ const char *system_default_filename(void)
 	return buffer;
 }
 
-void subsurface_command_line_init(int *argc, char ***argv)
-{
-	/* this is a no-op */
-}
-
-void subsurface_command_line_exit(int *argc, char ***argv)
-{
-	/* this is a no-op */
-}
-
 int enumerate_devices (device_callback_t callback, void *userdata)
 {
 	int index = -1;
diff --git a/macos.c b/macos.c
index d1b3bbe..64b23a7 100644
--- a/macos.c
+++ b/macos.c
@@ -38,16 +38,6 @@ const char *system_default_filename(void)
 	return buffer;
 }
 
-void subsurface_command_line_init(int *argc, char ***argv)
-{
-	/* this is a no-op */
-}
-
-void subsurface_command_line_exit(int *argc, char ***argv)
-{
-	/* this is a no-op */
-}
-
 int enumerate_devices (device_callback_t callback, void *userdata)
 {
 	int index = -1;
diff --git a/main.cpp b/main.cpp
index fddf508..c7d916c 100644
--- a/main.cpp
+++ b/main.cpp
@@ -32,23 +32,23 @@ int main(int argc, char **argv)
 	setup_system_prefs();
 	prefs = default_prefs;
 
-	subsurface_command_line_init(&argc, &argv);
 	init_ui(&argc, &argv);
 	parse_xml_init();
 
 	QStringList files;
 	QStringList importedFiles;
-	for (i = 1; i < argc; i++) {
-		const char *a = argv[i];
-		if (a[0] == '-') {
-			parse_argument(a);
+	QStringList arguments = QCoreApplication::arguments();
+	for (i = 1; i < arguments.length(); i++) {
+		QString a = arguments.at(i);
+		if (a.at(0) == '-') {
+			parse_argument(a.toLocal8Bit().data());
 			continue;
 		}
 		if (imported) {
-			importedFiles.push_back( QString(a) );
+			importedFiles.push_back(a);
 		} else {
 			no_filenames = false;
-			files.push_back( QString(a) );
+			files.push_back(a);
 		}
 	}
 	if (no_filenames) {
@@ -57,7 +57,6 @@ int main(int argc, char **argv)
 			files.push_back( QString(prefs.default_filename) );
 	}
 	parse_xml_exit();
-	subsurface_command_line_exit(&argc, &argv);
 	mainWindow()->loadFiles(files);
 	mainWindow()->importFiles(importedFiles);
 	run_ui();
diff --git a/windows.c b/windows.c
index 0c11774..eaa3894 100644
--- a/windows.c
+++ b/windows.c
@@ -26,69 +26,6 @@ const char *system_default_filename(void)
 	return buffer;
 }
 
-/* barely documented API */
-extern int __wgetmainargs(int *, wchar_t ***, wchar_t ***, int, int *);
-
-/* expand-convert the UTF-16 argument list to a list of UTF-8 strings */
-void subsurface_command_line_init(int *argc, char ***argv)
-{
-	wchar_t **wargv, **wenviron, *p, path[MAX_PATH] = {0};
-	char **argv_new;
-	char *s;
-	/* for si we assume that a struct address will equal the address
-	 * of its first and only int member */
-	int i, n, ret, si;
-
-	/* change the current process path to the module path, so that we can
-	 * access relative folders such as ./share and ./xslt */
-	GetModuleFileNameW(NULL, path, MAX_PATH - 1);
-	p = wcsrchr(path, '\\');
-	*(p + 1) = '\0';
-	SetCurrentDirectoryW(path);
-
-	/* memory leak tools may reports a potential issue here at a call
-	 * to strcpy_s in msvcrt, wich should be a false positive. but even if there
-	 * is some kind of a leak, it should be unique and have the same
-	 * lifespan as the process heap. */
-	ret = __wgetmainargs(&n, &wargv, &wenviron, TRUE, &si);
-	if (ret < 0) {
-		fprintf(stderr, "Cannot convert command line");
-		return;
-	}
-	argv_new = malloc(sizeof(char *) * (n + 1));
-
-#if MISSING_GLIB_FUNCTIONS
-	for (i = 0; i < n; ++i) {
-		s = g_utf16_to_utf8((gunichar2 *)wargv[i], -1, NULL, NULL, NULL);
-		if (!s) {
-			fprintf(stderr, "Cannot convert command line argument (%d) to UTF-8", (i + 1));
-			s = "\0";
-		} else if (!g_utf8_validate(s, -1, NULL)) {
-			fprintf(stderr,"Cannot validate command line argument '%s' (%d)", s, (i + 1));
-			free(s);
-			s = "\0";
-		}
-		argv_new[i] = s;
-	}
-#endif
-	argv_new[n] = NULL;
-
-	/* update the argument list and count */
-	if (argv && argc) {
-		*argv = argv_new;
-		*argc = n;
-	}
-}
-
-/* once done, free the argument list */
-void subsurface_command_line_exit(int *argc, char ***argv)
-{
-	int i;
-	for (i = 0; i < *argc; i++)
-		free((*argv)[i]);
-	free(*argv);
-}
-
 int enumerate_devices (device_callback_t callback, void *userdata)
 {
 	// Open the registry key.
-- 
1.7.11.msysgit.0



More information about the subsurface mailing list