insertion.c 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456
  1. /* insertion.c -- insertions for Texinfo.
  2. $Id: insertion.c,v 1.72 2009-01-01 07:24:57 olegkat Exp $
  3. Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
  4. 2007, 2008 Free Software Foundation, Inc.
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. #include "system.h"
  16. #include "cmds.h"
  17. #include "defun.h"
  18. #include "float.h"
  19. #include "html.h"
  20. #include "insertion.h"
  21. #include "macro.h"
  22. #include "makeinfo.h"
  23. #include "multi.h"
  24. #include "xml.h"
  25. /* Must match list in insertion.h. */
  26. static char *insertion_type_names[] =
  27. {
  28. "cartouche", "copying", "defcv", "deffn", "defivar", "defmac",
  29. "defmethod", "defop", "defopt", "defspec", "deftp", "deftypecv",
  30. "deftypefn", "deftypefun", "deftypeivar", "deftypemethod",
  31. "deftypeop", "deftypevar", "deftypevr", "defun", "defvar", "defvr",
  32. "detailmenu", "direntry", "display", "documentdescription",
  33. "enumerate", "example", "float", "flushleft", "flushright", "format",
  34. "ftable", "group", "ifclear", "ifdocbook", "ifhtml", "ifinfo",
  35. "ifnotdocbook", "ifnothtml", "ifnotinfo", "ifnotplaintext", "ifnottex",
  36. "ifnotxml", "ifplaintext", "ifset", "iftex", "ifxml", "itemize", "lisp",
  37. "menu", "multitable", "quotation", "raggedcenter", "raggedleft",
  38. "raggedright", "rawdocbook", "rawhtml", "rawtex",
  39. "rawxml", "smalldisplay", "smallexample", "smallformat", "smalllisp",
  40. "verbatim", "table", "tex", "vtable", "titlepage", "bad_type"
  41. };
  42. /* All nested environments. */
  43. INSERTION_ELT *insertion_stack = NULL;
  44. /* How deeply we're nested. */
  45. int insertion_level = 0;
  46. /* Set to 1 if we've processed (commentary) text in a @menu that
  47. wasn't part of a menu item. */
  48. int had_menu_commentary;
  49. /* How to examine menu lines. */
  50. int in_detailmenu = 0;
  51. /* Whether to examine menu lines. */
  52. int in_menu = 0;
  53. /* Set to 1 if <p> is written in normal context.
  54. Used for menu and itemize. */
  55. int in_paragraph = 0;
  56. /* Since an insertion is already in the stack before we reach the switch
  57. statement, we cannot use is_in_insertion_of_type (always returns true.) Also
  58. making it return the level found, and comparing it with the current level is
  59. no use, due to the order of stack. */
  60. static int float_active = 0;
  61. /* Unsetting escape_html blindly causes text inside @html/etc. to be escaped if
  62. used within a rmacro. */
  63. static int raw_output_block = 0;
  64. /* Non-zero if a <dl> element has a <dt> element in it. We use this when
  65. deciding whether to insert a <br> or not. */
  66. static int html_deflist_has_term = 0;
  67. const char default_item_function[] = { "@bullet" };
  68. void
  69. init_insertion_stack (void)
  70. {
  71. insertion_stack = NULL;
  72. }
  73. /* Return the type of the current insertion. */
  74. static enum insertion_type
  75. current_insertion_type (void)
  76. {
  77. return insertion_level ? insertion_stack->insertion : bad_type;
  78. }
  79. /* Return the string which is the function to wrap around items, or NULL
  80. if we're not in an environment where @item is ok. */
  81. static char *
  82. current_item_function (void)
  83. {
  84. int done = 0;
  85. INSERTION_ELT *elt = insertion_stack;
  86. /* Skip down through the stack until we find an insertion with an
  87. itemize function defined, i.e., skip conditionals, @cartouche, etc. */
  88. while (!done && elt)
  89. {
  90. switch (elt->insertion)
  91. {
  92. /* This list should match the one in cm_item. */
  93. case ifclear:
  94. case ifhtml:
  95. case ifinfo:
  96. case ifnothtml:
  97. case ifnotinfo:
  98. case ifnotplaintext:
  99. case ifnottex:
  100. case ifnotxml:
  101. case ifplaintext:
  102. case ifset:
  103. case iftex:
  104. case ifxml:
  105. case rawdocbook:
  106. case rawhtml:
  107. case rawxml:
  108. case rawtex:
  109. case tex:
  110. case cartouche:
  111. elt = elt->next;
  112. break;
  113. default:
  114. done = 1;
  115. }
  116. }
  117. /* item_function usually gets assigned the empty string. */
  118. return done && (*elt->item_function) ? elt->item_function : NULL;
  119. }
  120. /* Parse the item marker function off the input. If result is just "@",
  121. change it to "@ ", since "@" by itself is not a command. This makes
  122. "@ ", "@\t", and "@\n" all the same, but their default meanings are
  123. the same anyway, and let's not worry about supporting redefining them. */
  124. char *
  125. get_item_function (void)
  126. {
  127. char *item_function;
  128. char *item_loc;
  129. get_rest_of_line (0, &item_function);
  130. /* If the document erroneously says
  131. @itemize @bullet @item foobar
  132. it's nicer to give an error up front than repeat `@bullet expected
  133. braces' until we get a segmentation fault. */
  134. item_loc = strstr (item_function, "@item");
  135. if (item_loc)
  136. {
  137. line_error (_("@item not allowed in argument to @itemize"));
  138. *item_loc = 0;
  139. }
  140. /* If we hit the end of text in get_rest_of_line, backing up
  141. input pointer will cause the last character of the last line
  142. be pushed back onto the input, which is wrong. */
  143. if (input_text_offset < input_text_length)
  144. backup_input_pointer ();
  145. if (STREQ (item_function, "@"))
  146. {
  147. free (item_function);
  148. item_function = xstrdup ("@ ");
  149. }
  150. return item_function;
  151. }
  152. /* Push the state of the current insertion on the stack. */
  153. static void
  154. push_insertion (enum insertion_type type, char *item_function)
  155. {
  156. INSERTION_ELT *new = xmalloc (sizeof (INSERTION_ELT));
  157. new->item_function = item_function;
  158. new->filling_enabled = filling_enabled;
  159. new->indented_fill = indented_fill;
  160. new->insertion = type;
  161. new->line_number = line_number;
  162. new->filename = xstrdup (input_filename);
  163. new->inhibited = inhibit_paragraph_indentation;
  164. new->in_fixed_width_font = in_fixed_width_font;
  165. new->next = insertion_stack;
  166. insertion_stack = new;
  167. insertion_level++;
  168. }
  169. /* Pop the value on top of the insertion stack into the
  170. global variables. */
  171. void
  172. pop_insertion (void)
  173. {
  174. INSERTION_ELT *temp = insertion_stack;
  175. if (temp == NULL)
  176. return;
  177. in_fixed_width_font = temp->in_fixed_width_font;
  178. inhibit_paragraph_indentation = temp->inhibited;
  179. filling_enabled = temp->filling_enabled;
  180. indented_fill = temp->indented_fill;
  181. if (temp->item_function == default_item_function)
  182. temp->item_function = NULL;
  183. else
  184. free_and_clear (&(temp->item_function));
  185. free_and_clear (&(temp->filename));
  186. insertion_stack = insertion_stack->next;
  187. free (temp);
  188. insertion_level--;
  189. }
  190. /* Return a pointer to the print name of this
  191. enumerated type. */
  192. static const char *
  193. insertion_type_pname (enum insertion_type type)
  194. {
  195. if ((int) type < (int) bad_type)
  196. {
  197. if (type == rawdocbook)
  198. return "docbook";
  199. else if (type == rawhtml)
  200. return "html";
  201. else if (type == rawxml)
  202. return "xml";
  203. else if (type == rawtex)
  204. return "tex";
  205. else
  206. return insertion_type_names[(int) type];
  207. }
  208. else
  209. return _("Broken-Type in insertion_type_pname");
  210. }
  211. /* Return the insertion_type associated with NAME.
  212. If the type is not one of the known ones, return BAD_TYPE. */
  213. enum insertion_type
  214. find_type_from_name (char *name)
  215. {
  216. int index = 0;
  217. while (index < (int) bad_type)
  218. {
  219. if (STREQ (name, insertion_type_names[index]))
  220. return (enum insertion_type) index;
  221. if (index == rawdocbook && STREQ (name, "docbook"))
  222. return rawdocbook;
  223. if (index == rawhtml && STREQ (name, "html"))
  224. return rawhtml;
  225. if (index == rawxml && STREQ (name, "xml"))
  226. return rawxml;
  227. if (index == rawtex && STREQ (name, "tex"))
  228. return rawtex;
  229. index++;
  230. }
  231. return bad_type;
  232. }
  233. /* Simple function to query insertion_stack to see if we are inside a given
  234. insertion type. */
  235. int
  236. is_in_insertion_of_type (int type)
  237. {
  238. INSERTION_ELT *temp = insertion_stack;
  239. if (!insertion_level)
  240. return 0;
  241. while (temp)
  242. {
  243. if (temp->insertion == type)
  244. return 1;
  245. temp = temp->next;
  246. }
  247. return 0;
  248. }
  249. static int
  250. defun_insertion (enum insertion_type type)
  251. {
  252. return 0
  253. || (type == defcv)
  254. || (type == deffn)
  255. || (type == defivar)
  256. || (type == defmac)
  257. || (type == defmethod)
  258. || (type == defop)
  259. || (type == defopt)
  260. || (type == defspec)
  261. || (type == deftp)
  262. || (type == deftypecv)
  263. || (type == deftypefn)
  264. || (type == deftypefun)
  265. || (type == deftypeivar)
  266. || (type == deftypemethod)
  267. || (type == deftypeop)
  268. || (type == deftypevar)
  269. || (type == deftypevr)
  270. || (type == defun)
  271. || (type == defvar)
  272. || (type == defvr)
  273. ;
  274. }
  275. /* MAX_NS is the maximum nesting level for enumerations. I picked 100
  276. which seemed reasonable. This doesn't control the number of items,
  277. just the number of nested lists. */
  278. #define max_stack_depth 100
  279. #define ENUM_DIGITS 1
  280. #define ENUM_ALPHA 2
  281. typedef struct {
  282. int enumtype;
  283. int enumval;
  284. } DIGIT_ALPHA;
  285. DIGIT_ALPHA enumstack[max_stack_depth];
  286. int enumstack_offset = 0;
  287. int current_enumval = 1;
  288. int current_enumtype = ENUM_DIGITS;
  289. char *enumeration_arg = NULL;
  290. static void
  291. start_enumerating (int at, int type)
  292. {
  293. if ((enumstack_offset + 1) == max_stack_depth)
  294. {
  295. line_error (_("Enumeration stack overflow"));
  296. return;
  297. }
  298. enumstack[enumstack_offset].enumtype = current_enumtype;
  299. enumstack[enumstack_offset].enumval = current_enumval;
  300. enumstack_offset++;
  301. current_enumval = at;
  302. current_enumtype = type;
  303. }
  304. static void
  305. stop_enumerating (void)
  306. {
  307. --enumstack_offset;
  308. if (enumstack_offset < 0)
  309. enumstack_offset = 0;
  310. current_enumval = enumstack[enumstack_offset].enumval;
  311. current_enumtype = enumstack[enumstack_offset].enumtype;
  312. }
  313. /* Place a letter or digits into the output stream. */
  314. static void
  315. enumerate_item (void)
  316. {
  317. char temp[10];
  318. if (current_enumtype == ENUM_ALPHA)
  319. {
  320. if (current_enumval == ('z' + 1) || current_enumval == ('Z' + 1))
  321. {
  322. current_enumval = ((current_enumval - 1) == 'z' ? 'a' : 'A');
  323. warning (_("lettering overflow, restarting at %c"), current_enumval);
  324. }
  325. sprintf (temp, "%c. ", current_enumval);
  326. }
  327. else
  328. sprintf (temp, "%d. ", current_enumval);
  329. indent (current_output_column () + (current_indent - strlen (temp)));
  330. add_word (temp);
  331. current_enumval++;
  332. }
  333. static void
  334. enum_html (void)
  335. {
  336. char type;
  337. int start;
  338. if (isdigit (*enumeration_arg))
  339. {
  340. type = '1';
  341. start = atoi (enumeration_arg);
  342. }
  343. else if (isupper (*enumeration_arg))
  344. {
  345. type = 'A';
  346. start = *enumeration_arg - 'A' + 1;
  347. }
  348. else
  349. {
  350. type = 'a';
  351. start = *enumeration_arg - 'a' + 1;
  352. }
  353. add_html_block_elt_args ("<ol type=%c start=%d>\n", type, start);
  354. }
  355. /* Conditionally parse based on the current command name. */
  356. void
  357. command_name_condition (void)
  358. {
  359. char *discarder = xmalloc (8 + strlen (command));
  360. sprintf (discarder, "\n%cend %s", COMMAND_PREFIX, command);
  361. discard_until (discarder);
  362. discard_until ("\n");
  363. free (discarder);
  364. }
  365. /* This is where the work for all the "insertion" style
  366. commands is done. A huge switch statement handles the
  367. various setups, and generic code is on both sides. */
  368. void
  369. begin_insertion (enum insertion_type type)
  370. {
  371. int no_discard = 0;
  372. if (defun_insertion (type))
  373. {
  374. push_insertion (type, xstrdup (""));
  375. no_discard++;
  376. }
  377. else
  378. {
  379. push_insertion (type, get_item_function ());
  380. }
  381. switch (type)
  382. {
  383. case menu:
  384. if (!no_headers)
  385. close_paragraph ();
  386. filling_enabled = no_indent = 0;
  387. inhibit_paragraph_indentation = 1;
  388. if (html)
  389. {
  390. had_menu_commentary = 1;
  391. }
  392. else if (!no_headers && !xml)
  393. add_word ("* Menu:\n");
  394. if (xml)
  395. xml_insert_element (MENU, START);
  396. else
  397. in_fixed_width_font++;
  398. next_menu_item_number = 1;
  399. in_menu++;
  400. no_discard++;
  401. break;
  402. case detailmenu:
  403. if (!in_menu)
  404. {
  405. if (!no_headers)
  406. close_paragraph ();
  407. filling_enabled = no_indent = 0;
  408. inhibit_paragraph_indentation = 1;
  409. no_discard++;
  410. }
  411. if (xml)
  412. {
  413. xml_insert_element (DETAILMENU, START);
  414. skip_whitespace_and_newlines ();
  415. }
  416. else
  417. in_fixed_width_font++;
  418. in_detailmenu++;
  419. break;
  420. case direntry:
  421. close_single_paragraph ();
  422. filling_enabled = no_indent = 0;
  423. inhibit_paragraph_indentation = 1;
  424. add_word ("START-INFO-DIR-ENTRY\n");
  425. /* The zsh manual, maybe others, wrongly indents the * line of the
  426. direntry in the source. Ignore that whitespace. */
  427. skip_whitespace_and_newlines ();
  428. no_discard++;
  429. break;
  430. case documentdescription:
  431. {
  432. char *desc;
  433. int start_of_end;
  434. int save_fixed_width;
  435. discard_until ("\n"); /* ignore the @documentdescription line */
  436. start_of_end = get_until ("\n@end documentdescription", &desc);
  437. save_fixed_width = in_fixed_width_font;
  438. in_fixed_width_font = 0;
  439. document_description = expansion (desc, 0);
  440. free (desc);
  441. in_fixed_width_font = save_fixed_width;
  442. input_text_offset = start_of_end; /* go back to the @end to match */
  443. }
  444. break;
  445. case copying:
  446. /* Save the copying text away for @insertcopying,
  447. typically used on the back of the @titlepage (for TeX) and
  448. the Top node (for info/html). */
  449. if (input_text[input_text_offset] != '\n')
  450. discard_until ("\n"); /* ignore remainder of @copying line */
  451. input_text_offset = get_until ("\n@end copying", &copying_text);
  452. canon_white (copying_text);
  453. /* For info, output the copying text right away, so it will end up
  454. in the header of the Info file, before the first node, and thus
  455. get copied automatically to all the split files. For xml, also
  456. output it right away since xml output is never split.
  457. For html, we output it specifically in html_output_head.
  458. For plain text, there's no way to hide it, so the author must
  459. use @insertcopying in the desired location. */
  460. if (docbook)
  461. {
  462. if (!xml_in_bookinfo)
  463. {
  464. xml_insert_element (BOOKINFO, START);
  465. xml_in_bookinfo = 1;
  466. }
  467. xml_insert_element (LEGALNOTICE, START);
  468. }
  469. if (!html && !no_headers)
  470. cm_insert_copying ();
  471. if (docbook)
  472. xml_insert_element (LEGALNOTICE, END);
  473. break;
  474. case quotation:
  475. /* @quotation does filling (@display doesn't). */
  476. if (html)
  477. add_html_block_elt ("<blockquote>\n");
  478. else
  479. {
  480. /* with close_single_paragraph, we get no blank line above
  481. within @copying. */
  482. close_paragraph ();
  483. last_char_was_newline = no_indent = 0;
  484. indented_fill = filling_enabled = 1;
  485. inhibit_paragraph_indentation = 1;
  486. current_indent += default_indentation_increment;
  487. }
  488. if (xml)
  489. xml_insert_quotation (insertion_stack->item_function, START);
  490. else if (strlen(insertion_stack->item_function))
  491. execute_string ("@b{%s:} ", insertion_stack->item_function);
  492. break;
  493. case example:
  494. case smallexample:
  495. case lisp:
  496. case smalllisp:
  497. in_fixed_width_font++;
  498. /* fall through */
  499. /* Like @example but no fixed width font. */
  500. case display:
  501. case smalldisplay:
  502. /* Like @display but without indentation. */
  503. case smallformat:
  504. case format:
  505. close_single_paragraph ();
  506. inhibit_paragraph_indentation = 1;
  507. filling_enabled = 0;
  508. last_char_was_newline = 0;
  509. if (html)
  510. /* Kludge alert: if <pre> is followed by a newline, IE3,
  511. mozilla, maybe others render an extra blank line before the
  512. pre-formatted block. So don't output a newline. */
  513. add_html_block_elt_args ("<pre class=\"%s\">", command);
  514. if (type != format && type != smallformat)
  515. {
  516. current_indent += example_indentation_increment;
  517. if (html)
  518. {
  519. /* Since we didn't put \n after <pre>, we need to insert
  520. the indentation by hand. */
  521. int i;
  522. for (i = current_indent; i > 0; i--)
  523. add_char (' ');
  524. }
  525. }
  526. break;
  527. case multitable:
  528. do_multitable ();
  529. break;
  530. case table:
  531. case ftable:
  532. case vtable:
  533. case itemize:
  534. close_single_paragraph ();
  535. current_indent += default_indentation_increment;
  536. filling_enabled = indented_fill = 1;
  537. #if defined (INDENT_PARAGRAPHS_IN_TABLE)
  538. inhibit_paragraph_indentation = 0;
  539. #else
  540. inhibit_paragraph_indentation = 1;
  541. #endif /* !INDENT_PARAGRAPHS_IN_TABLE */
  542. /* Make things work for losers who forget the itemize syntax. */
  543. if (type == itemize)
  544. {
  545. if (!(*insertion_stack->item_function))
  546. {
  547. free (insertion_stack->item_function);
  548. insertion_stack->item_function = (char *) default_item_function;
  549. }
  550. }
  551. if (!*insertion_stack->item_function)
  552. {
  553. line_error (_("%s requires an argument: the formatter for %citem"),
  554. insertion_type_pname (type), COMMAND_PREFIX);
  555. }
  556. if (html)
  557. {
  558. if (type == itemize)
  559. {
  560. add_html_block_elt ("<ul>\n");
  561. in_paragraph = 0;
  562. }
  563. else
  564. { /* We are just starting, so this <dl>
  565. has no <dt> children yet. */
  566. html_deflist_has_term = 0;
  567. add_html_block_elt ("<dl>\n");
  568. }
  569. }
  570. if (xml)
  571. xml_begin_table (type, insertion_stack->item_function);
  572. while (input_text[input_text_offset] == '\n'
  573. && input_text[input_text_offset+1] == '\n')
  574. {
  575. line_number++;
  576. input_text_offset++;
  577. }
  578. break;
  579. case enumerate:
  580. close_single_paragraph ();
  581. no_indent = 0;
  582. #if defined (INDENT_PARAGRAPHS_IN_TABLE)
  583. inhibit_paragraph_indentation = 0;
  584. #else
  585. inhibit_paragraph_indentation = 1;
  586. #endif /* !INDENT_PARAGRAPHS_IN_TABLE */
  587. current_indent += default_indentation_increment;
  588. filling_enabled = indented_fill = 1;
  589. if (html)
  590. {
  591. enum_html ();
  592. in_paragraph = 0;
  593. }
  594. if (xml)
  595. xml_begin_enumerate (enumeration_arg);
  596. if (isdigit (*enumeration_arg))
  597. start_enumerating (atoi (enumeration_arg), ENUM_DIGITS);
  598. else
  599. start_enumerating (*enumeration_arg, ENUM_ALPHA);
  600. break;
  601. /* @group produces no output in info. */
  602. case group:
  603. /* Only close the paragraph if we are not inside of an
  604. @example-like environment. */
  605. if (xml)
  606. xml_insert_element (GROUP, START);
  607. else if (!insertion_stack->next
  608. || (insertion_stack->next->insertion != display
  609. && insertion_stack->next->insertion != smalldisplay
  610. && insertion_stack->next->insertion != example
  611. && insertion_stack->next->insertion != smallexample
  612. && insertion_stack->next->insertion != lisp
  613. && insertion_stack->next->insertion != smalllisp
  614. && insertion_stack->next->insertion != format
  615. && insertion_stack->next->insertion != smallformat
  616. && insertion_stack->next->insertion != flushleft
  617. && insertion_stack->next->insertion != flushright))
  618. close_single_paragraph ();
  619. break;
  620. case cartouche:
  621. if (html)
  622. add_html_block_elt ("<p><table class=\"cartouche\" summary=\"cartouche\" border=\"1\"><tr><td>\n");
  623. if (in_menu)
  624. no_discard++;
  625. break;
  626. case floatenv:
  627. /* Cannot nest floats, so complain. */
  628. if (float_active)
  629. {
  630. line_error (_("%cfloat environments cannot be nested"), COMMAND_PREFIX);
  631. pop_insertion ();
  632. break;
  633. }
  634. float_active++;
  635. { /* Collect data about this float. */
  636. /* Example: @float [FLOATTYPE][,XREFLABEL][,POSITION] */
  637. char floattype[200] = "";
  638. char xreflabel[200] = "";
  639. char position[200] = "";
  640. char *text;
  641. char *caption;
  642. char *shortcaption;
  643. int start_of_end;
  644. int save_line_number = line_number;
  645. int save_input_text_offset = input_text_offset;
  646. int i;
  647. if (strlen (insertion_stack->item_function) > 0)
  648. {
  649. int i = 0, t = 0, c = 0;
  650. while (insertion_stack->item_function[i])
  651. {
  652. if (insertion_stack->item_function[i] == ',')
  653. {
  654. switch (t)
  655. {
  656. case 0:
  657. floattype[c] = '\0';
  658. break;
  659. case 1:
  660. xreflabel[c] = '\0';
  661. break;
  662. case 2:
  663. position[c] = '\0';
  664. break;
  665. }
  666. c = 0;
  667. t++;
  668. i++;
  669. continue;
  670. }
  671. switch (t)
  672. {
  673. case 0:
  674. floattype[c] = insertion_stack->item_function[i];
  675. break;
  676. case 1:
  677. xreflabel[c] = insertion_stack->item_function[i];
  678. break;
  679. case 2:
  680. position[c] = insertion_stack->item_function[i];
  681. break;
  682. }
  683. c++;
  684. i++;
  685. }
  686. }
  687. skip_whitespace_and_newlines ();
  688. start_of_end = get_until ("\n@end float", &text);
  689. /* Get also the @caption. */
  690. i = search_forward_until_pos ("\n@caption{",
  691. save_input_text_offset, start_of_end);
  692. if (i > -1)
  693. {
  694. input_text_offset = i + sizeof ("\n@caption{") - 1;
  695. get_until_in_braces ("\n@end float", &caption);
  696. input_text_offset = save_input_text_offset;
  697. }
  698. else
  699. caption = "";
  700. /* ... and the @shortcaption. */
  701. i = search_forward_until_pos ("\n@shortcaption{",
  702. save_input_text_offset, start_of_end);
  703. if (i > -1)
  704. {
  705. input_text_offset = i + sizeof ("\n@shortcaption{") - 1;
  706. get_until_in_braces ("\n@end float", &shortcaption);
  707. input_text_offset = save_input_text_offset;
  708. }
  709. else
  710. shortcaption = "";
  711. canon_white (xreflabel);
  712. canon_white (floattype);
  713. canon_white (position);
  714. canon_white (caption);
  715. canon_white (shortcaption);
  716. add_new_float (xstrdup (xreflabel),
  717. xstrdup (caption), xstrdup (shortcaption),
  718. xstrdup (floattype), xstrdup (position));
  719. /* Move to the start of the @float so the contents get processed as
  720. usual. */
  721. input_text_offset = save_input_text_offset;
  722. line_number = save_line_number;
  723. }
  724. if (html)
  725. add_html_block_elt ("<div class=\"float\">\n");
  726. else if (docbook)
  727. xml_insert_element (FLOAT, START);
  728. else if (xml)
  729. {
  730. xml_insert_element_with_attribute (FLOAT, START,
  731. "name=\"%s\"", current_float_id ());
  732. xml_insert_element (FLOATTYPE, START);
  733. execute_string ("%s", current_float_type ());
  734. xml_insert_element (FLOATTYPE, END);
  735. xml_insert_element (FLOATPOS, START);
  736. execute_string ("%s", current_float_position ());
  737. xml_insert_element (FLOATPOS, END);
  738. }
  739. else
  740. { /* Info */
  741. close_single_paragraph ();
  742. inhibit_paragraph_indentation = 1;
  743. }
  744. /* Anchor now. Note that XML documents get their
  745. anchors with <float name="anchor"> tag. */
  746. if ((!xml || docbook) && strlen (current_float_id ()) > 0)
  747. execute_string ("@anchor{%s}", current_float_id ());
  748. break;
  749. /* Insertions that are no-ops in info, but do something in TeX. */
  750. case ifclear:
  751. case ifdocbook:
  752. case ifhtml:
  753. case ifinfo:
  754. case ifnotdocbook:
  755. case ifnothtml:
  756. case ifnotinfo:
  757. case ifnotplaintext:
  758. case ifnottex:
  759. case ifnotxml:
  760. case ifplaintext:
  761. case ifset:
  762. case iftex:
  763. case ifxml:
  764. case rawtex:
  765. if (in_menu)
  766. no_discard++;
  767. break;
  768. case rawdocbook:
  769. case rawhtml:
  770. case rawxml:
  771. raw_output_block++;
  772. if (raw_output_block > 0)
  773. {
  774. xml_no_para = 1;
  775. escape_html = 0;
  776. xml_keep_space++;
  777. }
  778. {
  779. /* Some deuglification for improved readability. */
  780. extern int xml_in_para;
  781. if (xml && !xml_in_para && xml_indentation_increment > 0)
  782. add_char ('\n');
  783. }
  784. break;
  785. case defcv:
  786. case deffn:
  787. case defivar:
  788. case defmac:
  789. case defmethod:
  790. case defop:
  791. case defopt:
  792. case defspec:
  793. case deftp:
  794. case deftypecv:
  795. case deftypefn:
  796. case deftypefun:
  797. case deftypeivar:
  798. case deftypemethod:
  799. case deftypeop:
  800. case deftypevar:
  801. case deftypevr:
  802. case defun:
  803. case defvar:
  804. case defvr:
  805. inhibit_paragraph_indentation = 1;
  806. filling_enabled = indented_fill = 1;
  807. current_indent += default_indentation_increment;
  808. no_indent = 0;
  809. if (xml)
  810. xml_begin_definition ();
  811. break;
  812. case flushleft:
  813. close_single_paragraph ();
  814. inhibit_paragraph_indentation = 1;
  815. filling_enabled = indented_fill = no_indent = 0;
  816. if (html)
  817. add_html_block_elt ("<div align=\"left\">");
  818. break;
  819. case flushright:
  820. close_single_paragraph ();
  821. filling_enabled = indented_fill = no_indent = 0;
  822. inhibit_paragraph_indentation = 1;
  823. force_flush_right++;
  824. if (html)
  825. add_html_block_elt ("<div align=\"right\">");
  826. break;
  827. case raggedcenter:
  828. close_single_paragraph ();
  829. filling_enabled = indented_fill = 1;
  830. no_indent = inhibit_paragraph_indentation = 1;
  831. if (html)
  832. add_html_block_elt ("<div align=\"center\">");
  833. break;
  834. case raggedleft:
  835. close_single_paragraph ();
  836. filling_enabled = indented_fill = 1;
  837. no_indent = inhibit_paragraph_indentation = 1;
  838. if (html)
  839. add_html_block_elt ("<div align=\"right\">");
  840. break;
  841. case raggedright:
  842. close_single_paragraph ();
  843. filling_enabled = indented_fill = 1;
  844. no_indent = inhibit_paragraph_indentation = 0;
  845. if (html)
  846. add_html_block_elt ("<div align=\"left\">");
  847. break;
  848. case titlepage:
  849. xml_insert_element (TITLEPAGE, START);
  850. break;
  851. default:
  852. line_error ("begin_insertion internal error: type=%d", type);
  853. }
  854. if (!no_discard)
  855. discard_until ("\n");
  856. }
  857. /* Try to end the insertion with the specified TYPE. With a value of
  858. `bad_type', TYPE gets translated to match the value currently on top
  859. of the stack. Otherwise, if TYPE doesn't match the top of the
  860. insertion stack, give error. */
  861. static void
  862. end_insertion (enum insertion_type type)
  863. {
  864. enum insertion_type temp_type;
  865. if (!insertion_level)
  866. return;
  867. temp_type = current_insertion_type ();
  868. if (type == bad_type)
  869. type = temp_type;
  870. if (type != temp_type)
  871. {
  872. line_error
  873. (_("`@end' expected `%s', but saw `%s'"),
  874. insertion_type_pname (temp_type), insertion_type_pname (type));
  875. return;
  876. }
  877. pop_insertion ();
  878. if (xml)
  879. {
  880. switch (type)
  881. {
  882. case ifinfo:
  883. case documentdescription:
  884. break;
  885. case quotation:
  886. xml_insert_quotation ("", END);
  887. break;
  888. case example:
  889. xml_insert_element (EXAMPLE, END);
  890. if (docbook && current_insertion_type () == floatenv)
  891. xml_insert_element (FLOATEXAMPLE, END);
  892. break;
  893. case smallexample:
  894. xml_insert_element (SMALLEXAMPLE, END);
  895. if (docbook && current_insertion_type () == floatenv)
  896. xml_insert_element (FLOATEXAMPLE, END);
  897. break;
  898. case lisp:
  899. xml_insert_element (LISP, END);
  900. if (docbook && current_insertion_type () == floatenv)
  901. xml_insert_element (FLOATEXAMPLE, END);
  902. break;
  903. case smalllisp:
  904. xml_insert_element (SMALLLISP, END);
  905. if (docbook && current_insertion_type () == floatenv)
  906. xml_insert_element (FLOATEXAMPLE, END);
  907. break;
  908. case cartouche:
  909. xml_insert_element (CARTOUCHE, END);
  910. break;
  911. case format:
  912. if (docbook && xml_in_bookinfo && xml_in_abstract)
  913. {
  914. xml_insert_element (ABSTRACT, END);
  915. xml_in_abstract = 0;
  916. }
  917. else
  918. xml_insert_element (FORMAT, END);
  919. break;
  920. case smallformat:
  921. xml_insert_element (SMALLFORMAT, END);
  922. break;
  923. case display:
  924. xml_insert_element (DISPLAY, END);
  925. break;
  926. case smalldisplay:
  927. xml_insert_element (SMALLDISPLAY, END);
  928. break;
  929. case table:
  930. case ftable:
  931. case vtable:
  932. case itemize:
  933. xml_end_table (type);
  934. break;
  935. case enumerate:
  936. xml_end_enumerate ();
  937. break;
  938. case group:
  939. xml_insert_element (GROUP, END);
  940. break;
  941. case titlepage:
  942. xml_insert_element (TITLEPAGE, END);
  943. break;
  944. }
  945. }
  946. switch (type)
  947. {
  948. /* Insertions which have no effect on paragraph formatting. */
  949. case copying:
  950. line_number--;
  951. break;
  952. case ifclear:
  953. case ifdocbook:
  954. case ifinfo:
  955. case ifhtml:
  956. case ifnotdocbook:
  957. case ifnothtml:
  958. case ifnotinfo:
  959. case ifnotplaintext:
  960. case ifnottex:
  961. case ifnotxml:
  962. case ifplaintext:
  963. case ifset:
  964. case iftex:
  965. case ifxml:
  966. case rawtex:
  967. case titlepage:
  968. break;
  969. case rawdocbook:
  970. case rawhtml:
  971. case rawxml:
  972. raw_output_block--;
  973. if (raw_output_block <= 0)
  974. {
  975. xml_no_para = 0;
  976. escape_html = 1;
  977. xml_keep_space--;
  978. }
  979. if ((xml || html)
  980. && output_paragraph_offset > 0
  981. && output_paragraph[output_paragraph_offset-1] == '\n')
  982. output_paragraph_offset--;
  983. break;
  984. case detailmenu:
  985. if (xml)
  986. xml_insert_element (DETAILMENU, END);
  987. in_detailmenu--; /* No longer hacking menus. */
  988. if (!in_menu)
  989. {
  990. if (!no_headers)
  991. close_insertion_paragraph ();
  992. }
  993. break;
  994. case direntry: /* Eaten if html. */
  995. insert_string ("END-INFO-DIR-ENTRY\n\n");
  996. close_insertion_paragraph ();
  997. break;
  998. case documentdescription:
  999. if (xml)
  1000. insert_string (document_description);
  1001. xml_insert_element (DOCUMENTDESCRIPTION, END);
  1002. break;
  1003. case menu:
  1004. in_menu--; /* No longer hacking menus. */
  1005. if (html && !no_headers)
  1006. add_html_block_elt ("</ul>\n");
  1007. else if (!no_headers && !xml)
  1008. close_insertion_paragraph ();
  1009. break;
  1010. case multitable:
  1011. end_multitable ();
  1012. break;
  1013. case enumerate:
  1014. stop_enumerating ();
  1015. close_insertion_paragraph ();
  1016. current_indent -= default_indentation_increment;
  1017. if (html)
  1018. add_html_block_elt ("</ol>\n");
  1019. break;
  1020. case flushleft:
  1021. if (html)
  1022. add_html_block_elt ("</div>\n");
  1023. close_insertion_paragraph ();
  1024. break;
  1025. case cartouche:
  1026. if (html)
  1027. add_html_block_elt ("</td></tr></table>\n");
  1028. close_insertion_paragraph ();
  1029. break;
  1030. case group:
  1031. if (!xml || docbook)
  1032. close_insertion_paragraph ();
  1033. break;
  1034. case floatenv:
  1035. if (xml)
  1036. xml_insert_element (FLOAT, END);
  1037. else
  1038. {
  1039. if (html)
  1040. add_html_block_elt ("<p><strong class=\"float-caption\">");
  1041. else
  1042. close_paragraph ();
  1043. no_indent = 1;
  1044. /* Legend:
  1045. 1) @float Foo,lbl & no caption: Foo 1.1
  1046. 2) @float Foo & no caption: Foo
  1047. 3) @float ,lbl & no caption: 1.1
  1048. 4) @float & no caption: */
  1049. if (!xml && !html)
  1050. indent (current_indent);
  1051. if (strlen (current_float_type ()))
  1052. execute_string ("%s", current_float_type ());
  1053. if (strlen (current_float_id ()) > 0)
  1054. {
  1055. if (strlen (current_float_type ()) > 0)
  1056. add_char (' ');
  1057. add_word (current_float_number ());
  1058. }
  1059. if (strlen (current_float_title ()) > 0)
  1060. {
  1061. if (strlen (current_float_type ()) > 0
  1062. || strlen (current_float_id ()) > 0)
  1063. insert_string (": ");
  1064. execute_string ("%s", current_float_title ());
  1065. }
  1066. /* Indent the following paragraph. */
  1067. inhibit_paragraph_indentation = 0;
  1068. if (html)
  1069. add_word ("</strong></p></div>\n");
  1070. else
  1071. close_paragraph ();
  1072. }
  1073. float_active--;
  1074. break;
  1075. case format:
  1076. case smallformat:
  1077. case display:
  1078. case smalldisplay:
  1079. case example:
  1080. case smallexample:
  1081. case lisp:
  1082. case smalllisp:
  1083. case quotation:
  1084. /* @format and @smallformat are the only fixed_width insertion
  1085. without a change in indentation. */
  1086. if (type != format && type != smallformat && type != quotation)
  1087. current_indent -= example_indentation_increment;
  1088. else if (type == quotation && !html)
  1089. current_indent -= default_indentation_increment;
  1090. if (html)
  1091. { /* The complex code in close_paragraph that kills whitespace
  1092. does not function here, since we've inserted non-whitespace
  1093. (the </whatever>) before it. The indentation already got
  1094. inserted at the end of the last example line, so we have to
  1095. delete it, or browsers wind up showing an extra blank line.
  1096. Furthermore, if we're inside indented environments, we
  1097. might have arbitrarily much indentation, so remove it all. */
  1098. kill_self_indent (-1);
  1099. add_html_block_elt (type == quotation
  1100. ? "</blockquote>\n" : "</pre>\n");
  1101. }
  1102. /* The ending of one of these insertions always marks the
  1103. start of a new paragraph, except for the XML output. */
  1104. if (!xml || docbook)
  1105. close_insertion_paragraph ();
  1106. /* </pre> closes paragraph without messing with </p>. */
  1107. if (html && type != quotation)
  1108. paragraph_is_open = 0;
  1109. break;
  1110. case table:
  1111. case ftable:
  1112. case vtable:
  1113. current_indent -= default_indentation_increment;
  1114. if (html)
  1115. add_html_block_elt ("</dl>\n");
  1116. close_insertion_paragraph ();
  1117. break;
  1118. case itemize:
  1119. current_indent -= default_indentation_increment;
  1120. if (html)
  1121. add_html_block_elt ("</ul>\n");
  1122. close_insertion_paragraph ();
  1123. break;
  1124. case flushright:
  1125. force_flush_right--;
  1126. if (html)
  1127. add_html_block_elt ("</div>\n");
  1128. close_insertion_paragraph ();
  1129. break;
  1130. case raggedcenter:
  1131. case raggedleft:
  1132. case raggedright:
  1133. if (html)
  1134. add_html_block_elt ("</div>\n");
  1135. close_insertion_paragraph ();
  1136. break;
  1137. /* Handle the @defun insertions with this default clause. */
  1138. default:
  1139. {
  1140. int base_type;
  1141. if (type < defcv || type > defvr)
  1142. line_error ("end_insertion internal error: type=%d", type);
  1143. base_type = get_base_type (type);
  1144. switch (base_type)
  1145. {
  1146. case deffn:
  1147. case defvr:
  1148. case deftp:
  1149. case deftypecv:
  1150. case deftypefn:
  1151. case deftypevr:
  1152. case defcv:
  1153. case defop:
  1154. case deftypemethod:
  1155. case deftypeop:
  1156. case deftypeivar:
  1157. if (html)
  1158. {
  1159. if (paragraph_is_open)
  1160. add_html_block_elt ("</p>");
  1161. /* close the div and blockquote which has been opened in defun.c */
  1162. if (!rollback_empty_tag ("blockquote"))
  1163. add_html_block_elt ("</blockquote>");
  1164. add_html_block_elt ("</div>\n");
  1165. }
  1166. if (xml)
  1167. xml_end_definition ();
  1168. break;
  1169. } /* switch (base_type)... */
  1170. current_indent -= default_indentation_increment;
  1171. close_insertion_paragraph ();
  1172. }
  1173. break;
  1174. }
  1175. if (current_indent < 0)
  1176. line_error ("end_insertion internal error: current indent=%d",
  1177. current_indent);
  1178. }
  1179. /* Insertions cannot cross certain boundaries, such as node beginnings. In
  1180. code that creates such boundaries, you should call `discard_insertions'
  1181. before doing anything else. It prints the errors for you, and cleans up
  1182. the insertion stack.
  1183. With nonzero SPECIALS_OK argument, allows unmatched
  1184. @if... conditionals, otherwise not. This is because conditionals can
  1185. cross node boundaries. Always happens with the @top node, for example. */
  1186. void
  1187. discard_insertions (int specials_ok)
  1188. {
  1189. int real_line_number = line_number;
  1190. while (insertion_stack)
  1191. {
  1192. if (specials_ok
  1193. && ((ifclear <= insertion_stack->insertion
  1194. && insertion_stack->insertion <= iftex)
  1195. || insertion_stack->insertion == rawdocbook
  1196. || insertion_stack->insertion == rawhtml
  1197. || insertion_stack->insertion == rawxml
  1198. || insertion_stack->insertion == rawtex))
  1199. break;
  1200. else
  1201. {
  1202. const char *offender = insertion_type_pname (insertion_stack->insertion);
  1203. file_line_error (insertion_stack->filename,
  1204. insertion_stack->line_number,
  1205. _("No matching `%cend %s'"), COMMAND_PREFIX,
  1206. offender);
  1207. pop_insertion ();
  1208. }
  1209. }
  1210. line_number = real_line_number;
  1211. }
  1212. /* Insertion (environment) commands. */
  1213. void
  1214. cm_quotation (void)
  1215. {
  1216. /* We start the blockquote element in the insertion. */
  1217. begin_insertion (quotation);
  1218. }
  1219. void
  1220. cm_example (void)
  1221. {
  1222. if (docbook && current_insertion_type () == floatenv)
  1223. xml_begin_docbook_float (FLOATEXAMPLE);
  1224. if (xml)
  1225. {
  1226. /* Rollback previous newlines. These occur between
  1227. </para> and <example>. */
  1228. if (output_paragraph_offset > 0
  1229. && output_paragraph[output_paragraph_offset-1] == '\n')
  1230. output_paragraph_offset--;
  1231. xml_insert_element (EXAMPLE, START);
  1232. /* Make sure example text is starting on a new line
  1233. for improved readability. */
  1234. if (docbook)
  1235. add_char ('\n');
  1236. }
  1237. begin_insertion (example);
  1238. }
  1239. void
  1240. cm_smallexample (void)
  1241. {
  1242. if (docbook && current_insertion_type () == floatenv)
  1243. xml_begin_docbook_float (FLOATEXAMPLE);
  1244. if (xml)
  1245. {
  1246. /* See cm_example comments about newlines. */
  1247. if (output_paragraph_offset > 0
  1248. && output_paragraph[output_paragraph_offset-1] == '\n')
  1249. output_paragraph_offset--;
  1250. xml_insert_element (SMALLEXAMPLE, START);
  1251. if (docbook)
  1252. add_char ('\n');
  1253. }
  1254. begin_insertion (smallexample);
  1255. }
  1256. void
  1257. cm_lisp (void)
  1258. {
  1259. if (docbook && current_insertion_type () == floatenv)
  1260. xml_begin_docbook_float (FLOATEXAMPLE);
  1261. if (xml)
  1262. {
  1263. /* See cm_example comments about newlines. */
  1264. if (output_paragraph_offset > 0
  1265. && output_paragraph[output_paragraph_offset-1] == '\n')
  1266. output_paragraph_offset--;
  1267. xml_insert_element (LISP, START);
  1268. if (docbook)
  1269. add_char ('\n');
  1270. }
  1271. begin_insertion (lisp);
  1272. }
  1273. void
  1274. cm_smalllisp (void)
  1275. {
  1276. if (docbook && current_insertion_type () == floatenv)
  1277. xml_begin_docbook_float (FLOATEXAMPLE);
  1278. if (xml)
  1279. {
  1280. /* See cm_example comments about newlines. */
  1281. if (output_paragraph_offset > 0
  1282. && output_paragraph[output_paragraph_offset-1] == '\n')
  1283. output_paragraph_offset--;
  1284. xml_insert_element (SMALLLISP, START);
  1285. if (docbook)
  1286. add_char ('\n');
  1287. }
  1288. begin_insertion (smalllisp);
  1289. }
  1290. void
  1291. cm_cartouche (void)
  1292. {
  1293. if (docbook && current_insertion_type () == floatenv)
  1294. xml_begin_docbook_float (CARTOUCHE);
  1295. if (xml)
  1296. xml_insert_element (CARTOUCHE, START);
  1297. begin_insertion (cartouche);
  1298. }
  1299. void
  1300. cm_copying (void)
  1301. {
  1302. begin_insertion (copying);
  1303. }
  1304. /* Not an insertion, despite the name, but it goes with cm_copying. */
  1305. void
  1306. cm_insert_copying (void)
  1307. {
  1308. if (!copying_text)
  1309. {
  1310. warning ("@copying not used before %s", command);
  1311. return;
  1312. }
  1313. /* It is desirable that @copying is set early in the input file. For
  1314. Info output, we write the copying text out right away, and thus it
  1315. may well be the first thing in the output, and we want the file
  1316. header first. The special case in add_char has to check for
  1317. executing_string, so it won't be effective. Thus, do it explicitly. */
  1318. output_head ();
  1319. execute_string ("%s", copying_text);
  1320. if (!xml && !html)
  1321. {
  1322. add_word ("\n\n");
  1323. /* Update output_position so that the node positions in the tag
  1324. tables will take account of the copying text. */
  1325. flush_output ();
  1326. }
  1327. }
  1328. void
  1329. cm_format (void)
  1330. {
  1331. if (xml)
  1332. {
  1333. if (docbook && xml_in_bookinfo)
  1334. {
  1335. xml_insert_element (ABSTRACT, START);
  1336. xml_in_abstract = 1;
  1337. }
  1338. else
  1339. {
  1340. /* See cm_example comments about newlines. */
  1341. if (output_paragraph_offset > 0
  1342. && output_paragraph[output_paragraph_offset-1] == '\n')
  1343. output_paragraph_offset--;
  1344. xml_insert_element (FORMAT, START);
  1345. if (docbook)
  1346. add_char ('\n');
  1347. }
  1348. }
  1349. begin_insertion (format);
  1350. }
  1351. void
  1352. cm_smallformat (void)
  1353. {
  1354. if (xml)
  1355. {
  1356. /* See cm_example comments about newlines. */
  1357. if (output_paragraph_offset > 0
  1358. && output_paragraph[output_paragraph_offset-1] == '\n')
  1359. output_paragraph_offset--;
  1360. xml_insert_element (SMALLFORMAT, START);
  1361. if (docbook)
  1362. add_char ('\n');
  1363. }
  1364. begin_insertion (smallformat);
  1365. }
  1366. void
  1367. cm_display (void)
  1368. {
  1369. if (xml)
  1370. {
  1371. /* See cm_example comments about newlines. */
  1372. if (output_paragraph_offset > 0
  1373. && output_paragraph[output_paragraph_offset-1] == '\n')
  1374. output_paragraph_offset--;
  1375. xml_insert_element (DISPLAY, START);
  1376. if (docbook)
  1377. add_char ('\n');
  1378. }
  1379. begin_insertion (display);
  1380. }
  1381. void
  1382. cm_smalldisplay (void)
  1383. {
  1384. if (xml)
  1385. {
  1386. /* See cm_example comments about newlines. */
  1387. if (output_paragraph_offset > 0
  1388. && output_paragraph[output_paragraph_offset-1] == '\n')
  1389. output_paragraph_offset--;
  1390. xml_insert_element (SMALLDISPLAY, START);
  1391. if (docbook)
  1392. add_char ('\n');
  1393. }
  1394. begin_insertion (smalldisplay);
  1395. }
  1396. void
  1397. cm_direntry (void)
  1398. {
  1399. if (html || xml || no_headers)
  1400. command_name_condition ();
  1401. else
  1402. begin_insertion (direntry);
  1403. }
  1404. void
  1405. cm_documentdescription (void)
  1406. {
  1407. if (html)
  1408. begin_insertion (documentdescription);
  1409. else if (xml)
  1410. {
  1411. xml_insert_element (DOCUMENTDESCRIPTION, START);
  1412. begin_insertion (documentdescription);
  1413. }
  1414. else
  1415. command_name_condition ();
  1416. }
  1417. void
  1418. cm_itemize (void)
  1419. {
  1420. begin_insertion (itemize);
  1421. }
  1422. /* Start an enumeration insertion of type TYPE. If the user supplied
  1423. no argument on the line, then use DEFAULT_STRING as the initial string. */
  1424. static void
  1425. do_enumeration (enum insertion_type type, char *default_string)
  1426. {
  1427. get_until_in_line (0, ".", &enumeration_arg);
  1428. canon_white (enumeration_arg);
  1429. if (!*enumeration_arg)
  1430. {
  1431. free (enumeration_arg);
  1432. enumeration_arg = xstrdup (default_string);
  1433. }
  1434. if (!isdigit (*enumeration_arg) && !isletter (*enumeration_arg))
  1435. {
  1436. warning (_("%s requires letter or digit"), insertion_type_pname (type));
  1437. switch (type)
  1438. {
  1439. case enumerate:
  1440. default_string = "1";
  1441. break;
  1442. }
  1443. enumeration_arg = xstrdup (default_string);
  1444. }
  1445. begin_insertion (type);
  1446. }
  1447. void
  1448. cm_enumerate (void)
  1449. {
  1450. do_enumeration (enumerate, "1");
  1451. }
  1452. /* Handle verbatim environment:
  1453. find_end_verbatim == 0: process until end of file
  1454. find_end_verbatim != 0: process until 'COMMAND_PREFIXend verbatim'
  1455. or end of file
  1456. No indentation is inserted: this is verbatim after all.
  1457. If you want indentation, enclose @verbatim in @example.
  1458. Thus, we cannot simply copy the input to the output, since the
  1459. verbatim environment may be encapsulated in an @example environment,
  1460. for example. */
  1461. void
  1462. handle_verbatim_environment (int find_end_verbatim)
  1463. {
  1464. int character;
  1465. int seen_end = 0;
  1466. int save_filling_enabled = filling_enabled;
  1467. int save_inhibit_paragraph_indentation = inhibit_paragraph_indentation;
  1468. if (!insertion_stack)
  1469. close_single_paragraph (); /* no blank lines if not at outer level */
  1470. inhibit_paragraph_indentation = 1;
  1471. filling_enabled = 0;
  1472. in_fixed_width_font++;
  1473. last_char_was_newline = 0;
  1474. if (html)
  1475. { /* If inside @example, we'll be preceded by the indentation
  1476. already. Browsers will ignore those spaces because we're about
  1477. to start another <pre> (don't ask me). So, wipe them out for
  1478. cleanliness, and re-insert. */
  1479. int i;
  1480. kill_self_indent (default_indentation_increment);
  1481. add_html_block_elt ("<pre class=\"verbatim\">");
  1482. for (i = current_indent; i > 0; i--)
  1483. add_char (' ');
  1484. }
  1485. else if (xml)
  1486. {
  1487. xml_insert_element (VERBATIM, START);
  1488. }
  1489. if (find_end_verbatim)
  1490. { /* Ignore the remainder of the @verbatim line. */
  1491. char *junk;
  1492. get_rest_of_line (0, &junk);
  1493. free (junk);
  1494. }
  1495. while (input_text_offset < input_text_length)
  1496. {
  1497. character = curchar ();
  1498. if (character == '\n')
  1499. line_number++;
  1500. /* Assume no newlines in END_VERBATIM. */
  1501. else if (find_end_verbatim && (character == COMMAND_PREFIX) /* @ */
  1502. && (input_text_length - input_text_offset > sizeof (END_VERBATIM))
  1503. && !strncmp (&input_text[input_text_offset+1], END_VERBATIM,
  1504. sizeof (END_VERBATIM)-1))
  1505. {
  1506. input_text_offset += sizeof (END_VERBATIM);
  1507. seen_end = 1;
  1508. break;
  1509. }
  1510. if (html && character == '&' && escape_html)
  1511. add_word ("&amp;");
  1512. else if (html && character == '<' && escape_html)
  1513. add_word ("&lt;");
  1514. else
  1515. add_char (character);
  1516. input_text_offset++;
  1517. }
  1518. if (find_end_verbatim && !seen_end)
  1519. warning (_("end of file inside verbatim block"));
  1520. if (html)
  1521. { /* See comments in example case above. */
  1522. kill_self_indent (default_indentation_increment);
  1523. add_word ("</pre>");
  1524. }
  1525. else if (xml)
  1526. {
  1527. xml_insert_element (VERBATIM, END);
  1528. }
  1529. in_fixed_width_font--;
  1530. filling_enabled = save_filling_enabled;
  1531. inhibit_paragraph_indentation = save_inhibit_paragraph_indentation;
  1532. }
  1533. void
  1534. cm_verbatim (void)
  1535. {
  1536. handle_verbatim_environment (1);
  1537. }
  1538. void
  1539. cm_table (void)
  1540. {
  1541. begin_insertion (table);
  1542. }
  1543. void
  1544. cm_multitable (void)
  1545. {
  1546. begin_insertion (multitable); /* @@ */
  1547. }
  1548. void
  1549. cm_ftable (void)
  1550. {
  1551. begin_insertion (ftable);
  1552. }
  1553. void
  1554. cm_vtable (void)
  1555. {
  1556. begin_insertion (vtable);
  1557. }
  1558. void
  1559. cm_group (void)
  1560. {
  1561. begin_insertion (group);
  1562. }
  1563. /* Insert raw HTML (no escaping of `<' etc.). */
  1564. void
  1565. cm_html (int arg)
  1566. {
  1567. if (process_html)
  1568. begin_insertion (rawhtml);
  1569. else
  1570. command_name_condition ();
  1571. }
  1572. void
  1573. cm_xml (int arg)
  1574. {
  1575. if (process_xml)
  1576. begin_insertion (rawxml);
  1577. else
  1578. command_name_condition ();
  1579. }
  1580. void
  1581. cm_docbook (int arg)
  1582. {
  1583. if (process_docbook)
  1584. begin_insertion (rawdocbook);
  1585. else
  1586. command_name_condition ();
  1587. }
  1588. void
  1589. cm_ifdocbook (void)
  1590. {
  1591. if (process_docbook)
  1592. begin_insertion (ifdocbook);
  1593. else
  1594. command_name_condition ();
  1595. }
  1596. void
  1597. cm_ifnotdocbook (void)
  1598. {
  1599. if (!process_docbook)
  1600. begin_insertion (ifnotdocbook);
  1601. else
  1602. command_name_condition ();
  1603. }
  1604. void
  1605. cm_ifhtml (void)
  1606. {
  1607. if (process_html)
  1608. begin_insertion (ifhtml);
  1609. else
  1610. command_name_condition ();
  1611. }
  1612. void
  1613. cm_ifnothtml (void)
  1614. {
  1615. if (!process_html)
  1616. begin_insertion (ifnothtml);
  1617. else
  1618. command_name_condition ();
  1619. }
  1620. void
  1621. cm_ifinfo (void)
  1622. {
  1623. if (process_info)
  1624. begin_insertion (ifinfo);
  1625. else
  1626. command_name_condition ();
  1627. }
  1628. void
  1629. cm_ifnotinfo (void)
  1630. {
  1631. if (!process_info)
  1632. begin_insertion (ifnotinfo);
  1633. else
  1634. command_name_condition ();
  1635. }
  1636. void
  1637. cm_ifplaintext (void)
  1638. {
  1639. if (process_plaintext)
  1640. begin_insertion (ifplaintext);
  1641. else
  1642. command_name_condition ();
  1643. }
  1644. void
  1645. cm_ifnotplaintext (void)
  1646. {
  1647. if (!process_plaintext)
  1648. begin_insertion (ifnotplaintext);
  1649. else
  1650. command_name_condition ();
  1651. }
  1652. void
  1653. cm_tex (void)
  1654. {
  1655. if (process_tex)
  1656. begin_insertion (rawtex);
  1657. else
  1658. command_name_condition ();
  1659. }
  1660. void
  1661. cm_iftex (void)
  1662. {
  1663. if (process_tex)
  1664. begin_insertion (iftex);
  1665. else
  1666. command_name_condition ();
  1667. }
  1668. void
  1669. cm_ifnottex (void)
  1670. {
  1671. if (!process_tex)
  1672. begin_insertion (ifnottex);
  1673. else
  1674. command_name_condition ();
  1675. }
  1676. void
  1677. cm_ifxml (void)
  1678. {
  1679. if (process_xml)
  1680. begin_insertion (ifxml);
  1681. else
  1682. command_name_condition ();
  1683. }
  1684. void
  1685. cm_ifnotxml (void)
  1686. {
  1687. if (!process_xml)
  1688. begin_insertion (ifnotxml);
  1689. else
  1690. command_name_condition ();
  1691. }
  1692. /* Generic xrefable block with a caption. */
  1693. void
  1694. cm_float (void)
  1695. {
  1696. begin_insertion (floatenv);
  1697. }
  1698. void
  1699. cm_caption (int arg)
  1700. {
  1701. char *temp;
  1702. /* This is a no_op command for most formats, as we handle it during @float
  1703. insertion. For XML though, we handle it here to keep document structure
  1704. as close as possible, to the Texinfo source. */
  1705. /* Everything is already handled at START. */
  1706. if (arg == END)
  1707. return;
  1708. /* Check if it's mislocated. */
  1709. if (current_insertion_type () != floatenv)
  1710. line_error (_("@%s not meaningful outside `@float' environment"), command);
  1711. get_until_in_braces ("\n@end float", &temp);
  1712. if (xml)
  1713. {
  1714. int elt = STREQ (command, "shortcaption") ? SHORTCAPTION : CAPTION;
  1715. xml_insert_element (elt, START);
  1716. if (!docbook)
  1717. execute_string ("%s", temp);
  1718. xml_insert_element (elt, END);
  1719. }
  1720. free (temp);
  1721. }
  1722. /* Begin an insertion where the lines are not filled or indented. */
  1723. void
  1724. cm_flushleft (void)
  1725. {
  1726. begin_insertion (flushleft);
  1727. }
  1728. /* Begin an insertion where the lines are not filled, and each line is
  1729. forced to the right-hand side of the page. */
  1730. void
  1731. cm_flushright (void)
  1732. {
  1733. begin_insertion (flushright);
  1734. }
  1735. void
  1736. cm_menu (void)
  1737. {
  1738. if (current_node == NULL && !macro_expansion_output_stream)
  1739. {
  1740. warning (_("@menu seen before first @node, creating `Top' node"));
  1741. warning (_("perhaps your @top node should be wrapped in @ifnottex rather than @ifinfo?"));
  1742. /* Include @top command so we can construct the implicit node tree. */
  1743. execute_string ("@node top\n@top Top\n");
  1744. }
  1745. begin_insertion (menu);
  1746. }
  1747. void
  1748. cm_detailmenu (void)
  1749. {
  1750. if (current_node == NULL && !macro_expansion_output_stream)
  1751. { /* Problems anyway, @detailmenu should always be inside @menu. */
  1752. warning (_("@detailmenu seen before first node, creating `Top' node"));
  1753. execute_string ("@node top\n@top Top\n");
  1754. }
  1755. begin_insertion (detailmenu);
  1756. }
  1757. void
  1758. cm_raggedcenter (void)
  1759. {
  1760. begin_insertion (raggedcenter);
  1761. }
  1762. void
  1763. cm_raggedleft (void)
  1764. {
  1765. begin_insertion (raggedleft);
  1766. }
  1767. void
  1768. cm_raggedright (void)
  1769. {
  1770. begin_insertion (raggedright);
  1771. }
  1772. /* Title page commands. */
  1773. void
  1774. cm_titlepage (void)
  1775. {
  1776. titlepage_cmd_present = 1;
  1777. if (xml && !docbook)
  1778. begin_insertion (titlepage);
  1779. else
  1780. command_name_condition ();
  1781. }
  1782. void
  1783. cm_author (void)
  1784. {
  1785. char *rest;
  1786. get_rest_of_line (1, &rest);
  1787. if (is_in_insertion_of_type (quotation))
  1788. {
  1789. if (html)
  1790. add_word_args ("&mdash; %s", rest);
  1791. else if (docbook)
  1792. {
  1793. /* FIXME Ideally, we should use an attribution element,
  1794. but they are supposed to be at the start of quotation
  1795. blocks. So to avoid looking ahead mess, let's just
  1796. use mdash like HTML for now. */
  1797. xml_insert_entity ("mdash");
  1798. add_word (rest);
  1799. }
  1800. else if (xml)
  1801. {
  1802. xml_insert_element (AUTHOR, START);
  1803. add_word (rest);
  1804. xml_insert_element (AUTHOR, END);
  1805. }
  1806. else
  1807. add_word_args ("-- %s", rest);
  1808. }
  1809. else if (is_in_insertion_of_type (titlepage))
  1810. {
  1811. if (xml && !docbook)
  1812. {
  1813. xml_insert_element (AUTHOR, START);
  1814. add_word (rest);
  1815. xml_insert_element (AUTHOR, END);
  1816. }
  1817. }
  1818. else
  1819. line_error (_("@%s not meaningful outside `@titlepage' and `@quotation' environments"),
  1820. command);
  1821. free (rest);
  1822. }
  1823. void
  1824. cm_titlepage_cmds (void)
  1825. {
  1826. char *rest;
  1827. get_rest_of_line (1, &rest);
  1828. if (!is_in_insertion_of_type (titlepage))
  1829. line_error (_("@%s not meaningful outside `@titlepage' environment"),
  1830. command);
  1831. if (xml && !docbook)
  1832. {
  1833. int elt = 0;
  1834. if (STREQ (command, "title"))
  1835. elt = BOOKTITLE;
  1836. else if (STREQ (command, "subtitle"))
  1837. elt = BOOKSUBTITLE;
  1838. xml_insert_element (elt, START);
  1839. add_word (rest);
  1840. xml_insert_element (elt, END);
  1841. }
  1842. free (rest);
  1843. }
  1844. /* End existing insertion block. */
  1845. void
  1846. cm_end (void)
  1847. {
  1848. char *temp;
  1849. enum insertion_type type;
  1850. get_rest_of_line (0, &temp);
  1851. if (!insertion_level)
  1852. {
  1853. line_error (_("Unmatched `%c%s'"), COMMAND_PREFIX, command);
  1854. return;
  1855. }
  1856. if (temp[0] == 0)
  1857. line_error (_("`%c%s' needs something after it"), COMMAND_PREFIX, command);
  1858. type = find_type_from_name (temp);
  1859. if (type == bad_type)
  1860. {
  1861. line_error (_("Bad argument `%s' to `@%s', using `%s'"),
  1862. temp, command, insertion_type_pname (current_insertion_type ()));
  1863. }
  1864. if (xml && type == menu) /* fixme */
  1865. {
  1866. xml_end_menu ();
  1867. }
  1868. end_insertion (type);
  1869. free (temp);
  1870. }
  1871. /* @itemx, @item. */
  1872. static int itemx_flag = 0;
  1873. /* Return whether CMD takes a brace-delimited {arg}. */
  1874. int
  1875. command_needs_braces (char *cmd)
  1876. {
  1877. int i;
  1878. for (i = 0; command_table[i].name; i++)
  1879. {
  1880. if (STREQ (command_table[i].name, cmd))
  1881. return command_table[i].argument_in_braces == BRACE_ARGS;
  1882. }
  1883. return 0; /* macro or alias */
  1884. }
  1885. void
  1886. cm_item (void)
  1887. {
  1888. char *rest_of_line, *item_func;
  1889. /* Can only hack "@item" while inside of an insertion. */
  1890. if (insertion_level)
  1891. {
  1892. INSERTION_ELT *stack = insertion_stack;
  1893. int original_input_text_offset;
  1894. skip_whitespace ();
  1895. original_input_text_offset = input_text_offset;
  1896. get_rest_of_line (0, &rest_of_line);
  1897. item_func = current_item_function ();
  1898. /* Do the right thing depending on which insertion function is active. */
  1899. switch_top:
  1900. switch (stack->insertion)
  1901. {
  1902. case multitable:
  1903. multitable_item ();
  1904. /* Support text directly after the @item. */
  1905. if (*rest_of_line)
  1906. {
  1907. line_number--;
  1908. input_text_offset = original_input_text_offset;
  1909. }
  1910. break;
  1911. case ifclear:
  1912. case ifhtml:
  1913. case ifinfo:
  1914. case ifnothtml:
  1915. case ifnotinfo:
  1916. case ifnotplaintext:
  1917. case ifnottex:
  1918. case ifnotxml:
  1919. case ifplaintext:
  1920. case ifset:
  1921. case iftex:
  1922. case ifxml:
  1923. case rawdocbook:
  1924. case rawhtml:
  1925. case rawxml:
  1926. case rawtex:
  1927. case tex:
  1928. case cartouche:
  1929. stack = stack->next;
  1930. if (!stack)
  1931. goto no_insertion;
  1932. else
  1933. goto switch_top;
  1934. break;
  1935. case menu:
  1936. case quotation:
  1937. case example:
  1938. case smallexample:
  1939. case lisp:
  1940. case smalllisp:
  1941. case format:
  1942. case smallformat:
  1943. case display:
  1944. case smalldisplay:
  1945. case group:
  1946. line_error (_("@%s not meaningful inside `@%s' block"),
  1947. command,
  1948. insertion_type_pname (current_insertion_type ()));
  1949. break;
  1950. case itemize:
  1951. case enumerate:
  1952. if (itemx_flag)
  1953. {
  1954. line_error (_("@itemx not meaningful inside `%s' block"),
  1955. insertion_type_pname (current_insertion_type ()));
  1956. }
  1957. else
  1958. {
  1959. if (html)
  1960. add_html_block_elt ("<li>");
  1961. else if (xml)
  1962. xml_begin_item ();
  1963. else
  1964. {
  1965. start_paragraph ();
  1966. kill_self_indent (-1);
  1967. filling_enabled = indented_fill = 1;
  1968. if (current_item_function ())
  1969. {
  1970. indent (current_indent - 2);
  1971. /* The item marker can be given with or without
  1972. braces -- @bullet and @bullet{} are both ok.
  1973. Or it might be something that doesn't take
  1974. braces at all, such as "o" or "#" or "@ ".
  1975. Thus, only supply braces if the item marker is
  1976. a command, they haven't supplied braces
  1977. themselves, and we know it needs them. */
  1978. if (item_func && *item_func)
  1979. {
  1980. if (*item_func == COMMAND_PREFIX
  1981. && item_func[strlen (item_func) - 1] != '}'
  1982. && command_needs_braces (item_func + 1))
  1983. execute_string ("%s{}", item_func);
  1984. else
  1985. execute_string ("%s", item_func);
  1986. }
  1987. insert (' ');
  1988. }
  1989. else
  1990. enumerate_item ();
  1991. /* Special hack. This makes `close_paragraph' a no-op until
  1992. `start_paragraph' has been called. */
  1993. must_start_paragraph = 1;
  1994. }
  1995. /* Handle text directly after the @item. */
  1996. if (*rest_of_line)
  1997. {
  1998. line_number--;
  1999. input_text_offset = original_input_text_offset;
  2000. }
  2001. }
  2002. break;
  2003. case table:
  2004. case ftable:
  2005. case vtable:
  2006. if (html)
  2007. { /* If nothing has been output since the last <dd>,
  2008. remove the empty <dd> element. Some browsers render
  2009. an extra empty line for <dd><dt>, which makes @itemx
  2010. conversion look ugly. */
  2011. rollback_empty_tag ("dd");
  2012. /* Force the browser to render one blank line before
  2013. each new @item in a table. But don't do that if
  2014. this is the first <dt> after the <dl>, or if we are
  2015. converting @itemx.
  2016. Note that there are some browsers which ignore <br>
  2017. in this context, but I cannot find any way to force
  2018. them all render exactly one blank line. */
  2019. if (!itemx_flag && html_deflist_has_term)
  2020. add_html_block_elt ("<br>");
  2021. /* We are about to insert a <dt>, so this <dl> has a term.
  2022. Feel free to insert a <br> next time. :) */
  2023. html_deflist_has_term = 1;
  2024. add_html_block_elt ("<dt>");
  2025. if (item_func && *item_func)
  2026. execute_string ("%s{%s}", item_func, rest_of_line);
  2027. else
  2028. execute_string ("%s", rest_of_line);
  2029. if (current_insertion_type () == ftable)
  2030. execute_string ("%cfindex %s\n", COMMAND_PREFIX, rest_of_line);
  2031. if (current_insertion_type () == vtable)
  2032. execute_string ("%cvindex %s\n", COMMAND_PREFIX, rest_of_line);
  2033. add_html_block_elt ("<dd>");
  2034. }
  2035. else if (xml) /* && docbook)*/ /* 05-08 */
  2036. {
  2037. xml_begin_table_item ();
  2038. if (!docbook && current_insertion_type () == ftable)
  2039. execute_string ("%cfindex %s\n", COMMAND_PREFIX, rest_of_line);
  2040. if (!docbook && current_insertion_type () == vtable)
  2041. execute_string ("%cvindex %s\n", COMMAND_PREFIX, rest_of_line);
  2042. if (item_func && *item_func)
  2043. execute_string ("%s{%s}", item_func, rest_of_line);
  2044. else
  2045. execute_string ("%s", rest_of_line);
  2046. xml_continue_table_item ();
  2047. }
  2048. else
  2049. {
  2050. /* We need this to determine if we have two @item's in a row
  2051. (see test just below). */
  2052. static int last_item_output_position = 0;
  2053. /* Get rid of extra characters. */
  2054. kill_self_indent (-1);
  2055. /* If we have one @item followed directly by another @item,
  2056. we need to insert a blank line. This is not true for
  2057. @itemx, though. */
  2058. if (!itemx_flag && last_item_output_position == output_position)
  2059. insert ('\n');
  2060. /* `close_paragraph' almost does what we want. The problem
  2061. is when paragraph_is_open, and last_char_was_newline, and
  2062. the last newline has been turned into a space, because
  2063. filling_enabled. I handle it here. */
  2064. if (last_char_was_newline && filling_enabled &&
  2065. paragraph_is_open)
  2066. insert ('\n');
  2067. close_paragraph ();
  2068. #if defined (INDENT_PARAGRAPHS_IN_TABLE)
  2069. /* Indent on a new line, but back up one indentation level. */
  2070. {
  2071. int save = inhibit_paragraph_indentation;
  2072. inhibit_paragraph_indentation = 1;
  2073. /* At this point, inserting any non-whitespace character will
  2074. force the existing indentation to be output. */
  2075. add_char ('i');
  2076. inhibit_paragraph_indentation = save;
  2077. }
  2078. #else /* !INDENT_PARAGRAPHS_IN_TABLE */
  2079. add_char ('i');
  2080. #endif /* !INDENT_PARAGRAPHS_IN_TABLE */
  2081. output_paragraph_offset--;
  2082. kill_self_indent (default_indentation_increment + 1);
  2083. /* Add item's argument to the line. */
  2084. filling_enabled = 0;
  2085. if (item_func && *item_func)
  2086. execute_string ("%s{%s}", item_func, rest_of_line);
  2087. else
  2088. execute_string ("%s", rest_of_line);
  2089. if (current_insertion_type () == ftable)
  2090. execute_string ("%cfindex %s\n", COMMAND_PREFIX, rest_of_line);
  2091. else if (current_insertion_type () == vtable)
  2092. execute_string ("%cvindex %s\n", COMMAND_PREFIX, rest_of_line);
  2093. /* Start a new line, and let start_paragraph ()
  2094. do the indenting of it for you. */
  2095. close_single_paragraph ();
  2096. indented_fill = filling_enabled = 1;
  2097. last_item_output_position = output_position;
  2098. }
  2099. }
  2100. free (rest_of_line);
  2101. }
  2102. else
  2103. {
  2104. no_insertion:
  2105. line_error (_("%c%s found outside of an insertion block"),
  2106. COMMAND_PREFIX, command);
  2107. }
  2108. }
  2109. void
  2110. cm_itemx (void)
  2111. {
  2112. itemx_flag++;
  2113. cm_item ();
  2114. itemx_flag--;
  2115. }
  2116. int headitem_flag = 0;
  2117. void
  2118. cm_headitem (void)
  2119. {
  2120. headitem_flag = 1;
  2121. cm_item ();
  2122. }