Added options to make Robodoc more customizable.
[robodoc.git] / Source / test_generator.c
1 /*
2 Copyright (C) 1994-2007  Frans Slothouber, Jacco van Weert, Petteri Kettunen,
3 Bernd Koesling, Thomas Aglassinger, Anthon Pang, Stefan Kost, David Druffner,
4 Sasha Vasko, Kai Hofmann, Thierry Pierron, Friedrich Haase, and Gergely Budai.
5
6 This file is part of ROBODoc
7
8 ROBODoc is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
21 */
22
23
24 /****h* ROBODoc/Test_Generator
25  * FUNCTION
26  *   The generator for test output.
27  *
28  *   The purpose of this generator is to create output that is easily
29  *   scanable by the system test scripts.  This to make it easier to
30  *   write tests for ROBODoc.
31  *
32  *   This generator produces output in utf-8 encoding.
33  *
34  *   This generator is experimental.
35  *
36  *******
37  * $Id: test_generator.c,v 1.10 2007/07/10 19:13:52 gumpu Exp $
38  */
39
40
41 #include <stdio.h>
42 #include <string.h>
43 #include <assert.h>
44 #include <ctype.h>
45 #include "test_generator.h"
46 #include "globals.h"
47 #include "util.h"
48
49
50
51 char               *RB_TEST_Get_Default_Extension(
52     void )
53 {
54     return ".xml";
55 }
56
57 void RB_TEST_Generate_String(
58     FILE *dest_doc,
59     char *a_string )
60 {
61     int                 i;
62     int                 l = strlen( a_string );
63     unsigned char       c;
64
65     for ( i = 0; i < l; ++i )
66     {
67         c = a_string[i];
68         RB_TEST_Generate_Char( dest_doc, c );
69     }
70 }
71
72 /* TODO Documentation */
73
74 void RB_TEST_Generate_Label(
75     FILE *dest_doc,
76     char *name )
77 {
78     int                 i;
79     int                 l = strlen( name );
80     unsigned char       c;
81
82     fprintf( dest_doc, "<label>" );
83     for ( i = 0; i < l; ++i )
84     {
85         c = name[i];
86         if ( utf8_isalnum( c ) )
87         {
88             RB_TEST_Generate_Char( dest_doc, c );
89         }
90         else
91         {
92             char                buf[4];
93
94             sprintf( buf, "%02x", c );
95             RB_TEST_Generate_Char( dest_doc, buf[0] );
96             RB_TEST_Generate_Char( dest_doc, buf[1] );
97         }
98     }
99     fprintf( dest_doc, "</label>" );
100 }
101
102
103 /****f* Generator/RB_TEST_Generate_Char
104  * NAME
105  *   RB_TEST_Generate_Char
106  * SYNOPSIS
107  *   void RB_TEST_Generate_Char( FILE * dest_doc, int c )
108  * FUNCTION
109  *   Switchboard to RB_TEST_Generate_Char
110  * SOURCE
111  */
112
113 void RB_TEST_Generate_Char(
114     FILE *dest_doc,
115     int c )
116 {
117     switch ( c )
118     {
119     default:
120         RB_FputcLatin1ToUtf8( dest_doc, c );
121         break;
122     }
123 }
124
125 /*****/
126
127 void RB_TEST_Generate_Header_Start(
128     FILE *dest_doc,
129     struct RB_header *cur_header )
130 {
131     fprintf( dest_doc, "<header name=\"" );
132     RB_TEST_Generate_String( dest_doc, cur_header->name );
133     fprintf( dest_doc, "\" header_module=\"" );
134     RB_TEST_Generate_String( dest_doc, cur_header->module_name );
135     fprintf( dest_doc, "\"" );
136     fprintf( dest_doc, " header_function_name=\"" );
137     RB_TEST_Generate_String( dest_doc, cur_header->function_name );
138     fprintf( dest_doc, "\" >\n" );
139 }
140
141 void RB_TEST_Generate_Header_End(
142     FILE *dest_doc,
143     struct RB_header *cur_header )
144 {
145     USE( cur_header );
146
147     fprintf( dest_doc, "</header>\n" );
148 }
149
150 void RB_TEST_Generate_Link(
151     FILE *dest,
152     char *dest_name,
153     char *filename,
154     char *labelname,
155     char *linkname
156      )
157 {
158     /* TODO print the other stuff too! */
159     USE( dest_name );
160     USE( filename );
161
162     fprintf( dest, "<link labelname=\"%s\" linkname=\"", labelname );
163     RB_TEST_Generate_String( dest, linkname );
164     fprintf( dest, "\" />\n" );
165 }
166
167 void RB_TEST_Generate_Doc_Start(
168     FILE *dest_doc,
169     char *src_name,
170     char *name,
171     char toc )
172 {
173     USE( toc );
174
175     if ( course_of_action.do_headless )
176     {
177         /* The user does not want the document head. */
178     }
179     else
180     {
181         fprintf( dest_doc, "<doc_start src_name=\"%s\" name=\"%s\">\n",
182                  src_name, name );
183     }
184 }
185
186
187 void RB_TEST_Generate_Doc_End(
188     FILE *dest_doc,
189     char *name )
190 {
191     USE( name );
192
193     if ( course_of_action.do_footless )
194     {
195         /* The user does not want the foot of the
196          * document.
197          */
198     }
199     else
200     {
201         fprintf( dest_doc, "%s", "</doc_start>\n" );
202     }
203 }
204
205
206 void RB_TEST_Generate_Item_Name(
207     FILE *dest_doc,
208     char *name )
209 {
210     fprintf( dest_doc, "<item id=\"" );
211     RB_TEST_Generate_String( dest_doc, name );
212     fprintf( dest_doc, "\">\n" );
213 }
214
215 void RB_TEST_Generate_Item_Begin(
216     FILE *dest_doc )
217 {
218     fprintf( dest_doc, "<item_body>\n" );
219 }
220
221
222 void RB_TEST_Generate_Item_End(
223     FILE *dest_doc )
224 {
225     fprintf( dest_doc, "</item_body>\n</item>\n" );
226 }
227
228
229 void RB_TEST_Generate_BeginSection(
230     FILE *dest_doc,
231     int depth,
232     char *name )
233 {
234     fprintf( dest_doc, "<section depth=\"%d\">", depth );
235     RB_TEST_Generate_String( dest_doc, name );
236     fprintf( dest_doc, "\n" );
237 }
238
239 void RB_TEST_Generate_EndSection(
240     FILE *dest_doc,
241     int depth,
242     char *name )
243 {
244     USE( depth );
245
246     fprintf( dest_doc, "</section>" );
247     RB_TEST_Generate_String( dest_doc, name );
248     fprintf( dest_doc, "\n" );
249 }
250
251
252 void RB_TEST_Generate_False_Link(
253     FILE *dest_doc,
254     char *name )
255 {
256     fprintf( dest_doc, "<false_link>" );
257     RB_TEST_Generate_String( dest_doc, name );
258     fprintf( dest_doc, "</false_link>" );
259 }
260
261
262
263 void TEST_Generate_Begin_Paragraph(
264     FILE *dest_doc )
265 {
266     fprintf( dest_doc, "<para>\n" );
267 }
268
269 void TEST_Generate_End_Paragraph(
270     FILE *dest_doc )
271 {
272     fprintf( dest_doc, "</para>\n" );
273 }
274
275
276 void TEST_Generate_Begin_Preformatted(
277     FILE *dest_doc )
278 {
279     fprintf( dest_doc, "<pre>\n" );
280 }
281
282 void TEST_Generate_End_Preformatted(
283     FILE *dest_doc )
284 {
285     fprintf( dest_doc, "</pre>\n" );
286 }
287
288
289 void TEST_Generate_Begin_List(
290     FILE *dest_doc )
291 {
292     fprintf( dest_doc, "<list>\n" );
293 }
294
295 void TEST_Generate_End_List(
296     FILE *dest_doc )
297 {
298     fprintf( dest_doc, "</list>\n" );
299 }
300
301 void TEST_Generate_Begin_List_Item(
302     FILE *dest_doc )
303 {
304     fprintf( dest_doc, "<list_item>\n" );
305 }
306
307 void TEST_Generate_End_List_Item(
308     FILE *dest_doc )
309 {
310     fprintf( dest_doc, "</list_item>\n" );
311 }