]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Start unifying po_scan and po_scan_file.
authorBruno Haible <bruno@clisp.org>
Mon, 28 Apr 2003 11:10:34 +0000 (11:10 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:10:24 +0000 (12:10 +0200)
gettext-tools/src/ChangeLog
gettext-tools/src/open-po.c
gettext-tools/src/open-po.h
gettext-tools/src/po-lex.c
gettext-tools/src/po-lex.h
gettext-tools/src/read-po-abstract.c

index 7369f47376dad57777108890d8a28933bb6b68bf..587013fa9feb417e5df8eb6f4a28e91859fa6b6c 100644 (file)
@@ -1,3 +1,15 @@
+2003-04-20  Bruno Haible  <bruno@clisp.org>
+
+       * open-po.h (open_po_file): Add argument 'exit_on_error'.
+       * open-po.c (try_open_po_file): Renamed from open_po_file.
+       (open_po_file): New function.
+       * po-lex.h (lex_end): Change return type to void.
+       (lex_open, lex_close): Remove declarations.
+       * po-lex.c (lex_end): Change return type to void.
+       (lex_open, lex_close): Remove functions.
+       * read-po-abstract.c (po_scan_file): Inline lex_open and lex_close.
+       Reuse po_scan code.
+
 2003-04-14  Bruno Haible  <bruno@clisp.org>
 
        * hostname.c (usage): Split strings: use one string per option
index 70a1e31ae74f00e3b3f1745b31e6b6cbb62df279..8e73081756fe5aa2171965f2ad2f2128e19f37ef 100644 (file)
@@ -1,5 +1,5 @@
 /* open-po - search for .po file along search path list and open for reading
-   Copyright (C) 1995-1996, 2000-2002 Free Software Foundation, Inc.
+   Copyright (C) 1995-1996, 2000-2003 Free Software Foundation, Inc.
    Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, April 1995.
 
    This program is free software; you can redistribute it and/or modify
@@ -24,6 +24,7 @@
 #include "open-po.h"
 
 #include <errno.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -31,6 +32,7 @@
 #include "dir-list.h"
 #include "pathname.h"
 #include "xmalloc.h"
+#include "error.h"
 #include "gettext.h"
 
 #define _(str) gettext (str)
 /* This macro is used to determine the number of elements in an erray.  */
 #define SIZEOF(a) (sizeof(a)/sizeof(a[0]))
 
-/* Open the input file with the name INPUT_NAME.  The ending .po is added
-   if necessary.  If INPUT_NAME is not an absolute file name and the file is
-   not found, the list of directories in "dir-list.h" is searched.  The
-   file's pathname is returned in *REAL_FILE_NAME_P, for error message
-   purposes.  */
-FILE *
-open_po_file (const char *input_name, char **real_file_name_p)
+static FILE *
+try_open_po_file (const char *input_name, char **real_file_name_p)
 {
   static const char *extension[] = { "", ".po", ".pot", };
   char *file_name;
@@ -104,3 +101,21 @@ open_po_file (const char *input_name, char **real_file_name_p)
   errno = ENOENT;
   return NULL;
 }
+
+/* Open the input file with the name INPUT_NAME.  The ending .po is added
+   if necessary.  If INPUT_NAME is not an absolute file name and the file is
+   not found, the list of directories in "dir-list.h" is searched.  The
+   file's pathname is returned in *REAL_FILE_NAME_P, for error message
+   purposes.  */
+FILE *
+open_po_file (const char *input_name, char **real_file_name_p,
+             bool exit_on_error)
+{
+  FILE *fp = try_open_po_file (input_name, real_file_name_p);
+
+  if (fp == NULL && exit_on_error)
+    error (EXIT_FAILURE, errno,
+          _("error while opening \"%s\" for reading"), *real_file_name_p);
+
+  return fp;
+}
index 1a4d25375d7cb5d124deb7d90ea50c89be194cb7..734f8f687ce580f1bbd62babbaeaaaa47a568543 100644 (file)
@@ -1,5 +1,5 @@
 /* Opening PO files.
-   Copyright (C) 1995-1997, 2000-2002 Free Software Foundation, Inc.
+   Copyright (C) 1995-1997, 2000-2003 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -18,6 +18,7 @@
 #ifndef _OPEN_PO_H
 #define _OPEN_PO_H
 
+#include <stdbool.h>
 #include <stdio.h>
 
 /* Open the input file with the name INPUT_NAME.  The ending .po is added
@@ -25,6 +26,7 @@
    not found, the list of directories in "dir-list.h" is searched.  The
    file's pathname is returned in *REAL_FILE_NAME_P, for error message
    purposes.  */
-extern FILE *open_po_file (const char *input_name, char **real_file_name_p);
+extern FILE *open_po_file (const char *input_name, char **real_file_name_p,
+                          bool exit_on_error);
 
 #endif /* _OPEN_PO_H */
index d621c45ec36d1fb17e0df892b778c6272b048e2c..d3aaf324c2c30a27d6ceff709481a436dcf65f63 100644 (file)
@@ -45,7 +45,6 @@
 #include "xmalloc.h"
 #include "exit.h"
 #include "error.h"
-#include "open-po.h"
 #include "str-list.h"
 #include "po-gram-gen2.h"
 
@@ -616,18 +615,15 @@ lex_start (FILE *fp, const char *real_filename, const char *logical_filename)
 }
 
 /* Terminate lexical analysis.  */
-FILE *
+void
 lex_end ()
 {
-  FILE *fp;
-
   if (error_message_count > 0)
     error (EXIT_FAILURE, 0,
           ngettext ("found %d fatal error", "found %d fatal errors",
                     error_message_count),
           error_message_count);
 
-  fp = mbf->fp;
   mbf->fp = NULL;
   gram_pos.file_name = NULL;
   gram_pos.line_number = 0;
@@ -636,34 +632,6 @@ lex_end ()
   error_message_count = 0;
   po_lex_obsolete = false;
   po_lex_charset_close ();
-
-  return fp;
-}
-
-
-/* Open the PO file FNAME and prepare its lexical analysis.  */
-void
-lex_open (const char *fname)
-{
-  char *real_filename;
-  FILE *fp = open_po_file (fname, &real_filename);
-  if (!fp)
-    error (EXIT_FAILURE, errno,
-          _("error while opening \"%s\" for reading"), fname);
-
-  lex_start (fp, real_filename, fname);
-}
-
-/* Terminate lexical analysis and close the current PO file.  */
-void
-lex_close ()
-{
-  FILE *fp;
-
-  fp = lex_end ();
-
-  if (fp != stdin)
-    fclose (fp);
 }
 
 
index 97f4d37be3df7bb675887f6fa531098b4d3944f3..a7934001b67affabd79e897877182469d1c0339f 100644 (file)
@@ -50,13 +50,7 @@ extern void lex_start (FILE *fp, const char *real_filename,
                       const char *logical_filename);
 
 /* Terminate lexical analysis.  */
-extern FILE *lex_end (void);
-
-/* Open the PO file FNAME and prepare its lexical analysis.  */
-extern void lex_open (const char *fname);
-
-/* Terminate lexical analysis and close the current PO file.  */
-extern void lex_close (void);
+extern void lex_end (void);
 
 /* Return the next token in the PO file.  The return codes are defined
    in "po-gram-gen2.h".  Associated data is put in 'po_gram_lval.  */
index 666f98c6bc19b6ed65d52f40e56a0a697899452a..2e5be2e8d3014fad6db7b06a6baefdd7be90cc5b 100644 (file)
@@ -31,6 +31,7 @@
 #include "po-charset.h"
 #include "po-gram.h"
 #include "po-hash.h"
+#include "open-po.h"
 #include "xmalloc.h"
 
 /* Local variables.  */
@@ -172,11 +173,13 @@ void
 po_scan_file (abstract_po_reader_ty *pop, const char *filename)
 {
   /* Open the file and parse it.  */
-  lex_open (filename);
-  po_scan_start (pop);
-  po_gram_parse ();
-  po_scan_end (pop);
-  lex_close ();
+  char *real_filename;
+  FILE *fp = open_po_file (filename, &real_filename, true);
+
+  po_scan (pop, fp, real_filename, filename);
+
+  if (fp != stdin)
+    fclose (fp);
 }