gvfs r1149 - in trunk: . po programs



Author: lferrett
Date: Fri Jan 18 10:07:14 2008
New Revision: 1149
URL: http://svn.gnome.org/viewvc/gvfs?rev=1149&view=rev

Log:
2008-01-18  Luca Ferretti  <elle uca libero it>

	* programs/Makefile.am:
	* programs/gvfs-cat.c: (cat), (main):
	Add i18n/l10n to gvfs-cat, plus indentation. For details see
	http://mail.gnome.org/archives/gnome-vfs-list/2008-January/msg00020.html
	
	po/POTFILES.in: Added programs/gvfs-cat.c



Modified:
   trunk/ChangeLog
   trunk/po/ChangeLog
   trunk/po/POTFILES.in
   trunk/programs/Makefile.am
   trunk/programs/gvfs-cat.c

Modified: trunk/po/POTFILES.in
==============================================================================
--- trunk/po/POTFILES.in	(original)
+++ trunk/po/POTFILES.in	Fri Jan 18 10:07:14 2008
@@ -57,3 +57,4 @@
 hal/ghalmount.c
 hal/ghalvolume.c
 hal/ghalvolumemonitor.c
+programs/gvfs-cat.c

Modified: trunk/programs/Makefile.am
==============================================================================
--- trunk/programs/Makefile.am	(original)
+++ trunk/programs/Makefile.am	Fri Jan 18 10:07:14 2008
@@ -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

Modified: trunk/programs/gvfs-cat.c
==============================================================================
--- trunk/programs/gvfs-cat.c	(original)
+++ trunk/programs/gvfs-cat.c	Fri Jan 18 10:07:14 2008
@@ -1,3 +1,5 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+
 /* GIO - GLib Input, Output and Streaming Library
  * 
  * Copyright (C) 2006-2007 Red Hat, Inc.
@@ -28,70 +30,87 @@
 #include <errno.h>
 
 #include <glib.h>
+#include <glib/gi18n.h>
 #include <gio/gio.h>
 
-static GOptionEntry entries[] = 
-{
-	{ NULL }
+static gchar **locations = NULL;
+
+static GOptionEntry entries[] = {
+  {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &locations, "locations", NULL},
+  {NULL}
 };
 
 static void
-cat (GFile *file)
+cat (GFile * file)
 {
   GInputStream *in;
-  char buffer[1024*8 + 1];
+  char buffer[1024 * 8 + 1];
   char *p;
   gssize res;
   gboolean close_res;
   GError *error;
-  
+
   error = NULL;
-  in = (GInputStream *)g_file_read (file, NULL, &error);
+  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;
     }
 
   while (1)
     {
-      res = g_input_stream_read (in, buffer, sizeof (buffer) - 1, NULL, &error);
+      res =
+        g_input_stream_read (in, buffer, sizeof (buffer) - 1, NULL, &error);
       if (res > 0)
-	{
-	  ssize_t written;
+        {
+          ssize_t written;
 
-	  p = buffer;
-	  while (res > 0)
-	    {
-	      written = write (STDOUT_FILENO, p, res);
-	      
-	      if (written == -1 && errno != EINTR)
-		{
-		  perror ("Error writing to stdout");
-		  goto out;
-		}
-	      res -= written;
-	      p += written;
-	    }
-	}
+          p = buffer;
+          while (res > 0)
+            {
+              written = write (STDOUT_FILENO, p, res);
+
+              if (written == -1 && errno != EINTR)
+                {
+                  /* 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;
+              p += written;
+            }
+        }
       else if (res < 0)
-	{
-	  g_printerr ("Error reading: %s\n", error->message);
-	  g_error_free (error);
-	  error = NULL;
-	  break;
-	}
+        {
+          /* 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;
+        }
       else if (res == 0)
-	break;
+        break;
     }
 
  out:
-  
+
   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 +118,66 @@
 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)
+    {
+      /* 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
     {
-      int i;
-      
-      for (i = 1; i < argc; i++) {
-	file = g_file_new_for_commandline_arg (argv[i]);
-	cat (file);
-	g_object_unref (file);
-      }
+      file = g_file_new_for_commandline_arg (locations[i]);
+      cat (file);
+      g_object_unref (file);
     }
+  while (locations[++i] != NULL);
 
   return 0;
 }



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