From: Bruno Haible Date: Tue, 24 Sep 2024 10:38:19 +0000 (+0200) Subject: xgettext: Use sf-istream from Gnulib. X-Git-Tag: v0.23~112 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b16a7153042e52558df10ad5999761e646a5380f;p=thirdparty%2Fgettext.git xgettext: Use sf-istream from Gnulib. * 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. --- diff --git a/autogen.sh b/autogen.sh index b69a27b1d..53dffdbe5 100755 --- a/autogen.sh +++ b/autogen.sh @@ -228,6 +228,7 @@ if ! $skip_gnulib; then relocatable-prog relocatable-script setlocale + sf-istream sh-filename sh-quote sigpipe diff --git a/gettext-tools/src/x-perl.c b/gettext-tools/src/x-perl.c index 1b0cec1f5..68dc3a3b1 100644 --- a/gettext-tools/src/x-perl.c +++ b/gettext-tools/src/x-perl.c @@ -32,6 +32,7 @@ #include #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); diff --git a/gettext-tools/src/x-php.c b/gettext-tools/src/x-php.c index b616ccd6f..4060e5149 100644 --- a/gettext-tools/src/x-php.c +++ b/gettext-tools/src/x-php.c @@ -31,6 +31,7 @@ #include #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;