]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wxSWIG/SWIG/ascii.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 *******************************************************************************/
20 /*******************************************************************************
25 * Module for producing ASCII documentation.
27 *******************************************************************************/
29 // -----------------------------------------------------------------------------
32 // Constructor. Initializes the ASCII module.
36 // Output : Documentation module object
39 // Sets page-width and indentation.
40 // -----------------------------------------------------------------------------
48 // -----------------------------------------------------------------------------
49 // void ASCII::print_string(char *s, int margin, int mode)
51 // Prints a string to the documentation file. Performs line wrapping and
55 // s = NULL terminate ASCII string
56 // margin = Number of characters to be inserted on left side
57 // mode = If set, text will be reformatted. Otherwise, it's
58 // printed verbatim (with indentation).
62 // Side Effects : None
63 // -----------------------------------------------------------------------------
65 void ASCII::print_string(char *s
, int margin
, int mode
) {
77 for (i
= 0; i
< margin
; i
++)
83 // Dump out text in formatted mode
85 // Strip leading white-space
87 while ((*c
) && (isspace(*c
))) {
97 for (i
= 0; i
< margin
; i
++)
113 for (i
= 0; i
< margin
; i
++)
120 // Skip over rest of white space found
121 while ((*c
) && isspace(*c
)) c
++;
126 if (lbreak
) fputc(' ',f_doc
);
135 // Dump out text in pre-formatted mode
140 for (i
= 0; i
< margin
; i
++)
153 // -----------------------------------------------------------------------------
154 // void ASCII::print_decl(DocEntry *de)
156 // Prints the documentation entry corresponding to a declaration
159 // de = Documentation entry (which should be for a declaration)
163 // Side Effects : None
164 // -----------------------------------------------------------------------------
166 void ASCII::print_decl(DocEntry
*de
) {
172 fprintf(f_doc
,"%s\n",c
);
174 // If there is any C annotation, print that
175 if (de
->print_info
) {
178 for (i
= 0; i
< indent
; i
++)
182 fprintf(f_doc
," ]\n");
188 print_string(c
,indent
,de
->format
);
190 if (de
->format
) fputc('\n',f_doc
);
196 // -----------------------------------------------------------------------------
197 // void ASCII::print_text(DocEntry *de)
199 // Prints the documentation for a block of text. Will strip any leading white
200 // space from the text block.
203 // de = Documentation entry of text
207 // Side Effects : None
208 // -----------------------------------------------------------------------------
210 void ASCII::print_text(DocEntry
*de
) {
214 while ((*c
== '\n')) c
++;
215 print_string(c
,0,de
->format
);
216 fprintf(f_doc
,"\n\n");
220 // -----------------------------------------------------------------------------
221 // void ASCII::title(DocEntry *de)
223 // Sets the title of the documentation file.
226 // de = Documentation entry of the title.
230 // Side Effects : None
231 // -----------------------------------------------------------------------------
233 void ASCII::title(DocEntry
*de
) {
238 fprintf(f_doc
,"%s\n\n",c
);
241 // If there is any C annotation, print that
242 if (de
->print_info
) {
247 fprintf(f_doc
," ]\n");
253 print_string(c
,0,de
->format
);
255 fprintf(f_doc
,"\n\n");
258 // -----------------------------------------------------------------------------
259 // void ASCII::newsection(DocEntry *de, int sectnum)
261 // Starts a new section. Will underline major sections and subsections, but
262 // not minor subsections.
265 // de = Documentation entry of the section
266 // sectnum = Section number.
271 // Forces a new subsection to be created within the ASCII module.
272 // -----------------------------------------------------------------------------
274 void ASCII::newsection(DocEntry
*de
,int sectnum
) {
279 sect_num
[sect_count
] = sectnum
;
281 for (i
= 0; i
< sect_count
; i
++) {
282 sprintf(temp
,"%d.",sect_num
[i
]);
283 fprintf(f_doc
,"%s",temp
);
287 fprintf(f_doc
," %s\n", c
);
288 len
+= strlen(c
) + 2;
290 // Print an underline if this is a major category
292 if (sect_count
<= 1) {
293 for (i
= 0; i
< len
; i
++)
296 } else if (sect_count
== 2) {
297 for (i
= 0; i
< len
; i
++)
304 // If there is any C annotation, print that
305 if (de
->print_info
) {
310 fprintf(f_doc
," ]\n\n");
314 // If there is a description text. Print it
318 print_string(c
,0,de
->format
);
324 // -----------------------------------------------------------------------------
325 // void ASCII::endsection()
327 // Ends the current section. It is an error to call this without having first
328 // called newsection().
335 // Pops out of the current section, moving back into the parent section
336 // -----------------------------------------------------------------------------
338 void ASCII::endsection() {
339 if (sect_count
> 0) sect_count
--;
342 // -----------------------------------------------------------------------------
343 // void ASCII::separator()
345 // Prints a small dashed line that is used to designate the end of C++ class
352 // Side Effects : None
353 // -----------------------------------------------------------------------------
355 void ASCII::separator() {
357 for (i
= 0; i
< 10; i
++)
359 fprintf(f_doc
,"\n\n");
362 // -----------------------------------------------------------------------------
363 // void ASCII::init(char *filename)
365 // Initializes the documentation module and opens up the documentation file.
367 // Inputs : filename = name of documentation file (without suffix)
371 // Side Effects : Opens the documentation file.
372 // -----------------------------------------------------------------------------
374 void ASCII::init(char *filename
) {
377 sprintf(f
,"%s.doc",filename
);
378 sprintf(fn
,"%s",filename
);
379 f_doc
= fopen(f
,"w");
381 fprintf(stderr
, "Unable to open %s\n", fn
);
387 // -----------------------------------------------------------------------------
388 // void ASCII::close()
390 // Closes the documentation module. This function should only be called once
396 // Side Effects : Closes the documentation file.
397 // -----------------------------------------------------------------------------
399 void ASCII::close(void) {
403 fprintf(stderr
,"Documentation written to %s.doc\n", fn
);
407 // -----------------------------------------------------------------------------
408 // void ASCII::style(char *name, char *value)
410 // Looks for style parameters that the user might have supplied using the
411 // %style directive. Unrecognized options are simply ignored.
414 // name = name of the style parameter
415 // value = value of the style parameter (optional)
419 // Side Effects : Can change internal settings of 'indent' and 'columns' members.
420 // -----------------------------------------------------------------------------
422 void ASCII::style(char *name
, char *value
) {
423 if (strcmp(name
,"ascii_indent") == 0) {
425 indent
= atoi(value
);
427 } else if (strcmp(name
,"ascii_columns") == 0) {
429 columns
= atoi(value
);
434 // -----------------------------------------------------------------------------
435 // void ASCII::parse_args(int argc, char **argv)
437 // Function for processing options supplied on the SWIG command line.
440 // argc = Number of arguments
441 // argv = Argument strings
445 // Side Effects : May set various internal parameters.
446 // -----------------------------------------------------------------------------
448 static char *ascii_usage
= "\
449 ASCII Documentation Options (available with -dascii)\n\
450 None available.\n\n";
452 void ASCII::parse_args(int argc
, char **argv
) {
455 for (i
= 0; i
< argc
; i
++) {
457 if (strcmp(argv
[i
],"-help") == 0) {
458 fputs(ascii_usage
,stderr
);