]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wxSWIG/SWIG/latex.cxx
1 /*******************************************************************************
2 * Simplified Wrapper and Interface Generator (SWIG)
4 * Author : David Beazley
6 * Department of Computer Science
7 * University of Chicago
10 * beazley@cs.uchicago.edu
12 * Please read the file LICENSE for the copyright and terms by which SWIG
13 * can be used and distributed.
14 *******************************************************************************/
16 /***********************************************************************
21 * Latex specific functions for producing documentation.
23 ***********************************************************************/
28 // -------------------------------------------------------------------
31 // Create new LaTeX handler
32 // -------------------------------------------------------------------
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";
47 tag_cinfo
= "{\\tt : }\\\\";
48 tag_section
= "\\section{:}";
49 tag_subsection
="\\subsection{:}";
50 tag_subsubsection
="\\subsubsection{:}";
53 // -------------------------------------------------------------------
54 // char *start_tag(char *tag) {
56 // Returns the start of a tag
57 // -------------------------------------------------------------------
59 char *LATEX::start_tag(char *tag
) {
65 while ((*c
) && (*c
!= ':')) {
72 // -------------------------------------------------------------------
73 // char *end_tag(char *tag) {
75 // Returns the end of a tag
76 // -------------------------------------------------------------------
78 char *LATEX::end_tag(char *tag
) {
84 while ((*c
) && (*c
!= ':')) {
97 // -------------------------------------------------------------------
98 // LATEX::print_string(char *s, String &str)
100 // Dumps string s to str, but performs some LaTeX character replacements
101 // -------------------------------------------------------------------
103 void LATEX::print_string(char *s
, String
&str
) {
115 str
<< "$" << *c
<< "$";
146 // --------------------------------------------------------------
147 // LATEX::print_decl(DocEntry *)
149 // Print a documentation entry
150 // --------------------------------------------------------------
152 void LATEX::print_decl(DocEntry
*de
) {
159 s_doc
<< start_tag(tag_usage
);
160 print_string(c
,s_doc
);
161 s_doc
<< end_tag(tag_usage
) << "\n";
164 // Check to see if there any information available
166 if ((strlen(de
->cinfo
.get()) && de
->print_info
) || strlen(de
->text
.get())) {
168 // There is additional information now. If we're in preformatting mode,
169 // we need to handle things differently
171 s_doc
<< start_tag(tag_descrip
) << "\n";
175 s_doc
<< start_tag(tag_preformat
) << "\n";
177 // If there is any C annotation, print that
178 if (de
->print_info
) {
181 s_doc
<< "[ " << c
<< " ]\n";
188 s_doc
<< end_tag(tag_preformat
) << "\n";
190 // We are in format mode now
191 // We need to emit some stubs for the description format
193 // If there is any C annotation, print that
194 if (de
->print_info
) {
197 s_doc
<< start_tag(tag_cinfo
) << "[ ";
198 print_string(c
,s_doc
);
199 s_doc
<< " ] " << end_tag(tag_cinfo
) << "\n";
202 // Print out descriptive text (if any).
205 s_doc
<< c
<< "\\\\\n";
208 s_doc
<< end_tag(tag_descrip
) << "\n";
210 s_doc
<< "\\\\\n"; // No description available, move to next line
214 // --------------------------------------------------------------
215 // LATEX::print_text(DocEntry *de)
217 // Print out some text. We use verbatim mode because of formatting
219 // --------------------------------------------------------------
221 void LATEX::print_text(DocEntry
*de
) {
226 s_doc
<< start_tag(tag_text
) << "\n";
228 s_doc
<< end_tag(tag_text
) << "\n\n";
230 s_doc
<< start_tag(tag_preformat
) << "\n";
232 s_doc
<< end_tag(tag_preformat
) << "\n\n";
237 void LATEX::title(DocEntry
*de
) {
242 s_doc
<< start_tag(tag_title
) << " ";
243 print_string(c
,s_doc
);
244 s_doc
<< end_tag(tag_title
) << "\\\\\n";
247 // Print out any C annotation and descriptive text
248 // Check to see if there any information available
250 if ((strlen(de
->cinfo
.get()) && de
->print_info
) || strlen(de
->text
.get())) {
252 // There is additional information now. If we're in preformatting mode,
253 // we need to handle things differently
257 s_doc
<< start_tag(tag_preformat
) << "\n";
259 // If there is any C annotation, print that
260 if (de
->print_info
) {
263 s_doc
<< "[ " << c
<< " ]\n";
271 s_doc
<< end_tag(tag_preformat
) << "\n\n";
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
);
277 // If there is any C annotation, print that
278 if (de
->print_info
) {
281 s_doc
<< start_tag(tag_cinfo
) << "[ ";
282 print_string(c
,s_doc
);
283 s_doc
<< " ] " << end_tag(tag_cinfo
) << "\n";
286 // Print out descriptive text (if any).
291 s_doc
<< end_tag(tag_text
);
296 void LATEX::newsection(DocEntry
*de
,int sectnum
) {
300 sect_num
[sect_count
] = sectnum
;
302 switch (sect_count
) {
303 case 1: /* Section */
306 case 2: /* Subsection */
307 tag
= tag_subsection
;
309 default: /* subsubsection */
310 tag
= tag_subsubsection
;
314 s_doc
<< start_tag(tag
);
316 print_string(c
,s_doc
);
317 s_doc
<< end_tag(tag
);
320 // Print out any C annotation and descriptive text
321 // Check to see if there any information available
323 if ((strlen(de
->cinfo
.get()) && de
->print_info
) || strlen(de
->text
.get())) {
325 // There is additional information now. If we're in preformatting mode,
326 // we need to handle things differently
330 s_doc
<< start_tag(tag_preformat
) << "\n";
332 // If there is any C annotation, print that
333 if (de
->print_info
) {
336 s_doc
<< "[ " << c
<< " ]\n";
344 s_doc
<< end_tag(tag_preformat
) << "\n\n";
346 // We are in format mode now
347 // We need to emit some stubs for the description format
349 s_doc
<< start_tag(tag_text
);
350 // If there is any C annotation, print that
351 if (de
->print_info
) {
354 s_doc
<< start_tag(tag_cinfo
) << "[ ";
355 print_string(c
,s_doc
);
356 s_doc
<< " ] " << end_tag(tag_cinfo
) << "\n";
359 // Print out descriptive text (if any).
364 s_doc
<< end_tag(tag_text
);
370 void LATEX::endsection() {
371 if (sect_count
> 0) sect_count
--;
374 void LATEX::separator() {
377 void LATEX::init(char *filename
) {
380 sprintf(f
,"%s.tex",filename
);
381 sprintf(fn
,"%s",filename
);
382 f_doc
= fopen(f
,"w");
384 fprintf(stderr
, "Unable to open %s\n", fn
);
389 void LATEX::close(void) {
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");
401 fprintf(stderr
,"Documentation written to %s.tex\n", fn
);
404 // -------------------------------------------------------------------
405 // LATEX::style(char *name, char *value)
407 // Process style parameters
408 // -------------------------------------------------------------------
410 void LATEX::style(char *name
, char *value
) {
411 if (strcmp(name
,"latex_title") == 0) {
413 tag_title
= copy_string(value
);
414 } else if (strcmp(name
,"latex_pagestyle") == 0) {
416 tag_pagestyle
= copy_string(value
);
417 } else if (strcmp(name
,"latex_section") == 0) {
419 tag_section
= copy_string(value
);
420 } else if (strcmp(name
,"latex_subsection") == 0) {
422 tag_subsection
= copy_string(value
);
423 } else if (strcmp(name
,"latex_subsubsection") == 0) {
425 tag_subsubsection
= copy_string(value
);
426 } else if (strcmp(name
,"latex_usage") == 0) {
428 tag_usage
= copy_string(value
);
429 } else if (strcmp(name
,"latex_descrip") == 0) {
431 tag_descrip
= copy_string(value
);
432 } else if (strcmp(name
,"latex_text") == 0) {
434 tag_text
= copy_string(value
);
435 } else if (strcmp(name
,"latex_cinfo") == 0) {
437 tag_cinfo
= copy_string(value
);
438 } else if (strcmp(name
,"latex_preformat") == 0) {
440 tag_preformat
= copy_string(value
);
441 } else if (strcmp(name
,"latex_parindent") == 0) {
443 tag_parindent
= copy_string(value
);
444 } else if (strcmp(name
,"latex_textwidth") == 0) {
446 tag_textwidth
= copy_string(value
);
447 } else if (strcmp(name
,"latex_documentstyle") == 0) {
449 tag_documentstyle
= copy_string(value
);
450 } else if (strcmp(name
,"latex_oddsidemargin") == 0) {
452 tag_oddsidemargin
= copy_string(value
);
456 // -------------------------------------------------------------------
457 // LATEX::parse_args(int argc, char **argv)
459 // Parse command line options
460 // -------------------------------------------------------------------
462 static char *latex_usage
= "\
463 LATEX Documentation Options (available with -dlatex)\n\
464 None available.\n\n";
466 void LATEX::parse_args(int argc
, char **argv
) {
469 for (i
= 0; i
< argc
; i
++) {
471 if (strcmp(argv
[i
],"-help") == 0) {
472 fputs(latex_usage
,stderr
);