1 /* xml.c -- xml output.
2 $Id: xml.c,v 1.11 2002/03/23 20:41:12 karl Exp $
4 Copyright (C) 2001, 02 Free Software Foundation, Inc.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 Written by Philippe Martin <feloy@free.fr>. */
24 #include "insertion.h"
32 int xml_index_divisions = 1;
35 void xml_close_sections (/* int level */);
37 typedef struct _element
41 int contained_in_para;
44 element texinfoml_element_list [] = {
46 { "setfilename", 0, 0 },
47 { "titlefont", 0, 0 },
57 { "subsection", 1, 0 },
58 { "subsubsection", 1, 0 },
61 { "unnumbered", 1, 0 },
62 { "unnumberedsec", 1, 0 },
63 { "unnumberedsubsec", 1, 0 },
64 { "unnumberedsubsubsec", 1, 0 },
67 { "appendixsec", 1, 0 },
68 { "appendixsubsec", 1, 0 },
69 { "appendixsubsubsec", 1, 0 },
71 { "majorheading", 1, 0 },
72 { "chapheading", 1, 0 },
74 { "subheading", 1, 0 },
75 { "subsubheading", 1, 0 },
78 { "menuentry", 1, 0 },
79 { "menutitle", 0, 0 },
80 { "menucomment", 1, 0 },
96 { "notfixedwidth", 0, 1 },
105 { "dircategory", 0, 0 },
106 { "quotation", 1, 0 },
108 { "smallexample", 1, 0 },
110 { "smalllisp", 1, 0 },
111 { "cartouche", 1, 0 },
114 { "smallformat", 1, 0 },
116 { "smalldisplay", 1, 0 },
117 { "footnote", 0, 1 },
120 { "itemfunction", 0, 0 },
122 { "enumerate", 0, 0 },
124 { "tableitem", 0, 0 }, /* not used */ /* TABLEITEM */
125 { "tableterm", 0, 0 }, /* not used */ /* TABLETERM */
127 { "indexterm", 0, 1 },
130 { "xrefnodename", 0, 1 },
131 { "xrefinfoname", 0, 1 },
132 { "xrefprinteddesc", 0, 1 },
133 { "xrefinfofile", 0, 1 },
134 { "xrefprintedname", 0, 1 },
137 { "inforefnodename", 0, 1 },
138 { "inforefrefname", 0, 1 },
139 { "inforefinfoname", 0, 1 },
143 { "urefdesc", 0, 1 },
144 { "urefreplacement", 0, 1 },
147 { "emailaddress", 0, 1 },
148 { "emailname", 0, 1 },
152 { "printindex", 0, 0 },
155 { "", 0, 1 }, /* PRIMARY (docbook) */
156 { "", 0, 1 }, /* SECONDARY (docbook) */
157 { "", 0, 0 }, /* INFORMALFIGURE (docbook) */
158 { "", 0, 0 }, /* MEDIAOBJECT (docbook) */
159 { "", 0, 0 }, /* IMAGEOBJECT (docbook) */
160 { "", 0, 0 }, /* IMAGEDATA (docbook) */
161 { "", 0, 0 }, /* TEXTOBJECT (docbook) */
162 { "", 0, 0 }, /* INDEXENTRY (docbook) */
163 { "", 0, 0 }, /* PRIMARYIE (docbook) */
164 { "", 0, 0 }, /* SECONDARYIE (docbook) */
165 { "", 0, 0 }, /* INDEXDIV (docbook) */
166 { "multitable", 0, 0 },
167 { "", 0, 0 }, /* TGROUP (docbook) */
168 { "columnfraction", 0, 0 },
169 { "", 0, 0 }, /* TBODY (docbook) */
170 { "entry", 0, 0 }, /* ENTRY (docbook) */
171 { "row", 0, 0 }, /* ROW (docbook) */
172 { "", 0, 0 }, /* BOOKINFO (docbook) */
173 { "", 0, 0 }, /* ABSTRACT (docbook) */
174 { "", 0, 0 }, /* REPLACEABLE (docbook) */
175 { "para", 0, 0 } /* Must be last */
176 /* name / contains para / contained in para */
179 element docbook_element_list [] = {
180 { "book", 0, 0 }, /* TEXINFO */
181 { "", 0, 0 }, /* SETFILENAME */
182 { "", 0, 0 }, /* TITLEINFO */
183 { "title", 0, 0 }, /* SETTITLE */
185 { "", 1, 0 }, /* NODE */
186 { "", 0, 0 }, /* NODENEXT */
187 { "", 0, 0 }, /* NODEPREV */
188 { "", 0, 0 }, /* NODEUP */
191 { "sect1", 1, 0 }, /* SECTION */
192 { "sect2", 1, 0 }, /* SUBSECTION */
193 { "sect3", 1, 0 }, /* SUBSUBSECTION */
195 { "chapter", 1, 0 }, /* TOP */
196 { "chapter", 1, 0 }, /* UNNUMBERED */
197 { "sect1", 1, 0 }, /* UNNUMBEREDSEC */
198 { "sect2", 1, 0 }, /* UNNUMBEREDSUBSEC */
199 { "sect3", 1, 0 }, /* UNNUMBEREDSUBSUBSEC */
201 { "appendix", 1, 0 },
202 { "sect1", 1, 0 }, /* APPENDIXSEC */
203 { "sect2", 1, 0 }, /* APPENDIXSUBSEC */
204 { "sect3", 1, 0 }, /* APPENDIXSUBSUBSEC */
206 { "chapter", 1, 0 }, /* MAJORHEADING */
207 { "chapter", 1, 0 }, /* CHAPHEADING */
208 { "sect1", 1, 0 }, /* HEADING */
209 { "sect2", 1, 0 }, /* SUBHEADING */
210 { "sect3", 1, 0 }, /* SUBSUBHEADING */
212 { "", 1, 0 }, /* MENU */
213 { "", 1, 0 }, /* MENUENTRY */
214 { "", 0, 0 }, /* MENUTITLE */
215 { "", 1, 0 }, /* MENUCOMMENT */
216 { "", 0, 0 }, /* MENUNODE */
217 { "anchor", 0, 0 }, /* NODENAME */
220 { "wordasword", 0, 1 }, /* TT */
221 { "command", 0, 1 }, /* CODE */
222 { "userinput", 0, 1 }, /* KBD */
223 { "wordasword", 0, 1 }, /* URL */
224 { "keycap", 0, 1 }, /* KEY */
225 { "varname", 0, 1 }, /* VAR */
226 { "", 0, 1 }, /* SC */
227 { "firstterm", 0, 1 }, /* DFN */
228 { "emphasis", 0, 1 }, /* EMPH */
229 { "emphasis", 0, 1 }, /* STRONG */
230 { "citation", 0, 1 }, /* CITE */
231 { "", 0, 1 }, /* NOTFIXEDWIDTH */
232 { "wordasword", 0, 1 }, /* I */
233 { "wordasword", 0, 1 }, /* B */
234 { "", 0, 1 }, /* R */
237 { "", 1, 0 }, /* IFINFO */
238 { "", 0, 0 }, /* SP */
239 { "", 1, 0 }, /* CENTER */
240 { "", 0, 0 }, /* DIRCATEGORY */
241 { "blockquote", 1, 0 }, /* QUOTATION */
243 { "screen", 0, 1 }, /* SMALLEXAMPLE */
244 { "screen", 0, 1 }, /* LISP */
245 { "screen", 0, 1 }, /* SMALLLISP */
246 { "", 1, 0 }, /* CARTOUCHE */
247 { "", 1, 0 }, /* COPYING */
248 { "screen", 0, 1 }, /* FORMAT */
249 { "screen", 0, 1 }, /* SMALLFORMAT */
250 { "screen", 0, 1 }, /* DISPLAY */
251 { "screen", 0, 1 }, /* SMALLDISPLAY */
252 { "footnote", 0, 1 },
254 { "itemizedlist", 0, 0 }, /* ITEMIZE */
255 { "", 0, 0 }, /* ITEMFUNCTION */
256 { "listitem", 1, 0 },
257 { "orderedlist", 0, 0 }, /* ENUMERATE */
258 { "variablelist", 0, 0 }, /* TABLE */
259 { "varlistentry", 0, 0 }, /* TABLEITEM */
260 { "term", 0, 0 }, /* TABLETERM */
262 { "indexterm", 0, 1 },
264 { "xref", 0, 1 }, /* XREF */
265 { "link", 0, 1 }, /* XREFNODENAME */
266 { "", 0, 1 }, /* XREFINFONAME */
267 { "", 0, 1 }, /* XREFPRINTEDDESC */
268 { "", 0, 1 }, /* XREFINFOFILE */
269 { "", 0, 1 }, /* XREFPRINTEDNAME */
271 { "", 0, 1 }, /* INFOREF */
272 { "", 0, 1 }, /* INFOREFNODENAME */
273 { "", 0, 1 }, /* INFOREFREFNAME */
274 { "", 0, 1 }, /* INFOREFINFONAME */
276 { "", 0, 1 }, /* UREF */
277 { "", 0, 1 }, /* UREFURL */
278 { "", 0, 1 }, /* UREFDESC */
279 { "", 0, 1 }, /* UREFREPLACEMENT */
281 { "ulink", 0, 1 }, /* EMAIL */
282 { "", 0, 1 }, /* EMAILADDRESS */
283 { "", 0, 1 }, /* EMAILNAME */
285 { "", 0, 0 }, /* GROUP */
287 { "index", 0, 0 }, /* PRINTINDEX */
288 { "", 0, 1 }, /* ANCHOR */
289 { "", 0, 1 }, /* IMAGE */
290 { "primary", 0, 1 }, /* PRIMARY */
291 { "secondary", 0, 1 },
292 { "informalfigure", 0, 0 },
293 { "mediaobject", 0, 0 },
294 { "imageobject", 0, 0 },
295 { "imagedata", 0, 0 },
296 { "textobject", 0, 0 },
297 { "indexentry", 0, 0 },
298 { "primaryie", 0, 0 },
299 { "secondaryie", 0, 0 },
300 { "indexdiv", 0, 0 },
301 { "informaltable", 0, 0 },
307 { "bookinfo", 0, 0 },
308 { "abstract", 1, 0 },
309 { "replaceable", 0, 0 },
311 { "para", 0, 0 } /* Must be last */
312 /* name / contains para / contained in para */
315 element *xml_element_list = NULL;
318 typedef struct _replace_element
320 int element_to_replace;
321 int element_containing;
322 int element_replacing;
325 /* Elements to replace - Docbook only
327 if `element_to_replace' have to be inserted
328 as a child of `element_containing,'
329 use `element_replacing' instead.
331 A value of `-1' for element_replacing means `do not use any element.'
334 replace_element replace_elements [] = {
335 { I, TABLETERM, EMPH },
336 { B, TABLETERM, EMPH },
338 { EXAMPLE, DISPLAY, -1 },
341 { EMPH, CODE, REPLACEABLE },
342 /* Add your elements to replace here */
346 int xml_in_menu_entry = 0;
347 int xml_in_menu_entry_comment = 0;
348 int xml_node_open = 0;
349 int xml_node_level = -1;
351 int xml_just_after_element = 0;
354 char *xml_node_id = NULL;
355 int xml_sort_index = 0;
357 static int xml_after_table_term = 0;
358 static int book_started = 0;
359 static int first_section_opened = 0;
360 static int in_abstract = 0;
362 static int xml_current_element ();
365 #if defined (VA_FPRINTF) && __STDC__
366 xml_insert_element_with_attribute (int elt, int arg, char *format, ...);
368 xml_insert_element_with_attribute ();
375 char *tem = xmalloc (strlen (id) + 1);
380 if (*p == ' ' || *p == '&' || *p == '/' || *p == '+')
394 for (i=0; i<=PARA; i++)
396 if (strcasecmp (name, texinfoml_element_list[i].name) == 0)
399 printf ("Error xml_element\n");
404 xml_begin_document (output_filename)
405 char *output_filename;
413 insert_string ("<!DOCTYPE Book PUBLIC \"-//OASIS//DTD DocBook V3.1//EN\">");
414 xml_element_list = docbook_element_list;
418 insert_string ("<!DOCTYPE texinfo SYSTEM \"texinfo.dtd\">");
419 xml_element_list = texinfoml_element_list;
423 if (language_code != last_language_code)
424 xml_insert_element_with_attribute (TEXINFO, START, "lang=\"%s\"", language_table[language_code].abbrev);
427 xml_insert_element (TEXINFO, START);
430 xml_insert_element (SETFILENAME, START);
431 insert_string (output_filename);
432 xml_insert_element (SETFILENAME, END);
437 static int element_stack[256];
438 static int element_stack_index = 0;
441 xml_push_current_element (elt)
444 element_stack[element_stack_index++] = elt;
445 if (element_stack_index > 200)
446 printf ("*** stack overflow (%d - %s) ***\n",
448 xml_element_list[elt].name);
452 xml_pop_current_element ()
454 element_stack_index--;
455 if (element_stack_index < 0)
456 printf ("*** stack underflow (%d - %d) ***\n",
458 xml_current_element());
462 xml_current_element ()
464 return element_stack[element_stack_index-1];
472 for (i = 0; i < element_stack_index; i++)
477 xml_indent_end_para ()
480 for (i = 0; i < element_stack_index; i++)
489 if (xml_node_level != -1)
491 xml_close_sections (xml_node_level);
494 xml_insert_element (NODE, END);
496 xml_insert_element (TEXINFO, END);
497 insert_string ("\n");
498 insert_string ("<!-- Keep this comment at the end of the file\n\
501 sgml-indent-step:1\n\
502 sgml-indent-data:nil\n\
505 if (element_stack_index != 0)
506 error ("Element stack index : %d\n", element_stack_index);
509 /* MUST be 0 or 1, not true or false values */
510 static int start_element_inserted = 1;
512 /* NOTE: We use `elt' rather than `element' in the argument list of
513 the next function, since otherwise the Solaris SUNWspro compiler
514 barfs because `element' is a typedef declared near the beginning of
517 #if defined (VA_FPRINTF) && __STDC__
518 xml_insert_element_with_attribute (int elt, int arg, char *format, ...)
520 xml_insert_element_with_attribute (elt, arg, format, va_alist)
527 /* Look at the replace_elements table to see if we have to change the element */
532 replace_element *element_list = replace_elements;
533 while (element_list->element_to_replace >= 0)
535 if ( ( (arg == START) &&
536 (element_list->element_containing == xml_current_element ()) &&
537 (element_list->element_to_replace == elt) ) ||
539 (element_list->element_containing == element_stack[element_stack_index-1-start_element_inserted]) &&
540 (element_list->element_to_replace == elt) ) )
542 elt = element_list->element_replacing;
548 /* Forget the element */
552 start_element_inserted = 0;
554 /* Replace the default value, for the next time */
555 start_element_inserted = 1;
563 if (xml_after_table_term && elt != TABLETERM)
565 xml_after_table_term = 0;
566 xml_insert_element (ITEM, START);
569 if (docbook && !only_macro_expansion && (in_menu || in_detailmenu))
572 if (!xml_element_list[elt].name || !strlen (xml_element_list[elt].name))
574 /* printf ("Warning: Inserting empty element %d\n", elt);*/
578 if (arg == START && !xml_in_para && !xml_no_para
579 && xml_element_list[elt].contained_in_para
580 && xml_element_list[xml_current_element()].contains_para )
583 insert_string ("<para>");
588 if (arg == START && xml_in_para && !xml_element_list[elt].contained_in_para)
590 xml_indent_end_para ();
591 insert_string ("</para>");
595 if (arg == END && xml_in_para && !xml_element_list[elt].contained_in_para)
597 xml_indent_end_para ();
598 insert_string ("</para>");
602 if (arg == START && !xml_in_para && !xml_element_list[elt].contained_in_para)
606 xml_push_current_element (elt);
608 xml_pop_current_element ();
613 insert_string (xml_element_list[elt].name);
615 /* printf ("%s ", xml_element_list[elt].name);*/
619 char temp_string[2000]; /* xx no fixed limits */
624 VA_START (ap, format);
626 VA_SPRINTF (temp_string, format, ap);
628 sprintf (temp_string, format, a1, a2, a3, a4, a5, a6, a7, a8);
631 insert_string (temp_string);
635 if (arg == START && xml_node_id && elt != NODENAME)
637 insert_string (" id=\"");
638 insert_string (xml_node_id);
639 insert_string ("\"");
646 xml_just_after_element = 1;
649 /* See the NOTE before xml_insert_element_with_attribute, for why we
650 use `elt' rather than `element' here. */
652 xml_insert_element (int elt, int arg)
654 xml_insert_element_with_attribute (elt, arg, NULL);
658 xml_insert_entity (char *entity_name)
660 int saved_escape_html = escape_html;
664 if (docbook && !only_macro_expansion && (in_menu || in_detailmenu))
667 if (!xml_in_para && !xml_no_para && !only_macro_expansion
668 && xml_element_list[xml_current_element ()].contains_para)
670 insert_string ("<para>");
675 escape_html = saved_escape_html;
676 insert_string (entity_name);
680 typedef struct _xml_section xml_section;
681 struct _xml_section {
687 xml_section *last_section = NULL;
692 if (xml_node_open && ! docbook)
694 if (xml_node_level != -1)
696 xml_close_sections (xml_node_level);
699 xml_insert_element (NODE, END);
701 xml_insert_element (NODE, START);
706 xml_close_sections (level)
709 if (!first_section_opened && in_abstract)
711 xml_insert_element (ABSTRACT, END);
712 xml_insert_element (BOOKINFO, END);
713 first_section_opened = 1;
715 while (last_section && last_section->level >= level)
717 xml_section *temp = last_section;
718 xml_insert_element (xml_element(last_section->name), END);
720 last_section = last_section->prev;
727 xml_open_section (level, name)
731 xml_section *sect = (xml_section *) xmalloc (sizeof (xml_section));
734 sect->name = xmalloc (1 + strlen (name));
735 strcpy (sect->name, name);
736 sect->prev = last_section;
739 if (xml_node_open && xml_node_level == -1)
740 xml_node_level = level;
744 xml_start_menu_entry (tem)
748 discard_until ("* ");
750 /* The line number was already incremented in reader_loop when we
751 saw the newline, and discard_until has now incremented again. */
754 if (xml_in_menu_entry)
756 if (xml_in_menu_entry_comment)
758 xml_insert_element (MENUCOMMENT, END);
759 xml_in_menu_entry_comment=0;
761 xml_insert_element (MENUENTRY, END);
764 xml_insert_element (MENUENTRY, START);
767 xml_insert_element (MENUNODE, START);
768 string = expansion (tem, 0);
770 xml_insert_element (MENUNODE, END);
773 /* The menu item may use macros, so expand them now. */
774 xml_insert_element (MENUTITLE, START);
775 only_macro_expansion++;
776 get_until_in_line (1, ":", &string);
777 only_macro_expansion--;
778 execute_string ("%s", string); /* get escaping done */
779 xml_insert_element (MENUTITLE, END);
782 if (looking_at ("::"))
785 { /* discard the node name */
786 get_until_in_line (0, ".", &string);
789 input_text_offset++; /* discard the second colon or the period */
790 xml_insert_element (MENUCOMMENT, START);
791 xml_in_menu_entry_comment ++;
797 if (xml_in_menu_entry)
799 if (xml_in_menu_entry_comment)
801 xml_insert_element (MENUCOMMENT, END);
802 xml_in_menu_entry_comment --;
804 xml_insert_element (MENUENTRY, END);
807 xml_insert_element (MENU, END);
810 static int xml_last_character;
813 xml_add_char (character)
818 if (docbook && !only_macro_expansion && (in_menu || in_detailmenu))
821 if (!first_section_opened && !in_abstract && xml_current_element () == TEXINFO
822 && !xml_no_para && character != '\r' && character != '\n' && character != ' ')
824 xml_insert_element (BOOKINFO, START);
825 xml_insert_element (ABSTRACT, START);
829 if (xml_after_table_term && !xml_sort_index)
831 xml_after_table_term = 0;
832 xml_insert_element (ITEM, START);
835 if (xml_just_after_element && !xml_in_para && !inhibit_paragraph_indentation)
837 if (character == '\r' || character == '\n' || character == '\t' || character == ' ')
839 xml_just_after_element = 0;
842 if (xml_element_list[xml_current_element()].contains_para
843 && !xml_in_para && !only_macro_expansion && !xml_no_para)
846 insert_string ("<para>\n");
852 if (character == '\n')
854 if (xml_last_character == '\n' && !only_macro_expansion && !xml_no_para
855 && xml_element_list[xml_current_element()].contains_para )
857 xml_indent_end_para ();
858 insert_string ("</para>");
860 xml_just_after_element = 1;
861 if (xml_in_menu_entry_comment)
863 xml_insert_element (MENUCOMMENT, END);
864 xml_in_menu_entry_comment = 0;
865 xml_insert_element (MENUENTRY, END);
866 xml_in_menu_entry = 0;
872 if (character == '\n' && !xml_in_para && !inhibit_paragraph_indentation)
875 xml_last_character = character;
877 if (character == '&' && escape_html)
878 insert_string ("&");
879 else if (character == '<' && escape_html)
880 insert_string ("<");
888 xml_insert_footnote (note)
891 xml_insert_element (FOOTNOTE, START);
892 insert_string ("<para>");
893 execute_string ("%s", note);
894 insert_string ("</para>");
895 xml_insert_element (FOOTNOTE, END);
902 static int xml_in_item[256];
903 static int xml_table_level = 0;
906 xml_begin_table (type, item_function)
907 enum insertion_type type;
915 /*if (docbook)*/ /* 05-08 */
917 xml_insert_element (TABLE, START);
919 xml_in_item[xml_table_level] = 0;
925 xml_insert_element (ITEMIZE, START);
927 xml_in_item[xml_table_level] = 0;
928 xml_insert_element (ITEMFUNCTION, START);
929 if (*item_function == COMMAND_PREFIX
930 && item_function[strlen (item_function) - 1] != '}'
931 && command_needs_braces (item_function + 1))
932 execute_string ("%s{}", item_function);
934 execute_string ("%s", item_function);
935 xml_insert_element (ITEMFUNCTION, END);
939 xml_insert_element_with_attribute (ITEMIZE, START,
941 (*item_function == COMMAND_PREFIX) ?
942 &item_function[1] : item_function);
944 xml_in_item[xml_table_level] = 0;
952 enum insertion_type type;
959 /* if (docbook)*/ /* 05-08 */
961 if (xml_in_item[xml_table_level])
963 xml_insert_element (ITEM, END);
964 xml_insert_element (TABLEITEM, END);
965 xml_in_item[xml_table_level] = 0;
967 xml_insert_element (TABLE, END);
972 if (xml_in_item[xml_table_level])
974 xml_insert_element (ITEM, END);
975 xml_in_item[xml_table_level] = 0;
977 xml_insert_element (ITEMIZE, END);
986 if (xml_in_item[xml_table_level])
987 xml_insert_element (ITEM, END);
989 xml_insert_element (ITEM, START);
990 xml_in_item[xml_table_level] = 1;
994 xml_begin_table_item ()
996 if (!xml_after_table_term)
998 if (xml_in_item[xml_table_level])
1000 xml_insert_element (ITEM, END);
1001 xml_insert_element (TABLEITEM, END);
1003 xml_insert_element (TABLEITEM, START);
1005 xml_insert_element (TABLETERM, START);
1006 xml_in_item[xml_table_level] = 1;
1007 xml_after_table_term = 0;
1011 xml_continue_table_item ()
1013 xml_insert_element (TABLETERM, END);
1014 xml_after_table_term = 1;
1018 xml_begin_enumerate (enum_arg)
1022 xml_insert_element_with_attribute (ENUMERATE, START, "first=\"%s\"", enum_arg);
1025 if (isdigit (*enum_arg))
1027 if (enum_arg[0] == '1')
1028 xml_insert_element_with_attribute (ENUMERATE, START,
1029 "numeration=\"Arabic\"", NULL);
1031 xml_insert_element_with_attribute (ENUMERATE, START,
1032 "continuation=\"Continues\" numeration=\"Arabic\"", NULL);
1034 else if (isupper (*enum_arg))
1036 if (enum_arg[0] == 'A')
1037 xml_insert_element_with_attribute (ENUMERATE, START,
1038 "numeration=\"Upperalpha\"", NULL);
1040 xml_insert_element_with_attribute (ENUMERATE, START,
1041 "continuation=\"Continues\" numeration=\"Upperalpha\"", NULL);
1045 if (enum_arg[0] == 'a')
1046 xml_insert_element_with_attribute (ENUMERATE, START,
1047 "numeration=\"Loweralpha\"", NULL);
1049 xml_insert_element_with_attribute (ENUMERATE, START,
1050 "continuation=\"Continues\" numeration=\"Loweralpha\"", NULL);
1054 xml_in_item[xml_table_level] = 0;
1058 xml_end_enumerate ()
1060 if (xml_in_item[xml_table_level])
1062 xml_insert_element (ITEM, END);
1063 xml_in_item[xml_table_level] = 0;
1065 xml_insert_element (ENUMERATE, END);
1070 xml_insert_text_file (name_arg)
1073 char *fullname = xmalloc (strlen (name_arg) + 4 + 1);
1075 strcpy (fullname, name_arg);
1076 strcat (fullname, ".txt");
1077 image_file = fopen (fullname, "r");
1081 int save_inhibit_indentation = inhibit_paragraph_indentation;
1082 int save_filling_enabled = filling_enabled;
1084 xml_insert_element (TEXTOBJECT, START);
1085 xml_insert_element (DISPLAY, START);
1087 inhibit_paragraph_indentation = 1;
1088 filling_enabled = 0;
1089 last_char_was_newline = 0;
1091 /* Maybe we need to remove the final newline if the image
1092 file is only one line to allow in-line images. On the
1093 other hand, they could just make the file without a
1095 while ((ch = getc (image_file)) != EOF)
1098 inhibit_paragraph_indentation = save_inhibit_indentation;
1099 filling_enabled = save_filling_enabled;
1101 xml_insert_element (DISPLAY, END);
1102 xml_insert_element (TEXTOBJECT, END);
1104 if (fclose (image_file) != 0)
1108 warning (_("@image file `%s' unreadable: %s"), fullname,
1115 xml_insert_docbook_image (name_arg)
1118 xml_insert_element (INFORMALFIGURE, START);
1119 xml_insert_element (MEDIAOBJECT, START);
1121 xml_insert_element (IMAGEOBJECT, START);
1122 xml_insert_element_with_attribute (IMAGEDATA, START, "fileref=\"%s.eps\" format=\"eps\"", name_arg);
1123 xml_pop_current_element ();
1124 xml_insert_element (IMAGEOBJECT, END);
1126 xml_insert_element (IMAGEOBJECT, START);
1127 xml_insert_element_with_attribute (IMAGEDATA, START, "fileref=\"%s.jpg\" format=\"jpg\"", name_arg);
1128 xml_pop_current_element ();
1129 xml_insert_element (IMAGEOBJECT, END);
1131 xml_insert_text_file (name_arg);
1133 xml_insert_element (MEDIAOBJECT, END);
1134 xml_insert_element (INFORMALFIGURE, END);
1146 /* Used to separate primary and secondary entries in an index */
1147 #define INDEX_SEP ", "
1149 xml_insert_indexterm (indexterm, index)
1155 xml_insert_element_with_attribute (INDEXTERM, START, "index=\"%s\"", index);
1156 execute_string ("%s", indexterm);
1157 xml_insert_element (INDEXTERM, END);
1162 char *primary = NULL, *secondary;
1165 expanded = expansion (indexterm);
1168 if (strstr (expanded+1, INDEX_SEP))
1170 primary = xmalloc (strlen (expanded) + 1);
1171 strcpy (primary, expanded);
1172 secondary = strstr (primary+1, INDEX_SEP);
1174 secondary += strlen (INDEX_SEP);
1176 xml_insert_element_with_attribute (INDEXTERM, START, "role=\"%s\"", index);
1177 xml_insert_element (PRIMARY, START);
1179 insert_string (primary);
1181 insert_string (expanded);
1182 xml_insert_element (PRIMARY, END);
1185 xml_insert_element (SECONDARY, START);
1186 insert_string (secondary);
1187 xml_insert_element (SECONDARY, END);
1189 xml_insert_element (INDEXTERM, END);
1195 int xml_last_section_output_position = 0;
1196 static char last_division_letter = ' ';
1197 static char index_primary[2000]; /** xx no fixed limit */
1198 static int indexdivempty = 0;
1200 static int in_indexentry = 0;
1201 static int in_secondary = 0;
1203 xml_close_indexentry ()
1208 xml_insert_element (SECONDARYIE, END);
1209 xml_insert_element (INDEXENTRY, END);
1218 We assume that we just opened a section, and so that the last output is
1219 <SECTION ID="node-name"><TITLE>Title</TITLE>
1220 where SECTION can be CHAPTER, ...
1223 xml_section *temp = last_section;
1225 int l = output_paragraph_offset-xml_last_section_output_position;
1226 char *tmp = xmalloc (l+1);
1228 strncpy (tmp, output_paragraph, l);
1230 /* We remove <SECTION */
1237 output_paragraph_offset = xml_last_section_output_position;
1238 xml_last_section_output_position = 0;
1240 xml_pop_current_element (); /* remove section element from elements stack */
1242 last_section = last_section->prev; /* remove section from sections stack */
1246 /* We put <INDEX> */
1247 xml_insert_element (PRINTINDEX, START);
1248 /* Remove the final > */
1249 output_paragraph_offset--;
1251 /* and put ID="node-name"><TITLE>Title</TITLE> */
1254 if (xml_index_divisions)
1256 xml_insert_element (INDEXDIV, START);
1264 xml_close_indexentry ();
1265 if (xml_index_divisions)
1266 xml_insert_element (INDEXDIV, END);
1267 xml_insert_element (PRINTINDEX, END);
1271 xml_index_divide (entry)
1275 if (strlen (entry) > (strlen (xml_element_list[CODE].name) + 2) &&
1276 strncmp (entry+1, xml_element_list[CODE].name, strlen (xml_element_list[CODE].name)) == 0)
1277 c = entry[strlen (xml_element_list[CODE].name)+2];
1280 if (tolower (c) != last_division_letter && isalpha (c))
1282 last_division_letter = tolower (c);
1283 xml_close_indexentry ();
1286 xml_insert_element (INDEXDIV, END);
1287 xml_insert_element (INDEXDIV, START);
1289 xml_insert_element (TITLE, START);
1290 insert (toupper (c));
1291 xml_insert_element (TITLE, END);
1296 xml_insert_indexentry (entry, node)
1300 char *primary = NULL, *secondary;
1301 if (xml_index_divisions)
1302 xml_index_divide (entry);
1305 if (strstr (entry+1, INDEX_SEP))
1307 primary = xmalloc (strlen (entry) + 1);
1308 strcpy (primary, entry);
1309 secondary = strstr (primary+1, INDEX_SEP);
1311 secondary += strlen (INDEX_SEP);
1313 if (in_secondary && strcmp (primary, index_primary) == 0)
1315 xml_insert_element (SECONDARYIE, END);
1316 xml_insert_element (SECONDARYIE, START);
1317 insert_string (secondary);
1321 xml_close_indexentry ();
1322 xml_insert_element (INDEXENTRY, START);
1324 xml_insert_element (PRIMARYIE, START);
1325 insert_string (primary);
1326 xml_insert_element (PRIMARYIE, END);
1327 xml_insert_element (SECONDARYIE, START);
1328 insert_string (secondary);
1334 xml_close_indexentry ();
1335 xml_insert_element (INDEXENTRY, START);
1337 xml_insert_element (PRIMARYIE, START);
1338 insert_string (entry);
1340 add_word_args (", %s", _("see "));
1341 xml_insert_element_with_attribute (XREF, START, "linkend=\"%s\"", xml_id (node));
1342 xml_pop_current_element ();
1346 strcpy (index_primary, primary);
1347 /* xml_insert_element (SECONDARYIE, END);*/
1348 /* *(secondary-1) = ',';*/ /* necessary ? */
1352 xml_insert_element (PRIMARYIE, END);
1354 /* xml_insert_element (INDEXENTRY, END); */
1361 xml_begin_multitable (ncolumns, column_widths)
1368 xml_insert_element (MULTITABLE, START);
1369 xml_insert_element_with_attribute (TGROUP, START, "cols=\"%d\"", ncolumns);
1370 for (i=0; i<ncolumns; i++)
1372 xml_insert_element_with_attribute (COLSPEC, START, "colwidth=\"%d*\"", column_widths[i]);
1373 xml_pop_current_element ();
1375 xml_insert_element (TBODY, START);
1380 xml_insert_element (MULTITABLE, START);
1381 for (i=0; i<ncolumns; i++)
1383 xml_insert_element (COLSPEC, START);
1384 add_word_args ("%d", column_widths[i]);
1385 xml_insert_element (COLSPEC, END);
1392 xml_end_multitable_row (first_row)
1397 xml_insert_element (ENTRY, END);
1398 xml_insert_element (ROW, END);
1400 xml_insert_element (ROW, START);
1401 xml_insert_element (ENTRY, START);
1405 xml_end_multitable_column ()
1407 xml_insert_element (ENTRY, END);
1408 xml_insert_element (ENTRY, START);
1412 xml_end_multitable ()
1416 xml_insert_element (ENTRY, END);
1417 xml_insert_element (ROW, END);
1418 xml_insert_element (TBODY, END);
1419 xml_insert_element (TGROUP, END);
1420 xml_insert_element (MULTITABLE, END);
1425 xml_insert_element (ENTRY, END);
1426 xml_insert_element (ROW, END);
1427 xml_insert_element (MULTITABLE, END);