+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
/* 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
#include "open-po.h"
#include <errno.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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;
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;
+}
/* 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
#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
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 */
#include "xmalloc.h"
#include "exit.h"
#include "error.h"
-#include "open-po.h"
#include "str-list.h"
#include "po-gram-gen2.h"
}
/* 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;
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);
}
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. */
#include "po-charset.h"
#include "po-gram.h"
#include "po-hash.h"
+#include "open-po.h"
#include "xmalloc.h"
/* Local variables. */
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);
}