From: Bruno Haible Date: Mon, 28 Apr 2003 11:10:34 +0000 (+0000) Subject: Start unifying po_scan and po_scan_file. X-Git-Tag: v0.12~65 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=57ed96766db913c3b2c0dbdb07ce0737dd6d0e82;p=thirdparty%2Fgettext.git Start unifying po_scan and po_scan_file. --- diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index 7369f4737..587013fa9 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,15 @@ +2003-04-20 Bruno Haible + + * 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 * hostname.c (usage): Split strings: use one string per option diff --git a/gettext-tools/src/open-po.c b/gettext-tools/src/open-po.c index 70a1e31ae..8e7308175 100644 --- a/gettext-tools/src/open-po.c +++ b/gettext-tools/src/open-po.c @@ -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 , April 1995. This program is free software; you can redistribute it and/or modify @@ -24,6 +24,7 @@ #include "open-po.h" #include +#include #include #include #include @@ -31,6 +32,7 @@ #include "dir-list.h" #include "pathname.h" #include "xmalloc.h" +#include "error.h" #include "gettext.h" #define _(str) gettext (str) @@ -38,13 +40,8 @@ /* 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; +} diff --git a/gettext-tools/src/open-po.h b/gettext-tools/src/open-po.h index 1a4d25375..734f8f687 100644 --- a/gettext-tools/src/open-po.h +++ b/gettext-tools/src/open-po.h @@ -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 #include /* 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 */ diff --git a/gettext-tools/src/po-lex.c b/gettext-tools/src/po-lex.c index d621c45ec..d3aaf324c 100644 --- a/gettext-tools/src/po-lex.c +++ b/gettext-tools/src/po-lex.c @@ -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); } diff --git a/gettext-tools/src/po-lex.h b/gettext-tools/src/po-lex.h index 97f4d37be..a7934001b 100644 --- a/gettext-tools/src/po-lex.h +++ b/gettext-tools/src/po-lex.h @@ -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. */ diff --git a/gettext-tools/src/read-po-abstract.c b/gettext-tools/src/read-po-abstract.c index 666f98c6b..2e5be2e8d 100644 --- a/gettext-tools/src/read-po-abstract.c +++ b/gettext-tools/src/read-po-abstract.c @@ -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); }