Il giorno gio, 10/01/2008 alle 15.15 +0100, Alexander Larsson ha scritto: > It looks like what G_OPTION_ARG_FILENAME does is convert from locale to > utf8 on windows and just strcpy on unix, while ARG_STRING always > converts from locale to utf8. So, using string here is wrong, and > FILENAME is ok also for uris (as they are ascii-only).
OK, converted to G_OPTION_ARG_FILENAME > > IMHO could be better prepend the program name and the file name (this is > > the behavior of plain cat(1)) > > > > $ gvfs-cat smb://server/file.txt > > gvfs-cat: smb://server/file.txt: No such file or directory > > Yeah, that looks better. Done. The only issue is that now the actual output is something like: gvfs-cat: uri:///file/name.ext: error opening file: Error opening file: No such file or directory :-( Do I've to remove "error opening file" from gvfs-cat? > > PS of course could be interesting add some cat(1) options, such as -n > > (number all output lines), -E (display $ at end of each line), -T > > (display TAB characters as ^I) and -s (never more than one single blank > > line). OK to open a bug and add commented GOptionExtry copying switch > > and comments from `cat --help`? > > Well. You could also just pipe through cat if you need these? > Changed the note tip suggesting the pipe. Note 1: there was a perror("Error writing to stdout"), I changed to g_printerr Note 2: yeah, there are some wrong indentations I'll fix before commit.
Index: programs/Makefile.am =================================================================== --- programs/Makefile.am (revisione 1144) +++ programs/Makefile.am (copia locale) @@ -1,30 +1,31 @@ NULL = -INCLUDES = \ - -I$(top_srcdir) \ - -I$(top_builddir) \ - $(GLIB_CFLAGS) \ +INCLUDES = \ + -I$(top_srcdir) \ + -I$(top_builddir) \ + $(GLIB_CFLAGS) \ + -DGVFS_LOCALEDIR=\""$(localedir)"\" \ -DG_DISABLE_DEPRECATED -libraries = \ +libraries = \ $(GLIB_LIBS) -bin_PROGRAMS = \ - gvfs-mount \ - gvfs-cat \ - gvfs-save \ - gvfs-ls \ - gvfs-info \ - gvfs-trash \ - gvfs-rm \ - gvfs-copy \ - gvfs-move \ - gvfs-monitor-file \ - gvfs-monitor-dir \ +bin_PROGRAMS = \ + gvfs-mount \ + gvfs-cat \ + gvfs-save \ + gvfs-ls \ + gvfs-info \ + gvfs-trash \ + gvfs-rm \ + gvfs-copy \ + gvfs-move \ + gvfs-monitor-file \ + gvfs-monitor-dir \ $(NULL) -bin_SCRIPTS = \ - gvfs-less \ +bin_SCRIPTS = \ + gvfs-less \ $(NULL) gvfs_cat_SOURCES = gvfs-cat.c Index: programs/gvfs-cat.c =================================================================== --- programs/gvfs-cat.c (revisione 1144) +++ programs/gvfs-cat.c (copia locale) @@ -28,10 +28,14 @@ #include <errno.h> #include <glib.h> +#include <glib/gi18n.h> #include <gio/gio.h> +static gchar **locations = NULL; + static GOptionEntry entries[] = { + {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &locations, "locations", NULL}, { NULL } }; @@ -49,7 +53,10 @@ in = (GInputStream *)g_file_read (file, NULL, &error); if (in == NULL) { - g_printerr ("Error opening file: %s\n", error->message); + /* Translators: the first %s is the program name, the second one */ + /* is the URI of the file, the third is the error message. */ + g_printerr (_("%s: %s: error opening file: %s\n"), + g_get_prgname (), g_file_get_uri (file), error->message); g_error_free (error); return; } @@ -68,7 +75,10 @@ if (written == -1 && errno != EINTR) { - perror ("Error writing to stdout"); + /* Translators: the first %s is the program name, the second one */ + /* is the URI of the file. */ + g_printerr (_("%s: %s, error writing to stdout"), + g_get_prgname (), g_file_get_uri (file)); goto out; } res -= written; @@ -77,7 +87,10 @@ } else if (res < 0) { - g_printerr ("Error reading: %s\n", error->message); + /* Translators: the first %s is the program name, the second one */ + /* is the URI of the file, the third is the error message. */ + g_printerr (_("%s: %s: error reading: %s\n"), + g_get_prgname (), g_file_get_uri (file), error->message); g_error_free (error); error = NULL; break; @@ -91,7 +104,10 @@ close_res = g_input_stream_close (in, NULL, &error); if (!close_res) { - g_printerr ("Error closing: %s\n", error->message); + /* Translators: the first %s is the program name, the second one */ + /* is the URI of the file, the third is the error message. */ + g_printerr (_("%s: %s:error closing: %s\n"), + g_get_prgname (), g_file_get_uri (file), error->message); g_error_free (error); } } @@ -99,30 +115,63 @@ int main (int argc, char *argv[]) { - GError *error; - GOptionContext *context; + GError *error = NULL; + GOptionContext *context = NULL; GFile *file; - + gchar *summary; + setlocale (LC_ALL, ""); + bindtextdomain (GETTEXT_PACKAGE, GVFS_LOCALEDIR); + bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); + textdomain (GETTEXT_PACKAGE); + g_type_init (); - error = NULL; - context = g_option_context_new ("- output files at <location>"); + /* Translators: this message will appear immediately after the */ + /* usage string - Usage: COMMAND [OPTION]... <THIS_MESSAGE> */ + context = g_option_context_new (_("LOCATION... - concatenate LOCATIONS to standard output")); + + /* Translators: this message will appear after the usage string */ + /* and before the list of options. */ + summary = g_strconcat (_("Concatenate files at locations and print to the " + "standard output. Works just like the traditional " + "cat utility, but using gvfs location instead " + "local files: for example you can use something " + "like smb://server/resource/file.txt as location " + "to concatenate."), + "\n\n", + _("Note: just pipe through cat if you need its " + "formatting option like -n, -T or other."), + NULL); + + g_option_context_set_summary (context, summary); + g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); g_option_context_parse (context, &argc, &argv, &error); + g_option_context_free (context); - - if (argc > 1) + g_free (summary); + + if (!locations) { - int i; - - for (i = 1; i < argc; i++) { - file = g_file_new_for_commandline_arg (argv[i]); - cat (file); - g_object_unref (file); - } + /* Translators: the %s is the program name. This error message */ + /* means the user is calling gvfs-cat without any argument. */ + g_printerr (_("%s: missing locations"), g_get_prgname ()); + g_printerr ("\n"); + g_printerr (_("Try \"%s --help\" for more information."), + g_get_prgname ()); + g_printerr ("\n"); + return 1; } + int i = 0; + + do { + file = g_file_new_for_commandline_arg (locations[i]); + cat (file); + g_object_unref (file); + } while (locations[++i]!=NULL) ; + return 0; } Index: po/POTFILES.in =================================================================== --- po/POTFILES.in (revisione 1144) +++ po/POTFILES.in (copia locale) @@ -57,3 +57,4 @@ hal/ghalmount.c hal/ghalvolume.c hal/ghalvolumemonitor.c +programs/gvfs-cat.c
_______________________________________________ gnome-vfs-list mailing list gnome-vfs-list@gnome.org http://mail.gnome.org/mailman/listinfo/gnome-vfs-list