texinfo-commits
[Top][All Lists]
Advanced

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

texinfo ChangeLog info/indices.c info/info-util...


From: Sergey Poznyakoff
Subject: texinfo ChangeLog info/indices.c info/info-util...
Date: Thu, 17 Nov 2011 10:05:00 +0000

CVSROOT:        /cvsroot/texinfo
Module name:    texinfo
Changes by:     Sergey Poznyakoff <gray>        11/11/17 10:04:59

Modified files:
        .              : ChangeLog 
        info           : indices.c info-utils.c info-utils.h infomap.c 
                         window.c 
        doc            : info-stnd.texi 

Log message:
        Implement info-virtual-index.
        
        * info/indices.c (info_virtual_index): New function.
        * info/info-utils.c (text_buffer_init)
        (text_buffer_free,text_buffer_vprintf)
        (text_buffer_add_string,text_buffer_fill)
        (text_buffer_add_char,text_buffer_printf): New functions.
        * info/info-utils.h (text_buffer): New struct.
        (text_buffer_init)
        (text_buffer_free,text_buffer_vprintf)  
        (text_buffer_add_string,text_buffer_fill)
        (text_buffer_add_char,text_buffer_printf): New protos.
        * info/infomap.c (default_emacs_like_info_keys): 'I'
        calls info-virtual-index.
        (default_vi_like_info_keys): ESC-I calls info-virtual-index.
        * info/window.c (message_buffer_size)
        (message_buffer_index): Remove.
        (message_buffer): Change type to struct text_buffer.
        All uses changed.
        
        * doc/info-stnd.texi: Document virtual-index.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/ChangeLog?cvsroot=texinfo&r1=1.1279&r2=1.1280
http://cvs.savannah.gnu.org/viewcvs/texinfo/info/indices.c?cvsroot=texinfo&r1=1.16&r2=1.17
http://cvs.savannah.gnu.org/viewcvs/texinfo/info/info-utils.c?cvsroot=texinfo&r1=1.16&r2=1.17
http://cvs.savannah.gnu.org/viewcvs/texinfo/info/info-utils.h?cvsroot=texinfo&r1=1.10&r2=1.11
http://cvs.savannah.gnu.org/viewcvs/texinfo/info/infomap.c?cvsroot=texinfo&r1=1.23&r2=1.24
http://cvs.savannah.gnu.org/viewcvs/texinfo/info/window.c?cvsroot=texinfo&r1=1.23&r2=1.24
http://cvs.savannah.gnu.org/viewcvs/texinfo/doc/info-stnd.texi?cvsroot=texinfo&r1=1.33&r2=1.34

Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/texinfo/texinfo/ChangeLog,v
retrieving revision 1.1279
retrieving revision 1.1280
diff -u -b -r1.1279 -r1.1280
--- ChangeLog   8 Nov 2011 00:21:01 -0000       1.1279
+++ ChangeLog   17 Nov 2011 10:04:59 -0000      1.1280
@@ -1,3 +1,27 @@
+2011-11-16  Sergey Poznyakoff  <address@hidden>
+
+       Implement info-virtual-index.
+       
+       * info/indices.c (info_virtual_index): New function.
+       * info/info-utils.c (text_buffer_init)
+       (text_buffer_free,text_buffer_vprintf)
+       (text_buffer_add_string,text_buffer_fill)
+       (text_buffer_add_char,text_buffer_printf): New functions.
+       * info/info-utils.h (text_buffer): New struct.
+       (text_buffer_init)
+       (text_buffer_free,text_buffer_vprintf)  
+       (text_buffer_add_string,text_buffer_fill)
+       (text_buffer_add_char,text_buffer_printf): New protos.
+       * info/infomap.c (default_emacs_like_info_keys): 'I'
+       calls info-virtual-index.
+       (default_vi_like_info_keys): ESC-I calls info-virtual-index.
+       * info/window.c (message_buffer_size)
+       (message_buffer_index): Remove.
+       (message_buffer): Change type to struct text_buffer.
+       All uses changed.
+
+       * doc/info-stnd.texi: Document virtual-index.
+       
 2011-11-07  Karl Berry  <address@hidden>
 
        * doc/texinfo.txi: replace @inforef's to the Info manual

Index: info/indices.c
===================================================================
RCS file: /cvsroot/texinfo/texinfo/info/indices.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- info/indices.c      18 Oct 2011 18:47:20 -0000      1.16
+++ info/indices.c      17 Nov 2011 10:04:59 -0000      1.17
@@ -1,5 +1,5 @@
 /* indices.c -- deal with an Info file index.
-   $Id: indices.c,v 1.16 2011/10/18 18:47:20 karl Exp $
+   $Id: indices.c,v 1.17 2011/11/17 10:04:59 gray Exp $
 
    Copyright (C) 1993, 1997, 1998, 1999, 2002, 2003, 2004, 2007, 2008, 2011
    Free Software Foundation, Inc.
@@ -798,3 +798,156 @@
   if (!info_error_was_printed)
     window_clear_echo_area ();
 }
+
+static FILE_BUFFER *
+create_virtindex_file_buffer (const char *filename, char *contents, size_t 
size)
+{
+  FILE_BUFFER *file_buffer;
+
+  file_buffer = make_file_buffer ();
+  file_buffer->filename = xstrdup (filename);
+  file_buffer->fullpath = xstrdup (filename);
+  file_buffer->finfo.st_size = 0;
+  file_buffer->flags = (N_IsInternal | N_CannotGC);
+
+  file_buffer->contents = contents;
+  file_buffer->filesize = size;
+  build_tags_and_nodes (file_buffer);
+  return file_buffer;
+}
+
+static NODE *
+create_virtindex_node (FILE_BUFFER *file_buffer)
+{
+  NODE *node;
+  TAG *tag = file_buffer->tags[0];
+  char *text = file_buffer->contents + tag->nodestart;
+
+  text += skip_node_separator (text);
+  
+  node = xmalloc (sizeof (NODE));
+  node->filename = file_buffer->filename;
+  node->nodename = xstrdup (tag->nodename);
+  node->contents = text;
+  node->nodelen = strlen (text);
+  node->body_start = strcspn(node->contents, "\n");
+
+  node->flags    = 0;
+  node->display_pos = 0;
+  node->parent = NULL;
+  node->flags = 0;
+  
+  return node;
+}
+
+#define NODECOL 41
+#define LINECOL 62
+
+static void
+format_reference (REFERENCE *ref, const char *filename, struct text_buffer 
*buf)
+{
+  size_t n;
+  
+  n = text_buffer_printf (buf, "* %s: ", ref->label);
+  if (n < NODECOL)
+    n += text_buffer_fill (buf, ' ', NODECOL - n);
+  
+  if (ref->filename && strcmp (ref->filename, filename))
+    n += text_buffer_printf (buf, "(%s)", ref->filename);
+  n += text_buffer_printf (buf, "%s. ", ref->nodename);
+
+  if (n < LINECOL)
+    n += text_buffer_fill (buf, ' ', LINECOL - n);
+  else
+    {
+      text_buffer_add_char (buf, '\n');
+      text_buffer_fill (buf, ' ', LINECOL);
+    }
+  
+  text_buffer_printf (buf, "(line %4d)\n", ref->line_number);
+}
+
+DECLARE_INFO_COMMAND (info_virtual_index,
+   _("List all matches of a string in the index"))
+{
+  char *line;
+  size_t linelen;
+  FILE_BUFFER *fb, *tfb;
+  NODE *node;
+  struct text_buffer text;
+  int i;
+  size_t cnt, off;
+  
+  line = info_read_maybe_completing (window, _("Index topic: "),
+                                    index_index);
+
+  window = active_window;
+
+  /* User aborted? */
+  if (!line)
+    {
+      info_abort_key (window, 1, 1);
+      return;
+    }
+
+  if (mbslen (line) < min_search_length)
+    {
+      info_error (_("Search string too short"));
+      free (line);
+      return;
+    }
+  linelen = strlen (line);
+  
+  fb = file_buffer_of_window (window);
+
+  if (!initial_index_filename ||
+      !fb ||
+      (FILENAME_CMP (initial_index_filename, fb->filename) != 0))
+    {
+      info_free_references (index_index);
+      window_message_in_echo_area (_("Finding index entries..."));
+      index_index = info_indices_of_file_buffer (fb);
+    }
+
+  text_buffer_init (&text);
+  text_buffer_printf (&text, _("Index for `%s'"), line);
+  text_buffer_add_char (&text, 0);
+  off = text.off;
+  text_buffer_printf (&text,
+                     "\n\n%c\n%s %s,  %s %s,  %s Top\n\n"
+                     "Info Virtual Index\n"
+                     "******************\n\n"
+                     "Index entries that match `%s':\n\n"
+                     "* Menu:\n\n",
+                     INFO_COOKIE,
+                     INFO_FILE_LABEL, fb->filename,
+                     INFO_NODE_LABEL, text.base,
+                     INFO_UP_LABEL, line);
+  memmove (text.base, text.base + off, text.off - off);
+  text.off -= off;
+
+  cnt = 0;
+  for (i = 0; index_index[i]; i++)
+    {
+      if (string_in_line (line, index_index[i]->label) != -1)
+       {
+         format_reference (index_index[i], fb->filename, &text);
+         cnt++;
+       }
+    }
+
+  if (cnt == 0)
+    {
+      text_buffer_free (&text);
+      info_error (_("No index entries containing `%s'."), line);
+      return;
+    }
+
+  tfb = create_virtindex_file_buffer (fb->filename, text.base, text.off);
+  node = create_virtindex_node (tfb);
+  
+  info_set_node_of_window (1, window, node);
+  
+  if (!info_error_was_printed)
+    window_clear_echo_area ();
+}

Index: info/info-utils.c
===================================================================
RCS file: /cvsroot/texinfo/texinfo/info/info-utils.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- info/info-utils.c   18 Oct 2011 18:47:20 -0000      1.16
+++ info/info-utils.c   17 Nov 2011 10:04:59 -0000      1.17
@@ -1,5 +1,5 @@
 /* info-utils.c -- miscellanous.
-   $Id: info-utils.c,v 1.16 2011/10/18 18:47:20 karl Exp $
+   $Id: info-utils.c,v 1.17 2011/11/17 10:04:59 gray Exp $
 
    Copyright (C) 1993, 1998, 2003, 2004, 2007, 2008, 2009, 2011
    Free Software Foundation, Inc.
@@ -747,3 +747,103 @@
 
   return win;
 }
+
+/* Flexible Text Buffer */
+
+void
+text_buffer_init (struct text_buffer *buf)
+{
+  memset (buf, 0, sizeof *buf);
+}
+
+void
+text_buffer_free (struct text_buffer *buf)
+{
+  free (buf->base);
+}
+
+size_t
+text_buffer_vprintf (struct text_buffer *buf, const char *format, va_list ap)
+{
+  ssize_t n;
+  
+  if (!buf->base)
+    {
+      if (buf->size == 0)
+       buf->size = 512; /* Initial allocation */
+      
+      buf->base = xmalloc (buf->size);
+    }
+  
+  for (;;)
+    {
+      n = vsnprintf (buf->base + buf->off, buf->size - buf->off,
+                    format, ap);
+      if (n < 0 || buf->off + n >= buf->size ||
+         !memchr (buf->base + buf->off, '\0', buf->size - buf->off + 1))
+       {
+         size_t newlen = buf->size * 2;
+         if (newlen < buf->size)
+           xalloc_die ();
+         buf->size = newlen;
+         buf->base = xrealloc (buf->base, buf->size);
+       }
+      else
+       {
+         buf->off += n;
+         break;
+       }
+    }
+  return n;
+}
+
+size_t
+text_buffer_add_string (struct text_buffer *buf, const char *str, size_t len)
+{
+  if (buf->off + len > buf->size)
+    {
+      buf->size = buf->off + len;
+      buf->base = xrealloc (buf->base, buf->size);
+    }
+  memcpy (buf->base + buf->off, str, len);
+  buf->off += len;
+  return len;
+}
+
+size_t
+text_buffer_fill (struct text_buffer *buf, int c, size_t len)
+{
+  char *p;
+  int i;
+  
+  if (buf->off + len > buf->size)
+    {
+      buf->size = buf->off + len;
+      buf->base = xrealloc (buf->base, buf->size);
+    }
+
+  for (i = 0, p = buf->base + buf->off; i < len; i++)
+    *p++ = c;
+  buf->off += len;
+  
+  return len;
+}
+
+void
+text_buffer_add_char (struct text_buffer *buf, int c)
+{
+  char ch = c;
+  text_buffer_add_string (buf, &ch, 1);
+}
+
+size_t
+text_buffer_printf (struct text_buffer *buf, const char *format, ...)
+{
+  va_list ap;
+  size_t n;
+  
+  va_start (ap, format);
+  n = text_buffer_vprintf (buf, format, ap);
+  va_end (ap);
+  return n;
+}

Index: info/info-utils.h
===================================================================
RCS file: /cvsroot/texinfo/texinfo/info/info-utils.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- info/info-utils.h   18 Oct 2011 18:47:20 -0000      1.10
+++ info/info-utils.h   17 Nov 2011 10:04:59 -0000      1.11
@@ -1,5 +1,5 @@
 /* info-utils.h -- Exported functions and variables from info-utils.c.
-   $Id: info-utils.h,v 1.10 2011/10/18 18:47:20 karl Exp $   
+   $Id: info-utils.h,v 1.11 2011/11/17 10:04:59 gray Exp $   
 
    Copyright (C) 1993, 1996, 1998, 2002, 2003, 2004, 2007, 2011
    Free Software Foundation, Inc.
@@ -133,4 +133,21 @@
       info_parse_label (INFO_ALTPREV_LABEL, n); \
   } while (0)
 
+struct text_buffer
+{
+  char *base;
+  size_t size;
+  size_t off;
+};
+
+void text_buffer_init (struct text_buffer *buf);
+void text_buffer_free (struct text_buffer *buf);
+size_t text_buffer_vprintf (struct text_buffer *buf, const char *format,
+                           va_list ap);
+size_t text_buffer_add_string (struct text_buffer *buf, const char *str,
+                              size_t len);
+size_t text_buffer_fill (struct text_buffer *buf, int c, size_t len);
+void text_buffer_add_char (struct text_buffer *buf, int c);
+size_t text_buffer_printf (struct text_buffer *buf, const char *format, ...);
+
 #endif /* not INFO_UTILS_H */

Index: info/infomap.c
===================================================================
RCS file: /cvsroot/texinfo/texinfo/info/infomap.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -b -r1.23 -r1.24
--- info/infomap.c      18 Oct 2011 18:47:20 -0000      1.23
+++ info/infomap.c      17 Nov 2011 10:04:59 -0000      1.24
@@ -1,5 +1,5 @@
 /* infomap.c -- keymaps for Info.
-   $Id: infomap.c,v 1.23 2011/10/18 18:47:20 karl Exp $
+   $Id: infomap.c,v 1.24 2011/11/17 10:04:59 gray Exp $
 
    Copyright (C) 1993, 1997, 1998, 1999, 2001, 2002, 2003, 2004, 2007,
    2008, 2011 Free Software Foundation, Inc.
@@ -329,6 +329,7 @@
         'h', NUL,                       A_info_get_help_window,
         'H', NUL,                       A_info_get_info_help_node,
         'i', NUL,                       A_info_index_search,
+       'I', NUL,                       A_info_virtual_index,
         'l', NUL,                       A_info_history_node,
         'm', NUL,                       A_info_menu_item,
         'n', NUL,                       A_info_next_node,
@@ -664,6 +665,7 @@
         ESC, 'f', NUL,                  A_info_xref_item,
         ESC, 'g', NUL,                  A_info_select_reference_this_line,
         ESC, 'h', NUL,                  A_info_get_info_help_node,
+       ESC, 'I', NUL,                  A_info_virtual_index,
         ESC, 'm', NUL,                  A_info_menu_item,
         ESC, 'n', NUL,                  A_info_search,
         ESC, 'N', NUL,                  A_info_search_backward,

Index: info/window.c
===================================================================
RCS file: /cvsroot/texinfo/texinfo/info/window.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -b -r1.23 -r1.24
--- info/window.c       28 Jul 2011 07:14:06 -0000      1.23
+++ info/window.c       17 Nov 2011 10:04:59 -0000      1.24
@@ -1,5 +1,5 @@
 /* window.c -- windows in Info.
-   $Id: window.c,v 1.23 2011/07/28 07:14:06 gray Exp $
+   $Id: window.c,v 1.24 2011/11/17 10:04:59 gray Exp $
 
    Copyright (C) 1993, 1997, 1998, 2001, 2002, 2003, 2004, 2007, 2008, 2011
    Free Software Foundation, Inc.
@@ -1207,44 +1207,14 @@
 }
 
 /* A place to build a message. */
-static char *message_buffer = NULL;
-static size_t message_buffer_size = 0;
-static size_t message_buffer_index = 0;
+static struct text_buffer message_buffer;
 
 /* Format MESSAGE_BUFFER with the results of printing FORMAT with ARG1 and
    ARG2. */
 static void
 build_message_buffer (const char *format, va_list ap)
 {
-  if (!message_buffer)
-    {
-      if (message_buffer_size == 0)
-       message_buffer_size = 512; /* Initial allocation */
-      
-      message_buffer = xmalloc (message_buffer_size);
-    }
-  
-  for (;;)
-    {
-      ssize_t n = vsnprintf (message_buffer + message_buffer_index,
-                            message_buffer_size - message_buffer_index,
-                            format, ap);
-      if (n < 0 || message_buffer_index + n >= message_buffer_size ||
-         !memchr (message_buffer + message_buffer_index, '\0',
-                  message_buffer_size - message_buffer_index + 1))
-       {
-         size_t newlen = message_buffer_size * 2;
-         if (newlen < message_buffer_size)
-           xalloc_die ();
-         message_buffer_size = newlen;
-         message_buffer = xrealloc (message_buffer, message_buffer_size);
-       }
-      else
-       {
-         message_buffer_index += n;
-         break;
-       }
-    }
+  text_buffer_vprintf (&message_buffer, format, ap);
 }
 
 /* Build a new node which has FORMAT printed with ARG1 and ARG2 as the
@@ -1305,9 +1275,9 @@
   node->display_pos =0;
 
   /* Make sure that this buffer ends with a newline. */
-  node->nodelen = 1 + strlen (message_buffer);
+  node->nodelen = 1 + strlen (message_buffer.base);
   node->contents = xmalloc (1 + node->nodelen);
-  strcpy (node->contents, message_buffer);
+  strcpy (node->contents, message_buffer.base);
   node->contents[node->nodelen - 1] = '\n';
   node->contents[node->nodelen] = '\0';
   return node;
@@ -1317,7 +1287,7 @@
 void
 initialize_message_buffer (void)
 {
-  message_buffer_index = 0;
+  message_buffer.off = 0;
 }
 
 /* Print supplied arguments using FORMAT to the end of the current message
@@ -1339,12 +1309,12 @@
 {
   char *p;
   
-  if (!message_buffer || !*message_buffer)
+  if (!message_buffer.base || !*message_buffer.base)
     return 0;
 
-  p = strrchr (message_buffer, '\n');
+  p = strrchr (message_buffer.base, '\n');
   if (!p)
-    p = message_buffer;
+    p = message_buffer.base;
   return string_width (p, 0);
 }
 

Index: doc/info-stnd.texi
===================================================================
RCS file: /cvsroot/texinfo/texinfo/doc/info-stnd.texi,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -b -r1.33 -r1.34
--- doc/info-stnd.texi  13 Oct 2011 00:06:51 -0000      1.33
+++ doc/info-stnd.texi  17 Nov 2011 10:04:59 -0000      1.34
@@ -1,5 +1,5 @@
 vb\input texinfo.tex    @c -*-texinfo-*-
address@hidden $Id: info-stnd.texi,v 1.33 2011/10/13 00:06:51 pertusus Exp $
address@hidden $Id: info-stnd.texi,v 1.34 2011/11/17 10:04:59 gray Exp $
 @c We must \input texinfo.tex instead of texinfo, otherwise make
 @c distcheck in the Texinfo distribution fails, because the texinfo Info
 @c file is made first, and texi2dvi must include . first in the path.
@@ -1057,6 +1057,14 @@
 predefined limit.  By default, this limit is set to 1 character.
 @xref{min-search-length}, for more information on this.
 
address@hidden @kbd{I} (@code{virtual-index})
address@hidden I
address@hidden virtual-index
address@hidden index, virtual
+Look up a string in the indices for this Info file, and show them in
+a single node.  It is similar to @code{virtual-index}, except that it
+constructs a special node to show all results.
+
 @item @kbd{,} (@code{next-index-match})
 @kindex ,
 @findex next-index-match



reply via email to

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