]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wxSWIG/SWIG/html.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 *******************************************************************************/
19 /*******************************************************************************
24 * HTML specific functions for producing documentation.
25 *******************************************************************************/
30 // -----------------------------------------------------------------------------
33 // Constructor. Creates a new HTML documentation module object.
37 // Output : HTML Object
39 // Side Effects : None
40 // -----------------------------------------------------------------------------
46 // Initialize default tags for various parts of the documentation
48 tag_body
= "<BODY BGCOLOR=\"#ffffff\">:</BODY>";
49 tag_title
= "<H1>:</H1>";
50 tag_contents
= "<HR><H1>:</H1>";
51 tag_section
= "<HR><H2>:</H2>";
52 tag_subsection
= "<H3>:</H3>";
53 tag_subsubsection
= "<H4>:</H4>";
54 tag_usage
= "<P><TT><B>:</B></TT>";
55 tag_descrip
= "<BLOCKQUOTE>:</BLOCKQUOTE>";
58 tag_preformat
= "<PRE>:</PRE>";
61 // -----------------------------------------------------------------------------
62 // char *HTML::start_tag(char *tag)
64 // Utility function for returning the first part of an HTML tag variable.
65 // A tag must look like this :
69 // The start tag for this would be "<b>"
71 // Inputs : tag = HTML tag string
73 // Output : Staring portion of the tag variable.
75 // Side Effects : None.
76 // -----------------------------------------------------------------------------
78 char *HTML::start_tag(char *tag
) {
84 while ((*c
) && (*c
!= ':')) {
91 // -----------------------------------------------------------------------------
92 // char *HTML::end_tag(char *tag)
94 // Utility for returning an end-tag. The counterpart to start_tag().
96 // Inputs : tag = HTML tag string
98 // Output : Ending portion of tag variable.
100 // Side Effects : None
101 // -----------------------------------------------------------------------------
103 char *HTML::end_tag(char *tag
) {
109 while ((*c
) && (*c
!= ':')) {
122 // -----------------------------------------------------------------------------
123 // void HTML::print_string(char *s, String &str, int mode)
125 // Outputs the contents of string s into String str. If mode is 1, we
126 // will reformat the text and apply a few common HTML character
129 // Inputs : s = Documentation text string
130 // mode = Formatting mode (0 = preformat, 1 = formatted)
132 // Output : str = Output is append to str.
134 // Side Effects : None
135 // -----------------------------------------------------------------------------
137 void HTML::print_string(char *s
, String
&str
,int mode
) {
168 // -----------------------------------------------------------------------------
169 // void HTML::print_decl(DocEntry *de)
171 // Generates documentation for a declaration.
173 // Inputs : de = Documentation entry
177 // Side Effects : None
178 // -----------------------------------------------------------------------------
180 void HTML::print_decl(DocEntry
*de
) {
184 while ((*c
) && ((*c
== ' ') || (*c
== '\t') || (*c
== '\n'))) c
++;
186 s_doc
<< start_tag(tag_usage
);
187 print_string(c
,s_doc
,PRE
);
188 s_doc
<< end_tag(tag_usage
) << "\n";
191 // Only print this if there is information
193 if ((strlen(de
->cinfo
.get()) && de
->print_info
) || strlen(de
->text
.get())) {
194 s_doc
<< start_tag(tag_descrip
);
196 s_doc
<< start_tag(tag_preformat
);
199 // If there is any C annotation, print that
200 if (de
->print_info
) {
203 s_doc
<< start_tag(tag_cinfo
);
205 print_string(c
,s_doc
,PRE
);
206 s_doc
<< " ]" << end_tag(tag_cinfo
) << "\n";
207 if (de
->format
) s_doc
<< "<BR>";
213 print_string(c
,s_doc
,de
->format
);
216 if ((strlen(de
->cinfo
.get()) && de
->print_info
) || strlen(de
->text
.get())) {
217 if (!de
->format
) s_doc
<< end_tag(tag_preformat
);
218 s_doc
<< end_tag(tag_descrip
) << "\n";
224 // -----------------------------------------------------------------------------
225 // void HTML::print_text(DocEntry *de)
227 // Generates documentation for a text-block. Strips any leading whitespace.
229 // Inputs : de = Documentation entry
233 // Side Effects : None
234 // -----------------------------------------------------------------------------
236 void HTML::print_text(DocEntry
*de
) {
240 s_doc
<< start_tag(tag_text
);
242 s_doc
<< start_tag(tag_preformat
);
243 print_string(c
,s_doc
,de
->format
);
245 s_doc
<< end_tag(tag_preformat
) << "\n";
246 s_doc
<< end_tag(tag_text
) << "\n";
250 // -----------------------------------------------------------------------------
251 // void HTML::title(DocEntry *de)
253 // Generates the title for an HTML document.
255 // Inputs : de = Title documentation entry
259 // Side Effects : None
260 // -----------------------------------------------------------------------------
262 void HTML::title(DocEntry
*de
) {
266 s_title
<< "<HEAD>\n"
268 print_string(c
,s_title
,PRE
);
269 s_title
<< "</TITLE>\n"
270 << start_tag(tag_body
) << "\n";
272 s_title
<< start_tag(tag_title
);
273 print_string(c
,s_title
,PRE
);
274 s_title
<< end_tag(tag_title
) << "\n";
278 s_title
<< start_tag(tag_preformat
);
280 // If there is any C annotation, print that
281 if (de
->print_info
) {
284 s_title
<< start_tag(tag_cinfo
) << "[ ";
285 print_string(c
,s_title
,de
->format
);
286 s_title
<< " ]" << end_tag(tag_cinfo
);
296 print_string(c
,s_title
,de
->format
);
299 s_title
<< end_tag(tag_preformat
) << "\n";
302 // -----------------------------------------------------------------------------
303 // void HTML::newsection(DocEntry *de, int sectnum)
305 // Creates a new section. sect_count is used to determine the formatting of
306 // the header. Also fills in a table of contents
309 // de = Documentation Entry
310 // sectnum = Section number
315 // Creates a new subsection. Updates HTML table of contents.
316 // -----------------------------------------------------------------------------
318 void HTML::newsection(DocEntry
*de
,int sectnum
) {
324 sect_num
[sect_count
] = sectnum
;
330 // Form table of contents
331 // if sect_count > last_section. We need to indent
332 // if sect_count < last_section. We need to pop out
334 if (sect_count
> last_section
) {
335 for (i
= 0; i
< sect_count
- last_section
; i
++)
337 } else if (sect_count
< last_section
) {
338 for (i
= 0; i
< last_section
- sect_count
; i
++)
342 last_section
= sect_count
;
343 contents
<< "<LI> <A HREF=\"#s";
345 s_doc
<< "<A name=\"s";
346 for (i
= 0; i
< sect_count
; i
++) {
347 s_doc
<< sect_num
[i
] << "_";
348 contents
<< sect_num
[i
] << "_";
353 // Figure out the tag fields
363 tag
= tag_subsection
;
366 tag
= tag_subsubsection
;
369 tag
= tag_subsubsection
;
375 for (i
= 0; i
< sect_count
; i
++) {
376 s_doc
<< sect_num
[i
] << ".";
377 contents
<< sect_num
[i
] << ".";
382 print_string(c
,s_doc
,PRE
);
383 print_string(c
,contents
,PRE
);
384 s_doc
<< end_tag(tag
) << "</A>\n";
385 contents
<< "</A>\n";
388 s_doc
<< start_tag(tag_preformat
);
390 // If there is any C annotation, print that
391 if (de
->print_info
) {
394 s_doc
<< start_tag(tag_cinfo
) << "[ ";
395 print_string(c
,s_doc
,de
->format
);
396 s_doc
<< " ]" << end_tag(tag_cinfo
);
404 // If there is a description text. Print it
408 print_string(c
,s_doc
,de
->format
);
412 s_doc
<< end_tag(tag_preformat
) << "\n";
416 // -----------------------------------------------------------------------------
417 // void HTML::endsection()
419 // Ends a subsection. It is an error to call this without first calling
420 // newsection previously.
426 // Side Effects : Closes current section and goes back to parent.
428 // -----------------------------------------------------------------------------
430 void HTML::endsection() {
431 if (sect_count
> 0) sect_count
--;
434 // -----------------------------------------------------------------------------
435 // void HTML::separator()
437 // Prints a separator after the declaration of a C++ class. Currently
438 // does nothing in HTML mode.
444 // Side Effects : None
445 // -----------------------------------------------------------------------------
447 void HTML::separator() {
450 // -----------------------------------------------------------------------------
451 // void HTML::init(char *filename)
453 // Initializes the HTML module and opens up the documentation file.
455 // Inputs : filename = Name of documentation file (without a suffix)
459 // Side Effects : Opens documentation file.
460 // -----------------------------------------------------------------------------
462 void HTML::init(char *filename
) {
465 sprintf(f
,"%s.html",filename
);
466 f_doc
= fopen(f
,"w");
468 fprintf(stderr
,"Unable to open %s\n",f
);
471 /* Print a HTML banner */
472 fprintf(f_doc
,"<HTML>\n");
476 // -----------------------------------------------------------------------------
477 // void HTML::close(void)
479 // Dumps the table of contents and forms the final documentation file. Closes
480 // the documentation file upon completion.
486 // Side Effects : Closes documentation file.
487 // -----------------------------------------------------------------------------
489 void HTML::close(void) {
492 for (i
= 0; i
< last_section
; i
++)
493 contents
<< "</UL>\n";
495 fprintf(f_doc
,"%s\n",s_title
.get());
497 fprintf(f_doc
,"%s Contents %s\n",start_tag(tag_contents
),end_tag(tag_contents
));
498 fprintf(f_doc
,"%s\n",contents
.get());
500 fprintf(f_doc
,"%s\n",s_doc
.get());
501 fprintf(f_doc
,"%s\n", end_tag(tag_body
));
502 fprintf(f_doc
,"</HTML>\n");
506 // -----------------------------------------------------------------------------
507 // void HTML::style(char *name, char *value)
509 // Process parameters given with the %style directive. Does nothing if an
510 // unrecognized parameter is given.
513 // name = name of style parameter
514 // value = ASCII string with value of parameter.
518 // Side Effects : Updates internal style parameters.
519 // -----------------------------------------------------------------------------
521 void HTML::style(char *name
, char *value
) {
522 if (strcmp(name
,"html_title") == 0) {
524 tag_title
= copy_string(value
);
525 } else if (strcmp(name
,"html_contents") == 0) {
527 tag_contents
= copy_string(value
);
528 } else if (strcmp(name
,"html_section") == 0) {
530 tag_section
= copy_string(value
);
531 } else if (strcmp(name
,"html_subsection") == 0) {
533 tag_subsection
= copy_string(value
);
534 } else if (strcmp(name
,"html_subsubsection") == 0) {
536 tag_subsubsection
= copy_string(value
);
537 } else if (strcmp(name
,"html_usage") == 0) {
539 tag_usage
= copy_string(value
);
540 } else if (strcmp(name
,"html_descrip") == 0) {
542 tag_descrip
= copy_string(value
);
543 } else if (strcmp(name
,"html_text") == 0) {
545 tag_text
= copy_string(value
);
546 } else if (strcmp(name
,"html_cinfo") == 0) {
548 tag_cinfo
= copy_string(value
);
549 } else if (strcmp(name
,"html_preformat") == 0) {
551 tag_preformat
= copy_string(value
);
552 } else if (strcmp(name
,"html_body") == 0) {
554 tag_body
= copy_string(value
);
558 // -----------------------------------------------------------------------------
559 // void HTML::parse_args(int argc, char **argv)
561 // Parse command line options given on the SWIG command line.
564 // argc = argument count
565 // argv = argument array
569 // Side Effects : Marks arguments as being parsed.
570 // -----------------------------------------------------------------------------
572 static char *html_usage
= "\
573 HTML Documentation Options (available with -dhtml)\n\
574 None available.\n\n";
576 void HTML::parse_args(int argc
, char **argv
) {
579 for (i
= 0; i
< argc
; i
++) {
581 if (strcmp(argv
[i
],"-help") == 0) {
582 fputs(html_usage
,stderr
);