From: Bruno Haible Date: Sun, 28 Jul 2024 15:02:45 +0000 (+0200) Subject: Refactor. X-Git-Tag: v0.23~213 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=684fc99f2381443a82526b1f509c16a0510b244d;p=thirdparty%2Fgettext.git Refactor. * gettext-tools/src/read-catalog-special.h: New file, extracted from gettext-tools/src/read-catalog-abstract.h. * gettext-tools/src/read-catalog-special.c: New file, extracted from gettext-tools/src/read-catalog-abstract.c. * gettext-tools/src/read-catalog-abstract.h (po_parse_comment_special): Remove declaration. * gettext-tools/src/read-catalog-abstract.c: Don't include . (po_parse_comment_special): Moved to read-catalog-special.c. * gettext-tools/src/Makefile.am (noinst_HEADERS): Add read-catalog-special.h. (libgettextsrc_la_SOURCES): Add read-catalog-special.c. * gettext-tools/src/FILES: Update. * gettext-tools/libgettextpo/Makefile.am (libgettextpo_la_AUXSOURCES): Add ../src/read-catalog-special.c. --- diff --git a/gettext-tools/libgettextpo/Makefile.am b/gettext-tools/libgettextpo/Makefile.am index 090efbd76..e0a7d8d48 100644 --- a/gettext-tools/libgettextpo/Makefile.am +++ b/gettext-tools/libgettextpo/Makefile.am @@ -1,5 +1,5 @@ ## Makefile for the gettext-tools/libgettextpo subdirectory of GNU gettext -## Copyright (C) 1995-1998, 2000-2016, 2019-2023 Free Software Foundation, Inc. +## Copyright (C) 1995-2024 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 @@ -64,9 +64,10 @@ libgettextpo_la_AUXSOURCES = \ ../src/po-charset.c \ ../src/po-lex.c \ ../src/po-gram-gen.c \ - ../src/read-po.c \ + ../src/read-catalog-special.c \ ../src/read-catalog-abstract.c \ ../src/read-catalog.c \ + ../src/read-po.c \ ../src/plural-table.c \ ../src/format-c.c \ ../src/format-c++-brace.c \ diff --git a/gettext-tools/src/FILES b/gettext-tools/src/FILES index 470603041..1f69ba9d0 100644 --- a/gettext-tools/src/FILES +++ b/gettext-tools/src/FILES @@ -79,6 +79,10 @@ po-xerror.c | po-lex.c | Lexical analysis of PO files. | +| read-catalog-special.h +| read-catalog-special.c +| Parsing of special comments (#, comments). +| | read-catalog-abstract.h | po-gram.h | po-gram-gen.y diff --git a/gettext-tools/src/Makefile.am b/gettext-tools/src/Makefile.am index 6cb3a0ce5..98a919c43 100644 --- a/gettext-tools/src/Makefile.am +++ b/gettext-tools/src/Makefile.am @@ -43,8 +43,9 @@ endif noinst_HEADERS = \ pos.h message.h po-error.h po-xerror.h po-gram.h po-charset.h \ - po-lex.h open-catalog.h read-catalog-abstract.h read-catalog.h \ - read-catalog-file.h read-po.h read-properties.h read-stringtable.h \ + po-lex.h open-catalog.h read-catalog-special.h \ + read-catalog-abstract.h read-catalog.h read-catalog-file.h \ + read-po.h read-properties.h read-stringtable.h \ str-list.h \ write-catalog.h write-po.h write-properties.h write-stringtable.h \ dir-list.h file-list.h po-gram-gen.h cldr-plural.h \ @@ -187,6 +188,7 @@ FORMAT_SOURCE += \ # libgettextsrc contains all code that is needed by at least two programs. libgettextsrc_la_SOURCES = \ $(COMMON_SOURCE) \ + read-catalog-special.c \ read-catalog.c read-catalog-file.c \ write-catalog.c write-properties.c write-stringtable.c write-po.c \ msgl-ascii.c \ diff --git a/gettext-tools/src/read-catalog-abstract.c b/gettext-tools/src/read-catalog-abstract.c index 404495028..441c60d8f 100644 --- a/gettext-tools/src/read-catalog-abstract.c +++ b/gettext-tools/src/read-catalog-abstract.c @@ -24,7 +24,6 @@ /* Specification. */ #include "read-catalog-abstract.h" -#include #include #include #include @@ -233,194 +232,6 @@ po_callback_comment_special (abstract_catalog_reader_ty *catr, const char *s) } -/* Parse a special comment and put the result in *fuzzyp, formatp, *rangep, - *wrapp. */ -void -po_parse_comment_special (const char *s, - bool *fuzzyp, enum is_format formatp[NFORMATS], - struct argument_range *rangep, enum is_wrap *wrapp, - enum is_syntax_check scp[NSYNTAXCHECKS]) -{ - size_t i; - - *fuzzyp = false; - for (i = 0; i < NFORMATS; i++) - formatp[i] = undecided; - rangep->min = -1; - rangep->max = -1; - *wrapp = undecided; - for (i = 0; i < NSYNTAXCHECKS; i++) - scp[i] = undecided; - - while (*s != '\0') - { - const char *t; - - /* Skip whitespace. */ - while (*s != '\0' && strchr ("\n \t\r\f\v,", *s) != NULL) - s++; - - /* Collect a token. */ - t = s; - while (*s != '\0' && strchr ("\n \t\r\f\v,", *s) == NULL) - s++; - if (s != t) - { - size_t len = s - t; - - /* Accept fuzzy flag. */ - if (len == 5 && memcmp (t, "fuzzy", 5) == 0) - { - *fuzzyp = true; - continue; - } - - /* Accept format description. */ - if (len >= 7 && memcmp (t + len - 7, "-format", 7) == 0) - { - const char *p; - size_t n; - enum is_format value; - - p = t; - n = len - 7; - - if (n >= 3 && memcmp (p, "no-", 3) == 0) - { - p += 3; - n -= 3; - value = no; - } - else if (n >= 9 && memcmp (p, "possible-", 9) == 0) - { - p += 9; - n -= 9; - value = possible; - } - else if (n >= 11 && memcmp (p, "impossible-", 11) == 0) - { - p += 11; - n -= 11; - value = impossible; - } - else - value = yes; - - for (i = 0; i < NFORMATS; i++) - if (strlen (format_language[i]) == n - && memcmp (format_language[i], p, n) == 0) - { - formatp[i] = value; - break; - } - if (i < NFORMATS) - continue; - } - - /* Accept range description "range: ..". */ - if (len == 6 && memcmp (t, "range:", 6) == 0) - { - /* Skip whitespace. */ - while (*s != '\0' && strchr ("\n \t\r\f\v,", *s) != NULL) - s++; - - /* Collect a token. */ - t = s; - while (*s != '\0' && strchr ("\n \t\r\f\v,", *s) == NULL) - s++; - /* Parse it. */ - if (*t >= '0' && *t <= '9') - { - unsigned int min = 0; - - for (; *t >= '0' && *t <= '9'; t++) - { - if (min <= INT_MAX / 10) - { - min = 10 * min + (*t - '0'); - if (min > INT_MAX) - min = INT_MAX; - } - else - /* Avoid integer overflow. */ - min = INT_MAX; - } - if (*t++ == '.') - if (*t++ == '.') - if (*t >= '0' && *t <= '9') - { - unsigned int max = 0; - for (; *t >= '0' && *t <= '9'; t++) - { - if (max <= INT_MAX / 10) - { - max = 10 * max + (*t - '0'); - if (max > INT_MAX) - max = INT_MAX; - } - else - /* Avoid integer overflow. */ - max = INT_MAX; - } - if (min <= max) - { - rangep->min = min; - rangep->max = max; - continue; - } - } - } - } - - /* Accept wrap description. */ - if (len == 4 && memcmp (t, "wrap", 4) == 0) - { - *wrapp = yes; - continue; - } - if (len == 7 && memcmp (t, "no-wrap", 7) == 0) - { - *wrapp = no; - continue; - } - - /* Accept syntax check description. */ - if (len >= 6 && memcmp (t + len - 6, "-check", 6) == 0) - { - const char *p; - size_t n; - enum is_syntax_check value; - - p = t; - n = len - 6; - - if (n >= 3 && memcmp (p, "no-", 3) == 0) - { - p += 3; - n -= 3; - value = no; - } - else - value = yes; - - for (i = 0; i < NSYNTAXCHECKS; i++) - if (strlen (syntax_check_name[i]) == n - && memcmp (syntax_check_name[i], p, n) == 0) - { - scp[i] = value; - break; - } - if (i < NSYNTAXCHECKS) - continue; - } - - /* Unknown special comment marker. It may have been generated - from a future xgettext version. Ignore it. */ - } - } -} - - /* Parse a GNU style file comment. Syntax: an arbitrary number of STRING COLON NUMBER diff --git a/gettext-tools/src/read-catalog-abstract.h b/gettext-tools/src/read-catalog-abstract.h index 80927807c..ad3786105 100644 --- a/gettext-tools/src/read-catalog-abstract.h +++ b/gettext-tools/src/read-catalog-abstract.h @@ -193,14 +193,6 @@ extern void po_callback_comment_special (abstract_catalog_reader_ty *catr, extern void po_callback_comment_dispatcher (abstract_catalog_reader_ty *catr, const char *s); -/* Parse a special comment and put the result in *fuzzyp, formatp, *rangep, - *wrapp. */ -extern void po_parse_comment_special (const char *s, bool *fuzzyp, - enum is_format formatp[NFORMATS], - struct argument_range *rangep, - enum is_wrap *wrapp, - enum is_syntax_check scp[NSYNTAXCHECKS]); - #ifdef __cplusplus } diff --git a/gettext-tools/src/read-catalog-special.c b/gettext-tools/src/read-catalog-special.c new file mode 100644 index 000000000..2b049747e --- /dev/null +++ b/gettext-tools/src/read-catalog-special.c @@ -0,0 +1,216 @@ +/* Parsing of special comments (#, comments) in textual message catalogs. + Copyright (C) 1995-2024 Free Software Foundation, Inc. + + This file was written by Peter Miller + + 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 3 of the License, 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, see . */ + + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +/* Specification. */ +#include "read-catalog-special.h" + +#include +#include + + +/* Parse a special comment and put the result in *fuzzyp, formatp, *rangep, + *wrapp, scp. */ +void +po_parse_comment_special (const char *s, + bool *fuzzyp, enum is_format formatp[NFORMATS], + struct argument_range *rangep, enum is_wrap *wrapp, + enum is_syntax_check scp[NSYNTAXCHECKS]) +{ + size_t i; + + *fuzzyp = false; + for (i = 0; i < NFORMATS; i++) + formatp[i] = undecided; + rangep->min = -1; + rangep->max = -1; + *wrapp = undecided; + for (i = 0; i < NSYNTAXCHECKS; i++) + scp[i] = undecided; + + while (*s != '\0') + { + const char *t; + + /* Skip whitespace. */ + while (*s != '\0' && strchr ("\n \t\r\f\v,", *s) != NULL) + s++; + + /* Collect a token. */ + t = s; + while (*s != '\0' && strchr ("\n \t\r\f\v,", *s) == NULL) + s++; + if (s != t) + { + size_t len = s - t; + + /* Accept fuzzy flag. */ + if (len == 5 && memcmp (t, "fuzzy", 5) == 0) + { + *fuzzyp = true; + continue; + } + + /* Accept format description. */ + if (len >= 7 && memcmp (t + len - 7, "-format", 7) == 0) + { + const char *p; + size_t n; + enum is_format value; + + p = t; + n = len - 7; + + if (n >= 3 && memcmp (p, "no-", 3) == 0) + { + p += 3; + n -= 3; + value = no; + } + else if (n >= 9 && memcmp (p, "possible-", 9) == 0) + { + p += 9; + n -= 9; + value = possible; + } + else if (n >= 11 && memcmp (p, "impossible-", 11) == 0) + { + p += 11; + n -= 11; + value = impossible; + } + else + value = yes; + + for (i = 0; i < NFORMATS; i++) + if (strlen (format_language[i]) == n + && memcmp (format_language[i], p, n) == 0) + { + formatp[i] = value; + break; + } + if (i < NFORMATS) + continue; + } + + /* Accept range description "range: ..". */ + if (len == 6 && memcmp (t, "range:", 6) == 0) + { + /* Skip whitespace. */ + while (*s != '\0' && strchr ("\n \t\r\f\v,", *s) != NULL) + s++; + + /* Collect a token. */ + t = s; + while (*s != '\0' && strchr ("\n \t\r\f\v,", *s) == NULL) + s++; + /* Parse it. */ + if (*t >= '0' && *t <= '9') + { + unsigned int min = 0; + + for (; *t >= '0' && *t <= '9'; t++) + { + if (min <= INT_MAX / 10) + { + min = 10 * min + (*t - '0'); + if (min > INT_MAX) + min = INT_MAX; + } + else + /* Avoid integer overflow. */ + min = INT_MAX; + } + if (*t++ == '.') + if (*t++ == '.') + if (*t >= '0' && *t <= '9') + { + unsigned int max = 0; + for (; *t >= '0' && *t <= '9'; t++) + { + if (max <= INT_MAX / 10) + { + max = 10 * max + (*t - '0'); + if (max > INT_MAX) + max = INT_MAX; + } + else + /* Avoid integer overflow. */ + max = INT_MAX; + } + if (min <= max) + { + rangep->min = min; + rangep->max = max; + continue; + } + } + } + } + + /* Accept wrap description. */ + if (len == 4 && memcmp (t, "wrap", 4) == 0) + { + *wrapp = yes; + continue; + } + if (len == 7 && memcmp (t, "no-wrap", 7) == 0) + { + *wrapp = no; + continue; + } + + /* Accept syntax check description. */ + if (len >= 6 && memcmp (t + len - 6, "-check", 6) == 0) + { + const char *p; + size_t n; + enum is_syntax_check value; + + p = t; + n = len - 6; + + if (n >= 3 && memcmp (p, "no-", 3) == 0) + { + p += 3; + n -= 3; + value = no; + } + else + value = yes; + + for (i = 0; i < NSYNTAXCHECKS; i++) + if (strlen (syntax_check_name[i]) == n + && memcmp (syntax_check_name[i], p, n) == 0) + { + scp[i] = value; + break; + } + if (i < NSYNTAXCHECKS) + continue; + } + + /* Unknown special comment marker. It may have been generated + from a future xgettext version. Ignore it. */ + } + } +} diff --git a/gettext-tools/src/read-catalog-special.h b/gettext-tools/src/read-catalog-special.h new file mode 100644 index 000000000..b0f0f4ef7 --- /dev/null +++ b/gettext-tools/src/read-catalog-special.h @@ -0,0 +1,46 @@ +/* Parsing of special comments (#, comments) in textual message catalogs. + Copyright (C) 1995-2024 Free Software Foundation, Inc. + + This file was written by Peter Miller + + 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 3 of the License, 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, see . */ + +#ifndef _READ_CATALOG_SPECIAL_H +#define _READ_CATALOG_SPECIAL_H + +#include "message.h" + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + + +/* Parse a special comment and put the result in *fuzzyp, formatp, *rangep, + *wrapp, scp. */ +extern void po_parse_comment_special (const char *s, bool *fuzzyp, + enum is_format formatp[NFORMATS], + struct argument_range *rangep, + enum is_wrap *wrapp, + enum is_syntax_check scp[NSYNTAXCHECKS]); + + +#ifdef __cplusplus +} +#endif + + +#endif /* _READ_CATALOG_SPECIAL_H */