diff options
author | Søren Sandmann <sandmann@redhat.com> | 2008-10-25 01:42:30 -0400 |
---|---|---|
committer | Søren Sandmann <sandmann@redhat.com> | 2008-10-25 01:42:30 -0400 |
commit | cb7c1d886e39bad3e39931d9690e125ef5cec101 (patch) | |
tree | 0ac34d942e5fd72057a9ef761bd98251c68ff776 | |
parent | 2468310301525f5e7d5f13725654bd8bbd0efa8d (diff) |
Split option processing out into its own function
-rw-r--r-- | siv.c | 55 |
1 files changed, 27 insertions, 28 deletions
@@ -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); |