[gedit] Command line option to list supported encodings



commit 0e342910137b7b393db893c994a3c0d262435ab0
Author: Paolo Borelli <porelli gnome org>
Date:   Sat May 16 23:14:42 2009 +0200

    Command line option to list supported encodings
    
    Add a --list-encodings command line option to print a list of the
    encodings supported by the --encoding option. Fixes bug #570585.
---
 data/gedit.1  |    3 +++
 gedit/gedit.c |   35 +++++++++++++++++++++++++++--------
 2 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/data/gedit.1 b/data/gedit.1
index 71b0dab..309c5e7 100644
--- a/data/gedit.1
+++ b/data/gedit.1
@@ -55,6 +55,9 @@ of a webpage to
 like "http://www.gnome.org";, or load a file from a FTP server,
 like "ftp://ftp.gnome.org/robots.txt";.
 .TP
+\fB\-\-list-encodings\fR
+Display list of possible values for the encoding option and exit
+.TP
 \fB\-\-version\fR
 Output version information and exit
 
diff --git a/gedit/gedit.c b/gedit/gedit.c
index 0f20ec8..d9633d5 100644
--- a/gedit/gedit.c
+++ b/gedit/gedit.c
@@ -76,14 +76,6 @@ static guint32 startup_timestamp = 0;
 static BaconMessageConnection *connection;
 #endif
 
-static void
-show_version_and_quit (void)
-{
-	g_print ("%s - Version %s\n", g_get_application_name (), VERSION);
-
-	exit (0);
-}
-
 /* command line */
 static gint line_position = 0;
 static gchar *encoding_charset = NULL;
@@ -93,6 +85,30 @@ static gboolean new_document_option = FALSE;
 static gchar **remaining_args = NULL;
 static GSList *file_list = NULL;
 
+static void
+show_version_and_quit (void)
+{
+	g_print ("%s - Version %s\n", g_get_application_name (), VERSION);
+
+	exit (0);
+}
+
+static void
+list_encodings_and_quit (void)
+{
+	gint i = 0;
+	const GeditEncoding *enc;
+
+	while ((enc = gedit_encoding_get_from_index (i)) != NULL) 
+	{
+		g_print ("%s\n", gedit_encoding_get_charset (enc));
+
+		++i;
+	}
+
+	exit (0);
+}
+
 static const GOptionEntry options [] =
 {
 	{ "version", 'V', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
@@ -101,6 +117,9 @@ static const GOptionEntry options [] =
 	{ "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")},
 
+	{ "list-encodings", '\0', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
+	  list_encodings_and_quit, N_("Display list of possible values for the encoding option"), NULL},
+
 	{ "new-window", '\0', 0, G_OPTION_ARG_NONE, &new_window_option,
 	  N_("Create a new toplevel window in an existing instance of gedit"), NULL },
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]