diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2000-02-09 01:25:32 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2000-02-09 01:25:32 +0000 |
commit | ebbee3c6618ceac8d12b56ab40e3f116922beb30 (patch) | |
tree | 16c0d15a452c38565e22d8b248037c5eb1105c0c /gnu | |
parent | 15829855b2eaf8684369703e363adce128391dc0 (diff) |
TexInfo 4.0. New manpages, can create html.
A bit more grumpy about bad texinfo, though.
Diffstat (limited to 'gnu')
-rw-r--r-- | gnu/usr.bin/texinfo/makeinfo/sectioning.c | 440 |
1 files changed, 150 insertions, 290 deletions
diff --git a/gnu/usr.bin/texinfo/makeinfo/sectioning.c b/gnu/usr.bin/texinfo/makeinfo/sectioning.c index 4353b994bd8..160e283ae7c 100644 --- a/gnu/usr.bin/texinfo/makeinfo/sectioning.c +++ b/gnu/usr.bin/texinfo/makeinfo/sectioning.c @@ -1,7 +1,7 @@ -/* sectioning.c -- for @chapter, @section, ..., @contents ... - $Id: sectioning.c,v 1.1.1.3 2006/07/17 16:03:48 espie Exp $ +/* sectioning.c -- all related stuff @chapter, @section... @contents + $Id: sectioning.c,v 1.1 2000/02/09 01:25:31 espie Exp $ - Copyright (C) 1999, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. + Copyright (C) 1999 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 @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - Originally written by Karl Heinz Marbaise <kama@hippo.fido.de>. */ + Written by Karl Heinz Marbaise <kama@hippo.fido.de>. */ #include "system.h" #include "cmds.h" @@ -26,7 +26,6 @@ #include "node.h" #include "toc.h" #include "sectioning.h" -#include "xml.h" /* See comment in sectioning.h. */ section_alist_type section_alist[] = { @@ -34,7 +33,6 @@ section_alist_type section_alist[] = { { "unnumberedsubsec", 4, ENUM_SECT_NO, TOC_YES }, { "unnumberedsec", 3, ENUM_SECT_NO, TOC_YES }, { "unnumbered", 2, ENUM_SECT_NO, TOC_YES }, - { "centerchap", 2, ENUM_SECT_NO, TOC_YES }, { "appendixsubsubsec", 5, ENUM_SECT_APP, TOC_YES }, /* numbered like A.X.X.X */ { "appendixsubsec", 4, ENUM_SECT_APP, TOC_YES }, @@ -53,7 +51,7 @@ section_alist_type section_alist[] = { { "heading", 3, ENUM_SECT_NO, TOC_NO }, { "chapheading", 2, ENUM_SECT_NO, TOC_NO }, { "majorheading", 2, ENUM_SECT_NO, TOC_NO }, - + { "top", 1, ENUM_SECT_NO, TOC_YES }, { NULL, 0, 0, 0 } }; @@ -82,18 +80,14 @@ static char *scoring_characters = "*=-."; /* Amount to offset the name of sectioning commands to levels by. */ static int section_alist_offset = 0; -/* These two variables are for @float, @cindex like commands that need to know - in which section they are used. */ -/* Last value returned by get_sectioning_number. */ -static char *last_sectioning_number = ""; -/* Last title used by sectioning_underscore, etc. */ -static char *last_sectioning_title = ""; /* num == ENUM_SECT_NO means unnumbered (should never call this) num == ENUM_SECT_YES means numbered num == ENUM_SECT_APP means numbered like A.1 and so on */ -static char * -get_sectioning_number (int level, int num) +char * +get_sectioning_number (level, num) + int level; + int num; { static char s[100]; /* should ever be enough for 99.99.99.99 Appendix A.1 */ @@ -108,10 +102,10 @@ get_sectioning_number (int level, int num) { p = s + strlen (s); if ((i == 0) && (enum_marker == APPENDIX_MAGIC)) - sprintf (p, "%c.", numbers[i] + 64); /* Should be changed to + sprintf (p, "%c.", numbers[i] + 64); /* Should be changed to be more portable */ else - sprintf (p, "%d.", numbers[i]); + sprintf (p, "%d.", numbers[i]); } /* the last number is never followed by a dot */ @@ -119,14 +113,9 @@ get_sectioning_number (int level, int num) if ((num == ENUM_SECT_APP) && (i == 0) && (enum_marker == APPENDIX_MAGIC)) - sprintf (p, _("Appendix %c"), numbers[i] + 64); + sprintf (p, _("Appendix %c "), numbers[i] + 64); else - sprintf (p, "%d", numbers[i]); - - /* Poor man's cache :-) */ - if (strlen (last_sectioning_number)) - free (last_sectioning_number); - last_sectioning_number = xstrdup (s); + sprintf (p, "%d ", numbers[i]); return s; } @@ -134,7 +123,8 @@ get_sectioning_number (int level, int num) /* Set the level of @top to LEVEL. Return the old level of @top. */ int -set_top_section_level (int level) +set_top_section_level (level) + int level; { int i, result = -1; @@ -150,8 +140,9 @@ set_top_section_level (int level) /* return the index of the given sectioning command in section_alist */ -static int -search_sectioning (char *text) +int +search_sectioning (text) + char *text; { int i; char *t; @@ -159,7 +150,7 @@ search_sectioning (char *text) /* ignore the optional command prefix */ if (text[0] == COMMAND_PREFIX) text++; - + for (i = 0; (t = section_alist[i].name); i++) { if (strcmp (t, text) == 0) @@ -169,14 +160,11 @@ search_sectioning (char *text) } return -1; } - -/* Return an integer which identifies the type of section present in - TEXT -- 1 for @top, 2 for chapters, ..., 5 for subsubsections (as - specified in section_alist). We take into account any @lowersections - and @raisesections. If SECNAME is non-NULL, also return the - corresponding section name. */ + +/* Return an integer which identifies the type section present in TEXT. */ int -what_section (char *text, char **secname) +what_section (text) + char *text; { int index, j; char *temp; @@ -214,215 +202,96 @@ what_section (char *text, char **secname) { return_val = section_alist[index].level + section_alist_offset; if (return_val < 0) - return_val = 0; + return_val = 0; else if (return_val > 5) - return_val = 5; - - if (secname) - { - int i; - int alist_size = sizeof (section_alist) / sizeof(section_alist_type); - /* Find location of offset sectioning entry, but don't go off - either end of the array. */ - int index_offset = MAX (index - section_alist_offset, 0); - index_offset = MIN (index_offset, alist_size - 1); - - /* Also make sure we don't go into the next "group" of - sectioning changes, e.g., change from an @appendix to an - @heading or some such. */ -#define SIGN(expr) ((expr) < 0 ? -1 : 1) - for (i = index; i != index_offset; i -= SIGN (section_alist_offset)) - { - /* As it happens, each group has unique .num/.toc values. */ - if (section_alist[i].num != section_alist[index_offset].num - || section_alist[i].toc != section_alist[index_offset].toc) - break; - } - *secname = section_alist[i].name; - } + return_val = 5; return return_val; } return -1; } -/* Returns current top level division (ie. chapter, unnumbered) number. - - For chapters, returns the number. - - For unnumbered sections, returns empty string. - - For appendices, returns A, B, etc. */ -char * -current_chapter_number (void) -{ - if (enum_marker == UNNUMBERED_MAGIC) - return xstrdup (""); - else if (enum_marker == APPENDIX_MAGIC) - { - char s[1]; - sprintf (s, "%c", numbers[0] + 64); - return xstrdup (s); - } - else - { - char s[5]; - sprintf (s, "%d", numbers[0]); - return xstrdup (s); - } -} - -/* Returns number of the last sectioning command used. */ -char * -current_sectioning_number (void) -{ - if (enum_marker == UNNUMBERED_MAGIC || !number_sections) - return xstrdup (""); - else - return xstrdup (last_sectioning_number); -} - -/* Returns arguments of the last sectioning command used. */ -char * -current_sectioning_name (void) -{ - return xstrdup (last_sectioning_title); -} - -/* insert_and_underscore, sectioning_underscore and sectioning_html call this. */ - -static char * -handle_enum_increment (int level, int index) -{ - /* Here is how TeX handles enumeration: - - Anything starting with @unnumbered is not enumerated. - - @majorheading and the like are not enumberated. */ - int i; - - /* First constraint above. */ - if (enum_marker == UNNUMBERED_MAGIC && level == 0) - return xstrdup (""); - - /* Second constraint. */ - if (section_alist[index].num == ENUM_SECT_NO) - return xstrdup (""); - - /* reset all counters which are one level deeper */ - for (i = level; i < 3; i++) - numbers [i + 1] = 0; - - numbers[level]++; - if (section_alist[index].num == ENUM_SECT_NO || enum_marker == UNNUMBERED_MAGIC - || !number_sections) - return xstrdup (""); - else - return xstrdup (get_sectioning_number (level, section_alist[index].num)); -} - void -sectioning_underscore (char *cmd) +sectioning_underscore (cmd) + char *cmd; { - char *temp, *secname; + char character; + char *temp; int level; - - /* If we're not indenting the first paragraph, we shall make it behave - like @noindent is called directly after the section heading. */ - if (! do_first_par_indent) - cm_noindent (); temp = xmalloc (2 + strlen (cmd)); temp[0] = COMMAND_PREFIX; strcpy (&temp[1], cmd); - level = what_section (temp, &secname); + level = what_section (temp); + free (temp); level -= 2; + if (level < 0) level = 0; - free (temp); - /* If the argument to @top is empty, we try using the one from @settitle. - Warn if both are unusable. */ - if (STREQ (command, "top")) + if (html) + sectioning_html (level, cmd); + else { - int save_input_text_offset = input_text_offset; - - get_rest_of_line (0, &temp); - - /* Due to get_rest_of_line ... */ - line_number--; - - if (strlen (temp) == 0 && (!title || strlen (title) == 0)) - warning ("Must specify a title with least one of @settitle or @top"); - - input_text_offset = save_input_text_offset; + character = scoring_characters[level]; + insert_and_underscore (level, character, cmd); } +} - if (xml) +/* insert_and_underscore and sectioning_html are the + only functions which call this. + I have created this, because it was exactly the same + code in both functions. */ +static char * +handle_enum_increment (level, index) + int level; + int index; +{ + /* special for unnumbered */ + if (number_sections && section_alist[index].num == ENUM_SECT_NO) + { + if (level == 0 + && enum_marker != UNNUMBERED_MAGIC) + enum_marker = UNNUMBERED_MAGIC; + } + /* enumerate only things which are allowed */ + if (number_sections && section_alist[index].num) { - /* If the section appears in the toc, it means it's a real section - unlike majorheading, chapheading etc. */ - if (section_alist[search_sectioning (cmd)].toc == TOC_YES) + /* reset the marker if we get into enumerated areas */ + if (section_alist[index].num == ENUM_SECT_YES + && level == 0 + && enum_marker == UNNUMBERED_MAGIC) + enum_marker = 0; + /* This is special for appendix; if we got the first + time an appendix command then we are entering appendix. + Thats the point we have to start countint with A, B and so on. */ + if (section_alist[index].num == ENUM_SECT_APP + && level == 0 + && enum_marker != APPENDIX_MAGIC) { - xml_close_sections (level); - /* Mark the beginning of the section - If the next command is printindex, we will remove - the section and put an Index instead */ - flush_output (); - xml_last_section_output_position = output_paragraph_offset; - - get_rest_of_line (0, &temp); - - /* Use @settitle value if @top parameter is empty. */ - if (STREQ (command, "top") && strlen(temp) == 0) - temp = xstrdup (title ? title : ""); - - /* Docbook does not support @unnumbered at all. So we provide numbers - that other formats use. @appendix seems to be fine though, so we let - Docbook handle that as usual. */ - if (docbook && enum_marker != APPENDIX_MAGIC) - { - if (section_alist[search_sectioning (cmd)].num == ENUM_SECT_NO - && section_alist[search_sectioning (cmd)].toc == TOC_YES) - xml_insert_element_with_attribute (xml_element (secname), - START, "label=\"%s\" xreflabel=\"%s\"", - handle_enum_increment (level, search_sectioning (cmd)), - text_expansion (temp)); - else - xml_insert_element_with_attribute (xml_element (secname), - START, "label=\"%s\"", - handle_enum_increment (level, search_sectioning (cmd))); - } - else - xml_insert_element (xml_element (secname), START); - - xml_insert_element (TITLE, START); - xml_open_section (level, secname); - execute_string ("%s", temp); - xml_insert_element (TITLE, END); - - free (temp); + enum_marker = APPENDIX_MAGIC; + numbers [0] = 0; /* this means we start with Appendix A */ } - else - { - if (docbook) - { - if (level > 0) - xml_insert_element_with_attribute (xml_element (secname), START, - "renderas=\"sect%d\"", level); - else - xml_insert_element_with_attribute (xml_element (secname), START, - "renderas=\"other\""); - } - else - xml_insert_element (xml_element (secname), START); + + /* only increment counters if we are not in unnumbered + area. This handles situations like this: + @unnumbered .... This sets enum_marker to UNNUMBERED_MAGIC + @section .... */ + if (enum_marker != UNNUMBERED_MAGIC) + { + int i; - get_rest_of_line (0, &temp); - execute_string ("%s", temp); - free (temp); + /* reset all counters which are one level deeper */ + for (i = level; i < 3; i++) + numbers [i + 1] = 0; + + numbers[level]++; + return xstrdup + (get_sectioning_number (level, section_alist[index].num)); + } + } /* if (number_sections)... */ - xml_insert_element (xml_element (secname), END); - } - } - else if (html) - sectioning_html (level, secname); - else - insert_and_underscore (level, secname); + return xstrdup (""); } @@ -430,14 +299,16 @@ sectioning_underscore (char *cmd) in a new, separate paragraph. Directly underneath it, insert a line of WITH_CHAR, the same length of the inserted text. */ void -insert_and_underscore (int level, char *cmd) +insert_and_underscore (level, with_char, cmd) + int level; + int with_char; + char *cmd; { int i, len; int index; int old_no_indent; unsigned char *starting_pos, *ending_pos; char *temp; - char with_char = scoring_characters[level]; close_paragraph (); filling_enabled = indented_fill = 0; @@ -448,23 +319,13 @@ insert_and_underscore (int level, char *cmd) append_to_expansion_output (input_text_offset + 1); get_rest_of_line (0, &temp); - - /* Use @settitle value if @top parameter is empty. */ - if (STREQ (command, "top") && strlen(temp) == 0) - temp = xstrdup (title ? title : ""); - starting_pos = output_paragraph + output_paragraph_offset; - /* Poor man's cache for section title. */ - if (strlen (last_sectioning_title)) - free (last_sectioning_title); - last_sectioning_title = xstrdup (temp); - index = search_sectioning (cmd); if (index < 0) { /* should never happen, but a poor guy, named Murphy ... */ - warning (_("Internal error (search_sectioning) `%s'!"), cmd); + warning (_("Internal error (search_sectioning) \"%s\"!"), cmd); return; } @@ -473,7 +334,7 @@ insert_and_underscore (int level, char *cmd) output. */ /* Step 1: produce "X.Y" and add it to Info output. */ - add_word_args ("%s ", handle_enum_increment (level, index)); + add_word (handle_enum_increment (level, index)); /* Step 2: add "SECTION-NAME" to both Info and macro-expanded output. */ if (macro_expansion_output_stream && !executing_string) @@ -508,9 +369,10 @@ insert_and_underscore (int level, char *cmd) /* Insert the text following input_text_offset up to the end of the line as an HTML heading element of the appropriate `level' and tagged as an anchor for the current node.. */ - void -sectioning_html (int level, char *cmd) +sectioning_html (level, cmd) + int level; + char *cmd; { static int toc_ref_count = 0; int index; @@ -523,26 +385,16 @@ sectioning_html (int level, char *cmd) old_no_indent = no_indent; no_indent = 1; - /* level 0 (chapter) is <h2>, and we go down from there. */ - add_html_block_elt_args ("<h%d class=\"%s\">", level + 2, cmd); + add_word_args ("<h%d>", level + 1); /* level 0 is <h1> */ /* If we are outside of any node, produce an anchor that 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 ("%sTOC%d\">", a_name, toc_ref_count++); - toc_anchor = substring (starting_pos + sizeof (a_name) - 1, + add_word_args ("<a name=\"TOC%d\">", toc_ref_count++); + toc_anchor = substring (starting_pos + 9, 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. - - Also, the anchor close must be output before the section name - in case the name itself contains an anchor. */ - add_word ("</a>"); } starting_pos = output_paragraph + output_paragraph_offset; @@ -551,10 +403,6 @@ sectioning_html (int level, char *cmd) get_rest_of_line (0, &temp); - /* Use @settitle value if @top parameter is empty. */ - if (STREQ (command, "top") && strlen(temp) == 0) - temp = xstrdup (title ? title : ""); - index = search_sectioning (cmd); if (index < 0) { @@ -564,11 +412,7 @@ sectioning_html (int level, char *cmd) } /* Produce "X.Y" and add it to HTML output. */ - { - char *title_number = handle_enum_increment (level, index); - if (strlen (title_number) > 0) - add_word_args ("%s ", title_number); - } + add_word (handle_enum_increment (level, index)); /* add the section name to both HTML and macro-expanded output. */ if (macro_expansion_output_stream && !executing_string) @@ -587,13 +431,13 @@ sectioning_html (int level, char *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 + 2); + add_word_args ("</h%d>", level+1); close_paragraph(); filling_enabled = 1; no_indent = old_no_indent; @@ -602,7 +446,7 @@ sectioning_html (int level, char *cmd) /* Shift the meaning of @section to @chapter. */ void -cm_raisesections (void) +cm_raisesections () { discard_until ("\n"); section_alist_offset--; @@ -610,7 +454,7 @@ cm_raisesections (void) /* Shift the meaning of @chapter to @section. */ void -cm_lowersections (void) +cm_lowersections () { discard_until ("\n"); section_alist_offset++; @@ -618,7 +462,8 @@ cm_lowersections (void) /* The command still works, but prints a warning message in addition. */ void -cm_ideprecated (int arg, int start, int end) +cm_ideprecated (arg, start, end) + int arg, start, end; { warning (_("%c%s is obsolete; use %c%s instead"), COMMAND_PREFIX, command, COMMAND_PREFIX, command + 1); @@ -629,7 +474,7 @@ cm_ideprecated (int arg, int start, int end) /* Treat this just like @unnumbered. The only difference is in node defaulting. */ void -cm_top (void) +cm_top () { /* It is an error to have more than one @top. */ if (top_node_seen && strcmp (current_node, "Top") != 0) @@ -643,8 +488,14 @@ cm_top (void) { if (tag->flags & TAG_FLAG_IS_TOP) { - file_line_error (tag->filename, tag->line_no, - _("Here is the %ctop node"), COMMAND_PREFIX); + int old_line_number = line_number; + char *old_input_filename = input_filename; + + line_number = tag->line_no; + input_filename = tag->filename; + line_error (_("Here is the %ctop node"), COMMAND_PREFIX); + input_filename = old_input_filename; + line_number = old_line_number; return; } tag = tag->next_ent; @@ -652,9 +503,10 @@ cm_top (void) } else { + TAG_ENTRY *top_node = find_node ("Top"); top_node_seen = 1; - /* It is an error to use @top before using @node. */ + /* It is an error to use @top before you have used @node. */ if (!tag_table) { char *top_name; @@ -666,6 +518,21 @@ cm_top (void) free (top_name); return; } + else if (html && splitting) + { + char *next = top_node ? top_node->next : NULL; + + add_word ("<p>"); + if (next) + { + add_word (_("Next:")); + add_word ("<a rel=next href=\""); + add_anchor_name (next, 1); + add_word ("\">"); + execute_string (next); + add_word ("</a>\n"); + } + } cm_unnumbered (); @@ -693,8 +560,7 @@ cm_top (void) if (input_text_offset < input_text_length) input_text_offset++; - this_section = what_section (input_text + input_text_offset, - NULL); + this_section = what_section (input_text + input_text_offset); /* If we found a sectioning command, then give the top section a level of this section - 1. */ @@ -708,44 +574,42 @@ cm_top (void) /* The remainder of the text on this line is a chapter heading. */ void -cm_chapter (void) +cm_chapter () { - enum_marker = 0; sectioning_underscore ("chapter"); } /* The remainder of the text on this line is a section heading. */ void -cm_section (void) +cm_section () { sectioning_underscore ("section"); } /* The remainder of the text on this line is a subsection heading. */ void -cm_subsection (void) +cm_subsection () { sectioning_underscore ("subsection"); } /* The remainder of the text on this line is a subsubsection heading. */ void -cm_subsubsection (void) +cm_subsubsection () { sectioning_underscore ("subsubsection"); } /* The remainder of the text on this line is an unnumbered heading. */ void -cm_unnumbered (void) +cm_unnumbered () { - enum_marker = UNNUMBERED_MAGIC; sectioning_underscore ("unnumbered"); } /* The remainder of the text on this line is an unnumbered section heading. */ void -cm_unnumberedsec (void) +cm_unnumberedsec () { sectioning_underscore ("unnumberedsec"); } @@ -753,7 +617,7 @@ cm_unnumberedsec (void) /* The remainder of the text on this line is an unnumbered subsection heading. */ void -cm_unnumberedsubsec (void) +cm_unnumberedsubsec () { sectioning_underscore ("unnumberedsubsec"); } @@ -761,32 +625,28 @@ cm_unnumberedsubsec (void) /* The remainder of the text on this line is an unnumbered subsubsection heading. */ void -cm_unnumberedsubsubsec (void) +cm_unnumberedsubsubsec () { sectioning_underscore ("unnumberedsubsubsec"); } /* The remainder of the text on this line is an appendix heading. */ void -cm_appendix (void) +cm_appendix () { - /* Reset top level number so we start from Appendix A */ - if (enum_marker != APPENDIX_MAGIC) - numbers [0] = 0; - enum_marker = APPENDIX_MAGIC; sectioning_underscore ("appendix"); } /* The remainder of the text on this line is an appendix section heading. */ void -cm_appendixsec (void) +cm_appendixsec () { sectioning_underscore ("appendixsec"); } /* The remainder of the text on this line is an appendix subsection heading. */ void -cm_appendixsubsec (void) +cm_appendixsubsec () { sectioning_underscore ("appendixsubsec"); } @@ -794,38 +654,38 @@ cm_appendixsubsec (void) /* The remainder of the text on this line is an appendix subsubsection heading. */ void -cm_appendixsubsubsec (void) +cm_appendixsubsubsec () { sectioning_underscore ("appendixsubsubsec"); } /* Compatibility functions substitute for chapter, section, etc. */ void -cm_majorheading (void) +cm_majorheading () { sectioning_underscore ("majorheading"); } void -cm_chapheading (void) +cm_chapheading () { sectioning_underscore ("chapheading"); } void -cm_heading (void) +cm_heading () { sectioning_underscore ("heading"); } void -cm_subheading (void) +cm_subheading () { sectioning_underscore ("subheading"); } void -cm_subsubheading (void) +cm_subsubheading () { sectioning_underscore ("subsubheading"); } |