texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]


From: Patrice Dumas
Date: Sat, 28 Sep 2024 15:54:36 -0400 (EDT)

branch: master
commit da28c6d21ef1d3c8d193891e8127bccdefbe0bc8
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Fri May 31 23:59:21 2024 +0200

    Add data structure for information on types in C
    
    * tp/Texinfo/XS/main/types_data.h (TYPES), tp/Texinfo/XS/Makefile.am
    (BUILT_SOURCES, libtexinfo_la_SOURCES, EXTRA_DIST),
    tp/Texinfo/XS/main/element_types.awk,
    tp/Texinfo/XS/main/element_types.txt: add code in element_types.awk to
    setup a TYPE structure for information on types, similar to the
    COMMAND data, but with flags only.  Add flags information in
    element_types.txt, to mark text elements.  Generate the structure
    array with information on all the types in main/types_data.c.
---
 .gitignore                           |  1 +
 ChangeLog                            | 13 ++++++++++++
 tp/TODO                              |  2 --
 tp/Texinfo/XS/Makefile.am            |  5 ++++-
 tp/Texinfo/XS/main/element_types.awk | 33 +++++++++++++++++++++++++++++
 tp/Texinfo/XS/main/element_types.txt | 41 +++++++++++++++++-------------------
 tp/Texinfo/XS/main/types_data.h      | 30 ++++++++++++++++++++++++++
 7 files changed, 100 insertions(+), 25 deletions(-)

diff --git a/.gitignore b/.gitignore
index 9bd1dfec36..cf8e68678a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -348,6 +348,7 @@ tp/Texinfo/XS/main/global_unique_commands_case.c
 tp/Texinfo/XS/main/options_get_perl.c
 tp/Texinfo/XS/main/options_init_free.c
 tp/Texinfo/XS/main/options_types.h
+tp/Texinfo/XS/main/types_data.c
 
 tp/Texinfo/XS/main/*.lo
 
diff --git a/ChangeLog b/ChangeLog
index 543996cb45..30880472c2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -11,6 +11,19 @@
 
        * NEWS, doc/info-stnd.texi (Custom Key Bindings): update.
 
+2024-05-31  Patrice Dumas  <pertusus@free.fr>
+
+       Add data structure for information on types in C
+
+       * tp/Texinfo/XS/main/types_data.h (TYPES), tp/Texinfo/XS/Makefile.am
+       (BUILT_SOURCES, libtexinfo_la_SOURCES, EXTRA_DIST),
+       tp/Texinfo/XS/main/element_types.awk,
+       tp/Texinfo/XS/main/element_types.txt: add code in element_types.awk to
+       setup a TYPE structure for information on types, similar to the
+       COMMAND data, but with flags only.  Add flags information in
+       element_types.txt, to mark text elements.  Generate the structure
+       array with information on all the types in main/types_data.c.
+
 2024-05-31  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/main/command_data.awk (END): initialize flags_str and
diff --git a/tp/TODO b/tp/TODO
index 39e8670be7..d918eb4708 100644
--- a/tp/TODO
+++ b/tp/TODO
@@ -101,8 +101,6 @@ parsetexi
     is_container_empty: (all text types) current->text.end == 0
   debug_parser.c
     print_element_debug_parser e->text.end > 0
-  handle_commands.c
-    check_no_text g->type == ET_normal_text or more general?
   parser.c
     merge_text last_element->text.space > 0
     check_space_element e->text.space > 0
diff --git a/tp/Texinfo/XS/Makefile.am b/tp/Texinfo/XS/Makefile.am
index 85355f3ad2..ece42e512a 100644
--- a/tp/Texinfo/XS/Makefile.am
+++ b/tp/Texinfo/XS/Makefile.am
@@ -124,6 +124,7 @@ libtexinfo_la_SOURCES= \
                      main/command_ids.h \
                      main/builtin_commands.c \
                      main/builtin_commands.h \
+                     main/types_data.h \
                      main/debug.c \
                      main/debug.h \
                      main/errors.c \
@@ -210,6 +211,7 @@ libtexinfo_la_SOURCES= \
 
 EXTRA_DIST += main/accent_tables_8bit_codepoints.c
 EXTRA_DIST += main/command_data.c
+EXTRA_DIST += main/types_data.c
 EXTRA_DIST += main/cmd_normalization.c
 EXTRA_DIST += main/cmd_unicode.c
 EXTRA_DIST += main/cmd_symbol.c
@@ -233,6 +235,7 @@ BUILT_SOURCES=main/accent_tables_8bit_codepoints.c \
               main/command_ids.h \
               main/element_types.c \
               main/element_types.h \
+              main/types_data.c \
               main/global_commands_types.h \
               main/global_multi_commands_case.c \
               main/global_unique_commands_case.c \
@@ -244,7 +247,7 @@ BUILT_SOURCES=main/accent_tables_8bit_codepoints.c \
 EXTRA_DIST+=main/element_types.txt main/element_types.awk \
           main/command_data.awk
 
-$(srcdir)/main/element_types.c $(srcdir)/main/element_types.h: 
main/element_types.txt main/element_types.awk
+$(srcdir)/main/element_types.c $(srcdir)/main/element_types.h 
$(srcdir)/main/types_data.c: main/element_types.txt main/element_types.awk
        $(GAWK) -v srcdir=$(srcdir)/main -f $(srcdir)/main/element_types.awk \
             $(srcdir)/main/element_types.txt
 
diff --git a/tp/Texinfo/XS/main/element_types.awk 
b/tp/Texinfo/XS/main/element_types.awk
index 6f51bb6b5f..37bd7eaef7 100644
--- a/tp/Texinfo/XS/main/element_types.awk
+++ b/tp/Texinfo/XS/main/element_types.awk
@@ -20,17 +20,27 @@ BEGIN {
     }
     ETH = srcdir "/element_types.h"
     ETC = srcdir "/element_types.c"
+    ETD = srcdir "/types_data.c"
 
     print "/* This file automatically generated by element_types.awk */" > ETH
     print "#ifndef ELEMENT_TYPES_H"                                      > ETH
     print "#define ELEMENT_TYPES_H"                                      > ETH
     print "enum element_type {"                                          > ETH
     print "ET_NONE,"                                                     > ETH
+
+    print "/* This file automatically generated by element_types.awk */" > ETD
+    print ""                                                             > ETD
+    print "#include \"types_data.h\""                                    > ETD
+    print ""                                                             > ETD
+    print "TYPE type_data[] = {"                                         > ETD
+    print "0, 0,"                                                        > ETD
 }
 
 !/^$/ && !/^#/ {
     print "ET_" $1 ","                                                > ETH
     array = array "\"" $1 "\",\n"
+    t = $1
+    types[t] = $2
 
     last_type = "ET_" $1
 }
@@ -49,6 +59,29 @@ END {
     print "0,"                                                        > ETC    
 
     print array                                                       > ETC    
 
     print "};"                                                        > ETC    
 
+
+    for (t in types) {
+        flags_str = ""
+        if (types[t] != "") {
+            split(types[t], flags_array, ",")
+            for (flag_idx in flags_array) {
+              if (flag_idx == 1) {
+                flags_str = flags_array[flag_idx]
+              } else {
+                old_str = flags_str
+                flags_str = old_str "," flags_array[flag_idx]
+              }
+            }
+        }
+        if (flags_str == "") {
+            flags = "0"
+        } else {
+            flags = "TF_" flags_str
+            gsub (/,/, " | TF_", flags)
+        }
+        print "\"" t "\", " flags "," > ETD
+    }
+    print "};" > ETD
 }
 
 function output_array (string)
diff --git a/tp/Texinfo/XS/main/element_types.txt 
b/tp/Texinfo/XS/main/element_types.txt
index dcd4fd506b..ffc3bb2e84 100644
--- a/tp/Texinfo/XS/main/element_types.txt
+++ b/tp/Texinfo/XS/main/element_types.txt
@@ -23,18 +23,18 @@ space_command_arg
 definfoenclose_command
 
 # For text elements
-empty_line
-raw
-ignorable_spaces_after_command
-spaces_at_end
-spaces_after_close_brace
-spaces_before_paragraph
-text_after_end
-text_before_beginning
-space_at_end_menu_node
-after_menu_description_line
-spaces_after_cmd_before_arg
-normal_text
+empty_line                                text
+raw                                       text
+ignorable_spaces_after_command            text
+spaces_at_end                             text
+spaces_after_close_brace                  text
+spaces_before_paragraph                   text
+text_after_end                            text
+text_before_beginning                     text
+space_at_end_menu_node                    text
+after_menu_description_line               text
+spaces_after_cmd_before_arg               text
+normal_text                               text
 
 # Other special types
 document_root
@@ -54,21 +54,18 @@ line_arg
 rawline_arg
 
 menu_entry
-# text
-menu_entry_leading_text
+menu_entry_leading_text                   text
 menu_entry_name
-# text
-menu_entry_separator
+menu_entry_separator                      text
 menu_entry_node
 menu_entry_description
 menu_comment
 # Used internally
-# text
-internal_menu_star
-internal_spaces_after_command
-internal_spaces_before_argument
-internal_spaces_before_brace_in_index
-internal_spaces_after_cmd_before_arg
+internal_menu_star                         text
+internal_spaces_after_command              text
+internal_spaces_before_argument            text
+internal_spaces_before_brace_in_index      text
+internal_spaces_after_cmd_before_arg       text
 
 macro_name
 macro_arg
diff --git a/tp/Texinfo/XS/main/types_data.h b/tp/Texinfo/XS/main/types_data.h
new file mode 100644
index 0000000000..3dbe5f02a7
--- /dev/null
+++ b/tp/Texinfo/XS/main/types_data.h
@@ -0,0 +1,30 @@
+/* types_data.h - declarations for types_data.c */
+#ifndef TYPES_DATA_H
+#define TYPES_DATA_H
+/* Copyright 2010-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
+   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 <http://www.gnu.org/licenses/>. */
+
+#include "element_types.h"
+
+typedef struct types_struct {
+  char *type_name;
+  unsigned long flags;
+} TYPE;
+
+extern TYPE type_data[];
+
+#define TF_text               0x0001
+
+#endif



reply via email to

[Prev in Thread] Current Thread [Next in Thread]