]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
its: Refactor.
authorBruno Haible <bruno@clisp.org>
Mon, 30 Sep 2024 16:44:43 +0000 (18:44 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 30 Sep 2024 16:44:43 +0000 (18:44 +0200)
* gettext-tools/src/its.h: Structure this file.
* gettext-tools/src/its.c: Likewise.

gettext-tools/src/its.c
gettext-tools/src/its.h

index 32ab432f3ecad0a2acb4bf3ee6ee39aca97014bb..8983c38803e500fa68698db51391dc27dc470f83 100644 (file)
 #define XML_NS "http://www.w3.org/XML/1998/namespace"
 #define GT_NS "https://www.gnu.org/s/gettext/ns/its/extensions/1.0"
 
+
+/* =================== Common API for xgettext and msgfmt =================== */
+
+/* --------------------------------- Values --------------------------------- */
+
 struct its_value_ty
 {
   char *name;
@@ -233,14 +238,8 @@ its_pool_destroy (struct its_pool_ty *pool)
   free (pool->items);
 }
 
-struct its_rule_list_ty
-{
-  struct its_rule_ty **items;
-  size_t nitems;
-  size_t nitems_max;
 
-  struct its_pool_ty pool;
-};
+/* ----------------------------- Lists of nodes ----------------------------- */
 
 struct its_node_list_ty
 {
@@ -262,6 +261,11 @@ its_node_list_append (struct its_node_list_ty *nodes,
   nodes->items[nodes->nitems++] = node;
 }
 
+
+/* ---------------------------- Rule base class ---------------------------- */
+
+struct its_rule_ty;
+
 /* Base class representing an ITS rule in global definition.  */
 struct its_rule_class_ty
 {
@@ -294,8 +298,6 @@ struct its_rule_ty
   ITS_RULE_TY
 };
 
-static hash_table classes;
-
 static void
 its_rule_destructor (struct its_rule_ty *rule)
 {
@@ -688,6 +690,9 @@ _its_error_missing_attribute (xmlNode *node, const char *attribute)
          node->name, attribute);
 }
 
+
+/* ---------------------------- <translateRule> ---------------------------- */
+
 /* Implementation of Translate data category.  */
 static void
 its_translate_rule_constructor (struct its_rule_ty *rule, xmlNode *node)
@@ -798,6 +803,9 @@ static struct its_rule_class_ty its_translate_rule_class =
     its_translate_rule_eval,
   };
 
+
+/* ----------------------------- <locNoteRule> ----------------------------- */
+
 /* Implementation of Localization Note data category.  */
 static void
 its_localization_note_rule_constructor (struct its_rule_ty *rule, xmlNode *node)
@@ -970,6 +978,9 @@ static struct its_rule_class_ty its_localization_note_rule_class =
     its_localization_note_rule_eval,
   };
 
+
+/* ---------------------------- <withinTextRule> ---------------------------- */
+
 /* Implementation of Element Within Text data category.  */
 static void
 its_element_within_text_rule_constructor (struct its_rule_ty *rule,
@@ -1040,6 +1051,9 @@ static struct its_rule_class_ty its_element_within_text_rule_class =
     its_element_within_text_rule_eval,
   };
 
+
+/* -------------------------- <preserveSpaceRule> -------------------------- */
+
 /* Implementation of Preserve Space data category.  */
 static void
 its_preserve_space_rule_constructor (struct its_rule_ty *rule,
@@ -1144,6 +1158,9 @@ static struct its_rule_class_ty its_preserve_space_rule_class =
     its_preserve_space_rule_eval,
   };
 
+
+/* ----------------------------- <contextRule> ----------------------------- */
+
 /* Implementation of Context data category.  */
 static void
 its_extension_context_rule_constructor (struct its_rule_ty *rule, xmlNode *node)
@@ -1210,6 +1227,9 @@ static struct its_rule_class_ty its_extension_context_rule_class =
     its_extension_context_rule_eval,
   };
 
+
+/* ------------------------------ <escapeRule> ------------------------------ */
+
 /* Implementation of Escape Special Characters data category.  */
 static void
 its_extension_escape_rule_constructor (struct its_rule_ty *rule, xmlNode *node)
@@ -1304,6 +1324,11 @@ static struct its_rule_class_ty its_extension_escape_rule_class =
     its_extension_escape_rule_eval,
   };
 
+
+/* ---------------------------- Rules in general ---------------------------- */
+
+static hash_table classes;
+
 static struct its_rule_ty *
 its_rule_alloc (struct its_rule_class_ty *method_table, xmlNode *node)
 {
@@ -1368,6 +1393,18 @@ init_classes (void)
 #undef ADD_RULE_CLASS
 }
 
+
+/* --------------------------- Loading the rules --------------------------- */
+
+struct its_rule_list_ty
+{
+  struct its_rule_ty **items;
+  size_t nitems;
+  size_t nitems_max;
+
+  struct its_pool_ty pool;
+};
+
 struct its_rule_list_ty *
 its_rule_list_alloc (void)
 {
@@ -1690,6 +1727,9 @@ _its_get_content (struct its_rule_list_ty *rules, xmlNode *node,
   return result;
 }
 
+
+/* ========================= API only for xgettext ========================= */
+
 static void
 _its_comment_append (string_list_ty *comments, const char *data)
 {
@@ -1892,6 +1932,9 @@ its_rule_list_extract (its_rule_list_ty *rules,
   xmlFreeDoc (doc);
 }
 
+
+/* ========================== API only for msgfmt ========================== */
+
 struct its_merge_context_ty
 {
   its_rule_list_ty *rules;
index 2349527988f1c862c9428f491b04b297579baa3f..9fe03e1dd2bb1a36d5b937d30478539482e4b59a 100644 (file)
 extern "C" {
 #endif
 
-enum its_whitespace_type_ty
-{
-  ITS_WHITESPACE_PRESERVE,
-  ITS_WHITESPACE_NORMALIZE,
-  ITS_WHITESPACE_NORMALIZE_PARAGRAPH,
-  ITS_WHITESPACE_TRIM
-};
 
-typedef struct its_rule_list_ty its_rule_list_ty;
+/* =================== Common API for xgettext and msgfmt =================== */
 
-typedef message_ty *
-        (*its_extract_callback_ty) (message_list_ty *mlp,
-                                    const char *msgctxt,
-                                    const char *msgid,
-                                    lex_pos_ty *pos,
-                                    const char *extracted_comment,
-                                    const char *marker,
-                                    enum its_whitespace_type_ty whitespace);
+typedef struct its_rule_list_ty its_rule_list_ty;
 
 /* Creates a fresh its_rule_list_ty holding global ITS rules.  */
 extern its_rule_list_ty *its_rule_list_alloc (void);
@@ -61,6 +47,26 @@ extern bool its_rule_list_add_from_string (struct its_rule_list_ty *rules,
 extern bool its_rule_list_add_from_file (its_rule_list_ty *rules,
                                          const char *filename);
 
+
+/* ========================= API only for xgettext ========================= */
+
+enum its_whitespace_type_ty
+{
+  ITS_WHITESPACE_PRESERVE,
+  ITS_WHITESPACE_NORMALIZE,
+  ITS_WHITESPACE_NORMALIZE_PARAGRAPH,
+  ITS_WHITESPACE_TRIM
+};
+
+typedef message_ty *
+        (*its_extract_callback_ty) (message_list_ty *mlp,
+                                    const char *msgctxt,
+                                    const char *msgid,
+                                    lex_pos_ty *pos,
+                                    const char *extracted_comment,
+                                    const char *marker,
+                                    enum its_whitespace_type_ty whitespace);
+
 /* Extracts messages from FP, accoding to the loaded ITS rules.  */
 extern void its_rule_list_extract (its_rule_list_ty *rules,
                                    FILE *fp, const char *real_filename,
@@ -68,6 +74,9 @@ extern void its_rule_list_extract (its_rule_list_ty *rules,
                                    msgdomain_list_ty *mdlp,
                                    its_extract_callback_ty callback);
 
+
+/* ========================== API only for msgfmt ========================== */
+
 typedef struct its_merge_context_ty its_merge_context_ty;
 
 extern its_merge_context_ty *
@@ -80,6 +89,7 @@ extern void its_merge_context_merge (its_merge_context_ty *context,
 extern void its_merge_context_write (its_merge_context_ty *context,
                                      FILE *fp);
 
+
 #ifdef __cplusplus
 }
 #endif