Index: gedit.c =================================================================== RCS file: /cvs/gnome/gedit/gedit/Attic/gedit.c,v retrieving revision 1.125.2.23 diff -u -p -r1.125.2.23 gedit.c --- gedit.c 17 Oct 2005 16:26:31 -0000 1.125.2.23 +++ gedit.c 6 Dec 2005 10:08:55 -0000 @@ -67,89 +67,82 @@ static gboolean new_window_option = FALS static gboolean new_document_option = FALSE; static GSList *file_list = NULL; -static const struct poptOption options [] = +static const GOptionEntry option_entries[] = { - { "encoding", '\0', POPT_ARG_STRING, &encoding_charset, 0, - N_("Set the character encoding to be used to open the files listed on the command line"), NULL }, + { "encoding", '\0', 0, G_OPTION_ARG_STRING, &encoding_charset, + N_("Set the character encoding to be used to open the files listed on the command line"), + N_("encoding") }, + + { "new-window", '\0', 0, G_OPTION_ARG_NONE, &new_window_option, + N_("Create a new toplevel window in an existing instance of gedit"), + NULL }, + + { "new-document", '\0', 0, G_OPTION_ARG_NONE, &new_document_option, + N_("Create a new document in an existing instance of gedit"), + NULL }, - { "new-window", '\0', POPT_ARG_NONE, &new_window_option, 0, - N_("Create a new toplevel window in an existing instance of gedit"), NULL }, - - { "new-document", '\0', POPT_ARG_NONE, &new_document_option, 0, - N_("Create a new document in an existing instance of gedit"), NULL }, - - {NULL, '\0', 0, NULL, 0} + {NULL, } }; +/* process options not handled with GOption */ static void -gedit_get_command_line_data (GnomeProgram *program) +gedit_process_command_line (int argc, char *argv[]) { - GValue value = { 0, }; - poptContext ctx; - gchar **args; - - g_value_init (&value, G_TYPE_POINTER); - g_object_get_property (G_OBJECT (program), - GNOME_PARAM_POPT_CONTEXT, - &value); - ctx = g_value_get_pointer (&value); - g_value_unset (&value); + gint i; - args = (gchar **) poptGetArgs(ctx); + if (argv == NULL) + return; - if (args) + /* process uri list */ + for (i = 1; i < argc; ++i) { - gint i; - - for (i = 0; args[i]; i++) + if (*argv[i] == '+') { - if (*args[i] == '+') - { - if (*(args[i] + 1) == '\0') - /* goto the last line of the document */ - line_position = G_MAXINT; - else - line_position = atoi (args[i] + 1); - } + if (*(argv[i] + 1) == '\0') + /* goto the last line of the document */ + line_position = G_MAXINT; else - { - gchar *uri; - gchar *canonical_uri; - - /* Note for the future: - * - * paolo: and flame whoever tells - * you that file:///gnome/test_files/hëllò - * doesn't work --- that's not a valid URI - * - * federico: well, another solution that - * does not requires patch to _from_shell_args - * is to check that the string returned by it - * contains only ASCII chars - * paolo: hmmmm, isn't there - * gnome_vfs_is_uri_valid() or something? - * : I will use gedit_utils_is_valid_uri () - * - */ - - uri = gnome_vfs_make_uri_from_shell_arg (args[i]); - canonical_uri = gnome_vfs_make_uri_canonical (uri); - g_free (uri); - - g_print ("URI: %s\n", canonical_uri); - - if (gedit_utils_is_valid_uri (canonical_uri)) - file_list = g_slist_prepend (file_list, - canonical_uri); - else - g_print (_("%s: malformed file name or URI.\n"), - args[i]); - } + line_position = atoi (argv[i] + 1); } + else + { + gchar *uri; + gchar *canonical_uri; - file_list = g_slist_reverse (file_list); + /* Note for the future: + * + * paolo: and flame whoever tells + * you that file:///gnome/test_files/hëllò + * doesn't work --- that's not a valid URI + * + * federico: well, another solution that + * does not requires patch to _from_shell_args + * is to check that the string returned by it + * contains only ASCII chars + * paolo: hmmmm, isn't there + * gnome_vfs_is_uri_valid() or something? + * : I will use gedit_utils_is_valid_uri () + * + */ + + uri = gnome_vfs_make_uri_from_shell_arg (argv[i]); + canonical_uri = gnome_vfs_make_uri_canonical (uri); + g_free (uri); + + g_print ("URI: %s\n", canonical_uri); + + if (gedit_utils_is_valid_uri (canonical_uri)) + file_list = g_slist_prepend (file_list, + canonical_uri); + else + g_print (_("%s: malformed file name or URI.\n"), + argv[i]); + } } + file_list = g_slist_reverse (file_list); + + /* process the encoding */ if (encoding_charset) { encoding = gedit_encoding_get_from_charset (encoding_charset); @@ -160,8 +153,6 @@ gedit_get_command_line_data (GnomeProgra g_free (encoding_charset); encoding_charset = NULL; } - - poptFreeContext (ctx); } static guint32 @@ -402,6 +393,7 @@ send_bacon_message (void) int main (int argc, char *argv[]) { + GOptionContext *context; GnomeProgram *program; GeditWindow *window; GeditApp *app; @@ -418,12 +410,17 @@ main (int argc, char *argv[]) startup_timestamp = get_startup_timestamp(); + context = g_option_context_new (NULL); + g_option_context_add_main_entries (context, + option_entries, + GETTEXT_PACKAGE); + gedit_debug_message (DEBUG_APP, "Run gnome_program_init"); - + /* Initialize gnome program */ program = gnome_program_init ("gedit", VERSION, LIBGNOMEUI_MODULE, argc, argv, - GNOME_PARAM_POPT_TABLE, options, + GNOME_PARAM_GOPTION_CONTEXT, context, GNOME_PARAM_HUMAN_READABLE_NAME, _("Text Editor"), GNOME_PARAM_APP_DATADIR, DATADIR, @@ -431,6 +428,8 @@ main (int argc, char *argv[]) gedit_debug_message (DEBUG_APP, "Done gnome_program_init"); + g_option_context_free (context); + /* Must be called after gnome_program_init to avoid problem with the * translation of --help messages */ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); @@ -445,7 +444,7 @@ main (int argc, char *argv[]) { gedit_debug_message (DEBUG_APP, "I'm a client"); - gedit_get_command_line_data (program); + gedit_process_command_line (argc, argv); send_bacon_message (); @@ -500,7 +499,7 @@ main (int argc, char *argv[]) if (!restored) { gedit_debug_message (DEBUG_APP, "Analyze command line data"); - gedit_get_command_line_data (program); + gedit_process_command_line (argc, argv); gedit_debug_message (DEBUG_APP, "Get default app"); app = gedit_app_get_default ();