diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2006-01-08 18:08:19 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2006-01-08 18:08:19 +0000 |
commit | 5d1c62e95d4f7c4dacad95ff9ad3989996ae5daa (patch) | |
tree | be47fbfb0a73925ecf151942249d9763f54750d0 /gnu/usr.bin | |
parent | 0a218f216c6be05dad5f64603a26fa0955a36311 (diff) |
Allow @value in @include. Backported from texinfo 3.8.
ok deraadt@, krw@
Diffstat (limited to 'gnu/usr.bin')
-rw-r--r-- | gnu/usr.bin/texinfo/makeinfo/cmds.c | 374 |
1 files changed, 317 insertions, 57 deletions
diff --git a/gnu/usr.bin/texinfo/makeinfo/cmds.c b/gnu/usr.bin/texinfo/makeinfo/cmds.c index 740007bc8cf..70e7a770616 100644 --- a/gnu/usr.bin/texinfo/makeinfo/cmds.c +++ b/gnu/usr.bin/texinfo/makeinfo/cmds.c @@ -1,7 +1,7 @@ /* cmds.c -- Texinfo commands. - $Id: cmds.c,v 1.1 2000/02/09 01:25:09 espie Exp $ + $Id: cmds.c,v 1.2 2006/01/08 18:08:18 kettenis Exp $ - Copyright (C) 1998, 99 Free Software Foundation, Inc. + Copyright (C) 1998, 99, 2000, 01, 02 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 @@ -29,6 +29,7 @@ #include "node.h" #include "sectioning.h" #include "toc.h" +#include "xml.h" #ifdef TM_IN_SYS_TIME #include <sys/time.h> @@ -45,7 +46,9 @@ void cm_direntry (), cm_dmn (), cm_dots (), cm_emph (), cm_enddots (), cm_i (), cm_image (), cm_kbd (), cm_key (), cm_no_op (), cm_novalidate (), cm_not_fixed_width (), cm_r (), - cm_strong (), cm_var (), cm_sc (), cm_w (), cm_email (), cm_url (); + cm_strong (), cm_var (), cm_sc (), cm_w (), cm_email (), cm_url (), + cm_verb (), cm_copying (), cm_insert_copying (), + cm_documentdescription (); void cm_anchor (), cm_node (), cm_menu (), cm_xref (), cm_ftable (), @@ -61,7 +64,8 @@ void cm_defcodeindex (), cm_result (), cm_expansion (), cm_equiv (), cm_print (), cm_error (), cm_point (), cm_today (), cm_flushleft (), cm_flushright (), cm_finalout (), cm_cartouche (), cm_detailmenu (), - cm_multitable (), cm_settitle (), cm_titlefont (), cm_tt (); + cm_multitable (), cm_settitle (), cm_titlefont (), cm_tt (), + cm_verbatim (), cm_verbatiminclude (); /* Conditionals. */ void cm_set (), cm_clear (), cm_ifset (), cm_ifclear (); @@ -80,7 +84,7 @@ static const char small_tag[] = "small"; COMMAND command_table[] = { { "\t", insert_space, NO_BRACE_ARGS }, { "\n", insert_space, NO_BRACE_ARGS }, - { " ", insert_self, NO_BRACE_ARGS }, + { " ", insert_space, NO_BRACE_ARGS }, { "!", insert_self, NO_BRACE_ARGS }, { "\"", cm_accent_umlaut, MAYBE_BRACE_ARGS }, { "'", cm_accent_acute, MAYBE_BRACE_ARGS }, @@ -92,6 +96,7 @@ COMMAND command_table[] = { { "=", cm_accent, MAYBE_BRACE_ARGS }, { "?", insert_self, NO_BRACE_ARGS }, { "@", insert_self, NO_BRACE_ARGS }, + { "\\", insert_self, NO_BRACE_ARGS }, { "^", cm_accent_hat, MAYBE_BRACE_ARGS }, { "`", cm_accent_grave, MAYBE_BRACE_ARGS }, { "{", insert_self, NO_BRACE_ARGS }, @@ -108,7 +113,10 @@ COMMAND command_table[] = { { "aa", cm_special_char, BRACE_ARGS }, { "acronym", cm_acronym, BRACE_ARGS }, { "ae", cm_special_char, BRACE_ARGS }, + { "afivepaper", cm_ignore_line, NO_BRACE_ARGS }, + { "afourlatex", cm_ignore_line, NO_BRACE_ARGS }, { "afourpaper", cm_ignore_line, NO_BRACE_ARGS }, + { "afourwide", cm_ignore_line, NO_BRACE_ARGS }, { "alias", cm_alias, NO_BRACE_ARGS }, { "anchor", cm_anchor, BRACE_ARGS }, { "appendix", cm_appendix, NO_BRACE_ARGS }, @@ -133,6 +141,7 @@ COMMAND command_table[] = { { "command", cm_code, BRACE_ARGS }, { "comment", cm_ignore_line, NO_BRACE_ARGS }, { "contents", cm_contents, NO_BRACE_ARGS }, + { "copying", cm_copying, NO_BRACE_ARGS }, { "copyright", cm_copyright, BRACE_ARGS }, { "ctrl", cm_obsolete, BRACE_ARGS }, { "defcodeindex", cm_defcodeindex, NO_BRACE_ARGS }, @@ -182,6 +191,7 @@ COMMAND command_table[] = { { "direntry", cm_direntry, NO_BRACE_ARGS }, { "display", cm_display, NO_BRACE_ARGS }, { "dmn", cm_no_op, BRACE_ARGS }, + { "documentdescription", cm_documentdescription, NO_BRACE_ARGS }, { "documentencoding", cm_documentencoding, NO_BRACE_ARGS }, { "documentlanguage", cm_documentlanguage, NO_BRACE_ARGS }, { "dotaccent", cm_accent, MAYBE_BRACE_ARGS }, @@ -195,6 +205,10 @@ COMMAND command_table[] = { { "env", cm_code, BRACE_ARGS }, { "equiv", cm_equiv, BRACE_ARGS }, { "error", cm_error, BRACE_ARGS }, + { "evenfooting", cm_ignore_line, NO_BRACE_ARGS }, + { "evenheading", cm_ignore_line, NO_BRACE_ARGS }, + { "everyfooting", cm_ignore_line, NO_BRACE_ARGS }, + { "everyheading", cm_ignore_line, NO_BRACE_ARGS }, { "example", cm_example, NO_BRACE_ARGS }, { "exampleindent", cm_exampleindent, NO_BRACE_ARGS }, { "exclamdown", cm_special_char, BRACE_ARGS }, @@ -221,13 +235,16 @@ COMMAND command_table[] = { { "ifinfo", cm_ifinfo, NO_BRACE_ARGS }, { "ifnothtml", cm_ifnothtml, NO_BRACE_ARGS }, { "ifnotinfo", cm_ifnotinfo, NO_BRACE_ARGS }, + { "ifnotplaintext", cm_ifnotplaintext, NO_BRACE_ARGS }, { "ifnottex", cm_ifnottex, NO_BRACE_ARGS }, + { "ifplaintext", cm_ifplaintext, NO_BRACE_ARGS }, { "ifset", cm_ifset, NO_BRACE_ARGS }, { "iftex", cm_iftex, NO_BRACE_ARGS }, { "ignore", command_name_condition, NO_BRACE_ARGS }, { "image", cm_image, BRACE_ARGS }, { "include", cm_include, NO_BRACE_ARGS }, { "inforef", cm_inforef, BRACE_ARGS }, + { "insertcopying", cm_insert_copying, NO_BRACE_ARGS }, { "item", cm_item, NO_BRACE_ARGS }, { "itemize", cm_itemize, NO_BRACE_ARGS }, { "itemx", cm_itemx, NO_BRACE_ARGS }, @@ -250,6 +267,8 @@ COMMAND command_table[] = { { "noindent", cm_novalidate, NO_BRACE_ARGS }, { "nwnode", cm_node, NO_BRACE_ARGS }, { "o", cm_special_char, BRACE_ARGS }, + { "oddfooting", cm_ignore_line, NO_BRACE_ARGS }, + { "oddheading", cm_ignore_line, NO_BRACE_ARGS }, { "oe", cm_special_char, BRACE_ARGS }, { "option", cm_code, BRACE_ARGS }, { "page", cm_no_op, NO_BRACE_ARGS }, @@ -294,7 +313,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 }, @@ -320,6 +339,9 @@ COMMAND command_table[] = { { "v", cm_accent, MAYBE_BRACE_ARGS }, { "value", cm_value, BRACE_ARGS }, { "var", cm_var, BRACE_ARGS }, + { "verb", cm_verb, NO_BRACE_ARGS }, + { "verbatim", cm_verbatim, NO_BRACE_ARGS }, + { "verbatiminclude", cm_verbatiminclude, NO_BRACE_ARGS }, { "vindex", cm_vindex, NO_BRACE_ARGS }, { "vtable", cm_vtable, NO_BRACE_ARGS }, { "w", cm_w, BRACE_ARGS }, @@ -363,7 +385,12 @@ insert_space (arg) int arg; { if (arg == START) - add_char (' '); + { + if (xml && !docbook) + xml_insert_entity ("space"); + else + add_char (' '); + } } /* Force a line break in the output. */ @@ -372,6 +399,10 @@ cm_asterisk () { if (html) add_word ("<br>"); + else if (xml && !docbook) + xml_insert_entity ("linebreak"); + else if (docbook) + xml_asterisk (); else { close_single_paragraph (); @@ -385,7 +416,14 @@ cm_dots (arg) int arg; { if (arg == START) - add_word (html ? "<small>...</small>" : "..."); + { + if (xml && !docbook) + xml_insert_entity ("dots"); + else if (docbook) + xml_insert_entity ("hellip"); + else + add_word (html ? "<small>...</small>" : "..."); + } } /* Insert ellipsis for sentence end. */ @@ -394,7 +432,17 @@ cm_enddots (arg) int arg; { if (arg == START) - add_word (html ? "<small>...</small>." : "...."); + { + if (xml && !docbook) + xml_insert_entity ("enddots"); + else if (docbook) + { + xml_insert_entity ("hellip"); + add_char ('.'); + } + else + add_word (html ? "<small>...</small>." : "...."); + } } void @@ -405,6 +453,10 @@ cm_bullet (arg) { if (html) add_word ("•"); + else if (xml && !docbook) + xml_insert_entity ("bullet"); + else if (docbook) + xml_insert_entity ("bull"); else add_char ('*'); } @@ -415,7 +467,12 @@ cm_minus (arg) int arg; { if (arg == START) - add_char ('-'); + { + if (xml) + xml_insert_entity ("minus"); + else + add_char ('-'); + } } /* Insert "TeX". */ @@ -424,7 +481,12 @@ cm_TeX (arg) int arg; { if (arg == START) - add_word ("TeX"); + { + if (xml && ! docbook) + xml_insert_entity ("tex"); + else + add_word ("TeX"); + } } /* Copyright symbol. */ @@ -433,10 +495,16 @@ cm_copyright (arg) int arg; { if (arg == START) + { if (html) add_word ("©"); + else if (xml && !docbook) + xml_insert_entity ("copyright"); + else if (docbook) + xml_insert_entity ("copy"); else add_word ("(C)"); + } } void @@ -462,6 +530,8 @@ cm_acronym (arg) { if (html) insert_html_tag (arg, small_tag); + else if (xml) + xml_insert_element (ACRONYM, arg); } void @@ -471,12 +541,18 @@ cm_tt (arg) /* @t{} is a no-op in Info. */ if (html) insert_html_tag (arg, "tt"); + else if (xml) + xml_insert_element (TT, arg); } void cm_code (arg) int arg; { + if (xml) + xml_insert_element (CODE, arg); + else + { extern int printing_index; if (arg == START) @@ -495,13 +571,16 @@ cm_code (arg) if (!printing_index) add_meta_char ('\''); } + } } void cm_kbd (arg) int arg; { - if (html) + if (xml) + xml_insert_element (KBD, arg); + else if (html) { /* Seems like we should increment in_fixed_width_font for Info format too, but then the quote-omitting special case gets confused. Punt. */ @@ -520,7 +599,9 @@ cm_kbd (arg) void cm_url (arg, start, end) { - if (html) + if (xml) + xml_insert_element (URL, arg); + else if (html) { if (arg == START) add_word ("<<code>"); @@ -538,7 +619,9 @@ void cm_key (arg) int arg; { - if (html) + if (xml) + xml_insert_element (KEY, arg); + else if (html) add_word (arg == START ? "<" : ">"); else add_char (arg == START ? '<' : '>'); @@ -558,6 +641,10 @@ void cm_var (arg, start_pos, end_pos) int arg, start_pos, end_pos; { + if (xml) + xml_insert_element (VAR, arg); + else + { not_fixed_width (arg); if (html) @@ -573,12 +660,17 @@ cm_var (arg, start_pos, end_pos) start_pos++; } } + } } void cm_sc (arg, start_pos, end_pos) int arg, start_pos, end_pos; { + if (xml) + xml_insert_element (SC, arg); + else + { not_fixed_width (arg); if (arg == START) @@ -588,11 +680,15 @@ cm_sc (arg, start_pos, end_pos) } else { - int all_upper = 1; + int all_upper; if (html) start_pos += sizeof (small_tag) + 2 - 1; /* skip <small> */ + /* Avoid the warning below if there's no text inside @sc{}, or + when processing menus under --no-headers. */ + all_upper = start_pos < end_pos; + while (start_pos < end_pos) { unsigned char c = output_paragraph[start_pos]; @@ -607,35 +703,111 @@ cm_sc (arg, start_pos, end_pos) if (html) insert_html_tag (arg, small_tag); } + } } void cm_dfn (arg, position) int arg, position; { + if (xml) + xml_insert_element (DFN, arg); + else + { if (html) insert_html_tag (arg, "dfn"); else if (arg == START) add_char ('"'); else add_meta_char ('"'); + } } void cm_emph (arg) int arg; { - if (html) + if (xml) + xml_insert_element (EMPH, arg); + else if (html) insert_html_tag (arg, "em"); else add_char ('_'); } void +cm_verb (arg) + int arg; +{ + int character; + int delimiter; + int seen_end = 0; + + in_fixed_width_font++; + /* are these necessary ? */ + last_char_was_newline = 0; + + if (html) + add_word ("<pre>"); + + if (input_text_offset < input_text_length) + { + character = curchar (); + if (character == '{') + input_text_offset++; + else + line_error (_("`{' expected, but saw `%c'"), character); + } + + if (input_text_offset < input_text_length) + { + delimiter = curchar (); + input_text_offset++; + } + + while (input_text_offset < input_text_length) + { + character = curchar (); + + if (character == '\n') + line_number++; + /* + Assume no newlines in END_VERBATIM + */ + else if (character == delimiter) + { + seen_end = 1; + input_text_offset++; + break; + } + + add_char (character); + input_text_offset++; + } + + if (!seen_end) + warning (_("end of file inside verb block")); + + if (input_text_offset < input_text_length) + { + character = curchar (); + if (character == '}') + input_text_offset++; + else + line_error (_("`}' expected, but saw `%c'"), character); + } + + if (html) + add_word ("</pre>"); +} + +void cm_strong (arg, position) int arg, position; { - if (html) + if (xml) + xml_insert_element (STRONG, arg); + else if (html) insert_html_tag (arg, "strong"); else add_char ('*'); @@ -645,7 +817,9 @@ void cm_cite (arg, position) int arg, position; { - if (html) + if (xml) + xml_insert_element (CITE, arg); + else if (html) insert_html_tag (arg, "cite"); else { @@ -661,6 +835,8 @@ void cm_not_fixed_width (arg, start, end) int arg, start, end; { + if (xml) + xml_insert_element (NOTFIXEDWIDTH, arg); not_fixed_width (arg); } @@ -668,7 +844,9 @@ void cm_i (arg) int arg; { - if (html) + if (xml) + xml_insert_element (I, arg); + else if (html) insert_html_tag (arg, "i"); else not_fixed_width (arg); @@ -678,7 +856,9 @@ void cm_b (arg) int arg; { - if (html) + if (xml) + xml_insert_element (B, arg); + else if (html) insert_html_tag (arg, "b"); else not_fixed_width (arg); @@ -688,32 +868,40 @@ void cm_r (arg) int arg; { - extern int printing_index; - - /* People use @r{} in index entries like this: - - @findex foo@r{, some text} - - This is supposed to produce output as if the entry were saying - "@code{foo}, some text", since the "fn" index is typeset as - @code. The following attempts to do the same in HTML. Note that - this relies on the fact that only @code bumps up the variable - in_fixed_width_font while processing index entries in HTML mode. */ - if (html && printing_index) + if (xml) + xml_insert_element (R, arg); + else { - int level = in_fixed_width_font; + extern int printing_index; - while (level--) - insert_html_tag (arg == START ? END : START, "code"); + /* People use @r{} in index entries like this: + + @findex foo@r{, some text} + + This is supposed to produce output as if the entry were saying + "@code{foo}, some text", since the "fn" index is typeset as + @code. The following attempts to do the same in HTML. Note that + this relies on the fact that only @code bumps up the variable + in_fixed_width_font while processing index entries in HTML mode. */ + if (html && printing_index) + { + int level = in_fixed_width_font; + + while (level--) + insert_html_tag (arg == START ? END : START, "code"); + } + + not_fixed_width (arg); } - - not_fixed_width (arg); } void cm_titlefont (arg) int arg; { + if (xml) + xml_insert_element (TITLEFONT, arg); + else not_fixed_width (arg); } @@ -776,15 +964,27 @@ cm_setfilename () char *filename; get_rest_of_line (1, &filename); /* warning ("`@%s %s' encountered and ignored", command, filename); */ + if (xml) + add_word_args ("<setfilename>%s</setfilename>", filename); free (filename); } void cm_settitle () { - get_rest_of_line (0, &title); + if (xml) + { + xml_begin_document (current_output_filename); + xml_insert_element (SETTITLE, START); + get_rest_of_line (0, &title); + execute_string ("%s", title); + xml_insert_element (SETTITLE, END); + } + else + get_rest_of_line (0, &title); } + /* Ignore argument in braces. */ void cm_ignore_arg (arg, start_pos, end_pos) @@ -813,13 +1013,26 @@ cm_sp () if (sscanf (line, "%d", &lines) != 1 || lines <= 0) line_error (_("@sp requires a positive numeric argument, not `%s'"), line); else - { /* Must disable filling since otherwise multiple newlines is like + { + if (xml) + { + xml_insert_element_with_attribute (SP, START, "lines=\"%s\"", line); + /* insert_string (line);*/ + xml_insert_element (SP, END); + } + else + { + /* Must disable filling since otherwise multiple newlines is like multiple spaces. Must close paragraph since that's what the manual says and that's what TeX does. */ int save_filling_enabled = filling_enabled; filling_enabled = 0; - close_paragraph (); + /* close_paragraph generates an extra blank line. */ + close_single_paragraph (); + + if (lines && html && !executing_string) + html_output_head (); while (lines--) { @@ -831,6 +1044,7 @@ cm_sp () filling_enabled = save_filling_enabled; } + } free (line); } @@ -840,8 +1054,16 @@ cm_dircategory () { char *line; - if (html) + if (html || docbook) cm_ignore_line (); + else if (xml) + { + xml_insert_element (DIRCATEGORY, START); + get_rest_of_line (1, &line); + insert_string (line); + free (line); + xml_insert_element (DIRCATEGORY, END); + } else { get_rest_of_line (1, &line); @@ -860,23 +1082,33 @@ cm_dircategory () /* Start a new line with just this text on it. Then center the line of text. - This always ends the current paragraph. */ + */ void cm_center () { + if (xml) + { + unsigned char *line; + xml_insert_element (CENTER, START); + get_rest_of_line (0, (char **)&line); + execute_string ("%s", (char *)line); + free (line); + xml_insert_element (CENTER, END); + } + else + { int i, start, length; unsigned char *line; int save_indented_fill = indented_fill; int save_filling_enabled = filling_enabled; int fudge_factor = 1; - close_paragraph (); filling_enabled = indented_fill = 0; cm_noindent (); start = output_paragraph_offset; if (html) - add_word ("<p align=\"center\">"); + add_word ("<div align=\"center\">"); inhibit_output_flushing (); get_rest_of_line (0, (char **)&line); @@ -884,7 +1116,7 @@ cm_center () free (line); uninhibit_output_flushing (); if (html) - add_word ("</p>"); + add_word ("</div>"); else { @@ -914,9 +1146,9 @@ cm_center () } insert ('\n'); - close_paragraph (); filling_enabled = save_filling_enabled; indented_fill = save_indented_fill; + } } /* Show what an expression returns. */ @@ -1012,18 +1244,26 @@ cm_exdent () in_fixed_width_font = save_in_fixed_width_font; } - -/* Remember this file, and move onto the next. */ -void -cm_include () +/* + Read include-filename, process the include-file: + verbatim_include == 0: process through reader_loop + verbatim_include != 0: process through handle_verbatim_environment + */ +static void +handle_include (verbatim_include) + int verbatim_include; { - char *filename; + char *arg, *filename; if (macro_expansion_output_stream && !executing_string) me_append_before_this_command (); close_paragraph (); - get_rest_of_line (0, &filename); + get_rest_of_line (0, &arg); + /* We really only want to expand @value, but it's easier to just do + everything. TeX will only work with @value. */ + filename = text_expansion (arg); + free (arg); if (macro_expansion_output_stream && !executing_string) remember_itext (input_text, input_text_offset); @@ -1041,7 +1281,7 @@ cm_include () i *= 2; printf ("%*s", i, ""); - printf ("%c%s %s\n", COMMAND_PREFIX, command, filename); + printf ("%c%s `%s'\n", COMMAND_PREFIX, command, filename); fflush (stdout); } @@ -1052,8 +1292,8 @@ cm_include () popfile (); line_number--; - /* Cannot "@include foo", in line 5 of "/wh/bar". */ - line_error ("%c%s %s: %s", COMMAND_PREFIX, command, filename, + /* /wh/bar:5: @include/@verbatiminclude `foo': No such file or dir */ + line_error ("%c%s `%s': %s", COMMAND_PREFIX, command, filename, strerror (errno)); free (filename); @@ -1062,14 +1302,34 @@ cm_include () else { if (macro_expansion_output_stream && !executing_string) - remember_itext (input_text, input_text_offset); - reader_loop (); + remember_itext (input_text, input_text_offset); + + if (!verbatim_include) + reader_loop (); + else + handle_verbatim_environment (0); } free (filename); popfile (); } +/* Include file as if put in @verbatim environment */ +void +cm_verbatiminclude () +{ + handle_include (1); +} + + +/* Remember this file, and move onto the next. */ +void +cm_include () +{ + handle_include (0); +} + + /* @bye: Signals end of processing. Easy to make this happen. */ void |