texinfo-commits
[Top][All Lists]
Advanced

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

[5567] do more in printed_representation


From: Gavin D. Smith
Subject: [5567] do more in printed_representation
Date: Sat, 17 May 2014 19:53:55 +0000

Revision: 5567
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=5567
Author:   gavin
Date:     2014-05-17 19:53:53 +0000 (Sat, 17 May 2014)
Log Message:
-----------
do more in printed_representation

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

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2014-05-17 15:32:55 UTC (rev 5566)
+++ trunk/ChangeLog     2014-05-17 19:53:53 UTC (rev 5567)
@@ -3,6 +3,12 @@
        * info/window.c (process_node_text): Don't split printed
        representations like "^X" across lines.
 
+       * info/info-utils.c (printed_representation): Take mbi_iterator_t
+       argument and handle Info tags and terminal escape sequences.
+       * info/window.c (process_node_text, window_scan_line): Use of
+       printed_representation updated.
+       * info/window.c (info_tag): No longer static.
+
 2014-05-14  Gavin Smith  <address@hidden>
 
        * info/window.c (process_node_text): First argument changed from

Modified: trunk/info/info-utils.c
===================================================================
--- trunk/info/info-utils.c     2014-05-17 15:32:55 UTC (rev 5566)
+++ trunk/info/info-utils.c     2014-05-17 19:53:53 UTC (rev 5567)
@@ -467,88 +467,110 @@
   return 0;
 }
 
-/* String representation of a char returned by printed_representation (). */
-static char *the_rep;
-static size_t the_rep_size;
+static struct text_buffer printed_rep = {}; /* Initialize with all zeroes. */
 
-/* Return a pointer to a string which is the printed representation
-   of CHARACTER if it were printed at HPOS. */
+/* Return pointer to string that is the printed representation of character
+   (or other logical unit) at ITER if it were printed at screen column
+   PL_CHARS.  Update mb_len (mbi_cur (*ITER)) if byte length is different.  If
+   ITER points at a tag, process tag if DO_TAGS is non-zero.  If ITER points at
+   an end-of-line character, set *DELIM to this character.  *PCHARS gets the
+   number of screen columns taken up by outputting the return value, and
+   *PBYTES the number of bytes in returned string.  Return value is not
+   null-terminated.  Return value must not be called by caller. */
+
 char *
-printed_representation (const char *character, size_t len, size_t hpos,
-                       /* Return: */
-                       size_t *plen)
+printed_representation (mbi_iterator_t *iter, int do_tags, int *delim,
+                        size_t pl_chars, size_t *pchars, size_t *pbytes) 
 {
-  const unsigned char *cp = (const unsigned char *) character;
-  register int i = 0;
   int printable_limit = ISO_Latin_p ? 255 : 127;
-#define REPSPACE(s)                                            \
-  do                                                           \
-    {                                                          \
-      while (the_rep_size < s)                                        \
-       {                                                      \
-         if (the_rep_size == 0)                               \
-           the_rep_size = 8; /* Initial allocation */         \
-         the_rep = x2realloc (the_rep, &the_rep_size);        \
-       }                                                      \
-    }                                                          \
-  while (0)
-    
-#define SC(c)                                                  \
-  do                                                           \
-    {                                                          \
-      REPSPACE(i + 1);                                         \
-      the_rep[i++] = c;                                        \
-    }                                                          \
-  while (0)
-  
-  for (; len > 0; cp++, len--)
+  struct text_buffer *rep = &printed_rep;
+
+  char *cur_ptr = (char *) mbi_cur_ptr (*iter);
+  size_t cur_len = mb_len (mbi_cur (*iter));
+
+  text_buffer_reset (&printed_rep);
+
+  if (mb_isprint (mbi_cur (*iter)))
     {
-      if (raw_escapes_p && *cp == '\033')
-       SC(*cp);
-      /* Show CTRL-x as ^X.  */
-      else if (iscntrl (*cp) && *cp < 127)
-       {
-         switch (*cp)
-           {
-           case '\r':
-           case '\n':
-             SC(*cp);
-             break;
+      *pchars = 1;
+      *pbytes = cur_len;
+      return cur_ptr;
+    }
+  else if (cur_len == 1)
+    {
+      if (*cur_ptr == '\r' || *cur_ptr == '\n')
+        {
+          *pchars = 1;
+          *pbytes = cur_len;
+          *delim = *cur_ptr;
+          text_buffer_add_char (rep, ' ');
+          return cur_ptr;
+        }
+      else if (ansi_escape (*iter, &cur_len))
+        {
+          *pchars = 0; 
+          *pbytes = cur_len;
+          ITER_SETBYTES (*iter, cur_len);
 
-           case '\t':
-             {
-               int tw;
+          return cur_ptr;
+        }
+      else if (info_tag (*iter, do_tags, &cur_len))
+        {
+          *pchars = 0; 
+          *pbytes = cur_len;
+          ITER_SETBYTES (*iter, cur_len);
+          return cur_ptr;
+        }
+      else if (*cur_ptr == '\t')
+        {
+          int i = 0;
 
-               tw = ((hpos + 8) & 0xf8) - hpos;
-               while (i < tw)
-                 SC(' ');
-               break;
-             }
-             
-           default:
-             SC('^');
-             SC(*cp | 0x40);
-           }
-       }
-      /* Show META-x as 0370.  */
-      else if (*cp > printable_limit)
-       {
-         REPSPACE (i + 5);
-         sprintf (the_rep + i, "\\%0o", *cp);
-         i = strlen (the_rep);
-       }
-      else if (*cp == DEL)
-       {
-         SC('^');
-         SC('?');
-       }
-      else
-       SC(*cp);
+          *pchars = ((pl_chars + 8) & 0xf8) - pl_chars;
+          *pbytes = *pchars;
+
+          /* We must output spaces instead of the tab because a tab may
+             not clear characters already on the screen. */
+          for (i = 0; i < *pbytes; i++)
+            text_buffer_add_char (rep, ' ');
+          return text_buffer_base (rep);
+        }
     }
-  
-  SC(0);
-  *plen = i - 1;
-  return the_rep;
+
+  /* Show CTRL-x as "^X".  */
+  if (iscntrl (*cur_ptr) && *cur_ptr < 127)
+    {
+      *pchars = 2;
+      *pbytes = 2;
+      text_buffer_add_char (rep, '^');
+      text_buffer_add_char (rep, *cur_ptr | 0x40);
+      return text_buffer_base (rep);
+    }
+  /* Show META-x as "\0370".  */
+  else if (*cur_ptr > printable_limit)
+    {
+      *pchars = 5;
+      *pbytes = cur_len;
+      text_buffer_printf (rep, "\\%0o", *cur_ptr);
+      return text_buffer_base (rep);
+    }
+  else if (*cur_ptr == DEL)
+    {
+      *pchars = 2;
+      *pbytes = cur_len;
+      text_buffer_add_char (rep, '^');
+      text_buffer_add_char (rep, '?');
+      return text_buffer_base (rep);
+    }
+  else
+    {
+      /* Use original bytes, although not recognized as anything.  This
+         shouldn't happen because of the many cases above .*/
+
+      *pchars = cur_len;
+      *pbytes = cur_len;
+      text_buffer_add_string (rep, cur_ptr, cur_len);
+      return text_buffer_base (rep);
+    }
 }
 
 

Modified: trunk/info/info-utils.h
===================================================================
--- trunk/info/info-utils.h     2014-05-17 15:32:55 UTC (rev 5566)
+++ trunk/info/info-utils.h     2014-05-17 19:53:53 UTC (rev 5567)
@@ -98,8 +98,10 @@
 
 /* Return a pointer to a string which is the printed representation
    of CHARACTER if it were printed at HPOS. */
-extern char *printed_representation (const char *str, size_t len,
-                                    size_t hpos, size_t *plen);
+extern char *printed_representation (mbi_iterator_t *iter, int do_tags,
+                          int *delim,
+                          size_t pl_chars,
+                          size_t *pchars, size_t *pbytes);
 
 /* Return a pointer to the part of PATHNAME that simply defines the file. */
 extern char *filename_non_directory (char *pathname);

Modified: trunk/info/window.c
===================================================================
--- trunk/info/window.c 2014-05-17 15:32:55 UTC (rev 5566)
+++ trunk/info/window.c 2014-05-17 19:53:53 UTC (rev 5567)
@@ -1386,7 +1386,7 @@
 
    Collected tag is processed if HANDLE!=0.
 */
-static int
+int
 info_tag (mbi_iterator_t iter, int handle, size_t *plen)
 {
   if (*mbi_cur_ptr (iter) == '\0' && mbi_avail (iter))
@@ -1475,63 +1475,28 @@
        mbi_advance (iter))
     {
       const char *cur_ptr = mbi_cur_ptr (iter);
-      size_t cur_len = mb_len (mbi_cur (iter));
-      size_t replen = 0;
+
+      size_t pchars = 0; /* Printed chars */
+      size_t pbytes = 0; /* Bytes to output. */
       int delim = 0;
       int finish;
 
-      if (mb_isprint (mbi_cur (iter)))
-       {
-         replen = 1;
-       }
-      else if (cur_len == 1)
-       {
-          if (*cur_ptr == '\r' || *cur_ptr == '\n')
-            {
-              replen = win->width - pl_chars;
-             delim = *cur_ptr;
-            }
-         else if (ansi_escape (iter, &cur_len))
-           {
-             replen = 0;
-             ITER_SETBYTES (iter, cur_len);
-           }
-         else if (info_tag (iter, do_tags, &cur_len)) 
-           {
-             ITER_SETBYTES (iter, cur_len);
-             continue;
-           }
-         else
-           {
-             if (*cur_ptr == '\t')
-               delim = *cur_ptr;
-              cur_ptr = printed_representation (cur_ptr, cur_len, pl_chars,
-                                               &cur_len);
-             replen = cur_len;
-            }
-        }
-      else if (show_malformed_multibyte_p || mbi_cur (iter).wc_valid)
-       {
-         /* FIXME: I'm not sure it's the best way to deal with unprintable
-            multibyte characters */
-         cur_ptr = printed_representation (cur_ptr, cur_len, pl_chars,
-                                           &cur_len);
-         replen = cur_len;
-       }
+      cur_ptr = printed_representation (&iter, do_tags, &delim,
+                                        pl_chars, &pchars, &pbytes);
 
       /* Ensure there is enough space in the buffer */
-      while (pl_bytes + cur_len + 2 > allocated_win_width - 1)
+      while (pl_bytes + pbytes + 2 > allocated_win_width - 1)
        printed_line = x2realloc (printed_line, &allocated_win_width);
 
       /* If this character can be printed without passing the width of
          the line, then stuff it into the line. */
-      if (pl_chars + replen < win->width)
+      if (!delim && pl_chars + pchars < win->width)
         {
          int i;
          
-         for (i = 0; i < cur_len; i++)
+         for (i = 0; i < pbytes; i++)
            printed_line[pl_bytes++] = cur_ptr[i];
-         pl_chars += replen;
+         pl_chars += pchars;
         }
       else
        {
@@ -1556,9 +1521,9 @@
               for (i = 0; pl_chars < (win->width - 1); pl_chars++)
                 printed_line[pl_bytes++] = ' ';
 
-             carried_over_count = replen;
+             carried_over_count = pchars;
               carried_over_ptr = cur_ptr;
-              carried_over_len = cur_len;
+              carried_over_len = pbytes;
 
               /* If printing the last character in this window couldn't
                  possibly cause the screen to scroll, place a backslash
@@ -1623,7 +1588,7 @@
     fun (win, pl_num, ll_num, pl_start, printed_line, pl_bytes, pl_chars);
 
   free (printed_line);
-  return ll_num; /* needed? */
+  return ll_num;
 }
 
 static void
@@ -1676,9 +1641,9 @@
                  void *closure)
 {
   mbi_iterator_t iter;
-  long cpos = win->line_starts[line];
   int delim = 0;
   char *endp;
+  const char *cur_ptr;
   
   if (!phys && line + 1 < win->line_count)
     endp = win->node->contents + win->line_starts[line + 1];
@@ -1691,55 +1656,19 @@
        !delim && mbi_avail (iter);
        mbi_advance (iter))
     {
-      const char *cur_ptr = mbi_cur_ptr (iter);
-      size_t cur_len = mb_len (mbi_cur (iter));
-      size_t replen;
+      size_t pchars, pbytes;
+      cur_ptr = mbi_cur_ptr (iter);
 
       if (cur_ptr >= endp)
        break;
       
-      if (mb_isprint (mbi_cur (iter)))
-       {
-         replen = 1;
-       }
-      else if (cur_len == 1)
-       {
-          if (*cur_ptr == '\r' || *cur_ptr == '\n')
-            {
-              replen = 1;
-             delim = 1;
-            }
-         else if (ansi_escape (iter, &cur_len))
-           {
-             ITER_SETBYTES (iter, cur_len);
-             replen = 0;
-           }
-         else if (info_tag (iter, 0, &cur_len)) 
-           {
-             ITER_SETBYTES (iter, cur_len);
-             cpos += cur_len;
-             replen = 0;
-           }
-         else
-           {
-              printed_representation (cur_ptr, cur_len,
-                                     win->line_map.used,
-                                     &replen);
-            }
-        }
-      else
-       {
-         /* FIXME: I'm not sure it's the best way to deal with unprintable
-            multibyte characters */
-         printed_representation (cur_ptr, cur_len, win->line_map.used,
-                                 &replen);
-       }
+      printed_representation (&iter, 0, &delim,
+                              win->line_map.used, &pchars, &pbytes);
 
       if (fun)
-       fun (closure, cpos, replen);
-      cpos += cur_len;
+       fun (closure, cur_ptr - win->node->contents, pchars);
     }
-  return cpos;
+  return cur_ptr - win->node->contents;
 }
 
 static void

Modified: trunk/info/window.h
===================================================================
--- trunk/info/window.h 2014-05-17 15:32:55 UTC (rev 5566)
+++ trunk/info/window.h 2014-05-17 19:53:53 UTC (rev 5567)
@@ -278,6 +278,8 @@
          int (*fun) (WINDOW *, size_t, size_t, size_t, char *,
                     size_t, size_t));
 
+int info_tag (mbi_iterator_t iter, int handle, size_t *plen);
+
 extern void window_compute_line_map (WINDOW *win);
 
 extern int window_point_to_column (WINDOW *win, long point, long *np);




reply via email to

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