1 /* insertion.c -- insertions for Texinfo.
2 $Id: insertion.c,v 1.47 2002/04/01 14:01:36 karl Exp $
4 Copyright (C) 1998, 99, 2000, 01, 02 Free Software Foundation, Inc.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software Foundation,
18 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 #include "insertion.h"
28 /* Must match list in insertion.h. */
29 static char *insertion_type_names[] =
31 "cartouche", "copying", "defcv", "deffn", "defivar", "defmac",
32 "defmethod", "defop", "defopt", "defspec", "deftp", "deftypefn",
33 "deftypefun", "deftypeivar", "deftypemethod", "deftypeop",
34 "deftypevar", "deftypevr", "defun", "defvar", "defvr", "detailmenu",
35 "direntry", "display", "documentdescription", "enumerate", "example",
36 "flushleft", "flushright", "format", "ftable", "group", "ifclear",
37 "ifhtml", "ifinfo", "ifnothtml", "ifnotinfo", "ifnotplaintext", "ifnottex",
38 "ifplaintext", "ifset", "iftex", "itemize", "lisp", "menu",
39 "multitable", "quotation", "rawhtml", "rawtex", "smalldisplay",
40 "smallexample", "smallformat", "smalllisp", "verbatim", "table",
41 "tex", "vtable", "bad_type"
44 /* All nested environments. */
45 INSERTION_ELT *insertion_stack = NULL;
47 /* How deeply we're nested. */
48 int insertion_level = 0;
50 /* Set to 1 if we've processed (commentary) text in a @menu that
51 wasn't part of a menu item. */
52 int had_menu_commentary;
54 /* How to examine menu lines. */
55 int in_detailmenu = 0;
57 /* Whether to examine menu lines. */
60 /* Set to 1 if <p> is written in normal context.
61 Used for menu and itemize. */
64 static const char dl_tag[] = "<dl>\n";
65 extern void cm_insert_copying ();
69 init_insertion_stack ()
71 insertion_stack = NULL;
74 /* Return the type of the current insertion. */
75 static enum insertion_type
76 current_insertion_type ()
78 return insertion_level ? insertion_stack->insertion : bad_type;
81 /* Return the string which is the function to wrap around items, or NULL
82 if we're not in an environment where @item is ok. */
84 current_item_function ()
87 INSERTION_ELT *elt = insertion_stack;
89 /* Skip down through the stack until we find an insertion with an
90 itemize function defined, i.e., skip conditionals, @cartouche, etc. */
93 switch (elt->insertion)
95 /* This list should match the one in cm_item. */
118 /* item_function usually gets assigned the empty string. */
119 return done && (*elt->item_function) ? elt->item_function : NULL;
122 /* Parse the item marker function off the input. If result is just "@",
123 change it to "@ ", since "@" by itself is not a command. This makes
124 "@ ", "@\t", and "@\n" all the same, but their default meanings are
125 the same anyway, and let's not worry about supporting redefining them. */
130 get_rest_of_line (0, &item_function);
132 /* If we hit the end of text in get_rest_of_line, backing up
133 input pointer will cause the last character of the last line
134 be pushed back onto the input, which is wrong. */
135 if (input_text_offset < input_text_length)
136 backup_input_pointer ();
138 if (STREQ (item_function, "@"))
140 free (item_function);
141 item_function = xstrdup ("@ ");
144 return item_function;
147 /* Push the state of the current insertion on the stack. */
149 push_insertion (type, item_function)
150 enum insertion_type type;
153 INSERTION_ELT *new = xmalloc (sizeof (INSERTION_ELT));
155 new->item_function = item_function;
156 new->filling_enabled = filling_enabled;
157 new->indented_fill = indented_fill;
158 new->insertion = type;
159 new->line_number = line_number;
160 new->filename = xstrdup (input_filename);
161 new->inhibited = inhibit_paragraph_indentation;
162 new->in_fixed_width_font = in_fixed_width_font;
163 new->next = insertion_stack;
164 insertion_stack = new;
168 /* Pop the value on top of the insertion stack into the
173 INSERTION_ELT *temp = insertion_stack;
178 in_fixed_width_font = temp->in_fixed_width_font;
179 inhibit_paragraph_indentation = temp->inhibited;
180 filling_enabled = temp->filling_enabled;
181 indented_fill = temp->indented_fill;
182 free_and_clear (&(temp->item_function));
183 free_and_clear (&(temp->filename));
184 insertion_stack = insertion_stack->next;
189 /* Return a pointer to the print name of this
192 insertion_type_pname (type)
193 enum insertion_type type;
195 if ((int) type < (int) bad_type)
196 return insertion_type_names[(int) type];
198 return _("Broken-Type in insertion_type_pname");
201 /* Return the insertion_type associated with NAME.
202 If the type is not one of the known ones, return BAD_TYPE. */
204 find_type_from_name (name)
208 while (index < (int) bad_type)
210 if (STREQ (name, insertion_type_names[index]))
211 return (enum insertion_type) index;
212 if (index == rawhtml && STREQ (name, "html"))
214 if (index == rawtex && STREQ (name, "tex"))
222 defun_insertion (type)
223 enum insertion_type type;
230 || (type == defmethod)
235 || (type == deftypefn)
236 || (type == deftypefun)
237 || (type == deftypeivar)
238 || (type == deftypemethod)
239 || (type == deftypeop)
240 || (type == deftypevar)
241 || (type == deftypevr)
248 /* MAX_NS is the maximum nesting level for enumerations. I picked 100
249 which seemed reasonable. This doesn't control the number of items,
250 just the number of nested lists. */
251 #define max_stack_depth 100
252 #define ENUM_DIGITS 1
259 DIGIT_ALPHA enumstack[max_stack_depth];
260 int enumstack_offset = 0;
261 int current_enumval = 1;
262 int current_enumtype = ENUM_DIGITS;
263 char *enumeration_arg = NULL;
266 start_enumerating (at, type)
269 if ((enumstack_offset + 1) == max_stack_depth)
271 line_error (_("Enumeration stack overflow"));
274 enumstack[enumstack_offset].enumtype = current_enumtype;
275 enumstack[enumstack_offset].enumval = current_enumval;
277 current_enumval = at;
278 current_enumtype = type;
285 if (enumstack_offset < 0)
286 enumstack_offset = 0;
288 current_enumval = enumstack[enumstack_offset].enumval;
289 current_enumtype = enumstack[enumstack_offset].enumtype;
292 /* Place a letter or digits into the output stream. */
298 if (current_enumtype == ENUM_ALPHA)
300 if (current_enumval == ('z' + 1) || current_enumval == ('Z' + 1))
302 current_enumval = ((current_enumval - 1) == 'z' ? 'a' : 'A');
303 warning (_("lettering overflow, restarting at %c"), current_enumval);
305 sprintf (temp, "%c. ", current_enumval);
308 sprintf (temp, "%d. ", current_enumval);
310 indent (output_column += (current_indent - strlen (temp)));
321 if (isdigit (*enumeration_arg))
324 start = atoi (enumeration_arg);
326 else if (isupper (*enumeration_arg))
329 start = *enumeration_arg - 'A' + 1;
334 start = *enumeration_arg - 'a' + 1;
337 add_word_args ("<ol type=%c start=%d>\n", type, start);
340 /* Conditionally parse based on the current command name. */
342 command_name_condition ()
344 char *discarder = xmalloc (8 + strlen (command));
346 sprintf (discarder, "\n%cend %s", COMMAND_PREFIX, command);
347 discard_until (discarder);
348 discard_until ("\n");
353 /* This is where the work for all the "insertion" style
354 commands is done. A huge switch statement handles the
355 various setups, and generic code is on both sides. */
357 begin_insertion (type)
358 enum insertion_type type;
362 if (defun_insertion (type))
364 push_insertion (type, xstrdup (""));
369 push_insertion (type, get_item_function ());
378 filling_enabled = no_indent = 0;
379 inhibit_paragraph_indentation = 1;
383 had_menu_commentary = 1;
385 else if (!no_headers && !xml)
386 add_word ("* Menu:\n");
389 xml_insert_element (MENU, START);
391 next_menu_item_number = 1;
393 in_fixed_width_font++;
403 filling_enabled = no_indent = 0;
404 inhibit_paragraph_indentation = 1;
409 in_fixed_width_font++;
414 close_single_paragraph ();
415 filling_enabled = no_indent = 0;
416 inhibit_paragraph_indentation = 1;
417 insert_string ("START-INFO-DIR-ENTRY\n");
420 case documentdescription:
424 int save_fixed_width;
426 discard_until ("\n"); /* ignore the @documentdescription line */
427 start_of_end = get_until ("\n@end documentdescription", &desc);
428 save_fixed_width = in_fixed_width_font;
430 in_fixed_width_font = 0;
431 document_description = expansion (desc, 0);
434 in_fixed_width_font = save_fixed_width;
435 input_text_offset = start_of_end; /* go back to the @end to match */
441 /* Save the copying text away for @insertcopying,
442 typically used on the back of the @titlepage (for TeX) and
443 the Top node (for info/html). */
447 discard_until ("\n"); /* ignore remainder of @copying line */
448 start_of_end = get_until ("\n@end copying", &text);
450 /* include all the output-format-specific markup. */
451 copying_text = full_expansion (text, 0);
454 input_text_offset = start_of_end; /* go back to the @end to match */
457 /* For info, output the copying text right away, so it will end up
458 in the header of the Info file, before the first node, and thus
459 get copied automatically to all the split files. For xml, also
460 output it right away since xml output is never split.
461 For html, we output it specifically in html_output_head.
462 For plain text, there's no way to hide it, so the author must
463 use @insertcopying in the desired location. */
464 if (!html && !no_headers)
465 cm_insert_copying ();
469 /* @quotation does filling (@display doesn't). */
471 add_word ("<blockquote>\n");
474 /* with close_single_paragraph, we get no blank line above
477 last_char_was_newline = no_indent = 0;
478 indented_fill = filling_enabled = 1;
479 inhibit_paragraph_indentation = 1;
481 current_indent += default_indentation_increment;
490 /* Like @display but without indentation. */
493 close_single_paragraph ();
494 inhibit_paragraph_indentation = 1;
495 in_fixed_width_font++;
497 last_char_was_newline = 0;
500 /* Kludge alert: if <pre> is followed by a newline, IE3
501 renders an extra blank line before the pre-formatted block.
502 Other browsers seem to not mind one way or the other. */
503 add_word ("<br><pre>");
505 if (type != format && type != smallformat)
506 current_indent += default_indentation_increment;
517 close_single_paragraph ();
518 current_indent += default_indentation_increment;
519 filling_enabled = indented_fill = 1;
520 #if defined (INDENT_PARAGRAPHS_IN_TABLE)
521 inhibit_paragraph_indentation = 0;
523 inhibit_paragraph_indentation = 1;
524 #endif /* !INDENT_PARAGRAPHS_IN_TABLE */
526 /* Make things work for losers who forget the itemize syntax. */
529 if (!(*insertion_stack->item_function))
531 free (insertion_stack->item_function);
532 insertion_stack->item_function = xstrdup ("@bullet");
536 if (!*insertion_stack->item_function)
538 line_error (_("%s requires an argument: the formatter for %citem"),
539 insertion_type_pname (type), COMMAND_PREFIX);
553 xml_begin_table (type, insertion_stack->item_function);
557 close_single_paragraph ();
559 #if defined (INDENT_PARAGRAPHS_IN_TABLE)
560 inhibit_paragraph_indentation = 0;
562 inhibit_paragraph_indentation = 1;
563 #endif /* !INDENT_PARAGRAPHS_IN_TABLE */
565 current_indent += default_indentation_increment;
566 filling_enabled = indented_fill = 1;
572 xml_begin_enumerate (enumeration_arg);
574 if (isdigit (*enumeration_arg))
575 start_enumerating (atoi (enumeration_arg), ENUM_DIGITS);
577 start_enumerating (*enumeration_arg, ENUM_ALPHA);
580 /* @group does nothing special in makeinfo. */
582 /* Only close the paragraph if we are not inside of an
583 @example-like environment. */
585 xml_insert_element (GROUP, START);
586 else if (!insertion_stack->next
587 || (insertion_stack->next->insertion != display
588 && insertion_stack->next->insertion != smalldisplay
589 && insertion_stack->next->insertion != example
590 && insertion_stack->next->insertion != smallexample
591 && insertion_stack->next->insertion != lisp
592 && insertion_stack->next->insertion != smalllisp
593 && insertion_stack->next->insertion != format
594 && insertion_stack->next->insertion != smallformat
595 && insertion_stack->next->insertion != flushleft
596 && insertion_stack->next->insertion != flushright))
597 close_single_paragraph ();
600 /* Insertions that are no-ops in info, but do something in TeX. */
640 inhibit_paragraph_indentation = 1;
641 filling_enabled = indented_fill = 1;
642 current_indent += default_indentation_increment;
647 close_single_paragraph ();
648 inhibit_paragraph_indentation = 1;
649 filling_enabled = indented_fill = no_indent = 0;
651 add_word ("<div align=\"left\">");
655 close_single_paragraph ();
656 filling_enabled = indented_fill = no_indent = 0;
657 inhibit_paragraph_indentation = 1;
660 add_word ("<div align=\"right\">");
664 line_error ("begin_insertion internal error: type=%d", type);
669 discard_until ("\n");
672 /* Try to end the insertion with the specified TYPE. With a value of
673 `bad_type', TYPE gets translated to match the value currently on top
674 of the stack. Otherwise, if TYPE doesn't match the top of the
675 insertion stack, give error. */
678 enum insertion_type type;
680 enum insertion_type temp_type;
682 if (!insertion_level)
685 temp_type = current_insertion_type ();
687 if (type == bad_type)
690 if (type != temp_type)
693 (_("`@end' expected `%s', but saw `%s'"),
694 insertion_type_pname (temp_type), insertion_type_pname (type));
705 case documentdescription:
708 xml_insert_element (COPYING, END);
711 xml_insert_element (QUOTATION, END);
714 xml_insert_element (EXAMPLE, END);
717 xml_insert_element (SMALLEXAMPLE, END);
720 xml_insert_element (LISP, END);
723 xml_insert_element (SMALLLISP, END);
726 xml_insert_element (CARTOUCHE, END);
729 xml_insert_element (FORMAT, END);
732 xml_insert_element (SMALLFORMAT, END);
735 xml_insert_element (DISPLAY, END);
738 xml_insert_element (SMALLDISPLAY, END);
744 xml_end_table (type);
747 xml_end_enumerate (type);
750 xml_insert_element (GROUP, END);
756 /* Insertions which have no effect on paragraph formatting. */
758 case documentdescription:
777 in_detailmenu--; /* No longer hacking menus. */
781 close_insertion_paragraph ();
785 case direntry: /* Eaten if html. */
786 insert_string ("END-INFO-DIR-ENTRY\n\n");
787 close_insertion_paragraph ();
791 in_menu--; /* No longer hacking menus. */
793 add_word ("</ul>\n");
794 else if (!no_headers)
795 close_insertion_paragraph ();
804 close_insertion_paragraph ();
805 current_indent -= default_indentation_increment;
807 add_word ("</ol>\n");
812 add_word ("</div>\n");
813 close_insertion_paragraph ();
818 close_insertion_paragraph ();
830 /* @format and @smallformat are the only fixed_width insertion
831 without a change in indentation. */
832 if (type != format && type != smallformat)
833 current_indent -= default_indentation_increment;
836 add_word (type == quotation ? "</blockquote>\n" : "</pre>\n");
838 /* The ending of one of these insertions always marks the
839 start of a new paragraph. */
840 close_insertion_paragraph ();
846 current_indent -= default_indentation_increment;
848 add_word ("</dl>\n");
852 current_indent -= default_indentation_increment;
854 add_word ("</ul>\n");
855 close_insertion_paragraph ();
861 add_word ("</div>\n");
862 close_insertion_paragraph ();
865 /* Handle the @defun insertions with this default clause. */
868 enum insertion_type base_type;
870 if (type < defcv || type > defvr)
871 line_error ("end_insertion internal error: type=%d", type);
873 base_type = get_base_type (type);
887 /* close the tables which has been opened in defun.c */
888 add_word ("</td></tr>\n</table>\n");
890 } /* switch (base_type)... */
892 current_indent -= default_indentation_increment;
893 close_insertion_paragraph ();
899 if (current_indent < 0)
900 line_error ("end_insertion internal error: current indent=%d",
904 /* Insertions cannot cross certain boundaries, such as node beginnings. In
905 code that creates such boundaries, you should call `discard_insertions'
906 before doing anything else. It prints the errors for you, and cleans up
909 With nonzero SPECIALS_OK argument, allows unmatched
910 @if... conditionals, otherwise not. This is because conditionals can
911 cross node boundaries. Always happens with the @top node, for example. */
913 discard_insertions (specials_ok)
916 int real_line_number = line_number;
917 while (insertion_stack)
920 && ((ifclear <= insertion_stack->insertion
921 && insertion_stack->insertion <= iftex)
922 || insertion_stack->insertion == rawhtml
923 || insertion_stack->insertion == rawtex))
927 char *offender = insertion_type_pname (insertion_stack->insertion);
929 file_line_error (insertion_stack->filename,
930 insertion_stack->line_number,
931 _("No matching `%cend %s'"), COMMAND_PREFIX,
936 line_number = real_line_number;
939 /* Insertion (environment) commands. */
945 xml_insert_element (QUOTATION, START);
946 begin_insertion (quotation);
953 xml_insert_element (EXAMPLE, START);
954 begin_insertion (example);
961 xml_insert_element (SMALLEXAMPLE, START);
962 begin_insertion (smallexample);
969 xml_insert_element (LISP, START);
970 begin_insertion (lisp);
977 xml_insert_element (SMALLLISP, START);
978 begin_insertion (smalllisp);
985 xml_insert_element (CARTOUCHE, START);
986 begin_insertion (cartouche);
993 xml_insert_element (COPYING, START);
994 begin_insertion (copying);
997 /* Not an insertion, despite the name, but it goes with cm_copying. */
1002 { /* insert_string rather than add_word because we've already done
1003 full expansion on copying_text when we saved it. */
1004 insert_string (copying_text);
1013 xml_insert_element (FORMAT, START);
1014 begin_insertion (format);
1021 xml_insert_element (SMALLFORMAT, START);
1022 begin_insertion (smallformat);
1029 xml_insert_element (DISPLAY, START);
1030 begin_insertion (display);
1037 xml_insert_element (SMALLDISPLAY, START);
1038 begin_insertion (smalldisplay);
1045 command_name_condition ();
1047 begin_insertion (direntry);
1051 cm_documentdescription ()
1054 begin_insertion (documentdescription);
1056 command_name_condition ();
1063 begin_insertion (itemize);
1066 /* Start an enumeration insertion of type TYPE. If the user supplied
1067 no argument on the line, then use DEFAULT_STRING as the initial string. */
1069 do_enumeration (type, default_string)
1071 char *default_string;
1073 get_until_in_line (0, ".", &enumeration_arg);
1074 canon_white (enumeration_arg);
1076 if (!*enumeration_arg)
1078 free (enumeration_arg);
1079 enumeration_arg = xstrdup (default_string);
1082 if (!isdigit (*enumeration_arg) && !isletter (*enumeration_arg))
1084 warning (_("%s requires letter or digit"), insertion_type_pname (type));
1089 default_string = "1";
1092 enumeration_arg = xstrdup (default_string);
1094 begin_insertion (type);
1100 do_enumeration (enumerate, "1");
1103 /* Handle verbatim environment:
1104 find_end_verbatim == 0: process until end of file
1105 find_end_verbatim != 0: process until 'COMMAND_PREFIXend verbatim'
1108 We cannot simply copy input stream onto output stream; as the
1109 verbatim environment may be encapsulated in an @example environment,
1112 handle_verbatim_environment (find_end_verbatim)
1113 int find_end_verbatim;
1117 int save_filling_enabled = filling_enabled;
1118 int save_inhibit_paragraph_indentation = inhibit_paragraph_indentation;
1120 close_single_paragraph ();
1121 inhibit_paragraph_indentation = 1;
1122 filling_enabled = 0;
1123 in_fixed_width_font++;
1124 last_char_was_newline = 0;
1126 /* No indentation: this is verbatim after all
1127 If you want indent, enclose @verbatim in @example
1128 current_indent += default_indentation_increment;
1134 while (input_text_offset < input_text_length)
1136 character = curchar ();
1138 if (character == '\n')
1141 Assume no newlines in END_VERBATIM
1143 else if (find_end_verbatim && (character == COMMAND_PREFIX) /* @ */
1144 && (input_text_length - input_text_offset > sizeof (END_VERBATIM))
1145 && !strncmp (&input_text[input_text_offset+1], END_VERBATIM,
1146 sizeof (END_VERBATIM)-1))
1148 input_text_offset += sizeof (END_VERBATIM);
1153 add_char (character);
1154 input_text_offset++;
1157 if (find_end_verbatim && !seen_end)
1158 warning (_("end of file inside verbatim block"));
1161 add_word ("</pre>");
1163 in_fixed_width_font--;
1164 filling_enabled = save_filling_enabled;
1165 inhibit_paragraph_indentation = save_inhibit_paragraph_indentation;
1171 handle_verbatim_environment (1);
1177 begin_insertion (table);
1183 begin_insertion (multitable); /* @@ */
1189 begin_insertion (ftable);
1195 begin_insertion (vtable);
1201 begin_insertion (group);
1204 /* Insert raw HTML (no escaping of `<' etc.). */
1209 begin_insertion (rawhtml);
1211 command_name_condition ();
1218 begin_insertion (ifhtml);
1220 command_name_condition ();
1227 begin_insertion (ifnothtml);
1229 command_name_condition ();
1237 begin_insertion (ifinfo);
1239 command_name_condition ();
1246 begin_insertion (ifnotinfo);
1248 command_name_condition ();
1255 if (process_plaintext)
1256 begin_insertion (ifplaintext);
1258 command_name_condition ();
1262 cm_ifnotplaintext ()
1264 if (!process_plaintext)
1265 begin_insertion (ifnotplaintext);
1267 command_name_condition ();
1275 begin_insertion (rawtex);
1277 command_name_condition ();
1284 begin_insertion (iftex);
1286 command_name_condition ();
1293 begin_insertion (ifnottex);
1295 command_name_condition ();
1298 /* Begin an insertion where the lines are not filled or indented. */
1302 begin_insertion (flushleft);
1305 /* Begin an insertion where the lines are not filled, and each line is
1306 forced to the right-hand side of the page. */
1310 begin_insertion (flushright);
1316 if (current_node == NULL)
1318 warning (_("@menu seen before first @node, creating `Top' node"));
1319 warning (_("perhaps your @top node should be wrapped in @ifnottex rather than @ifinfo?"));
1320 /* Include @top command so we can construct the implicit node tree. */
1321 execute_string ("@node top\n@top Top\n");
1323 begin_insertion (menu);
1329 if (current_node == NULL)
1330 { /* Problems anyway, @detailmenu should always be inside @menu. */
1331 warning (_("@detailmenu seen before first node, creating `Top' node"));
1332 execute_string ("@node top\n@top Top\n");
1334 begin_insertion (detailmenu);
1337 /* End existing insertion block. */
1342 enum insertion_type type;
1344 if (!insertion_level)
1346 line_error (_("Unmatched `%c%s'"), COMMAND_PREFIX, command);
1350 get_rest_of_line (0, &temp);
1353 line_error (_("`%c%s' needs something after it"), COMMAND_PREFIX, command);
1355 type = find_type_from_name (temp);
1357 if (type == bad_type)
1359 line_error (_("Bad argument to `%s', `%s', using `%s'"),
1360 command, temp, insertion_type_pname (current_insertion_type ()));
1362 if (xml && type == menu) /* fixme */
1366 end_insertion (type);
1370 /* @itemx, @item. */
1372 static int itemx_flag = 0;
1374 /* Return whether CMD takes a brace-delimited {arg}. */
1376 command_needs_braces (cmd)
1380 for (i = 0; command_table[i].name; i++)
1382 if (STREQ (command_table[i].name, cmd))
1383 return command_table[i].argument_in_braces == BRACE_ARGS;
1386 return 0; /* macro or alias */
1393 char *rest_of_line, *item_func;
1395 /* Can only hack "@item" while inside of an insertion. */
1396 if (insertion_level)
1398 INSERTION_ELT *stack = insertion_stack;
1399 int original_input_text_offset;
1402 original_input_text_offset = input_text_offset;
1404 get_rest_of_line (0, &rest_of_line);
1405 item_func = current_item_function ();
1407 /* Do the right thing depending on which insertion function is active. */
1409 switch (stack->insertion)
1413 /* Support text directly after the @item. */
1417 input_text_offset = original_input_text_offset;
1426 case ifnotplaintext:
1435 stack = stack->next;
1453 line_error (_("@%s not meaningful inside `@%s' block"),
1455 insertion_type_pname (current_insertion_type ()));
1462 line_error (_("@itemx not meaningful inside `%s' block"),
1463 insertion_type_pname (current_insertion_type ()));
1481 kill_self_indent (-1);
1482 filling_enabled = indented_fill = 1;
1484 if (current_item_function ())
1486 output_column = current_indent - 2;
1487 indent (output_column);
1489 /* The item marker can be given with or without
1490 braces -- @bullet and @bullet{} are both ok.
1491 Or it might be something that doesn't take
1492 braces at all, such as "o" or "#" or "@ ".
1493 Thus, only supply braces if the item marker is
1494 a command, they haven't supplied braces
1495 themselves, and we know it needs them. */
1496 if (item_func && *item_func)
1498 if (*item_func == COMMAND_PREFIX
1499 && item_func[strlen (item_func) - 1] != '}'
1500 && command_needs_braces (item_func + 1))
1501 execute_string ("%s{}", item_func);
1503 execute_string ("%s", item_func);
1511 /* Special hack. This makes `close_paragraph' a no-op until
1512 `start_paragraph' has been called. */
1513 must_start_paragraph = 1;
1516 /* Handle text directly after the @item. */
1520 input_text_offset = original_input_text_offset;
1530 static int last_html_output_position = 0;
1532 /* If nothing has been output since the last <dd>,
1533 remove the empty <dd> element. Some browsers render
1534 an extra empty line for <dd><dt>, which makes @itemx
1535 conversion look ugly. */
1536 if (last_html_output_position == output_position
1537 && strncmp ((char *) output_paragraph, "<dd>",
1538 output_paragraph_offset) == 0)
1539 output_paragraph_offset = 0;
1541 /* Force the browser to render one blank line before
1542 each new @item in a table. But don't do that unless
1543 this is the first <dt> after the <dl>, or if we are
1546 Note that there are some browsers which ignore <br>
1547 in this context, but I cannot find any way to force
1548 them all render exactly one blank line. */
1550 && strncmp ((char *) output_paragraph
1551 + output_paragraph_offset - sizeof (dl_tag) + 1,
1552 dl_tag, sizeof (dl_tag) - 1) != 0)
1556 if (item_func && *item_func)
1557 execute_string ("%s{%s}", item_func, rest_of_line);
1559 execute_string ("%s", rest_of_line);
1561 if (current_insertion_type () == ftable)
1562 execute_string ("%cfindex %s\n", COMMAND_PREFIX, rest_of_line);
1564 if (current_insertion_type () == vtable)
1565 execute_string ("%cvindex %s\n", COMMAND_PREFIX, rest_of_line);
1566 /* Make sure output_position is updated, so we could
1568 close_single_paragraph ();
1569 last_html_output_position = output_position;
1572 else if (xml) /* && docbook)*/ /* 05-08 */
1574 xml_begin_table_item ();
1575 if (item_func && *item_func)
1576 execute_string ("%s{%s}", item_func, rest_of_line);
1578 execute_string ("%s", rest_of_line);
1579 xml_continue_table_item ();
1583 /* We need this to determine if we have two @item's in a row
1584 (see test just below). */
1585 static int last_item_output_position = 0;
1587 /* Get rid of extra characters. */
1588 kill_self_indent (-1);
1590 /* If we have one @item followed directly by another @item,
1591 we need to insert a blank line. This is not true for
1593 if (!itemx_flag && last_item_output_position == output_position)
1596 /* `close_paragraph' almost does what we want. The problem
1597 is when paragraph_is_open, and last_char_was_newline, and
1598 the last newline has been turned into a space, because
1599 filling_enabled. I handle it here. */
1600 if (last_char_was_newline && filling_enabled &&
1605 #if defined (INDENT_PARAGRAPHS_IN_TABLE)
1606 /* Indent on a new line, but back up one indentation level. */
1608 int save = inhibit_paragraph_indentation;
1609 inhibit_paragraph_indentation = 1;
1610 /* At this point, inserting any non-whitespace character will
1611 force the existing indentation to be output. */
1613 inhibit_paragraph_indentation = save;
1615 #else /* !INDENT_PARAGRAPHS_IN_TABLE */
1617 #endif /* !INDENT_PARAGRAPHS_IN_TABLE */
1619 output_paragraph_offset--;
1620 kill_self_indent (default_indentation_increment + 1);
1622 /* Add item's argument to the line. */
1623 filling_enabled = 0;
1624 if (item_func && *item_func)
1625 execute_string ("%s{%s}", item_func, rest_of_line);
1627 execute_string ("%s", rest_of_line);
1629 if (current_insertion_type () == ftable)
1630 execute_string ("%cfindex %s\n", COMMAND_PREFIX, rest_of_line);
1631 else if (current_insertion_type () == vtable)
1632 execute_string ("%cvindex %s\n", COMMAND_PREFIX, rest_of_line);
1634 /* Start a new line, and let start_paragraph ()
1635 do the indenting of it for you. */
1636 close_single_paragraph ();
1637 indented_fill = filling_enabled = 1;
1638 last_item_output_position = output_position;
1641 free (rest_of_line);
1646 line_error (_("%c%s found outside of an insertion block"),
1647 COMMAND_PREFIX, command);