]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Allow reading the PO file from stdin.
authorBruno Haible <bruno@clisp.org>
Fri, 7 Jan 2005 19:56:33 +0000 (19:56 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:11:58 +0000 (12:11 +0200)
gettext-tools/src/ChangeLog
gettext-tools/src/gettext-po.c

index 05096dcbebf0bbaa34158d6627ee9d8a32eb94f5..e94e9250ef9f5d448fdea2e80cde3609c0ab0ce8 100644 (file)
@@ -1,3 +1,9 @@
+2005-01-07  Bruno Haible  <bruno@clisp.org>
+
+       * gettext-po.c (po_file_read): Interpret "-" and "/dev/stdin" as
+       denoting stdin.
+       Suggested by Asgeir Frimannsson <asgeirf@redhat.com>.
+
 2004-11-29  Bruno Haible  <bruno@clisp.org>
 
        * Makefile.am (libgettextpo_la_LDFLAGS): Add @LTLIBINTL@ @LTLIBICONV@.
index 8092a56249767c83d91faf2bc90b10c530aa79d6..fafb3abc8ff816c16dc25af0ae91545e19c5cb63 100644 (file)
@@ -1,5 +1,5 @@
 /* Public API for GNU gettext PO files.
-   Copyright (C) 2003-2004 Free Software Foundation, Inc.
+   Copyright (C) 2003-2005 Free Software Foundation, Inc.
    Written by Bruno Haible <bruno@clisp.org>, 2003.
 
    This program is free software; you can redistribute it and/or modify
@@ -27,6 +27,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
+#include <string.h>
 
 #include "message.h"
 #include "xalloc.h"
@@ -88,9 +89,17 @@ po_file_read (const char *filename, po_error_handler_t handler)
   FILE *fp;
   po_file_t file;
 
-  fp = fopen (filename, "r");
-  if (fp == NULL)
-    return NULL;
+  if (strcmp (filename, "-") == 0 || strcmp (filename, "/dev/stdin") == 0)
+    {
+      filename = _("<stdin>");
+      fp = stdin;
+    }
+  else
+    {
+      fp = fopen (filename, "r");
+      if (fp == NULL)
+       return NULL;
+    }
 
   /* Establish error handler around read_po().  */
   po_error             = handler->error;
@@ -110,7 +119,8 @@ po_file_read (const char *filename, po_error_handler_t handler)
   po_multiline_warning = multiline_warning;
   po_multiline_error   = multiline_error;
 
-  fclose (fp);
+  if (fp != stdin)
+    fclose (fp);
   return file;
 }
 #undef po_file_read
@@ -122,9 +132,17 @@ po_file_read (const char *filename)
   FILE *fp;
   po_file_t file;
 
-  fp = fopen (filename, "r");
-  if (fp == NULL)
-    return NULL;
+  if (strcmp (filename, "-") == 0 || strcmp (filename, "/dev/stdin") == 0)
+    {
+      filename = _("<stdin>");
+      fp = stdin;
+    }
+  else
+    {
+      fp = fopen (filename, "r");
+      if (fp == NULL)
+       return NULL;
+    }
 
   file = (struct po_file *) xmalloc (sizeof (struct po_file));
   file->real_filename = filename;
@@ -132,7 +150,8 @@ po_file_read (const char *filename)
   file->mdlp = read_po (fp, file->real_filename, file->logical_filename);
   file->domains = NULL;
 
-  fclose (fp);
+  if (fp != stdin)
+    fclose (fp);
   return file;
 }