summaryrefslogtreecommitdiff
path: root/gnu/usr.bin/texinfo/info/indices.c
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/usr.bin/texinfo/info/indices.c')
-rw-r--r--gnu/usr.bin/texinfo/info/indices.c522
1 files changed, 291 insertions, 231 deletions
diff --git a/gnu/usr.bin/texinfo/info/indices.c b/gnu/usr.bin/texinfo/info/indices.c
index 6848884288b..2a895e8a52b 100644
--- a/gnu/usr.bin/texinfo/info/indices.c
+++ b/gnu/usr.bin/texinfo/info/indices.c
@@ -1,9 +1,7 @@
-/* indices.c -- Commands for dealing with an Info file Index. */
+/* indices.c -- Commands for dealing with an Info file Index.
+ $Id: indices.c,v 1.2 1999/01/11 16:38:08 espie Exp $
-/* This file is part of GNU Info, a program for reading online documentation
- stored in Info format.
-
- Copyright (C) 1993 Free Software Foundation, Inc.
+ Copyright (C) 1993, 97 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -43,9 +41,9 @@ static char *initial_index_nodename = (char *)NULL;
/* A structure associating index names with index offset ranges. */
typedef struct {
- char *name; /* The nodename of this index. */
- int first; /* The index in our list of the first entry. */
- int last; /* The index in our list of the last entry. */
+ char *name; /* The nodename of this index. */
+ int first; /* The index in our list of the first entry. */
+ int last; /* The index in our list of the last entry. */
} INDEX_NAME_ASSOC;
/* An array associating index nodenames with index offset ranges. */
@@ -65,7 +63,7 @@ add_index_to_index_nodenames (array, node)
for (last = 0; array[last]; last++);
assoc = (INDEX_NAME_ASSOC *)xmalloc (sizeof (INDEX_NAME_ASSOC));
- assoc->name = strdup (node->nodename);
+ assoc->name = xstrdup (node->nodename);
if (!index_nodenames_index)
{
@@ -119,10 +117,10 @@ info_indices_of_file_buffer (file_buffer)
if (index_nodenames)
{
for (i = 0; index_nodenames[i]; i++)
- {
- free (index_nodenames[i]->name);
- free (index_nodenames[i]);
- }
+ {
+ free (index_nodenames[i]->name);
+ free (index_nodenames[i]);
+ }
index_nodenames_index = 0;
index_nodenames[0] = (INDEX_NAME_ASSOC *)NULL;
@@ -133,48 +131,59 @@ info_indices_of_file_buffer (file_buffer)
{
TAG *tag;
- for (i = 0; tag = file_buffer->tags[i]; i++)
- {
- if (string_in_line ("Index", tag->nodename) != -1)
- {
- NODE *node;
- REFERENCE **menu;
-
- /* Found one. Get its menu. */
- node = info_get_node (tag->filename, tag->nodename);
- if (!node)
- continue;
-
- /* Remember the filename and nodename of this index. */
- initial_index_filename = strdup (file_buffer->filename);
- initial_index_nodename = strdup (tag->nodename);
-
- menu = info_menu_of_node (node);
-
- /* If we have a menu, add this index's nodename and range
- to our list of index_nodenames. */
- if (menu)
- {
- add_index_to_index_nodenames (menu, node);
-
- /* Concatenate the references found so far. */
- result = info_concatenate_references (result, menu);
- }
- free (node);
- }
- }
+ for (i = 0; (tag = file_buffer->tags[i]); i++)
+ {
+ if (string_in_line ("Index", tag->nodename) != -1)
+ {
+ NODE *node;
+ REFERENCE **menu;
+
+ /* Found one. Get its menu. */
+ node = info_get_node (tag->filename, tag->nodename);
+ if (!node)
+ continue;
+
+ /* Remember the filename and nodename of this index. */
+ initial_index_filename = xstrdup (file_buffer->filename);
+ initial_index_nodename = xstrdup (tag->nodename);
+
+ menu = info_menu_of_node (node);
+
+ /* If we have a menu, add this index's nodename and range
+ to our list of index_nodenames. */
+ if (menu)
+ {
+ add_index_to_index_nodenames (menu, node);
+
+ /* Concatenate the references found so far. */
+ result = info_concatenate_references (result, menu);
+ }
+ free (node);
+ }
+ }
}
/* If there is a result, clean it up so that every entry has a filename. */
for (i = 0; result && result[i]; i++)
if (!result[i]->filename)
- result[i]->filename = strdup (file_buffer->filename);
+ result[i]->filename = xstrdup (file_buffer->filename);
return (result);
}
DECLARE_INFO_COMMAND (info_index_search,
- "Look up a string in the index for this file")
+ _("Look up a string in the index for this file"))
+{
+ do_info_index_search (window, count, 0);
+}
+
+/* Look up SEARCH_STRING in the index for this file. If SEARCH_STRING
+ is NULL, prompt user for input. */
+void
+do_info_index_search (window, count, search_string)
+ WINDOW *window;
+ int count;
+ char *search_string;
{
FILE_BUFFER *fb;
char *line;
@@ -193,47 +202,52 @@ DECLARE_INFO_COMMAND (info_index_search,
(strcmp (initial_index_filename, fb->filename) != 0))
{
info_free_references (index_index);
- window_message_in_echo_area ("Finding index entries...");
+ window_message_in_echo_area (_("Finding index entries..."));
index_index = info_indices_of_file_buffer (fb);
}
/* If there is no index, quit now. */
if (!index_index)
{
- info_error ("No indices found.");
- return;
- }
-
- /* Okay, there is an index. Let the user select one of the members of it. */
- line =
- info_read_maybe_completing (window, "Index entry: ", index_index);
-
- window = active_window;
-
- /* User aborted? */
- if (!line)
- {
- info_abort_key (active_window, 1, 0);
+ info_error (_("No indices found."));
return;
}
- /* Empty line means move to the Index node. */
- if (!*line)
+ /* Okay, there is an index. Look for SEARCH_STRING, or, if it is
+ empty, prompt for one. */
+ if (search_string && *search_string)
+ line = xstrdup (search_string);
+ else
{
- free (line);
-
- if (initial_index_filename && initial_index_nodename)
- {
- NODE *node;
-
- node =
- info_get_node (initial_index_filename, initial_index_nodename);
- set_remembered_pagetop_and_point (window);
- window_set_node_of_window (window, node);
- remember_window_and_node (window, node);
- window_clear_echo_area ();
- return;
- }
+ line = info_read_maybe_completing (window, _("Index entry: "),
+ index_index);
+ window = active_window;
+
+ /* User aborted? */
+ if (!line)
+ {
+ info_abort_key (active_window, 1, 0);
+ return;
+ }
+
+ /* Empty line means move to the Index node. */
+ if (!*line)
+ {
+ free (line);
+
+ if (initial_index_filename && initial_index_nodename)
+ {
+ NODE *node;
+
+ node = info_get_node (initial_index_filename,
+ initial_index_nodename);
+ set_remembered_pagetop_and_point (window);
+ window_set_node_of_window (window, node);
+ remember_window_and_node (window, node);
+ window_clear_echo_area ();
+ return;
+ }
+ }
}
/* The user typed either a completed index label, or a partial string.
@@ -246,9 +260,9 @@ DECLARE_INFO_COMMAND (info_index_search,
/* Start the search right after/before this index. */
if (count < 0)
{
- register int i;
- for (i = 0; index_index[i]; i++);
- index_offset = i;
+ register int i;
+ for (i = 0; index_index[i]; i++);
+ index_offset = i;
}
else
index_offset = -1;
@@ -267,8 +281,55 @@ DECLARE_INFO_COMMAND (info_index_search,
}
}
+int
+index_entry_exists (window, string)
+ WINDOW *window;
+ char *string;
+{
+ register int i;
+ FILE_BUFFER *fb;
+
+ /* If there is no previous search string, the user hasn't built an index
+ yet. */
+ if (!string)
+ return 0;
+
+ fb = file_buffer_of_window (window);
+ if (!initial_index_filename
+ || (strcmp (initial_index_filename, fb->filename) != 0))
+ {
+ info_free_references (index_index);
+ index_index = info_indices_of_file_buffer (fb);
+ }
+
+ /* If there is no index, that is an error. */
+ if (!index_index)
+ return 0;
+
+ for (i = 0; (i > -1) && (index_index[i]); i++)
+ if (strcmp (string, index_index[i]->label) == 0)
+ break;
+
+ /* If that failed, look for the next substring match. */
+ if ((i < 0) || (!index_index[i]))
+ {
+ for (i = 0; (i > -1) && (index_index[i]); i++)
+ if (string_in_line (string, index_index[i]->label) != -1)
+ break;
+
+ if ((i > -1) && (index_index[i]))
+ string_in_line (string, index_index[i]->label);
+ }
+
+ /* If that failed, return 0. */
+ if ((i < 0) || (!index_index[i]))
+ return 0;
+
+ return 1;
+}
+
DECLARE_INFO_COMMAND (info_next_index_match,
- "Go to the next matching index item from the last `\\[index-search]' command")
+ _("Go to the next matching index item from the last `\\[index-search]' command"))
{
register int i;
int partial, dir;
@@ -278,14 +339,14 @@ DECLARE_INFO_COMMAND (info_next_index_match,
yet. */
if (!index_search)
{
- info_error ("No previous index search string.");
+ info_error (_("No previous index search string."));
return;
}
/* If there is no index, that is an error. */
if (!index_index)
{
- info_error ("No index entries.");
+ info_error (_("No index entries."));
return;
}
@@ -308,18 +369,18 @@ DECLARE_INFO_COMMAND (info_next_index_match,
if ((i < 0) || (!index_index[i]))
{
for (i = index_offset + dir; (i > -1) && (index_index[i]); i += dir)
- if (string_in_line (index_search, index_index[i]->label) != -1)
- break;
+ if (string_in_line (index_search, index_index[i]->label) != -1)
+ break;
if ((i > -1) && (index_index[i]))
- partial = string_in_line (index_search, index_index[i]->label);
+ partial = string_in_line (index_search, index_index[i]->label);
}
/* If that failed, print an error. */
if ((i < 0) || (!index_index[i]))
{
- info_error ("No %sindex entries containing \"%s\".",
- index_offset > 0 ? "more " : "", index_search);
+ info_error (_("No %sindex entries containing \"%s\"."),
+ index_offset > 0 ? _("more ") : "", index_search);
return;
}
@@ -329,43 +390,43 @@ DECLARE_INFO_COMMAND (info_next_index_match,
/* Report to the user on what we have found. */
{
register int j;
- char *name = "CAN'T SEE THIS";
+ char *name = _("CAN'T SEE THIS");
char *match;
for (j = 0; index_nodenames[j]; j++)
{
- if ((i >= index_nodenames[j]->first) &&
- (i <= index_nodenames[j]->last))
- {
- name = index_nodenames[j]->name;
- break;
- }
+ if ((i >= index_nodenames[j]->first) &&
+ (i <= index_nodenames[j]->last))
+ {
+ name = index_nodenames[j]->name;
+ break;
+ }
}
/* If we had a partial match, indicate to the user which part of the
string matched. */
- match = strdup (index_index[i]->label);
+ match = xstrdup (index_index[i]->label);
if (partial && show_index_match)
{
- int j, ls, start, upper;
+ int j, ls, start, upper;
- ls = strlen (index_search);
- start = partial - ls;
- upper = isupper (match[start]) ? 1 : 0;
+ ls = strlen (index_search);
+ start = partial - ls;
+ upper = isupper (match[start]) ? 1 : 0;
- for (j = 0; j < ls; j++)
- if (upper)
- match[j + start] = info_tolower (match[j + start]);
- else
- match[j + start] = info_toupper (match[j + start]);
+ for (j = 0; j < ls; j++)
+ if (upper)
+ match[j + start] = info_tolower (match[j + start]);
+ else
+ match[j + start] = info_toupper (match[j + start]);
}
{
char *format;
format = replace_in_documentation
- ("Found \"%s\" in %s. (`\\[next-index-match]' tries to find next.)");
+ (_("Found \"%s\" in %s. (`\\[next-index-match]' tries to find next.)"));
window_message_in_echo_area (format, match, name);
}
@@ -379,7 +440,7 @@ DECLARE_INFO_COMMAND (info_next_index_match,
if (!node)
{
info_error (CANT_FILE_NODE,
- index_index[i]->filename, index_index[i]->nodename);
+ index_index[i]->filename, index_index[i]->nodename);
return;
}
@@ -397,16 +458,16 @@ DECLARE_INFO_COMMAND (info_next_index_match,
if (loc != -1)
{
- window->point = loc;
- window_adjust_pagetop (window);
+ window->point = loc;
+ window_adjust_pagetop (window);
}
}
}
/* **************************************************************** */
-/* */
-/* Info APROPOS: Search every known index. */
-/* */
+/* */
+/* Info APROPOS: Search every known index. */
+/* */
/* **************************************************************** */
/* For every menu item in DIR, search the indices of that file for
@@ -420,14 +481,13 @@ apropos_in_all_indices (search_string, inform)
REFERENCE **all_indices = (REFERENCE **)NULL;
REFERENCE **dir_menu = (REFERENCE **)NULL;
NODE *dir_node;
- int printed = 0;
dir_node = info_get_node ("dir", "Top");
if (dir_node)
dir_menu = info_menu_of_node (dir_node);
if (!dir_menu)
- return;
+ return NULL;
/* For every menu item in DIR, get the associated node's file buffer and
read the indices of that file buffer. Gather all of the indices into
@@ -441,54 +501,54 @@ apropos_in_all_indices (search_string, inform)
this_item = dir_menu[dir_index];
if (!this_item->filename)
- {
- if (dir_node->parent)
- this_item->filename = strdup (dir_node->parent);
- else
- this_item->filename = strdup (dir_node->filename);
- }
+ {
+ if (dir_node->parent)
+ this_item->filename = xstrdup (dir_node->parent);
+ else
+ this_item->filename = xstrdup (dir_node->filename);
+ }
/* Find this node. If we cannot find it, try using the label of the
- entry as a file (i.e., "(LABEL)Top"). */
+ entry as a file (i.e., "(LABEL)Top"). */
this_node = info_get_node (this_item->filename, this_item->nodename);
if (!this_node && this_item->nodename &&
- (strcmp (this_item->label, this_item->nodename) == 0))
- this_node = info_get_node (this_item->label, "Top");
+ (strcmp (this_item->label, this_item->nodename) == 0))
+ this_node = info_get_node (this_item->label, "Top");
if (!this_node)
- continue;
+ continue;
/* Get the file buffer associated with this node. */
{
- char *files_name;
+ char *files_name;
- files_name = this_node->parent;
- if (!files_name)
- files_name = this_node->filename;
+ files_name = this_node->parent;
+ if (!files_name)
+ files_name = this_node->filename;
- this_fb = info_find_file (files_name);
+ this_fb = info_find_file (files_name);
- if (this_fb && inform)
- message_in_echo_area ("Scanning indices of \"%s\"...", files_name);
+ if (this_fb && inform)
+ message_in_echo_area (_("Scanning indices of \"%s\"..."), files_name);
- this_index = info_indices_of_file_buffer (this_fb);
- free (this_node);
+ this_index = info_indices_of_file_buffer (this_fb);
+ free (this_node);
- if (this_fb && inform)
- unmessage_in_echo_area ();
+ if (this_fb && inform)
+ unmessage_in_echo_area ();
}
if (this_index)
- {
- /* Remember the filename which contains this set of references. */
- for (i = 0; this_index && this_index[i]; i++)
- if (!this_index[i]->filename)
- this_index[i]->filename = strdup (this_fb->filename);
-
- /* Concatenate with the other indices. */
- all_indices = info_concatenate_references (all_indices, this_index);
- }
+ {
+ /* Remember the filename which contains this set of references. */
+ for (i = 0; this_index && this_index[i]; i++)
+ if (!this_index[i]->filename)
+ this_index[i]->filename = xstrdup (this_fb->filename);
+
+ /* Concatenate with the other indices. */
+ all_indices = info_concatenate_references (all_indices, this_index);
+ }
}
info_free_references (dir_menu);
@@ -501,21 +561,21 @@ apropos_in_all_indices (search_string, inform)
int apropos_list_slots = 0;
for (i = 0; (entry = all_indices[i]); i++)
- {
- if (string_in_line (search_string, entry->label) != -1)
- {
- add_pointer_to_array
- (entry, apropos_list_index, apropos_list, apropos_list_slots,
- 100, REFERENCE *);
- }
- else
- {
- maybe_free (entry->label);
- maybe_free (entry->filename);
- maybe_free (entry->nodename);
- free (entry);
- }
- }
+ {
+ if (string_in_line (search_string, entry->label) != -1)
+ {
+ add_pointer_to_array
+ (entry, apropos_list_index, apropos_list, apropos_list_slots,
+ 100, REFERENCE *);
+ }
+ else
+ {
+ maybe_free (entry->label);
+ maybe_free (entry->filename);
+ maybe_free (entry->nodename);
+ free (entry);
+ }
+ }
free (all_indices);
all_indices = apropos_list;
@@ -524,7 +584,7 @@ apropos_in_all_indices (search_string, inform)
}
#define APROPOS_NONE \
- "No available info files reference \"%s\" in their indices."
+ _("No available info files reference \"%s\" in their indices.")
void
info_apropos (string)
@@ -544,8 +604,8 @@ info_apropos (string)
REFERENCE *entry;
for (i = 0; (entry = apropos_list[i]); i++)
- fprintf (stderr, "\"(%s)%s\" -- %s\n",
- entry->filename, entry->nodename, entry->label);
+ fprintf (stderr, "\"(%s)%s\" -- %s\n",
+ entry->filename, entry->nodename, entry->label);
}
info_free_references (apropos_list);
}
@@ -553,11 +613,11 @@ info_apropos (string)
static char *apropos_list_nodename = "*Apropos*";
DECLARE_INFO_COMMAND (info_index_apropos,
- "Grovel all known info file's indices for a string and build a menu")
+ _("Grovel all known info file's indices for a string and build a menu"))
{
char *line;
- line = info_read_in_echo_area (window, "Index apropos: ");
+ line = info_read_in_echo_area (window, _("Index apropos: "));
window = active_window;
@@ -577,85 +637,85 @@ DECLARE_INFO_COMMAND (info_index_apropos,
apropos_list = apropos_in_all_indices (line, 1);
if (!apropos_list)
- {
- info_error (APROPOS_NONE, line);
- }
+ {
+ info_error (APROPOS_NONE, line);
+ }
else
- {
- register int i;
- char *line_buffer;
-
- initialize_message_buffer ();
- printf_to_message_buffer
- ("\n* Menu: Nodes whoses indices contain \"%s\":\n", line);
- line_buffer = (char *)xmalloc (500);
-
- for (i = 0; apropos_list[i]; i++)
- {
- int len;
- sprintf (line_buffer, "* (%s)%s::",
- apropos_list[i]->filename, apropos_list[i]->nodename);
- len = pad_to (36, line_buffer);
- sprintf (line_buffer + len, "%s", apropos_list[i]->label);
- printf_to_message_buffer ("%s\n", line_buffer);
- }
- free (line_buffer);
- }
+ {
+ register int i;
+ char *line_buffer;
+
+ initialize_message_buffer ();
+ printf_to_message_buffer
+ (_("\n* Menu: Nodes whoses indices contain \"%s\":\n"), line);
+ line_buffer = (char *)xmalloc (500);
+
+ for (i = 0; apropos_list[i]; i++)
+ {
+ int len;
+ sprintf (line_buffer, "* (%s)%s::",
+ apropos_list[i]->filename, apropos_list[i]->nodename);
+ len = pad_to (36, line_buffer);
+ sprintf (line_buffer + len, "%s", apropos_list[i]->label);
+ printf_to_message_buffer ("%s\n", line_buffer);
+ }
+ free (line_buffer);
+ }
apropos_node = message_buffer_to_node ();
add_gcable_pointer (apropos_node->contents);
name_internal_node (apropos_node, apropos_list_nodename);
/* Even though this is an internal node, we don't want the window
- system to treat it specially. So we turn off the internalness
- of it here. */
+ system to treat it specially. So we turn off the internalness
+ of it here. */
apropos_node->flags &= ~N_IsInternal;
/* Find/Create a window to contain this node. */
{
- WINDOW *new;
- NODE *node;
-
- set_remembered_pagetop_and_point (window);
-
- /* If a window is visible and showing an apropos list already,
- re-use it. */
- for (new = windows; new; new = new->next)
- {
- node = new->node;
-
- if (internal_info_node_p (node) &&
- (strcmp (node->nodename, apropos_list_nodename) == 0))
- break;
- }
-
- /* If we couldn't find an existing window, try to use the next window
- in the chain. */
- if (!new && window->next)
- new = window->next;
-
- /* If we still don't have a window, make a new one to contain
- the list. */
- if (!new)
- {
- WINDOW *old_active;
-
- old_active = active_window;
- active_window = window;
- new = window_make_window ((NODE *)NULL);
- active_window = old_active;
- }
-
- /* If we couldn't make a new window, use this one. */
- if (!new)
- new = window;
-
- /* Lines do not wrap in this window. */
- new->flags |= W_NoWrap;
-
- window_set_node_of_window (new, apropos_node);
- remember_window_and_node (new, apropos_node);
- active_window = new;
+ WINDOW *new;
+ NODE *node;
+
+ set_remembered_pagetop_and_point (window);
+
+ /* If a window is visible and showing an apropos list already,
+ re-use it. */
+ for (new = windows; new; new = new->next)
+ {
+ node = new->node;
+
+ if (internal_info_node_p (node) &&
+ (strcmp (node->nodename, apropos_list_nodename) == 0))
+ break;
+ }
+
+ /* If we couldn't find an existing window, try to use the next window
+ in the chain. */
+ if (!new && window->next)
+ new = window->next;
+
+ /* If we still don't have a window, make a new one to contain
+ the list. */
+ if (!new)
+ {
+ WINDOW *old_active;
+
+ old_active = active_window;
+ active_window = window;
+ new = window_make_window ((NODE *)NULL);
+ active_window = old_active;
+ }
+
+ /* If we couldn't make a new window, use this one. */
+ if (!new)
+ new = window;
+
+ /* Lines do not wrap in this window. */
+ new->flags |= W_NoWrap;
+
+ window_set_node_of_window (new, apropos_node);
+ remember_window_and_node (new, apropos_node);
+ active_window = new;
}
info_free_references (apropos_list);
}