]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Unify three copies of read_name_from_file().
authorBruno Haible <bruno@clisp.org>
Tue, 7 Aug 2001 11:45:42 +0000 (11:45 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 7 Aug 2001 11:45:42 +0000 (11:45 +0000)
src/ChangeLog
src/Makefile.am
src/file-list.c [new file with mode: 0644]
src/file-list.h [new file with mode: 0644]
src/msgcat.c
src/msgcomm.c
src/xgettext.c

index 65992f407cc3031ef24be15e237040c5011a95d2..1c3d5480b451a36186abb0037277e758ecd41e72 100644 (file)
@@ -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.
index 31fbea2277fe519f5b55a916560fa706a3f6820b..8082cc0715d077385c1a0e992ecc8a6b1338686c 100644 (file)
@@ -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 (file)
index 0000000..1cffa56
--- /dev/null
@@ -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 (file)
index 0000000..3326c7f
--- /dev/null
@@ -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 */
index 6b7adb134c4e022dd0a2afd0d9938dd1227de810..80a4f184cb5140f3a8a24539b453ae69bb6aacbf 100644 (file)
@@ -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;
-}
index cff0e08780788e0efa6313146e0b625bb3322c4e..9abd8199852a5ebeb1d8b949c42235c7c5754de1 100644 (file)
@@ -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;
-}
index 705f3896991fb17c928905f5fe93c083cce02c3f..a2c29add3fa8fd3fa1c8dfd505ca413a7781cb16 100644 (file)
@@ -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;