]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wxSWIG/SWIG/latex.cxx
reSWIGged
[wxWidgets.git] / wxPython / wxSWIG / SWIG / latex.cxx
1 /*******************************************************************************
2 * Simplified Wrapper and Interface Generator (SWIG)
3 *
4 * Author : David Beazley
5 *
6 * Department of Computer Science
7 * University of Chicago
8 * 1100 E 58th Street
9 * Chicago, IL 60637
10 * beazley@cs.uchicago.edu
11 *
12 * Please read the file LICENSE for the copyright and terms by which SWIG
13 * can be used and distributed.
14 *******************************************************************************/
15
16 /***********************************************************************
17 * $Header$
18 *
19 * latex.c
20 *
21 * Latex specific functions for producing documentation.
22 *
23 ***********************************************************************/
24
25 #include "swig.h"
26 #include "latex.h"
27
28 // -------------------------------------------------------------------
29 // LATEX::LATEX()
30 //
31 // Create new LaTeX handler
32 // -------------------------------------------------------------------
33
34 LATEX::LATEX() {
35 sect_count = 0;
36
37 tag_pagestyle = "\\pagestyle{headings}";
38 tag_parindent = "0.0in";
39 tag_textwidth = "6.5in";
40 tag_documentstyle = "[11pt]{article}";
41 tag_oddsidemargin = "0.0in";
42 tag_title = "{\\Large \\bf : }";
43 tag_preformat = "{\\small \\begin{verbatim}:\\end{verbatim}}";
44 tag_usage = "{\\tt \\bf : }";
45 tag_descrip = "\\\\\n\\makebox[0.5in]{}\\begin{minipage}[t]{6in}:\n\\end{minipage}\\\\\n";
46 tag_text = ":\\\\";
47 tag_cinfo = "{\\tt : }\\\\";
48 tag_section = "\\section{:}";
49 tag_subsection="\\subsection{:}";
50 tag_subsubsection="\\subsubsection{:}";
51 }
52
53 // -------------------------------------------------------------------
54 // char *start_tag(char *tag) {
55 //
56 // Returns the start of a tag
57 // -------------------------------------------------------------------
58
59 char *LATEX::start_tag(char *tag) {
60 static String stag;
61 char *c;
62
63 stag = "";
64 c = tag;
65 while ((*c) && (*c != ':')) {
66 stag << *c;
67 c++;
68 }
69 return stag.get();
70 }
71
72 // -------------------------------------------------------------------
73 // char *end_tag(char *tag) {
74 //
75 // Returns the end of a tag
76 // -------------------------------------------------------------------
77
78 char *LATEX::end_tag(char *tag) {
79 static String etag;
80 char *c;
81
82 etag = "";
83 c = tag;
84 while ((*c) && (*c != ':')) {
85 c++;
86 }
87 if (*c) {
88 c++;
89 while (*c) {
90 etag << *c;
91 c++;
92 }
93 }
94 return etag.get();
95 }
96
97 // -------------------------------------------------------------------
98 // LATEX::print_string(char *s, String &str)
99 //
100 // Dumps string s to str, but performs some LaTeX character replacements
101 // -------------------------------------------------------------------
102
103 void LATEX::print_string(char *s, String &str) {
104
105 char *c;
106 c = s;
107 while (*c) {
108 switch(*c) {
109 case '*':
110 case '<':
111 case '>':
112 case '+':
113 case '=':
114 case '|':
115 str << "$" << *c << "$";
116 break;
117 case '\\':
118 str << "\\\\";
119 break;
120 case '_':
121 str << "\\_";
122 break;
123 case '%':
124 str << "\\%";
125 break;
126 case '$':
127 str << "\\$";
128 break;
129 case '&':
130 str << "\\&";
131 break;
132 case '#':
133 str << "\\#";
134 break;
135 case '\n':
136 str << "\\\\\n";
137 break;
138 default :
139 str << *c;
140 break;
141 }
142 c++;
143 }
144 }
145
146 // --------------------------------------------------------------
147 // LATEX::print_decl(DocEntry *)
148 //
149 // Print a documentation entry
150 // --------------------------------------------------------------
151
152 void LATEX::print_decl(DocEntry *de) {
153
154 char *c;
155
156 c = de->usage.get();
157
158 if (c) {
159 s_doc << start_tag(tag_usage);
160 print_string(c,s_doc);
161 s_doc << end_tag(tag_usage) << "\n";
162 }
163
164 // Check to see if there any information available
165
166 if ((strlen(de->cinfo.get()) && de->print_info) || strlen(de->text.get())) {
167
168 // There is additional information now. If we're in preformatting mode,
169 // we need to handle things differently
170
171 s_doc << start_tag(tag_descrip) << "\n";
172
173 if (!de->format) {
174 // Verbatim mode
175 s_doc << start_tag(tag_preformat) << "\n";
176
177 // If there is any C annotation, print that
178 if (de->print_info) {
179 c = de->cinfo.get();
180 if (strlen(c) > 0) {
181 s_doc << "[ " << c << " ]\n";
182 }
183 }
184 c = de->text.get();
185 if (strlen(c) > 0) {
186 s_doc << c;
187 }
188 s_doc << end_tag(tag_preformat) << "\n";
189 } else {
190 // We are in format mode now
191 // We need to emit some stubs for the description format
192
193 // If there is any C annotation, print that
194 if (de->print_info) {
195 c = de->cinfo.get();
196 if (strlen(c) > 0) {
197 s_doc << start_tag(tag_cinfo) << "[ ";
198 print_string(c,s_doc);
199 s_doc << " ] " << end_tag(tag_cinfo) << "\n";
200 }
201 }
202 // Print out descriptive text (if any).
203 c = de->text.get();
204 if (strlen(c) > 0) {
205 s_doc << c << "\\\\\n";
206 }
207 }
208 s_doc << end_tag(tag_descrip) << "\n";
209 } else {
210 s_doc << "\\\\\n"; // No description available, move to next line
211 }
212 }
213
214 // --------------------------------------------------------------
215 // LATEX::print_text(DocEntry *de)
216 //
217 // Print out some text. We use verbatim mode because of formatting
218 // problems.
219 // --------------------------------------------------------------
220
221 void LATEX::print_text(DocEntry *de) {
222 char *c;
223 c = de->text.get();
224 if (strlen(c) > 0) {
225 if (de->format) {
226 s_doc << start_tag(tag_text) << "\n";
227 s_doc << c;
228 s_doc << end_tag(tag_text) << "\n\n";
229 } else {
230 s_doc << start_tag(tag_preformat) << "\n";
231 s_doc << c;
232 s_doc << end_tag(tag_preformat) << "\n\n";
233 }
234 }
235 }
236
237 void LATEX::title(DocEntry *de) {
238 char *c;
239
240 c = de->usage.get();
241 if (strlen(c) > 0) {
242 s_doc << start_tag(tag_title) << " ";
243 print_string(c,s_doc);
244 s_doc << end_tag(tag_title) << "\\\\\n";
245 }
246
247 // Print out any C annotation and descriptive text
248 // Check to see if there any information available
249
250 if ((strlen(de->cinfo.get()) && de->print_info) || strlen(de->text.get())) {
251
252 // There is additional information now. If we're in preformatting mode,
253 // we need to handle things differently
254
255 if (!de->format) {
256 // Verbatim mode
257 s_doc << start_tag(tag_preformat) << "\n";
258
259 // If there is any C annotation, print that
260 if (de->print_info) {
261 c = de->cinfo.get();
262 if (strlen(c) > 0) {
263 s_doc << "[ " << c << " ]\n";
264 }
265 }
266
267 c = de->text.get();
268 if (strlen(c) > 0) {
269 s_doc << c;
270 }
271 s_doc << end_tag(tag_preformat) << "\n\n";
272 } else {
273 // We are in format mode now
274 // We need to emit some stubs for the description format
275 s_doc << start_tag(tag_text);
276
277 // If there is any C annotation, print that
278 if (de->print_info) {
279 c = de->cinfo.get();
280 if (strlen(c) > 0) {
281 s_doc << start_tag(tag_cinfo) << "[ ";
282 print_string(c,s_doc);
283 s_doc << " ] " << end_tag(tag_cinfo) << "\n";
284 }
285 }
286 // Print out descriptive text (if any).
287 c = de->text.get();
288 if (strlen(c) > 0) {
289 s_doc << c;
290 }
291 s_doc << end_tag(tag_text);
292 }
293 }
294 }
295
296 void LATEX::newsection(DocEntry *de,int sectnum) {
297 char *c;
298 char *tag;
299
300 sect_num[sect_count] = sectnum;
301 sect_count++;
302 switch (sect_count) {
303 case 1: /* Section */
304 tag = tag_section;
305 break;
306 case 2: /* Subsection */
307 tag = tag_subsection;
308 break;
309 default: /* subsubsection */
310 tag = tag_subsubsection;
311 break;
312 }
313
314 s_doc << start_tag(tag);
315 c = de->usage.get();
316 print_string(c,s_doc);
317 s_doc << end_tag(tag);
318
319
320 // Print out any C annotation and descriptive text
321 // Check to see if there any information available
322
323 if ((strlen(de->cinfo.get()) && de->print_info) || strlen(de->text.get())) {
324
325 // There is additional information now. If we're in preformatting mode,
326 // we need to handle things differently
327
328 if (!de->format) {
329 // Verbatim mode
330 s_doc << start_tag(tag_preformat) << "\n";
331
332 // If there is any C annotation, print that
333 if (de->print_info) {
334 c = de->cinfo.get();
335 if (strlen(c) > 0) {
336 s_doc << "[ " << c << " ]\n";
337 }
338 }
339
340 c = de->text.get();
341 if (strlen(c) > 0) {
342 s_doc << c;
343 }
344 s_doc << end_tag(tag_preformat) << "\n\n";
345 } else {
346 // We are in format mode now
347 // We need to emit some stubs for the description format
348
349 s_doc << start_tag(tag_text);
350 // If there is any C annotation, print that
351 if (de->print_info) {
352 c = de->cinfo.get();
353 if (strlen(c) > 0) {
354 s_doc << start_tag(tag_cinfo) << "[ ";
355 print_string(c,s_doc);
356 s_doc << " ] " << end_tag(tag_cinfo) << "\n";
357 }
358 }
359 // Print out descriptive text (if any).
360 c = de->text.get();
361 if (strlen(c) > 0) {
362 s_doc << c;
363 }
364 s_doc << end_tag(tag_text);
365 }
366 }
367 }
368
369
370 void LATEX::endsection() {
371 if (sect_count > 0) sect_count--;
372 }
373
374 void LATEX::separator() {
375 }
376
377 void LATEX::init(char *filename) {
378 char f[256];
379
380 sprintf(f,"%s.tex",filename);
381 sprintf(fn,"%s",filename);
382 f_doc = fopen(f,"w");
383 if (f_doc == NULL) {
384 fprintf(stderr, "Unable to open %s\n", fn);
385 SWIG_exit(1);
386 }
387 }
388
389 void LATEX::close(void) {
390
391 fprintf(f_doc,"\\documentstyle%s\n",tag_documentstyle);
392 fprintf(f_doc,"\\setlength{\\parindent}{%s}\n",tag_parindent);
393 fprintf(f_doc,"\\setlength{\\textwidth}{%s}\n",tag_textwidth);
394 fprintf(f_doc,"\\setlength{\\oddsidemargin}{%s}\n",tag_oddsidemargin);
395 fprintf(f_doc,"%s\n",tag_pagestyle);
396 fprintf(f_doc,"\\begin{document}\n");
397 fprintf(f_doc,"%s\n",s_doc.get());
398 fprintf(f_doc,"\\end{document}\n");
399 fclose(f_doc);
400 if (Verbose)
401 fprintf(stderr,"Documentation written to %s.tex\n", fn);
402 }
403
404 // -------------------------------------------------------------------
405 // LATEX::style(char *name, char *value)
406 //
407 // Process style parameters
408 // -------------------------------------------------------------------
409
410 void LATEX::style(char *name, char *value) {
411 if (strcmp(name,"latex_title") == 0) {
412 if (value)
413 tag_title = copy_string(value);
414 } else if (strcmp(name,"latex_pagestyle") == 0) {
415 if (value)
416 tag_pagestyle = copy_string(value);
417 } else if (strcmp(name,"latex_section") == 0) {
418 if (value)
419 tag_section = copy_string(value);
420 } else if (strcmp(name,"latex_subsection") == 0) {
421 if (value)
422 tag_subsection = copy_string(value);
423 } else if (strcmp(name,"latex_subsubsection") == 0) {
424 if (value)
425 tag_subsubsection = copy_string(value);
426 } else if (strcmp(name,"latex_usage") == 0) {
427 if (value)
428 tag_usage = copy_string(value);
429 } else if (strcmp(name,"latex_descrip") == 0) {
430 if (value)
431 tag_descrip = copy_string(value);
432 } else if (strcmp(name,"latex_text") == 0) {
433 if (value)
434 tag_text = copy_string(value);
435 } else if (strcmp(name,"latex_cinfo") == 0) {
436 if (value)
437 tag_cinfo = copy_string(value);
438 } else if (strcmp(name,"latex_preformat") == 0) {
439 if (value)
440 tag_preformat = copy_string(value);
441 } else if (strcmp(name,"latex_parindent") == 0) {
442 if (value)
443 tag_parindent = copy_string(value);
444 } else if (strcmp(name,"latex_textwidth") == 0) {
445 if (value)
446 tag_textwidth = copy_string(value);
447 } else if (strcmp(name,"latex_documentstyle") == 0) {
448 if (value)
449 tag_documentstyle = copy_string(value);
450 } else if (strcmp(name,"latex_oddsidemargin") == 0) {
451 if (value)
452 tag_oddsidemargin = copy_string(value);
453 }
454 }
455
456 // -------------------------------------------------------------------
457 // LATEX::parse_args(int argc, char **argv)
458 //
459 // Parse command line options
460 // -------------------------------------------------------------------
461
462 static char *latex_usage = "\
463 LATEX Documentation Options (available with -dlatex)\n\
464 None available.\n\n";
465
466 void LATEX::parse_args(int argc, char **argv) {
467 int i;
468
469 for (i = 0; i < argc; i++) {
470 if (argv[i]) {
471 if (strcmp(argv[i],"-help") == 0) {
472 fputs(latex_usage,stderr);
473 }
474 }
475 }
476 }
477
478
479
480
481
482
483
484
485
486
487
488
489
490