1 /* insertion.c -- insertions for Texinfo.
2 $Id: insertion.c,v 1.71 2008/04/09 17:31:10 karl Exp $
4 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
5 2007, 2008 Free Software Foundation, Inc.
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 #include "insertion.h"
31 /* Must match list in insertion.h. */
32 static char *insertion_type_names[] =
34 "cartouche", "copying", "defcv", "deffn", "defivar", "defmac",
35 "defmethod", "defop", "defopt", "defspec", "deftp", "deftypecv",
36 "deftypefn", "deftypefun", "deftypeivar", "deftypemethod",
37 "deftypeop", "deftypevar", "deftypevr", "defun", "defvar", "defvr",
38 "detailmenu", "direntry", "display", "documentdescription",
39 "enumerate", "example", "float", "flushleft", "flushright", "format",
40 "ftable", "group", "ifclear", "ifdocbook", "ifhtml", "ifinfo",
41 "ifnotdocbook", "ifnothtml", "ifnotinfo", "ifnotplaintext", "ifnottex",
42 "ifnotxml", "ifplaintext", "ifset", "iftex", "ifxml", "itemize", "lisp",
43 "menu", "multitable", "quotation", "rawdocbook", "rawhtml", "rawtex",
44 "rawxml", "smalldisplay", "smallexample", "smallformat", "smalllisp",
45 "verbatim", "table", "tex", "vtable", "titlepage", "bad_type"
48 /* All nested environments. */
49 INSERTION_ELT *insertion_stack = NULL;
51 /* How deeply we're nested. */
52 int insertion_level = 0;
54 /* Set to 1 if we've processed (commentary) text in a @menu that
55 wasn't part of a menu item. */
56 int had_menu_commentary;
58 /* How to examine menu lines. */
59 int in_detailmenu = 0;
61 /* Whether to examine menu lines. */
64 /* Set to 1 if <p> is written in normal context.
65 Used for menu and itemize. */
68 /* Since an insertion is already in the stack before we reach the switch
69 statement, we cannot use is_in_insertion_of_type (always returns true.) Also
70 making it return the level found, and comparing it with the current level is
71 no use, due to the order of stack. */
72 static int float_active = 0;
74 /* Unsetting escape_html blindly causes text inside @html/etc. to be escaped if
75 used within a rmacro. */
76 static int raw_output_block = 0;
78 /* Non-zero if a <dl> element has a <dt> element in it. We use this when
79 deciding whether to insert a <br> or not. */
80 static int html_deflist_has_term = 0;
82 const char default_item_function[] = { "@bullet" };
85 init_insertion_stack (void)
87 insertion_stack = NULL;
90 /* Return the type of the current insertion. */
91 static enum insertion_type
92 current_insertion_type (void)
94 return insertion_level ? insertion_stack->insertion : bad_type;
97 /* Return the string which is the function to wrap around items, or NULL
98 if we're not in an environment where @item is ok. */
100 current_item_function (void)
103 INSERTION_ELT *elt = insertion_stack;
105 /* Skip down through the stack until we find an insertion with an
106 itemize function defined, i.e., skip conditionals, @cartouche, etc. */
109 switch (elt->insertion)
111 /* This list should match the one in cm_item. */
138 /* item_function usually gets assigned the empty string. */
139 return done && (*elt->item_function) ? elt->item_function : NULL;
142 /* Parse the item marker function off the input. If result is just "@",
143 change it to "@ ", since "@" by itself is not a command. This makes
144 "@ ", "@\t", and "@\n" all the same, but their default meanings are
145 the same anyway, and let's not worry about supporting redefining them. */
147 get_item_function (void)
152 get_rest_of_line (0, &item_function);
154 /* If the document erroneously says
155 @itemize @bullet @item foobar
156 it's nicer to give an error up front than repeat `@bullet expected
157 braces' until we get a segmentation fault. */
158 item_loc = strstr (item_function, "@item");
161 line_error (_("@item not allowed in argument to @itemize"));
165 /* If we hit the end of text in get_rest_of_line, backing up
166 input pointer will cause the last character of the last line
167 be pushed back onto the input, which is wrong. */
168 if (input_text_offset < input_text_length)
169 backup_input_pointer ();
171 if (STREQ (item_function, "@"))
173 free (item_function);
174 item_function = xstrdup ("@ ");
177 return item_function;
180 /* Push the state of the current insertion on the stack. */
182 push_insertion (enum insertion_type type, char *item_function)
184 INSERTION_ELT *new = xmalloc (sizeof (INSERTION_ELT));
186 new->item_function = item_function;
187 new->filling_enabled = filling_enabled;
188 new->indented_fill = indented_fill;
189 new->insertion = type;
190 new->line_number = line_number;
191 new->filename = xstrdup (input_filename);
192 new->inhibited = inhibit_paragraph_indentation;
193 new->in_fixed_width_font = in_fixed_width_font;
194 new->next = insertion_stack;
195 insertion_stack = new;
199 /* Pop the value on top of the insertion stack into the
204 INSERTION_ELT *temp = insertion_stack;
209 in_fixed_width_font = temp->in_fixed_width_font;
210 inhibit_paragraph_indentation = temp->inhibited;
211 filling_enabled = temp->filling_enabled;
212 indented_fill = temp->indented_fill;
213 if (temp->item_function == default_item_function)
214 temp->item_function = NULL;
216 free_and_clear (&(temp->item_function));
217 free_and_clear (&(temp->filename));
218 insertion_stack = insertion_stack->next;
223 /* Return a pointer to the print name of this
226 insertion_type_pname (enum insertion_type type)
228 if ((int) type < (int) bad_type)
230 if (type == rawdocbook)
232 else if (type == rawhtml)
234 else if (type == rawxml)
236 else if (type == rawtex)
239 return insertion_type_names[(int) type];
242 return _("Broken-Type in insertion_type_pname");
245 /* Return the insertion_type associated with NAME.
246 If the type is not one of the known ones, return BAD_TYPE. */
248 find_type_from_name (char *name)
251 while (index < (int) bad_type)
253 if (STREQ (name, insertion_type_names[index]))
254 return (enum insertion_type) index;
255 if (index == rawdocbook && STREQ (name, "docbook"))
257 if (index == rawhtml && STREQ (name, "html"))
259 if (index == rawxml && STREQ (name, "xml"))
261 if (index == rawtex && STREQ (name, "tex"))
268 /* Simple function to query insertion_stack to see if we are inside a given
271 is_in_insertion_of_type (int type)
273 INSERTION_ELT *temp = insertion_stack;
275 if (!insertion_level)
280 if (temp->insertion == type)
290 defun_insertion (enum insertion_type type)
297 || (type == defmethod)
302 || (type == deftypecv)
303 || (type == deftypefn)
304 || (type == deftypefun)
305 || (type == deftypeivar)
306 || (type == deftypemethod)
307 || (type == deftypeop)
308 || (type == deftypevar)
309 || (type == deftypevr)
316 /* MAX_NS is the maximum nesting level for enumerations. I picked 100
317 which seemed reasonable. This doesn't control the number of items,
318 just the number of nested lists. */
319 #define max_stack_depth 100
320 #define ENUM_DIGITS 1
327 DIGIT_ALPHA enumstack[max_stack_depth];
328 int enumstack_offset = 0;
329 int current_enumval = 1;
330 int current_enumtype = ENUM_DIGITS;
331 char *enumeration_arg = NULL;
334 start_enumerating (int at, int type)
336 if ((enumstack_offset + 1) == max_stack_depth)
338 line_error (_("Enumeration stack overflow"));
341 enumstack[enumstack_offset].enumtype = current_enumtype;
342 enumstack[enumstack_offset].enumval = current_enumval;
344 current_enumval = at;
345 current_enumtype = type;
349 stop_enumerating (void)
352 if (enumstack_offset < 0)
353 enumstack_offset = 0;
355 current_enumval = enumstack[enumstack_offset].enumval;
356 current_enumtype = enumstack[enumstack_offset].enumtype;
359 /* Place a letter or digits into the output stream. */
361 enumerate_item (void)
365 if (current_enumtype == ENUM_ALPHA)
367 if (current_enumval == ('z' + 1) || current_enumval == ('Z' + 1))
369 current_enumval = ((current_enumval - 1) == 'z' ? 'a' : 'A');
370 warning (_("lettering overflow, restarting at %c"), current_enumval);
372 sprintf (temp, "%c. ", current_enumval);
375 sprintf (temp, "%d. ", current_enumval);
377 indent (current_output_column () + (current_indent - strlen (temp)));
388 if (isdigit (*enumeration_arg))
391 start = atoi (enumeration_arg);
393 else if (isupper (*enumeration_arg))
396 start = *enumeration_arg - 'A' + 1;
401 start = *enumeration_arg - 'a' + 1;
404 add_html_block_elt_args ("<ol type=%c start=%d>\n", type, start);
407 /* Conditionally parse based on the current command name. */
409 command_name_condition (void)
411 char *discarder = xmalloc (8 + strlen (command));
413 sprintf (discarder, "\n%cend %s", COMMAND_PREFIX, command);
414 discard_until (discarder);
415 discard_until ("\n");
420 /* This is where the work for all the "insertion" style
421 commands is done. A huge switch statement handles the
422 various setups, and generic code is on both sides. */
424 begin_insertion (enum insertion_type type)
428 if (defun_insertion (type))
430 push_insertion (type, xstrdup (""));
435 push_insertion (type, get_item_function ());
444 filling_enabled = no_indent = 0;
445 inhibit_paragraph_indentation = 1;
449 had_menu_commentary = 1;
451 else if (!no_headers && !xml)
452 add_word ("* Menu:\n");
455 xml_insert_element (MENU, START);
457 in_fixed_width_font++;
459 next_menu_item_number = 1;
470 filling_enabled = no_indent = 0;
471 inhibit_paragraph_indentation = 1;
478 xml_insert_element (DETAILMENU, START);
479 skip_whitespace_and_newlines ();
482 in_fixed_width_font++;
488 close_single_paragraph ();
489 filling_enabled = no_indent = 0;
490 inhibit_paragraph_indentation = 1;
491 add_word ("START-INFO-DIR-ENTRY\n");
493 /* The zsh manual, maybe others, wrongly indents the * line of the
494 direntry in the source. Ignore that whitespace. */
495 skip_whitespace_and_newlines ();
499 case documentdescription:
503 int save_fixed_width;
505 discard_until ("\n"); /* ignore the @documentdescription line */
506 start_of_end = get_until ("\n@end documentdescription", &desc);
507 save_fixed_width = in_fixed_width_font;
509 in_fixed_width_font = 0;
510 document_description = expansion (desc, 0);
513 in_fixed_width_font = save_fixed_width;
514 input_text_offset = start_of_end; /* go back to the @end to match */
519 /* Save the copying text away for @insertcopying,
520 typically used on the back of the @titlepage (for TeX) and
521 the Top node (for info/html). */
522 if (input_text[input_text_offset] != '\n')
523 discard_until ("\n"); /* ignore remainder of @copying line */
525 input_text_offset = get_until ("\n@end copying", ©ing_text);
526 canon_white (copying_text);
528 /* For info, output the copying text right away, so it will end up
529 in the header of the Info file, before the first node, and thus
530 get copied automatically to all the split files. For xml, also
531 output it right away since xml output is never split.
532 For html, we output it specifically in html_output_head.
533 For plain text, there's no way to hide it, so the author must
534 use @insertcopying in the desired location. */
537 if (!xml_in_bookinfo)
539 xml_insert_element (BOOKINFO, START);
542 xml_insert_element (LEGALNOTICE, START);
545 if (!html && !no_headers)
546 cm_insert_copying ();
549 xml_insert_element (LEGALNOTICE, END);
553 /* @quotation does filling (@display doesn't). */
555 add_html_block_elt ("<blockquote>\n");
558 /* with close_single_paragraph, we get no blank line above
561 last_char_was_newline = no_indent = 0;
562 indented_fill = filling_enabled = 1;
563 inhibit_paragraph_indentation = 1;
564 current_indent += default_indentation_increment;
567 xml_insert_quotation (insertion_stack->item_function, START);
568 else if (strlen(insertion_stack->item_function))
569 execute_string ("@b{%s:} ", insertion_stack->item_function);
576 in_fixed_width_font++;
579 /* Like @example but no fixed width font. */
582 /* Like @display but without indentation. */
585 close_single_paragraph ();
586 inhibit_paragraph_indentation = 1;
588 last_char_was_newline = 0;
591 /* Kludge alert: if <pre> is followed by a newline, IE3,
592 mozilla, maybe others render an extra blank line before the
593 pre-formatted block. So don't output a newline. */
594 add_html_block_elt_args ("<pre class=\"%s\">", command);
596 if (type != format && type != smallformat)
598 current_indent += example_indentation_increment;
601 /* Since we didn't put \n after <pre>, we need to insert
602 the indentation by hand. */
604 for (i = current_indent; i > 0; i--)
618 close_single_paragraph ();
619 current_indent += default_indentation_increment;
620 filling_enabled = indented_fill = 1;
621 #if defined (INDENT_PARAGRAPHS_IN_TABLE)
622 inhibit_paragraph_indentation = 0;
624 inhibit_paragraph_indentation = 1;
625 #endif /* !INDENT_PARAGRAPHS_IN_TABLE */
627 /* Make things work for losers who forget the itemize syntax. */
630 if (!(*insertion_stack->item_function))
632 free (insertion_stack->item_function);
633 insertion_stack->item_function = (char *) default_item_function;
637 if (!*insertion_stack->item_function)
639 line_error (_("%s requires an argument: the formatter for %citem"),
640 insertion_type_pname (type), COMMAND_PREFIX);
647 add_html_block_elt ("<ul>\n");
651 { /* We are just starting, so this <dl>
652 has no <dt> children yet. */
653 html_deflist_has_term = 0;
654 add_html_block_elt ("<dl>\n");
658 xml_begin_table (type, insertion_stack->item_function);
660 while (input_text[input_text_offset] == '\n'
661 && input_text[input_text_offset+1] == '\n')
670 close_single_paragraph ();
672 #if defined (INDENT_PARAGRAPHS_IN_TABLE)
673 inhibit_paragraph_indentation = 0;
675 inhibit_paragraph_indentation = 1;
676 #endif /* !INDENT_PARAGRAPHS_IN_TABLE */
678 current_indent += default_indentation_increment;
679 filling_enabled = indented_fill = 1;
688 xml_begin_enumerate (enumeration_arg);
690 if (isdigit (*enumeration_arg))
691 start_enumerating (atoi (enumeration_arg), ENUM_DIGITS);
693 start_enumerating (*enumeration_arg, ENUM_ALPHA);
696 /* @group produces no output in info. */
698 /* Only close the paragraph if we are not inside of an
699 @example-like environment. */
701 xml_insert_element (GROUP, START);
702 else if (!insertion_stack->next
703 || (insertion_stack->next->insertion != display
704 && insertion_stack->next->insertion != smalldisplay
705 && insertion_stack->next->insertion != example
706 && insertion_stack->next->insertion != smallexample
707 && insertion_stack->next->insertion != lisp
708 && insertion_stack->next->insertion != smalllisp
709 && insertion_stack->next->insertion != format
710 && insertion_stack->next->insertion != smallformat
711 && insertion_stack->next->insertion != flushleft
712 && insertion_stack->next->insertion != flushright))
713 close_single_paragraph ();
718 add_html_block_elt ("<p><table class=\"cartouche\" summary=\"cartouche\" border=\"1\"><tr><td>\n");
724 /* Cannot nest floats, so complain. */
727 line_error (_("%cfloat environments cannot be nested"), COMMAND_PREFIX);
734 { /* Collect data about this float. */
735 /* Example: @float [FLOATTYPE][,XREFLABEL][,POSITION] */
736 char floattype[200] = "";
737 char xreflabel[200] = "";
738 char position[200] = "";
743 int save_line_number = line_number;
744 int save_input_text_offset = input_text_offset;
747 if (strlen (insertion_stack->item_function) > 0)
749 int i = 0, t = 0, c = 0;
750 while (insertion_stack->item_function[i])
752 if (insertion_stack->item_function[i] == ',')
775 floattype[c] = insertion_stack->item_function[i];
778 xreflabel[c] = insertion_stack->item_function[i];
781 position[c] = insertion_stack->item_function[i];
789 skip_whitespace_and_newlines ();
791 start_of_end = get_until ("\n@end float", &text);
793 /* Get also the @caption. */
794 i = search_forward_until_pos ("\n@caption{",
795 save_input_text_offset, start_of_end);
798 input_text_offset = i + sizeof ("\n@caption{") - 1;
799 get_until_in_braces ("\n@end float", &caption);
800 input_text_offset = save_input_text_offset;
805 /* ... and the @shortcaption. */
806 i = search_forward_until_pos ("\n@shortcaption{",
807 save_input_text_offset, start_of_end);
810 input_text_offset = i + sizeof ("\n@shortcaption{") - 1;
811 get_until_in_braces ("\n@end float", &shortcaption);
812 input_text_offset = save_input_text_offset;
817 canon_white (xreflabel);
818 canon_white (floattype);
819 canon_white (position);
820 canon_white (caption);
821 canon_white (shortcaption);
823 add_new_float (xstrdup (xreflabel),
824 xstrdup (caption), xstrdup (shortcaption),
825 xstrdup (floattype), xstrdup (position));
827 /* Move to the start of the @float so the contents get processed as
829 input_text_offset = save_input_text_offset;
830 line_number = save_line_number;
834 add_html_block_elt ("<div class=\"float\">\n");
836 xml_insert_element (FLOAT, START);
839 xml_insert_element_with_attribute (FLOAT, START,
840 "name=\"%s\"", current_float_id ());
842 xml_insert_element (FLOATTYPE, START);
843 execute_string ("%s", current_float_type ());
844 xml_insert_element (FLOATTYPE, END);
846 xml_insert_element (FLOATPOS, START);
847 execute_string ("%s", current_float_position ());
848 xml_insert_element (FLOATPOS, END);
852 close_single_paragraph ();
853 inhibit_paragraph_indentation = 1;
856 /* Anchor now. Note that XML documents get their
857 anchors with <float name="anchor"> tag. */
858 if ((!xml || docbook) && strlen (current_float_id ()) > 0)
859 execute_string ("@anchor{%s}", current_float_id ());
863 /* Insertions that are no-ops in info, but do something in TeX. */
888 if (raw_output_block > 0)
896 /* Some deuglification for improved readability. */
897 extern int xml_in_para;
898 if (xml && !xml_in_para && xml_indentation_increment > 0)
924 inhibit_paragraph_indentation = 1;
925 filling_enabled = indented_fill = 1;
926 current_indent += default_indentation_increment;
929 xml_begin_definition ();
933 close_single_paragraph ();
934 inhibit_paragraph_indentation = 1;
935 filling_enabled = indented_fill = no_indent = 0;
937 add_html_block_elt ("<div align=\"left\">");
941 close_single_paragraph ();
942 filling_enabled = indented_fill = no_indent = 0;
943 inhibit_paragraph_indentation = 1;
946 add_html_block_elt ("<div align=\"right\">");
950 xml_insert_element (TITLEPAGE, START);
954 line_error ("begin_insertion internal error: type=%d", type);
958 discard_until ("\n");
961 /* Try to end the insertion with the specified TYPE. With a value of
962 `bad_type', TYPE gets translated to match the value currently on top
963 of the stack. Otherwise, if TYPE doesn't match the top of the
964 insertion stack, give error. */
966 end_insertion (enum insertion_type type)
968 enum insertion_type temp_type;
970 if (!insertion_level)
973 temp_type = current_insertion_type ();
975 if (type == bad_type)
978 if (type != temp_type)
981 (_("`@end' expected `%s', but saw `%s'"),
982 insertion_type_pname (temp_type), insertion_type_pname (type));
993 case documentdescription:
996 xml_insert_quotation ("", END);
999 xml_insert_element (EXAMPLE, END);
1000 if (docbook && current_insertion_type () == floatenv)
1001 xml_insert_element (FLOATEXAMPLE, END);
1004 xml_insert_element (SMALLEXAMPLE, END);
1005 if (docbook && current_insertion_type () == floatenv)
1006 xml_insert_element (FLOATEXAMPLE, END);
1009 xml_insert_element (LISP, END);
1010 if (docbook && current_insertion_type () == floatenv)
1011 xml_insert_element (FLOATEXAMPLE, END);
1014 xml_insert_element (SMALLLISP, END);
1015 if (docbook && current_insertion_type () == floatenv)
1016 xml_insert_element (FLOATEXAMPLE, END);
1019 xml_insert_element (CARTOUCHE, END);
1022 if (docbook && xml_in_bookinfo && xml_in_abstract)
1024 xml_insert_element (ABSTRACT, END);
1025 xml_in_abstract = 0;
1028 xml_insert_element (FORMAT, END);
1031 xml_insert_element (SMALLFORMAT, END);
1034 xml_insert_element (DISPLAY, END);
1037 xml_insert_element (SMALLDISPLAY, END);
1043 xml_end_table (type);
1046 xml_end_enumerate ();
1049 xml_insert_element (GROUP, END);
1052 xml_insert_element (TITLEPAGE, END);
1058 /* Insertions which have no effect on paragraph formatting. */
1070 case ifnotplaintext:
1086 if (raw_output_block <= 0)
1094 && output_paragraph_offset > 0
1095 && output_paragraph[output_paragraph_offset-1] == '\n')
1096 output_paragraph_offset--;
1101 xml_insert_element (DETAILMENU, END);
1103 in_detailmenu--; /* No longer hacking menus. */
1107 close_insertion_paragraph ();
1111 case direntry: /* Eaten if html. */
1112 insert_string ("END-INFO-DIR-ENTRY\n\n");
1113 close_insertion_paragraph ();
1116 case documentdescription:
1118 insert_string (document_description);
1119 xml_insert_element (DOCUMENTDESCRIPTION, END);
1123 in_menu--; /* No longer hacking menus. */
1124 if (html && !no_headers)
1125 add_html_block_elt ("</ul>\n");
1126 else if (!no_headers && !xml)
1127 close_insertion_paragraph ();
1135 stop_enumerating ();
1136 close_insertion_paragraph ();
1137 current_indent -= default_indentation_increment;
1139 add_html_block_elt ("</ol>\n");
1144 add_html_block_elt ("</div>\n");
1145 close_insertion_paragraph ();
1150 add_html_block_elt ("</td></tr></table>\n");
1151 close_insertion_paragraph ();
1155 if (!xml || docbook)
1156 close_insertion_paragraph ();
1161 xml_insert_element (FLOAT, END);
1165 add_html_block_elt ("<p><strong class=\"float-caption\">");
1172 1) @float Foo,lbl & no caption: Foo 1.1
1173 2) @float Foo & no caption: Foo
1174 3) @float ,lbl & no caption: 1.1
1175 4) @float & no caption: */
1178 indent (current_indent);
1180 if (strlen (current_float_type ()))
1181 execute_string ("%s", current_float_type ());
1183 if (strlen (current_float_id ()) > 0)
1185 if (strlen (current_float_type ()) > 0)
1188 add_word (current_float_number ());
1191 if (strlen (current_float_title ()) > 0)
1193 if (strlen (current_float_type ()) > 0
1194 || strlen (current_float_id ()) > 0)
1195 insert_string (": ");
1197 execute_string ("%s", current_float_title ());
1200 /* Indent the following paragraph. */
1201 inhibit_paragraph_indentation = 0;
1204 add_word ("</strong></p></div>\n");
1220 /* @format and @smallformat are the only fixed_width insertion
1221 without a change in indentation. */
1222 if (type != format && type != smallformat && type != quotation)
1223 current_indent -= example_indentation_increment;
1224 else if (type == quotation && !html)
1225 current_indent -= default_indentation_increment;
1228 { /* The complex code in close_paragraph that kills whitespace
1229 does not function here, since we've inserted non-whitespace
1230 (the </whatever>) before it. The indentation already got
1231 inserted at the end of the last example line, so we have to
1232 delete it, or browsers wind up showing an extra blank line.
1233 Furthermore, if we're inside indented environments, we
1234 might have arbitrarily much indentation, so remove it all. */
1235 kill_self_indent (-1);
1236 add_html_block_elt (type == quotation
1237 ? "</blockquote>\n" : "</pre>\n");
1240 /* The ending of one of these insertions always marks the
1241 start of a new paragraph, except for the XML output. */
1242 if (!xml || docbook)
1243 close_insertion_paragraph ();
1245 /* </pre> closes paragraph without messing with </p>. */
1246 if (html && type != quotation)
1247 paragraph_is_open = 0;
1253 current_indent -= default_indentation_increment;
1255 add_html_block_elt ("</dl>\n");
1256 close_insertion_paragraph ();
1260 current_indent -= default_indentation_increment;
1262 add_html_block_elt ("</ul>\n");
1263 close_insertion_paragraph ();
1267 force_flush_right--;
1269 add_html_block_elt ("</div>\n");
1270 close_insertion_paragraph ();
1273 /* Handle the @defun insertions with this default clause. */
1278 if (type < defcv || type > defvr)
1279 line_error ("end_insertion internal error: type=%d", type);
1281 base_type = get_base_type (type);
1297 if (paragraph_is_open)
1298 add_html_block_elt ("</p>");
1299 /* close the div and blockquote which has been opened in defun.c */
1300 if (!rollback_empty_tag ("blockquote"))
1301 add_html_block_elt ("</blockquote>");
1302 add_html_block_elt ("</div>\n");
1305 xml_end_definition ();
1307 } /* switch (base_type)... */
1309 current_indent -= default_indentation_increment;
1310 close_insertion_paragraph ();
1316 if (current_indent < 0)
1317 line_error ("end_insertion internal error: current indent=%d",
1321 /* Insertions cannot cross certain boundaries, such as node beginnings. In
1322 code that creates such boundaries, you should call `discard_insertions'
1323 before doing anything else. It prints the errors for you, and cleans up
1324 the insertion stack.
1326 With nonzero SPECIALS_OK argument, allows unmatched
1327 @if... conditionals, otherwise not. This is because conditionals can
1328 cross node boundaries. Always happens with the @top node, for example. */
1330 discard_insertions (int specials_ok)
1332 int real_line_number = line_number;
1333 while (insertion_stack)
1336 && ((ifclear <= insertion_stack->insertion
1337 && insertion_stack->insertion <= iftex)
1338 || insertion_stack->insertion == rawdocbook
1339 || insertion_stack->insertion == rawhtml
1340 || insertion_stack->insertion == rawxml
1341 || insertion_stack->insertion == rawtex))
1345 const char *offender = insertion_type_pname (insertion_stack->insertion);
1347 file_line_error (insertion_stack->filename,
1348 insertion_stack->line_number,
1349 _("No matching `%cend %s'"), COMMAND_PREFIX,
1354 line_number = real_line_number;
1357 /* Insertion (environment) commands. */
1362 /* We start the blockquote element in the insertion. */
1363 begin_insertion (quotation);
1369 if (docbook && current_insertion_type () == floatenv)
1370 xml_begin_docbook_float (FLOATEXAMPLE);
1374 /* Rollback previous newlines. These occur between
1375 </para> and <example>. */
1376 if (output_paragraph_offset > 0
1377 && output_paragraph[output_paragraph_offset-1] == '\n')
1378 output_paragraph_offset--;
1380 xml_insert_element (EXAMPLE, START);
1382 /* Make sure example text is starting on a new line
1383 for improved readability. */
1388 begin_insertion (example);
1392 cm_smallexample (void)
1394 if (docbook && current_insertion_type () == floatenv)
1395 xml_begin_docbook_float (FLOATEXAMPLE);
1399 /* See cm_example comments about newlines. */
1400 if (output_paragraph_offset > 0
1401 && output_paragraph[output_paragraph_offset-1] == '\n')
1402 output_paragraph_offset--;
1403 xml_insert_element (SMALLEXAMPLE, START);
1408 begin_insertion (smallexample);
1414 if (docbook && current_insertion_type () == floatenv)
1415 xml_begin_docbook_float (FLOATEXAMPLE);
1419 /* See cm_example comments about newlines. */
1420 if (output_paragraph_offset > 0
1421 && output_paragraph[output_paragraph_offset-1] == '\n')
1422 output_paragraph_offset--;
1423 xml_insert_element (LISP, START);
1428 begin_insertion (lisp);
1434 if (docbook && current_insertion_type () == floatenv)
1435 xml_begin_docbook_float (FLOATEXAMPLE);
1439 /* See cm_example comments about newlines. */
1440 if (output_paragraph_offset > 0
1441 && output_paragraph[output_paragraph_offset-1] == '\n')
1442 output_paragraph_offset--;
1443 xml_insert_element (SMALLLISP, START);
1448 begin_insertion (smalllisp);
1454 if (docbook && current_insertion_type () == floatenv)
1455 xml_begin_docbook_float (CARTOUCHE);
1458 xml_insert_element (CARTOUCHE, START);
1459 begin_insertion (cartouche);
1465 begin_insertion (copying);
1468 /* Not an insertion, despite the name, but it goes with cm_copying. */
1470 cm_insert_copying (void)
1474 warning ("@copying not used before %s", command);
1478 /* It is desirable that @copying is set early in the input file. For
1479 Info output, we write the copying text out right away, and thus it
1480 may well be the first thing in the output, and we want the file
1481 header first. The special case in add_char has to check for
1482 executing_string, so it won't be effective. Thus, do it explicitly. */
1484 execute_string ("%s", copying_text);
1489 /* Update output_position so that the node positions in the tag
1490 tables will take account of the copying text. */
1500 if (docbook && xml_in_bookinfo)
1502 xml_insert_element (ABSTRACT, START);
1503 xml_in_abstract = 1;
1507 /* See cm_example comments about newlines. */
1508 if (output_paragraph_offset > 0
1509 && output_paragraph[output_paragraph_offset-1] == '\n')
1510 output_paragraph_offset--;
1511 xml_insert_element (FORMAT, START);
1516 begin_insertion (format);
1520 cm_smallformat (void)
1524 /* See cm_example comments about newlines. */
1525 if (output_paragraph_offset > 0
1526 && output_paragraph[output_paragraph_offset-1] == '\n')
1527 output_paragraph_offset--;
1528 xml_insert_element (SMALLFORMAT, START);
1533 begin_insertion (smallformat);
1541 /* See cm_example comments about newlines. */
1542 if (output_paragraph_offset > 0
1543 && output_paragraph[output_paragraph_offset-1] == '\n')
1544 output_paragraph_offset--;
1545 xml_insert_element (DISPLAY, START);
1550 begin_insertion (display);
1554 cm_smalldisplay (void)
1558 /* See cm_example comments about newlines. */
1559 if (output_paragraph_offset > 0
1560 && output_paragraph[output_paragraph_offset-1] == '\n')
1561 output_paragraph_offset--;
1562 xml_insert_element (SMALLDISPLAY, START);
1567 begin_insertion (smalldisplay);
1573 if (html || xml || no_headers)
1574 command_name_condition ();
1576 begin_insertion (direntry);
1580 cm_documentdescription (void)
1583 begin_insertion (documentdescription);
1587 xml_insert_element (DOCUMENTDESCRIPTION, START);
1588 begin_insertion (documentdescription);
1592 command_name_condition ();
1599 begin_insertion (itemize);
1602 /* Start an enumeration insertion of type TYPE. If the user supplied
1603 no argument on the line, then use DEFAULT_STRING as the initial string. */
1605 do_enumeration (enum insertion_type type, char *default_string)
1607 get_until_in_line (0, ".", &enumeration_arg);
1608 canon_white (enumeration_arg);
1610 if (!*enumeration_arg)
1612 free (enumeration_arg);
1613 enumeration_arg = xstrdup (default_string);
1616 if (!isdigit (*enumeration_arg) && !isletter (*enumeration_arg))
1618 warning (_("%s requires letter or digit"), insertion_type_pname (type));
1623 default_string = "1";
1626 enumeration_arg = xstrdup (default_string);
1628 begin_insertion (type);
1634 do_enumeration (enumerate, "1");
1639 /* Handle verbatim environment:
1640 find_end_verbatim == 0: process until end of file
1641 find_end_verbatim != 0: process until 'COMMAND_PREFIXend verbatim'
1644 No indentation is inserted: this is verbatim after all.
1645 If you want indentation, enclose @verbatim in @example.
1647 Thus, we cannot simply copy the input to the output, since the
1648 verbatim environment may be encapsulated in an @example environment,
1652 handle_verbatim_environment (int find_end_verbatim)
1656 int save_filling_enabled = filling_enabled;
1657 int save_inhibit_paragraph_indentation = inhibit_paragraph_indentation;
1659 if (!insertion_stack)
1660 close_single_paragraph (); /* no blank lines if not at outer level */
1661 inhibit_paragraph_indentation = 1;
1662 filling_enabled = 0;
1663 in_fixed_width_font++;
1664 last_char_was_newline = 0;
1667 { /* If inside @example, we'll be preceded by the indentation
1668 already. Browsers will ignore those spaces because we're about
1669 to start another <pre> (don't ask me). So, wipe them out for
1670 cleanliness, and re-insert. */
1672 kill_self_indent (default_indentation_increment);
1673 add_html_block_elt ("<pre class=\"verbatim\">");
1674 for (i = current_indent; i > 0; i--)
1679 xml_insert_element (VERBATIM, START);
1682 if (find_end_verbatim)
1683 { /* Ignore the remainder of the @verbatim line. */
1685 get_rest_of_line (0, &junk);
1689 while (input_text_offset < input_text_length)
1691 character = curchar ();
1693 if (character == '\n')
1696 /* Assume no newlines in END_VERBATIM. */
1697 else if (find_end_verbatim && (character == COMMAND_PREFIX) /* @ */
1698 && (input_text_length - input_text_offset > sizeof (END_VERBATIM))
1699 && !strncmp (&input_text[input_text_offset+1], END_VERBATIM,
1700 sizeof (END_VERBATIM)-1))
1702 input_text_offset += sizeof (END_VERBATIM);
1707 if (html && character == '&' && escape_html)
1709 else if (html && character == '<' && escape_html)
1712 add_char (character);
1714 input_text_offset++;
1717 if (find_end_verbatim && !seen_end)
1718 warning (_("end of file inside verbatim block"));
1721 { /* See comments in example case above. */
1722 kill_self_indent (default_indentation_increment);
1723 add_word ("</pre>");
1727 xml_insert_element (VERBATIM, END);
1730 in_fixed_width_font--;
1731 filling_enabled = save_filling_enabled;
1732 inhibit_paragraph_indentation = save_inhibit_paragraph_indentation;
1738 handle_verbatim_environment (1);
1744 begin_insertion (table);
1748 cm_multitable (void)
1750 begin_insertion (multitable); /* @@ */
1756 begin_insertion (ftable);
1762 begin_insertion (vtable);
1768 begin_insertion (group);
1771 /* Insert raw HTML (no escaping of `<' etc.). */
1776 begin_insertion (rawhtml);
1778 command_name_condition ();
1785 begin_insertion (rawxml);
1787 command_name_condition ();
1791 cm_docbook (int arg)
1793 if (process_docbook)
1794 begin_insertion (rawdocbook);
1796 command_name_condition ();
1802 if (process_docbook)
1803 begin_insertion (ifdocbook);
1805 command_name_condition ();
1809 cm_ifnotdocbook (void)
1811 if (!process_docbook)
1812 begin_insertion (ifnotdocbook);
1814 command_name_condition ();
1821 begin_insertion (ifhtml);
1823 command_name_condition ();
1830 begin_insertion (ifnothtml);
1832 command_name_condition ();
1840 begin_insertion (ifinfo);
1842 command_name_condition ();
1849 begin_insertion (ifnotinfo);
1851 command_name_condition ();
1856 cm_ifplaintext (void)
1858 if (process_plaintext)
1859 begin_insertion (ifplaintext);
1861 command_name_condition ();
1865 cm_ifnotplaintext (void)
1867 if (!process_plaintext)
1868 begin_insertion (ifnotplaintext);
1870 command_name_condition ();
1878 begin_insertion (rawtex);
1880 command_name_condition ();
1887 begin_insertion (iftex);
1889 command_name_condition ();
1896 begin_insertion (ifnottex);
1898 command_name_condition ();
1905 begin_insertion (ifxml);
1907 command_name_condition ();
1914 begin_insertion (ifnotxml);
1916 command_name_condition ();
1920 /* Generic xrefable block with a caption. */
1924 begin_insertion (floatenv);
1928 cm_caption (int arg)
1932 /* This is a no_op command for most formats, as we handle it during @float
1933 insertion. For XML though, we handle it here to keep document structure
1934 as close as possible, to the Texinfo source. */
1936 /* Everything is already handled at START. */
1940 /* Check if it's mislocated. */
1941 if (current_insertion_type () != floatenv)
1942 line_error (_("@%s not meaningful outside `@float' environment"), command);
1944 get_until_in_braces ("\n@end float", &temp);
1948 int elt = STREQ (command, "shortcaption") ? SHORTCAPTION : CAPTION;
1949 xml_insert_element (elt, START);
1951 execute_string ("%s", temp);
1952 xml_insert_element (elt, END);
1958 /* Begin an insertion where the lines are not filled or indented. */
1962 begin_insertion (flushleft);
1965 /* Begin an insertion where the lines are not filled, and each line is
1966 forced to the right-hand side of the page. */
1968 cm_flushright (void)
1970 begin_insertion (flushright);
1976 if (current_node == NULL && !macro_expansion_output_stream)
1978 warning (_("@menu seen before first @node, creating `Top' node"));
1979 warning (_("perhaps your @top node should be wrapped in @ifnottex rather than @ifinfo?"));
1980 /* Include @top command so we can construct the implicit node tree. */
1981 execute_string ("@node top\n@top Top\n");
1983 begin_insertion (menu);
1987 cm_detailmenu (void)
1989 if (current_node == NULL && !macro_expansion_output_stream)
1990 { /* Problems anyway, @detailmenu should always be inside @menu. */
1991 warning (_("@detailmenu seen before first node, creating `Top' node"));
1992 execute_string ("@node top\n@top Top\n");
1994 begin_insertion (detailmenu);
1997 /* Title page commands. */
2002 titlepage_cmd_present = 1;
2003 if (xml && !docbook)
2004 begin_insertion (titlepage);
2006 command_name_condition ();
2013 get_rest_of_line (1, &rest);
2015 if (is_in_insertion_of_type (quotation))
2018 add_word_args ("— %s", rest);
2021 /* FIXME Ideally, we should use an attribution element,
2022 but they are supposed to be at the start of quotation
2023 blocks. So to avoid looking ahead mess, let's just
2024 use mdash like HTML for now. */
2025 xml_insert_entity ("mdash");
2030 xml_insert_element (AUTHOR, START);
2032 xml_insert_element (AUTHOR, END);
2035 add_word_args ("-- %s", rest);
2037 else if (is_in_insertion_of_type (titlepage))
2039 if (xml && !docbook)
2041 xml_insert_element (AUTHOR, START);
2043 xml_insert_element (AUTHOR, END);
2047 line_error (_("@%s not meaningful outside `@titlepage' and `@quotation' environments"),
2054 cm_titlepage_cmds (void)
2058 get_rest_of_line (1, &rest);
2060 if (!is_in_insertion_of_type (titlepage))
2061 line_error (_("@%s not meaningful outside `@titlepage' environment"),
2064 if (xml && !docbook)
2068 if (STREQ (command, "title"))
2070 else if (STREQ (command, "subtitle"))
2073 xml_insert_element (elt, START);
2075 xml_insert_element (elt, END);
2081 /* End existing insertion block. */
2086 enum insertion_type type;
2088 get_rest_of_line (0, &temp);
2090 if (!insertion_level)
2092 line_error (_("Unmatched `%c%s'"), COMMAND_PREFIX, command);
2097 line_error (_("`%c%s' needs something after it"), COMMAND_PREFIX, command);
2099 type = find_type_from_name (temp);
2101 if (type == bad_type)
2103 line_error (_("Bad argument `%s' to `@%s', using `%s'"),
2104 temp, command, insertion_type_pname (current_insertion_type ()));
2106 if (xml && type == menu) /* fixme */
2110 end_insertion (type);
2114 /* @itemx, @item. */
2116 static int itemx_flag = 0;
2118 /* Return whether CMD takes a brace-delimited {arg}. */
2120 command_needs_braces (char *cmd)
2123 for (i = 0; command_table[i].name; i++)
2125 if (STREQ (command_table[i].name, cmd))
2126 return command_table[i].argument_in_braces == BRACE_ARGS;
2129 return 0; /* macro or alias */
2136 char *rest_of_line, *item_func;
2138 /* Can only hack "@item" while inside of an insertion. */
2139 if (insertion_level)
2141 INSERTION_ELT *stack = insertion_stack;
2142 int original_input_text_offset;
2145 original_input_text_offset = input_text_offset;
2147 get_rest_of_line (0, &rest_of_line);
2148 item_func = current_item_function ();
2150 /* Do the right thing depending on which insertion function is active. */
2152 switch (stack->insertion)
2156 /* Support text directly after the @item. */
2160 input_text_offset = original_input_text_offset;
2169 case ifnotplaintext:
2182 stack = stack->next;
2200 line_error (_("@%s not meaningful inside `@%s' block"),
2202 insertion_type_pname (current_insertion_type ()));
2209 line_error (_("@itemx not meaningful inside `%s' block"),
2210 insertion_type_pname (current_insertion_type ()));
2215 add_html_block_elt ("<li>");
2221 kill_self_indent (-1);
2222 filling_enabled = indented_fill = 1;
2224 if (current_item_function ())
2226 indent (current_indent - 2);
2228 /* The item marker can be given with or without
2229 braces -- @bullet and @bullet{} are both ok.
2230 Or it might be something that doesn't take
2231 braces at all, such as "o" or "#" or "@ ".
2232 Thus, only supply braces if the item marker is
2233 a command, they haven't supplied braces
2234 themselves, and we know it needs them. */
2235 if (item_func && *item_func)
2237 if (*item_func == COMMAND_PREFIX
2238 && item_func[strlen (item_func) - 1] != '}'
2239 && command_needs_braces (item_func + 1))
2240 execute_string ("%s{}", item_func);
2242 execute_string ("%s", item_func);
2249 /* Special hack. This makes `close_paragraph' a no-op until
2250 `start_paragraph' has been called. */
2251 must_start_paragraph = 1;
2254 /* Handle text directly after the @item. */
2258 input_text_offset = original_input_text_offset;
2267 { /* If nothing has been output since the last <dd>,
2268 remove the empty <dd> element. Some browsers render
2269 an extra empty line for <dd><dt>, which makes @itemx
2270 conversion look ugly. */
2271 rollback_empty_tag ("dd");
2273 /* Force the browser to render one blank line before
2274 each new @item in a table. But don't do that if
2275 this is the first <dt> after the <dl>, or if we are
2278 Note that there are some browsers which ignore <br>
2279 in this context, but I cannot find any way to force
2280 them all render exactly one blank line. */
2281 if (!itemx_flag && html_deflist_has_term)
2282 add_html_block_elt ("<br>");
2284 /* We are about to insert a <dt>, so this <dl> has a term.
2285 Feel free to insert a <br> next time. :) */
2286 html_deflist_has_term = 1;
2288 add_html_block_elt ("<dt>");
2289 if (item_func && *item_func)
2290 execute_string ("%s{%s}", item_func, rest_of_line);
2292 execute_string ("%s", rest_of_line);
2294 if (current_insertion_type () == ftable)
2295 execute_string ("%cfindex %s\n", COMMAND_PREFIX, rest_of_line);
2297 if (current_insertion_type () == vtable)
2298 execute_string ("%cvindex %s\n", COMMAND_PREFIX, rest_of_line);
2300 add_html_block_elt ("<dd>");
2302 else if (xml) /* && docbook)*/ /* 05-08 */
2304 xml_begin_table_item ();
2306 if (!docbook && current_insertion_type () == ftable)
2307 execute_string ("%cfindex %s\n", COMMAND_PREFIX, rest_of_line);
2309 if (!docbook && current_insertion_type () == vtable)
2310 execute_string ("%cvindex %s\n", COMMAND_PREFIX, rest_of_line);
2312 if (item_func && *item_func)
2313 execute_string ("%s{%s}", item_func, rest_of_line);
2315 execute_string ("%s", rest_of_line);
2316 xml_continue_table_item ();
2320 /* We need this to determine if we have two @item's in a row
2321 (see test just below). */
2322 static int last_item_output_position = 0;
2324 /* Get rid of extra characters. */
2325 kill_self_indent (-1);
2327 /* If we have one @item followed directly by another @item,
2328 we need to insert a blank line. This is not true for
2330 if (!itemx_flag && last_item_output_position == output_position)
2333 /* `close_paragraph' almost does what we want. The problem
2334 is when paragraph_is_open, and last_char_was_newline, and
2335 the last newline has been turned into a space, because
2336 filling_enabled. I handle it here. */
2337 if (last_char_was_newline && filling_enabled &&
2342 #if defined (INDENT_PARAGRAPHS_IN_TABLE)
2343 /* Indent on a new line, but back up one indentation level. */
2345 int save = inhibit_paragraph_indentation;
2346 inhibit_paragraph_indentation = 1;
2347 /* At this point, inserting any non-whitespace character will
2348 force the existing indentation to be output. */
2350 inhibit_paragraph_indentation = save;
2352 #else /* !INDENT_PARAGRAPHS_IN_TABLE */
2354 #endif /* !INDENT_PARAGRAPHS_IN_TABLE */
2356 output_paragraph_offset--;
2357 kill_self_indent (default_indentation_increment + 1);
2359 /* Add item's argument to the line. */
2360 filling_enabled = 0;
2361 if (item_func && *item_func)
2362 execute_string ("%s{%s}", item_func, rest_of_line);
2364 execute_string ("%s", rest_of_line);
2366 if (current_insertion_type () == ftable)
2367 execute_string ("%cfindex %s\n", COMMAND_PREFIX, rest_of_line);
2368 else if (current_insertion_type () == vtable)
2369 execute_string ("%cvindex %s\n", COMMAND_PREFIX, rest_of_line);
2371 /* Start a new line, and let start_paragraph ()
2372 do the indenting of it for you. */
2373 close_single_paragraph ();
2374 indented_fill = filling_enabled = 1;
2375 last_item_output_position = output_position;
2378 free (rest_of_line);
2383 line_error (_("%c%s found outside of an insertion block"),
2384 COMMAND_PREFIX, command);
2396 int headitem_flag = 0;