# HG changeset patch # User gqview # Date 1160899574 0 # Node ID 07773a3c5b295fd957fdb868e3264742c8890541 # Parent 56f62cdde8e0244c851876dfb833f15c9bab480b Sun Oct 15 04:03:41 2006 John Ellis * main.c: Fix command line parser to work with any combination of files and/or folders on the command line. diff -r 56f62cdde8e0 -r 07773a3c5b29 ChangeLog --- a/ChangeLog Sun Oct 15 06:59:10 2006 +0000 +++ b/ChangeLog Sun Oct 15 08:06:14 2006 +0000 @@ -1,3 +1,8 @@ +Sun Oct 15 04:03:41 2006 John Ellis + + * main.c: Fix command line parser to work with any combination of files + and/or folders on the command line. + Sun Oct 15 02:50:22 2006 John Ellis * eu.po: Add Basque translation, diff -r 56f62cdde8e0 -r 07773a3c5b29 TODO --- a/TODO Sun Oct 15 06:59:10 2006 +0000 +++ b/TODO Sun Oct 15 08:06:14 2006 +0000 @@ -94,7 +94,7 @@ Minor (non blockers): ---------------------------------------------- - > allow multiple command line dirs to work as expected +d> allow multiple command line dirs to work as expected (ie contents of each are treated as given on command line) > allow editor commands to be interrupted (via SIGTERM?) diff -r 56f62cdde8e0 -r 07773a3c5b29 src/main.c --- a/src/main.c Sun Oct 15 06:59:10 2006 +0000 +++ b/src/main.c Sun Oct 15 08:06:14 2006 +0000 @@ -817,15 +817,15 @@ static gint startup_command_line_collection = FALSE; -static void parse_command_line_add_file(const gchar *new_path, gchar **path, gchar **file, +static void parse_command_line_add_file(const gchar *file_path, gchar **path, gchar **file, GList **list, GList **collection_list) { gchar *path_parsed; - path_parsed = g_strdup(new_path); + path_parsed = g_strdup(file_path); parse_out_relatives(path_parsed); - if (file_extension_match(new_path, ".gqv")) + if (file_extension_match(path_parsed, ".gqv")) { *collection_list = g_list_append(*collection_list, path_parsed); } @@ -833,8 +833,76 @@ { if (!*path) *path = remove_level_from_path(path_parsed); if (!*file) *file = g_strdup(path_parsed); - *list = g_list_append(*list, path_parsed); + *list = g_list_prepend(*list, path_parsed); + } +} + +static void parse_command_line_add_dir(const gchar *dir, gchar **path, gchar **file, + GList **list) +{ + GList *files = NULL; + gchar *path_parsed; + + path_parsed = g_strdup(dir); + parse_out_relatives(path_parsed); + + if (path_list(path_parsed, &files, NULL)) + { + GList *work; + + files = path_list_filter(files, FALSE); + files = path_list_sort(files); + + work = files; + while (work) + { + gchar *p; + + p = work->data; + if (!*path) *path = remove_level_from_path(p); + if (!*file) *file = g_strdup(p); + *list = g_list_prepend(*list, p); + + work = work->next; + } + + g_list_free(files); } + + g_free(path_parsed); +} + +static void parse_command_line_process_dir(const gchar *dir, gchar **path, gchar **file, + GList **list, gchar **first_dir) +{ + + if (!*list && !*first_dir) + { + *first_dir = g_strdup(dir); + } + else + { + if (*first_dir) + { + parse_command_line_add_dir(*first_dir, path, file, list); + g_free(*first_dir); + *first_dir = NULL; + } + parse_command_line_add_dir(dir, path, file, list); + } +} + +static void parse_command_line_process_file(const gchar *file_path, gchar **path, gchar **file, + GList **list, GList **collection_list, gchar **first_dir) +{ + + if (*first_dir) + { + parse_command_line_add_dir(*first_dir, path, file, list); + g_free(*first_dir); + *first_dir = NULL; + } + parse_command_line_add_file(file_path, path, file, list, collection_list); } static void parse_command_line(int argc, char *argv[], gchar **path, gchar **file, @@ -843,6 +911,7 @@ GList *list = NULL; GList *remote_list = NULL; gint remote_do = FALSE; + gchar *first_dir = NULL; if (argc > 1) { @@ -854,21 +923,23 @@ const gchar *cmd_line = argv[i]; gchar *cmd_all = concat_dir_and_file(base_dir, cmd_line); - if (!*path && cmd_line[0] == '/' && isdir(cmd_line)) + if (cmd_line[0] == '/' && isdir(cmd_line)) { - *path = g_strdup(cmd_line); + parse_command_line_process_dir(cmd_line, path, file, &list, &first_dir); } - else if (!*path && isdir(cmd_all)) + else if (isdir(cmd_all)) { - *path = g_strdup(cmd_all); + parse_command_line_process_dir(cmd_all, path, file, &list, &first_dir); } else if (cmd_line[0] == '/' && isfile(cmd_line)) { - parse_command_line_add_file(cmd_line, path, file, &list, collection_list); + parse_command_line_process_file(cmd_line, path, file, + &list, collection_list, &first_dir); } else if (isfile(cmd_all)) { - parse_command_line_add_file(cmd_all, path, file, &list, collection_list); + parse_command_line_process_file(cmd_all, path, file, + &list, collection_list, &first_dir); } else if (strcmp(cmd_line, "--debug") == 0) { @@ -979,6 +1050,15 @@ parse_out_relatives(*file); } + list = g_list_reverse(list); + + if (!*path && first_dir) + { + *path = first_dir; + first_dir = NULL; + } + g_free(first_dir); + if (remote_do) { gqview_remote_control(argv[0], remote_list, *path, list, *collection_list);