]>
Commit | Line | Data |
---|---|---|
c90f71dd RD |
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 | #include "swig.h" | |
17 | #include "ascii.h" | |
18 | #include <ctype.h> | |
19 | ||
20 | /******************************************************************************* | |
21 | * $Header$ | |
22 | * | |
23 | * File : ascii.cxx | |
24 | * | |
25 | * Module for producing ASCII documentation. | |
26 | * | |
27 | *******************************************************************************/ | |
28 | ||
29 | // ----------------------------------------------------------------------------- | |
30 | // ASCII::ASCII() | |
31 | // | |
32 | // Constructor. Initializes the ASCII module. | |
33 | // | |
34 | // Inputs : None | |
35 | // | |
36 | // Output : Documentation module object | |
37 | // | |
38 | // Side Effects : | |
39 | // Sets page-width and indentation. | |
40 | // ----------------------------------------------------------------------------- | |
41 | ||
42 | ASCII::ASCII() { | |
43 | sect_count = 0; | |
44 | indent = 8; | |
45 | columns = 70; | |
46 | } | |
47 | ||
48 | // ----------------------------------------------------------------------------- | |
49 | // void ASCII::print_string(char *s, int margin, int mode) | |
50 | // | |
51 | // Prints a string to the documentation file. Performs line wrapping and | |
52 | // other formatting. | |
53 | // | |
54 | // Inputs : | |
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). | |
59 | // | |
60 | // Output : None | |
61 | // | |
62 | // Side Effects : None | |
63 | // ----------------------------------------------------------------------------- | |
64 | ||
65 | void ASCII::print_string(char *s, int margin, int mode) { | |
66 | ||
67 | char *c; | |
68 | int i; | |
69 | int lbreak = 0; | |
70 | int col; | |
71 | ||
72 | c = s; | |
73 | ||
74 | if (!s) return; | |
75 | // Apply indentation | |
76 | ||
77 | for (i = 0; i < margin; i++) | |
78 | fputc(' ',f_doc); | |
79 | ||
80 | col = margin; | |
81 | if (mode) { | |
82 | ||
83 | // Dump out text in formatted mode | |
84 | ||
85 | // Strip leading white-space | |
86 | ||
87 | while ((*c) && (isspace(*c))) { | |
88 | c++; | |
89 | } | |
90 | while (*c) { | |
91 | switch(*c) { | |
92 | case '\n': | |
93 | case '\\': | |
94 | if (lbreak) { | |
95 | col = margin; | |
96 | fputc('\n',f_doc); | |
97 | for (i = 0; i < margin; i++) | |
98 | fputc(' ',f_doc); | |
99 | lbreak = 0; | |
100 | } else { | |
101 | if ((*c) == '\n') { | |
102 | col++; | |
103 | } | |
104 | lbreak++; | |
105 | } | |
106 | break; | |
107 | case ' ': | |
108 | case '\t': | |
109 | case '\r': | |
110 | case '\f': | |
111 | if (col > columns) { | |
112 | fputc('\n',f_doc); | |
113 | for (i = 0; i < margin; i++) | |
114 | fputc(' ',f_doc); | |
115 | col = margin; | |
116 | } else { | |
117 | fputc(' ',f_doc); | |
118 | col++; | |
119 | } | |
120 | // Skip over rest of white space found | |
121 | while ((*c) && isspace(*c)) c++; | |
122 | c--; | |
123 | lbreak = 0; | |
124 | break; | |
125 | default : | |
126 | if (lbreak) fputc(' ',f_doc); | |
127 | lbreak = 0; | |
128 | fputc(*c,f_doc); | |
129 | col++; | |
130 | break; | |
131 | } | |
132 | c++; | |
133 | } | |
134 | } else { | |
135 | // Dump out text in pre-formatted mode | |
136 | while (*c) { | |
137 | switch(*c) { | |
138 | case '\n': | |
139 | fputc('\n',f_doc); | |
140 | for (i = 0; i < margin; i++) | |
141 | fputc(' ',f_doc); | |
142 | break; | |
143 | default : | |
144 | fputc(*c,f_doc); | |
145 | col++; | |
146 | break; | |
147 | } | |
148 | c++; | |
149 | } | |
150 | } | |
151 | } | |
152 | ||
153 | // ----------------------------------------------------------------------------- | |
154 | // void ASCII::print_decl(DocEntry *de) | |
155 | // | |
156 | // Prints the documentation entry corresponding to a declaration | |
157 | // | |
158 | // Inputs : | |
159 | // de = Documentation entry (which should be for a declaration) | |
160 | // | |
161 | // Output : None | |
162 | // | |
163 | // Side Effects : None | |
164 | // ----------------------------------------------------------------------------- | |
165 | ||
166 | void ASCII::print_decl(DocEntry *de) { | |
167 | ||
168 | int i; | |
169 | char *c; | |
170 | ||
171 | c = de->usage.get(); | |
172 | fprintf(f_doc,"%s\n",c); | |
173 | ||
174 | // If there is any C annotation, print that | |
175 | if (de->print_info) { | |
176 | c = de->cinfo.get(); | |
177 | if (strlen(c) > 0) { | |
178 | for (i = 0; i < indent; i++) | |
179 | fputc(' ',f_doc); | |
180 | fprintf(f_doc,"[ "); | |
181 | print_string(c,0,1); | |
182 | fprintf(f_doc," ]\n"); | |
183 | } | |
184 | } | |
185 | ||
186 | c = de->text.get(); | |
187 | if (strlen(c) > 0) { | |
188 | print_string(c,indent,de->format); | |
189 | fprintf(f_doc,"\n"); | |
190 | if (de->format) fputc('\n',f_doc); | |
191 | } else { | |
192 | fprintf(f_doc,"\n"); | |
193 | } | |
194 | } | |
195 | ||
196 | // ----------------------------------------------------------------------------- | |
197 | // void ASCII::print_text(DocEntry *de) | |
198 | // | |
199 | // Prints the documentation for a block of text. Will strip any leading white | |
200 | // space from the text block. | |
201 | // | |
202 | // Inputs : | |
203 | // de = Documentation entry of text | |
204 | // | |
205 | // Output : None | |
206 | // | |
207 | // Side Effects : None | |
208 | // ----------------------------------------------------------------------------- | |
209 | ||
210 | void ASCII::print_text(DocEntry *de) { | |
211 | char *c; | |
212 | c = de->text.get(); | |
213 | if (strlen(c) > 0) { | |
214 | while ((*c == '\n')) c++; | |
215 | print_string(c,0,de->format); | |
216 | fprintf(f_doc,"\n\n"); | |
217 | } | |
218 | } | |
219 | ||
220 | // ----------------------------------------------------------------------------- | |
221 | // void ASCII::title(DocEntry *de) | |
222 | // | |
223 | // Sets the title of the documentation file. | |
224 | // | |
225 | // Inputs : | |
226 | // de = Documentation entry of the title. | |
227 | // | |
228 | // Output : None | |
229 | // | |
230 | // Side Effects : None | |
231 | // ----------------------------------------------------------------------------- | |
232 | ||
233 | void ASCII::title(DocEntry *de) { | |
234 | char *c; | |
235 | ||
236 | c = de->usage.get(); | |
237 | if (strlen(c) > 0) { | |
238 | fprintf(f_doc,"%s\n\n",c); | |
239 | } | |
240 | ||
241 | // If there is any C annotation, print that | |
242 | if (de->print_info) { | |
243 | c = de->cinfo.get(); | |
244 | if (strlen(c) > 0) { | |
245 | fprintf(f_doc,"[ "); | |
246 | print_string(c,0,1); | |
247 | fprintf(f_doc," ]\n"); | |
248 | } | |
249 | } | |
250 | ||
251 | c = de->text.get(); | |
252 | if (strlen(c)) { | |
253 | print_string(c,0,de->format); | |
254 | } | |
255 | fprintf(f_doc,"\n\n"); | |
256 | } | |
257 | ||
258 | // ----------------------------------------------------------------------------- | |
259 | // void ASCII::newsection(DocEntry *de, int sectnum) | |
260 | // | |
261 | // Starts a new section. Will underline major sections and subsections, but | |
262 | // not minor subsections. | |
263 | // | |
264 | // Inputs : | |
265 | // de = Documentation entry of the section | |
266 | // sectnum = Section number. | |
267 | // | |
268 | // Output : None | |
269 | // | |
270 | // Side Effects : | |
271 | // Forces a new subsection to be created within the ASCII module. | |
272 | // ----------------------------------------------------------------------------- | |
273 | ||
274 | void ASCII::newsection(DocEntry *de,int sectnum) { | |
275 | int i,len = 0; | |
276 | char temp[256]; | |
277 | char *c; | |
278 | ||
279 | sect_num[sect_count] = sectnum; | |
280 | sect_count++; | |
281 | for (i = 0; i < sect_count; i++) { | |
282 | sprintf(temp,"%d.",sect_num[i]); | |
283 | fprintf(f_doc,"%s",temp); | |
284 | len += strlen(temp); | |
285 | } | |
286 | c = de->usage.get(); | |
287 | fprintf(f_doc," %s\n", c); | |
288 | len += strlen(c) + 2; | |
289 | ||
290 | // Print an underline if this is a major category | |
291 | ||
292 | if (sect_count <= 1) { | |
293 | for (i = 0; i < len; i++) | |
294 | fputc('=',f_doc); | |
295 | fputc('\n',f_doc); | |
296 | } else if (sect_count == 2) { | |
297 | for (i = 0; i < len; i++) | |
298 | fputc('-',f_doc); | |
299 | fputc('\n',f_doc); | |
300 | } else { | |
301 | fputc('\n',f_doc); | |
302 | } | |
303 | ||
304 | // If there is any C annotation, print that | |
305 | if (de->print_info) { | |
306 | c = de->cinfo.get(); | |
307 | if (strlen(c) > 0) { | |
308 | fprintf(f_doc,"[ "); | |
309 | print_string(c,0,1); | |
310 | fprintf(f_doc," ]\n\n"); | |
311 | } | |
312 | } | |
313 | ||
314 | // If there is a description text. Print it | |
315 | ||
316 | c = de->text.get(); | |
317 | if (strlen(c) > 0) { | |
318 | print_string(c,0,de->format); | |
319 | fprintf(f_doc,"\n"); | |
320 | } | |
321 | fprintf(f_doc,"\n"); | |
322 | } | |
323 | ||
324 | // ----------------------------------------------------------------------------- | |
325 | // void ASCII::endsection() | |
326 | // | |
327 | // Ends the current section. It is an error to call this without having first | |
328 | // called newsection(). | |
329 | // | |
330 | // Inputs : None | |
331 | // | |
332 | // Output : None | |
333 | // | |
334 | // Side Effects : | |
335 | // Pops out of the current section, moving back into the parent section | |
336 | // ----------------------------------------------------------------------------- | |
337 | ||
338 | void ASCII::endsection() { | |
339 | if (sect_count > 0) sect_count--; | |
340 | } | |
341 | ||
342 | // ----------------------------------------------------------------------------- | |
343 | // void ASCII::separator() | |
344 | // | |
345 | // Prints a small dashed line that is used to designate the end of C++ class | |
346 | // subsections. | |
347 | // | |
348 | // Inputs : None | |
349 | // | |
350 | // Output : None | |
351 | // | |
352 | // Side Effects : None | |
353 | // ----------------------------------------------------------------------------- | |
354 | ||
355 | void ASCII::separator() { | |
356 | int i; | |
357 | for (i = 0; i < 10; i++) | |
358 | fputc('-',f_doc); | |
359 | fprintf(f_doc,"\n\n"); | |
360 | } | |
361 | ||
362 | // ----------------------------------------------------------------------------- | |
363 | // void ASCII::init(char *filename) | |
364 | // | |
365 | // Initializes the documentation module and opens up the documentation file. | |
366 | // | |
367 | // Inputs : filename = name of documentation file (without suffix) | |
368 | // | |
369 | // Output : None | |
370 | // | |
371 | // Side Effects : Opens the documentation file. | |
372 | // ----------------------------------------------------------------------------- | |
373 | ||
374 | void ASCII::init(char *filename) { | |
375 | char f[256]; | |
376 | ||
377 | sprintf(f,"%s.doc",filename); | |
378 | sprintf(fn,"%s",filename); | |
379 | f_doc = fopen(f,"w"); | |
380 | if (f_doc == NULL) { | |
381 | fprintf(stderr, "Unable to open %s\n", fn); | |
382 | SWIG_exit(1); | |
383 | } | |
384 | ||
385 | } | |
386 | ||
387 | // ----------------------------------------------------------------------------- | |
388 | // void ASCII::close() | |
389 | // | |
390 | // Closes the documentation module. This function should only be called once | |
391 | // | |
392 | // Inputs : None | |
393 | // | |
394 | // Output : None | |
395 | // | |
396 | // Side Effects : Closes the documentation file. | |
397 | // ----------------------------------------------------------------------------- | |
398 | ||
399 | void ASCII::close(void) { | |
400 | ||
401 | fclose(f_doc); | |
402 | if (Verbose) | |
403 | fprintf(stderr,"Documentation written to %s.doc\n", fn); | |
404 | ||
405 | } | |
406 | ||
407 | // ----------------------------------------------------------------------------- | |
408 | // void ASCII::style(char *name, char *value) | |
409 | // | |
410 | // Looks for style parameters that the user might have supplied using the | |
411 | // %style directive. Unrecognized options are simply ignored. | |
412 | // | |
413 | // Inputs : | |
414 | // name = name of the style parameter | |
415 | // value = value of the style parameter (optional) | |
416 | // | |
417 | // Output : None | |
418 | // | |
419 | // Side Effects : Can change internal settings of 'indent' and 'columns' members. | |
420 | // ----------------------------------------------------------------------------- | |
421 | ||
422 | void ASCII::style(char *name, char *value) { | |
423 | if (strcmp(name,"ascii_indent") == 0) { | |
424 | if (value) { | |
425 | indent = atoi(value); | |
426 | } | |
427 | } else if (strcmp(name,"ascii_columns") == 0) { | |
428 | if (value) { | |
429 | columns = atoi(value); | |
430 | } | |
431 | } | |
432 | } | |
433 | ||
434 | // ----------------------------------------------------------------------------- | |
435 | // void ASCII::parse_args(int argc, char **argv) | |
436 | // | |
437 | // Function for processing options supplied on the SWIG command line. | |
438 | // | |
439 | // Inputs : | |
440 | // argc = Number of arguments | |
441 | // argv = Argument strings | |
442 | // | |
443 | // Output : None | |
444 | // | |
445 | // Side Effects : May set various internal parameters. | |
446 | // ----------------------------------------------------------------------------- | |
447 | ||
448 | static char *ascii_usage = "\ | |
449 | ASCII Documentation Options (available with -dascii)\n\ | |
450 | None available.\n\n"; | |
451 | ||
452 | void ASCII::parse_args(int argc, char **argv) { | |
453 | int i; | |
454 | ||
455 | for (i = 0; i < argc; i++) { | |
456 | if (argv[i]) { | |
457 | if (strcmp(argv[i],"-help") == 0) { | |
458 | fputs(ascii_usage,stderr); | |
459 | } | |
460 | } | |
461 | } | |
462 | } | |
463 | ||
464 |