1 /* docbook.c -- docbook output.
2 $Id: docbook.c,v 1.3 2001/12/31 16:52:17 karl Exp $
4 Copyright (C) 2001 Free Software Foundation, Inc.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software Foundation,
18 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 #include "insertion.h"
27 #include "sectioning.h"
29 int docbook_version_inserted = 0;
30 int docbook_first_chapter_found = 0;
31 int docbook_must_insert_node_anchor = 0;
32 int docbook_begin_book_p = 0;
33 int docbook_no_new_paragraph = 0;
35 static int section_level = -1;
36 static int in_docbook_paragraph = 0;
37 static int in_list = 0;
39 static int in_table = 0;
40 static int in_term = 0;
41 static int in_entry = 0;
42 static int in_varlistitem = 0;
44 static int in_example = 0;
47 docbook_begin_section (level, cmd)
53 static char *last_chap = NULL;
56 docbook_first_chapter_found = 1;
57 filling_enabled = indented_fill = 0;
58 old_no_indent = no_indent;
61 if (!docbook_begin_book_p)
62 docbook_begin_book ();
64 if (macro_expansion_output_stream && !executing_string)
65 append_to_expansion_output (input_text_offset + 1);
67 get_rest_of_line (0, &temp);
69 if (in_docbook_paragraph)
71 insert_string ("\n</para>\n\n");
72 adjust_braces_following (0, 10);
74 in_docbook_paragraph = 0;
75 docbook_no_new_paragraph++;
77 if (level > section_level + 1)
78 level = section_level + 1;
80 for (i = section_level; i >= level ; i--)
84 if (last_chap && strcmp(last_chap, "appendix") == 0)
85 add_word ("</appendix>\n\n");
87 add_word ("</chapter>\n\n");
90 add_word_args ("</sect%d>\n\n", i);
93 section_level = level;
97 if (strcmp(cmd, "appendix") == 0)
98 add_word ("<appendix");
100 add_word ("<chapter");
104 add_word_args ("<sect%d", level);
106 if (docbook_must_insert_node_anchor)
109 tem = expansion (current_node, 0);
110 add_escaped_anchor_name (tem, 0);
113 docbook_must_insert_node_anchor = 0;
116 add_word ("<title>");
118 if (macro_expansion_output_stream && !executing_string)
120 char *temp1 = xmalloc (2 + strlen (temp));
121 sprintf (temp1, "%s", temp);
122 remember_itext (input_text, input_text_offset);
123 me_execute_string (temp1);
127 execute_string ("%s", temp);
131 add_word ("</title>\n");
135 no_indent = old_no_indent;
136 docbook_no_new_paragraph--;
137 insert_string("\n<para>");
138 in_docbook_paragraph = 1;
142 docbook_begin_paragraph ()
144 if (!docbook_first_chapter_found)
150 if (in_table && !in_term)
153 insert_string ("\n<listitem><para>\n");
155 insert_string ("\n</para>\n\n<para>\n");
162 if (in_docbook_paragraph)
164 insert_string ("\n</para>\n\n");
165 adjust_braces_following (0, 10);
169 if (docbook_must_insert_node_anchor)
172 insert_string ("<para id=\"");
173 adjust_braces_following (0, 10);
174 tem = expansion (current_node, 0);
175 add_escaped_anchor_name (tem, 0);
178 docbook_must_insert_node_anchor = 0;
183 insert_string ("<para>\n");
184 adjust_braces_following (0, 7);
186 in_docbook_paragraph = 1;
190 docbook_begin_book ()
192 if (!docbook_begin_book_p)
193 docbook_begin_book_p = 1;
197 ++docbook_no_new_paragraph;
198 add_word_args ("<!DOCTYPE book PUBLIC \"-//Davenport//DTD DocBook V3.0//EN\">\n\
199 <book>\n<title>%s</title>\n", title);
200 --docbook_no_new_paragraph;
207 if (in_docbook_paragraph)
209 insert_string ("\n</para>\n\n");
212 for (i = section_level; i >= 0 ; i--)
215 add_word ("</chapter>\n");
217 add_word_args ("</sect%d>\n", i);
220 add_word ("</book>\n");
224 docbook_insert_tag (start_or_end, tag)
228 if (!paragraph_is_open && start_or_end == START)
229 docbook_begin_paragraph ();
232 if (start_or_end == START)
237 for (; *tag && *tag != ' '; tag++)
244 docbook_xref1 (node_name)
248 add_word ("<xref linkend=\"");
249 tem = expansion (node_name, 0);
250 add_escaped_anchor_name (tem, 1);
256 docbook_xref2 (node_name, ref_name)
261 add_word ("<xref linkend=\"");
262 tem = expansion (node_name, 0);
263 add_escaped_anchor_name (tem, 1);
269 docbook_quote (character)
272 switch (language_code)
275 if (character == '`')
288 if (character == '`')
302 #define IS_BLANK(c) (c == ' ' || c == '\t' || c == '\n')
305 docbook_is_punctuation (character, next)
309 return ( (character == ';'
317 docbook_punctuation (character)
320 switch (language_code)
323 while (output_paragraph[output_paragraph_offset-1] == ' ')
324 output_paragraph_offset--;
330 static int in_item = 0;
333 docbook_begin_itemize ()
335 if (in_docbook_paragraph)
336 insert_string ("\n</para>\n");
338 in_docbook_paragraph = 0;
339 insert_string ("\n<itemizedlist>\n");
345 docbook_end_itemize ()
349 insert_string ("\n</para></listitem>\n");
352 insert_string ("\n</itemizedlist>\n\n<para>\n");
353 in_docbook_paragraph = 1;
358 docbook_begin_enumerate ()
360 if (in_docbook_paragraph)
361 insert_string ("\n</para>\n");
362 in_docbook_paragraph = 0;
363 insert_string ("\n<orderedlist>\n");
369 docbook_end_enumerate ()
373 insert_string ("\n</para></listitem>\n");
376 insert_string ("\n</orderedlist>\n\n<para>\n");
377 in_docbook_paragraph = 1;
382 docbook_begin_table ()
385 if (in_docbook_paragraph)
386 insert_string ("\n</para>\n\n");
387 in_docbook_paragraph = 0;
390 add_word ("\n<variablelist>\n");
400 docbook_begin_paragraph ();
401 insert_string ("\n</para></listitem>\n</varlistentry>\n\n</variablelist>\n");
405 insert_string ("\n</para>\n\n");
406 in_docbook_paragraph = 0;
410 insert_string ("\n<para>\n\n");
411 in_docbook_paragraph = 1;
422 insert_string ("\n</para></listitem>\n");
423 insert_string ("\n<listitem><para>\n");
424 in_docbook_paragraph = 1;
429 docbook_add_table_item ()
433 insert_string ("\n</para></listitem>\n</varlistentry>\n\n");
439 insert_string ("<varlistentry>\n");
442 insert_string ("<term>");
448 docbook_close_table_item ()
450 insert_string ("</term>");
456 docbook_add_anchor (anchor)
459 add_word ("<anchor id=\"");
460 add_anchor_name (anchor, 0);
465 docbook_footnote (note)
468 /* add_word_args ("<footnote><para>\n%s\n</para></footnote>\n", note); */
469 add_word ("<footnote><para>\n");
470 execute_string("%s", note);
471 add_word("\n</para></footnote>\n");
475 docbook_begin_index ()
477 add_word ("<variablelist>\n");
481 docbook_begin_example ()
483 add_word ("\n\n<screen>\n");
488 docbook_end_example ()
491 add_word ("</screen>\n\n");