]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
xgettext: Use sf-istream from Gnulib.
authorBruno Haible <bruno@clisp.org>
Tue, 24 Sep 2024 10:38:19 +0000 (12:38 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 26 Sep 2024 11:12:13 +0000 (13:12 +0200)
* autogen.sh (GNULIB_MODULES_TOOLS_FOR_SRC): Add sf-istream.
* gettext-tools/src/x-perl.c: Include sf-istream.h.
(struct perl_extractor): Replace fp, input, input_end fields with a single
sf_istream_t.
(phase1_getc, get_here_document, skip_pod, interpolate_keywords, extract_perl):
Update.
* gettext-tools/src/x-php.c: Include sf-istream.h.
(struct php_extractor): Replace fp, input, input_end fields with a single
sf_istream_t.
(phase1_getc): Simplify.
(process_heredoc, phase4_get, extract_php): Update.

autogen.sh
gettext-tools/src/x-perl.c
gettext-tools/src/x-php.c

index b69a27b1d6596548ba211ef9b300ab904fdac45f..53dffdbe5c0a1d6123ba95173f87e5a676e24656 100755 (executable)
@@ -228,6 +228,7 @@ if ! $skip_gnulib; then
     relocatable-prog
     relocatable-script
     setlocale
+    sf-istream
     sh-filename
     sh-quote
     sigpipe
index 1b0cec1f52f3aa8b87b7ba735153179a88756cfb..68dc3a3b17cfab3bcfb59231bb39217504b91c37 100644 (file)
@@ -32,6 +32,7 @@
 #include <error.h>
 #include "attribute.h"
 #include "message.h"
+#include "sf-istream.h"
 #include "rc-str-list.h"
 #include "string-desc.h"
 #include "xgettext.h"
@@ -275,11 +276,8 @@ struct perl_extractor
   /* Accumulator for the output.  */
   message_list_ty *mlp;
 
-  /* The input file stream, when reading from a file.  */
-  FILE *fp;
-  /* The input area, when reading from a string.  */
-  const char *input;
-  const char *input_end;
+  /* The input.  */
+  sf_istream_t input;
 
   int line_number;
 
@@ -355,15 +353,16 @@ phase1_getc (struct perl_extractor *xp)
   if (xp->end_of_file)
     return EOF;
 
-  if (xp->fp != NULL)
+  if (xp->input.fp != NULL)
     {
       if (xp->linepos >= xp->linesize)
         {
-          xp->linesize = getline (&xp->linebuf, &xp->linebuf_size, xp->fp);
+          xp->linesize =
+            getline (&xp->linebuf, &xp->linebuf_size, xp->input.fp);
 
           if (xp->linesize < 0)
             {
-              if (ferror (xp->fp))
+              if (ferror (xp->input.fp))
                 error (EXIT_FAILURE, errno, _("error while reading \"%s\""),
                        real_file_name);
               xp->end_of_file = true;
@@ -391,8 +390,8 @@ phase1_getc (struct perl_extractor *xp)
     {
       if (xp->linebuf == NULL)
         {
-          xp->linebuf = xp->input;
-          xp->linesize = xp->input_end - xp->input;
+          xp->linebuf = (char *) xp->input.input;
+          xp->linesize = xp->input.input_end - xp->input.input;
           xp->linepos = 0;
         }
       if (xp->linepos >= xp->linesize)
@@ -446,13 +445,13 @@ get_here_document (struct perl_extractor *xp, const char *delimiter)
 
   for (;;)
     {
-      int read_bytes = getline (&my_linebuf, &my_linebuf_size, xp->fp);
+      int read_bytes = getline (&my_linebuf, &my_linebuf_size, xp->input.fp);
       char *my_line_utf8;
       bool chomp;
 
       if (read_bytes < 0)
         {
-          if (ferror (xp->fp))
+          if (ferror (xp->input.fp))
             {
               error (EXIT_FAILURE, errno, _("error while reading \"%s\""),
                      real_file_name);
@@ -540,11 +539,11 @@ skip_pod (struct perl_extractor *xp)
 
   for (;;)
     {
-      xp->linesize = getline (&xp->linebuf, &xp->linebuf_size, xp->fp);
+      xp->linesize = getline (&xp->linebuf, &xp->linebuf_size, xp->input.fp);
 
       if (xp->linesize < 0)
         {
-          if (ferror (xp->fp))
+          if (ferror (xp->input.fp))
             error (EXIT_FAILURE, errno, _("error while reading \"%s\""),
                    real_file_name);
           return;
@@ -2024,9 +2023,9 @@ interpolate_keywords (struct perl_extractor *xp, string_desc_t string,
 
                 struct perl_extractor *rxp = XMALLOC (struct perl_extractor);
                 rxp->mlp = xp->mlp;
-                rxp->fp = NULL;
-                rxp->input = substring;
-                rxp->input_end = substring + bufpos;
+                sf_istream_init_from_string_desc (
+                  &rxp->input,
+                  string_desc_new_addr (bufpos, substring));
                 rxp->line_number = xp->line_number;
                 perl_extractor_init_rest (rxp);
 
@@ -3979,9 +3978,7 @@ extract_perl (FILE *f, const char *real_filename, const char *logical_filename,
   struct perl_extractor *xp = XMALLOC (struct perl_extractor);
 
   xp->mlp = mdlp->item[0]->messages;
-  xp->fp = f;
-  xp->input = NULL;
-  xp->input_end = NULL;
+  sf_istream_init_from_file (&xp->input, f);
   real_file_name = real_filename;
   logical_file_name = xstrdup (logical_filename);
   perl_extractor_init_rest (xp);
index b616ccd6f87551f4f94184d97a016c0a857a25c4..4060e51498115a9d6209698bfddbd9587cf16624 100644 (file)
@@ -31,6 +31,7 @@
 #include <error.h>
 #include "attribute.h"
 #include "message.h"
+#include "sf-istream.h"
 #include "rc-str-list.h"
 #include "xgettext.h"
 #include "xg-pos.h"
@@ -175,11 +176,8 @@ struct php_extractor
   /* Accumulator for the output.  */
   message_list_ty *mlp;
 
-  /* The input file stream, when reading from a file.  */
-  FILE *fp;
-  /* The input area, when reading from a string.  */
-  const char *input;
-  const char *input_end;
+  /* The input.  */
+  sf_istream_t input;
 
   int line_number;
 
@@ -256,26 +254,20 @@ phase1_getc (struct php_extractor *xp)
 
   if (xp->phase1_pushback_length)
     c = xp->phase1_pushback[--(xp->phase1_pushback_length)];
-  else if (xp->fp != NULL)
+  else
     {
-      c = getc (xp->fp);
+      c = sf_getc (&xp->input);
 
       if (c == EOF)
         {
-          if (ferror (xp->fp))
+          if (sf_ferror (&xp->input))
             error (EXIT_FAILURE, errno, _("error while reading \"%s\""),
                    real_file_name);
           return EOF;
         }
     }
-  else
-    {
-      if (xp->input == xp->input_end)
-        return EOF;
-      c = *(xp->input++);
-    }
 
-  if (xp->fp != NULL && c == '\n')
+  if (xp->input.fp != NULL && c == '\n')
     xp->line_number++;
 
   return c;
@@ -1065,9 +1057,8 @@ process_heredoc (struct php_extractor *xp, const char *doc, int doc_line_number)
 
     struct php_extractor *rxp = XMALLOC (struct php_extractor);
     rxp->mlp = xp->mlp;
-    rxp->fp = NULL;
-    rxp->input = substring;
-    rxp->input_end = substring + bufpos;
+    sf_istream_init_from_string_desc (&rxp->input,
+                                      string_desc_new_addr (bufpos, substring));
     rxp->line_number = xp->line_number;
     php_extractor_init_rest (rxp);
 
@@ -1453,9 +1444,9 @@ phase4_get (struct php_extractor *xp, token_ty *tp)
 
             struct php_extractor *rxp = XMALLOC (struct php_extractor);
             rxp->mlp = xp->mlp;
-            rxp->fp = NULL;
-            rxp->input = substring;
-            rxp->input_end = substring + bufpos;
+            sf_istream_init_from_string_desc (
+              &rxp->input,
+              string_desc_new_addr (bufpos, substring));
             rxp->line_number = xp->line_number;
             php_extractor_init_rest (rxp);
 
@@ -2143,9 +2134,7 @@ extract_php (FILE *f,
   struct php_extractor *xp = XMALLOC (struct php_extractor);
 
   xp->mlp = mdlp->item[0]->messages;
-  xp->fp = f;
-  xp->input = NULL;
-  xp->input_end = NULL;
+  sf_istream_init_from_file (&xp->input, f);
   real_file_name = real_filename;
   logical_file_name = xstrdup (logical_filename);
   xp->line_number = 1;