[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: @contents problem with 4.0f
From: |
Eli Zaretskii |
Subject: |
Re: @contents problem with 4.0f |
Date: |
Wed, 23 Jan 2002 22:47:36 +0200 |
> From: "address@hidden" <address@hidden>
> Date: Wed, 23 Jan 2002 13:25:51 +0100
>
> here is a sample test to visualize bugs with @contents command
You are right, there were quite a few problems with TOC in the
pretest. Please try the patches below:
2002-01-23 Eli Zaretskii <address@hidden>
* makeinfo/toc.h <TOC_ENTRY_ELT>: New member html_file.
* makeinfo/toc.c (toc_add_entry): Compute and set the html_file
member.
(shortcontents_update_html): Produce the toc_* links correctly,
without duplicating the link text. Fix comparison with "Top".
Handle the case when there's @shortcontents, but no @contents.
(contents_update_html): Fix the way toc_* anchors are produced
from toc_entry_alist[i]->name: take only the node name from the
string in toc_entry_alist[i]->name. Fix comparison with "Top".
* makeinfo/sectioning.c (sectioning_html): Take the toc_anchor
substring before closing the anchor with </a>. Fix the closing
</hN> tag--add 2 to level, not 1. Use sizeof instead of a magic
value of 9.
* makeinfo/cmds.c: Make @summarycontents call cm_shortcontents, as
promised by the docs.
--- makeinfo/toc.h~0 Sun Apr 25 22:49:22 1999
+++ makeinfo/toc.h Wed Jan 23 21:25:02 2002
@@ -32,6 +32,7 @@
typedef struct toc_entry_elt {
char *name;
char *containing_node; /* Name of node containing this section. */
+ char *html_file; /* Name of HTML node-file in split-HTML mode */
int number; /* counting number from 0...n independent from
chapter/section can be used for anchors or
references to it. */
--- makeinfo/toc.c~0 Wed Jan 16 17:52:56 2002
+++ makeinfo/toc.c Wed Jan 23 22:18:32 2002
@@ -60,6 +60,7 @@ toc_add_entry (tocname, level, node_name
char *anchor;
{
char *tocname_and_node, *expanded_node, *s, *d;
+ char *filename = NULL;
if (!node_name)
node_name = "";
@@ -71,12 +72,7 @@ toc_add_entry (tocname, level, node_name
toc_entry_alist[toc_counter] = xmalloc (sizeof (TOC_ENTRY_ELT));
- if (html && splitting)
- {
- /* For split html: one node, one ref. */
- toc_entry_alist[toc_counter]->name = xstrdup (node_name);
- }
- else if (html)
+ if (html)
{
/* We need to insert the expanded node name into the TOC, so
that when we eventually output the TOC, its <A REF= link will
@@ -92,6 +88,13 @@ toc_add_entry (tocname, level, node_name
s = expanded_node = expand_node_name (node_name);
else
expanded_node = anchor;
+ if (splitting)
+ {
+ if (!anchor)
+ filename = nodename_to_filename (expanded_node);
+ else
+ filename = filename_part (current_output_filename);
+ }
/* Sigh... Need to HTML-escape the expanded node name like
add_anchor_name does, except that we are not writing this to
the output, so can't use add_anchor_name... */
@@ -142,6 +145,7 @@ toc_add_entry (tocname, level, node_name
toc_entry_alist[toc_counter]->containing_node = xstrdup (node_name);
toc_entry_alist[toc_counter]->level = level;
toc_entry_alist[toc_counter]->number = toc_counter;
+ toc_entry_alist[toc_counter]->html_file = filename;
/* have to be done at least */
return toc_counter++;
@@ -237,8 +241,10 @@ contents_update_html (fp)
}
/* No `Top' or double entries in toc. */
- if (strcasecmp (toc_entry_alist[i]->name, "Top") != 0
- && i
+ if (!(strncasecmp (toc_entry_alist[i]->name,
+ "Top", sizeof ("Top") - 1) == 0
+ && toc_entry_alist[i]->name[sizeof ("Top")] == '"')
+ && i
&& strcmp (toc_entry_alist[i]->name, toc_entry_alist[i-1]->name))
{
/* each toc entry is a list item. */
@@ -247,22 +253,24 @@ contents_update_html (fp)
/* For chapters (only), insert an anchor that the short contents
will link to. */
if (toc_entry_alist[i]->level == 0)
- fprintf (fp, "<a name=\"toc_%s\"></a>\n ",
- toc_entry_alist[i]->name);
-
- /* Insert link -- to an external file if splitting, or within the
- current document if not splitting. */
- if (splitting)
- {
- char *filename = nodename_to_filename (toc_entry_alist[i]->name);
- fprintf (fp, "<a href=\"%s\">", filename);
- free (filename);
- }
- else
- fprintf (fp, "<a href=\"#%s\">", toc_entry_alist[i]->name);
+ {
+ char *p = toc_entry_alist[i]->name;
- /* Insert text of link (always the node name), close the link. */
- fprintf (fp, "%s</a>\n", toc_entry_alist[i]->name);
+ /* toc_entry_alist[i]->name has the form `foo">bar',
+ that is, it includes both the node name and anchor
+ text. We need to find where `foo', the node name,
+ ends, and use that in toc_FOO. */
+ while (*p && *p != '"')
+ p++;
+ fprintf (fp, "<a name=\"toc_%.*s\"></a>\n ",
+ p - toc_entry_alist[i]->name, toc_entry_alist[i]->name);
+ }
+
+ /* Insert link -- to an external file if splitting, or
+ within the current document if not splitting. */
+ fprintf (fp, "<a href=\"%s#%s</a>\n",
+ splitting ? toc_entry_alist[i]->html_file : "",
+ toc_entry_alist[i]->name);
}
last_level = toc_entry_alist[i]->level;
@@ -314,25 +322,40 @@ shortcontents_update_html (fp)
FILE *fp;
{
int i;
+ char *toc_file;
/* does exist any toc? */
if (!toc_counter)
return;
-
+
flush_output (); /* in case we are writing stdout */
fprintf (fp, "\n<h2>%s</h2>\n<ul>\n", _("Short Contents"));
+ if (contents_filename)
+ toc_file = filename_part (contents_filename);
+
/* Omit first entry (and Top, in case it's somewhere other than first)
since we omit these from the main toc also. */
for (i = 1; i < toc_counter; i++)
{
char *name = toc_entry_alist[i]->name;
+
if (toc_entry_alist[i]->level == 0
- && strcasecmp (name, "Top") != 0)
- fprintf (fp, "<li><a href=\"#toc_%s\">%s</a>\n", name, name);
+ && !(strncasecmp (name, "Top", sizeof ("Top") - 1) == 0
+ && name[sizeof ("Top")] == '"'))
+ {
+ if (contents_filename)
+ fprintf (fp, "<li><a href=\"%s#toc_%s</a>\n",
+ splitting ? toc_file : "", name);
+ else
+ fprintf (fp, "<a href=\"%s#%s</a>\n",
+ splitting ? toc_entry_alist[i]->html_file : "", name);
+ }
}
fputs ("</ul>\n\n", fp);
+ if (contents_filename)
+ free (toc_file);
}
/* short contents in ASCII (--no-headers). */
--- makeinfo/sectioning.c~0 Sat Jan 19 03:09:12 2002
+++ makeinfo/sectioning.c Wed Jan 23 21:32:02 2002
@@ -419,10 +419,16 @@ sectioning_html (level, cmd)
the TOC could refer to. */
if (!current_node || !*current_node)
{
+ static const char a_name[] = "<a name=\"";
+
starting_pos = output_paragraph + output_paragraph_offset;
- add_word_args ("<a name=\"TOC%d\"></a>", toc_ref_count++);
- toc_anchor = substring (starting_pos + 9,
+ add_word_args ("%sTOC%d\">", a_name, toc_ref_count++);
+ toc_anchor = substring (starting_pos + sizeof (a_name) - 1,
output_paragraph + output_paragraph_offset);
+ /* This must be added after toc_anchor is extracted, since
+ toc_anchor cannot include the closing </a>. For details,
+ see toc.c:toc_add_entry and toc.c:contents_update_html. */
+ add_word ("</a>");
}
starting_pos = output_paragraph + output_paragraph_offset;
@@ -459,13 +465,13 @@ sectioning_html (level, cmd)
if (section_alist[index].toc == TOC_YES)
toc_add_entry (substring (starting_pos, ending_pos),
level, current_node, toc_anchor);
-
+
free (temp);
if (outstanding_node)
outstanding_node = 0;
- add_word_args ("</h%d>", level+1);
+ add_word_args ("</h%d>", level + 2);
close_paragraph();
filling_enabled = 1;
no_indent = old_no_indent;
--- makeinfo/cmds.c~0 Wed Sep 19 16:45:44 2001
+++ makeinfo/cmds.c Wed Jan 23 19:57:04 2002
@@ -301,7 +301,7 @@ COMMAND command_table[] = {
{ "subsection", cm_subsection, NO_BRACE_ARGS },
{ "subsubheading", cm_subsubheading, NO_BRACE_ARGS },
{ "subsubsection", cm_subsubsection, NO_BRACE_ARGS },
- { "summarycontents", cm_no_op, NO_BRACE_ARGS },
+ { "summarycontents", cm_shortcontents, NO_BRACE_ARGS },
{ "syncodeindex", cm_synindex, NO_BRACE_ARGS },
{ "synindex", cm_synindex, NO_BRACE_ARGS },
{ "t", cm_tt, BRACE_ARGS },