]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Refactor.
authorBruno Haible <bruno@clisp.org>
Sun, 28 Jul 2024 15:02:45 +0000 (17:02 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 28 Jul 2024 15:02:45 +0000 (17:02 +0200)
* 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 <limits.h>.
(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.

gettext-tools/libgettextpo/Makefile.am
gettext-tools/src/FILES
gettext-tools/src/Makefile.am
gettext-tools/src/read-catalog-abstract.c
gettext-tools/src/read-catalog-abstract.h
gettext-tools/src/read-catalog-special.c [new file with mode: 0644]
gettext-tools/src/read-catalog-special.h [new file with mode: 0644]

index 090efbd761850b14de923f954b837b825966ca38..e0a7d8d4859f0c6b963d698aeb551c8d673e5637 100644 (file)
@@ -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 \
index 47060304164e330785c02f5ff194ec7490fc553c..1f69ba9d08f023f64e3414a1dfc3ef365de19861 100644 (file)
@@ -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
index 6cb3a0ce57db0e73a190ac98244a9703f7b9c5ef..98a919c43037ab42ea31b179d6e71ec5dfd5b847 100644 (file)
@@ -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 \
index 4044950282239dfd9170628bd2da557f8206e6fb..441c60d8f695b09d86317d704fa8dd3e94c56d05 100644 (file)
@@ -24,7 +24,6 @@
 /* Specification.  */
 #include "read-catalog-abstract.h"
 
-#include <limits.h>
 #include <stdbool.h>
 #include <stdlib.h>
 #include <string.h>
@@ -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: <min>..<max>".  */
-          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
index 80927807cb34963a5b94ce09fb74d8b0a0e9f022..ad37861055b59bb5e1294e0e487c886f93b81ed9 100644 (file)
@@ -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 (file)
index 0000000..2b04974
--- /dev/null
@@ -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 <millerp@canb.auug.org.au>
+
+   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 <https://www.gnu.org/licenses/>.  */
+
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+/* Specification.  */
+#include "read-catalog-special.h"
+
+#include <limits.h>
+#include <string.h>
+
+
+/* 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: <min>..<max>".  */
+          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 (file)
index 0000000..b0f0f4e
--- /dev/null
@@ -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 <millerp@canb.auug.org.au>
+
+   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 <https://www.gnu.org/licenses/>.  */
+
+#ifndef _READ_CATALOG_SPECIAL_H
+#define _READ_CATALOG_SPECIAL_H
+
+#include "message.h"
+
+#include <stdbool.h>
+
+
+#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 */