[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[7499] implement --virtual-index
From: |
gavinsmith0123 |
Subject: |
[7499] implement --virtual-index |
Date: |
Mon, 7 Nov 2016 20:29:49 +0000 (UTC) |
Revision: 7499
http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=7499
Author: gavin
Date: 2016-11-07 20:29:49 +0000 (Mon, 07 Nov 2016)
Log Message:
-----------
implement --virtual-index
Modified Paths:
--------------
trunk/ChangeLog
trunk/info/indices.c
trunk/info/indices.h
trunk/info/info.c
trunk/info/session.c
trunk/info/session.h
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2016-11-05 20:25:20 UTC (rev 7498)
+++ trunk/ChangeLog 2016-11-07 20:29:49 UTC (rev 7499)
@@ -1,3 +1,13 @@
+2016-11-07 Gavin Smith <address@hidden>
+
+ * info/indices.c (create_virtual_index): Split function out from
+ 'info_virtual_index'.
+ * info/info.c (virtual_index_p): New variable.
+ (long_options): New option "--virtual-index".
+ (main): If --virtual-index given, then call create_virtual_index
+ and output the result, either in an interactive session or to
+ an output file.
+
2016-11-05 Gavin Smith <address@hidden>
* tp/Texinfo/Parser.pm (_register_extra_menu_entry_information):
Modified: trunk/info/indices.c
===================================================================
--- trunk/info/indices.c 2016-11-05 20:25:20 UTC (rev 7498)
+++ trunk/info/indices.c 2016-11-07 20:29:49 UTC (rev 7499)
@@ -803,15 +803,70 @@
text_buffer_printf (buf, "(line %4d)\n", ref->line_number);
}
+NODE *
+create_virtual_index (FILE_BUFFER *file_buffer, char *index_search)
+{
+ struct text_buffer text;
+ int i;
+ size_t cnt;
+ NODE *node;
+
+ text_buffer_init (&text);
+ text_buffer_printf (&text,
+ "File: %s, Node: Index for '%s'\n\n",
+ file_buffer->filename, index_search);
+ text_buffer_printf (&text, _("Virtual Index\n"
+ "*************\n\n"
+ "Index entries that match '%s':\n"),
+ index_search);
+ text_buffer_add_string (&text, "\0\b[index\0\b]", 11);
+ text_buffer_printf (&text, "\n* Menu:\n\n");
+
+ cnt = 0;
+
+ index_offset = 0;
+ index_initial = 0;
+ index_partial = 0;
+ while (1)
+ {
+ REFERENCE *result;
+ int match_offset;
+
+ next_index_match (file_buffer, index_search, index_offset, 1, &result,
+ &i, &match_offset);
+ if (!result)
+ break;
+ format_reference (index_index[i],
+ file_buffer->filename, &text);
+ cnt++;
+ }
+ text_buffer_add_char (&text, '\0');
+
+ if (cnt == 0)
+ {
+ text_buffer_free (&text);
+ return 0;
+ }
+
+ node = info_create_node ();
+ asprintf (&node->nodename, "Index for '%s'", index_search);
+ node->fullpath = file_buffer->filename;
+ node->contents = text_buffer_base (&text);
+ node->nodelen = text_buffer_off (&text) - 1;
+ node->body_start = strcspn (node->contents, "\n");
+ node->flags |= N_IsInternal | N_WasRewritten;
+
+ scan_node_contents (node, 0, 0);
+
+ return node;
+}
+
DECLARE_INFO_COMMAND (info_virtual_index,
_("List all matches of a string in the index"))
{
char *prompt, *line;
FILE_BUFFER *fb;
NODE *node;
- struct text_buffer text;
- int i;
- size_t cnt;
fb = file_buffer_of_window (window);
@@ -855,51 +910,11 @@
return; /* No previous search string, and no string given. */
}
- text_buffer_init (&text);
- text_buffer_printf (&text,
- "File: %s, Node: Index for '%s'\n\n",
- fb->filename, index_search);
- text_buffer_printf (&text, _("Virtual Index\n"
- "*************\n\n"
- "Index entries that match '%s':\n"),
- index_search);
- text_buffer_add_string (&text, "\0\b[index\0\b]", 11);
- text_buffer_printf (&text, "\n* Menu:\n\n");
-
- cnt = 0;
-
- index_offset = 0;
- index_initial = 0;
- index_partial = 0;
- while (1)
+ node = create_virtual_index (fb, index_search);
+ if (!node)
{
- REFERENCE *result;
- int match_offset;
-
- next_index_match (file_buffer_of_window (window), index_search,
- index_offset, 1, &result, &i, &match_offset);
- if (!result)
- break;
- format_reference (index_index[i], fb->filename, &text);
- cnt++;
- }
- text_buffer_add_char (&text, '\0');
-
- if (cnt == 0)
- {
- text_buffer_free (&text);
info_error (_("No index entries containing '%s'."), index_search);
return;
}
-
- node = info_create_node ();
- asprintf (&node->nodename, "Index for '%s'", index_search);
- node->fullpath = fb->filename;
- node->contents = text_buffer_base (&text);
- node->nodelen = text_buffer_off (&text) - 1;
- node->body_start = strcspn (node->contents, "\n");
- node->flags |= N_IsInternal | N_WasRewritten;
-
- scan_node_contents (node, 0, 0);
info_set_node_of_window (window, node);
}
Modified: trunk/info/indices.h
===================================================================
--- trunk/info/indices.h 2016-11-05 20:25:20 UTC (rev 7498)
+++ trunk/info/indices.h 2016-11-07 20:29:49 UTC (rev 7499)
@@ -35,6 +35,7 @@
REFERENCE **result, int *found_offset, int *match_offset);
void report_index_match (int i, int match_offset);
REFERENCE *look_in_indices (FILE_BUFFER *fb, char *string, int sloppy);
+NODE *create_virtual_index (FILE_BUFFER *file_buffer, char *index_search);
#define APROPOS_NONE \
N_("No available info files have '%s' in their indices.")
Modified: trunk/info/info.c
===================================================================
--- trunk/info/info.c 2016-11-05 20:25:20 UTC (rev 7498)
+++ trunk/info/info.c 2016-11-07 20:29:49 UTC (rev 7499)
@@ -42,6 +42,10 @@
apropos, this puts the user at the node, running info. */
static int index_search_p = 0;
+/* Searching all indices for INDEX_SEARCH_STRING, and display a list of
+ the results. */
+static int virtual_index_p = 0;
+
/* Non-zero means look for the node which describes the invocation
and command-line options of the program, and start the info
session at that node. */
@@ -117,6 +121,7 @@
#define RESTORE_OPTION 3
#define IDXSRCH_OPTION 4
#define INITFLE_OPTION 5
+#define VIRTIDX_OPTION 6
static struct option long_options[] = {
{ "all", 0, 0, 'a' },
@@ -143,6 +148,7 @@
{ "variable", 1, 0, 'v' },
{ "version", 0, &print_version_p, 1 },
{ "vi-keys", 0, &vi_keys_p, 1 },
+ { "virtual-index", 1, 0, VIRTIDX_OPTION },
{ "where", 0, &print_where_p, 1 },
#if defined(__MSDOS__) || defined(__MINGW32__)
{ "speech-friendly", 0, &speech_friendly, 1 },
@@ -793,6 +799,9 @@
break;
/* User has specified a string to search all indices for. */
+ case VIRTIDX_OPTION:
+ virtual_index_p = 1;
+ /* fall through */
case IDXSRCH_OPTION:
index_search_p = 1;
free (index_search_string);
@@ -968,10 +977,47 @@
get_initial_file (&argc, &argv, &error);
+ /* If the user specified `--virtual-index=STRING', create
+ and display the menu of results. */
+ if (virtual_index_p && initial_file)
+ {
+ FILE_BUFFER *initial_fb;
+ initial_fb = info_find_file (initial_file);
+ if (initial_fb)
+ {
+ NODE *node = create_virtual_index (initial_fb,
+ index_search_string);
+ if (node)
+ {
+ if (user_output_filename)
+ {
+ FILE *output_stream = 0;
+ if (strcmp (user_output_filename, "-") == 0)
+ output_stream = stdout;
+ else
+ output_stream = fopen (user_output_filename, "w");
+ if (output_stream)
+ {
+ write_node_to_stream (node, output_stream);
+ }
+ exit (0);
+ }
+ else
+ {
+ initialize_info_session ();
+ info_set_node_of_window (active_window, node);
+ info_read_and_dispatch ();
+ close_info_session ();
+ exit (0);
+ }
+ }
+ }
+ }
+
/* If the user specified `--index-search=STRING',
start the info session in the node corresponding
to what they want. */
- if (index_search_p && initial_file && !user_output_filename)
+ else if (index_search_p && initial_file && !user_output_filename)
{
FILE_BUFFER *initial_fb;
initial_fb = info_find_file (initial_file);
Modified: trunk/info/session.c
===================================================================
--- trunk/info/session.c 2016-11-05 20:25:20 UTC (rev 7498)
+++ trunk/info/session.c 2016-11-07 20:29:49 UTC (rev 7499)
@@ -3689,7 +3689,6 @@
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);
@@ -3878,7 +3877,7 @@
debug (1, (_("finished printing node %s"), node_printed_rep (window->node)));
}
-static int
+int
write_node_to_stream (NODE *node, FILE *stream)
{
return fwrite (node->contents, node->nodelen, 1, stream) != 1;
Modified: trunk/info/session.h
===================================================================
--- trunk/info/session.h 2016-11-05 20:25:20 UTC (rev 7498)
+++ trunk/info/session.h 2016-11-07 20:29:49 UTC (rev 7499)
@@ -74,6 +74,7 @@
void dump_nodes_to_file (REFERENCE **references,
char *output_filename, int flags);
+int write_node_to_stream (NODE *node, FILE *stream);
char *program_name_from_file_name (char *file_name);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [7499] implement --virtual-index,
gavinsmith0123 <=