texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/XS/texi2any.c (main): use a variable


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/XS/texi2any.c (main): use a variable to be more robust for non_first_file_cmdline_options initialization and free'ing.
Date: Sun, 05 Jan 2025 07:50:03 -0500

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

pertusus pushed a commit to branch master
in repository texinfo.

The following commit(s) were added to refs/heads/master by this push:
     new 56b10cdc55 * tp/Texinfo/XS/texi2any.c (main): use a variable to be 
more robust for non_first_file_cmdline_options initialization and free'ing.
56b10cdc55 is described below

commit 56b10cdc5584bd0ee9a2f06d9b52cd077173fe61
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Jan 5 13:49:50 2025 +0100

    * tp/Texinfo/XS/texi2any.c (main): use a variable to be more robust
    for non_first_file_cmdline_options initialization and free'ing.
    
    * tp/Texinfo/XS/texi2any.c (main): close files.
---
 ChangeLog                |  7 +++++++
 tp/Texinfo/XS/texi2any.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 58 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index cb5f5adccb..eb8e8f74c5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2025-01-05  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/texi2any.c (main): use a variable to be more robust
+       for non_first_file_cmdline_options initialization and free'ing.
+
+       * tp/Texinfo/XS/texi2any.c (main): close files.
+
 2025-01-05  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/texi2any.c (main): free texi2dvi_args also in case
diff --git a/tp/Texinfo/XS/texi2any.c b/tp/Texinfo/XS/texi2any.c
index a392ab5c54..7350c4886e 100644
--- a/tp/Texinfo/XS/texi2any.c
+++ b/tp/Texinfo/XS/texi2any.c
@@ -894,6 +894,9 @@ main (int argc, char *argv[], char *env[])
   /* used except for the first file, to remove some options that are only
      relevant for the first file */
   OPTIONS_LIST non_first_file_cmdline_options;
+  /* make sure that non_first_file_cmdline_options was initialized,
+     even if a file was skipped */
+  int non_first_file_cmdline_initialized = 0;
   size_t errors_count = 0;
   size_t errors_nr;
   STRING_LIST *texinfo_language_config_dirs;
@@ -957,6 +960,7 @@ main (int argc, char *argv[], char *env[])
   unsigned long transformation_flags = 0;
   const char *txi_xs_external_conversion;
   const char *txi_xs_external_formatting;
+  FILE *main_program_unclosed_stdout = 0;
 
   parse_file_path (argv[0], program_file_name_and_directory);
   program_file = program_file_name_and_directory[0];
@@ -2491,7 +2495,11 @@ main (int argc, char *argv[], char *env[])
 
       if (i != 0)
         {
-          initialize_options_list (&non_first_file_cmdline_options);
+          if (!non_first_file_cmdline_initialized)
+            {
+              initialize_options_list (&non_first_file_cmdline_options);
+              non_first_file_cmdline_initialized = 1;
+            }
           copy_options_list (&non_first_file_cmdline_options,
                              &cmdline_options);
           options_list_remove_option_number (&non_first_file_cmdline_options,
@@ -2514,6 +2522,9 @@ main (int argc, char *argv[], char *env[])
       copy_options_list (&convert_options, init_files_options);
       copy_options_list (&convert_options, file_cmdline_options);
 
+      if (i != 0)
+        clear_options_list (&non_first_file_cmdline_options);
+
       /* prepend to INCLUDE_DIRECTORIES by resetting include directories to
          merged prepended directories and command line include directories */
       converter_include_dirs_option
@@ -2570,6 +2581,34 @@ main (int argc, char *argv[], char *env[])
 
       errors_count = handle_errors (errors_nr, errors_count, &opened_files);
 
+      if (converter->output_files_information.unclosed_files.number > 0)
+        {
+          FILE_STREAM_LIST *unclosed_files
+            = &converter->output_files_information.unclosed_files;
+
+          for (j = 0; j < unclosed_files->number; j++)
+            {
+              FILE_STREAM *file_stream = &unclosed_files->list[j];
+               /*
+              fprintf (stderr, "Unclosed file '%s' %p\n",
+                file_stream->file_path, file_stream->stream);
+                */
+              if (!strcmp (file_stream->file_path, "-"))
+                main_program_unclosed_stdout = file_stream->stream;
+              else
+                {
+                  if (fclose (file_stream->stream))
+                    {
+                      fprintf (stderr, _("%s: error on closing %s: %s"),
+                               program_file, file_stream->file_path,
+                               strerror (errno));
+                      errors_count = handle_errors (1,
+                                                errors_count, &opened_files);
+                    }
+                }
+            }
+        }
+
       if (format_specification->flags & STTF_internal_links && i == 0)
         {
           OPTION *internal_links_option
@@ -2791,9 +2830,19 @@ main (int argc, char *argv[], char *env[])
       clear_options_list (&convert_options);
     }
 
+  if (main_program_unclosed_stdout)
+    {
+      if (fclose (main_program_unclosed_stdout))
+        {
+          fprintf (stderr, _("%s: error on closing %s: %s"),
+                   program_file, "-", strerror (errno));
+          errors_count = handle_errors (1, errors_count, &opened_files);
+        }
+    }
+
   destroy_converter_initialization_info (converter_init_info);
 
-  if (input_files.number > 1)
+  if (non_first_file_cmdline_initialized)
     free_options_list (&non_first_file_cmdline_options);
 
   free_strings_list (&prepended_include_directories);



reply via email to

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