From: Bruno Haible Date: Fri, 7 Jan 2005 19:56:33 +0000 (+0000) Subject: Allow reading the PO file from stdin. X-Git-Tag: v0.14.2~200 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=228136492757e8e299f0e7f3ef75b76e2c3ce0ca;p=thirdparty%2Fgettext.git Allow reading the PO file from stdin. --- diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index 05096dcbe..e94e9250e 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,9 @@ +2005-01-07 Bruno Haible + + * gettext-po.c (po_file_read): Interpret "-" and "/dev/stdin" as + denoting stdin. + Suggested by Asgeir Frimannsson . + 2004-11-29 Bruno Haible * Makefile.am (libgettextpo_la_LDFLAGS): Add @LTLIBINTL@ @LTLIBICONV@. diff --git a/gettext-tools/src/gettext-po.c b/gettext-tools/src/gettext-po.c index 8092a5624..fafb3abc8 100644 --- a/gettext-tools/src/gettext-po.c +++ b/gettext-tools/src/gettext-po.c @@ -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 , 2003. This program is free software; you can redistribute it and/or modify @@ -27,6 +27,7 @@ #include #include #include +#include #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 = _(""); + 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 = _(""); + 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; }