summaryrefslogtreecommitdiffstats
path: root/contrib/texinfo/makeinfo/index.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/texinfo/makeinfo/index.c')
-rw-r--r--contrib/texinfo/makeinfo/index.c397
1 files changed, 213 insertions, 184 deletions
diff --git a/contrib/texinfo/makeinfo/index.c b/contrib/texinfo/makeinfo/index.c
index 05466ce..edaf4e1 100644
--- a/contrib/texinfo/makeinfo/index.c
+++ b/contrib/texinfo/makeinfo/index.c
@@ -1,7 +1,7 @@
/* index.c -- indexing for Texinfo.
- $Id: index.c,v 1.21 1999/07/18 18:50:02 karl Exp $
+ $Id: index.c,v 1.24 2002/01/22 14:28:07 karl Exp $
- Copyright (C) 1998, 99 Free Software Foundation, Inc.
+ Copyright (C) 1998, 99, 2002 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
@@ -22,6 +22,7 @@
#include "lang.h"
#include "macro.h"
#include "toc.h"
+#include "xml.h"
/* An index element... */
typedef struct index_elt
@@ -226,7 +227,13 @@ index_add_arg (name)
(see the findexerr test). */
new->defining_file = xstrdup (input_filename);
the_indices[which] = new;
+ /* The index breaks if there are colons in the entry. */
+ if (strchr (new->entry_text, ':'))
+ warning (_("Info cannot handle `:' in index entry `%s'"),
+ new->entry_text);
}
+ if (xml)
+ xml_insert_indexterm (index_entry, name);
}
/* The function which user defined index commands call. */
@@ -583,7 +590,7 @@ sort_index (index)
/* If this particular entry should be printed as a "code" index,
then expand it as @code{entry}, i.e. as in fixed-width font. */
array[count-1]->entry = expansion (temp->entry_text,
- array[count-1]->code);
+ array[count-1]->code);
temp = temp->next;
}
@@ -621,203 +628,225 @@ int printing_index = 0;
void
cm_printindex ()
{
- int item;
- INDEX_ELT *index;
- INDEX_ELT *last_index = 0;
- INDEX_ELT **array;
- char *index_name;
- unsigned line_length;
- char *line;
- int saved_inhibit_paragraph_indentation = inhibit_paragraph_indentation;
- int saved_filling_enabled = filling_enabled;
- int saved_line_number = line_number;
- char *saved_input_filename = input_filename;
-
- close_paragraph ();
- get_rest_of_line (0, &index_name);
-
- index = index_list (index_name);
- if (index == (INDEX_ELT *)-1)
+ if (xml && !docbook)
{
- line_error (_("Unknown index `%s' in @printindex"), index_name);
- free (index_name);
- return;
+ char *index_name;
+ get_rest_of_line (0, &index_name);
+ xml_insert_element (PRINTINDEX, START);
+ insert_string (index_name);
+ xml_insert_element (PRINTINDEX, END);
}
-
- /* Do this before sorting, so execute_string in index_element_compare
- will give the same results as when we actually print. */
- printing_index = 1;
- filling_enabled = 0;
- inhibit_paragraph_indentation = 1;
- array = sort_index (index);
-
- close_paragraph ();
- if (html)
- add_word ("<ul compact>");
- else if (!no_headers)
- add_word ("* Menu:\n\n");
-
- me_inhibit_expansion++;
-
- /* This will probably be enough. */
- line_length = 100;
- line = xmalloc (line_length);
-
- for (item = 0; (index = array[item]); item++)
+ else
{
- /* A pathological document might have an index entry outside of any
- node. Don't crash; try using the section name instead. */
- char *index_node = index->node;
-
- line_number = index->defining_line;
- input_filename = index->defining_file;
-
- if ((!index_node || !*index_node) && html)
- index_node = toc_find_section_of_node (index_node);
-
- if (!index_node || !*index_node)
+ int item;
+ INDEX_ELT *index;
+ INDEX_ELT *last_index = 0;
+ INDEX_ELT **array;
+ char *index_name;
+ unsigned line_length;
+ char *line;
+ int saved_inhibit_paragraph_indentation = inhibit_paragraph_indentation;
+ int saved_filling_enabled = filling_enabled;
+ int saved_line_number = line_number;
+ char *saved_input_filename = input_filename;
+
+ close_paragraph ();
+ get_rest_of_line (0, &index_name);
+
+ index = index_list (index_name);
+ if (index == (INDEX_ELT *)-1)
{
- line_error (_("Entry for index `%s' outside of any node"),
- index_name);
- if (html || !no_headers)
- index_node = _("(outside of any node)");
+ line_error (_("Unknown index `%s' in @printindex"), index_name);
+ free (index_name);
+ return;
}
-
+
+ /* Do this before sorting, so execute_string is in the good environment */
+ if (xml && docbook)
+ xml_begin_index ();
+
+ /* Do this before sorting, so execute_string in index_element_compare
+ will give the same results as when we actually print. */
+ printing_index = 1;
+ filling_enabled = 0;
+ inhibit_paragraph_indentation = 1;
+ xml_sort_index = 1;
+ array = sort_index (index);
+ xml_sort_index = 0;
+ close_paragraph ();
if (html)
- /* fixme: html: we should use specific index anchors pointing
+ add_word ("<ul compact>");
+ else if (!no_headers && !docbook)
+ add_word ("* Menu:\n\n");
+
+ me_inhibit_expansion++;
+
+ /* This will probably be enough. */
+ line_length = 100;
+ line = xmalloc (line_length);
+
+ for (item = 0; (index = array[item]); item++)
+ {
+ /* A pathological document might have an index entry outside of any
+ node. Don't crash; try using the section name instead. */
+ char *index_node = index->node;
+
+ line_number = index->defining_line;
+ input_filename = index->defining_file;
+
+ if ((!index_node || !*index_node) && html)
+ index_node = toc_find_section_of_node (index_node);
+
+ if (!index_node || !*index_node)
+ {
+ line_error (_("Entry for index `%s' outside of any node"),
+ index_name);
+ if (html || !no_headers)
+ index_node = _("(outside of any node)");
+ }
+
+ if (html)
+ /* fixme: html: we should use specific index anchors pointing
to the actual location of the indexed position (but then we
have to find something to wrap the anchor around). */
- {
- if (last_index
- && STREQ (last_index->entry_text, index->entry_text))
- add_word (", "); /* Don't repeat the previous entry. */
- else
- {
- /* In the HTML case, the expanded index entry is not
- good for us, since it was expanded for non-HTML mode
- inside sort_index. So we need to HTML-escape and
- expand the original entry text here. */
- char *escaped_entry = xstrdup (index->entry_text);
- char *expanded_entry;
-
- /* expansion() doesn't HTML-escape the argument, so need
- to do it separately. */
- escaped_entry = escape_string (escaped_entry);
- expanded_entry = expansion (escaped_entry, index->code);
- add_word_args ("\n<li>%s: ", expanded_entry);
- free (escaped_entry);
- free (expanded_entry);
- }
- add_word ("<a href=\"");
- if (index->node && *index->node)
{
- /* Make sure any non-macros in the node name are expanded. */
- in_fixed_width_font++;
- index_node = expansion (index_node, 0);
- in_fixed_width_font--;
- add_anchor_name (index_node, 1);
- add_word_args ("\">%s</a>", index_node);
- free (index_node);
+ if (last_index
+ && STREQ (last_index->entry_text, index->entry_text))
+ add_word (", "); /* Don't repeat the previous entry. */
+ else
+ {
+ /* In the HTML case, the expanded index entry is not
+ good for us, since it was expanded for non-HTML mode
+ inside sort_index. So we need to HTML-escape and
+ expand the original entry text here. */
+ char *escaped_entry = xstrdup (index->entry_text);
+ char *expanded_entry;
+
+ /* expansion() doesn't HTML-escape the argument, so need
+ to do it separately. */
+ escaped_entry = escape_string (escaped_entry);
+ expanded_entry = expansion (escaped_entry, index->code);
+ add_word_args ("\n<li>%s: ", expanded_entry);
+ free (escaped_entry);
+ free (expanded_entry);
+ }
+ add_word ("<a href=\"");
+ if (index->node && *index->node)
+ {
+ /* Make sure any non-macros in the node name are expanded. */
+ in_fixed_width_font++;
+ index_node = expansion (index_node, 0);
+ in_fixed_width_font--;
+ add_anchor_name (index_node, 1);
+ add_word_args ("\">%s</a>", index_node);
+ free (index_node);
+ }
+ else if (STREQ (index_node, _("(outside of any node)")))
+ {
+ add_anchor_name (index_node, 1);
+ add_word_args ("\">%s</a>", index_node);
+ }
+ else
+ /* If we use the section instead of the (missing) node, then
+ index_node already includes all we need except the #. */
+ add_word_args ("#%s</a>", index_node);
}
- else if (STREQ (index_node, _("(outside of any node)")))
+ else if (xml && docbook)
{
- add_anchor_name (index_node, 1);
- add_word_args ("\">%s</a>", index_node);
+ xml_insert_indexentry (index->entry, index_node);
}
else
- /* If we use the section instead of the (missing) node, then
- index_node already includes all we need except the #. */
- add_word_args ("#%s</a>", index_node);
- }
- else
- {
- unsigned new_length = strlen (index->entry);
-
- if (new_length < 50) /* minimum length used below */
- new_length = 50;
- new_length += strlen (index_node) + 7; /* * : .\n\0 */
-
- if (new_length > line_length)
- {
- line_length = new_length;
- line = xrealloc (line, line_length);
- }
- /* Print the entry, nicely formatted. We've already
- expanded any commands in index->entry, including any
- implicit @code. Thus, can't call execute_string, since
- @@ has turned into @. */
- if (!no_headers)
- {
- sprintf (line, "* %-37s ", index->entry);
- line[2 + strlen (index->entry)] = ':';
- insert_string (line);
- /* Make sure any non-macros in the node name are expanded. */
- in_fixed_width_font++;
- execute_string ("%s.\n", index_node);
- in_fixed_width_font--;
- }
- else
- {
- /* With --no-headers, the @node lines are gone, so
- there's little sense in referring to them in the
- index. Instead, output the number or name of the
- section that corresponds to that node. */
- char *section_name = toc_find_section_of_node (index_node);
-
- sprintf (line, "%-*s ", number_sections ? 50 : 1, index->entry);
- line[strlen (index->entry)] = ':';
- insert_string (line);
- if (section_name)
- {
- int idx = 0;
- unsigned ref_len = strlen (section_name) + 30;
-
- if (ref_len > line_length)
- {
- line_length = ref_len;
- line = xrealloc (line, line_length);
- }
-
- if (number_sections)
- {
- while (section_name[idx]
- && (isdigit (section_name[idx])
- || (idx && section_name[idx] == '.')))
- idx++;
- }
- if (idx)
- sprintf (line, " See %.*s.\n", idx, section_name);
- else
- sprintf (line, "\n See ``%s''.\n", section_name);
+ {
+ unsigned new_length = strlen (index->entry);
+
+ if (new_length < 50) /* minimum length used below */
+ new_length = 50;
+ new_length += strlen (index_node) + 7; /* * : .\n\0 */
+
+ if (new_length > line_length)
+ {
+ line_length = new_length;
+ line = xrealloc (line, line_length);
+ }
+ /* Print the entry, nicely formatted. We've already
+ expanded any commands in index->entry, including any
+ implicit @code. Thus, can't call execute_string, since
+ @@ has turned into @. */
+ if (!no_headers)
+ {
+ sprintf (line, "* %-37s ", index->entry);
+ line[2 + strlen (index->entry)] = ':';
insert_string (line);
- }
- else
+ /* Make sure any non-macros in the node name are expanded. */
+ in_fixed_width_font++;
+ execute_string ("%s.\n", index_node);
+ in_fixed_width_font--;
+ }
+ else
{
- insert_string (" "); /* force a blank */
- execute_string ("See node %s.\n", index_node);
+ /* With --no-headers, the @node lines are gone, so
+ there's little sense in referring to them in the
+ index. Instead, output the number or name of the
+ section that corresponds to that node. */
+ char *section_name = toc_find_section_of_node (index_node);
+
+ sprintf (line, "%-*s ", number_sections ? 50 : 1, index->entry);
+ line[strlen (index->entry)] = ':';
+ insert_string (line);
+ if (section_name)
+ {
+ int idx = 0;
+ unsigned ref_len = strlen (section_name) + 30;
+
+ if (ref_len > line_length)
+ {
+ line_length = ref_len;
+ line = xrealloc (line, line_length);
+ }
+
+ if (number_sections)
+ {
+ while (section_name[idx]
+ && (isdigit (section_name[idx])
+ || (idx && section_name[idx] == '.')))
+ idx++;
+ }
+ if (idx)
+ sprintf (line, " See %.*s.\n", idx, section_name);
+ else
+ sprintf (line, "\n See ``%s''.\n", section_name);
+ insert_string (line);
+ }
+ else
+ {
+ insert_string (" "); /* force a blank */
+ execute_string ("See node %s.\n", index_node);
+ }
}
- }
- }
+ }
+
+ /* Prevent `output_paragraph' from growing to the size of the
+ whole index. */
+ flush_output ();
+ last_index = index;
+ }
- /* Prevent `output_paragraph' from growing to the size of the
- whole index. */
- flush_output ();
- last_index = index;
+ free (line);
+ free (index_name);
+
+ me_inhibit_expansion--;
+
+ printing_index = 0;
+ free (array);
+ close_single_paragraph ();
+ filling_enabled = saved_filling_enabled;
+ inhibit_paragraph_indentation = saved_inhibit_paragraph_indentation;
+ input_filename = saved_input_filename;
+ line_number = saved_line_number;
+
+ if (html)
+ add_word ("</ul>");
+ else if (xml && docbook)
+ xml_end_index ();
}
-
- free (line);
- free (index_name);
-
- me_inhibit_expansion--;
-
- printing_index = 0;
- free (array);
- close_single_paragraph ();
- filling_enabled = saved_filling_enabled;
- inhibit_paragraph_indentation = saved_inhibit_paragraph_indentation;
- input_filename = saved_input_filename;
- line_number = saved_line_number;
-
- if (html)
- add_word ("</ul>");
}
OpenPOWER on IntegriCloud