]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
xgettext: Define functions for the Ruby support.
authorBruno Haible <bruno@clisp.org>
Sun, 26 Apr 2020 21:35:16 +0000 (23:35 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 26 Apr 2020 22:23:15 +0000 (00:23 +0200)
* gettext-tools/src/xg-message.h (decide_is_format, intersect_range,
decide_do_wrap, decide_syntax_check): New declarations.
* gettext-tools/src/xg-message.c (decide_is_format, intersect_range,
decide_do_wrap, decide_syntax_check): New functions. extracted from
remember_a_message.
(remember_a_message): Invoke these functions.

gettext-tools/src/xg-message.c
gettext-tools/src/xg-message.h

index 5b9d3577feca741f9478f96c7524e287f85f5e2d..7b053798ce8d980442b500b9b592d6b1d2292769 100644 (file)
@@ -1,5 +1,5 @@
 /* Extracting a message.  Accumulating the message list.
-   Copyright (C) 2001-2019 Free Software Foundation, Inc.
+   Copyright (C) 2001-2020 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
@@ -107,6 +107,109 @@ set_format_flags_from_context (enum is_format is_format[NFORMATS],
 }
 
 
+void
+decide_is_format (message_ty *mp)
+{
+  size_t i;
+
+  /* If it is not already decided, through programmer comments, whether the
+     msgid is a format string, examine the msgid.  This is a heuristic.  */
+  for (i = 0; i < NFORMATS; i++)
+    {
+      if (mp->is_format[i] == undecided
+          && (formatstring_parsers[i] == current_formatstring_parser1
+              || formatstring_parsers[i] == current_formatstring_parser2
+              || formatstring_parsers[i] == current_formatstring_parser3)
+          /* But avoid redundancy: objc-format is stronger than c-format.  */
+          && !(i == format_c && possible_format_p (mp->is_format[format_objc]))
+          && !(i == format_objc && possible_format_p (mp->is_format[format_c]))
+          /* Avoid flagging a string as c-format when it's known to be a
+             qt-format or qt-plural-format or kde-format or boost-format
+             string.  */
+          && !(i == format_c
+               && (possible_format_p (mp->is_format[format_qt])
+                   || possible_format_p (mp->is_format[format_qt_plural])
+                   || possible_format_p (mp->is_format[format_kde])
+                   || possible_format_p (mp->is_format[format_kde_kuit])
+                   || possible_format_p (mp->is_format[format_boost])))
+          /* Avoid flagging a string as kde-format when it's known to
+             be a kde-kuit-format string.  */
+          && !(i == format_kde
+               && possible_format_p (mp->is_format[format_kde_kuit]))
+          /* Avoid flagging a string as kde-kuit-format when it's
+             known to be a kde-format string.  Note that this relies
+             on the fact that format_kde < format_kde_kuit, so a
+             string will be marked as kde-format if both are
+             undecided.  */
+          && !(i == format_kde_kuit
+               && possible_format_p (mp->is_format[format_kde])))
+        {
+          struct formatstring_parser *parser = formatstring_parsers[i];
+          char *invalid_reason = NULL;
+          void *descr = parser->parse (mp->msgid, false, NULL, &invalid_reason);
+
+          if (descr != NULL)
+            {
+              /* msgid is a valid format string.  We mark only those msgids
+                 as format strings which contain at least one format directive
+                 and thus are format strings with a high probability.  We
+                 don't mark strings without directives as format strings,
+                 because that would force the programmer to add
+                 "xgettext: no-c-format" anywhere where a translator wishes
+                 to use a percent sign.  So, the msgfmt checking will not be
+                 perfect.  Oh well.  */
+              if (parser->get_number_of_directives (descr) > 0
+                  && !(parser->is_unlikely_intentional != NULL
+                       && parser->is_unlikely_intentional (descr)))
+                mp->is_format[i] = possible;
+
+              parser->free (descr);
+            }
+          else
+            {
+              /* msgid is not a valid format string.  */
+              mp->is_format[i] = impossible;
+              free (invalid_reason);
+            }
+        }
+    }
+}
+
+void
+intersect_range (message_ty *mp, const struct argument_range *range)
+{
+  if (has_range_p (*range))
+    {
+      if (has_range_p (mp->range))
+        {
+          if (range->min < mp->range.min)
+            mp->range.min = range->min;
+          if (range->max > mp->range.max)
+            mp->range.max = range->max;
+        }
+      else
+        mp->range = *range;
+    }
+}
+
+void
+decide_do_wrap (message_ty *mp)
+{
+  /* By default we wrap.  */
+  mp->do_wrap = (mp->do_wrap == no ? no : yes);
+}
+
+void
+decide_syntax_check (message_ty *mp)
+{
+  size_t i;
+
+  for (i = 0; i < NSYNTAXCHECKS; i++)
+    if (mp->do_syntax_check[i] == undecided)
+      mp->do_syntax_check[i] = default_syntax_check[i] == yes ? yes : no;
+}
+
+
 static void
 warn_format_string (enum is_format is_format[NFORMATS], const char *string,
                     lex_pos_ty *pos, const char *pretty_msgstr)
@@ -418,91 +521,18 @@ meta information, not the empty string.\n")));
       }
   }
 
-  /* If it is not already decided, through programmer comments, whether the
-     msgid is a format string, examine the msgid.  This is a heuristic.  */
   for (i = 0; i < NFORMATS; i++)
-    {
-      if (is_format[i] == undecided
-          && (formatstring_parsers[i] == current_formatstring_parser1
-              || formatstring_parsers[i] == current_formatstring_parser2
-              || formatstring_parsers[i] == current_formatstring_parser3)
-          /* But avoid redundancy: objc-format is stronger than c-format.  */
-          && !(i == format_c && possible_format_p (is_format[format_objc]))
-          && !(i == format_objc && possible_format_p (is_format[format_c]))
-          /* Avoid flagging a string as c-format when it's known to be a
-             qt-format or qt-plural-format or kde-format or boost-format
-             string.  */
-          && !(i == format_c
-               && (possible_format_p (is_format[format_qt])
-                   || possible_format_p (is_format[format_qt_plural])
-                   || possible_format_p (is_format[format_kde])
-                   || possible_format_p (is_format[format_kde_kuit])
-                   || possible_format_p (is_format[format_boost])))
-          /* Avoid flagging a string as kde-format when it's known to
-             be a kde-kuit-format string.  */
-          && !(i == format_kde
-               && possible_format_p (is_format[format_kde_kuit]))
-          /* Avoid flagging a string as kde-kuit-format when it's
-             known to be a kde-format string.  Note that this relies
-             on the fact that format_kde < format_kde_kuit, so a
-             string will be marked as kde-format if both are
-             undecided.  */
-          && !(i == format_kde_kuit
-               && possible_format_p (is_format[format_kde])))
-        {
-          struct formatstring_parser *parser = formatstring_parsers[i];
-          char *invalid_reason = NULL;
-          void *descr = parser->parse (mp->msgid, false, NULL, &invalid_reason);
+    mp->is_format[i] = is_format[i];
+  decide_is_format (mp);
 
-          if (descr != NULL)
-            {
-              /* msgid is a valid format string.  We mark only those msgids
-                 as format strings which contain at least one format directive
-                 and thus are format strings with a high probability.  We
-                 don't mark strings without directives as format strings,
-                 because that would force the programmer to add
-                 "xgettext: no-c-format" anywhere where a translator wishes
-                 to use a percent sign.  So, the msgfmt checking will not be
-                 perfect.  Oh well.  */
-              if (parser->get_number_of_directives (descr) > 0
-                  && !(parser->is_unlikely_intentional != NULL
-                       && parser->is_unlikely_intentional (descr)))
-                is_format[i] = possible;
+  intersect_range (mp, &range);
 
-              parser->free (descr);
-            }
-          else
-            {
-              /* msgid is not a valid format string.  */
-              is_format[i] = impossible;
-              free (invalid_reason);
-            }
-        }
-      mp->is_format[i] = is_format[i];
-    }
-
-  if (has_range_p (range))
-    {
-      if (has_range_p (mp->range))
-        {
-          if (range.min < mp->range.min)
-            mp->range.min = range.min;
-          if (range.max > mp->range.max)
-            mp->range.max = range.max;
-        }
-      else
-        mp->range = range;
-    }
-
-  mp->do_wrap = do_wrap == no ? no : yes;       /* By default we wrap.  */
+  mp->do_wrap = do_wrap;
+  decide_do_wrap (mp);
 
   for (i = 0; i < NSYNTAXCHECKS; i++)
-    {
-      if (do_syntax_check[i] == undecided)
-        do_syntax_check[i] = default_syntax_check[i] == yes ? yes : no;
-
-      mp->do_syntax_check[i] = do_syntax_check[i];
-    }
+    mp->do_syntax_check[i] = do_syntax_check[i];
+  decide_syntax_check (mp);
 
   /* Warn about the use of non-reorderable format strings when the programming
      language also provides reorderable format strings.  */
index 8def094e7b2efa8b795f05785763db817f1484cd..eedc9202a8318362c268c5489b627c2192feb754 100644 (file)
@@ -1,5 +1,5 @@
 /* Extracting a message.  Accumulating the message list.
-   Copyright (C) 2001-2019 Free Software Foundation, Inc.
+   Copyright (C) 2001-2020 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
@@ -76,6 +76,21 @@ extern void remember_a_message_plural (message_ty *mp,
                                        refcounted_string_list_ty *comment,
                                        bool comment_is_utf8);
 
+/* The following functions are used by remember_a_message.
+   Most extractors don't need to invoke them explicitly.  */
+
+/* Eliminates the 'undecided' values in mp->is_format.  */
+extern void decide_is_format (message_ty *mp);
+
+/* Adds a range restriction to mp->range.  */
+extern void intersect_range (message_ty *mp, const struct argument_range *range);
+
+/* Eliminates the 'undecided' value in mp->do_wrap.  */
+extern void decide_do_wrap (message_ty *mp);
+
+/* Eliminates the 'undecided' values in mp->syntax_check.  */
+extern void decide_syntax_check (message_ty *mp);
+
 
 #ifdef __cplusplus
 }