texinfo-commits
[Top][All Lists]
Advanced

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

[5564] process_node_text, line_starts


From: Gavin D. Smith
Subject: [5564] process_node_text, line_starts
Date: Wed, 14 May 2014 14:48:25 +0000

Revision: 5564
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=5564
Author:   gavin
Date:     2014-05-14 14:48:22 +0000 (Wed, 14 May 2014)
Log Message:
-----------
process_node_text, line_starts

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

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2014-05-14 06:23:39 UTC (rev 5563)
+++ trunk/ChangeLog     2014-05-14 14:48:22 UTC (rev 5564)
@@ -1,5 +1,19 @@
 2014-05-14  Gavin Smith  <address@hidden>
 
+       * info/window.h (WINDOW): line_starts changed to pointer to
+       (array of) offsets.  This stops the need to write expressions like
+       "win->line_starts[line] - win->node->contents" in many places.  All
+       uses updated.
+
+       * info/window.c (process_node_text): Set line_starts.
+
+       * info/window.c (process_node_text, _calc_line_starts)
+       * info/display.c (display_node_text): Consistent variable naming
+       among local variable names in process_node_text and the arguments
+       for the functions it calls.
+
+2014-05-14  Gavin Smith  <address@hidden>
+
        * info/session.c (info_select_reference): Code merged from
        info_next_index_match: Call window_log_to_phys_line.
        * info/indices.c (info_next_index_match): Call info_select_reference.

Modified: trunk/info/display.c
===================================================================
--- trunk/info/display.c        2014-05-14 06:23:39 UTC (rev 5563)
+++ trunk/info/display.c        2014-05-14 14:48:22 UTC (rev 5564)
@@ -113,14 +113,14 @@
 }
 
 int
-display_node_text(void *closure, size_t pline_index, size_t lline_index,
-                 const char *src_line,
-                 char *printed_line, size_t pl_index, size_t pl_count)
+display_node_text (void *closure, size_t pl_num, size_t ll_num,
+                   size_t pl_start, char *printed_line,
+                   size_t pl_bytes, size_t pl_chars)
 {
   struct display_node_closure *dn = closure;
   WINDOW *win = dn->win;
   DISPLAY_LINE **display = dn->display;
-  DISPLAY_LINE *entry = display[win->first_row + pline_index];
+  DISPLAY_LINE *entry = display[win->first_row + pl_num];
 
   /* We have the exact line as it should appear on the screen.
      Check to see if this line matches the one already appearing
@@ -139,31 +139,31 @@
          /* Need to erase the line if it has escape sequences.  */
          || (raw_escapes_p && mbschr (entry->text, '\033') != 0))
        {
-         terminal_goto_xy (0, win->first_row + pline_index);
+         terminal_goto_xy (0, win->first_row + pl_num);
          terminal_clear_to_eol ();
          entry->inverse = 0;
          entry->text[0] = '\0';
          entry->textlen = 0;
        }
 
-      i = find_diff (printed_line, pl_index,
+      i = find_diff (printed_line, pl_bytes,
                     entry->text, strlen (entry->text), &off);
 
       /* If the lines are not the same length, or if they differed
         at all, we must do some redrawing. */
-      if (i != pl_count || pl_count != entry->textlen)
+      if (i != pl_chars || pl_chars != entry->textlen)
        {
          /* Move to the proper point on the terminal. */
-         terminal_goto_xy (i, win->first_row + pline_index);
+         terminal_goto_xy (i, win->first_row + pl_num);
          /* If there is any text to print, print it. */
-         if (i != pl_count)
+         if (i != pl_chars)
            terminal_put_text (printed_line + i);
          
          /* If the printed text didn't extend all the way to the edge
             of the window, and text was appearing between here and the
             edge of the window, clear from here to the end of the
             line. */
-         if ((pl_count < win->width && pl_count < entry->textlen)
+         if ((pl_chars < win->width && pl_chars < entry->textlen)
              || entry->inverse)
            terminal_clear_to_eol ();
          
@@ -179,7 +179,7 @@
               bytes only.  */
            entry->text = xrealloc (entry->text, strlen (printed_line) + 1);
          strcpy (entry->text + off, printed_line + off);
-         entry->textlen = pl_count;
+         entry->textlen = pl_chars;
          
          /* Lines showing node text are not in inverse.  Only modelines
             have that distinction. */
@@ -196,7 +196,7 @@
       return 1;
     }
 
-  if (pline_index + 1 == win->height)
+  if (pl_num + 1 == win->height)
     return 1;
 
   return 0;
@@ -236,7 +236,8 @@
       dnc.display = the_display;
       
       line_index = process_node_text (win,
-                                     win->line_starts[win->pagetop],
+                                     win->node->contents
+                                        + win->line_starts[win->pagetop],
                                      1,
                                      display_node_text,
                                      &dnc);
@@ -367,7 +368,7 @@
    that appear in the OLD_STARTS array. */
 void
 display_scroll_line_starts (WINDOW *window, int old_pagetop,
-    char **old_starts, int old_count)
+    long *old_starts, int old_count)
 {
   register int i, old, new;     /* Indices into the line starts arrays. */
   int last_new, last_old;       /* Index of the last visible line. */

Modified: trunk/info/display.h
===================================================================
--- trunk/info/display.h        2014-05-14 06:23:39 UTC (rev 5563)
+++ trunk/info/display.h        2014-05-14 14:48:22 UTC (rev 5564)
@@ -70,6 +70,6 @@
    starts that used to appear in this window.  OLD_COUNT is the number of lines
    that appear in the OLD_STARTS array. */
 extern void display_scroll_line_starts (WINDOW *window, int old_pagetop,
-    char **old_starts, int old_count);
+    long *old_starts, int old_count);
 
 #endif /* not INFO_DISPLAY_H */

Modified: trunk/info/session.c
===================================================================
--- trunk/info/session.c        2014-05-14 06:23:39 UTC (rev 5563)
+++ trunk/info/session.c        2014-05-14 14:48:22 UTC (rev 5564)
@@ -530,7 +530,7 @@
   if ((point_line < window->pagetop) ||
       ((point_line - window->pagetop) > window->height - 1))
     window->point =
-      window->line_starts[window->pagetop] - window->node->contents;
+      window->line_starts[window->pagetop];
 
   window->flags |= W_UpdateWindow;
 
@@ -617,7 +617,7 @@
       goal = window_get_goal_column (window);
       window->goal_column = goal;
 
-      window->point = window->line_starts[new] - window->node->contents;
+      window->point = window->line_starts[new];
       window->point += window_chars_to_goal (window, goal);
       info_show_point (window);
     }
@@ -733,7 +733,7 @@
   int line = window_line_of_point (win);
   if (line + 1 >= win->line_count)
     return 1;
-  win->point = win->line_starts[line + 1] - win->node->contents;
+  win->point = win->line_starts[line + 1];
   window_compute_line_map (win);
   return 0;
 }
@@ -747,7 +747,7 @@
   int line = window_line_of_point (win);
   if (line == 0)
     return 1;
-  win->point = win->line_starts[line - 1] - win->node->contents;
+  win->point = win->line_starts[line - 1];
   window_compute_line_map (win);
   return 0;
 }
@@ -1790,12 +1790,12 @@
           line = window_log_to_phys_line (window, entry->line_number - 1);
 
           if (line >= 0 && line < window->line_count)
-            loc = window->line_starts[line] - window->node->contents;
+            loc = window->line_starts[line];
           else
             {
               /* Try to find an occurence of LABEL in this node.  This
                  could be useful for following index entries. */
-              long start = window->line_starts[1] - window->node->contents;
+              long start = window->line_starts[1];
               loc = info_target_search_node (node, entry->label, start, 1);
             }
 
@@ -2396,9 +2396,9 @@
      point is in. */
 
   line_no = window_line_of_point (window);
-  this_line = window->line_starts[line_no] - window->node->contents;
+  this_line = window->line_starts[line_no];
   if (window->line_starts[line_no + 1])
-    next_line = window->line_starts[line_no + 1] - window->node->contents;
+    next_line = window->line_starts[line_no + 1];
   else
     next_line = window->node->nodelen;
 
@@ -4150,7 +4150,7 @@
       /* Find window bottom */
       long n = window->height + window->pagetop;
       if (n < window->line_count)
-       n = window->line_starts[n] - window->node->contents;
+       n = window->line_starts[n];
       else
        n = window->node->nodelen;
       info_search_1 (window, last_search_direction * count,
@@ -4171,7 +4171,7 @@
       /* Find window bottom */
       long n;
 
-      n = window->line_starts[window->pagetop] - window->node->contents - 1;
+      n = window->line_starts[window->pagetop] - 1;
       if (n < 0)
        n = 0;
       info_search_1 (window, -last_search_direction * count,
@@ -4751,7 +4751,7 @@
   if (line >= window->line_count)
     line = window->line_count - 1;
 
-  window->point = (window->line_starts[line] - window->node->contents);
+  window->point = window->line_starts[line];
 }
 
 /* Clear the screen and redraw its contents.  Given a numeric argument,

Modified: trunk/info/window.c
===================================================================
--- trunk/info/window.c 2014-05-14 06:23:39 UTC (rev 5563)
+++ trunk/info/window.c 2014-05-14 14:48:22 UTC (rev 5564)
@@ -586,7 +586,7 @@
 
   if (window != the_echo_area)
     {
-      char **old_starts;
+      long *old_starts;
       long *old_xlat;
       int old_lines, old_pagetop;
 
@@ -839,15 +839,15 @@
 }
 
 static int
-_calc_line_starts (void *closure, size_t pline_index, size_t lline_index,
-                  const char *src_line,
-                  char *printed_line, size_t pl_index, size_t pl_count)
+_calc_line_starts (void *closure, size_t pl_num, size_t ll_num,
+                   size_t pl_start, char *printed_line,
+                   size_t pl_bytes, size_t pl_chars)
 {
   struct calc_closure *cp = closure;
 
   calc_closure_expand (cp);
-  cp->win->line_starts[cp->win->line_count] = (char*) src_line;
-  cp->win->log_line_no[cp->win->line_count] = lline_index;
+  cp->win->line_starts[cp->win->line_count] = pl_start;
+  cp->win->log_line_no[cp->win->line_count] = ll_num;
   cp->win->line_count++;
   return 0;
 }
@@ -869,7 +869,7 @@
   process_node_text (window, window->node->contents, 0,
                     _calc_line_starts, &closure);
   calc_closure_expand (&closure);
-  window->line_starts[window->line_count] = NULL;
+  window->line_starts[window->line_count] = 0;
   window->log_line_no[window->line_count] = 0;
   window_line_map_init (window);
 }
@@ -913,21 +913,14 @@
 window_adjust_pagetop (WINDOW *window)
 {
   register int line = 0;
-  char *contents;
 
   if (!window->node)
     return;
 
-  contents = window->node->contents;
-
   /* Find the first printed line start which is after WINDOW->point. */
   for (line = 0; line < window->line_count; line++)
     {
-      char *line_start;
-
-      line_start = window->line_starts[line];
-
-      if ((line_start - contents) > window->point)
+      if (window->line_starts[line] > window->point)
         break;
     }
 
@@ -973,14 +966,13 @@
 
   /* Try to optimize.  Check to see if point is past the pagetop for
      this window, and if so, start searching forward from there. */
-  if ((window->pagetop > -1 && window->pagetop < window->line_count) &&
-      (window->line_starts[window->pagetop] - window->node->contents)
-      <= window->point)
+  if (window->pagetop > -1 && window->pagetop < window->line_count
+      && window->line_starts[window->pagetop] <= window->point)
     start = window->pagetop;
 
   for (i = start; i < window->line_count; i++)
     {
-      if ((window->line_starts[i] - window->node->contents) > window->point)
+      if (window->line_starts[i] > window->point)
         break;
     }
 
@@ -1186,7 +1178,7 @@
 
   window->pagetop = desired_line;
   window->point =
-    window->line_starts[window->pagetop] - window->node->contents;
+    window->line_starts[window->pagetop];
   window->flags |= W_UpdateWindow;
   window_make_modeline (window);
 }
@@ -1460,17 +1452,17 @@
 
    FUN is called for every line collected from the node. Its arguments:
 
-     int (*fun) (void *closure, size_t phys_line_no, size_t log_line_no,
-                  const char *src_line, char *prt_line,
-                 size_t prt_bytes, size_t prt_chars)
+     int (*fun) (void *closure, size_t pl_num, size_t ll_num,
+                  size_t pl_start, char *printed_line,
+                 size_t pl_bytes, size_t pl_chars)
 
      closure  -- An opaque pointer passed as 5th parameter to 
process_node_text;
-     line_no  -- Number of processed physical line (starts from 0);
-     log_line_no -- Number of processed logical line (starts from 0);
-     src_line -- Pointer to the source line (unmodified);
-     prt_line -- Collected line contents, ready for output;
-     prt_bytes -- Number of bytes in prt_line;
-     prt_chars -- Number of characters in prt_line.
+     pl_num  -- Number of processed physical lines (starts from 0);
+     ll_num -- Number of processed logical lines (starts from 0);
+     pl_start -- Offset of start of physical line from START;
+     printed_line -- Collected line contents, ready for output;
+     pl_bytes -- Number of bytes in prt_line;
+     pl_chars -- Number of characters in prt_line.
 
    If FUN returns non zero, process_node_text stops processing and returns
    immediately.
@@ -1484,15 +1476,15 @@
 process_node_text (WINDOW *win, char *start,
                   int do_tags,
                   int (*fun) (void *, size_t, size_t,
-                              const char *, char *, size_t, size_t),
+                              size_t, char *, size_t, size_t),
                   void *closure)
 {
   char *printed_line;      /* Buffer for a printed line. */
-  size_t pl_count = 0;     /* Number of *characters* written to PRINTED_LINE */
-  size_t pl_index = 0;     /* Index into PRINTED_LINE. */
-  size_t in_index = 0;
-  size_t line_index = 0;   /* Number of physical lines done so far. */
-  size_t logline_index = 0;/* Number of logical lines */
+  size_t pl_chars = 0;     /* Number of *characters* written to PRINTED_LINE */
+  size_t pl_bytes = 0;     /* Index into PRINTED_LINE. */
+  size_t pl_start = 0;     /* Offset of start of current physical line. */
+  size_t pl_num = 0;       /* Number of physical lines done so far. */
+  size_t ll_num = 0;       /* Number of logical lines */
   size_t allocated_win_width;
   mbi_iterator_t iter;
   
@@ -1503,19 +1495,15 @@
   printed_line = xmalloc (allocated_win_width);
 
   for (mbi_init (iter, start, 
-                win->node->contents + win->node->nodelen - start),
-        pl_count = 0;
+                win->node->contents + win->node->nodelen - start);
        mbi_avail (iter);
        mbi_advance (iter))
     {
-      const char *carried_over_ptr;
-      size_t carried_over_len = 0;
-      size_t carried_over_count = 0;
       const char *cur_ptr = mbi_cur_ptr (iter);
       size_t cur_len = mb_len (mbi_cur (iter));
       size_t replen = 0;
       int delim = 0;
-      int rc;
+      int finish;
 
       if (mb_isprint (mbi_cur (iter)))
        {
@@ -1525,7 +1513,7 @@
        {
           if (*cur_ptr == '\r' || *cur_ptr == '\n')
             {
-              replen = win->width - pl_count;
+              replen = win->width - pl_chars;
              delim = *cur_ptr;
             }
          else if (ansi_escape (iter, &cur_len))
@@ -1542,7 +1530,7 @@
            {
              if (*cur_ptr == '\t')
                delim = *cur_ptr;
-              cur_ptr = printed_representation (cur_ptr, cur_len, pl_count,
+              cur_ptr = printed_representation (cur_ptr, cur_len, pl_chars,
                                                &cur_len);
              replen = cur_len;
             }
@@ -1551,34 +1539,37 @@
        {
          /* 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_count,
+         cur_ptr = printed_representation (cur_ptr, cur_len, pl_chars,
                                            &cur_len);
          replen = cur_len;
        }
 
       /* Ensure there is enough space in the buffer */
-      while (pl_index + cur_len + 2 > allocated_win_width - 1)
+      while (pl_bytes + cur_len + 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_count + replen < win->width)
+      if (pl_chars + replen < win->width)
         {
          int i;
          
          for (i = 0; i < cur_len; i++)
-           printed_line[pl_index++] = cur_ptr[i];
-         pl_count += replen;
-         in_index += mb_len (mbi_cur (iter));
+           printed_line[pl_bytes++] = cur_ptr[i];
+         pl_chars += replen;
         }
       else
        {
           /* If this character cannot be printed in this line, we have
              found the end of this line as it would appear on the screen.
              Carefully print the end of the line, and then compare. */
+          const char *carried_over_ptr;
+          size_t carried_over_len = 0;
+          size_t carried_over_count = 0;
+
           if (delim)
             {
-              printed_line[pl_index] = '\0';
+              printed_line[pl_bytes] = '\0';
               carried_over_ptr = NULL;
             }
          else
@@ -1601,9 +1592,9 @@
                  /* Remember the offset of the last character printed out of
                     REP so that we can carry the character over to the next
                     line. */
-                 for (i = 0; pl_count < (win->width - 1);
-                      pl_count++)
-                   printed_line[pl_index++] = cur_ptr[i++];
+                 for (i = 0; pl_chars < (win->width - 1);
+                      pl_chars++)
+                   printed_line[pl_bytes++] = cur_ptr[i++];
 
                  carried_over_ptr = cur_ptr + i;
                  carried_over_len = cur_len;
@@ -1612,67 +1603,70 @@
               /* If printing the last character in this window couldn't
                  possibly cause the screen to scroll, place a backslash
                  in the rightmost column. */
-              if (1 + line_index + win->first_row < the_screen->height)
+              if (1 + pl_num + win->first_row < the_screen->height)
                 {
                   if (win->flags & W_NoWrap)
-                    printed_line[pl_index++] = '$';
+                    printed_line[pl_bytes++] = '$';
                   else
-                    printed_line[pl_index++] = '\\';
-                 pl_count++;
+                    printed_line[pl_bytes++] = '\\';
+                 pl_chars++;
                 }
-              printed_line[pl_index] = '\0';
+              printed_line[pl_bytes] = '\0';
             }
 
-         rc = fun (closure, line_index, logline_index,
-                   mbi_cur_ptr (iter) - in_index,
-                   printed_line, pl_index, pl_count);
+         finish = fun (closure, pl_num, ll_num,
+                       pl_start,
+                       printed_line, pl_bytes, pl_chars);
 
-          ++line_index;
+          ++pl_num;
          if (delim == '\r' || delim == '\n')
-           ++logline_index;
+           ++ll_num;
 
-         /* Reset all data to the start of the line. */
-         pl_index = 0;
-         pl_count = 0;
-         in_index = 0;
+         /* Start a new physical line at next character. */
+         pl_bytes = 0;
+         pl_chars = 0;
+         pl_start = mbi_cur_ptr (iter) + mb_len (mbi_cur (iter)) - start;
 
-         if (rc)
+         if (finish)
            break;
          
           /* If there are bytes carried over, stuff them
              into the buffer now. */
+          /* There is enough space for this because there was enough space
+             for the whole logical line of which this is only a part. */
+          /* Expected to be "short", i.e. a representation like "^A". *./
           if (carried_over_ptr)
            {
              for (; carried_over_len;
-                  carried_over_len--, carried_over_ptr++, pl_index++)
-               printed_line[pl_index] = *carried_over_ptr;
-             pl_count += carried_over_count;
+                  carried_over_len--, carried_over_ptr++, pl_bytes++)
+               printed_line[pl_bytes] = *carried_over_ptr;
+             pl_chars += carried_over_count;
            }
        
           /* If this window has chosen not to wrap lines, skip to the end
-             of the physical line in the buffer, and start a new line here. */
-          if (pl_index && win->flags & W_NoWrap)
+             of the logical line in the buffer, and start a new line here. */
+          if (pl_bytes && win->flags & W_NoWrap)
             {
              for (; mbi_avail (iter); mbi_advance (iter))
                if (mb_len (mbi_cur (iter)) == 1
                    && *mbi_cur_ptr (iter) == '\n')
                  break;
 
-             pl_index = 0;
-             pl_count = 0;
-             in_index = 0;
+             pl_bytes = 0;
+             pl_chars = 0;
+              pl_start = mbi_cur_ptr (iter) + mb_len (mbi_cur (iter)) - start;
              printed_line[0] = 0;
            }
        }
     }
 
-  if (pl_count)
-    fun (closure, line_index, logline_index,
-        mbi_cur_ptr (iter) - in_index,
-        printed_line, pl_index, pl_count);
+  if (pl_chars)
+    fun (closure, pl_num, ll_num,
+         pl_start,
+        printed_line, pl_bytes, pl_chars);
 
   free (printed_line);
-  return line_index;
+  return ll_num; /* needed? */
 }
 
 static void
@@ -1725,19 +1719,18 @@
                  void *closure)
 {
   mbi_iterator_t iter;
-  long cpos = win->line_starts[line] - win->node->contents;
+  long cpos = win->line_starts[line];
   int delim = 0;
   char *endp;
   
   if (!phys && line + 1 < win->line_count)
-    endp = win->line_starts[line + 1];
+    endp = win->node->contents + win->line_starts[line + 1];
   else
     endp = win->node->contents + win->node->nodelen;
   
   for (mbi_init (iter,
-                win->line_starts[line], 
-                win->node->contents + win->node->nodelen -
-                  win->line_starts[line]);
+                win->node->contents + win->line_starts[line], 
+                win->node->nodelen - win->line_starts[line]);
        !delim && mbi_avail (iter);
        mbi_advance (iter))
     {

Modified: trunk/info/window.h
===================================================================
--- trunk/info/window.h 2014-05-14 06:23:39 UTC (rev 5563)
+++ trunk/info/window.h 2014-05-14 14:48:22 UTC (rev 5564)
@@ -76,10 +76,11 @@
   WINDOW_STATE_DECL;    /* Node, pagetop and point. */
   LINE_MAP line_map;    /* Current line map */
   char *modeline;       /* Calculated text of the modeline for this window. */
-  char **line_starts;   /* Array of printed line starts for this node. */
-  long line_count;      /* Number of lines appearing in LINE_STARTS. */
+  long *line_starts;    /* Offsets of printed line starts in node->contents.*/
   long *log_line_no;    /* Number of logical line corresponding to each
-                          physical one. */
+                           physical one. */
+  long line_count;      /* Number of elements in LINE_STARTS and LOG_LINE_NO.*/
+
   int flags;            /* See below for details. */
 } WINDOW;
 
@@ -273,7 +274,7 @@
 
 extern size_t process_node_text
         (WINDOW *win, char *start, int do_tags,
-         int (*fun) (void *, size_t, size_t, const char *, char *,
+         int (*fun) (void *, size_t, size_t, size_t, char *,
                     size_t, size_t),
         void *closure);
 




reply via email to

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