texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/XS/parsetexi/parser.c (set_restricte


From: Gavin D. Smith
Subject: branch master updated: * tp/Texinfo/XS/parsetexi/parser.c (set_restricted, global_restricted): New. * tp/Texinfo/XS/parsetexi/macro.c (new_macro): Do nothing if global_restricted is set.
Date: Mon, 27 Nov 2023 14:04:45 -0500

This is an automated email from the git hooks/post-receive script.

gavin pushed a commit to branch master
in repository texinfo.

The following commit(s) were added to refs/heads/master by this push:
     new 9f6736ec53 * tp/Texinfo/XS/parsetexi/parser.c (set_restricted, 
global_restricted): New. * tp/Texinfo/XS/parsetexi/macro.c (new_macro): Do 
nothing if global_restricted is set.
9f6736ec53 is described below

commit 9f6736ec53bc8a1123233e5b80d8d60333a4068c
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Mon Nov 27 19:04:02 2023 +0000

    * tp/Texinfo/XS/parsetexi/parser.c (set_restricted, global_restricted):
    New.
    * tp/Texinfo/XS/parsetexi/macro.c (new_macro): Do nothing if
    global_restricted is set.
    
    * tp/Texinfo/XS/parsetexi/Parsetexi.xs,
    * tp/Texinfo/XS/parsetexi/api.c (parser_set_restricted):
    New function.  Call set_restricted.
    
    * tp/Texinfo/XS/parsetexi/Parsetexi.pm (simple_parser):
    Set 'restricted' flag.
    (parser): If 'restricted' flag is set, call parser_set_restricted.
    
    * tp/t/init_files_tests.t
    (macro_defined_txiinternalvalue_in_translation): Re-add test,
    to check what is done with this input and init file.  From Patrice.
---
 ChangeLog                                          |  19 +++
 tp/Makefile.tres                                   |   1 +
 tp/Texinfo/XS/parsetexi/Parsetexi.pm               |   9 ++
 tp/Texinfo/XS/parsetexi/Parsetexi.xs               |   3 +
 tp/Texinfo/XS/parsetexi/api.c                      |   6 +
 tp/Texinfo/XS/parsetexi/api.h                      |   1 +
 tp/Texinfo/XS/parsetexi/macro.c                    |   3 +
 tp/Texinfo/XS/parsetexi/parser.c                   |   9 +-
 tp/Texinfo/XS/parsetexi/parser.h                   |   2 +
 tp/t/init/translate_txiinternalvalue_macro.init    |  30 ++++
 tp/t/init_files_tests.t                            |   7 +
 ...acro_defined_txiinternalvalue_in_translation.pl | 155 +++++++++++++++++++++
 12 files changed, 244 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index f9b7939785..f171343eb7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2023-11-27  Gavin Smith <gavinsmith0123@gmail.com>
+
+       * tp/Texinfo/XS/parsetexi/parser.c (set_restricted, global_restricted):
+       New.
+       * tp/Texinfo/XS/parsetexi/macro.c (new_macro): Do nothing if
+       global_restricted is set.
+
+       * tp/Texinfo/XS/parsetexi/Parsetexi.xs,
+       * tp/Texinfo/XS/parsetexi/api.c (parser_set_restricted):
+       New function.  Call set_restricted.
+
+       * tp/Texinfo/XS/parsetexi/Parsetexi.pm (simple_parser):
+       Set 'restricted' flag.
+       (parser): If 'restricted' flag is set, call parser_set_restricted.
+
+       * tp/t/init_files_tests.t
+       (macro_defined_txiinternalvalue_in_translation): Re-add test,
+       to check what is done with this input and init file.  From Patrice.
+
 2023-11-27  Gavin Smith <gavinsmith0123@gmail.com>
 
        * tp/Texinfo/ParserNonXS.pm (_new_macro),
diff --git a/tp/Makefile.tres b/tp/Makefile.tres
index 6fb559e2e1..d46f256d9c 100644
--- a/tp/Makefile.tres
+++ b/tp/Makefile.tres
@@ -988,6 +988,7 @@ test_files_generated_list = 
$(test_tap_files_generated_list) \
   t/results/init_files_tests/customize_translations/res_html \
   t/results/init_files_tests/documentation_examples.pl \
   t/results/init_files_tests/documentation_examples/res_html \
+  t/results/init_files_tests/macro_defined_txiinternalvalue_in_translation.pl \
   t/results/init_files_tests/modified_translation.pl \
   t/results/init_files_tests/redefined_need.pl \
   t/results/init_files_tests/sc_formatting_with_css.pl \
diff --git a/tp/Texinfo/XS/parsetexi/Parsetexi.pm 
b/tp/Texinfo/XS/parsetexi/Parsetexi.pm
index 7e3d9fe23b..31fbd6875d 100644
--- a/tp/Texinfo/XS/parsetexi/Parsetexi.pm
+++ b/tp/Texinfo/XS/parsetexi/Parsetexi.pm
@@ -77,6 +77,13 @@ sub get_conf($$)
 }
 
 sub simple_parser {
+  my $conf = shift;
+
+  $new_conf = {'restricted' => 1};
+  if ($conf) {
+    %$new_conf = (%new_conf, %conf);
+  }
+
   goto &parser;
 }
 
@@ -164,6 +171,8 @@ sub parser (;$$)
         parser_set_locale_encoding ($utf8_bytes);
       } elsif ($key eq 'accept_internalvalue' and $conf->{$key}) {
         parser_set_accept_internalvalue(1);
+      } elsif ($key eq 'restricted' and $conf->{'key'}) {
+        parser_set_restricted(1);
       } elsif ($key eq 'registrar' or $key eq 'COMMAND_LINE_ENCODING') {
         # no action needed, only used in perl code
       } else {
diff --git a/tp/Texinfo/XS/parsetexi/Parsetexi.xs 
b/tp/Texinfo/XS/parsetexi/Parsetexi.xs
index dff91d6297..071b0f5380 100644
--- a/tp/Texinfo/XS/parsetexi/Parsetexi.xs
+++ b/tp/Texinfo/XS/parsetexi/Parsetexi.xs
@@ -153,3 +153,6 @@ parser_set_debug (int i)
 void
 parser_set_accept_internalvalue (int value)
 
+void
+parser_set_restricted (int value)
+
diff --git a/tp/Texinfo/XS/parsetexi/api.c b/tp/Texinfo/XS/parsetexi/api.c
index 0e7c927c0d..9e56790398 100644
--- a/tp/Texinfo/XS/parsetexi/api.c
+++ b/tp/Texinfo/XS/parsetexi/api.c
@@ -267,3 +267,9 @@ parser_set_accept_internalvalue (int value)
 {
   set_accept_internalvalue (value);
 }
+
+void
+parser_set_restricted (int value)
+{
+  set_restricted(value);
+}
diff --git a/tp/Texinfo/XS/parsetexi/api.h b/tp/Texinfo/XS/parsetexi/api.h
index 8fabdbf08e..7070cc02aa 100644
--- a/tp/Texinfo/XS/parsetexi/api.h
+++ b/tp/Texinfo/XS/parsetexi/api.h
@@ -18,6 +18,7 @@ void parser_add_include_directory (char *filename);
 void parser_add_expanded_format (char *format);
 void parser_clear_expanded_formats (void);
 void parser_set_accept_internalvalue (int value);
+void parser_set_restricted (int value);
 void parser_set_DOC_ENCODING_FOR_INPUT_FILE_NAME (int i);
 void parser_set_input_file_name_encoding (char *value);
 void parser_set_locale_encoding (char *value);
diff --git a/tp/Texinfo/XS/parsetexi/macro.c b/tp/Texinfo/XS/parsetexi/macro.c
index 5e2a4387ac..c01e4bc248 100644
--- a/tp/Texinfo/XS/parsetexi/macro.c
+++ b/tp/Texinfo/XS/parsetexi/macro.c
@@ -69,6 +69,9 @@ new_macro (char *name, ELEMENT *macro)
   MACRO *m = 0;
   size_t free_slot = 0;
 
+  if (global_restricted)
+    return;
+
   /* Check for an existing definition first for us to overwrite. */
   new = lookup_command (name);
   if (new)
diff --git a/tp/Texinfo/XS/parsetexi/parser.c b/tp/Texinfo/XS/parsetexi/parser.c
index b157937e58..cdfd8559ee 100644
--- a/tp/Texinfo/XS/parsetexi/parser.c
+++ b/tp/Texinfo/XS/parsetexi/parser.c
@@ -312,6 +312,7 @@ char *global_clickstyle = 0;
 char *global_documentlanguage = 0;
 int global_documentlanguage_fixed = 0;
 int global_accept_internalvalue = 0;
+int global_restricted = 0;
 
 enum kbd_enum global_kbdinputstyle = kbd_distinct;
 
@@ -336,11 +337,17 @@ set_documentlanguage_override (char *value)
 
 
 void
-set_accept_internalvalue(int value)
+set_accept_internalvalue (int value)
 {
   global_accept_internalvalue = value;
 }
 
+void
+set_restricted (int value)
+{
+  global_restricted = value;
+}
+
 /* Record the information from a command of global effect. */
 int
 register_global_command (ELEMENT *current)
diff --git a/tp/Texinfo/XS/parsetexi/parser.h b/tp/Texinfo/XS/parsetexi/parser.h
index 873305ed49..568ea850f8 100644
--- a/tp/Texinfo/XS/parsetexi/parser.h
+++ b/tp/Texinfo/XS/parsetexi/parser.h
@@ -81,6 +81,7 @@ int parse_texi (ELEMENT *root_elt, ELEMENT *current_elt);
 int parse_texi_document (void);
 void set_documentlanguage_override (char *value);
 void set_accept_internalvalue (int value);
+void set_restricted (int value);
 
 void push_conditional_stack (enum command_id cond, SOURCE_MARK *source_mark);
 CONDITIONAL_STACK_ITEM *pop_conditional_stack (void);
@@ -132,6 +133,7 @@ extern char *global_clickstyle;
 extern char *global_documentlanguage;
 extern int global_documentlanguage_fixed;
 extern int global_accept_internalvalue;
+extern int global_restricted;
 
 enum kbd_enum {kbd_none, kbd_code, kbd_example, kbd_distinct };
 extern enum kbd_enum global_kbdinputstyle;
diff --git a/tp/t/init/translate_txiinternalvalue_macro.init 
b/tp/t/init/translate_txiinternalvalue_macro.init
new file mode 100644
index 0000000000..8269fd1a7f
--- /dev/null
+++ b/tp/t/init/translate_txiinternalvalue_macro.init
@@ -0,0 +1,30 @@
+
+texinfo_register_command_formatting('sp', \&my_sp_formatting);
+
+sub my_sp_formatting($$$$$)
+{
+  my $self = shift;
+  my $cmdname = shift;
+  my $command = shift;
+  my $args = shift;
+  my $content = shift;
+
+  if (defined($command->{'extra'})
+      and defined($command->{'extra'}->{'misc_args'})
+      and defined($command->{'extra'}->{'misc_args'}->[0])) {
+    my $sp_nr = $command->{'extra'}->{'misc_args'}->[0];
+    my $translated_tree = $self->gdt('@macro txiinternalvalue
+user internalvalue
+@end macro
+{myarg} @TeX{}', {'myarg' => {'contents' => [{'text' => $sp_nr}]}});
+    #print STDERR "T 
".Texinfo::Common::debug_print_tree($translated_tree)."\n";
+    $result = $self->convert_tree($translated_tree);
+    return $result;
+  }
+
+  return &{$self->default_command_conversion($cmdname)}($self,
+        $cmdname, $command, $args, $content);
+}
+
+
+1;
diff --git a/tp/t/init_files_tests.t b/tp/t/init_files_tests.t
index 0b1ae6e7e2..3e4276abd5 100644
--- a/tp/t/init_files_tests.t
+++ b/tp/t/init_files_tests.t
@@ -21,6 +21,13 @@ fr @error{}.
 pt @error{}.
 
 ', {'init_files' => ['command_translation_modified.init']}],
+['macro_defined_txiinternalvalue_in_translation',
+'@sp 1
+
+@sp 2
+
+',{'init_files' => ['translate_txiinternalvalue_macro.init'],
+}],
 );
 
 my @file_tests = (
diff --git 
a/tp/t/results/init_files_tests/macro_defined_txiinternalvalue_in_translation.pl
 
b/tp/t/results/init_files_tests/macro_defined_txiinternalvalue_in_translation.pl
new file mode 100644
index 0000000000..8a984fe89a
--- /dev/null
+++ 
b/tp/t/results/init_files_tests/macro_defined_txiinternalvalue_in_translation.pl
@@ -0,0 +1,155 @@
+use vars qw(%result_texis %result_texts %result_trees %result_errors 
+   %result_indices %result_sectioning %result_nodes %result_menus
+   %result_floats %result_converted %result_converted_errors 
+   %result_elements %result_directions_text %result_indices_sort_strings);
+
+use utf8;
+
+$result_trees{'macro_defined_txiinternalvalue_in_translation'} = {
+  'contents' => [
+    {
+      'contents' => [
+        {
+          'args' => [
+            {
+              'contents' => [
+                {
+                  'text' => '1'
+                }
+              ],
+              'info' => {
+                'spaces_after_argument' => {
+                  'text' => '
+'
+                }
+              },
+              'type' => 'line_arg'
+            }
+          ],
+          'cmdname' => 'sp',
+          'extra' => {
+            'misc_args' => [
+              '1'
+            ]
+          },
+          'info' => {
+            'spaces_before_argument' => {
+              'text' => ' '
+            }
+          },
+          'source_info' => {
+            'file_name' => '',
+            'line_nr' => 1,
+            'macro' => ''
+          }
+        },
+        {
+          'text' => '
+',
+          'type' => 'empty_line'
+        },
+        {
+          'args' => [
+            {
+              'contents' => [
+                {
+                  'text' => '2'
+                }
+              ],
+              'info' => {
+                'spaces_after_argument' => {
+                  'text' => '
+'
+                }
+              },
+              'type' => 'line_arg'
+            }
+          ],
+          'cmdname' => 'sp',
+          'extra' => {
+            'misc_args' => [
+              '2'
+            ]
+          },
+          'info' => {
+            'spaces_before_argument' => {
+              'text' => ' '
+            }
+          },
+          'source_info' => {
+            'file_name' => '',
+            'line_nr' => 3,
+            'macro' => ''
+          }
+        },
+        {
+          'text' => '
+',
+          'type' => 'empty_line'
+        }
+      ],
+      'type' => 'before_node_section'
+    }
+  ],
+  'type' => 'document_root'
+};
+
+$result_texis{'macro_defined_txiinternalvalue_in_translation'} = '@sp 1
+
+@sp 2
+
+';
+
+
+$result_texts{'macro_defined_txiinternalvalue_in_translation'} = '
+
+
+
+
+';
+
+$result_errors{'macro_defined_txiinternalvalue_in_translation'} = [];
+
+
+$result_floats{'macro_defined_txiinternalvalue_in_translation'} = {};
+
+
+
+$result_converted{'html'}->{'macro_defined_txiinternalvalue_in_translation'} = 
'<!DOCTYPE html>
+<html>
+<!-- Created by texinfo, http://www.gnu.org/software/texinfo/ -->
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+<title>Untitled Document</title>
+
+<meta name="description" content="Untitled Document">
+<meta name="keywords" content="Untitled Document">
+<meta name="resource-type" content="document">
+<meta name="distribution" content="global">
+<meta name="viewport" content="width=device-width,initial-scale=1">
+
+
+
+</head>
+
+<body lang="en">
+1 TeX
+2 TeX
+
+
+
+</body>
+</html>
+';
+
+$result_converted_errors{'html'}->{'macro_defined_txiinternalvalue_in_translation'}
 = [
+  {
+    'error_line' => 'warning: must specify a title with a title command or @top
+',
+    'text' => 'must specify a title with a title command or @top',
+    'type' => 'warning'
+  }
+];
+
+
+1;



reply via email to

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