texinfo-commits
[Top][All Lists]
Advanced

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

[7857] parsetexi check for language codes to pass languages.t test


From: gavinsmith0123
Subject: [7857] parsetexi check for language codes to pass languages.t test
Date: Sun, 25 Jun 2017 13:53:15 -0400 (EDT)

Revision: 7857
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=7857
Author:   gavin
Date:     2017-06-25 13:53:14 -0400 (Sun, 25 Jun 2017)
Log Message:
-----------
parsetexi check for language codes to pass languages.t test

Modified Paths:
--------------
    trunk/tp/parsetexi/Parsetexi.pm
    trunk/tp/parsetexi/end_line.c

Modified: trunk/tp/parsetexi/Parsetexi.pm
===================================================================
--- trunk/tp/parsetexi/Parsetexi.pm     2017-06-25 16:49:05 UTC (rev 7856)
+++ trunk/tp/parsetexi/Parsetexi.pm     2017-06-25 17:53:14 UTC (rev 7857)
@@ -1,4 +1,4 @@
-# Copyright 2014, 2015, 2016 Free Software Foundation, Inc.
+# Copyright 2014, 2015, 2016, 2017 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
@@ -25,6 +25,7 @@
 
 require Exporter;
 
+use Texinfo::Common;
 use Texinfo::Encoding;
 use Texinfo::Convert::NodeNameNormalization;
 
@@ -258,68 +259,6 @@
   }
 }
 
-# Copied from Texinfo::Parser.  Should move this to a common module.
-sub _complete_indices {
-  my $self = shift;
-
-  my ($index_entry, $index_contents_normalized);
-    
-  my $save_lang = $self->get_conf('documentlanguage');
-
-  foreach my $index_name (keys(%{$self->{'index_names'}})) {
-    next if !defined $self->{'index_names'}->{$index_name}->{'index_entries'};
-    foreach my $entry 
(@{$self->{'index_names'}->{$index_name}->{'index_entries'}}) {
-      $entry->{'in_code'} = $self->{'index_names'}->{$index_name}->{'in_code'};
-      
-      if (!defined $entry->{'content'}) {
-        my $def_command = $entry->{'command'}->{'extra'}->{'def_command'};
-
-        my $def_parsed_hash = 
$entry->{'command'}->{'extra'}->{'def_parsed_hash'}; 
-        if ($def_parsed_hash and $def_parsed_hash->{'class'}
-            and $def_command) {
-          # Use the document language that was current when the command was
-          # used for getting the translation.
-          $self->{'documentlanguage'} = 
$entry->{'command'}->{'extra'}->{'documentlanguage'};
-          delete $entry->{'command'}->{'extra'}->{'documentlanguage'};
-          if ($def_command eq 'defop'
-              or $def_command eq 'deftypeop'
-              or $def_command eq 'defmethod'
-              or $def_command eq 'deftypemethod') {
-            $index_entry = $self->gdt('{name} on {class}',
-                                  {'name' => $def_parsed_hash->{'name'},
-                                   'class' => $def_parsed_hash->{'class'}});
-           $index_contents_normalized
-             = [_non_bracketed_contents($def_parsed_hash->{'name'}),
-                { 'text' => ' on '},
-                _non_bracketed_contents($def_parsed_hash->{'class'})];
-          } elsif ($def_command eq 'defivar'
-                   or $def_command eq 'deftypeivar'
-                   or $def_command eq 'deftypecv') {
-            $index_entry = $self->gdt('{name} of {class}',
-                                     {'name' => $def_parsed_hash->{'name'},
-                                     'class' => $def_parsed_hash->{'class'}});
-            $index_contents_normalized
-              = [_non_bracketed_contents($def_parsed_hash->{'name'}),
-                 { 'text' => ' of '},
-                 _non_bracketed_contents($def_parsed_hash->{'class'})];
-          }
-        }
-        # 'root_line' is the container returned by gdt.
-        if ($index_entry->{'type'} and $index_entry->{'type'} eq 'root_line') {
-          for my $child (@{$index_entry->{'contents'}}) {
-            delete $child->{'parent'};
-          }
-        }
-        if ($index_entry->{'contents'}) {
-          $entry->{'content'} = address@hidden>{'contents'}}];
-          $entry->{'content_normalized'} = $index_contents_normalized;
-        }
-      }
-    }
-  }
-  $self->{'documentlanguage'} = $save_lang;
-}
-
 sub get_parser_info {
   my $self = shift;
 
@@ -331,7 +270,6 @@
   $FLOATS = build_float_list ();
 
   $INDEX_NAMES = build_index_data ();
-  _complete_indices ($self);
 
   $GLOBAL_INFO = build_global_info ();
   $GLOBAL_INFO2 = build_global_info2 ();
@@ -344,6 +282,7 @@
   $self->{'extra'} = $GLOBAL_INFO2;
 
   _get_errors ($self);
+  Texinfo::Common::complete_indices ($self);
 }
 
 # Replacement for Texinfo::Parser::parse_texi_file (line 835)

Modified: trunk/tp/parsetexi/end_line.c
===================================================================
--- trunk/tp/parsetexi/end_line.c       2017-06-25 16:49:05 UTC (rev 7856)
+++ trunk/tp/parsetexi/end_line.c       2017-06-25 17:53:14 UTC (rev 7857)
@@ -1711,27 +1711,40 @@
               p = text;
               while (isalpha (*p))
                 p++;
-              if (*p == '_')
+              if (*p && *p != '_')
                 {
-                  q = p + 1;
-                  p = q;
-                  /* Language code should be of the form LL_CC, language code
-                     followed by country code. */
-                  while (isalpha (*p))
-                    p++;
-                  if (*p)
-                    {
-                      /* non-alphabetic char in country code */
-                      command_warn (current, "%s is not a valid region code",
-                                    q);
-                    }
-                }
-              else if (*p)
-                {
                    /* non-alphabetic char in language code */
                   command_warn (current, "%s is not a valid language code",
                                 text);
                 }
+              else
+                {
+                  if (p - text > 4)
+                    {
+                      /* looks too long */
+                      char c = *p;
+                      *p = 0;
+                      command_warn (current, "%s is not a valid language code",
+                                    text);
+                      *p = c;
+                    }
+                  if (*p == '_')
+                    {
+                      q = p + 1;
+                      p = q;
+                      /* Language code should be of the form LL_CC,
+                         language code followed by country code. */
+                      while (isalpha (*p))
+                        p++;
+                      if (*p || p - q > 4)
+                        {
+                          /* non-alphabetic char in country code or code
+                             is too long. */
+                          command_warn (current,
+                                        "%s is not a valid region code", q);
+                        }
+                    }
+                }
 
               global_documentlanguage = text;
               /* TODO: check customization variable */




reply via email to

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