texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: Character conversion for info reference labels


From: Gavin D. Smith
Subject: branch master updated: Character conversion for info reference labels
Date: Sat, 20 Aug 2022 07:11:22 -0400

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 67dffdb9f7 Character conversion for info reference labels
67dffdb9f7 is described below

commit 67dffdb9f7075296d259474b36bfa46a321d34bf
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Sat Aug 20 12:11:12 2022 +0100

    Character conversion for info reference labels
    
    * info/scan.c (scan_reference_label): Convert reference label
    using iconv conversion.
    (init_conversion, close_conversion): Set iconv object to (iconv_t) -1
    after calling iconv_close so we know not to use it.
    
    Patrice reported that index entries would not be converted and
    not found with info --apropros.
---
 ChangeLog   | 12 ++++++++++++
 info/scan.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 60 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 7b03edd6a1..d9e0588a0b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2022-08-20  Gavin Smith  <gavinsmith0123@gmail.com>
+
+       Character conversion for info reference labels
+
+       * info/scan.c (scan_reference_label): Convert reference label
+       using iconv conversion.
+       (init_conversion, close_conversion): Set iconv object to (iconv_t) -1
+       after calling iconv_close so we know not to use it.
+
+       Patrice reported that index entries would not be converted and
+       not found with info --apropros.
+
 2022-08-19  Gavin Smith  <gavinsmith0123@gmail.com>
 
        \vtop for @group
diff --git a/info/scan.c b/info/scan.c
index f59fbb9ce8..c013d643fd 100644
--- a/info/scan.c
+++ b/info/scan.c
@@ -524,6 +524,7 @@ init_conversion (FILE_BUFFER *fb)
         {
           /* Return if no conversion function implemented */
           iconv_close (iconv_to_output);
+          iconv_to_output = (iconv_t) -1;
           return; 
         }
     }
@@ -539,6 +540,7 @@ void close_conversion (void)
   if (convert_encoding_p)
     {
       iconv_close (iconv_to_output);
+      iconv_to_output = (iconv_t) -1;
       if (!file_is_in_utf8) iconv_close (iconv_to_utf8);
     }
 #endif
@@ -1169,9 +1171,52 @@ scan_reference_label (REFERENCE *entry, int in_index)
       label_len += m - 1;
     }
 
-  entry->label = xmalloc (label_len + 1);
-  memcpy (entry->label, inptr, label_len);
-  entry->label[label_len] = '\0';
+#if HAVE_ICONV
+  if (iconv_to_output != (iconv_t) -1 && iconv_to_output != (iconv_t) 0)
+    {
+      static struct text_buffer label_text;
+      size_t iconv_ret;
+      size_t inbytesleft = label_len;
+      char *p = inptr;
+      text_buffer_reset (&label_text);
+      text_buffer_alloc (&label_text, label_len);
+
+      while (1)
+        {
+          iconv_ret = text_buffer_iconv (&label_text, iconv_to_output,
+                                         (ICONV_CONST char **)&p,
+                                         &inbytesleft);
+
+          /* Make sure libiconv flushes out the last converted character. */
+          if (iconv_ret != (size_t) -1
+                && text_buffer_iconv (&label_text, iconv_to_output,
+                       NULL, NULL) != (size_t) -1)
+            break; /* Success: all of input converted. */
+
+          /* There's been an error while converting. */
+          switch (errno)
+            {
+            case E2BIG:
+              /* Ran out of space in output buffer.  Allocate more
+                 and try again. */
+              text_buffer_alloc (&label_text, label_len);
+              continue;
+            default: /* EINVAL or EILSEQ or unknown error */
+              goto no_convert;
+            }
+        }
+
+      text_buffer_add_char (&label_text, '\0');
+      entry->label = strdup (label_text.base);
+    }
+  else
+#endif
+    {
+  no_convert:
+      entry->label = xmalloc (label_len + 1);
+      memcpy (entry->label, inptr, label_len);
+      entry->label[label_len] = '\0';
+    }
   canonicalize_whitespace (entry->label);
 
   if (preprocess_nodes_p)



reply via email to

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