texinfo-commits
[Top][All Lists]
Advanced

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

[7794] convert eols unconditionally on msdos


From: gavinsmith0123
Subject: [7794] convert eols unconditionally on msdos
Date: Thu, 18 May 2017 16:59:44 -0400 (EDT)

Revision: 7794
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=7794
Author:   gavin
Date:     2017-05-18 16:59:43 -0400 (Thu, 18 May 2017)
Log Message:
-----------
convert eols unconditionally on msdos

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/info/filesys.c
    trunk/info/nodes.c
    trunk/info/nodes.h

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2017-05-17 21:10:02 UTC (rev 7793)
+++ trunk/ChangeLog     2017-05-18 20:59:43 UTC (rev 7794)
@@ -1,3 +1,29 @@
+2017-05-18  Gavin Smith  <address@hidden>
+
+       * info/nodes.c, info/filesys.c (convert_eols): Function moved 
+       between files.  Change arguments and modify text in place.  Do
+       not realloc the buffer to make it smaller.
+       * info/filesys.c (filesys_read_info_file)
+       [__MSDOS__, __MINGW32__]: Call convert_eols and realloc buffer.  
+       This reinstates call that was removed on 2014-10-24, except now 
+       it is MS-DOS/Windows only.
+
+       * info/nodes.c (find_node_from_tag): Remove most of the code
+       here that deals with conversion of end-of-lines, including
+       code updating pointers to node contents in currently-displayed 
+       windows.
+       * info/nodes.c (adjust_nodestart): Do not take extra argument 
+       giving the slack to search for a node.
+       * info/nodes.h (N_EOLs_Converted): Remove.
+
+       This reverses changes made on 2014-12-29.  Although there has 
+       not been a report of any problems with this code, it is too 
+       complicated and difficult to understand for what it achieves 
+       (allow reading Info files whether CR bytes before LF bytes are 
+       counted in the tag table or not).  It updates global data across 
+       the program which could cause problems in the future if there 
+       are changes elsewhere in the program.
+
 2017-05-17  Gavin Smith  <address@hidden>
 
        * tp/Texinfo/Parser.pm (_next_text):

Modified: trunk/info/filesys.c
===================================================================
--- trunk/info/filesys.c        2017-05-17 21:10:02 UTC (rev 7793)
+++ trunk/info/filesys.c        2017-05-18 20:59:43 UTC (rev 7794)
@@ -281,6 +281,35 @@
   return 0;
 }
 
+#if defined (__MSDOS__) || defined (__MINGW32__)
+/* Given a chunk of text and its length, convert all CRLF pairs at every
+   end-of-line into a single Newline character.  Return the length of
+   produced text.
+
+   This is required because the rest of code is too entrenched in having
+   a single newline at each EOL; in particular, searching for various
+   Info headers and cookies can become extremely tricky if that assumption
+   breaks. */
+static long
+convert_eols (char *text, long int textlen)
+{
+  register char *s = text;
+  register char *d = text;
+
+  while (textlen--)
+    {
+      if (*s == '\r' && textlen && s[1] == '\n')
+       {
+         s++;
+         textlen--;
+       }
+      *d++ = *s++;
+    }
+
+  return d - text;
+}
+#endif
+
 /* Read the contents of PATHNAME, returning a buffer with the contents of
    that file in it, and returning the size of that buffer in FILESIZE.
    If the file turns out to be compressed, set IS_COMPRESSED to non-zero.
@@ -330,6 +359,28 @@
       close (descriptor);
     }
 
+#if defined (__MSDOS__) || defined (__MINGW32__)
+  /* Old versions of makeinfo on MS-DOS or MS-Windows generated Info files
+     with CR-LF line endings which are only counted as one byte in the file
+     tag table.  Convert any of these DOS-style CRLF EOLs into Unix-style NL
+     so that these files can be read correctly on such operating systems.
+
+     Don't do this on GNU/Linux (or other Unix-type operating system), so
+     as not to encourage Info files with CR-LF line endings to be distributed
+     widely beyond their native operating system, which would cause only
+     problems.  (If someone really needs to, they can convert the line endings
+     themselves with a separate program.)
+     Also, this will allow any Info files that contain any CR-LF endings by
+     mistake to work as expected (except on MS-DOS/Windows). */
+
+  fsize = convert_eols (contents, fsize);
+
+  /* EOL conversion can shrink the text quite a bit.  We don't
+     want to waste storage.  */
+  contents = xrealloc (contents, 1 + fsize);
+  contents[fsize] = '\0';
+#endif
+
   *filesize = fsize;
 
   return contents;

Modified: trunk/info/nodes.c
===================================================================
--- trunk/info/nodes.c  2017-05-17 21:10:02 UTC (rev 7793)
+++ trunk/info/nodes.c  2017-05-18 20:59:43 UTC (rev 7794)
@@ -865,6 +865,7 @@
                                       char **filename, char **nodename,
                                       char *filename_in, char *nodename_in);
 static void node_set_body_start (NODE *node);
+static int adjust_nodestart (FILE_BUFFER *file_buffer, TAG *tag);
 
 /* Return a pointer to a newly allocated TAG structure, with
    fields filled in. */
@@ -1119,35 +1120,6 @@
 }
 
 
-/* Convert any CRLF pairs in the SOURCE file and place the converted buffer in 
-   DESTINATION.  DESTINATION->contents must be allocated on the heap and at 
-   least as big as SOURCE->contents, including a terminating null.  
DESTINATION 
-   is allowed to be the same as SOURCE to convert in place. */
-void
-convert_eols (FILE_BUFFER *destination, FILE_BUFFER *source)
-{
-  register char *d = destination->contents;
-  register char *s = source->contents;
-
-  long textlen = source->filesize;
-  while (textlen--)
-    {
-      if (*s == '\r' && textlen && s[1] == '\n')
-        {
-          s++;
-          textlen--;
-        }
-      *d++ = *s++;
-    }
-  *d = '\0';
-
-  destination->filesize = d - destination->contents;
-  /* EOL conversion can shrink the text quite a bit.  We don't
-     want to waste storage.  */
-  destination->contents = xrealloc (destination->contents,
-                                    d - destination->contents + 1);
-}
-
 /* Magic number that RMS used to decide how much a tags table pointer could
    be off by.  I feel that it should be much smaller, like 4.  */
 #define DEFAULT_INFO_FUDGE 1000
@@ -1159,7 +1131,7 @@
    Set NODE->nodestart_adjusted directly on the separator that precedes this 
    node.  If the node could not be found, return 0. */
 static int
-adjust_nodestart (FILE_BUFFER *fb, TAG *node, int slack)
+adjust_nodestart (FILE_BUFFER *fb, TAG *node)
 {
   long position = -1;
   SEARCH_BINDING s;
@@ -1185,8 +1157,8 @@
 
       /* Oh well, I guess we have to try to find it in a larger area. */
 
-      s.start -= slack;
-      s.end += slack;
+      s.start -= DEFAULT_INFO_FUDGE;
+      s.end += DEFAULT_INFO_FUDGE;
 
       if (s.start < 0)
         s.start = 0;
@@ -1224,103 +1196,13 @@
   TAG **t;
   WINDOW *w;
 
-  /* Start off with a small fudge to reduce chance of finding a node and then
-     later having to convert the EOL's, leaving us with the question of what to
-     do with the existing buffer and the nodes that refer to it. */
-  if (!(fb->flags & N_EOLs_Converted))
-    slack = 4;
-  else
-    slack = DEFAULT_INFO_FUDGE;
-
   if (tag->nodestart_adjusted != -1)
     success = 1;
   else
-    success = adjust_nodestart (fb, tag, slack);
+    success = adjust_nodestart (fb, tag);
 
   if (success)
     return success;
-
-  if (fb->flags & N_EOLs_Converted || strict_node_location_p)
-    return 0;
-
-  /* Convert EOL's.  If the Info file was produced under MS-Windows with
-     some versions of makeinfo, it's possible that it has CR-LF line endings 
-     with the CR bytes not counted in the tag table. */
-
-  convert_eols (fb, fb);
-  fb->flags |= N_EOLs_Converted;
-
-  /* Restore tags table to what was read from the file. */
-  for (t = parent->tags; *t; t++)
-    {
-      /* For split files, only restore the part of the tag table for
-         the subfile. */
-      if (!FILENAME_CMP ((*t)->filename, fb->fullpath))
-        {
-          NODE *n = &(*t)->cache;
-          int is_anchor = n->nodelen == 0;
-          (*t)->nodestart_adjusted = -1;
-          if (n->flags & N_WasRewritten)
-            free (n->contents);
-          info_free_references (n->references);
-          free (n->next); free (n->prev); free (n->up);
-          memset (n, 0, sizeof (NODE));
-          if (!is_anchor)
-            n->nodelen = -1;
-        }
-    }
-
-  /* Look for the node again. */
-  success = adjust_nodestart (fb, tag, DEFAULT_INFO_FUDGE);
-
-  /* For each window, check for file buffer being used in window history, 
-     including currently displayed node, and amend it to refer properly to the 
-     converted file buffer.  (Window history was set in 
info_set_node_of_window 
-     in session.c. )
-
-     There is a chance that there is a NODE in some local variable 
-     somewhere, which we can't update. */
-
-  for (w = windows; w; w = w->next)
-    {
-      WINDOW_STATE **h;
-
-      if (!w->hist)
-        continue;
-
-      w->node = 0;
-      for (h = w->hist; *h; h++)
-        {
-          NODE *n = (*h)->node;;
-          if (!(n->flags & N_IsInternal)
-              && (n->subfile ? (!FILENAME_CMP (n->subfile, fb->fullpath))
-                             : (!FILENAME_CMP (n->fullpath, fb->fullpath))))
-            {
-              /* The call to info_get_node is indirectly recursive, but it 
-                 should not recurse twice because of the N_EOLs_Converted 
-                 conditional above. */
-              (*h)->node = info_get_node (n->fullpath, n->nodename);
-              if ((*h)->node)
-                {
-                  (*h)->node->active_menu = n->active_menu;
-                  free_history_node (n);
-                }
-              else
-                {
-                  /* We found the node before, but now we can't.  Just leave
-                     the node as it was (possibly with its contents pointer
-                     pointing to the wrong place). */
-                  (*h)->node = n;
-                }
-            }
-        }
-      if (h > w->hist)
-        w->node = (*(h - 1))->node;
-    }
-
-  if (success)
-    return success;
-
   return 0;
 }
 

Modified: trunk/info/nodes.h
===================================================================
--- trunk/info/nodes.h  2017-05-17 21:10:02 UTC (rev 7793)
+++ trunk/info/nodes.h  2017-05-18 20:59:43 UTC (rev 7794)
@@ -67,10 +67,9 @@
 #define N_IsIndex      0x200    /* An index node. */
 #define N_IsDir        0x400    /* A dir node. */
 #define N_Subfile      0x800    /* File buffer is a subfile of a split file. */
-#define N_EOLs_Converted 0x1000 /* CR bytes were stripped before LF. */
-#define N_Gone         0x2000   /* File is no more. */
-#define N_Simple       0x4000   /* Data about cross-references is missing. */
-#define N_SeenBySearch 0x8000   /* Node has already been seen in a search. */
+#define N_Gone         0x1000   /* File is no more. */
+#define N_Simple       0x2000   /* Data about cross-references is missing. */
+#define N_SeenBySearch 0x4000   /* Node has already been seen in a search. */
 
 /* String constants. */
 #define INFO_FILE_LABEL                 "File:"




reply via email to

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