diff options
-rw-r--r-- | src/ChangeLog | 18 | ||||
-rw-r--r-- | src/Makefile.am | 9 | ||||
-rw-r--r-- | src/file-list.c | 93 | ||||
-rw-r--r-- | src/file-list.h | 29 | ||||
-rw-r--r-- | src/msgcat.c | 64 | ||||
-rw-r--r-- | src/msgcomm.c | 65 | ||||
-rw-r--r-- | src/xgettext.c | 63 |
7 files changed, 151 insertions, 190 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 65992f4..1c3d548 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,21 @@ +2001-07-26 Bruno Haible <haible@clisp.cons.org> + + * file-list.h: New file. + * file-list.c: New file, extracted from msgcomm.c. + * msgcat.c: Include file-list.h. + (main): Call read_names_from_file instead of read_name_from_file. + (read_name_from_file): Remove function. + * msgcomm.c: Include file-list.h. + (main): Call read_names_from_file instead of read_name_from_file. + (read_name_from_file): Remove function. + * xgettext.c: Include file-list.h. + (main): Call read_names_from_file instead of read_name_from_file. + (read_name_from_file): Remove function. + * Makefile.am (noinst_HEADERS): Add file-list.h. + (xgettext_SOURCES): Add file-list.c. + (msgcat_SOURCES): Likewise. + (msgcomm_SOURCES): Likewise. + 2001-07-23 Bruno Haible <haible@clisp.cons.org> * msgcomm.c: Assume <limits.h> exists. diff --git a/src/Makefile.am b/src/Makefile.am index 31fbea2..8082cc0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -25,7 +25,8 @@ msgcat msgcomm msgconv msgen msgexec msggrep msguniq noinst_HEADERS = pos.h message.h po-gram.h po-hash.h po-charset.h po-lex.h \ po.h open-po.h read-po.h str-list.h write-po.h xget-lex.h dir-list.h \ -po-gram-gen.h po-hash-gen.h msgl-charset.h msgl-iconv.h msgl-ascii.h msgl-cat.h +file-list.h po-gram-gen.h po-hash-gen.h msgl-charset.h msgl-iconv.h \ +msgl-ascii.h msgl-cat.h EXTRA_DIST = FILES @@ -52,13 +53,13 @@ msgl-ascii.c msgunfmt_SOURCES = message.c msgunfmt.c str-list.c write-po.c msgl-ascii.c xgettext_SOURCES = message.c open-po.c po-gram-gen.y po-hash-gen.y \ po-charset.c po-lex.c po.c str-list.c xget-lex.c xgettext.c dir-list.c \ -write-po.c msgl-ascii.c +write-po.c msgl-ascii.c file-list.c msgcat_SOURCES = msgcat.c message.c open-po.c po-gram-gen.y po-hash-gen.y \ po-charset.c po-lex.c po.c read-po.c str-list.c dir-list.c write-po.c \ -msgl-ascii.c msgl-iconv.c msgl-cat.c +msgl-ascii.c msgl-iconv.c msgl-cat.c file-list.c msgcomm_SOURCES = msgcomm.c message.c open-po.c po-gram-gen.y po-hash-gen.y \ po-charset.c po-lex.c po.c read-po.c str-list.c dir-list.c write-po.c \ -msgl-ascii.c msgl-iconv.c msgl-cat.c +msgl-ascii.c msgl-iconv.c msgl-cat.c file-list.c msgconv_SOURCES = msgconv.c message.c open-po.c po-gram-gen.y po-hash-gen.y \ po-charset.c po-lex.c po.c read-po.c str-list.c dir-list.c write-po.c \ msgl-ascii.c msgl-iconv.c diff --git a/src/file-list.c b/src/file-list.c new file mode 100644 index 0000000..1cffa56 --- /dev/null +++ b/src/file-list.c @@ -0,0 +1,93 @@ +/* Reading file lists. + Copyright (C) 1995-1998, 2000, 2001 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 + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "file-list.h" +#include "str-list.h" +#include "error.h" +#include "getline.h" +#include "libgettext.h" + +/* A convenience macro. I don't like writing gettext() every time. */ +#define _(str) gettext (str) + + +/* Read list of filenames from a file. */ +string_list_ty * +read_names_from_file (file_name) + const char *file_name; +{ + size_t line_len = 0; + char *line_buf = NULL; + FILE *fp; + string_list_ty *result; + + if (strcmp (file_name, "-") == 0) + fp = stdin; + else + { + fp = fopen (file_name, "r"); + if (fp == NULL) + error (EXIT_FAILURE, errno, + _("error while opening \"%s\" for reading"), file_name); + } + + result = string_list_alloc (); + + while (!feof (fp)) + { + /* Read next line from file. */ + int len = getline (&line_buf, &line_len, fp); + + /* In case of an error leave loop. */ + if (len < 0) + break; + + /* Remove trailing '\n' and trailing whitespace. */ + if (len > 0 && line_buf[len - 1] == '\n') + line_buf[--len] = '\0'; + while (len > 0 + && (line_buf[len - 1] == ' ' + || line_buf[len - 1] == '\t' + || line_buf[len - 1] == '\r')) + line_buf[--len] = '\0'; + + /* Test if we have to ignore the line. */ + if (*line_buf == '\0' || *line_buf == '#') + continue; + + string_list_append_unique (result, line_buf); + } + + /* Free buffer allocated through getline. */ + if (line_buf != NULL) + free (line_buf); + + /* Close input stream. */ + if (fp != stdin) + fclose (fp); + + return result; +} diff --git a/src/file-list.h b/src/file-list.h new file mode 100644 index 0000000..3326c7f --- /dev/null +++ b/src/file-list.h @@ -0,0 +1,29 @@ +/* Reading file lists. + Copyright (C) 2001 Free Software Foundation, Inc. + Written by Bruno Haible <haible@clisp.cons.org>, 2001. + + 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 + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +#ifndef _FILE_LIST_H +#define _FILE_LIST_H + +#include "str-list.h" + +/* Read list of filenames from a file. + One filename per line. Lines starting with # and whitespace lines are + ignored. Trailing whitespace is removed. */ +extern string_list_ty *read_names_from_file PARAMS ((const char *file_name)); + +#endif /* _FILE_LIST_H */ diff --git a/src/msgcat.c b/src/msgcat.c index 6b7adb1..80a4f18 100644 --- a/src/msgcat.c +++ b/src/msgcat.c @@ -21,7 +21,6 @@ # include "config.h" #endif -#include <errno.h> #include <getopt.h> #include <limits.h> #include <stdio.h> @@ -30,6 +29,7 @@ #include "dir-list.h" #include "str-list.h" +#include "file-list.h" #include "error.h" #include "progname.h" #include "message.h" @@ -77,7 +77,6 @@ static const struct option long_options[] = /* Prototypes for local functions. */ static void usage PARAMS ((int status)); -static string_list_ty *read_name_from_file PARAMS ((const char *file_name)); int @@ -249,7 +248,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ /* Determine list of files we have to process. */ if (files_from != NULL) - file_list = read_name_from_file (files_from); + file_list = read_names_from_file (files_from); else file_list = string_list_alloc (); /* Append names from command line. */ @@ -373,62 +372,3 @@ Informative output:\n\ exit (status); } - - -/* Read list of files to process from file. */ -static string_list_ty * -read_name_from_file (file_name) - const char *file_name; -{ - size_t line_len = 0; - char *line_buf = NULL; - FILE *fp; - string_list_ty *result; - - if (strcmp (file_name, "-") == 0) - fp = stdin; - else - { - fp = fopen (file_name, "r"); - if (fp == NULL) - error (EXIT_FAILURE, errno, - _("error while opening \"%s\" for reading"), file_name); - } - - result = string_list_alloc (); - - while (!feof (fp)) - { - /* Read next line from file. */ - int len = getline (&line_buf, &line_len, fp); - - /* In case of an error leave loop. */ - if (len < 0) - break; - - /* Remove trailing '\n' and trailing whitespace. */ - if (len > 0 && line_buf[len - 1] == '\n') - line_buf[--len] = '\0'; - while (len > 0 - && (line_buf[len - 1] == ' ' - || line_buf[len - 1] == '\t' - || line_buf[len - 1] == '\r')) - line_buf[--len] = '\0'; - - /* Test if we have to ignore the line. */ - if (*line_buf == '\0' || *line_buf == '#') - continue; - - string_list_append_unique (result, line_buf); - } - - /* Free buffer allocated through getline. */ - if (line_buf != NULL) - free (line_buf); - - /* Close input stream. */ - if (fp != stdin) - fclose (fp); - - return result; -} diff --git a/src/msgcomm.c b/src/msgcomm.c index cff0e08..9abd819 100644 --- a/src/msgcomm.c +++ b/src/msgcomm.c @@ -21,7 +21,6 @@ # include <config.h> #endif -#include <errno.h> #include <getopt.h> #include <limits.h> #include <locale.h> @@ -30,9 +29,9 @@ #include "dir-list.h" #include "str-list.h" +#include "file-list.h" #include "error.h" #include "progname.h" -#include "getline.h" #include "message.h" #include "read-po.h" #include "write-po.h" @@ -86,7 +85,6 @@ static void usage PARAMS ((int status)) __attribute__ ((noreturn)) #endif ; -static string_list_ty *read_name_from_file PARAMS ((const char *file_name)); int @@ -254,7 +252,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ /* Determine list of files we have to process. */ if (files_from != NULL) - file_list = read_name_from_file (files_from); + file_list = read_names_from_file (files_from); else file_list = string_list_alloc (); /* Append names from command line. */ @@ -388,62 +386,3 @@ Informative output:\n\ exit (status); } - - -/* Read list of files to process from file. */ -static string_list_ty * -read_name_from_file (file_name) - const char *file_name; -{ - size_t line_len = 0; - char *line_buf = NULL; - FILE *fp; - string_list_ty *result; - - if (strcmp (file_name, "-") == 0) - fp = stdin; - else - { - fp = fopen (file_name, "r"); - if (fp == NULL) - error (EXIT_FAILURE, errno, - _("error while opening \"%s\" for reading"), file_name); - } - - result = string_list_alloc (); - - while (!feof (fp)) - { - /* Read next line from file. */ - int len = getline (&line_buf, &line_len, fp); - - /* In case of an error leave loop. */ - if (len < 0) - break; - - /* Remove trailing '\n' and trailing whitespace. */ - if (len > 0 && line_buf[len - 1] == '\n') - line_buf[--len] = '\0'; - while (len > 0 - && (line_buf[len - 1] == ' ' - || line_buf[len - 1] == '\t' - || line_buf[len - 1] == '\r')) - line_buf[--len] = '\0'; - - /* Test if we have to ignore the line. */ - if (*line_buf == '\0' || *line_buf == '#') - continue; - - string_list_append_unique (result, line_buf); - } - - /* Free buffer allocated through getline. */ - if (line_buf != NULL) - free (line_buf); - - /* Close input stream. */ - if (fp != stdin) - fclose (fp); - - return result; -} diff --git a/src/xgettext.c b/src/xgettext.c index 705f389..a2c29ad 100644 --- a/src/xgettext.c +++ b/src/xgettext.c @@ -40,6 +40,7 @@ extern int errno; #endif #include "dir-list.h" +#include "file-list.h" #include "error.h" #include "progname.h" #include "hash.h" @@ -148,7 +149,6 @@ static void usage PARAMS ((int status)) __attribute__ ((noreturn)) #endif ; -static string_list_ty *read_name_from_file PARAMS ((const char *file_name)); static void exclude_directive_domain PARAMS ((po_ty *pop, char *name)); static void exclude_directive_message PARAMS ((po_ty *pop, char *msgid, lex_pos_ty *msgid_pos, @@ -430,7 +430,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ /* Determine list of files we have to process. */ if (files_from != NULL) - file_list = read_name_from_file (files_from); + file_list = read_names_from_file (files_from); else file_list = string_list_alloc (); /* Append names from command line. */ @@ -609,65 +609,6 @@ Informative output:\n\ } -/* Read list of files to process from file. */ -static string_list_ty * -read_name_from_file (file_name) - const char *file_name; -{ - size_t line_len = 0; - char *line_buf = NULL; - FILE *fp; - string_list_ty *result; - - if (strcmp (file_name, "-") == 0) - fp = stdin; - else - { - fp = fopen (file_name, "r"); - if (fp == NULL) - error (EXIT_FAILURE, errno, - _("error while opening \"%s\" for reading"), file_name); - } - - result = string_list_alloc (); - - while (!feof (fp)) - { - /* Read next line from file. */ - int len = getline (&line_buf, &line_len, fp); - - /* In case of an error leave loop. */ - if (len < 0) - break; - - /* Remove trailing '\n' and trailing whitespace. */ - if (len > 0 && line_buf[len - 1] == '\n') - line_buf[--len] = '\0'; - while (len > 0 - && (line_buf[len - 1] == ' ' - || line_buf[len - 1] == '\t' - || line_buf[len - 1] == '\r')) - line_buf[--len] = '\0'; - - /* Test if we have to ignore the line. */ - if (*line_buf == '\0' || *line_buf == '#') - continue; - - string_list_append_unique (result, line_buf); - } - - /* Free buffer allocated through getline. */ - if (line_buf != NULL) - free (line_buf); - - /* Close input stream. */ - if (fp != stdin) - fclose (fp); - - return result; -} - - static void exclude_directive_domain (pop, name) po_ty *pop; |