texinfo-commits
[Top][All Lists]
Advanced

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

[5332] Check for I/O errors when dumping nodes to file.


From: Sergey Poznyakoff
Subject: [5332] Check for I/O errors when dumping nodes to file.
Date: Tue, 20 Aug 2013 12:04:19 +0000

Revision: 5332
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=5332
Author:   gray
Date:     2013-08-20 12:04:17 +0000 (Tue, 20 Aug 2013)
Log Message:
-----------
Check for I/O errors when dumping nodes to file.
Use a general-purpose interface for storing and looking up in
a list of names.

* info/info-utils.c (info_namelist_add)
(info_namelist_free): New functions.
* info/info-utils.h: Likewise.
* info/info.c (namelist_add,namelist_free): Move to
info-utils.c, redeclare as extern.
(all_files): Update accordingly.
* info/session.c [VERBOSE_NODE_DUMPING]: Replace with
calls to debug.
(write_node_to_stream)
(dump_node_to_stream): Return error code.
(dump_nodes_to_file): Check for I/O errors,
(dumped_already): Change data type to struct
info_namelist_entry *.
(dumped_already_index, dumped_already_slots): Remove.
(initialize_dumping): Rewrite.

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/info/info-utils.c
    trunk/info/info-utils.h
    trunk/info/info.c
    trunk/info/session.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2013-08-20 08:08:30 UTC (rev 5331)
+++ trunk/ChangeLog     2013-08-20 12:04:17 UTC (rev 5332)
@@ -1,5 +1,27 @@
 2013-08-20  Sergey Poznyakoff  <address@hidden>
 
+       Check for I/O errors when dumping nodes to file.
+       Use a general-purpose interface for storing and looking up in
+       a list of names.
+
+       * info/info-utils.c (info_namelist_add)
+       (info_namelist_free): New functions.
+       * info/info-utils.h: Likewise.
+       * info/info.c (namelist_add,namelist_free): Move to
+       info-utils.c, redeclare as extern.
+       (all_files): Update accordingly.
+       * info/session.c [VERBOSE_NODE_DUMPING]: Replace with
+       calls to debug.
+       (write_node_to_stream)
+       (dump_node_to_stream): Return error code.
+       (dump_nodes_to_file): Check for I/O errors,
+       (dumped_already): Change data type to struct
+       info_namelist_entry *.
+       (dumped_already_index, dumped_already_slots): Remove.
+       (initialize_dumping): Rewrite.
+
+2013-08-20  Sergey Poznyakoff  <address@hidden>
+
        Bind display-file to C-g in vi mode.
 
        * info/infomap.c (default_vi_like_info_keys): Bind display-file to

Modified: trunk/info/info-utils.c
===================================================================
--- trunk/info/info-utils.c     2013-08-20 08:08:30 UTC (rev 5331)
+++ trunk/info/info-utils.c     2013-08-20 12:04:17 UTC (rev 5332)
@@ -880,3 +880,37 @@
   va_end (ap);
   return n;
 }
+
+struct info_namelist_entry
+{
+  struct info_namelist_entry *next;
+  char name[1];
+};
+
+int
+info_namelist_add (struct info_namelist_entry **ptop, const char *name)
+{
+  struct info_namelist_entry *p;
+
+  for (p = *ptop; p; p = p->next)
+    if (strcmp (p->name, name) == 0)
+      return 1;
+
+  p = xmalloc (sizeof (*p) + strlen (name));
+  strcpy (p->name, name);
+  p->next = *ptop;
+  *ptop = p;
+  return 0;
+}
+
+void
+info_namelist_free (struct info_namelist_entry *top)
+{
+  while (top)
+    {
+      struct info_namelist_entry *next = top->next;
+      free (top);
+      top = next;
+    }
+}
+

Modified: trunk/info/info-utils.h
===================================================================
--- trunk/info/info-utils.h     2013-08-20 08:08:30 UTC (rev 5331)
+++ trunk/info/info-utils.h     2013-08-20 12:04:17 UTC (rev 5332)
@@ -169,5 +169,9 @@
 #define text_buffer_reset(buf) ((buf)->off = 0)
 #define text_buffer_base(buf) ((buf)->base)
 #define text_buffer_off(buf) ((buf)->off)
+
+struct info_namelist_entry;
+int info_namelist_add (struct info_namelist_entry **ptop, const char *name);
+void info_namelist_free (struct info_namelist_entry *top);
 
 #endif /* not INFO_UTILS_H */

Modified: trunk/info/info.c
===================================================================
--- trunk/info/info.c   2013-08-20 08:08:30 UTC (rev 5331)
+++ trunk/info/info.c   2013-08-20 12:04:17 UTC (rev 5332)
@@ -199,8 +199,8 @@
       if (print_where_p)
         printf ("%s\n", filename ? filename : "unknown?!");
       else if (user_output_filename)
-        dump_nodes_to_file
-          (filename, user_nodenames, user_output_filename, dump_subnodes);
+        dump_nodes_to_file (filename, user_nodenames,
+                           user_output_filename, dump_subnodes);
       else
         begin_multiple_window_info_session (filename, user_nodenames);
 
@@ -376,48 +376,14 @@
   return argv;
 }
 
-struct namelist_ent
-{
-  struct namelist_ent *next;
-  char name[1];
-};
-
 static int
-namelist_add (struct namelist_ent **ptop, const char *name)
-{
-  struct namelist_ent *p;
-
-  for (p = *ptop; p; p = p->next)
-    if (strcmp (p->name, name) == 0)
-      return 1;
-
-  p = xmalloc (sizeof (*p) + strlen (name));
-  strcpy (p->name, name);
-  p->next = *ptop;
-  *ptop = p;
-  return 0;
-}
-
-static void
-namelist_free (struct namelist_ent *top)
-{
-  while (top)
-    {
-      struct namelist_ent *next = top->next;
-      free (top);
-      top = next;
-    }
-}
-
-
-static int
 all_files (char *filename, int argc, char **argv)
 {
   REFERENCE **fref;
   char *fname;
   int i, j;
   int dirok;
-  struct namelist_ent *nlist = NULL;
+  struct info_namelist_entry *nlist = NULL;
   int dump_flags = dump_subnodes;
   
   if (user_filename)
@@ -479,7 +445,7 @@
        }
       else
        {
-         if (namelist_add (&nlist, fref[i]->filename) == 0)
+         if (info_namelist_add (&nlist, fref[i]->filename) == 0)
            {
              if (print_where_p)
                printf ("%s\n", fref[i]->filename);
@@ -502,7 +468,7 @@
        }
     }
   
-  namelist_free (nlist);
+  info_namelist_free (nlist);
 
   if (print_where_p || user_output_filename)
     return EXIT_SUCCESS;

Modified: trunk/info/session.c
===================================================================
--- trunk/info/session.c        2013-08-20 08:08:30 UTC (rev 5331)
+++ trunk/info/session.c        2013-08-20 12:04:17 UTC (rev 5332)
@@ -2823,8 +2823,8 @@
       REFERENCE *entry;
       char *arg = *menus; /* Remember the name of the menu entry we want. */
 
-      debug(3, ("looking for %s in %s:%s", arg, initial_node->filename,
-               initial_node->nodename));
+      debug (3, ("looking for %s in %s:%s", arg, initial_node->filename,
+                initial_node->nodename));
       /* A leading space is certainly NOT part of a node name.  Most
          probably, they typed a space after the separating comma.  The
          strings in menus[] have their whitespace canonicalized, so
@@ -2842,13 +2842,13 @@
          realize it. */
       if (!menu)
         {
-         debug(3, ("no menu found"));
+         debug (3, ("no menu found"));
           if (arg == first_arg && !strict)
             {
               node = make_manpage_node (first_arg);
               if (node)
                {
-                 debug(3, ("falling back to manpage node"));
+                 debug (3, ("falling back to manpage node"));
                  goto maybe_got_node;
                }
             }
@@ -2868,7 +2868,7 @@
           int i;
           int best_guess = -1;
 
-         debug(3, ("no entry found: guessing"));
+         debug (3, ("no entry found: guessing"));
           for (i = 0; (entry = menu[i]); i++)
             {
               if (mbscasecmp (entry->label, arg) == 0)
@@ -2914,7 +2914,7 @@
         entry->filename = xstrdup (initial_node->parent ? initial_node->parent
                                                      : initial_node->filename);
 
-      debug(3, ("entry: %s, %s", entry->filename, entry->nodename));
+      debug (3, ("entry: %s, %s", entry->filename, entry->nodename));
       
       /* Try to find this node.  */
       node = info_get_node (entry->filename, entry->nodename, 
@@ -2935,7 +2935,7 @@
     maybe_got_node:
       if (!node)
         {
-         debug(3, ("no matching node found"));
+         debug (3, ("no matching node found"));
          if (err_node)
            *err_node = format_message_node (
                     _("Unable to find node referenced by `%s' in `%s'."),
@@ -2945,7 +2945,7 @@
           return strict ? NULL : initial_node;
         }
 
-      debug(3, ("node: %s, %s", node->filename, node->nodename));
+      debug (3, ("node: %s, %s", node->filename, node->nodename));
       
       info_free_references (menu);
 
@@ -3485,10 +3485,16 @@
 /*                                                                  */
 /* **************************************************************** */
 
-#define VERBOSE_NODE_DUMPING
-static void write_node_to_stream (NODE *node, FILE *stream);
-static void dump_node_to_stream (char *filename, char *nodename,
-    FILE *stream, int dump_subnodes);
+enum
+  {
+    DUMP_SUCCESS,
+    DUMP_INFO_ERROR,
+    DUMP_SYS_ERROR
+  };
+
+static int write_node_to_stream (NODE *node, FILE *stream);
+static int dump_node_to_stream (char *filename, char *nodename,
+                               FILE *stream, int dump_subnodes);
 static void initialize_dumping (void);
 
 /* Dump the nodes specified by FILENAME and NODENAMES to the file named
@@ -3498,8 +3504,10 @@
 dump_nodes_to_file (char *filename, char **nodenames,
                    char *output_filename, int flags)
 {
-  register int i;
+  int i;
   FILE *output_stream;
+  
+  debug (1, (_("writing file %s"), filename));
 
   /* Get the stream to print the nodes to.  Special case of an output
      filename of "-" means to dump the nodes to stdout. */
@@ -3514,37 +3522,43 @@
       return;
     }
 
+  initialize_dumping ();
+
   /* Print each node to stream. */
-  initialize_dumping ();
+  if (flags & DUMP_APPEND)
+    fputc ('\f', output_stream);
   for (i = 0; nodenames[i]; i++)
-    dump_node_to_stream (filename, nodenames[i], output_stream,
-                        flags & DUMP_SUBNODES);
-
+    {
+      if (dump_node_to_stream (filename, nodenames[i], output_stream,
+                              flags & DUMP_SUBNODES) == DUMP_SYS_ERROR)
+       {
+         info_error (_("error writing to %s: %s"), filename, strerror (errno));
+         exit (EXIT_FAILURE);
+       }
+    }
+  
   if (output_stream != stdout)
     fclose (output_stream);
 
-#if defined (VERBOSE_NODE_DUMPING)
-  info_error ("%s", _("Done."));
-#endif /* VERBOSE_NODE_DUMPING */
+  debug (1, (_("closing %s"), filename));
 }
 
 /* A place to remember already dumped nodes. */
-static char **dumped_already = NULL;
-static int dumped_already_index = 0;
-static int dumped_already_slots = 0;
+static struct info_namelist_entry *dumped_already;
 
 static void
 initialize_dumping (void)
 {
-  dumped_already_index = 0;
+  info_namelist_free (dumped_already);
+  dumped_already = NULL;
 }
 
 /* Get and print the node specified by FILENAME and NODENAME to STREAM.
    If DUMP_SUBNODES is non-zero, recursively dump the nodes which appear
    in the menu of each node dumped. */
-static void
+static int
 dump_node_to_stream (char *filename, char *nodename,
-    FILE *stream, int dump_subnodes)
+                    FILE *stream, int dump_subnodes)
 {
   register int i;
   NODE *node;
@@ -3564,25 +3578,21 @@
           else
             info_error (msg_cant_find_node, nodename);
         }
-      return;
+      return DUMP_INFO_ERROR;
     }
 
   /* If we have already dumped this node, don't dump it again. */
-  for (i = 0; i < dumped_already_index; i++)
-    if (strcmp (node->nodename, dumped_already[i]) == 0)
-      {
-        free (node);
-        return;
-      }
-  add_pointer_to_array (node->nodename, dumped_already_index, dumped_already,
-                        dumped_already_slots, 50, char *);
+  if (info_namelist_add (&dumped_already, node->nodename))
+    {
+      free (node);
+      return DUMP_SUCCESS;
+    }
 
-#if defined (VERBOSE_NODE_DUMPING)
   /* Maybe we should print some information about the node being output. */
-  info_error (_("Writing node %s..."), node_printed_rep (node));
-#endif /* VERBOSE_NODE_DUMPING */
+  debug (1, (_("writing node %s..."), node_printed_rep (node)));
 
-  write_node_to_stream (node, stream);
+  if (write_node_to_stream (node, stream))
+    return DUMP_SYS_ERROR;
 
   /* If we are dumping subnodes, get the list of menu items in this node,
      and dump each one recursively. */
@@ -3601,14 +3611,17 @@
               /* We don't dump Info files which are different than the
                  current one. */
               if (!menu[i]->filename)
-                dump_node_to_stream
-                  (filename, menu[i]->nodename, stream, dump_subnodes);
+                if (dump_node_to_stream (filename, menu[i]->nodename,
+                                        stream, dump_subnodes) == 
DUMP_SYS_ERROR)
+                 return DUMP_SYS_ERROR;
             }
           info_free_references (menu);
         }
     }
 
   free (node);
+
+  return DUMP_SUCCESS;
 }
 
 /* Dump NODE to FILENAME.  If DUMP_SUBNODES is set, recursively dump
@@ -3619,6 +3632,8 @@
   FILE *output_stream;
   char *nodes_filename;
 
+  debug (1, (_("writing file %s"), filename));
+  
   /* Get the stream to print this node to.  Special case of an output
      filename of "-" means to dump the nodes to stdout. */
   if (strcmp (filename, "-") == 0)
@@ -3638,17 +3653,23 @@
     nodes_filename = node->filename;
 
   initialize_dumping ();
+  
   if (flags & DUMP_APPEND)
     fputc ('\f', output_stream);
-  dump_node_to_stream (nodes_filename, node->nodename,
-                      output_stream, flags & DUMP_SUBNODES);
+  fprintf (output_stream, "%s\n", info_find_fullpath (node->filename));
 
+  if (dump_node_to_stream (nodes_filename, node->nodename,
+                          output_stream, flags & DUMP_SUBNODES)
+      == DUMP_SYS_ERROR)
+    {
+      info_error (_("error writing to %s: %s"), filename, strerror (errno));
+      exit (EXIT_FAILURE);
+    }
+
   if (output_stream != stdout)
     fclose (output_stream);
 
-#if defined (VERBOSE_NODE_DUMPING)
-  info_error ("%s", _("Done."));
-#endif /* VERBOSE_NODE_DUMPING */
+  debug (1, (_("closing file %s"), filename));
 }
 
 #if !defined (DEFAULT_INFO_PRINT_COMMAND)
@@ -3695,10 +3716,8 @@
       return;
     }
 
-#if defined (VERBOSE_NODE_DUMPING)
   /* Maybe we should print some information about the node being output. */
-  info_error (_("Printing node %s..."), node_printed_rep (node));
-#endif /* VERBOSE_NODE_DUMPING */
+  debug (1, (_("printing node %s..."), node_printed_rep (node)));
 
   write_node_to_stream (node, printer_pipe);
   if (piping)
@@ -3706,15 +3725,13 @@
   else
     fclose (printer_pipe);
 
-#if defined (VERBOSE_NODE_DUMPING)
-  info_error ("%s", _("Done."));
-#endif /* VERBOSE_NODE_DUMPING */
+  debug (1, (_("finished printing node %s"), node_printed_rep (node)));
 }
 
-static void
+static int
 write_node_to_stream (NODE *node, FILE *stream)
 {
-  fwrite (node->contents, 1, node->nodelen, stream);
+  return fwrite (node->contents, node->nodelen, 1, stream) != 1;
 }
 
 /* **************************************************************** */
@@ -5376,8 +5393,9 @@
   if (fname)
     {
       int line = window_line_of_point (window);
-      window_message_in_echo_area ("File name: %s, line %d of %ld (%d%%)",
-                                  fname, line, window->line_count,
+      window_message_in_echo_area ("File name: %s, line %d of %lu (%d%%)",
+                                  fname, line,
+                                  (unsigned long) window->line_count,
                                   line * 100 / window->line_count);
     }
   else




reply via email to

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