1 /* cmds.c -- Texinfo commands.
2    $Id: cmds.c,v 1.55 2004/12/14 00:15:36 karl Exp $
3 
4    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software
5    Foundation, Inc.
6 
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 2, or (at your option)
10    any later version.
11 
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.
16 
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software Foundation,
19    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
20 
21 #include "system.h"
22 #include "cmds.h"
23 #include "defun.h"
24 #include "files.h"
25 #include "footnote.h"
26 #include "html.h"
27 #include "insertion.h"
28 #include "lang.h"
29 #include "macro.h"
30 #include "makeinfo.h"
31 #include "node.h"
32 #include "sectioning.h"
33 #include "toc.h"
34 #include "xml.h"
35 
36 #ifdef TM_IN_SYS_TIME
37 #include <sys/time.h>
38 #else
39 #include <time.h>
40 #endif
41 
42 __RCSID("$MirOS: src/gnu/usr.bin/texinfo/makeinfo/cmds.c,v 1.4 2009/12/27 17:58:40 tg Exp $");
43 
44 /* Options. */
45 static void cm_exampleindent (void),
46      cm_firstparagraphindent (void),
47      cm_paragraphindent (void),
48      cm_novalidate (void);
49 
50 /* Internals. */
51 static void cm_obsolete (int arg, int start, int end),
52      not_fixed_width (int arg);
53 
54 /* The dispatch table.  */
55 COMMAND command_table[] = {
56   { "\t", insert_space, NO_BRACE_ARGS },
57   { "\n", insert_space, NO_BRACE_ARGS },
58   { " ", insert_space, NO_BRACE_ARGS },
59   { "!", cm_punct, NO_BRACE_ARGS },
60   { "\"", cm_accent_umlaut, MAYBE_BRACE_ARGS },
61   { "'", cm_accent_acute, MAYBE_BRACE_ARGS },
62   { "*", cm_asterisk, NO_BRACE_ARGS },
63   { ",", cm_accent_cedilla, MAYBE_BRACE_ARGS },
64   { "-", cm_no_op, NO_BRACE_ARGS },
65   { ".", cm_punct, NO_BRACE_ARGS },
66   { "/", cm_no_op, NO_BRACE_ARGS },
67   { ":", cm_colon, NO_BRACE_ARGS },
68   { "=", cm_accent, MAYBE_BRACE_ARGS },
69   { "?", cm_punct, NO_BRACE_ARGS },
70   { "@", insert_self, NO_BRACE_ARGS },
71   { "\\", insert_self, NO_BRACE_ARGS },
72   { "^", cm_accent_hat, MAYBE_BRACE_ARGS },
73   { "`", cm_accent_grave, MAYBE_BRACE_ARGS },
74   { "{", insert_self, NO_BRACE_ARGS },
75   { "|", cm_no_op, NO_BRACE_ARGS },
76   { "}", insert_self, NO_BRACE_ARGS },
77   { "~", cm_accent_tilde, MAYBE_BRACE_ARGS },
78   { "AA", cm_special_char, BRACE_ARGS },
79   { "AE", cm_special_char, BRACE_ARGS },
80   { "H", cm_accent, MAYBE_BRACE_ARGS },
81   { "L", cm_special_char, BRACE_ARGS },
82   { "LaTeX", cm_LaTeX, BRACE_ARGS },
83   { "O", cm_special_char, BRACE_ARGS },
84   { "OE", cm_special_char, BRACE_ARGS },
85   { "TeX", cm_TeX, BRACE_ARGS },
86   { "aa", cm_special_char, BRACE_ARGS },
87   { "abbr", cm_abbr, BRACE_ARGS },
88   { "acronym", cm_acronym, BRACE_ARGS },
89   { "ae", cm_special_char, BRACE_ARGS },
90   { "afivepaper", cm_ignore_line, NO_BRACE_ARGS },
91   { "afourlatex", cm_ignore_line, NO_BRACE_ARGS },
92   { "afourpaper", cm_ignore_line, NO_BRACE_ARGS },
93   { "afourwide", cm_ignore_line, NO_BRACE_ARGS },
94   { "alias", cm_alias, NO_BRACE_ARGS },
95   { "anchor", cm_anchor, BRACE_ARGS },
96   { "appendix", cm_appendix, NO_BRACE_ARGS },
97   { "appendixsection", cm_appendixsec, NO_BRACE_ARGS },
98   { "appendixsec", cm_appendixsec, NO_BRACE_ARGS },
99   { "appendixsubsec", cm_appendixsubsec, NO_BRACE_ARGS },
100   { "appendixsubsubsec", cm_appendixsubsubsec, NO_BRACE_ARGS },
101   { "asis", cm_no_op, BRACE_ARGS },
102   { "author", cm_author, NO_BRACE_ARGS },
103   { "b", cm_b, BRACE_ARGS },
104   { "bullet", cm_bullet, BRACE_ARGS },
105   { "bye", cm_bye, NO_BRACE_ARGS },
106   { "c", cm_comment, NO_BRACE_ARGS },
107   { "caption", cm_caption, BRACE_ARGS },
108   { "cartouche", cm_cartouche, NO_BRACE_ARGS },
109   { "center", cm_center, NO_BRACE_ARGS },
110   { "centerchap", cm_unnumbered, NO_BRACE_ARGS },
111   { "chapheading", cm_chapheading, NO_BRACE_ARGS },
112   { "chapter", cm_chapter, NO_BRACE_ARGS },
113   { "cindex", cm_cindex, NO_BRACE_ARGS },
114   { "cite", cm_cite, BRACE_ARGS },
115   { "clear", cm_clear, NO_BRACE_ARGS },
116   { "code", cm_code, BRACE_ARGS },
117   { "comma", cm_comma, BRACE_ARGS },
118   { "command", cm_code, BRACE_ARGS },
119   { "comment", cm_comment, NO_BRACE_ARGS },
120   { "contents", cm_contents, NO_BRACE_ARGS },
121   { "copying", cm_copying, NO_BRACE_ARGS },
122   { "copyright", cm_copyright, BRACE_ARGS },
123   { "ctrl", cm_obsolete, BRACE_ARGS },
124   { "defcodeindex", cm_defcodeindex, NO_BRACE_ARGS },
125   { "defcv", cm_defun, NO_BRACE_ARGS },
126   { "defcvx", cm_defun, NO_BRACE_ARGS },
127   { "deffn", cm_defun, NO_BRACE_ARGS },
128   { "deffnx", cm_defun, NO_BRACE_ARGS },
129   { "defindex", cm_defindex, NO_BRACE_ARGS },
130   { "definfoenclose", cm_definfoenclose, NO_BRACE_ARGS },
131   { "defivar", cm_defun, NO_BRACE_ARGS },
132   { "defivarx", cm_defun, NO_BRACE_ARGS },
133   { "defmac", cm_defun, NO_BRACE_ARGS },
134   { "defmacx", cm_defun, NO_BRACE_ARGS },
135   { "defmethod", cm_defun, NO_BRACE_ARGS },
136   { "defmethodx", cm_defun, NO_BRACE_ARGS },
137   { "defop", cm_defun, NO_BRACE_ARGS },
138   { "defopt", cm_defun, NO_BRACE_ARGS },
139   { "defoptx", cm_defun, NO_BRACE_ARGS },
140   { "defopx", cm_defun, NO_BRACE_ARGS },
141   { "defspec", cm_defun, NO_BRACE_ARGS },
142   { "defspecx", cm_defun, NO_BRACE_ARGS },
143   { "deftp", cm_defun, NO_BRACE_ARGS },
144   { "deftpx", cm_defun, NO_BRACE_ARGS },
145   { "deftypecv", cm_defun, NO_BRACE_ARGS },
146   { "deftypecvx", cm_defun, NO_BRACE_ARGS },
147   { "deftypefn", cm_defun, NO_BRACE_ARGS },
148   { "deftypefnx", cm_defun, NO_BRACE_ARGS },
149   { "deftypefun", cm_defun, NO_BRACE_ARGS },
150   { "deftypefunx", cm_defun, NO_BRACE_ARGS },
151   { "deftypeivar", cm_defun, NO_BRACE_ARGS },
152   { "deftypeivarx", cm_defun, NO_BRACE_ARGS },
153   { "deftypemethod", cm_defun, NO_BRACE_ARGS },
154   { "deftypemethodx", cm_defun, NO_BRACE_ARGS },
155   { "deftypeop", cm_defun, NO_BRACE_ARGS },
156   { "deftypeopx", cm_defun, NO_BRACE_ARGS },
157   { "deftypevar", cm_defun, NO_BRACE_ARGS },
158   { "deftypevarx", cm_defun, NO_BRACE_ARGS },
159   { "deftypevr", cm_defun, NO_BRACE_ARGS },
160   { "deftypevrx", cm_defun, NO_BRACE_ARGS },
161   { "defun", cm_defun, NO_BRACE_ARGS },
162   { "defunx", cm_defun, NO_BRACE_ARGS },
163   { "defvar", cm_defun, NO_BRACE_ARGS },
164   { "defvarx", cm_defun, NO_BRACE_ARGS },
165   { "defvr", cm_defun, NO_BRACE_ARGS },
166   { "defvrx", cm_defun, NO_BRACE_ARGS },
167   { "detailmenu", cm_detailmenu, NO_BRACE_ARGS },
168   { "dfn", cm_dfn, BRACE_ARGS },
169   { "dircategory", cm_dircategory, NO_BRACE_ARGS },
170   { "direntry", cm_direntry, NO_BRACE_ARGS },
171   { "display", cm_display, NO_BRACE_ARGS },
172   { "dmn", cm_dmn, BRACE_ARGS },
173   { "docbook", cm_docbook, NO_BRACE_ARGS },
174   { "documentdescription", cm_documentdescription, NO_BRACE_ARGS },
175   { "documentencoding", cm_documentencoding, NO_BRACE_ARGS },
176   { "documentlanguage", cm_documentlanguage, NO_BRACE_ARGS },
177   { "dotaccent", cm_accent, MAYBE_BRACE_ARGS },
178   { "dotless", cm_dotless, BRACE_ARGS },
179   { "dots", cm_dots, BRACE_ARGS },
180   { "email", cm_email, BRACE_ARGS },
181   { "emph", cm_emph, BRACE_ARGS },
182   { "end", cm_end, NO_BRACE_ARGS },
183   { "enddots", cm_enddots, BRACE_ARGS },
184   { "enumerate", cm_enumerate, NO_BRACE_ARGS },
185   { "env", cm_code, BRACE_ARGS },
186   { "equiv", cm_equiv, BRACE_ARGS },
187   { "error", cm_error, BRACE_ARGS },
188   { "euro", cm_special_char, BRACE_ARGS },
189   { "evenfooting", cm_ignore_line, NO_BRACE_ARGS },
190   { "evenheading", cm_ignore_line, NO_BRACE_ARGS },
191   { "everyfooting", cm_ignore_line, NO_BRACE_ARGS },
192   { "everyheading", cm_ignore_line, NO_BRACE_ARGS },
193   { "example", cm_example, NO_BRACE_ARGS },
194   { "exampleindent", cm_exampleindent, NO_BRACE_ARGS },
195   { "exclamdown", cm_special_char, BRACE_ARGS },
196   { "exdent", cm_exdent, NO_BRACE_ARGS },
197   { "expansion", cm_expansion, BRACE_ARGS },
198   { "file", cm_code, BRACE_ARGS },
199   { "finalout", cm_no_op, NO_BRACE_ARGS },
200   { "findex", cm_findex, NO_BRACE_ARGS },
201   { "firstparagraphindent", cm_firstparagraphindent, NO_BRACE_ARGS },
202   { "float", cm_float, NO_BRACE_ARGS },
203   { "flushleft", cm_flushleft, NO_BRACE_ARGS },
204   { "flushright", cm_flushright, NO_BRACE_ARGS },
205   { "footnote", cm_footnote, NO_BRACE_ARGS}, /* self-arg eater */
206   { "footnotestyle", cm_footnotestyle, NO_BRACE_ARGS },
207   { "format", cm_format, NO_BRACE_ARGS },
208   { "ftable", cm_ftable, NO_BRACE_ARGS },
209   { "group", cm_group, NO_BRACE_ARGS },
210   { "heading", cm_heading, NO_BRACE_ARGS },
211   { "headings", cm_ignore_line, NO_BRACE_ARGS },
212   { "headitem", cm_headitem, NO_BRACE_ARGS },
213   { "html", cm_html, NO_BRACE_ARGS },
214   { "hyphenation", cm_ignore_arg, BRACE_ARGS },
215   { "i", cm_i, BRACE_ARGS },
216   { "ifclear", cm_ifclear, NO_BRACE_ARGS },
217   { "ifeq", cm_ifeq, NO_BRACE_ARGS },
218   { "ifdocbook", cm_ifdocbook, NO_BRACE_ARGS },
219   { "ifhtml", cm_ifhtml, NO_BRACE_ARGS },
220   { "ifinfo", cm_ifinfo, NO_BRACE_ARGS },
221   { "ifnotdocbook", cm_ifnotdocbook, NO_BRACE_ARGS },
222   { "ifnothtml", cm_ifnothtml, NO_BRACE_ARGS },
223   { "ifnotinfo", cm_ifnotinfo, NO_BRACE_ARGS },
224   { "ifnotplaintext", cm_ifnotplaintext, NO_BRACE_ARGS },
225   { "ifnottex", cm_ifnottex, NO_BRACE_ARGS },
226   { "ifnotxml", cm_ifnotxml, NO_BRACE_ARGS },
227   { "ifplaintext", cm_ifplaintext, NO_BRACE_ARGS },
228   { "ifset", cm_ifset, NO_BRACE_ARGS },
229   { "iftex", cm_iftex, NO_BRACE_ARGS },
230   { "ifxml", cm_ifxml, NO_BRACE_ARGS },
231   { "ignore", command_name_condition, NO_BRACE_ARGS },
232   { "image", cm_image, BRACE_ARGS },
233   { "include", cm_include, NO_BRACE_ARGS },
234   { "indent", cm_indent, NO_BRACE_ARGS },
235   { "indicateurl", cm_indicate_url, BRACE_ARGS },
236   { "inforef", cm_inforef, BRACE_ARGS },
237   { "insertcopying", cm_insert_copying, NO_BRACE_ARGS },
238   { "item", cm_item, NO_BRACE_ARGS },
239   { "itemize", cm_itemize, NO_BRACE_ARGS },
240   { "itemx", cm_itemx, NO_BRACE_ARGS },
241   { "kbd", cm_kbd, BRACE_ARGS },
242   { "kbdinputstyle", cm_ignore_line, NO_BRACE_ARGS },
243   { "key", cm_key, BRACE_ARGS },
244   { "kindex", cm_kindex, NO_BRACE_ARGS },
245   { "l", cm_special_char, BRACE_ARGS },
246   { "lisp", cm_lisp, NO_BRACE_ARGS },
247   { "listoffloats", cm_listoffloats, NO_BRACE_ARGS },
248   { "lowersections", cm_lowersections, NO_BRACE_ARGS },
249   { "macro", cm_macro, NO_BRACE_ARGS },
250   { "majorheading", cm_majorheading, NO_BRACE_ARGS },
251   { "math", cm_math, BRACE_ARGS },
252   { "menu", cm_menu, NO_BRACE_ARGS },
253   { "minus", cm_minus, BRACE_ARGS },
254   { "multitable", cm_multitable, NO_BRACE_ARGS },
255   { "need", cm_ignore_line, NO_BRACE_ARGS },
256   { "node", cm_node, NO_BRACE_ARGS },
257   { "noindent", cm_noindent_cmd, NO_BRACE_ARGS },
258   { "novalidate", cm_novalidate, NO_BRACE_ARGS },
259   { "nwnode", cm_node, NO_BRACE_ARGS },
260   { "o", cm_special_char, BRACE_ARGS },
261   { "oddfooting", cm_ignore_line, NO_BRACE_ARGS },
262   { "oddheading", cm_ignore_line, NO_BRACE_ARGS },
263   { "oe", cm_special_char, BRACE_ARGS },
264   { "option", cm_code, BRACE_ARGS },
265   { "ordf", cm_special_char, BRACE_ARGS },
266   { "ordm", cm_special_char, BRACE_ARGS },
267   { "page", cm_no_op, NO_BRACE_ARGS },
268   { "pagesizes", cm_ignore_line, NO_BRACE_ARGS },
269   { "paragraphindent", cm_paragraphindent, NO_BRACE_ARGS },
270   { "pindex", cm_pindex, NO_BRACE_ARGS },
271   { "point", cm_point, BRACE_ARGS },
272   { "pounds", cm_special_char, BRACE_ARGS },
273   { "print", cm_print, BRACE_ARGS },
274   { "printindex", cm_printindex, NO_BRACE_ARGS },
275   { "pxref", cm_pxref, BRACE_ARGS },
276   { "questiondown", cm_special_char, BRACE_ARGS },
277   { "quotation", cm_quotation, NO_BRACE_ARGS },
278   { "r", cm_r, BRACE_ARGS },
279   { "raisesections", cm_raisesections, NO_BRACE_ARGS },
280   { "ref", cm_ref, BRACE_ARGS },
281   { "refill", cm_no_op, NO_BRACE_ARGS },
282   { "registeredsymbol", cm_registeredsymbol, BRACE_ARGS },
283   { "result", cm_result, BRACE_ARGS },
284   { "ringaccent", cm_accent, MAYBE_BRACE_ARGS },
285   { "rmacro", cm_rmacro, NO_BRACE_ARGS },
286   { "samp", cm_code, BRACE_ARGS },
287   { "sansserif", cm_sansserif, BRACE_ARGS },
288   { "sc", cm_sc, BRACE_ARGS },
289   { "section", cm_section, NO_BRACE_ARGS },
290   { "set", cm_set, NO_BRACE_ARGS },
291   { "setchapternewpage", cm_ignore_line, NO_BRACE_ARGS },
292   { "setchapterstyle", cm_obsolete, NO_BRACE_ARGS },
293   { "setcontentsaftertitlepage", cm_no_op, NO_BRACE_ARGS },
294   { "setfilename", cm_setfilename, NO_BRACE_ARGS },
295   { "setshortcontentsaftertitlepage", cm_no_op, NO_BRACE_ARGS },
296   { "settitle", cm_settitle, NO_BRACE_ARGS },
297   { "shortcaption", cm_caption, BRACE_ARGS },
298   { "shortcontents", cm_contents, NO_BRACE_ARGS },
299   { "shorttitlepage", cm_ignore_line, NO_BRACE_ARGS },
300   { "slanted", cm_slanted, BRACE_ARGS },
301   { "smallbook", cm_ignore_line, NO_BRACE_ARGS },
302   { "smalldisplay", cm_smalldisplay, NO_BRACE_ARGS },
303   { "smallexample", cm_smallexample, NO_BRACE_ARGS },
304   { "smallformat", cm_smallformat, NO_BRACE_ARGS },
305   { "smalllisp", cm_smalllisp, NO_BRACE_ARGS },
306   { "sp", cm_sp, NO_BRACE_ARGS },
307   { "ss", cm_special_char, BRACE_ARGS },
308   { "strong", cm_strong, BRACE_ARGS },
309   { "subheading", cm_subheading, NO_BRACE_ARGS },
310   { "subsection", cm_subsection, NO_BRACE_ARGS },
311   { "subsubheading", cm_subsubheading, NO_BRACE_ARGS },
312   { "subsubsection", cm_subsubsection, NO_BRACE_ARGS },
313   { "subtitle", cm_titlepage_cmds, NO_BRACE_ARGS },
314   { "summarycontents", cm_contents, NO_BRACE_ARGS },
315   { "syncodeindex", cm_synindex, NO_BRACE_ARGS },
316   { "synindex", cm_synindex, NO_BRACE_ARGS },
317   { "t", cm_tt, BRACE_ARGS },
318   { "tab", cm_tab, NO_BRACE_ARGS },
319   { "table", cm_table, NO_BRACE_ARGS },
320   { "tex", cm_tex, NO_BRACE_ARGS },
321   { "tie", cm_tie, BRACE_ARGS },
322   { "tieaccent", cm_accent, MAYBE_BRACE_ARGS },
323   { "tindex", cm_tindex, NO_BRACE_ARGS },
324   { "title", cm_titlepage_cmds, NO_BRACE_ARGS },
325   { "titlefont", cm_titlefont, BRACE_ARGS },
326   { "titlepage", cm_titlepage, NO_BRACE_ARGS },
327   { "today", cm_today, BRACE_ARGS },
328   { "top", cm_top, NO_BRACE_ARGS  },
329   { "u", cm_accent, MAYBE_BRACE_ARGS },
330   { "ubaraccent", cm_accent, MAYBE_BRACE_ARGS },
331   { "udotaccent", cm_accent, MAYBE_BRACE_ARGS },
332   { "unmacro", cm_unmacro, NO_BRACE_ARGS },
333   { "unnumbered", cm_unnumbered, NO_BRACE_ARGS },
334   { "unnumberedsec", cm_unnumberedsec, NO_BRACE_ARGS },
335   { "unnumberedsubsec", cm_unnumberedsubsec, NO_BRACE_ARGS },
336   { "unnumberedsubsubsec", cm_unnumberedsubsubsec, NO_BRACE_ARGS },
337   { "uref", cm_uref, BRACE_ARGS },
338   { "url", cm_uref, BRACE_ARGS },
339   { "v", cm_accent, MAYBE_BRACE_ARGS },
340   { "value", cm_value, BRACE_ARGS },
341   { "var", cm_var, BRACE_ARGS },
342   { "verb", cm_verb, NO_BRACE_ARGS },
343   { "verbatim", cm_verbatim, NO_BRACE_ARGS },
344   { "verbatiminclude", cm_verbatiminclude, NO_BRACE_ARGS },
345   { "vindex", cm_vindex, NO_BRACE_ARGS },
346   { "vtable", cm_vtable, NO_BRACE_ARGS },
347   { "vskip", cm_ignore_line, NO_BRACE_ARGS },
348   { "w", cm_w, BRACE_ARGS },
349   { "xml", cm_xml, NO_BRACE_ARGS },
350   { "xref", cm_xref, BRACE_ARGS },
351 
352   /* Deprecated commands.  These used to be for italics.  */
353   { "iappendix", cm_ideprecated, NO_BRACE_ARGS },
354   { "iappendixsec", cm_ideprecated, NO_BRACE_ARGS },
355   { "iappendixsection", cm_ideprecated, NO_BRACE_ARGS },
356   { "iappendixsubsec", cm_ideprecated, NO_BRACE_ARGS },
357   { "iappendixsubsubsec", cm_ideprecated, NO_BRACE_ARGS },
358   { "ichapter", cm_ideprecated, NO_BRACE_ARGS },
359   { "isection", cm_ideprecated, NO_BRACE_ARGS },
360   { "isubsection", cm_ideprecated, NO_BRACE_ARGS },
361   { "isubsubsection", cm_ideprecated, NO_BRACE_ARGS },
362   { "iunnumbered", cm_ideprecated, NO_BRACE_ARGS },
363   { "iunnumberedsec", cm_ideprecated, NO_BRACE_ARGS },
364   { "iunnumberedsubsec", cm_ideprecated, NO_BRACE_ARGS },
365   { "iunnumberedsubsubsec", cm_ideprecated, NO_BRACE_ARGS },
366 
367   /* Now @include does what this was used to. */
368   { "infoinclude", cm_obsolete, NO_BRACE_ARGS },
369   { "titlespec", cm_obsolete, NO_BRACE_ARGS },
370 
371   { NULL, NULL, NO_BRACE_ARGS }
372 };
373 
374 /* The bulk of the Texinfo commands. */
375 
376 /* Commands which insert their own names. */
377 void
insert_self(int arg)378 insert_self (int arg)
379 {
380   if (arg == START)
381     add_word (command);
382 }
383 
384 void
insert_space(int arg)385 insert_space (int arg)
386 {
387   if (arg == START)
388     {
389       if (xml && !docbook)
390         xml_insert_entity ("space");
391       else
392         add_char (' ');
393     }
394 }
395 
396 /* Insert a comma.  Useful when a literal , would break our parsing of
397    multiple arguments.  */
398 void
cm_comma(int arg)399 cm_comma (int arg)
400 {
401   if (arg == START)
402     add_char (',');
403 }
404 
405 
406 /* Force a line break in the output. */
407 void
cm_asterisk(void)408 cm_asterisk (void)
409 {
410   if (html)
411     add_word ("<br>");
412   else if (xml && !docbook)
413     xml_insert_entity ("linebreak");
414   else if (docbook)
415     xml_asterisk ();
416   else
417     {
418       close_single_paragraph ();
419       cm_noindent ();
420     }
421 }
422 
423 /* Insert ellipsis. */
424 void
cm_dots(int arg)425 cm_dots (int arg)
426 {
427   if (arg == START)
428     {
429       if (xml && !docbook)
430         xml_insert_entity ("dots");
431       else if (docbook)
432         xml_insert_entity ("hellip");
433       else
434 	if (html && !in_fixed_width_font)
435 	  insert_string ("<small class=\"dots\">...</small>");
436 	else
437 	  add_word ("...");
438     }
439 }
440 
441 /* Insert ellipsis for sentence end. */
442 void
cm_enddots(int arg)443 cm_enddots (int arg)
444 {
445   if (arg == START)
446     {
447       if (xml && !docbook)
448 	xml_insert_entity ("enddots");
449       else if (docbook)
450 	{
451 	  xml_insert_entity ("hellip");
452 	  add_char ('.');
453 	}
454       else
455 	if (html && !in_fixed_width_font)
456 	  insert_string ("<small class=\"enddots\">....</small>");
457 	else
458 	  add_word ("....");
459     }
460 }
461 
462 void
cm_bullet(int arg)463 cm_bullet (int arg)
464 {
465   if (arg == START)
466     {
467       if (html)
468         add_word ("&bull;");
469       else if (xml && !docbook)
470 	xml_insert_entity ("bullet");
471       else if (docbook)
472 	xml_insert_entity ("bull");
473       else
474         add_char ('*');
475     }
476 }
477 
478 void
cm_minus(int arg)479 cm_minus (int arg)
480 {
481   if (arg == START)
482     {
483       if (xml)
484 	xml_insert_entity ("minus");
485       else if (html)
486         add_word ("&minus;");
487       else
488 	add_char ('-');
489     }
490 }
491 
492 /* Formatting a dimension unit.  */
493 void
cm_dmn(int arg)494 cm_dmn (int arg)
495 {
496   if (html)
497     insert_html_tag_with_attribute (arg, "span", "class=\"dmn\"");
498   else if (docbook)
499     /* No units in docbook yet.  */
500     ;
501   else if (xml)
502     xml_insert_element (DIMENSION, arg);
503 }
504 
505 /* Insert "TeX". */
506 void
cm_TeX(int arg)507 cm_TeX (int arg)
508 {
509   static int last_position;
510 
511   if (arg == START)
512     {
513       if (xml)
514 	xml_insert_entity ("tex");
515       else
516 	add_word ("TeX");
517 
518       last_position = output_paragraph_offset;
519     }
520   else if (last_position != output_paragraph_offset)
521     {
522       warning (_("arguments to @%s ignored"), command);
523       output_paragraph_offset = last_position;
524     }
525 }
526 
527 /* Insert "LaTeX".  */
528 void
cm_LaTeX(int arg)529 cm_LaTeX (int arg)
530 {
531   static int last_position;
532 
533   if (arg == START)
534     {
535       if (xml)
536         xml_insert_entity ("latex");
537       else
538         add_word ("LaTeX");
539 
540       last_position = output_paragraph_offset;
541     }
542   else if (last_position != output_paragraph_offset)
543     {
544       warning (_("arguments to @%s ignored"), command);
545       output_paragraph_offset = last_position;
546     }
547 }
548 
549 /* Copyright symbol.  */
550 void
cm_copyright(int arg)551 cm_copyright (int arg)
552 {
553   if (arg == START)
554     {
555     if (html)
556       add_word ("&copy;");
557     else if (xml && !docbook)
558       xml_insert_entity ("copyright");
559     else if (docbook)
560       xml_insert_entity ("copy");
561     else
562       add_word ("(C)");
563     }
564 }
565 
566 /* Registered symbol.  */
567 void
cm_registeredsymbol(int arg)568 cm_registeredsymbol (int arg)
569 {
570   if (arg == START)
571     {
572       if (html)
573         add_word ("&reg;");
574       else if (docbook)
575         xml_insert_entity ("reg");
576       else if (xml && !docbook)
577         xml_insert_entity ("registered");
578       else
579         add_word ("(R)");
580     }
581 }
582 
583 void
cm_today(int arg)584 cm_today (int arg)
585 {
586   static char *months[12] =
587     { N_("January"), N_("February"), N_("March"), N_("April"), N_("May"),
588       N_("June"), N_("July"), N_("August"), N_("September"), N_("October"),
589       N_("November"), N_("December") };
590   if (arg == START)
591     {
592       time_t timer = time (0);
593       struct tm *ts = localtime (&timer);
594       add_word_args ("%d %s %d", ts->tm_mday, _(months[ts->tm_mon]),
595                      ts->tm_year + 1900);
596     }
597 }
598 
599 void
cm_comment(void)600 cm_comment (void)
601 {
602   /* For HTML, do not output comments before HTML header is written,
603      otherwise comments before @settitle cause an empty <title> in the
604      header.  */
605   if ((html && html_output_head_p) || xml)
606     {
607       char *line;
608       get_rest_of_line (0, &line);
609 
610       if (strlen (line) > 0)
611         {
612           int save_inhibit_indentation = inhibit_paragraph_indentation;
613           int save_paragraph_is_open = paragraph_is_open;
614           int save_escape_html = escape_html;
615           int save_xml_no_para = xml_no_para;
616           int i;
617 
618           inhibit_paragraph_indentation = 1;
619           escape_html = 0;
620           xml_no_para = 1;
621 
622           /* @c and @comment can appear between @item and @itemx,
623              @deffn and @deffnx.  */
624           xml_dont_touch_items_defs++;
625 
626           /* Use insert for HTML, and XML when indentation is enabled.
627              For Docbook, use add_char.  */
628           if (xml && xml_indentation_increment > 0
629               && output_paragraph[output_paragraph_offset-1] != '\n')
630             insert ('\n');
631 
632           /* Crunch double hyphens in comments.  */
633           add_html_block_elt ("<!-- ");
634           for (i = 0; i < strlen (line); i++)
635             if (line[i] != '-' || (i && line[i-1] != '-'))
636               add_char (line[i]);
637           add_word (" -->");
638 
639           if (html)
640             add_char ('\n');
641 
642           inhibit_paragraph_indentation = save_inhibit_indentation;
643           paragraph_is_open = save_paragraph_is_open;
644           escape_html = save_escape_html;
645           xml_no_para = save_xml_no_para;
646           xml_dont_touch_items_defs--;
647         }
648 
649       free (line);
650     }
651   else
652     cm_ignore_line ();
653 }
654 
655 
656 
657 /* We keep acronyms with two arguments around, to be able to refer to them
658    later with only one argument.  */
659 static ACRONYM_DESC *acronyms_stack = NULL;
660 
661 static void
cm_acronym_or_abbr(int arg,int is_abbr)662 cm_acronym_or_abbr (int arg, int is_abbr)
663 {
664   char *aa, *description;
665   unsigned len;
666 
667   /* We do everything at START.  */
668   if (arg == END)
669     return;
670 
671   get_until_in_braces (",", &aa);
672   if (input_text[input_text_offset] == ',')
673     input_text_offset++;
674   get_until_in_braces ("}", &description);
675 
676   canon_white (aa);
677   canon_white (description);
678 
679   /* If not enclosed in braces, strip after comma to be compatible
680      with texinfo.tex.  */
681   if (description[0] != '{' && strchr (description, ',') != NULL)
682     {
683       int i = 0;
684       while (description[i] != ',')
685         i++;
686       /* For now, just terminate the string at comma.  */
687       description[i] = 0;
688     }
689 
690   /* Get description out of braces.  */
691   if (description[0] == '{')
692     description++;
693 
694   len = strlen (description);
695   if (len && description[len-1] == '}')
696     description[len-1] = 0;
697 
698   /* Save new description.  */
699   if (strlen (description) > 0)
700     {
701       ACRONYM_DESC *new = xmalloc (sizeof (ACRONYM_DESC));
702 
703       new->acronym = xstrdup (aa);
704       new->description = xstrdup (description);
705       new->next = acronyms_stack;
706       acronyms_stack = new;
707     }
708 
709   if (html)
710     {
711       add_word (is_abbr ? "<abbr" : "<acronym");
712 
713       if (strlen (description) > 0)
714         add_word_args (" title=\"%s\"", text_expansion (description));
715       else if (acronyms_stack)
716         {
717           /* No second argument, get from previous.  Search order is from
718              last to first defined, so we get the most recent version of
719              the description.  */
720           ACRONYM_DESC *temp = acronyms_stack;
721 
722           while (temp)
723             {
724               if (STREQ (aa, temp->acronym)
725                   && strlen (temp->description) > 0)
726                 {
727                   add_word_args (" title=\"%s\"",
728                                  text_expansion (temp->description));
729                   break;
730                 }
731               temp = temp->next;
732             }
733         }
734 
735       add_char ('>');
736       execute_string ("%s", aa);
737       add_word (is_abbr ? "</abbr>" : "</acronym>");
738     }
739   else if (docbook)
740     {
741       xml_insert_element (is_abbr ? ABBREV : ACRONYM, START);
742       execute_string ("%s", aa);
743       xml_insert_element (is_abbr ? ABBREV : ACRONYM, END);
744     }
745   else if (xml)
746     {
747       xml_insert_element (is_abbr ? ABBREV : ACRONYM, START);
748 
749       xml_insert_element (is_abbr ? ABBREVWORD : ACRONYMWORD, START);
750       execute_string ("%s", aa);
751       xml_insert_element (is_abbr ? ABBREVWORD : ACRONYMWORD, END);
752 
753       if (strlen (description) > 0)
754         {
755           xml_insert_element (is_abbr ? ABBREVDESC : ACRONYMDESC, START);
756           execute_string ("%s", description);
757           xml_insert_element (is_abbr ? ABBREVDESC : ACRONYMDESC, END);
758         }
759 
760       xml_insert_element (is_abbr ? ABBREV : ACRONYM, END);
761     }
762   else
763     execute_string ("%s", aa);
764 
765   /* Put description into parenthesis after the acronym for all outputs
766      except XML.  */
767   if (strlen (description) > 0 && (!xml || docbook))
768     add_word_args (" (%s)", description);
769 }
770 
771 void
cm_acronym(int arg)772 cm_acronym (int arg)
773 {
774   cm_acronym_or_abbr (arg, 0);
775 }
776 
777 void
cm_abbr(int arg)778 cm_abbr (int arg)
779 {
780   cm_acronym_or_abbr (arg, 1);
781 }
782 
783 void
cm_tt(int arg)784 cm_tt (int arg)
785 {
786   /* @t{} is a no-op in Info.  */
787   if (html)
788     insert_html_tag (arg, "tt");
789   else if (xml)
790     xml_insert_element (TT, arg);
791 }
792 
793 void
cm_code(int arg)794 cm_code (int arg)
795 {
796   if (arg == START)
797     in_fixed_width_font++;
798 
799   if (xml)
800     {
801       if (STREQ (command, "command"))
802 	xml_insert_element (COMMAND_TAG, arg);
803       else if (STREQ (command, "env"))
804 	xml_insert_element (ENV, arg);
805       else if (STREQ (command, "file"))
806 	xml_insert_element (FILE_TAG, arg);
807       else if (STREQ (command, "option"))
808 	xml_insert_element (OPTION, arg);
809       else if (STREQ (command, "samp"))
810         {
811           if (docbook && arg == START)
812             {
813               /* Even though @samp is in_fixed_width_font, it
814                  should always start a paragraph.  Unfortunately,
815                  in_fixed_width_font inhibits that.  */
816               xml_start_para ();
817               xml_insert_entity ("lsquo");
818             }
819           xml_insert_element (SAMP, arg);
820           if (docbook && arg == END)
821             xml_insert_entity ("rsquo");
822         }
823       else
824 	xml_insert_element (CODE, arg);
825     }
826   else if (html)
827     {
828       if (STREQ (command, "code"))
829         insert_html_tag (arg, "code");
830       else
831         { /* Use <samp> tag in general to get typewriter.  */
832           if (arg == START)
833             { /* If @samp specifically, add quotes a la TeX output.  */
834               if (STREQ (command, "samp")) add_char ('`');
835             }
836           insert_html_tag_with_attribute (arg, "samp", "class=\"%s\"",command);
837           if (arg == END)
838             {
839               if (STREQ (command, "samp")) add_char ('\'');
840             }
841         }
842     }
843   else
844     {
845       extern int printing_index;
846 
847       if (!printing_index)
848         {
849           if (arg == START)
850             add_char ('`');
851           else
852             add_meta_char ('\'');
853         }
854     }
855 }
856 
857 void
cm_kbd(int arg)858 cm_kbd (int arg)
859 {
860   if (xml)
861     xml_insert_element (KBD, arg);
862   else if (html)
863     { /* Seems like we should increment in_fixed_width_font for Info
864          format too, but then the quote-omitting special case gets
865          confused.  Punt.  */
866       if (arg == START)
867         in_fixed_width_font++;
868       insert_html_tag (arg, "kbd");
869     }
870   else
871     { /* People use @kbd in an example to get the "user input" font.
872          We don't want quotes in that case.  */
873       if (!in_fixed_width_font)
874         cm_code (arg);
875     }
876 }
877 
878 /* Just show a url (http://example.org/..., for example), don't link to it.  */
879 void
cm_indicate_url(int arg,int start,int end)880 cm_indicate_url (int arg, int start, int end)
881 {
882   if (xml)
883     xml_insert_element (URL, arg);
884   else if (html)
885     {
886       if (arg == START)
887         add_word ("&lt;");
888       insert_html_tag (arg, "code");
889       if (arg != START)
890         add_word ("&gt;");
891     }
892   else
893     if (arg == START)
894       add_word ("<");
895     else
896       add_word (">");
897 }
898 
899 void
cm_key(int arg)900 cm_key (int arg)
901 {
902   if (xml)
903     xml_insert_element (KEY, arg);
904   else if (html)
905     add_word (arg == START ? "&lt;" : "&gt;");
906   else
907     add_char (arg == START ? '<' : '>');
908 }
909 
910 /* Handle a command that switches to a non-fixed-width font.  */
911 void
not_fixed_width(int arg)912 not_fixed_width (int arg)
913 {
914   if (arg == START)
915     in_fixed_width_font = 0;
916 }
917 
918 /* @var in makeinfo just uppercases the text. */
919 void
cm_var(int arg,int start_pos,int end_pos)920 cm_var (int arg, int start_pos, int end_pos)
921 {
922   if (xml)
923     xml_insert_element (VAR, arg);
924   else
925     {
926   not_fixed_width (arg);
927 
928   if (html)
929     insert_html_tag (arg, "var");
930   else if (arg == END)
931     {
932       while (start_pos < end_pos)
933         {
934           unsigned char c = output_paragraph[start_pos];
935           if (strchr ("[](),", c))
936             warning (_("unlikely character %c in @var"), c);
937           output_paragraph[start_pos] = coerce_to_upper (c);
938           start_pos++;
939         }
940     }
941     }
942 }
943 
944 void
cm_sc(int arg,int start_pos,int end_pos)945 cm_sc (int arg, int start_pos, int end_pos)
946 {
947   if (xml)
948     xml_insert_element (SC, arg);
949   else
950     {
951       not_fixed_width (arg);
952 
953       if (arg == START)
954         {
955           if (html)
956             insert_html_tag_with_attribute (arg, "span", "class=\"sc\"");
957         }
958       else
959         {
960           int all_upper;
961 
962           if (html)
963             start_pos += sizeof ("<span class=\"sc\">") - 1; /* skip <span> */
964 
965           /* Avoid the warning below if there's no text inside @sc{}, or
966              when processing menus under --no-headers.  */
967           all_upper = start_pos < end_pos;
968 
969           while (start_pos < end_pos)
970             {
971               unsigned char c = output_paragraph[start_pos];
972               if (!isupper (c))
973                 all_upper = 0;
974               if (!html)
975                 output_paragraph[start_pos] = coerce_to_upper (c);
976               start_pos++;
977             }
978           if (all_upper)
979             warning (_("@sc argument all uppercase, thus no effect"));
980 
981           if (html)
982             insert_html_tag (arg, "span");
983         }
984     }
985 }
986 
987 void
cm_dfn(int arg,int position)988 cm_dfn (int arg, int position)
989 {
990   if (xml)
991     xml_insert_element (DFN, arg);
992   else
993     {
994   if (html)
995     insert_html_tag (arg, "dfn");
996   else if (arg == START)
997     add_char ('"');
998   else
999     add_meta_char ('"');
1000     }
1001 }
1002 
1003 void
cm_emph(int arg)1004 cm_emph (int arg)
1005 {
1006   if (xml)
1007     xml_insert_element (EMPH, arg);
1008   else if (html)
1009     insert_html_tag (arg, "em");
1010   else
1011     add_char ('_');
1012 }
1013 
1014 void
cm_verb(int arg)1015 cm_verb (int arg)
1016 {
1017   int character;
1018   int delimiter = 0; /* avoid warning */
1019   int seen_end = 0;
1020 
1021   in_fixed_width_font++;
1022   /* are these necessary ? */
1023   last_char_was_newline = 0;
1024 
1025   if (html)
1026     add_word ("<tt>");
1027 
1028   if (input_text_offset < input_text_length)
1029     {
1030       character = curchar ();
1031       if (character == '{')
1032 	input_text_offset++;
1033       else
1034 	line_error (_("`{' expected, but saw `%c'"), character);
1035     }
1036 
1037   if (input_text_offset < input_text_length)
1038     {
1039       delimiter = curchar ();
1040       input_text_offset++;
1041     }
1042 
1043   while (input_text_offset < input_text_length)
1044     {
1045       character = curchar ();
1046 
1047       if (character == '\n')
1048         {
1049           line_number++;
1050           if (html)
1051             add_word ("<br>\n");
1052         }
1053 
1054       else if (html && character == '<')
1055         add_word ("&lt;");
1056 
1057       else if (html && character == '&')
1058         add_word ("&amp;");
1059 
1060       else if (character == delimiter && input_text[input_text_offset+1] == '}')
1061 	{ /* Assume no newlines in END_VERBATIM. */
1062 	  seen_end = 1;
1063 	  input_text_offset++;
1064 	  break;
1065 	}
1066 
1067       else
1068         add_char (character);
1069 
1070       input_text_offset++;
1071     }
1072 
1073   if (!seen_end)
1074     warning (_("end of file inside verb block"));
1075 
1076   if (input_text_offset < input_text_length)
1077     {
1078       character = curchar ();
1079       if (character == '}')
1080 	input_text_offset++;
1081       else
1082 	line_error (_("`}' expected, but saw `%c'"), character);
1083     }
1084 
1085   if (html)
1086     add_word ("</tt>");
1087 
1088   in_fixed_width_font--;
1089 }
1090 
1091 
1092 void
cm_strong(int arg,int start_pos,int end_pos)1093 cm_strong (int arg, int start_pos, int end_pos)
1094 {
1095   if (docbook && arg == START)
1096     xml_insert_element_with_attribute (B, arg, "role=\"bold\"");
1097   else if (xml)
1098     xml_insert_element (STRONG, arg);
1099   else if (html)
1100     insert_html_tag (arg, "strong");
1101   else
1102     add_char ('*');
1103 
1104   if (!xml && !html && !docbook && !no_headers
1105       && arg == END
1106       && end_pos - start_pos >= 6
1107       && (strncasecmp ((char *) output_paragraph + start_pos, "*Note:", 6) == 0
1108           || strncasecmp ((char *) output_paragraph + start_pos, "*Note ", 6) == 0))
1109     {
1110       /* Translators: "Note:" is literal here and should not be
1111          translated.  @strong{Nota}, say, does not cause the problem.  */
1112       warning (_("@strong{Note...} produces a spurious cross-reference in Info; reword to avoid that"));
1113       /* Adjust the output to avoid writing the bad xref.  */
1114       output_paragraph[start_pos + 5] = '_';
1115     }
1116 }
1117 
1118 void
cm_cite(int arg,int position)1119 cm_cite (int arg, int position)
1120 {
1121   if (xml)
1122     xml_insert_element (CITE, arg);
1123   else if (html)
1124     insert_html_tag (arg, "cite");
1125   else
1126     {
1127       if (arg == START)
1128         add_char ('`');
1129       else
1130         add_char ('\'');
1131     }
1132 }
1133 
1134 /* No highlighting, but argument switches fonts.  */
1135 void
cm_not_fixed_width(int arg,int start,int end)1136 cm_not_fixed_width (int arg, int start, int end)
1137 {
1138   if (xml)
1139     xml_insert_element (NOTFIXEDWIDTH, arg);
1140   not_fixed_width (arg);
1141 }
1142 
1143 void
cm_i(int arg)1144 cm_i (int arg)
1145 {
1146   /* Make use of <lineannotation> of Docbook, if we are
1147      inside an @example or similar.  */
1148   extern int printing_index;
1149   if (docbook && !filling_enabled && !printing_index)
1150     xml_insert_element (LINEANNOTATION, arg);
1151   else if (xml)
1152     xml_insert_element (I, arg);
1153   else if (html)
1154     insert_html_tag (arg, "i");
1155   else
1156     not_fixed_width (arg);
1157 }
1158 
1159 void
cm_slanted(int arg)1160 cm_slanted (int arg)
1161 {
1162   /* Make use of <lineannotation> of Docbook, if we are
1163      inside an @example or similar.  */
1164   extern int printing_index;
1165   if (docbook && !filling_enabled && !printing_index)
1166     xml_insert_element (LINEANNOTATION, arg);
1167   else if (xml)
1168     xml_insert_element (SLANTED, arg);
1169   else if (html)
1170     insert_html_tag (arg, "i");
1171   else
1172     not_fixed_width (arg);
1173 }
1174 
1175 void
cm_b(int arg)1176 cm_b (int arg)
1177 {
1178   /* See cm_i comments.  */
1179   extern int printing_index;
1180   if (docbook && !filling_enabled && !printing_index)
1181     xml_insert_element (LINEANNOTATION, arg);
1182   else if (docbook && arg == START)
1183     xml_insert_element_with_attribute (B, arg, "role=\"bold\"");
1184   else if (xml)
1185     xml_insert_element (B, arg);
1186   else if (html)
1187     insert_html_tag (arg, "b");
1188   else
1189     not_fixed_width (arg);
1190 }
1191 
1192 void
cm_r(int arg)1193 cm_r (int arg)
1194 {
1195   /* See cm_i comments.  */
1196   extern int printing_index;
1197   if (docbook && !filling_enabled && !printing_index)
1198     xml_insert_element (LINEANNOTATION, arg);
1199   else if (xml)
1200     xml_insert_element (R, arg);
1201   else if (html)
1202     insert_html_tag_with_attribute (arg, "span", "class=\"roman\"");
1203   else
1204     not_fixed_width (arg);
1205 }
1206 
1207 void
cm_sansserif(int arg)1208 cm_sansserif (int arg)
1209 {
1210   /* See cm_i comments.  */
1211   extern int printing_index;
1212   if (docbook && !filling_enabled && !printing_index)
1213     xml_insert_element (LINEANNOTATION, arg);
1214   else if (xml)
1215     xml_insert_element (SANSSERIF, arg);
1216   else if (html)
1217     insert_html_tag_with_attribute (arg, "span", "class=\"sansserif\"");
1218   else
1219     not_fixed_width (arg);
1220 }
1221 
1222 void
cm_titlefont(int arg)1223 cm_titlefont (int arg)
1224 {
1225   if (xml)
1226     xml_insert_element (TITLEFONT, arg);
1227   else
1228    {
1229      not_fixed_width (arg);
1230      if (html)
1231 	{
1232 	  html_title_written = 1; /* suppress title from @settitle */
1233 	  if (arg == START)
1234 	    add_word ("<h1 class=\"titlefont\">");
1235 	  else
1236 	    add_word ("</h1>\n");
1237 	}
1238    }
1239 }
1240 
1241 
1242 /* Unfortunately, we cannot interpret @math{} contents like TeX does.  We just
1243    pass them through.  */
1244 void
cm_math(int arg)1245 cm_math (int arg)
1246 {
1247   if (xml && !docbook)
1248     xml_insert_element (MATH, arg);
1249 }
1250 
1251 /* Various commands are no-op's. */
1252 void
cm_no_op(void)1253 cm_no_op (void)
1254 {
1255 }
1256 
1257 
1258 /* For proofing single chapters, etc.  */
1259 void
cm_novalidate(void)1260 cm_novalidate (void)
1261 {
1262   validating = 0;
1263 }
1264 
1265 
1266 /* Prevent the argument from being split across two lines. */
1267 void
cm_w(int arg)1268 cm_w (int arg)
1269 {
1270   if (arg == START)
1271     non_splitting_words++;
1272   else
1273     {
1274       if (docbook || html || xml)
1275         /* This is so @w{$}Log$ doesn't end up as <dollar>Log<dollar>
1276            in the output.  */
1277         insert_string ("<!-- /@w -->");
1278 
1279       non_splitting_words--;
1280     }
1281 }
1282 
1283 
1284 /* An unbreakable word space.  Same as @w{ } for makeinfo, but different
1285    for TeX (the space stretches and stretches, and does not inhibit
1286    hyphenation).  */
1287 void
cm_tie(int arg)1288 cm_tie (int arg)
1289 {
1290   if (arg == START)
1291     {
1292       cm_w (START);
1293       add_char (' ');
1294     }
1295   else
1296     cm_w (END);
1297 }
1298 
1299 /* Explain that this command is obsolete, thus the user shouldn't
1300    do anything with it. */
1301 static void
cm_obsolete(int arg,int start,int end)1302 cm_obsolete (int arg, int start, int end)
1303 {
1304   if (arg == START)
1305     warning (_("%c%s is obsolete"), COMMAND_PREFIX, command);
1306 }
1307 
1308 
1309 /* Inhibit the indentation of the next paragraph, but not of following
1310    paragraphs.  */
1311 void
cm_noindent(void)1312 cm_noindent (void)
1313 {
1314   if (!inhibit_paragraph_indentation)
1315     inhibit_paragraph_indentation = -1;
1316 }
1317 
1318 void
cm_noindent_cmd(void)1319 cm_noindent_cmd (void)
1320 {
1321   cm_noindent ();
1322   xml_no_indent = 1;
1323   skip_whitespace_and_newlines();
1324 
1325   if (xml)
1326     xml_start_para ();
1327   else if (html && !paragraph_is_open)
1328     add_html_block_elt ("<p class=\"noindent\">");
1329   else
1330     {
1331       paragraph_is_open = 0;
1332       start_paragraph ();
1333     }
1334 }
1335 
1336 /* Force indentation of the next paragraph. */
1337 void
cm_indent(void)1338 cm_indent (void)
1339 {
1340   inhibit_paragraph_indentation = 0;
1341   xml_no_indent = 0;
1342   skip_whitespace_and_newlines();
1343 
1344   if (xml)
1345     xml_start_para ();
1346   else if (html && !paragraph_is_open)
1347     add_html_block_elt ("<p class=\"indent\">");
1348   else
1349     start_paragraph ();
1350 }
1351 
1352 /* I don't know exactly what to do with this.  Should I allow
1353    someone to switch filenames in the middle of output?  Since the
1354    file could be partially written, this doesn't seem to make sense.
1355    Another option: ignore it, since they don't really want to
1356    switch files.  Finally, complain, or at least warn.  It doesn't
1357    really matter, anyway, since this doesn't get executed.  */
1358 void
cm_setfilename(void)1359 cm_setfilename (void)
1360 {
1361   char *filename;
1362   get_rest_of_line (1, &filename);
1363   /* warning ("`@%s %s' encountered and ignored", command, filename); */
1364   if (xml)
1365     add_word_args ("<setfilename>%s</setfilename>", filename);
1366   free (filename);
1367 }
1368 
1369 void
cm_settitle(void)1370 cm_settitle (void)
1371 {
1372   if (xml)
1373     {
1374       xml_begin_document (current_output_filename);
1375       xml_insert_element (SETTITLE, START);
1376       xml_in_book_title = 1;
1377       get_rest_of_line (0, &title);
1378       execute_string ("%s", title);
1379       xml_in_book_title = 0;
1380       xml_insert_element (SETTITLE, END);
1381     }
1382   else
1383     get_rest_of_line (0, &title);
1384 }
1385 
1386 
1387 /* Ignore argument in braces.  */
1388 void
cm_ignore_arg(int arg,int start_pos,int end_pos)1389 cm_ignore_arg (int arg, int start_pos, int end_pos)
1390 {
1391   if (arg == END)
1392     output_paragraph_offset = start_pos;
1393 }
1394 
1395 /* Ignore argument on rest of line.  */
1396 void
cm_ignore_line(void)1397 cm_ignore_line (void)
1398 {
1399   discard_until ("\n");
1400 }
1401 
1402 /* Insert the number of blank lines passed as argument. */
1403 void
cm_sp(void)1404 cm_sp (void)
1405 {
1406   int lines;
1407   char *line;
1408 
1409   /* Due to tricky stuff in execute_string(), @value{} can't be expanded.
1410      So there is really no reason to enable expansion for @sp parameters.  */
1411   get_rest_of_line (0, &line);
1412 
1413   if (sscanf (line, "%d", &lines) != 1 || lines <= 0)
1414     line_error (_("@sp requires a positive numeric argument, not `%s'"), line);
1415   else
1416     {
1417       if (xml)
1418 	{
1419           /* @sp can appear between @item and @itemx, @deffn and @deffnx.  */
1420           xml_dont_touch_items_defs++;
1421 	  xml_insert_element_with_attribute (SP, START, "lines=\"%s\"", line);
1422 	  /*	  insert_string (line);*/
1423 	  xml_insert_element (SP, END);
1424           xml_dont_touch_items_defs--;
1425 	}
1426       else
1427         {
1428           /* Must disable filling since otherwise multiple newlines is like
1429              multiple spaces.  Must close paragraph since that's what the
1430              manual says and that's what TeX does.  */
1431           int save_filling_enabled = filling_enabled;
1432           filling_enabled = 0;
1433 
1434           /* close_paragraph generates an extra blank line.  */
1435           close_single_paragraph ();
1436 
1437           if (lines && html && !executing_string)
1438             html_output_head ();
1439 
1440           if (html)
1441             add_html_block_elt ("<pre class=\"sp\">\n");
1442 
1443           while (lines--)
1444             add_char ('\n');
1445 
1446           if (html)
1447             add_html_block_elt ("</pre>\n");
1448 
1449           filling_enabled = save_filling_enabled;
1450         }
1451     }
1452   free (line);
1453 }
1454 
1455 /* @dircategory LINE outputs INFO-DIR-SECTION LINE, unless --no-headers.  */
1456 void
cm_dircategory(void)1457 cm_dircategory (void)
1458 {
1459   char *line;
1460 
1461   if (html || docbook)
1462     cm_ignore_line ();
1463   else if (xml)
1464     {
1465       xml_insert_element (DIRCATEGORY, START);
1466       get_rest_of_line (1, &line);
1467       insert_string (line);
1468       free (line);
1469       xml_insert_element (DIRCATEGORY, END);
1470     }
1471   else
1472     {
1473       get_rest_of_line (1, &line);
1474 
1475       if (!no_headers && !html)
1476         {
1477           kill_self_indent (-1); /* make sure there's no indentation */
1478           insert_string ("INFO-DIR-SECTION ");
1479           insert_string (line);
1480           insert ('\n');
1481         }
1482 
1483       free (line);
1484     }
1485 }
1486 
1487 /* Start a new line with just this text on it.
1488    Then center the line of text.
1489    */
1490 void
cm_center(void)1491 cm_center (void)
1492 {
1493   if (xml)
1494     {
1495       char *line;
1496       xml_insert_element (CENTER, START);
1497       get_rest_of_line (0, &line);
1498       execute_string ("%s", line);
1499       free (line);
1500       xml_insert_element (CENTER, END);
1501     }
1502   else
1503     {
1504       int i, start, length;
1505       char *line;
1506       int save_indented_fill = indented_fill;
1507       int save_filling_enabled = filling_enabled;
1508       int fudge_factor = 1;
1509 
1510       filling_enabled = indented_fill = 0;
1511       cm_noindent ();
1512       start = output_paragraph_offset;
1513 
1514       if (html)
1515         add_html_block_elt ("<div align=\"center\">");
1516 
1517       inhibit_output_flushing ();
1518       get_rest_of_line (0, &line);
1519       execute_string ("%s", line);
1520       free (line);
1521       uninhibit_output_flushing ();
1522       if (html)
1523         add_html_block_elt ("</div>");
1524 
1525        else
1526          {
1527            i = output_paragraph_offset - 1;
1528            while (i > (start - 1) && output_paragraph[i] == '\n')
1529              i--;
1530 
1531            output_paragraph_offset = ++i;
1532            length = output_paragraph_offset - start;
1533 
1534            if (length < (fill_column - fudge_factor))
1535              {
1536                line = xmalloc (1 + length);
1537                memcpy (line, (char *)(output_paragraph + start), length);
1538 
1539                i = (fill_column - fudge_factor - length) / 2;
1540                output_paragraph_offset = start;
1541 
1542                while (i--)
1543                  insert (' ');
1544 
1545                for (i = 0; i < length; i++)
1546                  insert (line[i]);
1547 
1548                free (line);
1549              }
1550          }
1551 
1552       insert ('\n');
1553       filling_enabled = save_filling_enabled;
1554       indented_fill = save_indented_fill;
1555       close_single_paragraph ();
1556       if (looking_at("\n"))
1557         insert ('\n');
1558     }
1559 }
1560 
1561 /* Show what an expression returns. */
1562 void
cm_result(int arg)1563 cm_result (int arg)
1564 {
1565   if (arg == END)
1566     add_word (html ? "=&gt;" : "=>");
1567 }
1568 
1569 /* What an expression expands to. */
1570 void
cm_expansion(int arg)1571 cm_expansion (int arg)
1572 {
1573   if (arg == END)
1574     add_word (html ? "==&gt;" : "==>");
1575 }
1576 
1577 /* Indicates two expressions are equivalent. */
1578 void
cm_equiv(int arg)1579 cm_equiv (int arg)
1580 {
1581   if (arg == END)
1582     add_word ("==");
1583 }
1584 
1585 /* What an expression may print. */
1586 void
cm_print(int arg)1587 cm_print (int arg)
1588 {
1589   if (arg == END)
1590     add_word ("-|");
1591 }
1592 
1593 /* An error signaled. */
1594 void
cm_error(int arg)1595 cm_error (int arg)
1596 {
1597   if (arg == END)
1598     add_word (html ? "error--&gt;" : "error-->");
1599 }
1600 
1601 /* The location of point in an example of a buffer. */
1602 void
cm_point(int arg)1603 cm_point (int arg)
1604 {
1605   if (arg == END)
1606     add_word ("-!-");
1607 }
1608 
1609 /* @exdent: Start a new line with just this text on it.
1610    The text is outdented one level if possible. */
1611 void
cm_exdent(void)1612 cm_exdent (void)
1613 {
1614   char *line;
1615   int save_indent = current_indent;
1616   int save_in_fixed_width_font = in_fixed_width_font;
1617 
1618   /* Read argument.  */
1619   get_rest_of_line (0, &line);
1620 
1621   /* Exdent the output.  Actually this may be a no-op.   */
1622   if (current_indent)
1623     current_indent -= default_indentation_increment;
1624 
1625   /* @exdent arg is supposed to be in roman.  */
1626   in_fixed_width_font = 0;
1627 
1628   /* The preceding newline already inserted the `current_indent'.
1629      Remove one level's worth.  */
1630   kill_self_indent (default_indentation_increment);
1631 
1632   if (html)
1633     add_word ("<br>");
1634   else if (docbook)
1635     xml_insert_element (LINEANNOTATION, START);
1636   else if (xml)
1637     xml_insert_element (EXDENT, START);
1638 
1639   /* Can't close_single_paragraph, then we lose preceding blank lines.  */
1640   flush_output ();
1641   execute_string ("%s", line);
1642   free (line);
1643 
1644   if (html)
1645     add_word ("<br>");
1646   else if (xml)
1647     {
1648       xml_insert_element (docbook ? LINEANNOTATION : EXDENT, END);
1649       insert ('\n');
1650     }
1651 
1652   close_single_paragraph ();
1653 
1654   current_indent = save_indent;
1655   in_fixed_width_font = save_in_fixed_width_font;
1656   if (!xml)
1657     start_paragraph ();
1658 }
1659 
1660 /*
1661   Read include-filename, process the include-file:
1662     verbatim_include == 0: process through reader_loop
1663     verbatim_include != 0: process through handle_verbatim_environment
1664  */
1665 static void
handle_include(int verbatim_include)1666 handle_include (int verbatim_include)
1667 {
1668   char *arg, *filename;
1669 
1670   if (macro_expansion_output_stream && !executing_string)
1671     me_append_before_this_command ();
1672 
1673   if (!insertion_stack)
1674     close_paragraph ();  /* No blank lines etc. if not at outer level.  */
1675 
1676   get_rest_of_line (0, &arg);
1677   /* We really only want to expand @value, but it's easier to just do
1678      everything.  TeX will only work with @value.  */
1679   filename = text_expansion (arg);
1680   free (arg);
1681 
1682   if (macro_expansion_output_stream && !executing_string)
1683     remember_itext (input_text, input_text_offset);
1684 
1685   pushfile ();
1686 
1687   /* In verbose mode we print info about including another file. */
1688   if (verbose_mode)
1689     {
1690       int i = 0;
1691       FSTACK *stack = filestack;
1692 
1693       for (i = 0, stack = filestack; stack; stack = stack->next, i++);
1694 
1695       i *= 2;
1696 
1697       printf ("%*s", i, "");
1698       printf ("%c%s `%s'\n", COMMAND_PREFIX, command, filename);
1699       fflush (stdout);
1700     }
1701 
1702   if (!find_and_load (filename, 1))
1703     {
1704       popfile ();
1705       line_number--;
1706 
1707       /* /wh/bar:5: @include/@verbatiminclude `foo': No such file or dir */
1708       line_error ("%c%s `%s': %s", COMMAND_PREFIX, command, filename,
1709                   strerror (errno));
1710 
1711       free (filename);
1712       return;
1713     }
1714   else
1715     {
1716       if (macro_expansion_output_stream && !executing_string)
1717 	remember_itext (input_text, input_text_offset);
1718 
1719       if (!verbatim_include)
1720 	reader_loop ();
1721       else
1722 	handle_verbatim_environment (0);
1723     }
1724   free (filename);
1725   popfile ();
1726 }
1727 
1728 
1729 /* Include file as if put in @verbatim environment */
1730 void
cm_verbatiminclude(void)1731 cm_verbatiminclude (void)
1732 {
1733   handle_include (1);
1734 }
1735 
1736 
1737 /* Remember this file, and move onto the next. */
1738 void
cm_include(void)1739 cm_include (void)
1740 {
1741   handle_include (0);
1742 }
1743 
1744 
1745 /* @bye: Signals end of processing.  Easy to make this happen. */
1746 
1747 void
cm_bye(void)1748 cm_bye (void)
1749 {
1750   discard_braces (); /* should not have any unclosed braces left */
1751   input_text_offset = input_text_length;
1752 }
1753 
1754 /* @paragraphindent */
1755 
1756 static void
cm_paragraphindent(void)1757 cm_paragraphindent (void)
1758 {
1759   char *arg;
1760 
1761   get_rest_of_line (1, &arg);
1762   if (set_paragraph_indent (arg) != 0)
1763     line_error (_("Bad argument to %c%s"), COMMAND_PREFIX, command);
1764 
1765   free (arg);
1766 }
1767 
1768 
1769 /* @exampleindent: change indentation of example-like environments.   */
1770 static int
set_example_indentation_increment(char * string)1771 set_example_indentation_increment (char *string)
1772 {
1773   if (strcmp (string, "asis") == 0 || strcmp (string, _("asis")) == 0)
1774     ;
1775   else if (strcmp (string, "none") == 0 || strcmp (string, _("none")) == 0)
1776     example_indentation_increment = 0;
1777   else if (sscanf (string, "%d", &example_indentation_increment) != 1)
1778     return -1;
1779   return 0;
1780 }
1781 
1782 static void
cm_exampleindent(void)1783 cm_exampleindent (void)
1784 {
1785   char *arg;
1786 
1787   get_rest_of_line (1, &arg);
1788   if (set_example_indentation_increment (arg) != 0)
1789     line_error (_("Bad argument to @%s"), command);
1790 
1791   if (input_text[input_text_offset] == '\n')
1792     close_single_paragraph ();
1793 
1794   free (arg);
1795 }
1796 
1797 
1798 /* @firstparagraphindent: suppress indentation in first paragraphs after
1799    headings. */
1800 static int
set_firstparagraphindent(char * string)1801 set_firstparagraphindent (char *string)
1802 {
1803   if (STREQ (string, "insert") || STREQ (string, _("insert")))
1804     do_first_par_indent = 1;
1805   else if (STREQ (string, "none") || STREQ (string, _("none")))
1806     do_first_par_indent = 0;
1807   else
1808     return -1;
1809   return 0;
1810 }
1811 
1812 static void
cm_firstparagraphindent(void)1813 cm_firstparagraphindent (void)
1814 {
1815   char *arg;
1816 
1817   get_rest_of_line (1, &arg);
1818   if (set_firstparagraphindent (arg) != 0)
1819     line_error (_("Bad argument to %c%s"), COMMAND_PREFIX, command);
1820 
1821   free (arg);
1822 }
1823 
1824 /* For DocBook and XML, produce &period; for `.@:'. This gives the processing
1825    software a fighting chance to treat it specially by not adding extra space.
1826 
1827    Do this also for ?, !, and :.  */
1828 void
cm_colon(void)1829 cm_colon (void)
1830 {
1831   if (xml)
1832     {
1833       if (strchr (".?!:", input_text[input_text_offset-3]) != NULL)
1834         {
1835           /* Erase literal character that's there, except `>', which is
1836              part of the XML tag.  */
1837           if (output_paragraph[output_paragraph_offset-1] != '>')
1838             output_paragraph_offset--;
1839 
1840           switch (input_text[input_text_offset-3])
1841             {
1842             case '.':
1843               xml_insert_entity ("period");
1844               break;
1845             case '?':
1846               xml_insert_entity ("quest");
1847               break;
1848             case '!':
1849               xml_insert_entity ("excl");
1850               break;
1851             case ':':
1852               xml_insert_entity ("colon");
1853               break;
1854             }
1855         }
1856     }
1857 }
1858 
1859 /* Ending sentences explicitly.  Currently, only outputs entities for XML
1860    output, for other formats it calls insert_self.  */
1861 void
cm_punct(int arg)1862 cm_punct (int arg)
1863 {
1864   if (xml && !docbook)
1865     {
1866       switch (input_text[input_text_offset-1])
1867         {
1868         case '.':
1869           xml_insert_entity ("eosperiod");
1870           break;
1871         case '?':
1872           xml_insert_entity ("eosquest");
1873           break;
1874         case '!':
1875           xml_insert_entity ("eosexcl");
1876           break;
1877         }
1878     }
1879   else
1880     {
1881       insert_self (arg);
1882     }
1883 }
1884