3 /* insertion.c -- insertions for Texinfo.
4 Id: insertion.c,v 1.55 2004/11/11 18:34:28 karl Exp
6 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software Foundation,
21 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
28 #include "insertion.h"
34 /* Must match list in insertion.h. */
35 static char *insertion_type_names
[] =
37 "cartouche", "copying", "defcv", "deffn", "defivar", "defmac",
38 "defmethod", "defop", "defopt", "defspec", "deftp", "deftypecv",
39 "deftypefn", "deftypefun", "deftypeivar", "deftypemethod",
40 "deftypeop", "deftypevar", "deftypevr", "defun", "defvar", "defvr",
41 "detailmenu", "direntry", "display", "documentdescription",
42 "enumerate", "example", "float", "flushleft", "flushright", "format",
43 "ftable", "group", "ifclear", "ifdocbook", "ifhtml", "ifinfo",
44 "ifnotdocbook", "ifnothtml", "ifnotinfo", "ifnotplaintext", "ifnottex",
45 "ifnotxml", "ifplaintext", "ifset", "iftex", "ifxml", "itemize", "lisp",
46 "menu", "multitable", "quotation", "rawdocbook", "rawhtml", "rawtex",
47 "rawxml", "smalldisplay", "smallexample", "smallformat", "smalllisp",
48 "verbatim", "table", "tex", "vtable", "titlepage", "bad_type"
51 /* All nested environments. */
52 INSERTION_ELT
*insertion_stack
= NULL
;
54 /* How deeply we're nested. */
55 int insertion_level
= 0;
57 /* Set to 1 if we've processed (commentary) text in a @menu that
58 wasn't part of a menu item. */
59 int had_menu_commentary
;
61 /* How to examine menu lines. */
62 int in_detailmenu
= 0;
64 /* Whether to examine menu lines. */
67 /* Set to 1 if <p> is written in normal context.
68 Used for menu and itemize. */
71 /* Since an insertion is already in the stack before we reach the switch
72 statement, we cannot use is_in_insertion_of_type (always returns true.) Also
73 making it return the level found, and comparing it with the current level is
74 no use, due to the order of stack. */
75 static int float_active
= 0;
77 /* Unsetting escape_html blindly causes text inside @html/etc. to be escaped if
78 used within a rmacro. */
79 static int raw_output_block
= 0;
81 /* Non-zero if a <dl> element has a <dt> element in it. We use this when
82 deciding whether to insert a <br> or not. */
83 static int html_deflist_has_term
= 0;
86 init_insertion_stack (void)
88 insertion_stack
= NULL
;
91 /* Return the type of the current insertion. */
92 static enum insertion_type
93 current_insertion_type (void)
95 return insertion_level
? insertion_stack
->insertion
: bad_type
;
98 /* Return the string which is the function to wrap around items, or NULL
99 if we're not in an environment where @item is ok. */
101 current_item_function (void)
104 INSERTION_ELT
*elt
= insertion_stack
;
106 /* Skip down through the stack until we find an insertion with an
107 itemize function defined, i.e., skip conditionals, @cartouche, etc. */
110 switch (elt
->insertion
)
112 /* This list should match the one in cm_item. */
139 /* item_function usually gets assigned the empty string. */
140 return done
&& (*elt
->item_function
) ? elt
->item_function
: NULL
;
143 /* Parse the item marker function off the input. If result is just "@",
144 change it to "@ ", since "@" by itself is not a command. This makes
145 "@ ", "@\t", and "@\n" all the same, but their default meanings are
146 the same anyway, and let's not worry about supporting redefining them. */
148 get_item_function (void)
153 get_rest_of_line (0, &item_function
);
155 /* If the document erroneously says
156 @itemize @bullet @item foobar
157 it's nicer to give an error up front than repeat `@bullet expected
158 braces' until we get a segmentation fault. */
159 item_loc
= strstr (item_function
, "@item");
162 line_error (_("@item not allowed in argument to @itemize"));
166 /* If we hit the end of text in get_rest_of_line, backing up
167 input pointer will cause the last character of the last line
168 be pushed back onto the input, which is wrong. */
169 if (input_text_offset
< input_text_length
)
170 backup_input_pointer ();
172 if (STREQ (item_function
, "@"))
174 free (item_function
);
175 item_function
= xstrdup ("@ ");
178 return item_function
;
181 /* Push the state of the current insertion on the stack. */
183 push_insertion (enum insertion_type type
, char *item_function
)
185 INSERTION_ELT
*new = xmalloc (sizeof (INSERTION_ELT
));
187 new->item_function
= item_function
;
188 new->filling_enabled
= filling_enabled
;
189 new->indented_fill
= indented_fill
;
190 new->insertion
= type
;
191 new->line_number
= line_number
;
192 new->filename
= xstrdup (input_filename
);
193 new->inhibited
= inhibit_paragraph_indentation
;
194 new->in_fixed_width_font
= in_fixed_width_font
;
195 new->next
= insertion_stack
;
196 insertion_stack
= new;
200 /* Pop the value on top of the insertion stack into the
205 INSERTION_ELT
*temp
= insertion_stack
;
210 in_fixed_width_font
= temp
->in_fixed_width_font
;
211 inhibit_paragraph_indentation
= temp
->inhibited
;
212 filling_enabled
= temp
->filling_enabled
;
213 indented_fill
= temp
->indented_fill
;
214 free_and_clear (&(temp
->item_function
));
215 free_and_clear (&(temp
->filename
));
216 insertion_stack
= insertion_stack
->next
;
221 /* Return a pointer to the print name of this
224 insertion_type_pname (enum insertion_type type
)
226 if ((int) type
< (int) bad_type
)
228 if (type
== rawdocbook
)
230 else if (type
== rawhtml
)
232 else if (type
== rawxml
)
234 else if (type
== rawtex
)
237 return insertion_type_names
[(int) type
];
240 return _("Broken-Type in insertion_type_pname");
243 /* Return the insertion_type associated with NAME.
244 If the type is not one of the known ones, return BAD_TYPE. */
246 find_type_from_name (char *name
)
249 while (index
< (int) bad_type
)
251 if (STREQ (name
, insertion_type_names
[index
]))
252 return (enum insertion_type
) index
;
253 if (index
== rawdocbook
&& STREQ (name
, "docbook"))
255 if (index
== rawhtml
&& STREQ (name
, "html"))
257 if (index
== rawxml
&& STREQ (name
, "xml"))
259 if (index
== rawtex
&& STREQ (name
, "tex"))
266 /* Simple function to query insertion_stack to see if we are inside a given
269 is_in_insertion_of_type (int type
)
271 INSERTION_ELT
*temp
= insertion_stack
;
273 if (!insertion_level
)
278 if (temp
->insertion
== type
)
288 defun_insertion (enum insertion_type type
)
295 || (type
== defmethod
)
300 || (type
== deftypecv
)
301 || (type
== deftypefn
)
302 || (type
== deftypefun
)
303 || (type
== deftypeivar
)
304 || (type
== deftypemethod
)
305 || (type
== deftypeop
)
306 || (type
== deftypevar
)
307 || (type
== deftypevr
)
314 /* MAX_NS is the maximum nesting level for enumerations. I picked 100
315 which seemed reasonable. This doesn't control the number of items,
316 just the number of nested lists. */
317 #define max_stack_depth 100
318 #define ENUM_DIGITS 1
325 DIGIT_ALPHA enumstack
[max_stack_depth
];
326 int enumstack_offset
= 0;
327 int current_enumval
= 1;
328 int current_enumtype
= ENUM_DIGITS
;
329 char *enumeration_arg
= NULL
;
332 start_enumerating (int at
, int type
)
334 if ((enumstack_offset
+ 1) == max_stack_depth
)
336 line_error (_("Enumeration stack overflow"));
339 enumstack
[enumstack_offset
].enumtype
= current_enumtype
;
340 enumstack
[enumstack_offset
].enumval
= current_enumval
;
342 current_enumval
= at
;
343 current_enumtype
= type
;
347 stop_enumerating (void)
350 if (enumstack_offset
< 0)
351 enumstack_offset
= 0;
353 current_enumval
= enumstack
[enumstack_offset
].enumval
;
354 current_enumtype
= enumstack
[enumstack_offset
].enumtype
;
357 /* Place a letter or digits into the output stream. */
359 enumerate_item (void)
363 if (current_enumtype
== ENUM_ALPHA
)
365 if (current_enumval
== ('z' + 1) || current_enumval
== ('Z' + 1))
367 current_enumval
= ((current_enumval
- 1) == 'z' ? 'a' : 'A');
368 warning (_("lettering overflow, restarting at %c"), current_enumval
);
370 sprintf (temp
, "%c. ", current_enumval
);
373 sprintf (temp
, "%d. ", current_enumval
);
375 indent (output_column
+= (current_indent
- strlen (temp
)));
386 if (isdigit (*enumeration_arg
))
389 start
= atoi (enumeration_arg
);
391 else if (isupper (*enumeration_arg
))
394 start
= *enumeration_arg
- 'A' + 1;
399 start
= *enumeration_arg
- 'a' + 1;
402 add_html_block_elt_args ("<ol type=%c start=%d>\n", type
, start
);
405 /* Conditionally parse based on the current command name. */
407 command_name_condition (void)
409 char *discarder
= xmalloc (8 + strlen (command
));
411 sprintf (discarder
, "\n%cend %s", COMMAND_PREFIX
, command
);
412 discard_until (discarder
);
413 discard_until ("\n");
418 /* This is where the work for all the "insertion" style
419 commands is done. A huge switch statement handles the
420 various setups, and generic code is on both sides. */
422 begin_insertion (enum insertion_type type
)
426 if (defun_insertion (type
))
428 push_insertion (type
, xstrdup (""));
433 push_insertion (type
, get_item_function ());
442 filling_enabled
= no_indent
= 0;
443 inhibit_paragraph_indentation
= 1;
447 had_menu_commentary
= 1;
449 else if (!no_headers
&& !xml
)
450 add_word ("* Menu:\n");
453 xml_insert_element (MENU
, START
);
455 in_fixed_width_font
++;
457 next_menu_item_number
= 1;
468 filling_enabled
= no_indent
= 0;
469 inhibit_paragraph_indentation
= 1;
476 xml_insert_element (DETAILMENU
, START
);
477 skip_whitespace_and_newlines();
480 in_fixed_width_font
++;
486 close_single_paragraph ();
487 filling_enabled
= no_indent
= 0;
488 inhibit_paragraph_indentation
= 1;
489 insert_string ("START-INFO-DIR-ENTRY\n");
492 case documentdescription
:
496 int save_fixed_width
;
498 discard_until ("\n"); /* ignore the @documentdescription line */
499 start_of_end
= get_until ("\n@end documentdescription", &desc
);
500 save_fixed_width
= in_fixed_width_font
;
502 in_fixed_width_font
= 0;
503 document_description
= expansion (desc
, 0);
506 in_fixed_width_font
= save_fixed_width
;
507 input_text_offset
= start_of_end
; /* go back to the @end to match */
512 /* Save the copying text away for @insertcopying,
513 typically used on the back of the @titlepage (for TeX) and
514 the Top node (for info/html). */
515 if (input_text
[input_text_offset
] != '\n')
516 discard_until ("\n"); /* ignore remainder of @copying line */
518 input_text_offset
= get_until ("\n@end copying", ©ing_text
);
519 canon_white (copying_text
);
521 /* For info, output the copying text right away, so it will end up
522 in the header of the Info file, before the first node, and thus
523 get copied automatically to all the split files. For xml, also
524 output it right away since xml output is never split.
525 For html, we output it specifically in html_output_head.
526 For plain text, there's no way to hide it, so the author must
527 use @insertcopying in the desired location. */
530 if (!xml_in_bookinfo
)
532 xml_insert_element (BOOKINFO
, START
);
535 xml_insert_element (LEGALNOTICE
, START
);
538 if (!html
&& !no_headers
)
539 cm_insert_copying ();
542 xml_insert_element (LEGALNOTICE
, END
);
547 /* @quotation does filling (@display doesn't). */
549 add_html_block_elt ("<blockquote>\n");
552 /* with close_single_paragraph, we get no blank line above
555 last_char_was_newline
= no_indent
= 0;
556 indented_fill
= filling_enabled
= 1;
557 inhibit_paragraph_indentation
= 1;
559 current_indent
+= default_indentation_increment
;
561 xml_insert_quotation (insertion_stack
->item_function
, START
);
562 else if (strlen(insertion_stack
->item_function
))
563 execute_string ("@b{%s:} ", insertion_stack
->item_function
);
570 in_fixed_width_font
++;
573 /* Like @example but no fixed width font. */
576 /* Like @display but without indentation. */
579 close_single_paragraph ();
580 inhibit_paragraph_indentation
= 1;
582 last_char_was_newline
= 0;
585 /* Kludge alert: if <pre> is followed by a newline, IE3,
586 mozilla, maybe others render an extra blank line before the
587 pre-formatted block. So don't output a newline. */
588 add_html_block_elt_args ("<pre class=\"%s\">", command
);
590 if (type
!= format
&& type
!= smallformat
)
592 current_indent
+= example_indentation_increment
;
595 /* Since we didn't put \n after <pre>, we need to insert
596 the indentation by hand. */
598 for (i
= current_indent
; i
> 0; i
--)
612 close_single_paragraph ();
613 current_indent
+= default_indentation_increment
;
614 filling_enabled
= indented_fill
= 1;
615 #if defined (INDENT_PARAGRAPHS_IN_TABLE)
616 inhibit_paragraph_indentation
= 0;
618 inhibit_paragraph_indentation
= 1;
619 #endif /* !INDENT_PARAGRAPHS_IN_TABLE */
621 /* Make things work for losers who forget the itemize syntax. */
624 if (!(*insertion_stack
->item_function
))
626 free (insertion_stack
->item_function
);
627 insertion_stack
->item_function
= xstrdup ("@bullet");
631 if (!*insertion_stack
->item_function
)
633 line_error (_("%s requires an argument: the formatter for %citem"),
634 insertion_type_pname (type
), COMMAND_PREFIX
);
641 add_html_block_elt ("<ul>\n");
645 { /* We are just starting, so this <dl>
646 has no <dt> children yet. */
647 html_deflist_has_term
= 0;
648 add_html_block_elt ("<dl>\n");
652 xml_begin_table (type
, insertion_stack
->item_function
);
654 while (input_text
[input_text_offset
] == '\n'
655 && input_text
[input_text_offset
+1] == '\n')
664 close_single_paragraph ();
666 #if defined (INDENT_PARAGRAPHS_IN_TABLE)
667 inhibit_paragraph_indentation
= 0;
669 inhibit_paragraph_indentation
= 1;
670 #endif /* !INDENT_PARAGRAPHS_IN_TABLE */
672 current_indent
+= default_indentation_increment
;
673 filling_enabled
= indented_fill
= 1;
682 xml_begin_enumerate (enumeration_arg
);
684 if (isdigit (*enumeration_arg
))
685 start_enumerating (atoi (enumeration_arg
), ENUM_DIGITS
);
687 start_enumerating (*enumeration_arg
, ENUM_ALPHA
);
690 /* @group produces no output in info. */
692 /* Only close the paragraph if we are not inside of an
693 @example-like environment. */
695 xml_insert_element (GROUP
, START
);
696 else if (!insertion_stack
->next
697 || (insertion_stack
->next
->insertion
!= display
698 && insertion_stack
->next
->insertion
!= smalldisplay
699 && insertion_stack
->next
->insertion
!= example
700 && insertion_stack
->next
->insertion
!= smallexample
701 && insertion_stack
->next
->insertion
!= lisp
702 && insertion_stack
->next
->insertion
!= smalllisp
703 && insertion_stack
->next
->insertion
!= format
704 && insertion_stack
->next
->insertion
!= smallformat
705 && insertion_stack
->next
->insertion
!= flushleft
706 && insertion_stack
->next
->insertion
!= flushright
))
707 close_single_paragraph ();
712 add_html_block_elt ("<p><table class=\"cartouche\" summary=\"cartouche\" border=\"1\"><tr><td>\n");
718 /* Cannot nest floats, so complain. */
721 line_error (_("%cfloat environments cannot be nested"), COMMAND_PREFIX
);
728 { /* Collect data about this float. */
729 /* Example: @float [FLOATTYPE][,XREFLABEL][,POSITION] */
730 char floattype
[200] = "";
731 char xreflabel
[200] = "";
732 char position
[200] = "";
737 int save_line_number
= line_number
;
738 int save_input_text_offset
= input_text_offset
;
741 if (strlen (insertion_stack
->item_function
) > 0)
743 int i
= 0, t
= 0, c
= 0;
744 while (insertion_stack
->item_function
[i
])
746 if (insertion_stack
->item_function
[i
] == ',')
769 floattype
[c
] = insertion_stack
->item_function
[i
];
772 xreflabel
[c
] = insertion_stack
->item_function
[i
];
775 position
[c
] = insertion_stack
->item_function
[i
];
783 skip_whitespace_and_newlines ();
785 start_of_end
= get_until ("\n@end float", &text
);
787 /* Get also the @caption. */
788 i
= search_forward_until_pos ("\n@caption{",
789 save_input_text_offset
, start_of_end
);
792 input_text_offset
= i
+ sizeof ("\n@caption{") - 1;
793 get_until_in_braces ("\n@end float", &caption
);
794 input_text_offset
= save_input_text_offset
;
799 /* ... and the @shortcaption. */
800 i
= search_forward_until_pos ("\n@shortcaption{",
801 save_input_text_offset
, start_of_end
);
804 input_text_offset
= i
+ sizeof ("\n@shortcaption{") - 1;
805 get_until_in_braces ("\n@end float", &shortcaption
);
806 input_text_offset
= save_input_text_offset
;
811 canon_white (xreflabel
);
812 canon_white (floattype
);
813 canon_white (position
);
814 canon_white (caption
);
815 canon_white (shortcaption
);
817 add_new_float (xstrdup (xreflabel
),
818 xstrdup (caption
), xstrdup (shortcaption
),
819 xstrdup (floattype
), xstrdup (position
));
821 /* Move to the start of the @float so the contents get processed as
823 input_text_offset
= save_input_text_offset
;
824 line_number
= save_line_number
;
828 add_html_block_elt ("<div class=\"float\">\n");
830 xml_insert_element (FLOAT
, START
);
833 xml_insert_element_with_attribute (FLOAT
, START
,
834 "name=\"%s\"", current_float_id ());
836 xml_insert_element (FLOATTYPE
, START
);
837 execute_string ("%s", current_float_type ());
838 xml_insert_element (FLOATTYPE
, END
);
840 xml_insert_element (FLOATPOS
, START
);
841 execute_string ("%s", current_float_position ());
842 xml_insert_element (FLOATPOS
, END
);
846 close_single_paragraph ();
847 inhibit_paragraph_indentation
= 1;
850 /* Anchor now. Note that XML documents get their
851 anchors with <float name="anchor"> tag. */
852 if ((!xml
|| docbook
) && strlen (current_float_id ()) > 0)
853 execute_string ("@anchor{%s}", current_float_id ());
857 /* Insertions that are no-ops in info, but do something in TeX. */
882 if (raw_output_block
> 0)
890 /* Some deuglification for improved readability. */
891 extern int xml_in_para
;
892 if (xml
&& !xml_in_para
&& xml_indentation_increment
> 0)
918 inhibit_paragraph_indentation
= 1;
919 filling_enabled
= indented_fill
= 1;
920 current_indent
+= default_indentation_increment
;
923 xml_begin_definition ();
927 close_single_paragraph ();
928 inhibit_paragraph_indentation
= 1;
929 filling_enabled
= indented_fill
= no_indent
= 0;
931 add_html_block_elt ("<div align=\"left\">");
935 close_single_paragraph ();
936 filling_enabled
= indented_fill
= no_indent
= 0;
937 inhibit_paragraph_indentation
= 1;
940 add_html_block_elt ("<div align=\"right\">");
944 xml_insert_element (TITLEPAGE
, START
);
948 line_error ("begin_insertion internal error: type=%d", type
);
952 discard_until ("\n");
955 /* Try to end the insertion with the specified TYPE. With a value of
956 `bad_type', TYPE gets translated to match the value currently on top
957 of the stack. Otherwise, if TYPE doesn't match the top of the
958 insertion stack, give error. */
960 end_insertion (int type
)
964 if (!insertion_level
)
967 temp_type
= current_insertion_type ();
969 if (type
== bad_type
)
972 if (type
!= temp_type
)
975 (_("`@end' expected `%s', but saw `%s'"),
976 insertion_type_pname (temp_type
), insertion_type_pname (type
));
987 case documentdescription
:
990 xml_insert_quotation ("", END
);
993 xml_insert_element (EXAMPLE
, END
);
994 if (docbook
&& current_insertion_type () == floatenv
)
995 xml_insert_element (FLOATEXAMPLE
, END
);
998 xml_insert_element (SMALLEXAMPLE
, END
);
999 if (docbook
&& current_insertion_type () == floatenv
)
1000 xml_insert_element (FLOATEXAMPLE
, END
);
1003 xml_insert_element (LISP
, END
);
1004 if (docbook
&& current_insertion_type () == floatenv
)
1005 xml_insert_element (FLOATEXAMPLE
, END
);
1008 xml_insert_element (SMALLLISP
, END
);
1009 if (docbook
&& current_insertion_type () == floatenv
)
1010 xml_insert_element (FLOATEXAMPLE
, END
);
1013 xml_insert_element (CARTOUCHE
, END
);
1016 if (docbook
&& xml_in_bookinfo
&& xml_in_abstract
)
1018 xml_insert_element (ABSTRACT
, END
);
1019 xml_in_abstract
= 0;
1022 xml_insert_element (FORMAT
, END
);
1025 xml_insert_element (SMALLFORMAT
, END
);
1028 xml_insert_element (DISPLAY
, END
);
1031 xml_insert_element (SMALLDISPLAY
, END
);
1037 xml_end_table (type
);
1040 xml_end_enumerate ();
1043 xml_insert_element (GROUP
, END
);
1046 xml_insert_element (TITLEPAGE
, END
);
1052 /* Insertions which have no effect on paragraph formatting. */
1064 case ifnotplaintext
:
1080 if (raw_output_block
<= 0)
1087 if ((xml
|| html
) && output_paragraph
[output_paragraph_offset
-1] == '\n')
1088 output_paragraph_offset
--;
1093 xml_insert_element (DETAILMENU
, END
);
1095 in_detailmenu
--; /* No longer hacking menus. */
1099 close_insertion_paragraph ();
1103 case direntry
: /* Eaten if html. */
1104 insert_string ("END-INFO-DIR-ENTRY\n\n");
1105 close_insertion_paragraph ();
1108 case documentdescription
:
1110 insert_string (document_description
);
1111 xml_insert_element (DOCUMENTDESCRIPTION
, END
);
1115 in_menu
--; /* No longer hacking menus. */
1116 if (html
&& !no_headers
)
1117 add_html_block_elt ("</ul>\n");
1118 else if (!no_headers
&& !xml
)
1119 close_insertion_paragraph ();
1127 stop_enumerating ();
1128 close_insertion_paragraph ();
1129 current_indent
-= default_indentation_increment
;
1131 add_html_block_elt ("</ol>\n");
1136 add_html_block_elt ("</div>\n");
1137 close_insertion_paragraph ();
1142 add_html_block_elt ("</td></tr></table>\n");
1143 close_insertion_paragraph ();
1147 if (!xml
|| docbook
)
1148 close_insertion_paragraph ();
1153 xml_insert_element (FLOAT
, END
);
1157 add_html_block_elt ("<p><strong class=\"float-caption\">");
1164 1) @float Foo,lbl & no caption: Foo 1.1
1165 2) @float Foo & no caption: Foo
1166 3) @float ,lbl & no caption: 1.1
1167 4) @float & no caption: */
1170 indent (current_indent
);
1172 if (strlen (current_float_type ()))
1173 execute_string ("%s", current_float_type ());
1175 if (strlen (current_float_id ()) > 0)
1177 if (strlen (current_float_type ()) > 0)
1180 add_word (current_float_number ());
1183 if (strlen (current_float_title ()) > 0)
1185 if (strlen (current_float_type ()) > 0
1186 || strlen (current_float_id ()) > 0)
1187 insert_string (": ");
1189 execute_string ("%s", current_float_title ());
1192 /* Indent the following paragraph. */
1193 inhibit_paragraph_indentation
= 0;
1196 add_word ("</strong></p></div>\n");
1212 /* @format and @smallformat are the only fixed_width insertion
1213 without a change in indentation. */
1214 if (type
!= format
&& type
!= smallformat
&& type
!= quotation
)
1215 current_indent
-= example_indentation_increment
;
1216 else if (type
== quotation
)
1217 current_indent
-= default_indentation_increment
;
1220 { /* The complex code in close_paragraph that kills whitespace
1221 does not function here, since we've inserted non-whitespace
1222 (the </whatever>) before it. The indentation already got
1223 inserted at the end of the last example line, so we have to
1224 delete it, or browsers wind up showing an extra blank line. */
1225 kill_self_indent (default_indentation_increment
);
1226 add_html_block_elt (type
== quotation
1227 ? "</blockquote>\n" : "</pre>\n");
1230 /* The ending of one of these insertions always marks the
1231 start of a new paragraph, except for the XML output. */
1232 if (!xml
|| docbook
)
1233 close_insertion_paragraph ();
1235 /* </pre> closes paragraph without messing with </p>. */
1236 if (html
&& type
!= quotation
)
1237 paragraph_is_open
= 0;
1243 current_indent
-= default_indentation_increment
;
1245 add_html_block_elt ("</dl>\n");
1246 close_insertion_paragraph ();
1250 current_indent
-= default_indentation_increment
;
1252 add_html_block_elt ("</ul>\n");
1253 close_insertion_paragraph ();
1257 force_flush_right
--;
1259 add_html_block_elt ("</div>\n");
1260 close_insertion_paragraph ();
1263 /* Handle the @defun insertions with this default clause. */
1268 if (type
< defcv
|| type
> defvr
)
1269 line_error ("end_insertion internal error: type=%d", type
);
1271 base_type
= get_base_type (type
);
1287 if (paragraph_is_open
)
1288 add_html_block_elt ("</p>");
1289 /* close the div and blockquote which has been opened in defun.c */
1290 if (!rollback_empty_tag ("blockquote"))
1291 add_html_block_elt ("</blockquote>");
1292 add_html_block_elt ("</div>\n");
1295 xml_end_definition ();
1297 } /* switch (base_type)... */
1299 current_indent
-= default_indentation_increment
;
1300 close_insertion_paragraph ();
1306 if (current_indent
< 0)
1307 line_error ("end_insertion internal error: current indent=%d",
1311 /* Insertions cannot cross certain boundaries, such as node beginnings. In
1312 code that creates such boundaries, you should call `discard_insertions'
1313 before doing anything else. It prints the errors for you, and cleans up
1314 the insertion stack.
1316 With nonzero SPECIALS_OK argument, allows unmatched
1317 @if... conditionals, otherwise not. This is because conditionals can
1318 cross node boundaries. Always happens with the @top node, for example. */
1320 discard_insertions (int specials_ok
)
1322 int real_line_number
= line_number
;
1323 while (insertion_stack
)
1326 && ((ifclear
<= insertion_stack
->insertion
1327 && insertion_stack
->insertion
<= iftex
)
1328 || insertion_stack
->insertion
== rawdocbook
1329 || insertion_stack
->insertion
== rawhtml
1330 || insertion_stack
->insertion
== rawxml
1331 || insertion_stack
->insertion
== rawtex
))
1335 const char *offender
= insertion_type_pname (insertion_stack
->insertion
);
1337 file_line_error (insertion_stack
->filename
,
1338 insertion_stack
->line_number
,
1339 _("No matching `%cend %s'"), COMMAND_PREFIX
,
1344 line_number
= real_line_number
;
1347 /* Insertion (environment) commands. */
1352 /* We start the blockquote element in the insertion. */
1353 begin_insertion (quotation
);
1359 if (docbook
&& current_insertion_type () == floatenv
)
1360 xml_begin_docbook_float (FLOATEXAMPLE
);
1364 /* Rollback previous newlines. These occur between
1365 </para> and <example>. */
1366 if (output_paragraph
[output_paragraph_offset
-1] == '\n')
1367 output_paragraph_offset
--;
1369 xml_insert_element (EXAMPLE
, START
);
1371 /* Make sure example text is starting on a new line
1372 for improved readability. */
1377 begin_insertion (example
);
1381 cm_smallexample (void)
1383 if (docbook
&& current_insertion_type () == floatenv
)
1384 xml_begin_docbook_float (FLOATEXAMPLE
);
1388 /* See cm_example comments about newlines. */
1389 if (output_paragraph
[output_paragraph_offset
-1] == '\n')
1390 output_paragraph_offset
--;
1391 xml_insert_element (SMALLEXAMPLE
, START
);
1396 begin_insertion (smallexample
);
1402 if (docbook
&& current_insertion_type () == floatenv
)
1403 xml_begin_docbook_float (FLOATEXAMPLE
);
1407 /* See cm_example comments about newlines. */
1408 if (output_paragraph
[output_paragraph_offset
-1] == '\n')
1409 output_paragraph_offset
--;
1410 xml_insert_element (LISP
, START
);
1415 begin_insertion (lisp
);
1421 if (docbook
&& current_insertion_type () == floatenv
)
1422 xml_begin_docbook_float (FLOATEXAMPLE
);
1426 /* See cm_example comments about newlines. */
1427 if (output_paragraph
[output_paragraph_offset
-1] == '\n')
1428 output_paragraph_offset
--;
1429 xml_insert_element (SMALLLISP
, START
);
1434 begin_insertion (smalllisp
);
1440 if (docbook
&& current_insertion_type () == floatenv
)
1441 xml_begin_docbook_float (CARTOUCHE
);
1444 xml_insert_element (CARTOUCHE
, START
);
1445 begin_insertion (cartouche
);
1451 begin_insertion (copying
);
1454 /* Not an insertion, despite the name, but it goes with cm_copying. */
1456 cm_insert_copying (void)
1460 warning ("@copying not used before %s", command
);
1464 execute_string ("%s", copying_text
);
1469 /* Update output_position so that the node positions in the tag
1470 tables will take account of the copying text. */
1480 if (docbook
&& xml_in_bookinfo
)
1482 xml_insert_element (ABSTRACT
, START
);
1483 xml_in_abstract
= 1;
1487 /* See cm_example comments about newlines. */
1488 if (output_paragraph
[output_paragraph_offset
-1] == '\n')
1489 output_paragraph_offset
--;
1490 xml_insert_element (FORMAT
, START
);
1495 begin_insertion (format
);
1499 cm_smallformat (void)
1503 /* See cm_example comments about newlines. */
1504 if (output_paragraph
[output_paragraph_offset
-1] == '\n')
1505 output_paragraph_offset
--;
1506 xml_insert_element (SMALLFORMAT
, START
);
1511 begin_insertion (smallformat
);
1519 /* See cm_example comments about newlines. */
1520 if (output_paragraph
[output_paragraph_offset
-1] == '\n')
1521 output_paragraph_offset
--;
1522 xml_insert_element (DISPLAY
, START
);
1527 begin_insertion (display
);
1531 cm_smalldisplay (void)
1535 /* See cm_example comments about newlines. */
1536 if (output_paragraph
[output_paragraph_offset
-1] == '\n')
1537 output_paragraph_offset
--;
1538 xml_insert_element (SMALLDISPLAY
, START
);
1543 begin_insertion (smalldisplay
);
1549 if (html
|| xml
|| no_headers
)
1550 command_name_condition ();
1552 begin_insertion (direntry
);
1556 cm_documentdescription (void)
1559 begin_insertion (documentdescription
);
1563 xml_insert_element (DOCUMENTDESCRIPTION
, START
);
1564 begin_insertion (documentdescription
);
1568 command_name_condition ();
1575 begin_insertion (itemize
);
1578 /* Start an enumeration insertion of type TYPE. If the user supplied
1579 no argument on the line, then use DEFAULT_STRING as the initial string. */
1581 do_enumeration (int type
, char *default_string
)
1583 get_until_in_line (0, ".", &enumeration_arg
);
1584 canon_white (enumeration_arg
);
1586 if (!*enumeration_arg
)
1588 free (enumeration_arg
);
1589 enumeration_arg
= xstrdup (default_string
);
1592 if (!isdigit (*enumeration_arg
) && !isletter (*enumeration_arg
))
1594 warning (_("%s requires letter or digit"), insertion_type_pname (type
));
1599 default_string
= "1";
1602 enumeration_arg
= xstrdup (default_string
);
1604 begin_insertion (type
);
1610 do_enumeration (enumerate
, "1");
1613 /* Handle verbatim environment:
1614 find_end_verbatim == 0: process until end of file
1615 find_end_verbatim != 0: process until 'COMMAND_PREFIXend verbatim'
1618 We cannot simply copy input stream onto output stream; as the
1619 verbatim environment may be encapsulated in an @example environment,
1622 handle_verbatim_environment (int find_end_verbatim
)
1626 int save_filling_enabled
= filling_enabled
;
1627 int save_inhibit_paragraph_indentation
= inhibit_paragraph_indentation
;
1628 int save_escape_html
= escape_html
;
1630 if (!insertion_stack
)
1631 close_single_paragraph (); /* no blank lines if not at outer level */
1632 inhibit_paragraph_indentation
= 1;
1633 filling_enabled
= 0;
1634 in_fixed_width_font
++;
1635 last_char_was_newline
= 0;
1637 /* No indentation: this is verbatim after all
1638 If you want indent, enclose @verbatim in @example
1639 current_indent += default_indentation_increment;
1643 { /* If inside @example, we'll be preceded by the indentation
1644 already. Browsers will ignore those spaces because we're about
1645 to start another <pre> (don't ask me). So, wipe them out for
1646 cleanliness, and re-insert. */
1648 kill_self_indent (default_indentation_increment
);
1649 add_html_block_elt ("<pre class=\"verbatim\">");
1650 for (i
= current_indent
; i
> 0; i
--)
1655 xml_insert_element (VERBATIM
, START
);
1657 add_word ("<![CDATA[");
1660 while (input_text_offset
< input_text_length
)
1662 character
= curchar ();
1664 if (character
== '\n')
1667 /* Assume no newlines in END_VERBATIM. */
1668 else if (find_end_verbatim
&& (character
== COMMAND_PREFIX
) /* @ */
1669 && (input_text_length
- input_text_offset
> sizeof (END_VERBATIM
))
1670 && !strncmp (&input_text
[input_text_offset
+1], END_VERBATIM
,
1671 sizeof (END_VERBATIM
)-1))
1673 input_text_offset
+= sizeof (END_VERBATIM
);
1678 if (html
&& character
== '&' && escape_html
)
1680 else if (html
&& character
== '<' && escape_html
)
1683 add_char (character
);
1685 input_text_offset
++;
1688 if (find_end_verbatim
&& !seen_end
)
1689 warning (_("end of file inside verbatim block"));
1692 { /* See comments in example case above. */
1693 kill_self_indent (default_indentation_increment
);
1694 add_word ("</pre>");
1699 xml_insert_element (VERBATIM
, END
);
1700 escape_html
= save_escape_html
;
1703 in_fixed_width_font
--;
1704 filling_enabled
= save_filling_enabled
;
1705 inhibit_paragraph_indentation
= save_inhibit_paragraph_indentation
;
1711 handle_verbatim_environment (1);
1717 begin_insertion (table
);
1721 cm_multitable (void)
1723 begin_insertion (multitable
); /* @@ */
1729 begin_insertion (ftable
);
1735 begin_insertion (vtable
);
1741 begin_insertion (group
);
1744 /* Insert raw HTML (no escaping of `<' etc.). */
1749 begin_insertion (rawhtml
);
1751 command_name_condition ();
1758 begin_insertion (rawxml
);
1760 command_name_condition ();
1764 cm_docbook (int arg
)
1766 if (process_docbook
)
1767 begin_insertion (rawdocbook
);
1769 command_name_condition ();
1775 if (process_docbook
)
1776 begin_insertion (ifdocbook
);
1778 command_name_condition ();
1782 cm_ifnotdocbook (void)
1784 if (!process_docbook
)
1785 begin_insertion (ifnotdocbook
);
1787 command_name_condition ();
1794 begin_insertion (ifhtml
);
1796 command_name_condition ();
1803 begin_insertion (ifnothtml
);
1805 command_name_condition ();
1813 begin_insertion (ifinfo
);
1815 command_name_condition ();
1822 begin_insertion (ifnotinfo
);
1824 command_name_condition ();
1829 cm_ifplaintext (void)
1831 if (process_plaintext
)
1832 begin_insertion (ifplaintext
);
1834 command_name_condition ();
1838 cm_ifnotplaintext (void)
1840 if (!process_plaintext
)
1841 begin_insertion (ifnotplaintext
);
1843 command_name_condition ();
1851 begin_insertion (rawtex
);
1853 command_name_condition ();
1860 begin_insertion (iftex
);
1862 command_name_condition ();
1869 begin_insertion (ifnottex
);
1871 command_name_condition ();
1878 begin_insertion (ifxml
);
1880 command_name_condition ();
1887 begin_insertion (ifnotxml
);
1889 command_name_condition ();
1893 /* Generic xrefable block with a caption. */
1897 begin_insertion (floatenv
);
1901 cm_caption (int arg
)
1905 /* This is a no_op command for most formats, as we handle it during @float
1906 insertion. For XML though, we handle it here to keep document structure
1907 as close as possible, to the Texinfo source. */
1909 /* Everything is already handled at START. */
1913 /* Check if it's mislocated. */
1914 if (current_insertion_type () != floatenv
)
1915 line_error (_("@%s not meaningful outside `@float' environment"), command
);
1917 get_until_in_braces ("\n@end float", &temp
);
1921 int elt
= STREQ (command
, "shortcaption") ? SHORTCAPTION
: CAPTION
;
1922 xml_insert_element (elt
, START
);
1924 execute_string ("%s", temp
);
1925 xml_insert_element (elt
, END
);
1931 /* Begin an insertion where the lines are not filled or indented. */
1935 begin_insertion (flushleft
);
1938 /* Begin an insertion where the lines are not filled, and each line is
1939 forced to the right-hand side of the page. */
1941 cm_flushright (void)
1943 begin_insertion (flushright
);
1949 if (current_node
== NULL
&& !macro_expansion_output_stream
)
1951 warning (_("@menu seen before first @node, creating `Top' node"));
1952 warning (_("perhaps your @top node should be wrapped in @ifnottex rather than @ifinfo?"));
1953 /* Include @top command so we can construct the implicit node tree. */
1954 execute_string ("@node top\n@top Top\n");
1956 begin_insertion (menu
);
1960 cm_detailmenu (void)
1962 if (current_node
== NULL
&& !macro_expansion_output_stream
)
1963 { /* Problems anyway, @detailmenu should always be inside @menu. */
1964 warning (_("@detailmenu seen before first node, creating `Top' node"));
1965 execute_string ("@node top\n@top Top\n");
1967 begin_insertion (detailmenu
);
1970 /* Title page commands. */
1975 titlepage_cmd_present
= 1;
1976 if (xml
&& !docbook
)
1977 begin_insertion (titlepage
);
1979 command_name_condition ();
1986 get_rest_of_line (1, &rest
);
1988 if (is_in_insertion_of_type (quotation
))
1991 add_word_args ("— %s", rest
);
1994 /* FIXME Ideally, we should use an attribution element,
1995 but they are supposed to be at the start of quotation
1996 blocks. So to avoid looking ahead mess, let's just
1997 use mdash like HTML for now. */
1998 xml_insert_entity ("mdash");
2003 xml_insert_element (AUTHOR
, START
);
2005 xml_insert_element (AUTHOR
, END
);
2008 add_word_args ("-- %s", rest
);
2010 else if (is_in_insertion_of_type (titlepage
))
2012 if (xml
&& !docbook
)
2014 xml_insert_element (AUTHOR
, START
);
2016 xml_insert_element (AUTHOR
, END
);
2020 line_error (_("@%s not meaningful outside `@titlepage' and `@quotation' environments"),
2027 cm_titlepage_cmds (void)
2031 get_rest_of_line (1, &rest
);
2033 if (!is_in_insertion_of_type (titlepage
))
2034 line_error (_("@%s not meaningful outside `@titlepage' environment"),
2037 if (xml
&& !docbook
)
2041 if (STREQ (command
, "title"))
2043 else if (STREQ (command
, "subtitle"))
2046 xml_insert_element (elt
, START
);
2048 xml_insert_element (elt
, END
);
2054 /* End existing insertion block. */
2061 get_rest_of_line (0, &temp
);
2063 if (!insertion_level
)
2065 line_error (_("Unmatched `%c%s'"), COMMAND_PREFIX
, command
);
2070 line_error (_("`%c%s' needs something after it"), COMMAND_PREFIX
, command
);
2072 type
= find_type_from_name (temp
);
2074 if (type
== bad_type
)
2076 line_error (_("Bad argument `%s' to `@%s', using `%s'"),
2077 temp
, command
, insertion_type_pname (current_insertion_type ()));
2079 if (xml
&& type
== menu
) /* fixme */
2083 end_insertion (type
);
2087 /* @itemx, @item. */
2089 static int itemx_flag
= 0;
2091 /* Return whether CMD takes a brace-delimited {arg}. */
2093 command_needs_braces (char *cmd
)
2096 for (i
= 0; command_table
[i
].name
; i
++)
2098 if (STREQ (command_table
[i
].name
, cmd
))
2099 return command_table
[i
].argument_in_braces
== BRACE_ARGS
;
2102 return 0; /* macro or alias */
2109 char *rest_of_line
, *item_func
;
2111 /* Can only hack "@item" while inside of an insertion. */
2112 if (insertion_level
)
2114 INSERTION_ELT
*stack
= insertion_stack
;
2115 int original_input_text_offset
;
2118 original_input_text_offset
= input_text_offset
;
2120 get_rest_of_line (0, &rest_of_line
);
2121 item_func
= current_item_function ();
2123 /* Do the right thing depending on which insertion function is active. */
2125 switch (stack
->insertion
)
2129 /* Support text directly after the @item. */
2133 input_text_offset
= original_input_text_offset
;
2142 case ifnotplaintext
:
2155 stack
= stack
->next
;
2173 line_error (_("@%s not meaningful inside `@%s' block"),
2175 insertion_type_pname (current_insertion_type ()));
2182 line_error (_("@itemx not meaningful inside `%s' block"),
2183 insertion_type_pname (current_insertion_type ()));
2188 add_html_block_elt ("<li>");
2194 kill_self_indent (-1);
2195 filling_enabled
= indented_fill
= 1;
2197 if (current_item_function ())
2199 output_column
= current_indent
- 2;
2200 indent (output_column
);
2202 /* The item marker can be given with or without
2203 braces -- @bullet and @bullet{} are both ok.
2204 Or it might be something that doesn't take
2205 braces at all, such as "o" or "#" or "@ ".
2206 Thus, only supply braces if the item marker is
2207 a command, they haven't supplied braces
2208 themselves, and we know it needs them. */
2209 if (item_func
&& *item_func
)
2211 if (*item_func
== COMMAND_PREFIX
2212 && item_func
[strlen (item_func
) - 1] != '}'
2213 && command_needs_braces (item_func
+ 1))
2214 execute_string ("%s{}", item_func
);
2216 execute_string ("%s", item_func
);
2224 /* Special hack. This makes `close_paragraph' a no-op until
2225 `start_paragraph' has been called. */
2226 must_start_paragraph
= 1;
2229 /* Handle text directly after the @item. */
2233 input_text_offset
= original_input_text_offset
;
2242 { /* If nothing has been output since the last <dd>,
2243 remove the empty <dd> element. Some browsers render
2244 an extra empty line for <dd><dt>, which makes @itemx
2245 conversion look ugly. */
2246 rollback_empty_tag ("dd");
2248 /* Force the browser to render one blank line before
2249 each new @item in a table. But don't do that if
2250 this is the first <dt> after the <dl>, or if we are
2253 Note that there are some browsers which ignore <br>
2254 in this context, but I cannot find any way to force
2255 them all render exactly one blank line. */
2256 if (!itemx_flag
&& html_deflist_has_term
)
2257 add_html_block_elt ("<br>");
2259 /* We are about to insert a <dt>, so this <dl> has a term.
2260 Feel free to insert a <br> next time. :) */
2261 html_deflist_has_term
= 1;
2263 add_html_block_elt ("<dt>");
2264 if (item_func
&& *item_func
)
2265 execute_string ("%s{%s}", item_func
, rest_of_line
);
2267 execute_string ("%s", rest_of_line
);
2269 if (current_insertion_type () == ftable
)
2270 execute_string ("%cfindex %s\n", COMMAND_PREFIX
, rest_of_line
);
2272 if (current_insertion_type () == vtable
)
2273 execute_string ("%cvindex %s\n", COMMAND_PREFIX
, rest_of_line
);
2275 add_html_block_elt ("<dd>");
2277 else if (xml
) /* && docbook)*/ /* 05-08 */
2279 xml_begin_table_item ();
2281 if (!docbook
&& current_insertion_type () == ftable
)
2282 execute_string ("%cfindex %s\n", COMMAND_PREFIX
, rest_of_line
);
2284 if (!docbook
&& current_insertion_type () == vtable
)
2285 execute_string ("%cvindex %s\n", COMMAND_PREFIX
, rest_of_line
);
2287 if (item_func
&& *item_func
)
2288 execute_string ("%s{%s}", item_func
, rest_of_line
);
2290 execute_string ("%s", rest_of_line
);
2291 xml_continue_table_item ();
2295 /* We need this to determine if we have two @item's in a row
2296 (see test just below). */
2297 static int last_item_output_position
= 0;
2299 /* Get rid of extra characters. */
2300 kill_self_indent (-1);
2302 /* If we have one @item followed directly by another @item,
2303 we need to insert a blank line. This is not true for
2305 if (!itemx_flag
&& last_item_output_position
== output_position
)
2308 /* `close_paragraph' almost does what we want. The problem
2309 is when paragraph_is_open, and last_char_was_newline, and
2310 the last newline has been turned into a space, because
2311 filling_enabled. I handle it here. */
2312 if (last_char_was_newline
&& filling_enabled
&&
2317 #if defined (INDENT_PARAGRAPHS_IN_TABLE)
2318 /* Indent on a new line, but back up one indentation level. */
2320 int save
= inhibit_paragraph_indentation
;
2321 inhibit_paragraph_indentation
= 1;
2322 /* At this point, inserting any non-whitespace character will
2323 force the existing indentation to be output. */
2325 inhibit_paragraph_indentation
= save
;
2327 #else /* !INDENT_PARAGRAPHS_IN_TABLE */
2329 #endif /* !INDENT_PARAGRAPHS_IN_TABLE */
2331 output_paragraph_offset
--;
2332 kill_self_indent (default_indentation_increment
+ 1);
2334 /* Add item's argument to the line. */
2335 filling_enabled
= 0;
2336 if (item_func
&& *item_func
)
2337 execute_string ("%s{%s}", item_func
, rest_of_line
);
2339 execute_string ("%s", rest_of_line
);
2341 if (current_insertion_type () == ftable
)
2342 execute_string ("%cfindex %s\n", COMMAND_PREFIX
, rest_of_line
);
2343 else if (current_insertion_type () == vtable
)
2344 execute_string ("%cvindex %s\n", COMMAND_PREFIX
, rest_of_line
);
2346 /* Start a new line, and let start_paragraph ()
2347 do the indenting of it for you. */
2348 close_single_paragraph ();
2349 indented_fill
= filling_enabled
= 1;
2350 last_item_output_position
= output_position
;
2353 free (rest_of_line
);
2358 line_error (_("%c%s found outside of an insertion block"),
2359 COMMAND_PREFIX
, command
);
2371 int headitem_flag
= 0;