From cb7c1d886e39bad3e39931d9690e125ef5cec101 Mon Sep 17 00:00:00 2001 From: Søren Sandmann Date: Sat, 25 Oct 2008 01:42:30 -0400 Subject: Split option processing out into its own function --- siv.c | 55 +++++++++++++++++++++++++++---------------------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/siv.c b/siv.c index e992732..33c1136 100644 --- a/siv.c +++ b/siv.c @@ -321,15 +321,11 @@ app_set_meta_data (App *app, g_hash_table_destroy (table); } - -static void -app_new (int argc, char **argv) +static char ** +process_options (int argc, char **argv) { - GList *filenames = NULL; - GList *list; - App *app; int i; - GPtrArray *err_files = g_ptr_array_new (); + GPtrArray *result = g_ptr_array_new (); for (i = 1; i < argc; ++i) { @@ -342,24 +338,33 @@ app_new (int argc, char **argv) g_print ("%s %s\n", APPLICATION_NAME, PACKAGE_VERSION); exit (1); - return; + return NULL; } if (g_path_is_absolute (option)) - { name = g_strdup (option); - } else - { name = g_build_filename (g_get_current_dir(), option, NULL); - } - filenames = g_list_prepend (filenames, name); + g_ptr_array_add (result, name); } + g_ptr_array_add (result, NULL); + + return (char **)g_ptr_array_free (result, FALSE); +} + +static void +app_new (int argc, char **argv) +{ + GPtrArray *err_files = g_ptr_array_new (); + char **filenames; + App *app; + int i; + + filenames = process_options (argc, argv); + app = g_new0 (App, 1); - - filenames = g_list_reverse (filenames); /* When a window is created, it increases the app->n_windows counter; * when it is destroyed it decreases it. The problem is if the first @@ -370,17 +375,14 @@ app_new (int argc, char **argv) * prevent that from happening. */ app->n_windows = 1; - - if (filenames) - { - int i; - i = 0; - for (list = filenames; list != NULL; list = list->next) + if (filenames[0]) + { + for (i = 0; filenames[i] != NULL; ++i) { SivWindow *window; GError *err = NULL; - char *filename = list->data; + char *filename = filenames[i]; /* Don't open more than 32 windows */ if (++i > 32) @@ -388,7 +390,7 @@ app_new (int argc, char **argv) window = window_new (app); - if (!window_load_file (window, list->data, &err)) + if (!window_load_file (window, filename, &err)) { g_ptr_array_add (err_files, g_strdup (filename)); g_error_free (err); @@ -400,17 +402,14 @@ app_new (int argc, char **argv) window_show (window, GDK_CURRENT_TIME); } } - - for (list = filenames; list != NULL; list = list->next) - g_free (list->data); - - g_list_free (filenames); } else { window_show (window_new (app), GDK_CURRENT_TIME); } + g_strfreev (filenames); + app_show_could_not_open (NULL, err_files->len, (char **)err_files->pdata); g_ptr_array_foreach (err_files, (GFunc)g_free, NULL); -- cgit v1.2.3