texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Tue, 1 Oct 2024 12:40:10 -0400 (EDT)

branch: master
commit a78fb6d64eb6991cbfd862bd5a4e0e256c745079
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Thu Jul 25 19:12:53 2024 +0200

    * tp/Texinfo/XS/parsetexi/input.c (set_input_encoding)
    (encode_file_name): add filename_encoding_conversion to cache the
    encoding conversion like reverse_iconv did previously.  Reset in
    set_input_encoding.  Call directly encode_with_iconv instead of
    encode_string.
---
 ChangeLog                       |  8 ++++++++
 tp/Texinfo/XS/parsetexi/input.c | 45 +++++++++++++++++++++++++----------------
 2 files changed, 36 insertions(+), 17 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 971e4ba29f..26df58564e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-07-25  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/parsetexi/input.c (set_input_encoding)
+       (encode_file_name): add filename_encoding_conversion to cache the
+       encoding conversion like reverse_iconv did previously.  Reset in
+       set_input_encoding.  Call directly encode_with_iconv instead of
+       encode_string.
+
 2024-07-25  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/parsetexi/input.c (set_input_encoding)
diff --git a/tp/Texinfo/XS/parsetexi/input.c b/tp/Texinfo/XS/parsetexi/input.c
index da637b87bf..8cd00d2b10 100644
--- a/tp/Texinfo/XS/parsetexi/input.c
+++ b/tp/Texinfo/XS/parsetexi/input.c
@@ -57,6 +57,9 @@ static char *input_pushback_string;
 
 static ENCODING_CONVERSION *current_encoding_conversion = 0;
 
+/* used in encode_file_name */
+static ENCODING_CONVERSION *filename_encoding_conversion = 0;
+
 /* ENCODING should always be lower cased */
 /* WARNING: it is very important for the first call to
    set_input_encoding to be for "utf-8" as the codes assume
@@ -66,6 +69,8 @@ set_input_encoding (const char *encoding)
 {
   int encoding_set = 0;
 
+  filename_encoding_conversion = 0;
+
   current_encoding_conversion
     = get_encoding_conversion (encoding, &input_conversions);
   if (current_encoding_conversion)
@@ -170,25 +175,33 @@ convert_to_utf8 (char *s)
 char *
 encode_file_name (char *filename)
 {
-  int status;
-  const char *encoding = 0;
 
-  if (global_parser_conf.input_file_name_encoding)
-    encoding = global_parser_conf.input_file_name_encoding;
-  else if (global_parser_conf.doc_encoding_for_input_file_name)
+  if (!filename_encoding_conversion)
     {
-      if (current_encoding_conversion
-          && strcmp (parsed_document->global_info.input_encoding_name,
-                     "utf-8"))
-        encoding = current_encoding_conversion->encoding_name;
+      const char *encoding = 0;
+
+      if (global_parser_conf.input_file_name_encoding)
+        encoding = global_parser_conf.input_file_name_encoding;
+      else if (global_parser_conf.doc_encoding_for_input_file_name)
+        {
+          if (current_encoding_conversion
+              && strcmp (parsed_document->global_info.input_encoding_name,
+                         "utf-8"))
+            encoding = current_encoding_conversion->encoding_name;
+        }
+      else if (global_parser_conf.locale_encoding)
+        encoding = global_parser_conf.locale_encoding;
+
+      if (encoding)
+        filename_encoding_conversion = get_encoding_conversion (encoding,
+                                                    &output_conversions);
     }
-  else if (global_parser_conf.locale_encoding)
-    encoding = global_parser_conf.locale_encoding;
 
-  if (encoding)
+  if (filename_encoding_conversion)
     {
-      char *result = encode_string (filename, encoding, &status,
-                                    &current_source_info);
+      char *result
+        = encode_with_iconv (filename_encoding_conversion->iconv,
+                             filename, &current_source_info);
       char *saved_string = save_string (result);
       free (result);
       return saved_string;
@@ -509,10 +522,8 @@ save_string (const char *string)
 void
 parser_reset_encoding_list (void)
 {
-  /* could be named global_encoding_conversion and reset in wipe_global_info,
-     but we prefer to keep it static as long as it is only used in one
-     file */
   current_encoding_conversion = 0;
+  filename_encoding_conversion = 0;
 }
 
 int



reply via email to

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