Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | #!/usr/bin/perl -w |
2 | ||
3 | use strict; | |
4 | ||
5 | ## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ## | |
6 | ## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ## | |
7 | ## Copyright (C) 2001 Simon Huggins ## | |
70c95b00 | 8 | ## Copyright (C) 2005-2012 Randy Dunlap ## |
1b40c194 | 9 | ## Copyright (C) 2012 Dan Luedtke ## |
1da177e4 LT |
10 | ## ## |
11 | ## #define enhancements by Armin Kuster <akuster@mvista.com> ## | |
12 | ## Copyright (c) 2000 MontaVista Software, Inc. ## | |
13 | ## ## | |
14 | ## This software falls under the GNU General Public License. ## | |
15 | ## Please read the COPYING file for more information ## | |
16 | ||
1da177e4 LT |
17 | # 18/01/2001 - Cleanups |
18 | # Functions prototyped as foo(void) same as foo() | |
19 | # Stop eval'ing where we don't need to. | |
20 | # -- huggie@earth.li | |
21 | ||
22 | # 27/06/2001 - Allowed whitespace after initial "/**" and | |
23 | # allowed comments before function declarations. | |
24 | # -- Christian Kreibich <ck@whoop.org> | |
25 | ||
26 | # Still to do: | |
27 | # - add perldoc documentation | |
28 | # - Look more closely at some of the scarier bits :) | |
29 | ||
30 | # 26/05/2001 - Support for separate source and object trees. | |
31 | # Return error code. | |
32 | # Keith Owens <kaos@ocs.com.au> | |
33 | ||
34 | # 23/09/2001 - Added support for typedefs, structs, enums and unions | |
35 | # Support for Context section; can be terminated using empty line | |
36 | # Small fixes (like spaces vs. \s in regex) | |
37 | # -- Tim Jansen <tim@tjansen.de> | |
38 | ||
1b40c194 DL |
39 | # 25/07/2012 - Added support for HTML5 |
40 | # -- Dan Luedtke <mail@danrl.de> | |
1da177e4 | 41 | |
fadc0b31 JN |
42 | sub usage { |
43 | my $message = <<"EOF"; | |
44 | Usage: $0 [OPTION ...] FILE ... | |
45 | ||
46 | Read C language source or header FILEs, extract embedded documentation comments, | |
47 | and print formatted documentation to standard output. | |
48 | ||
49 | The documentation comments are identified by "/**" opening comment mark. See | |
50 | Documentation/kernel-doc-nano-HOWTO.txt for the documentation comment syntax. | |
51 | ||
52 | Output format selection (mutually exclusive): | |
53 | -docbook Output DocBook format. | |
54 | -html Output HTML format. | |
55 | -html5 Output HTML5 format. | |
56 | -list Output symbol list format. This is for use by docproc. | |
57 | -man Output troff manual page format. This is the default. | |
c0d1b6ee | 58 | -rst Output reStructuredText format. |
fadc0b31 JN |
59 | -text Output plain text format. |
60 | ||
61 | Output selection (mutually exclusive): | |
86ae2e38 JN |
62 | -export Only output documentation for symbols that have been |
63 | exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() | |
64 | in the same FILE. | |
65 | -internal Only output documentation for symbols that have NOT been | |
66 | exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() | |
67 | in the same FILE. | |
fadc0b31 JN |
68 | -function NAME Only output documentation for the given function(s) |
69 | or DOC: section title(s). All other functions and DOC: | |
70 | sections are ignored. May be specified multiple times. | |
71 | -nofunction NAME Do NOT output documentation for the given function(s); | |
72 | only output documentation for the other functions and | |
73 | DOC: sections. May be specified multiple times. | |
74 | ||
75 | Output selection modifiers: | |
76 | -no-doc-sections Do not output DOC: sections. | |
77 | ||
78 | Other parameters: | |
79 | -v Verbose output, more warnings and other information. | |
80 | -h Print this help. | |
81 | ||
82 | EOF | |
83 | print $message; | |
84 | exit 1; | |
85 | } | |
1da177e4 LT |
86 | |
87 | # | |
88 | # format of comments. | |
89 | # In the following table, (...)? signifies optional structure. | |
90 | # (...)* signifies 0 or more structure elements | |
91 | # /** | |
92 | # * function_name(:)? (- short description)? | |
93 | # (* @parameterx: (description of parameter x)?)* | |
94 | # (* a blank line)? | |
95 | # * (Description:)? (Description of function)? | |
96 | # * (section header: (section description)? )* | |
97 | # (*)?*/ | |
98 | # | |
99 | # So .. the trivial example would be: | |
100 | # | |
101 | # /** | |
102 | # * my_function | |
b9d97328 | 103 | # */ |
1da177e4 | 104 | # |
891dcd2f | 105 | # If the Description: header tag is omitted, then there must be a blank line |
1da177e4 LT |
106 | # after the last parameter specification. |
107 | # e.g. | |
108 | # /** | |
109 | # * my_function - does my stuff | |
110 | # * @my_arg: its mine damnit | |
111 | # * | |
3c3b809e | 112 | # * Does my stuff explained. |
1da177e4 LT |
113 | # */ |
114 | # | |
115 | # or, could also use: | |
116 | # /** | |
117 | # * my_function - does my stuff | |
118 | # * @my_arg: its mine damnit | |
3c3b809e | 119 | # * Description: Does my stuff explained. |
1da177e4 LT |
120 | # */ |
121 | # etc. | |
122 | # | |
b9d97328 | 123 | # Besides functions you can also write documentation for structs, unions, |
3c3b809e RD |
124 | # enums and typedefs. Instead of the function name you must write the name |
125 | # of the declaration; the struct/union/enum/typedef must always precede | |
126 | # the name. Nesting of declarations is not supported. | |
1da177e4 LT |
127 | # Use the argument mechanism to document members or constants. |
128 | # e.g. | |
129 | # /** | |
130 | # * struct my_struct - short description | |
131 | # * @a: first member | |
132 | # * @b: second member | |
3c3b809e | 133 | # * |
1da177e4 LT |
134 | # * Longer description |
135 | # */ | |
136 | # struct my_struct { | |
137 | # int a; | |
138 | # int b; | |
aeec46b9 MW |
139 | # /* private: */ |
140 | # int c; | |
1da177e4 LT |
141 | # }; |
142 | # | |
143 | # All descriptions can be multiline, except the short function description. | |
3c3b809e | 144 | # |
a4c6ebed DCLP |
145 | # For really longs structs, you can also describe arguments inside the |
146 | # body of the struct. | |
147 | # eg. | |
148 | # /** | |
149 | # * struct my_struct - short description | |
150 | # * @a: first member | |
151 | # * @b: second member | |
152 | # * | |
153 | # * Longer description | |
154 | # */ | |
155 | # struct my_struct { | |
156 | # int a; | |
157 | # int b; | |
158 | # /** | |
159 | # * @c: This is longer description of C | |
160 | # * | |
161 | # * You can use paragraphs to describe arguments | |
162 | # * using this method. | |
163 | # */ | |
164 | # int c; | |
165 | # }; | |
166 | # | |
167 | # This should be use only for struct/enum members. | |
168 | # | |
3c3b809e RD |
169 | # You can also add additional sections. When documenting kernel functions you |
170 | # should document the "Context:" of the function, e.g. whether the functions | |
1da177e4 | 171 | # can be called form interrupts. Unlike other sections you can end it with an |
3c3b809e | 172 | # empty line. |
4092bac7 YB |
173 | # A non-void function should have a "Return:" section describing the return |
174 | # value(s). | |
3c3b809e | 175 | # Example-sections should contain the string EXAMPLE so that they are marked |
1da177e4 LT |
176 | # appropriately in DocBook. |
177 | # | |
178 | # Example: | |
179 | # /** | |
180 | # * user_function - function that can only be called in user context | |
181 | # * @a: some argument | |
182 | # * Context: !in_interrupt() | |
3c3b809e | 183 | # * |
1da177e4 LT |
184 | # * Some description |
185 | # * Example: | |
186 | # * user_function(22); | |
187 | # */ | |
188 | # ... | |
189 | # | |
190 | # | |
191 | # All descriptive text is further processed, scanning for the following special | |
192 | # patterns, which are highlighted appropriately. | |
193 | # | |
194 | # 'funcname()' - function | |
195 | # '$ENVVAR' - environmental variable | |
196 | # '&struct_name' - name of a structure (up to two words including 'struct') | |
197 | # '@parameter' - name of a parameter | |
198 | # '%CONST' - name of a constant. | |
199 | ||
8484baaa RD |
200 | ## init lots of data |
201 | ||
1da177e4 LT |
202 | my $errors = 0; |
203 | my $warnings = 0; | |
5f8c7c98 | 204 | my $anon_struct_union = 0; |
1da177e4 LT |
205 | |
206 | # match expressions used to find embedded type information | |
207 | my $type_constant = '\%([-_\w]+)'; | |
208 | my $type_func = '(\w+)\(\)'; | |
209 | my $type_param = '\@(\w+)'; | |
3eb014a1 | 210 | my $type_struct = '\&((struct\s*)*[_\w]+)'; |
6b5b55f6 | 211 | my $type_struct_xml = '\\&((struct\s*)*[_\w]+)'; |
1da177e4 | 212 | my $type_env = '(\$\w+)'; |
c0d1b6ee JC |
213 | my $type_enum_full = '\&(enum)\s*([_\w]+)'; |
214 | my $type_struct_full = '\&(struct)\s*([_\w]+)'; | |
1da177e4 LT |
215 | |
216 | # Output conversion substitutions. | |
217 | # One for each output format | |
218 | ||
219 | # these work fairly well | |
4d732701 DCLP |
220 | my @highlights_html = ( |
221 | [$type_constant, "<i>\$1</i>"], | |
222 | [$type_func, "<b>\$1</b>"], | |
223 | [$type_struct_xml, "<i>\$1</i>"], | |
224 | [$type_env, "<b><i>\$1</i></b>"], | |
225 | [$type_param, "<tt><b>\$1</b></tt>"] | |
226 | ); | |
6b5b55f6 RD |
227 | my $local_lt = "\\\\\\\\lt:"; |
228 | my $local_gt = "\\\\\\\\gt:"; | |
229 | my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>" | |
1da177e4 | 230 | |
1b40c194 | 231 | # html version 5 |
4d732701 DCLP |
232 | my @highlights_html5 = ( |
233 | [$type_constant, "<span class=\"const\">\$1</span>"], | |
234 | [$type_func, "<span class=\"func\">\$1</span>"], | |
235 | [$type_struct_xml, "<span class=\"struct\">\$1</span>"], | |
236 | [$type_env, "<span class=\"env\">\$1</span>"], | |
237 | [$type_param, "<span class=\"param\">\$1</span>]"] | |
238 | ); | |
1b40c194 DL |
239 | my $blankline_html5 = $local_lt . "br /" . $local_gt; |
240 | ||
1da177e4 | 241 | # XML, docbook format |
4d732701 DCLP |
242 | my @highlights_xml = ( |
243 | ["([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>"], | |
244 | [$type_constant, "<constant>\$1</constant>"], | |
245 | [$type_struct_xml, "<structname>\$1</structname>"], | |
246 | [$type_param, "<parameter>\$1</parameter>"], | |
247 | [$type_func, "<function>\$1</function>"], | |
248 | [$type_env, "<envar>\$1</envar>"] | |
249 | ); | |
5c98fc03 | 250 | my $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n"; |
1da177e4 LT |
251 | |
252 | # gnome, docbook format | |
4d732701 DCLP |
253 | my @highlights_gnome = ( |
254 | [$type_constant, "<replaceable class=\"option\">\$1</replaceable>"], | |
255 | [$type_func, "<function>\$1</function>"], | |
256 | [$type_struct, "<structname>\$1</structname>"], | |
257 | [$type_env, "<envar>\$1</envar>"], | |
258 | [$type_param, "<parameter>\$1</parameter>" ] | |
259 | ); | |
1da177e4 LT |
260 | my $blankline_gnome = "</para><para>\n"; |
261 | ||
262 | # these are pretty rough | |
4d732701 DCLP |
263 | my @highlights_man = ( |
264 | [$type_constant, "\$1"], | |
265 | [$type_func, "\\\\fB\$1\\\\fP"], | |
266 | [$type_struct, "\\\\fI\$1\\\\fP"], | |
267 | [$type_param, "\\\\fI\$1\\\\fP"] | |
268 | ); | |
1da177e4 LT |
269 | my $blankline_man = ""; |
270 | ||
271 | # text-mode | |
4d732701 DCLP |
272 | my @highlights_text = ( |
273 | [$type_constant, "\$1"], | |
274 | [$type_func, "\$1"], | |
275 | [$type_struct, "\$1"], | |
276 | [$type_param, "\$1"] | |
277 | ); | |
1da177e4 LT |
278 | my $blankline_text = ""; |
279 | ||
c0d1b6ee JC |
280 | # rst-mode |
281 | my @highlights_rst = ( | |
282 | [$type_constant, "``\$1``"], | |
283 | [$type_func, "\\:c\\:func\\:`\$1`"], | |
62850976 JN |
284 | [$type_struct_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"], |
285 | [$type_enum_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"], | |
286 | [$type_struct, "\\:c\\:type\\:`struct \$1 <\$1>`"], | |
c0d1b6ee JC |
287 | [$type_param, "**\$1**"] |
288 | ); | |
289 | my $blankline_rst = "\n"; | |
290 | ||
eda603f6 | 291 | # list mode |
4d732701 DCLP |
292 | my @highlights_list = ( |
293 | [$type_constant, "\$1"], | |
294 | [$type_func, "\$1"], | |
295 | [$type_struct, "\$1"], | |
296 | [$type_param, "\$1"] | |
297 | ); | |
eda603f6 | 298 | my $blankline_list = ""; |
1da177e4 | 299 | |
1da177e4 | 300 | # read arguments |
b9d97328 | 301 | if ($#ARGV == -1) { |
1da177e4 LT |
302 | usage(); |
303 | } | |
304 | ||
8484baaa RD |
305 | my $kernelversion; |
306 | my $dohighlight = ""; | |
307 | ||
1da177e4 LT |
308 | my $verbose = 0; |
309 | my $output_mode = "man"; | |
e314ba31 | 310 | my $output_preformatted = 0; |
4b44595a | 311 | my $no_doc_sections = 0; |
4d732701 | 312 | my @highlights = @highlights_man; |
1da177e4 LT |
313 | my $blankline = $blankline_man; |
314 | my $modulename = "Kernel API"; | |
315 | my $function_only = 0; | |
b2c4105b BH |
316 | my $show_not_found = 0; |
317 | ||
318 | my @build_time; | |
319 | if (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) && | |
320 | (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') { | |
321 | @build_time = gmtime($seconds); | |
322 | } else { | |
323 | @build_time = localtime; | |
324 | } | |
325 | ||
3c3b809e RD |
326 | my $man_date = ('January', 'February', 'March', 'April', 'May', 'June', |
327 | 'July', 'August', 'September', 'October', | |
b2c4105b BH |
328 | 'November', 'December')[$build_time[4]] . |
329 | " " . ($build_time[5]+1900); | |
1da177e4 | 330 | |
8484baaa | 331 | # Essentially these are globals. |
b9d97328 RD |
332 | # They probably want to be tidied up, made more localised or something. |
333 | # CAVEAT EMPTOR! Some of the others I localised may not want to be, which | |
1da177e4 | 334 | # could cause "use of undefined value" or other bugs. |
b9d97328 RD |
335 | my ($function, %function_table, %parametertypes, $declaration_purpose); |
336 | my ($type, $declaration_name, $return_type); | |
1c32fd0c | 337 | my ($newsection, $newcontents, $prototype, $brcount, %source_map); |
1da177e4 | 338 | |
bd0e88e5 RD |
339 | if (defined($ENV{'KBUILD_VERBOSE'})) { |
340 | $verbose = "$ENV{'KBUILD_VERBOSE'}"; | |
341 | } | |
342 | ||
3c3b809e | 343 | # Generated docbook code is inserted in a template at a point where |
1da177e4 LT |
344 | # docbook v3.1 requires a non-zero sequence of RefEntry's; see: |
345 | # http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html | |
346 | # We keep track of number of generated entries and generate a dummy | |
347 | # if needs be to ensure the expanded template can be postprocessed | |
348 | # into html. | |
349 | my $section_counter = 0; | |
350 | ||
351 | my $lineprefix=""; | |
352 | ||
353 | # states | |
354 | # 0 - normal code | |
355 | # 1 - looking for function name | |
356 | # 2 - scanning field start. | |
357 | # 3 - scanning prototype. | |
358 | # 4 - documentation block | |
a4c6ebed | 359 | # 5 - gathering documentation outside main block |
1da177e4 | 360 | my $state; |
850622df | 361 | my $in_doc_sect; |
1da177e4 | 362 | |
a4c6ebed DCLP |
363 | # Split Doc State |
364 | # 0 - Invalid (Before start or after finish) | |
365 | # 1 - Is started (the /** was found inside a struct) | |
366 | # 2 - The @parameter header was found, start accepting multi paragraph text. | |
367 | # 3 - Finished (the */ was found) | |
368 | # 4 - Error - Comment without header was found. Spit a warning as it's not | |
369 | # proper kernel-doc and ignore the rest. | |
370 | my $split_doc_state; | |
371 | ||
1da177e4 LT |
372 | #declaration types: can be |
373 | # 'function', 'struct', 'union', 'enum', 'typedef' | |
374 | my $decl_type; | |
375 | ||
376 | my $doc_special = "\@\%\$\&"; | |
377 | ||
378 | my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start. | |
379 | my $doc_end = '\*/'; | |
380 | my $doc_com = '\s*\*\s*'; | |
12ae6779 | 381 | my $doc_com_body = '\s*\* ?'; |
b9d97328 RD |
382 | my $doc_decl = $doc_com . '(\w+)'; |
383 | my $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)'; | |
12ae6779 | 384 | my $doc_content = $doc_com_body . '(.*)'; |
b9d97328 | 385 | my $doc_block = $doc_com . 'DOC:\s*(.*)?'; |
a4c6ebed DCLP |
386 | my $doc_split_start = '^\s*/\*\*\s*$'; |
387 | my $doc_split_sect = '\s*\*\s*(@[\w\s]+):(.*)'; | |
388 | my $doc_split_end = '^\s*\*/\s*$'; | |
86ae2e38 | 389 | my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;'; |
1da177e4 LT |
390 | |
391 | my %constants; | |
392 | my %parameterdescs; | |
393 | my @parameterlist; | |
394 | my %sections; | |
395 | my @sectionlist; | |
a1d94aa5 RD |
396 | my $sectcheck; |
397 | my $struct_actual; | |
1da177e4 LT |
398 | |
399 | my $contents = ""; | |
400 | my $section_default = "Description"; # default section | |
401 | my $section_intro = "Introduction"; | |
402 | my $section = $section_default; | |
403 | my $section_context = "Context"; | |
4092bac7 | 404 | my $section_return = "Return"; |
1da177e4 LT |
405 | |
406 | my $undescribed = "-- undescribed --"; | |
407 | ||
408 | reset_state(); | |
409 | ||
410 | while ($ARGV[0] =~ m/^-(.*)/) { | |
411 | my $cmd = shift @ARGV; | |
412 | if ($cmd eq "-html") { | |
413 | $output_mode = "html"; | |
4d732701 | 414 | @highlights = @highlights_html; |
1da177e4 | 415 | $blankline = $blankline_html; |
1b40c194 DL |
416 | } elsif ($cmd eq "-html5") { |
417 | $output_mode = "html5"; | |
4d732701 | 418 | @highlights = @highlights_html5; |
1b40c194 | 419 | $blankline = $blankline_html5; |
1da177e4 LT |
420 | } elsif ($cmd eq "-man") { |
421 | $output_mode = "man"; | |
4d732701 | 422 | @highlights = @highlights_man; |
1da177e4 LT |
423 | $blankline = $blankline_man; |
424 | } elsif ($cmd eq "-text") { | |
425 | $output_mode = "text"; | |
4d732701 | 426 | @highlights = @highlights_text; |
1da177e4 | 427 | $blankline = $blankline_text; |
c0d1b6ee JC |
428 | } elsif ($cmd eq "-rst") { |
429 | $output_mode = "rst"; | |
430 | @highlights = @highlights_rst; | |
431 | $blankline = $blankline_rst; | |
1da177e4 LT |
432 | } elsif ($cmd eq "-docbook") { |
433 | $output_mode = "xml"; | |
4d732701 | 434 | @highlights = @highlights_xml; |
1da177e4 | 435 | $blankline = $blankline_xml; |
eda603f6 JB |
436 | } elsif ($cmd eq "-list") { |
437 | $output_mode = "list"; | |
4d732701 | 438 | @highlights = @highlights_list; |
eda603f6 | 439 | $blankline = $blankline_list; |
1da177e4 LT |
440 | } elsif ($cmd eq "-gnome") { |
441 | $output_mode = "gnome"; | |
4d732701 | 442 | @highlights = @highlights_gnome; |
1da177e4 LT |
443 | $blankline = $blankline_gnome; |
444 | } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document | |
445 | $modulename = shift @ARGV; | |
446 | } elsif ($cmd eq "-function") { # to only output specific functions | |
447 | $function_only = 1; | |
448 | $function = shift @ARGV; | |
449 | $function_table{$function} = 1; | |
450 | } elsif ($cmd eq "-nofunction") { # to only output specific functions | |
451 | $function_only = 2; | |
452 | $function = shift @ARGV; | |
453 | $function_table{$function} = 1; | |
86ae2e38 JN |
454 | } elsif ($cmd eq "-export") { # only exported symbols |
455 | $function_only = 3; | |
456 | %function_table = () | |
457 | } elsif ($cmd eq "-internal") { # only non-exported symbols | |
458 | $function_only = 4; | |
459 | %function_table = () | |
1da177e4 LT |
460 | } elsif ($cmd eq "-v") { |
461 | $verbose = 1; | |
462 | } elsif (($cmd eq "-h") || ($cmd eq "--help")) { | |
463 | usage(); | |
4b44595a JB |
464 | } elsif ($cmd eq '-no-doc-sections') { |
465 | $no_doc_sections = 1; | |
e946c43a JB |
466 | } elsif ($cmd eq '-show-not-found') { |
467 | $show_not_found = 1; | |
1da177e4 LT |
468 | } |
469 | } | |
470 | ||
8484baaa RD |
471 | # continue execution near EOF; |
472 | ||
53f049fa BP |
473 | # get kernel version from env |
474 | sub get_kernel_version() { | |
1b9bc22d | 475 | my $version = 'unknown kernel version'; |
53f049fa BP |
476 | |
477 | if (defined($ENV{'KERNELVERSION'})) { | |
478 | $version = $ENV{'KERNELVERSION'}; | |
479 | } | |
480 | return $version; | |
481 | } | |
1da177e4 LT |
482 | |
483 | ## | |
484 | # dumps section contents to arrays/hashes intended for that purpose. | |
485 | # | |
486 | sub dump_section { | |
94dc7ad5 | 487 | my $file = shift; |
1da177e4 LT |
488 | my $name = shift; |
489 | my $contents = join "\n", @_; | |
490 | ||
491 | if ($name =~ m/$type_constant/) { | |
492 | $name = $1; | |
493 | # print STDERR "constant section '$1' = '$contents'\n"; | |
494 | $constants{$name} = $contents; | |
495 | } elsif ($name =~ m/$type_param/) { | |
496 | # print STDERR "parameter def '$1' = '$contents'\n"; | |
497 | $name = $1; | |
498 | $parameterdescs{$name} = $contents; | |
a1d94aa5 | 499 | $sectcheck = $sectcheck . $name . " "; |
ced69090 RD |
500 | } elsif ($name eq "@\.\.\.") { |
501 | # print STDERR "parameter def '...' = '$contents'\n"; | |
502 | $name = "..."; | |
503 | $parameterdescs{$name} = $contents; | |
a1d94aa5 | 504 | $sectcheck = $sectcheck . $name . " "; |
1da177e4 LT |
505 | } else { |
506 | # print STDERR "other section '$name' = '$contents'\n"; | |
94dc7ad5 | 507 | if (defined($sections{$name}) && ($sections{$name} ne "")) { |
d40e1e65 | 508 | print STDERR "${file}:$.: error: duplicate section name '$name'\n"; |
94dc7ad5 RD |
509 | ++$errors; |
510 | } | |
1da177e4 LT |
511 | $sections{$name} = $contents; |
512 | push @sectionlist, $name; | |
513 | } | |
514 | } | |
515 | ||
b112e0f7 JB |
516 | ## |
517 | # dump DOC: section after checking that it should go out | |
518 | # | |
519 | sub dump_doc_section { | |
94dc7ad5 | 520 | my $file = shift; |
b112e0f7 JB |
521 | my $name = shift; |
522 | my $contents = join "\n", @_; | |
523 | ||
4b44595a JB |
524 | if ($no_doc_sections) { |
525 | return; | |
526 | } | |
527 | ||
b112e0f7 JB |
528 | if (($function_only == 0) || |
529 | ( $function_only == 1 && defined($function_table{$name})) || | |
530 | ( $function_only == 2 && !defined($function_table{$name}))) | |
531 | { | |
94dc7ad5 | 532 | dump_section($file, $name, $contents); |
b112e0f7 JB |
533 | output_blockhead({'sectionlist' => \@sectionlist, |
534 | 'sections' => \%sections, | |
535 | 'module' => $modulename, | |
536 | 'content-only' => ($function_only != 0), }); | |
537 | } | |
538 | } | |
539 | ||
1da177e4 LT |
540 | ## |
541 | # output function | |
542 | # | |
543 | # parameterdescs, a hash. | |
544 | # function => "function name" | |
545 | # parameterlist => @list of parameters | |
546 | # parameterdescs => %parameter descriptions | |
547 | # sectionlist => @list of sections | |
a21217da | 548 | # sections => %section descriptions |
3c3b809e | 549 | # |
1da177e4 LT |
550 | |
551 | sub output_highlight { | |
552 | my $contents = join "\n",@_; | |
553 | my $line; | |
554 | ||
555 | # DEBUG | |
556 | # if (!defined $contents) { | |
557 | # use Carp; | |
558 | # confess "output_highlight got called with no args?\n"; | |
559 | # } | |
560 | ||
1b40c194 DL |
561 | if ($output_mode eq "html" || $output_mode eq "html5" || |
562 | $output_mode eq "xml") { | |
6b5b55f6 RD |
563 | $contents = local_unescape($contents); |
564 | # convert data read & converted thru xml_escape() into &xyz; format: | |
2b35f4d9 | 565 | $contents =~ s/\\\\\\/\&/g; |
6b5b55f6 | 566 | } |
3eb014a1 | 567 | # print STDERR "contents b4:$contents\n"; |
1da177e4 LT |
568 | eval $dohighlight; |
569 | die $@ if $@; | |
3eb014a1 RD |
570 | # print STDERR "contents af:$contents\n"; |
571 | ||
1b40c194 DL |
572 | # strip whitespaces when generating html5 |
573 | if ($output_mode eq "html5") { | |
574 | $contents =~ s/^\s+//; | |
575 | $contents =~ s/\s+$//; | |
576 | } | |
1da177e4 | 577 | foreach $line (split "\n", $contents) { |
12ae6779 DS |
578 | if (! $output_preformatted) { |
579 | $line =~ s/^\s*//; | |
580 | } | |
3c308798 | 581 | if ($line eq ""){ |
e314ba31 DS |
582 | if (! $output_preformatted) { |
583 | print $lineprefix, local_unescape($blankline); | |
584 | } | |
1da177e4 | 585 | } else { |
3c308798 | 586 | $line =~ s/\\\\\\/\&/g; |
cdccb316 RD |
587 | if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { |
588 | print "\\&$line"; | |
589 | } else { | |
590 | print $lineprefix, $line; | |
591 | } | |
1da177e4 LT |
592 | } |
593 | print "\n"; | |
594 | } | |
595 | } | |
596 | ||
1b40c194 | 597 | # output sections in html |
1da177e4 LT |
598 | sub output_section_html(%) { |
599 | my %args = %{$_[0]}; | |
600 | my $section; | |
601 | ||
602 | foreach $section (@{$args{'sectionlist'}}) { | |
603 | print "<h3>$section</h3>\n"; | |
604 | print "<blockquote>\n"; | |
605 | output_highlight($args{'sections'}{$section}); | |
606 | print "</blockquote>\n"; | |
3c3b809e | 607 | } |
1da177e4 LT |
608 | } |
609 | ||
610 | # output enum in html | |
611 | sub output_enum_html(%) { | |
612 | my %args = %{$_[0]}; | |
613 | my ($parameter); | |
614 | my $count; | |
b9d97328 | 615 | print "<h2>enum " . $args{'enum'} . "</h2>\n"; |
1da177e4 | 616 | |
b9d97328 | 617 | print "<b>enum " . $args{'enum'} . "</b> {<br>\n"; |
1da177e4 LT |
618 | $count = 0; |
619 | foreach $parameter (@{$args{'parameterlist'}}) { | |
b9d97328 | 620 | print " <b>" . $parameter . "</b>"; |
1da177e4 LT |
621 | if ($count != $#{$args{'parameterlist'}}) { |
622 | $count++; | |
623 | print ",\n"; | |
624 | } | |
625 | print "<br>"; | |
626 | } | |
627 | print "};<br>\n"; | |
628 | ||
629 | print "<h3>Constants</h3>\n"; | |
630 | print "<dl>\n"; | |
631 | foreach $parameter (@{$args{'parameterlist'}}) { | |
b9d97328 | 632 | print "<dt><b>" . $parameter . "</b>\n"; |
1da177e4 LT |
633 | print "<dd>"; |
634 | output_highlight($args{'parameterdescs'}{$parameter}); | |
635 | } | |
636 | print "</dl>\n"; | |
637 | output_section_html(@_); | |
638 | print "<hr>\n"; | |
639 | } | |
640 | ||
d28bee0c | 641 | # output typedef in html |
1da177e4 LT |
642 | sub output_typedef_html(%) { |
643 | my %args = %{$_[0]}; | |
644 | my ($parameter); | |
645 | my $count; | |
b9d97328 | 646 | print "<h2>typedef " . $args{'typedef'} . "</h2>\n"; |
1da177e4 | 647 | |
b9d97328 | 648 | print "<b>typedef " . $args{'typedef'} . "</b>\n"; |
1da177e4 LT |
649 | output_section_html(@_); |
650 | print "<hr>\n"; | |
651 | } | |
652 | ||
653 | # output struct in html | |
654 | sub output_struct_html(%) { | |
655 | my %args = %{$_[0]}; | |
656 | my ($parameter); | |
657 | ||
b9d97328 RD |
658 | print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n"; |
659 | print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n"; | |
1da177e4 LT |
660 | foreach $parameter (@{$args{'parameterlist'}}) { |
661 | if ($parameter =~ /^#/) { | |
662 | print "$parameter<br>\n"; | |
663 | next; | |
664 | } | |
665 | my $parameter_name = $parameter; | |
666 | $parameter_name =~ s/\[.*//; | |
667 | ||
3c308798 | 668 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
1da177e4 LT |
669 | $type = $args{'parametertypes'}{$parameter}; |
670 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { | |
671 | # pointer-to-function | |
3eb014a1 | 672 | print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n"; |
1da177e4 | 673 | } elsif ($type =~ m/^(.*?)\s*(:.*)/) { |
3eb014a1 RD |
674 | # bitfield |
675 | print " <i>$1</i> <b>$parameter</b>$2;<br>\n"; | |
1da177e4 | 676 | } else { |
3eb014a1 | 677 | print " <i>$type</i> <b>$parameter</b>;<br>\n"; |
1da177e4 LT |
678 | } |
679 | } | |
680 | print "};<br>\n"; | |
681 | ||
682 | print "<h3>Members</h3>\n"; | |
683 | print "<dl>\n"; | |
684 | foreach $parameter (@{$args{'parameterlist'}}) { | |
685 | ($parameter =~ /^#/) && next; | |
686 | ||
687 | my $parameter_name = $parameter; | |
688 | $parameter_name =~ s/\[.*//; | |
689 | ||
3c308798 | 690 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
b9d97328 | 691 | print "<dt><b>" . $parameter . "</b>\n"; |
1da177e4 LT |
692 | print "<dd>"; |
693 | output_highlight($args{'parameterdescs'}{$parameter_name}); | |
694 | } | |
695 | print "</dl>\n"; | |
696 | output_section_html(@_); | |
697 | print "<hr>\n"; | |
698 | } | |
699 | ||
700 | # output function in html | |
701 | sub output_function_html(%) { | |
702 | my %args = %{$_[0]}; | |
703 | my ($parameter, $section); | |
704 | my $count; | |
1da177e4 | 705 | |
b9d97328 RD |
706 | print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n"; |
707 | print "<i>" . $args{'functiontype'} . "</i>\n"; | |
708 | print "<b>" . $args{'function'} . "</b>\n"; | |
1da177e4 LT |
709 | print "("; |
710 | $count = 0; | |
711 | foreach $parameter (@{$args{'parameterlist'}}) { | |
712 | $type = $args{'parametertypes'}{$parameter}; | |
713 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { | |
714 | # pointer-to-function | |
715 | print "<i>$1</i><b>$parameter</b>) <i>($2)</i>"; | |
716 | } else { | |
b9d97328 | 717 | print "<i>" . $type . "</i> <b>" . $parameter . "</b>"; |
1da177e4 LT |
718 | } |
719 | if ($count != $#{$args{'parameterlist'}}) { | |
720 | $count++; | |
721 | print ",\n"; | |
722 | } | |
723 | } | |
724 | print ")\n"; | |
725 | ||
726 | print "<h3>Arguments</h3>\n"; | |
727 | print "<dl>\n"; | |
728 | foreach $parameter (@{$args{'parameterlist'}}) { | |
729 | my $parameter_name = $parameter; | |
730 | $parameter_name =~ s/\[.*//; | |
731 | ||
3c308798 | 732 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
b9d97328 | 733 | print "<dt><b>" . $parameter . "</b>\n"; |
1da177e4 LT |
734 | print "<dd>"; |
735 | output_highlight($args{'parameterdescs'}{$parameter_name}); | |
736 | } | |
737 | print "</dl>\n"; | |
738 | output_section_html(@_); | |
739 | print "<hr>\n"; | |
740 | } | |
741 | ||
b112e0f7 JB |
742 | # output DOC: block header in html |
743 | sub output_blockhead_html(%) { | |
1da177e4 LT |
744 | my %args = %{$_[0]}; |
745 | my ($parameter, $section); | |
746 | my $count; | |
747 | ||
748 | foreach $section (@{$args{'sectionlist'}}) { | |
749 | print "<h3>$section</h3>\n"; | |
750 | print "<ul>\n"; | |
751 | output_highlight($args{'sections'}{$section}); | |
752 | print "</ul>\n"; | |
753 | } | |
754 | print "<hr>\n"; | |
755 | } | |
756 | ||
1b40c194 DL |
757 | # output sections in html5 |
758 | sub output_section_html5(%) { | |
759 | my %args = %{$_[0]}; | |
760 | my $section; | |
761 | ||
762 | foreach $section (@{$args{'sectionlist'}}) { | |
763 | print "<section>\n"; | |
764 | print "<h1>$section</h1>\n"; | |
765 | print "<p>\n"; | |
766 | output_highlight($args{'sections'}{$section}); | |
767 | print "</p>\n"; | |
768 | print "</section>\n"; | |
769 | } | |
770 | } | |
771 | ||
772 | # output enum in html5 | |
773 | sub output_enum_html5(%) { | |
774 | my %args = %{$_[0]}; | |
775 | my ($parameter); | |
776 | my $count; | |
777 | my $html5id; | |
778 | ||
779 | $html5id = $args{'enum'}; | |
780 | $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; | |
781 | print "<article class=\"enum\" id=\"enum:". $html5id . "\">"; | |
782 | print "<h1>enum " . $args{'enum'} . "</h1>\n"; | |
783 | print "<ol class=\"code\">\n"; | |
784 | print "<li>"; | |
785 | print "<span class=\"keyword\">enum</span> "; | |
786 | print "<span class=\"identifier\">" . $args{'enum'} . "</span> {"; | |
787 | print "</li>\n"; | |
788 | $count = 0; | |
789 | foreach $parameter (@{$args{'parameterlist'}}) { | |
790 | print "<li class=\"indent\">"; | |
791 | print "<span class=\"param\">" . $parameter . "</span>"; | |
792 | if ($count != $#{$args{'parameterlist'}}) { | |
793 | $count++; | |
794 | print ","; | |
795 | } | |
796 | print "</li>\n"; | |
797 | } | |
798 | print "<li>};</li>\n"; | |
799 | print "</ol>\n"; | |
800 | ||
801 | print "<section>\n"; | |
802 | print "<h1>Constants</h1>\n"; | |
803 | print "<dl>\n"; | |
804 | foreach $parameter (@{$args{'parameterlist'}}) { | |
805 | print "<dt>" . $parameter . "</dt>\n"; | |
806 | print "<dd>"; | |
807 | output_highlight($args{'parameterdescs'}{$parameter}); | |
808 | print "</dd>\n"; | |
809 | } | |
810 | print "</dl>\n"; | |
811 | print "</section>\n"; | |
812 | output_section_html5(@_); | |
813 | print "</article>\n"; | |
814 | } | |
815 | ||
816 | # output typedef in html5 | |
817 | sub output_typedef_html5(%) { | |
818 | my %args = %{$_[0]}; | |
819 | my ($parameter); | |
820 | my $count; | |
821 | my $html5id; | |
822 | ||
823 | $html5id = $args{'typedef'}; | |
824 | $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; | |
825 | print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n"; | |
826 | print "<h1>typedef " . $args{'typedef'} . "</h1>\n"; | |
827 | ||
828 | print "<ol class=\"code\">\n"; | |
829 | print "<li>"; | |
830 | print "<span class=\"keyword\">typedef</span> "; | |
831 | print "<span class=\"identifier\">" . $args{'typedef'} . "</span>"; | |
832 | print "</li>\n"; | |
833 | print "</ol>\n"; | |
834 | output_section_html5(@_); | |
835 | print "</article>\n"; | |
836 | } | |
837 | ||
838 | # output struct in html5 | |
839 | sub output_struct_html5(%) { | |
840 | my %args = %{$_[0]}; | |
841 | my ($parameter); | |
842 | my $html5id; | |
843 | ||
844 | $html5id = $args{'struct'}; | |
845 | $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; | |
846 | print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n"; | |
847 | print "<hgroup>\n"; | |
848 | print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>"; | |
849 | print "<h2>". $args{'purpose'} . "</h2>\n"; | |
850 | print "</hgroup>\n"; | |
851 | print "<ol class=\"code\">\n"; | |
852 | print "<li>"; | |
853 | print "<span class=\"type\">" . $args{'type'} . "</span> "; | |
854 | print "<span class=\"identifier\">" . $args{'struct'} . "</span> {"; | |
855 | print "</li>\n"; | |
856 | foreach $parameter (@{$args{'parameterlist'}}) { | |
857 | print "<li class=\"indent\">"; | |
858 | if ($parameter =~ /^#/) { | |
859 | print "<span class=\"param\">" . $parameter ."</span>\n"; | |
860 | print "</li>\n"; | |
861 | next; | |
862 | } | |
863 | my $parameter_name = $parameter; | |
864 | $parameter_name =~ s/\[.*//; | |
865 | ||
866 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; | |
867 | $type = $args{'parametertypes'}{$parameter}; | |
868 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { | |
869 | # pointer-to-function | |
870 | print "<span class=\"type\">$1</span> "; | |
871 | print "<span class=\"param\">$parameter</span>"; | |
872 | print "<span class=\"type\">)</span> "; | |
873 | print "(<span class=\"args\">$2</span>);"; | |
874 | } elsif ($type =~ m/^(.*?)\s*(:.*)/) { | |
875 | # bitfield | |
876 | print "<span class=\"type\">$1</span> "; | |
877 | print "<span class=\"param\">$parameter</span>"; | |
878 | print "<span class=\"bits\">$2</span>;"; | |
879 | } else { | |
880 | print "<span class=\"type\">$type</span> "; | |
881 | print "<span class=\"param\">$parameter</span>;"; | |
882 | } | |
883 | print "</li>\n"; | |
884 | } | |
885 | print "<li>};</li>\n"; | |
886 | print "</ol>\n"; | |
887 | ||
888 | print "<section>\n"; | |
889 | print "<h1>Members</h1>\n"; | |
890 | print "<dl>\n"; | |
891 | foreach $parameter (@{$args{'parameterlist'}}) { | |
892 | ($parameter =~ /^#/) && next; | |
893 | ||
894 | my $parameter_name = $parameter; | |
895 | $parameter_name =~ s/\[.*//; | |
896 | ||
897 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; | |
898 | print "<dt>" . $parameter . "</dt>\n"; | |
899 | print "<dd>"; | |
900 | output_highlight($args{'parameterdescs'}{$parameter_name}); | |
901 | print "</dd>\n"; | |
902 | } | |
903 | print "</dl>\n"; | |
904 | print "</section>\n"; | |
905 | output_section_html5(@_); | |
906 | print "</article>\n"; | |
907 | } | |
908 | ||
909 | # output function in html5 | |
910 | sub output_function_html5(%) { | |
911 | my %args = %{$_[0]}; | |
912 | my ($parameter, $section); | |
913 | my $count; | |
914 | my $html5id; | |
915 | ||
916 | $html5id = $args{'function'}; | |
917 | $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; | |
918 | print "<article class=\"function\" id=\"func:". $html5id . "\">\n"; | |
919 | print "<hgroup>\n"; | |
920 | print "<h1>" . $args{'function'} . "</h1>"; | |
921 | print "<h2>" . $args{'purpose'} . "</h2>\n"; | |
922 | print "</hgroup>\n"; | |
923 | print "<ol class=\"code\">\n"; | |
924 | print "<li>"; | |
925 | print "<span class=\"type\">" . $args{'functiontype'} . "</span> "; | |
926 | print "<span class=\"identifier\">" . $args{'function'} . "</span> ("; | |
927 | print "</li>"; | |
928 | $count = 0; | |
929 | foreach $parameter (@{$args{'parameterlist'}}) { | |
930 | print "<li class=\"indent\">"; | |
931 | $type = $args{'parametertypes'}{$parameter}; | |
932 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { | |
933 | # pointer-to-function | |
934 | print "<span class=\"type\">$1</span> "; | |
935 | print "<span class=\"param\">$parameter</span>"; | |
936 | print "<span class=\"type\">)</span> "; | |
937 | print "(<span class=\"args\">$2</span>)"; | |
938 | } else { | |
939 | print "<span class=\"type\">$type</span> "; | |
940 | print "<span class=\"param\">$parameter</span>"; | |
941 | } | |
942 | if ($count != $#{$args{'parameterlist'}}) { | |
943 | $count++; | |
944 | print ","; | |
945 | } | |
946 | print "</li>\n"; | |
947 | } | |
948 | print "<li>)</li>\n"; | |
949 | print "</ol>\n"; | |
950 | ||
951 | print "<section>\n"; | |
952 | print "<h1>Arguments</h1>\n"; | |
953 | print "<p>\n"; | |
954 | print "<dl>\n"; | |
955 | foreach $parameter (@{$args{'parameterlist'}}) { | |
956 | my $parameter_name = $parameter; | |
957 | $parameter_name =~ s/\[.*//; | |
958 | ||
959 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; | |
960 | print "<dt>" . $parameter . "</dt>\n"; | |
961 | print "<dd>"; | |
962 | output_highlight($args{'parameterdescs'}{$parameter_name}); | |
963 | print "</dd>\n"; | |
964 | } | |
965 | print "</dl>\n"; | |
966 | print "</section>\n"; | |
967 | output_section_html5(@_); | |
968 | print "</article>\n"; | |
969 | } | |
970 | ||
971 | # output DOC: block header in html5 | |
972 | sub output_blockhead_html5(%) { | |
973 | my %args = %{$_[0]}; | |
974 | my ($parameter, $section); | |
975 | my $count; | |
976 | my $html5id; | |
977 | ||
978 | foreach $section (@{$args{'sectionlist'}}) { | |
979 | $html5id = $section; | |
980 | $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; | |
981 | print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n"; | |
982 | print "<h1>$section</h1>\n"; | |
983 | print "<p>\n"; | |
984 | output_highlight($args{'sections'}{$section}); | |
985 | print "</p>\n"; | |
986 | } | |
987 | print "</article>\n"; | |
988 | } | |
989 | ||
1da177e4 LT |
990 | sub output_section_xml(%) { |
991 | my %args = %{$_[0]}; | |
3c3b809e | 992 | my $section; |
1da177e4 LT |
993 | # print out each section |
994 | $lineprefix=" "; | |
995 | foreach $section (@{$args{'sectionlist'}}) { | |
c73894c1 RW |
996 | print "<refsect1>\n"; |
997 | print "<title>$section</title>\n"; | |
1da177e4 | 998 | if ($section =~ m/EXAMPLE/i) { |
c73894c1 | 999 | print "<informalexample><programlisting>\n"; |
e314ba31 | 1000 | $output_preformatted = 1; |
c73894c1 RW |
1001 | } else { |
1002 | print "<para>\n"; | |
1da177e4 LT |
1003 | } |
1004 | output_highlight($args{'sections'}{$section}); | |
e314ba31 | 1005 | $output_preformatted = 0; |
1da177e4 | 1006 | if ($section =~ m/EXAMPLE/i) { |
c73894c1 RW |
1007 | print "</programlisting></informalexample>\n"; |
1008 | } else { | |
1009 | print "</para>\n"; | |
1da177e4 | 1010 | } |
c73894c1 | 1011 | print "</refsect1>\n"; |
1da177e4 LT |
1012 | } |
1013 | } | |
1014 | ||
1015 | # output function in XML DocBook | |
1016 | sub output_function_xml(%) { | |
1017 | my %args = %{$_[0]}; | |
1018 | my ($parameter, $section); | |
1019 | my $count; | |
1020 | my $id; | |
1021 | ||
b9d97328 | 1022 | $id = "API-" . $args{'function'}; |
1da177e4 LT |
1023 | $id =~ s/[^A-Za-z0-9]/-/g; |
1024 | ||
5449bc94 | 1025 | print "<refentry id=\"$id\">\n"; |
8b0c2d98 MW |
1026 | print "<refentryinfo>\n"; |
1027 | print " <title>LINUX</title>\n"; | |
1028 | print " <productname>Kernel Hackers Manual</productname>\n"; | |
1029 | print " <date>$man_date</date>\n"; | |
1030 | print "</refentryinfo>\n"; | |
1da177e4 | 1031 | print "<refmeta>\n"; |
b9d97328 | 1032 | print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n"; |
8b0c2d98 | 1033 | print " <manvolnum>9</manvolnum>\n"; |
0366299b | 1034 | print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; |
1da177e4 LT |
1035 | print "</refmeta>\n"; |
1036 | print "<refnamediv>\n"; | |
b9d97328 | 1037 | print " <refname>" . $args{'function'} . "</refname>\n"; |
1da177e4 LT |
1038 | print " <refpurpose>\n"; |
1039 | print " "; | |
1040 | output_highlight ($args{'purpose'}); | |
1041 | print " </refpurpose>\n"; | |
1042 | print "</refnamediv>\n"; | |
1043 | ||
1044 | print "<refsynopsisdiv>\n"; | |
1045 | print " <title>Synopsis</title>\n"; | |
1046 | print " <funcsynopsis><funcprototype>\n"; | |
b9d97328 RD |
1047 | print " <funcdef>" . $args{'functiontype'} . " "; |
1048 | print "<function>" . $args{'function'} . " </function></funcdef>\n"; | |
1da177e4 LT |
1049 | |
1050 | $count = 0; | |
1051 | if ($#{$args{'parameterlist'}} >= 0) { | |
1052 | foreach $parameter (@{$args{'parameterlist'}}) { | |
1053 | $type = $args{'parametertypes'}{$parameter}; | |
1054 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { | |
1055 | # pointer-to-function | |
1056 | print " <paramdef>$1<parameter>$parameter</parameter>)\n"; | |
1057 | print " <funcparams>$2</funcparams></paramdef>\n"; | |
1058 | } else { | |
b9d97328 | 1059 | print " <paramdef>" . $type; |
1da177e4 LT |
1060 | print " <parameter>$parameter</parameter></paramdef>\n"; |
1061 | } | |
1062 | } | |
1063 | } else { | |
6013d544 | 1064 | print " <void/>\n"; |
1da177e4 LT |
1065 | } |
1066 | print " </funcprototype></funcsynopsis>\n"; | |
1067 | print "</refsynopsisdiv>\n"; | |
1068 | ||
1069 | # print parameters | |
1070 | print "<refsect1>\n <title>Arguments</title>\n"; | |
1071 | if ($#{$args{'parameterlist'}} >= 0) { | |
1072 | print " <variablelist>\n"; | |
1073 | foreach $parameter (@{$args{'parameterlist'}}) { | |
1074 | my $parameter_name = $parameter; | |
1075 | $parameter_name =~ s/\[.*//; | |
1076 | ||
1077 | print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n"; | |
1078 | print " <listitem>\n <para>\n"; | |
1079 | $lineprefix=" "; | |
1080 | output_highlight($args{'parameterdescs'}{$parameter_name}); | |
1081 | print " </para>\n </listitem>\n </varlistentry>\n"; | |
1082 | } | |
1083 | print " </variablelist>\n"; | |
1084 | } else { | |
1085 | print " <para>\n None\n </para>\n"; | |
1086 | } | |
1087 | print "</refsect1>\n"; | |
1088 | ||
1089 | output_section_xml(@_); | |
1090 | print "</refentry>\n\n"; | |
1091 | } | |
1092 | ||
1093 | # output struct in XML DocBook | |
1094 | sub output_struct_xml(%) { | |
1095 | my %args = %{$_[0]}; | |
1096 | my ($parameter, $section); | |
1097 | my $id; | |
1098 | ||
b9d97328 | 1099 | $id = "API-struct-" . $args{'struct'}; |
1da177e4 LT |
1100 | $id =~ s/[^A-Za-z0-9]/-/g; |
1101 | ||
5449bc94 | 1102 | print "<refentry id=\"$id\">\n"; |
8b0c2d98 MW |
1103 | print "<refentryinfo>\n"; |
1104 | print " <title>LINUX</title>\n"; | |
1105 | print " <productname>Kernel Hackers Manual</productname>\n"; | |
1106 | print " <date>$man_date</date>\n"; | |
1107 | print "</refentryinfo>\n"; | |
1da177e4 | 1108 | print "<refmeta>\n"; |
b9d97328 | 1109 | print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n"; |
8b0c2d98 | 1110 | print " <manvolnum>9</manvolnum>\n"; |
0366299b | 1111 | print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; |
1da177e4 LT |
1112 | print "</refmeta>\n"; |
1113 | print "<refnamediv>\n"; | |
b9d97328 | 1114 | print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n"; |
1da177e4 LT |
1115 | print " <refpurpose>\n"; |
1116 | print " "; | |
1117 | output_highlight ($args{'purpose'}); | |
1118 | print " </refpurpose>\n"; | |
1119 | print "</refnamediv>\n"; | |
1120 | ||
1121 | print "<refsynopsisdiv>\n"; | |
1122 | print " <title>Synopsis</title>\n"; | |
1123 | print " <programlisting>\n"; | |
b9d97328 | 1124 | print $args{'type'} . " " . $args{'struct'} . " {\n"; |
1da177e4 LT |
1125 | foreach $parameter (@{$args{'parameterlist'}}) { |
1126 | if ($parameter =~ /^#/) { | |
2b35f4d9 RD |
1127 | my $prm = $parameter; |
1128 | # convert data read & converted thru xml_escape() into &xyz; format: | |
1129 | # This allows us to have #define macros interspersed in a struct. | |
1130 | $prm =~ s/\\\\\\/\&/g; | |
1131 | print "$prm\n"; | |
1da177e4 LT |
1132 | next; |
1133 | } | |
1134 | ||
1135 | my $parameter_name = $parameter; | |
1136 | $parameter_name =~ s/\[.*//; | |
1137 | ||
1138 | defined($args{'parameterdescs'}{$parameter_name}) || next; | |
3c308798 | 1139 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
1da177e4 LT |
1140 | $type = $args{'parametertypes'}{$parameter}; |
1141 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { | |
1142 | # pointer-to-function | |
1143 | print " $1 $parameter) ($2);\n"; | |
1144 | } elsif ($type =~ m/^(.*?)\s*(:.*)/) { | |
51f5a0c8 | 1145 | # bitfield |
1da177e4 LT |
1146 | print " $1 $parameter$2;\n"; |
1147 | } else { | |
b9d97328 | 1148 | print " " . $type . " " . $parameter . ";\n"; |
1da177e4 LT |
1149 | } |
1150 | } | |
1151 | print "};"; | |
1152 | print " </programlisting>\n"; | |
1153 | print "</refsynopsisdiv>\n"; | |
1154 | ||
1155 | print " <refsect1>\n"; | |
1156 | print " <title>Members</title>\n"; | |
1157 | ||
39f00c08 | 1158 | if ($#{$args{'parameterlist'}} >= 0) { |
1da177e4 LT |
1159 | print " <variablelist>\n"; |
1160 | foreach $parameter (@{$args{'parameterlist'}}) { | |
1161 | ($parameter =~ /^#/) && next; | |
1162 | ||
1163 | my $parameter_name = $parameter; | |
1164 | $parameter_name =~ s/\[.*//; | |
1165 | ||
1166 | defined($args{'parameterdescs'}{$parameter_name}) || next; | |
1167 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; | |
1168 | print " <varlistentry>"; | |
1169 | print " <term>$parameter</term>\n"; | |
1170 | print " <listitem><para>\n"; | |
1171 | output_highlight($args{'parameterdescs'}{$parameter_name}); | |
1172 | print " </para></listitem>\n"; | |
1173 | print " </varlistentry>\n"; | |
1174 | } | |
1175 | print " </variablelist>\n"; | |
39f00c08 RD |
1176 | } else { |
1177 | print " <para>\n None\n </para>\n"; | |
1178 | } | |
1da177e4 LT |
1179 | print " </refsect1>\n"; |
1180 | ||
1181 | output_section_xml(@_); | |
1182 | ||
1183 | print "</refentry>\n\n"; | |
1184 | } | |
1185 | ||
1186 | # output enum in XML DocBook | |
1187 | sub output_enum_xml(%) { | |
1188 | my %args = %{$_[0]}; | |
1189 | my ($parameter, $section); | |
1190 | my $count; | |
1191 | my $id; | |
1192 | ||
b9d97328 | 1193 | $id = "API-enum-" . $args{'enum'}; |
1da177e4 LT |
1194 | $id =~ s/[^A-Za-z0-9]/-/g; |
1195 | ||
5449bc94 | 1196 | print "<refentry id=\"$id\">\n"; |
8b0c2d98 MW |
1197 | print "<refentryinfo>\n"; |
1198 | print " <title>LINUX</title>\n"; | |
1199 | print " <productname>Kernel Hackers Manual</productname>\n"; | |
1200 | print " <date>$man_date</date>\n"; | |
1201 | print "</refentryinfo>\n"; | |
1da177e4 | 1202 | print "<refmeta>\n"; |
b9d97328 | 1203 | print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n"; |
8b0c2d98 | 1204 | print " <manvolnum>9</manvolnum>\n"; |
0366299b | 1205 | print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; |
1da177e4 LT |
1206 | print "</refmeta>\n"; |
1207 | print "<refnamediv>\n"; | |
b9d97328 | 1208 | print " <refname>enum " . $args{'enum'} . "</refname>\n"; |
1da177e4 LT |
1209 | print " <refpurpose>\n"; |
1210 | print " "; | |
1211 | output_highlight ($args{'purpose'}); | |
1212 | print " </refpurpose>\n"; | |
1213 | print "</refnamediv>\n"; | |
1214 | ||
1215 | print "<refsynopsisdiv>\n"; | |
1216 | print " <title>Synopsis</title>\n"; | |
1217 | print " <programlisting>\n"; | |
b9d97328 | 1218 | print "enum " . $args{'enum'} . " {\n"; |
1da177e4 LT |
1219 | $count = 0; |
1220 | foreach $parameter (@{$args{'parameterlist'}}) { | |
3c308798 RD |
1221 | print " $parameter"; |
1222 | if ($count != $#{$args{'parameterlist'}}) { | |
1da177e4 LT |
1223 | $count++; |
1224 | print ","; | |
3c308798 | 1225 | } |
1da177e4 LT |
1226 | print "\n"; |
1227 | } | |
1228 | print "};"; | |
1229 | print " </programlisting>\n"; | |
1230 | print "</refsynopsisdiv>\n"; | |
1231 | ||
1232 | print "<refsect1>\n"; | |
3c3b809e | 1233 | print " <title>Constants</title>\n"; |
1da177e4 LT |
1234 | print " <variablelist>\n"; |
1235 | foreach $parameter (@{$args{'parameterlist'}}) { | |
1236 | my $parameter_name = $parameter; | |
1237 | $parameter_name =~ s/\[.*//; | |
1238 | ||
1239 | print " <varlistentry>"; | |
1240 | print " <term>$parameter</term>\n"; | |
1241 | print " <listitem><para>\n"; | |
1242 | output_highlight($args{'parameterdescs'}{$parameter_name}); | |
1243 | print " </para></listitem>\n"; | |
1244 | print " </varlistentry>\n"; | |
1245 | } | |
1246 | print " </variablelist>\n"; | |
1247 | print "</refsect1>\n"; | |
1248 | ||
1249 | output_section_xml(@_); | |
1250 | ||
1251 | print "</refentry>\n\n"; | |
1252 | } | |
1253 | ||
1254 | # output typedef in XML DocBook | |
1255 | sub output_typedef_xml(%) { | |
1256 | my %args = %{$_[0]}; | |
1257 | my ($parameter, $section); | |
1258 | my $id; | |
1259 | ||
b9d97328 | 1260 | $id = "API-typedef-" . $args{'typedef'}; |
1da177e4 LT |
1261 | $id =~ s/[^A-Za-z0-9]/-/g; |
1262 | ||
5449bc94 | 1263 | print "<refentry id=\"$id\">\n"; |
8b0c2d98 MW |
1264 | print "<refentryinfo>\n"; |
1265 | print " <title>LINUX</title>\n"; | |
1266 | print " <productname>Kernel Hackers Manual</productname>\n"; | |
1267 | print " <date>$man_date</date>\n"; | |
1268 | print "</refentryinfo>\n"; | |
1da177e4 | 1269 | print "<refmeta>\n"; |
b9d97328 | 1270 | print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n"; |
8b0c2d98 | 1271 | print " <manvolnum>9</manvolnum>\n"; |
1da177e4 LT |
1272 | print "</refmeta>\n"; |
1273 | print "<refnamediv>\n"; | |
b9d97328 | 1274 | print " <refname>typedef " . $args{'typedef'} . "</refname>\n"; |
1da177e4 LT |
1275 | print " <refpurpose>\n"; |
1276 | print " "; | |
1277 | output_highlight ($args{'purpose'}); | |
1278 | print " </refpurpose>\n"; | |
1279 | print "</refnamediv>\n"; | |
1280 | ||
1281 | print "<refsynopsisdiv>\n"; | |
1282 | print " <title>Synopsis</title>\n"; | |
b9d97328 | 1283 | print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n"; |
1da177e4 LT |
1284 | print "</refsynopsisdiv>\n"; |
1285 | ||
1286 | output_section_xml(@_); | |
1287 | ||
1288 | print "</refentry>\n\n"; | |
1289 | } | |
1290 | ||
1291 | # output in XML DocBook | |
b112e0f7 | 1292 | sub output_blockhead_xml(%) { |
1da177e4 LT |
1293 | my %args = %{$_[0]}; |
1294 | my ($parameter, $section); | |
1295 | my $count; | |
1296 | ||
1297 | my $id = $args{'module'}; | |
1298 | $id =~ s/[^A-Za-z0-9]/-/g; | |
1299 | ||
1300 | # print out each section | |
1301 | $lineprefix=" "; | |
1302 | foreach $section (@{$args{'sectionlist'}}) { | |
b112e0f7 JB |
1303 | if (!$args{'content-only'}) { |
1304 | print "<refsect1>\n <title>$section</title>\n"; | |
1305 | } | |
1da177e4 LT |
1306 | if ($section =~ m/EXAMPLE/i) { |
1307 | print "<example><para>\n"; | |
e314ba31 | 1308 | $output_preformatted = 1; |
b112e0f7 JB |
1309 | } else { |
1310 | print "<para>\n"; | |
1da177e4 LT |
1311 | } |
1312 | output_highlight($args{'sections'}{$section}); | |
e314ba31 | 1313 | $output_preformatted = 0; |
1da177e4 LT |
1314 | if ($section =~ m/EXAMPLE/i) { |
1315 | print "</para></example>\n"; | |
b112e0f7 JB |
1316 | } else { |
1317 | print "</para>"; | |
1318 | } | |
1319 | if (!$args{'content-only'}) { | |
1320 | print "\n</refsect1>\n"; | |
1da177e4 | 1321 | } |
1da177e4 LT |
1322 | } |
1323 | ||
1324 | print "\n\n"; | |
1325 | } | |
1326 | ||
1327 | # output in XML DocBook | |
1328 | sub output_function_gnome { | |
1329 | my %args = %{$_[0]}; | |
1330 | my ($parameter, $section); | |
1331 | my $count; | |
1332 | my $id; | |
1333 | ||
b9d97328 | 1334 | $id = $args{'module'} . "-" . $args{'function'}; |
1da177e4 LT |
1335 | $id =~ s/[^A-Za-z0-9]/-/g; |
1336 | ||
1337 | print "<sect2>\n"; | |
b9d97328 | 1338 | print " <title id=\"$id\">" . $args{'function'} . "</title>\n"; |
1da177e4 LT |
1339 | |
1340 | print " <funcsynopsis>\n"; | |
b9d97328 RD |
1341 | print " <funcdef>" . $args{'functiontype'} . " "; |
1342 | print "<function>" . $args{'function'} . " "; | |
1da177e4 LT |
1343 | print "</function></funcdef>\n"; |
1344 | ||
1345 | $count = 0; | |
1346 | if ($#{$args{'parameterlist'}} >= 0) { | |
1347 | foreach $parameter (@{$args{'parameterlist'}}) { | |
1348 | $type = $args{'parametertypes'}{$parameter}; | |
1349 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { | |
1350 | # pointer-to-function | |
1351 | print " <paramdef>$1 <parameter>$parameter</parameter>)\n"; | |
1352 | print " <funcparams>$2</funcparams></paramdef>\n"; | |
1353 | } else { | |
b9d97328 | 1354 | print " <paramdef>" . $type; |
1da177e4 LT |
1355 | print " <parameter>$parameter</parameter></paramdef>\n"; |
1356 | } | |
1357 | } | |
1358 | } else { | |
1359 | print " <void>\n"; | |
1360 | } | |
1361 | print " </funcsynopsis>\n"; | |
1362 | if ($#{$args{'parameterlist'}} >= 0) { | |
1363 | print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n"; | |
1364 | print "<tgroup cols=\"2\">\n"; | |
1365 | print "<colspec colwidth=\"2*\">\n"; | |
1366 | print "<colspec colwidth=\"8*\">\n"; | |
1367 | print "<tbody>\n"; | |
1368 | foreach $parameter (@{$args{'parameterlist'}}) { | |
1369 | my $parameter_name = $parameter; | |
1370 | $parameter_name =~ s/\[.*//; | |
1371 | ||
1372 | print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n"; | |
1373 | print " <entry>\n"; | |
1374 | $lineprefix=" "; | |
1375 | output_highlight($args{'parameterdescs'}{$parameter_name}); | |
1376 | print " </entry></row>\n"; | |
1377 | } | |
1378 | print " </tbody></tgroup></informaltable>\n"; | |
1379 | } else { | |
1380 | print " <para>\n None\n </para>\n"; | |
1381 | } | |
1382 | ||
1383 | # print out each section | |
1384 | $lineprefix=" "; | |
1385 | foreach $section (@{$args{'sectionlist'}}) { | |
1386 | print "<simplesect>\n <title>$section</title>\n"; | |
1387 | if ($section =~ m/EXAMPLE/i) { | |
1388 | print "<example><programlisting>\n"; | |
e314ba31 | 1389 | $output_preformatted = 1; |
1da177e4 LT |
1390 | } else { |
1391 | } | |
1392 | print "<para>\n"; | |
1393 | output_highlight($args{'sections'}{$section}); | |
e314ba31 | 1394 | $output_preformatted = 0; |
1da177e4 LT |
1395 | print "</para>\n"; |
1396 | if ($section =~ m/EXAMPLE/i) { | |
1397 | print "</programlisting></example>\n"; | |
1398 | } else { | |
1399 | } | |
1400 | print " </simplesect>\n"; | |
1401 | } | |
1402 | ||
1403 | print "</sect2>\n\n"; | |
1404 | } | |
1405 | ||
1406 | ## | |
1407 | # output function in man | |
1408 | sub output_function_man(%) { | |
1409 | my %args = %{$_[0]}; | |
1410 | my ($parameter, $section); | |
1411 | my $count; | |
1412 | ||
1413 | print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; | |
1414 | ||
1415 | print ".SH NAME\n"; | |
b9d97328 | 1416 | print $args{'function'} . " \\- " . $args{'purpose'} . "\n"; |
1da177e4 LT |
1417 | |
1418 | print ".SH SYNOPSIS\n"; | |
a21217da | 1419 | if ($args{'functiontype'} ne "") { |
b9d97328 | 1420 | print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n"; |
a21217da | 1421 | } else { |
b9d97328 | 1422 | print ".B \"" . $args{'function'} . "\n"; |
a21217da | 1423 | } |
1da177e4 LT |
1424 | $count = 0; |
1425 | my $parenth = "("; | |
1426 | my $post = ","; | |
1427 | foreach my $parameter (@{$args{'parameterlist'}}) { | |
1428 | if ($count == $#{$args{'parameterlist'}}) { | |
1429 | $post = ");"; | |
1430 | } | |
1431 | $type = $args{'parametertypes'}{$parameter}; | |
1432 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { | |
1433 | # pointer-to-function | |
b9d97328 | 1434 | print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n"; |
1da177e4 LT |
1435 | } else { |
1436 | $type =~ s/([^\*])$/$1 /; | |
b9d97328 | 1437 | print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n"; |
1da177e4 LT |
1438 | } |
1439 | $count++; | |
1440 | $parenth = ""; | |
1441 | } | |
1442 | ||
1443 | print ".SH ARGUMENTS\n"; | |
1444 | foreach $parameter (@{$args{'parameterlist'}}) { | |
1445 | my $parameter_name = $parameter; | |
1446 | $parameter_name =~ s/\[.*//; | |
1447 | ||
b9d97328 | 1448 | print ".IP \"" . $parameter . "\" 12\n"; |
1da177e4 LT |
1449 | output_highlight($args{'parameterdescs'}{$parameter_name}); |
1450 | } | |
1451 | foreach $section (@{$args{'sectionlist'}}) { | |
1452 | print ".SH \"", uc $section, "\"\n"; | |
1453 | output_highlight($args{'sections'}{$section}); | |
1454 | } | |
1455 | } | |
1456 | ||
1457 | ## | |
1458 | # output enum in man | |
1459 | sub output_enum_man(%) { | |
1460 | my %args = %{$_[0]}; | |
1461 | my ($parameter, $section); | |
1462 | my $count; | |
1463 | ||
1464 | print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n"; | |
1465 | ||
1466 | print ".SH NAME\n"; | |
b9d97328 | 1467 | print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n"; |
1da177e4 LT |
1468 | |
1469 | print ".SH SYNOPSIS\n"; | |
b9d97328 | 1470 | print "enum " . $args{'enum'} . " {\n"; |
1da177e4 LT |
1471 | $count = 0; |
1472 | foreach my $parameter (@{$args{'parameterlist'}}) { | |
3c308798 | 1473 | print ".br\n.BI \" $parameter\"\n"; |
1da177e4 LT |
1474 | if ($count == $#{$args{'parameterlist'}}) { |
1475 | print "\n};\n"; | |
1476 | last; | |
1477 | } | |
1478 | else { | |
1479 | print ", \n.br\n"; | |
1480 | } | |
1481 | $count++; | |
1482 | } | |
1483 | ||
1484 | print ".SH Constants\n"; | |
1485 | foreach $parameter (@{$args{'parameterlist'}}) { | |
1486 | my $parameter_name = $parameter; | |
1487 | $parameter_name =~ s/\[.*//; | |
1488 | ||
b9d97328 | 1489 | print ".IP \"" . $parameter . "\" 12\n"; |
1da177e4 LT |
1490 | output_highlight($args{'parameterdescs'}{$parameter_name}); |
1491 | } | |
1492 | foreach $section (@{$args{'sectionlist'}}) { | |
1493 | print ".SH \"$section\"\n"; | |
1494 | output_highlight($args{'sections'}{$section}); | |
1495 | } | |
1496 | } | |
1497 | ||
1498 | ## | |
1499 | # output struct in man | |
1500 | sub output_struct_man(%) { | |
1501 | my %args = %{$_[0]}; | |
1502 | my ($parameter, $section); | |
1503 | ||
b9d97328 | 1504 | print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n"; |
1da177e4 LT |
1505 | |
1506 | print ".SH NAME\n"; | |
b9d97328 | 1507 | print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n"; |
1da177e4 LT |
1508 | |
1509 | print ".SH SYNOPSIS\n"; | |
b9d97328 | 1510 | print $args{'type'} . " " . $args{'struct'} . " {\n.br\n"; |
1da177e4 LT |
1511 | |
1512 | foreach my $parameter (@{$args{'parameterlist'}}) { | |
1513 | if ($parameter =~ /^#/) { | |
1514 | print ".BI \"$parameter\"\n.br\n"; | |
1515 | next; | |
1516 | } | |
1517 | my $parameter_name = $parameter; | |
1518 | $parameter_name =~ s/\[.*//; | |
1519 | ||
3c308798 | 1520 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
1da177e4 LT |
1521 | $type = $args{'parametertypes'}{$parameter}; |
1522 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { | |
1523 | # pointer-to-function | |
b9d97328 | 1524 | print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n"; |
1da177e4 | 1525 | } elsif ($type =~ m/^(.*?)\s*(:.*)/) { |
1d7e1d45 | 1526 | # bitfield |
b9d97328 | 1527 | print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n"; |
1da177e4 LT |
1528 | } else { |
1529 | $type =~ s/([^\*])$/$1 /; | |
b9d97328 | 1530 | print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n"; |
1da177e4 LT |
1531 | } |
1532 | print "\n.br\n"; | |
1533 | } | |
1534 | print "};\n.br\n"; | |
1535 | ||
c51d3dac | 1536 | print ".SH Members\n"; |
1da177e4 LT |
1537 | foreach $parameter (@{$args{'parameterlist'}}) { |
1538 | ($parameter =~ /^#/) && next; | |
1539 | ||
1540 | my $parameter_name = $parameter; | |
1541 | $parameter_name =~ s/\[.*//; | |
1542 | ||
3c308798 | 1543 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
b9d97328 | 1544 | print ".IP \"" . $parameter . "\" 12\n"; |
1da177e4 LT |
1545 | output_highlight($args{'parameterdescs'}{$parameter_name}); |
1546 | } | |
1547 | foreach $section (@{$args{'sectionlist'}}) { | |
1548 | print ".SH \"$section\"\n"; | |
1549 | output_highlight($args{'sections'}{$section}); | |
1550 | } | |
1551 | } | |
1552 | ||
1553 | ## | |
1554 | # output typedef in man | |
1555 | sub output_typedef_man(%) { | |
1556 | my %args = %{$_[0]}; | |
1557 | my ($parameter, $section); | |
1558 | ||
1559 | print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n"; | |
1560 | ||
1561 | print ".SH NAME\n"; | |
b9d97328 | 1562 | print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n"; |
1da177e4 LT |
1563 | |
1564 | foreach $section (@{$args{'sectionlist'}}) { | |
1565 | print ".SH \"$section\"\n"; | |
1566 | output_highlight($args{'sections'}{$section}); | |
1567 | } | |
1568 | } | |
1569 | ||
b112e0f7 | 1570 | sub output_blockhead_man(%) { |
1da177e4 LT |
1571 | my %args = %{$_[0]}; |
1572 | my ($parameter, $section); | |
1573 | my $count; | |
1574 | ||
1575 | print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; | |
1576 | ||
1577 | foreach $section (@{$args{'sectionlist'}}) { | |
1578 | print ".SH \"$section\"\n"; | |
1579 | output_highlight($args{'sections'}{$section}); | |
1580 | } | |
1581 | } | |
1582 | ||
1583 | ## | |
1584 | # output in text | |
1585 | sub output_function_text(%) { | |
1586 | my %args = %{$_[0]}; | |
1587 | my ($parameter, $section); | |
a21217da | 1588 | my $start; |
1da177e4 | 1589 | |
f47634b2 | 1590 | print "Name:\n\n"; |
b9d97328 | 1591 | print $args{'function'} . " - " . $args{'purpose'} . "\n"; |
f47634b2 RD |
1592 | |
1593 | print "\nSynopsis:\n\n"; | |
a21217da | 1594 | if ($args{'functiontype'} ne "") { |
b9d97328 | 1595 | $start = $args{'functiontype'} . " " . $args{'function'} . " ("; |
a21217da | 1596 | } else { |
b9d97328 | 1597 | $start = $args{'function'} . " ("; |
a21217da | 1598 | } |
1da177e4 | 1599 | print $start; |
a21217da | 1600 | |
1da177e4 LT |
1601 | my $count = 0; |
1602 | foreach my $parameter (@{$args{'parameterlist'}}) { | |
1603 | $type = $args{'parametertypes'}{$parameter}; | |
1604 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { | |
1605 | # pointer-to-function | |
b9d97328 | 1606 | print $1 . $parameter . ") (" . $2; |
1da177e4 | 1607 | } else { |
b9d97328 | 1608 | print $type . " " . $parameter; |
1da177e4 LT |
1609 | } |
1610 | if ($count != $#{$args{'parameterlist'}}) { | |
1611 | $count++; | |
1612 | print ",\n"; | |
1613 | print " " x length($start); | |
1614 | } else { | |
1615 | print ");\n\n"; | |
1616 | } | |
1617 | } | |
1618 | ||
1619 | print "Arguments:\n\n"; | |
1620 | foreach $parameter (@{$args{'parameterlist'}}) { | |
1621 | my $parameter_name = $parameter; | |
1622 | $parameter_name =~ s/\[.*//; | |
1623 | ||
b9d97328 | 1624 | print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n"; |
1da177e4 LT |
1625 | } |
1626 | output_section_text(@_); | |
1627 | } | |
1628 | ||
1629 | #output sections in text | |
1630 | sub output_section_text(%) { | |
1631 | my %args = %{$_[0]}; | |
1632 | my $section; | |
1633 | ||
1634 | print "\n"; | |
1635 | foreach $section (@{$args{'sectionlist'}}) { | |
1636 | print "$section:\n\n"; | |
1637 | output_highlight($args{'sections'}{$section}); | |
3c3b809e | 1638 | } |
1da177e4 LT |
1639 | print "\n\n"; |
1640 | } | |
1641 | ||
1642 | # output enum in text | |
1643 | sub output_enum_text(%) { | |
1644 | my %args = %{$_[0]}; | |
1645 | my ($parameter); | |
1646 | my $count; | |
1647 | print "Enum:\n\n"; | |
1648 | ||
b9d97328 RD |
1649 | print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n"; |
1650 | print "enum " . $args{'enum'} . " {\n"; | |
1da177e4 LT |
1651 | $count = 0; |
1652 | foreach $parameter (@{$args{'parameterlist'}}) { | |
3c308798 | 1653 | print "\t$parameter"; |
1da177e4 LT |
1654 | if ($count != $#{$args{'parameterlist'}}) { |
1655 | $count++; | |
1656 | print ","; | |
1657 | } | |
1658 | print "\n"; | |
1659 | } | |
1660 | print "};\n\n"; | |
1661 | ||
1662 | print "Constants:\n\n"; | |
1663 | foreach $parameter (@{$args{'parameterlist'}}) { | |
1664 | print "$parameter\n\t"; | |
b9d97328 | 1665 | print $args{'parameterdescs'}{$parameter} . "\n"; |
1da177e4 LT |
1666 | } |
1667 | ||
1668 | output_section_text(@_); | |
1669 | } | |
1670 | ||
1671 | # output typedef in text | |
1672 | sub output_typedef_text(%) { | |
1673 | my %args = %{$_[0]}; | |
1674 | my ($parameter); | |
1675 | my $count; | |
1676 | print "Typedef:\n\n"; | |
1677 | ||
b9d97328 | 1678 | print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n"; |
1da177e4 LT |
1679 | output_section_text(@_); |
1680 | } | |
1681 | ||
1682 | # output struct as text | |
1683 | sub output_struct_text(%) { | |
1684 | my %args = %{$_[0]}; | |
1685 | my ($parameter); | |
1686 | ||
b9d97328 RD |
1687 | print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n"; |
1688 | print $args{'type'} . " " . $args{'struct'} . " {\n"; | |
1da177e4 LT |
1689 | foreach $parameter (@{$args{'parameterlist'}}) { |
1690 | if ($parameter =~ /^#/) { | |
1691 | print "$parameter\n"; | |
1692 | next; | |
1693 | } | |
1694 | ||
1695 | my $parameter_name = $parameter; | |
1696 | $parameter_name =~ s/\[.*//; | |
1697 | ||
3c308798 | 1698 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
1da177e4 LT |
1699 | $type = $args{'parametertypes'}{$parameter}; |
1700 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { | |
1701 | # pointer-to-function | |
1702 | print "\t$1 $parameter) ($2);\n"; | |
1703 | } elsif ($type =~ m/^(.*?)\s*(:.*)/) { | |
51f5a0c8 | 1704 | # bitfield |
1da177e4 LT |
1705 | print "\t$1 $parameter$2;\n"; |
1706 | } else { | |
b9d97328 | 1707 | print "\t" . $type . " " . $parameter . ";\n"; |
1da177e4 LT |
1708 | } |
1709 | } | |
1710 | print "};\n\n"; | |
1711 | ||
1712 | print "Members:\n\n"; | |
1713 | foreach $parameter (@{$args{'parameterlist'}}) { | |
1714 | ($parameter =~ /^#/) && next; | |
1715 | ||
1716 | my $parameter_name = $parameter; | |
1717 | $parameter_name =~ s/\[.*//; | |
1718 | ||
3c308798 | 1719 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
1da177e4 | 1720 | print "$parameter\n\t"; |
b9d97328 | 1721 | print $args{'parameterdescs'}{$parameter_name} . "\n"; |
1da177e4 LT |
1722 | } |
1723 | print "\n"; | |
1724 | output_section_text(@_); | |
1725 | } | |
1726 | ||
b112e0f7 | 1727 | sub output_blockhead_text(%) { |
1da177e4 LT |
1728 | my %args = %{$_[0]}; |
1729 | my ($parameter, $section); | |
1730 | ||
1731 | foreach $section (@{$args{'sectionlist'}}) { | |
1732 | print " $section:\n"; | |
1733 | print " -> "; | |
1734 | output_highlight($args{'sections'}{$section}); | |
1735 | } | |
1736 | } | |
1737 | ||
c0d1b6ee JC |
1738 | ## |
1739 | # output in restructured text | |
1740 | # | |
1741 | ||
1742 | # | |
1743 | # This could use some work; it's used to output the DOC: sections, and | |
1744 | # starts by putting out the name of the doc section itself, but that tends | |
1745 | # to duplicate a header already in the template file. | |
1746 | # | |
1747 | sub output_blockhead_rst(%) { | |
1748 | my %args = %{$_[0]}; | |
1749 | my ($parameter, $section); | |
1750 | ||
1751 | foreach $section (@{$args{'sectionlist'}}) { | |
1752 | print "**$section**\n\n"; | |
1753 | output_highlight_rst($args{'sections'}{$section}); | |
1754 | print "\n"; | |
1755 | } | |
1756 | } | |
1757 | ||
1758 | sub output_highlight_rst { | |
1759 | my $contents = join "\n",@_; | |
1760 | my $line; | |
1761 | ||
1762 | # undo the evil effects of xml_escape() earlier | |
1763 | $contents = xml_unescape($contents); | |
1764 | ||
1765 | eval $dohighlight; | |
1766 | die $@ if $@; | |
1767 | ||
1768 | foreach $line (split "\n", $contents) { | |
1769 | if ($line eq "") { | |
1770 | print $lineprefix, $blankline; | |
1771 | } else { | |
1772 | $line =~ s/\\\\\\/\&/g; | |
1773 | print $lineprefix, $line; | |
1774 | } | |
1775 | print "\n"; | |
1776 | } | |
1777 | } | |
1778 | ||
1779 | sub output_function_rst(%) { | |
1780 | my %args = %{$_[0]}; | |
1781 | my ($parameter, $section); | |
1782 | my $start; | |
1783 | ||
1784 | print ".. c:function:: "; | |
1785 | if ($args{'functiontype'} ne "") { | |
1786 | $start = $args{'functiontype'} . " " . $args{'function'} . " ("; | |
1787 | } else { | |
1788 | $start = $args{'function'} . " ("; | |
1789 | } | |
1790 | print $start; | |
1791 | ||
1792 | my $count = 0; | |
1793 | foreach my $parameter (@{$args{'parameterlist'}}) { | |
1794 | if ($count ne 0) { | |
1795 | print ", "; | |
1796 | } | |
1797 | $count++; | |
1798 | $type = $args{'parametertypes'}{$parameter}; | |
1799 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { | |
1800 | # pointer-to-function | |
1801 | print $1 . $parameter . ") (" . $2; | |
1802 | } else { | |
1803 | print $type . " " . $parameter; | |
1804 | } | |
1805 | } | |
1806 | print ")\n\n " . $args{'purpose'} . "\n\n"; | |
1807 | ||
1808 | print ":Parameters:\n\n"; | |
1809 | foreach $parameter (@{$args{'parameterlist'}}) { | |
1810 | my $parameter_name = $parameter; | |
1811 | #$parameter_name =~ s/\[.*//; | |
1812 | $type = $args{'parametertypes'}{$parameter}; | |
1813 | ||
1814 | if ($type ne "") { | |
1815 | print " ``$type $parameter``\n"; | |
1816 | } else { | |
1817 | print " ``$parameter``\n"; | |
1818 | } | |
5e64fa9c JN |
1819 | if (defined($args{'parameterdescs'}{$parameter_name}) && |
1820 | $args{'parameterdescs'}{$parameter_name} ne $undescribed) { | |
c0d1b6ee JC |
1821 | my $oldprefix = $lineprefix; |
1822 | $lineprefix = " "; | |
1823 | output_highlight_rst($args{'parameterdescs'}{$parameter_name}); | |
1824 | $lineprefix = $oldprefix; | |
1825 | } else { | |
1826 | print "\n _undescribed_\n"; | |
1827 | } | |
1828 | print "\n"; | |
1829 | } | |
1830 | output_section_rst(@_); | |
1831 | } | |
1832 | ||
1833 | sub output_section_rst(%) { | |
1834 | my %args = %{$_[0]}; | |
1835 | my $section; | |
1836 | my $oldprefix = $lineprefix; | |
1837 | $lineprefix = " "; | |
1838 | ||
1839 | foreach $section (@{$args{'sectionlist'}}) { | |
1840 | print ":$section:\n\n"; | |
1841 | output_highlight_rst($args{'sections'}{$section}); | |
1842 | print "\n"; | |
1843 | } | |
1844 | print "\n"; | |
1845 | $lineprefix = $oldprefix; | |
1846 | } | |
1847 | ||
1848 | sub output_enum_rst(%) { | |
1849 | my %args = %{$_[0]}; | |
1850 | my ($parameter); | |
1851 | my $count; | |
c0d1b6ee | 1852 | my $name = "enum " . $args{'enum'}; |
62850976 JN |
1853 | |
1854 | print "\n\n.. c:type:: " . $name . "\n\n"; | |
c0d1b6ee JC |
1855 | print " " . $args{'purpose'} . "\n\n"; |
1856 | ||
1857 | print "..\n\n:Constants:\n\n"; | |
1858 | my $oldprefix = $lineprefix; | |
1859 | $lineprefix = " "; | |
1860 | foreach $parameter (@{$args{'parameterlist'}}) { | |
1861 | print " `$parameter`\n"; | |
1862 | if ($args{'parameterdescs'}{$parameter} ne $undescribed) { | |
1863 | output_highlight_rst($args{'parameterdescs'}{$parameter}); | |
1864 | } else { | |
1865 | print " undescribed\n"; | |
1866 | } | |
1867 | print "\n"; | |
1868 | } | |
1869 | $lineprefix = $oldprefix; | |
1870 | output_section_rst(@_); | |
1871 | } | |
1872 | ||
1873 | sub output_typedef_rst(%) { | |
1874 | my %args = %{$_[0]}; | |
1875 | my ($parameter); | |
1876 | my $count; | |
1877 | my $name = "typedef " . $args{'typedef'}; | |
1878 | ||
62850976 JN |
1879 | ### FIXME: should the name below contain "typedef" or not? |
1880 | print "\n\n.. c:type:: " . $name . "\n\n"; | |
1881 | print " " . $args{'purpose'} . "\n\n"; | |
c0d1b6ee JC |
1882 | |
1883 | output_section_rst(@_); | |
1884 | } | |
1885 | ||
1886 | sub output_struct_rst(%) { | |
1887 | my %args = %{$_[0]}; | |
1888 | my ($parameter); | |
1889 | my $name = $args{'type'} . " " . $args{'struct'}; | |
1890 | ||
62850976 | 1891 | print "\n\n.. c:type:: " . $name . "\n\n"; |
c0d1b6ee JC |
1892 | print " " . $args{'purpose'} . "\n\n"; |
1893 | ||
1894 | print ":Definition:\n\n"; | |
1895 | print " ::\n\n"; | |
1896 | print " " . $args{'type'} . " " . $args{'struct'} . " {\n"; | |
1897 | foreach $parameter (@{$args{'parameterlist'}}) { | |
1898 | if ($parameter =~ /^#/) { | |
1899 | print " " . "$parameter\n"; | |
1900 | next; | |
1901 | } | |
1902 | ||
1903 | my $parameter_name = $parameter; | |
1904 | $parameter_name =~ s/\[.*//; | |
1905 | ||
1906 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; | |
1907 | $type = $args{'parametertypes'}{$parameter}; | |
1908 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { | |
1909 | # pointer-to-function | |
1910 | print " $1 $parameter) ($2);\n"; | |
1911 | } elsif ($type =~ m/^(.*?)\s*(:.*)/) { | |
1912 | # bitfield | |
1913 | print " $1 $parameter$2;\n"; | |
1914 | } else { | |
1915 | print " " . $type . " " . $parameter . ";\n"; | |
1916 | } | |
1917 | } | |
1918 | print " };\n\n"; | |
1919 | ||
1920 | print ":Members:\n\n"; | |
1921 | foreach $parameter (@{$args{'parameterlist'}}) { | |
1922 | ($parameter =~ /^#/) && next; | |
1923 | ||
1924 | my $parameter_name = $parameter; | |
1925 | $parameter_name =~ s/\[.*//; | |
1926 | ||
1927 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; | |
1928 | $type = $args{'parametertypes'}{$parameter}; | |
1929 | print " `$type $parameter`" . "\n"; | |
1930 | my $oldprefix = $lineprefix; | |
1931 | $lineprefix = " "; | |
1932 | output_highlight_rst($args{'parameterdescs'}{$parameter_name}); | |
1933 | $lineprefix = $oldprefix; | |
1934 | print "\n"; | |
1935 | } | |
1936 | print "\n"; | |
1937 | output_section_rst(@_); | |
1938 | } | |
1939 | ||
1940 | ||
eda603f6 JB |
1941 | ## list mode output functions |
1942 | ||
1943 | sub output_function_list(%) { | |
1944 | my %args = %{$_[0]}; | |
1945 | ||
1946 | print $args{'function'} . "\n"; | |
1947 | } | |
1948 | ||
1949 | # output enum in list | |
1950 | sub output_enum_list(%) { | |
1951 | my %args = %{$_[0]}; | |
1952 | print $args{'enum'} . "\n"; | |
1953 | } | |
1954 | ||
1955 | # output typedef in list | |
1956 | sub output_typedef_list(%) { | |
1957 | my %args = %{$_[0]}; | |
1958 | print $args{'typedef'} . "\n"; | |
1959 | } | |
1960 | ||
1961 | # output struct as list | |
1962 | sub output_struct_list(%) { | |
1963 | my %args = %{$_[0]}; | |
1964 | ||
1965 | print $args{'struct'} . "\n"; | |
1966 | } | |
1967 | ||
1968 | sub output_blockhead_list(%) { | |
1969 | my %args = %{$_[0]}; | |
1970 | my ($parameter, $section); | |
1971 | ||
1972 | foreach $section (@{$args{'sectionlist'}}) { | |
1973 | print "DOC: $section\n"; | |
1974 | } | |
1975 | } | |
1976 | ||
1da177e4 | 1977 | ## |
27205744 RD |
1978 | # generic output function for all types (function, struct/union, typedef, enum); |
1979 | # calls the generated, variable output_ function name based on | |
1980 | # functype and output_mode | |
1da177e4 LT |
1981 | sub output_declaration { |
1982 | no strict 'refs'; | |
1983 | my $name = shift; | |
1984 | my $functype = shift; | |
1985 | my $func = "output_${functype}_$output_mode"; | |
3c3b809e | 1986 | if (($function_only==0) || |
86ae2e38 JN |
1987 | ( ($function_only == 1 || $function_only == 3) && |
1988 | defined($function_table{$name})) || | |
1989 | ( ($function_only == 2 || $function_only == 4) && | |
1990 | !($functype eq "function" && defined($function_table{$name})))) | |
1da177e4 | 1991 | { |
3c308798 | 1992 | &$func(@_); |
1da177e4 LT |
1993 | $section_counter++; |
1994 | } | |
1995 | } | |
1996 | ||
1997 | ## | |
27205744 | 1998 | # generic output function - calls the right one based on current output mode. |
b112e0f7 | 1999 | sub output_blockhead { |
1da177e4 | 2000 | no strict 'refs'; |
b9d97328 | 2001 | my $func = "output_blockhead_" . $output_mode; |
1da177e4 LT |
2002 | &$func(@_); |
2003 | $section_counter++; | |
2004 | } | |
2005 | ||
2006 | ## | |
3c3b809e | 2007 | # takes a declaration (struct, union, enum, typedef) and |
1da177e4 LT |
2008 | # invokes the right handler. NOT called for functions. |
2009 | sub dump_declaration($$) { | |
2010 | no strict 'refs'; | |
2011 | my ($prototype, $file) = @_; | |
b9d97328 | 2012 | my $func = "dump_" . $decl_type; |
1da177e4 LT |
2013 | &$func(@_); |
2014 | } | |
2015 | ||
2016 | sub dump_union($$) { | |
2017 | dump_struct(@_); | |
2018 | } | |
2019 | ||
2020 | sub dump_struct($$) { | |
2021 | my $x = shift; | |
2022 | my $file = shift; | |
a1d94aa5 | 2023 | my $nested; |
1da177e4 | 2024 | |
52dc5aec RD |
2025 | if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) { |
2026 | #my $decl_type = $1; | |
3c308798 RD |
2027 | $declaration_name = $2; |
2028 | my $members = $3; | |
1da177e4 LT |
2029 | |
2030 | # ignore embedded structs or unions | |
a1d94aa5 RD |
2031 | $members =~ s/({.*})//g; |
2032 | $nested = $1; | |
1da177e4 | 2033 | |
aeec46b9 | 2034 | # ignore members marked private: |
0d8c39e6 MCC |
2035 | $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi; |
2036 | $members =~ s/\/\*\s*private:.*//gosi; | |
aeec46b9 MW |
2037 | # strip comments: |
2038 | $members =~ s/\/\*.*?\*\///gos; | |
a1d94aa5 | 2039 | $nested =~ s/\/\*.*?\*\///gos; |
d960eea9 RD |
2040 | # strip kmemcheck_bitfield_{begin,end}.*; |
2041 | $members =~ s/kmemcheck_bitfield_.*?;//gos; | |
ef5da59f | 2042 | # strip attributes |
f0074929 | 2043 | $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; |
7b990789 | 2044 | $members =~ s/__aligned\s*\([^;]*\)//gos; |
f0074929 | 2045 | $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos; |
b22b5a9e CN |
2046 | # replace DECLARE_BITMAP |
2047 | $members =~ s/DECLARE_BITMAP\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos; | |
aeec46b9 | 2048 | |
1da177e4 | 2049 | create_parameterlist($members, ';', $file); |
a1d94aa5 | 2050 | check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested); |
1da177e4 LT |
2051 | |
2052 | output_declaration($declaration_name, | |
2053 | 'struct', | |
2054 | {'struct' => $declaration_name, | |
2055 | 'module' => $modulename, | |
2056 | 'parameterlist' => \@parameterlist, | |
2057 | 'parameterdescs' => \%parameterdescs, | |
2058 | 'parametertypes' => \%parametertypes, | |
2059 | 'sectionlist' => \@sectionlist, | |
2060 | 'sections' => \%sections, | |
2061 | 'purpose' => $declaration_purpose, | |
2062 | 'type' => $decl_type | |
2063 | }); | |
2064 | } | |
2065 | else { | |
d40e1e65 | 2066 | print STDERR "${file}:$.: error: Cannot parse struct or union!\n"; |
1da177e4 LT |
2067 | ++$errors; |
2068 | } | |
2069 | } | |
2070 | ||
2071 | sub dump_enum($$) { | |
2072 | my $x = shift; | |
2073 | my $file = shift; | |
2074 | ||
aeec46b9 | 2075 | $x =~ s@/\*.*?\*/@@gos; # strip comments. |
4468e21e CN |
2076 | # strip #define macros inside enums |
2077 | $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos; | |
b6d676db | 2078 | |
1da177e4 | 2079 | if ($x =~ /enum\s+(\w+)\s*{(.*)}/) { |
3c308798 RD |
2080 | $declaration_name = $1; |
2081 | my $members = $2; | |
1da177e4 LT |
2082 | |
2083 | foreach my $arg (split ',', $members) { | |
2084 | $arg =~ s/^\s*(\w+).*/$1/; | |
2085 | push @parameterlist, $arg; | |
2086 | if (!$parameterdescs{$arg}) { | |
3c308798 | 2087 | $parameterdescs{$arg} = $undescribed; |
d40e1e65 | 2088 | print STDERR "${file}:$.: warning: Enum value '$arg' ". |
1da177e4 LT |
2089 | "not described in enum '$declaration_name'\n"; |
2090 | } | |
2091 | ||
2092 | } | |
3c3b809e | 2093 | |
1da177e4 LT |
2094 | output_declaration($declaration_name, |
2095 | 'enum', | |
2096 | {'enum' => $declaration_name, | |
2097 | 'module' => $modulename, | |
2098 | 'parameterlist' => \@parameterlist, | |
2099 | 'parameterdescs' => \%parameterdescs, | |
2100 | 'sectionlist' => \@sectionlist, | |
2101 | 'sections' => \%sections, | |
2102 | 'purpose' => $declaration_purpose | |
2103 | }); | |
2104 | } | |
2105 | else { | |
d40e1e65 | 2106 | print STDERR "${file}:$.: error: Cannot parse enum!\n"; |
1da177e4 LT |
2107 | ++$errors; |
2108 | } | |
2109 | } | |
2110 | ||
2111 | sub dump_typedef($$) { | |
2112 | my $x = shift; | |
2113 | my $file = shift; | |
2114 | ||
aeec46b9 | 2115 | $x =~ s@/\*.*?\*/@@gos; # strip comments. |
1da177e4 | 2116 | |
83766452 MCC |
2117 | # Parse function prototypes |
2118 | if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/) { | |
2119 | # Function typedefs | |
2120 | $return_type = $1; | |
2121 | $declaration_name = $2; | |
2122 | my $args = $3; | |
2123 | ||
2124 | create_parameterlist($args, ',', $file); | |
1da177e4 LT |
2125 | |
2126 | output_declaration($declaration_name, | |
83766452 MCC |
2127 | 'function', |
2128 | {'function' => $declaration_name, | |
1da177e4 | 2129 | 'module' => $modulename, |
83766452 MCC |
2130 | 'functiontype' => $return_type, |
2131 | 'parameterlist' => \@parameterlist, | |
2132 | 'parameterdescs' => \%parameterdescs, | |
2133 | 'parametertypes' => \%parametertypes, | |
1da177e4 LT |
2134 | 'sectionlist' => \@sectionlist, |
2135 | 'sections' => \%sections, | |
2136 | 'purpose' => $declaration_purpose | |
2137 | }); | |
83766452 MCC |
2138 | return; |
2139 | } | |
2140 | ||
2141 | while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { | |
2142 | $x =~ s/\(*.\)\s*;$/;/; | |
2143 | $x =~ s/\[*.\]\s*;$/;/; | |
1da177e4 | 2144 | } |
83766452 MCC |
2145 | |
2146 | if ($x =~ /typedef.*\s+(\w+)\s*;/) { | |
3a80a766 MCC |
2147 | $declaration_name = $1; |
2148 | ||
2149 | output_declaration($declaration_name, | |
2150 | 'typedef', | |
2151 | {'typedef' => $declaration_name, | |
2152 | 'module' => $modulename, | |
2153 | 'sectionlist' => \@sectionlist, | |
2154 | 'sections' => \%sections, | |
2155 | 'purpose' => $declaration_purpose | |
2156 | }); | |
2157 | } | |
1da177e4 | 2158 | else { |
d40e1e65 | 2159 | print STDERR "${file}:$.: error: Cannot parse typedef!\n"; |
1da177e4 LT |
2160 | ++$errors; |
2161 | } | |
2162 | } | |
2163 | ||
a1d94aa5 RD |
2164 | sub save_struct_actual($) { |
2165 | my $actual = shift; | |
2166 | ||
2167 | # strip all spaces from the actual param so that it looks like one string item | |
2168 | $actual =~ s/\s*//g; | |
2169 | $struct_actual = $struct_actual . $actual . " "; | |
2170 | } | |
2171 | ||
1da177e4 LT |
2172 | sub create_parameterlist($$$) { |
2173 | my $args = shift; | |
2174 | my $splitter = shift; | |
2175 | my $file = shift; | |
2176 | my $type; | |
2177 | my $param; | |
2178 | ||
a6d3fe77 | 2179 | # temporarily replace commas inside function pointer definition |
1da177e4 | 2180 | while ($args =~ /(\([^\),]+),/) { |
3c308798 | 2181 | $args =~ s/(\([^\),]+),/$1#/g; |
1da177e4 | 2182 | } |
3c3b809e | 2183 | |
1da177e4 LT |
2184 | foreach my $arg (split($splitter, $args)) { |
2185 | # strip comments | |
2186 | $arg =~ s/\/\*.*\*\///; | |
3c308798 RD |
2187 | # strip leading/trailing spaces |
2188 | $arg =~ s/^\s*//; | |
1da177e4 LT |
2189 | $arg =~ s/\s*$//; |
2190 | $arg =~ s/\s+/ /; | |
2191 | ||
2192 | if ($arg =~ /^#/) { | |
2193 | # Treat preprocessor directive as a typeless variable just to fill | |
2194 | # corresponding data structures "correctly". Catch it later in | |
2195 | # output_* subs. | |
2196 | push_parameter($arg, "", $file); | |
00d62961 | 2197 | } elsif ($arg =~ m/\(.+\)\s*\(/) { |
1da177e4 LT |
2198 | # pointer-to-function |
2199 | $arg =~ tr/#/,/; | |
00d62961 | 2200 | $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/; |
1da177e4 LT |
2201 | $param = $1; |
2202 | $type = $arg; | |
00d62961 | 2203 | $type =~ s/([^\(]+\(\*?)\s*$param/$1/; |
a1d94aa5 | 2204 | save_struct_actual($param); |
1da177e4 | 2205 | push_parameter($param, $type, $file); |
aeec46b9 | 2206 | } elsif ($arg) { |
1da177e4 LT |
2207 | $arg =~ s/\s*:\s*/:/g; |
2208 | $arg =~ s/\s*\[/\[/g; | |
2209 | ||
2210 | my @args = split('\s*,\s*', $arg); | |
2211 | if ($args[0] =~ m/\*/) { | |
2212 | $args[0] =~ s/(\*+)\s*/ $1/; | |
2213 | } | |
884f2810 BP |
2214 | |
2215 | my @first_arg; | |
2216 | if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) { | |
2217 | shift @args; | |
2218 | push(@first_arg, split('\s+', $1)); | |
2219 | push(@first_arg, $2); | |
2220 | } else { | |
2221 | @first_arg = split('\s+', shift @args); | |
2222 | } | |
2223 | ||
1da177e4 LT |
2224 | unshift(@args, pop @first_arg); |
2225 | $type = join " ", @first_arg; | |
2226 | ||
2227 | foreach $param (@args) { | |
2228 | if ($param =~ m/^(\*+)\s*(.*)/) { | |
a1d94aa5 | 2229 | save_struct_actual($2); |
1da177e4 LT |
2230 | push_parameter($2, "$type $1", $file); |
2231 | } | |
2232 | elsif ($param =~ m/(.*?):(\d+)/) { | |
7b97887e | 2233 | if ($type ne "") { # skip unnamed bit-fields |
a1d94aa5 | 2234 | save_struct_actual($1); |
7b97887e RD |
2235 | push_parameter($1, "$type:$2", $file) |
2236 | } | |
1da177e4 LT |
2237 | } |
2238 | else { | |
a1d94aa5 | 2239 | save_struct_actual($param); |
1da177e4 LT |
2240 | push_parameter($param, $type, $file); |
2241 | } | |
2242 | } | |
2243 | } | |
2244 | } | |
2245 | } | |
2246 | ||
2247 | sub push_parameter($$$) { | |
2248 | my $param = shift; | |
2249 | my $type = shift; | |
2250 | my $file = shift; | |
2251 | ||
5f8c7c98 RD |
2252 | if (($anon_struct_union == 1) && ($type eq "") && |
2253 | ($param eq "}")) { | |
2254 | return; # ignore the ending }; from anon. struct/union | |
2255 | } | |
2256 | ||
2257 | $anon_struct_union = 0; | |
1da177e4 LT |
2258 | my $param_name = $param; |
2259 | $param_name =~ s/\[.*//; | |
2260 | ||
a6d3fe77 | 2261 | if ($type eq "" && $param =~ /\.\.\.$/) |
1da177e4 | 2262 | { |
ced69090 RD |
2263 | if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { |
2264 | $parameterdescs{$param} = "variable arguments"; | |
2265 | } | |
1da177e4 LT |
2266 | } |
2267 | elsif ($type eq "" && ($param eq "" or $param eq "void")) | |
2268 | { | |
1da177e4 LT |
2269 | $param="void"; |
2270 | $parameterdescs{void} = "no arguments"; | |
2271 | } | |
134fe01b RD |
2272 | elsif ($type eq "" && ($param eq "struct" or $param eq "union")) |
2273 | # handle unnamed (anonymous) union or struct: | |
2274 | { | |
2275 | $type = $param; | |
5f8c7c98 | 2276 | $param = "{unnamed_" . $param . "}"; |
134fe01b | 2277 | $parameterdescs{$param} = "anonymous\n"; |
5f8c7c98 | 2278 | $anon_struct_union = 1; |
134fe01b RD |
2279 | } |
2280 | ||
a6d3fe77 | 2281 | # warn if parameter has no description |
134fe01b RD |
2282 | # (but ignore ones starting with # as these are not parameters |
2283 | # but inline preprocessor statements); | |
2284 | # also ignore unnamed structs/unions; | |
5f8c7c98 | 2285 | if (!$anon_struct_union) { |
a6d3fe77 MW |
2286 | if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) { |
2287 | ||
1da177e4 LT |
2288 | $parameterdescs{$param_name} = $undescribed; |
2289 | ||
2290 | if (($type eq 'function') || ($type eq 'enum')) { | |
d40e1e65 | 2291 | print STDERR "${file}:$.: warning: Function parameter ". |
1da177e4 LT |
2292 | "or member '$param' not " . |
2293 | "described in '$declaration_name'\n"; | |
2294 | } | |
d40e1e65 | 2295 | print STDERR "${file}:$.: warning:" . |
3c308798 | 2296 | " No description found for parameter '$param'\n"; |
1da177e4 | 2297 | ++$warnings; |
3c308798 RD |
2298 | } |
2299 | } | |
1da177e4 | 2300 | |
2b35f4d9 RD |
2301 | $param = xml_escape($param); |
2302 | ||
25985edc | 2303 | # strip spaces from $param so that it is one continuous string |
e34e7dbb RD |
2304 | # on @parameterlist; |
2305 | # this fixes a problem where check_sections() cannot find | |
2306 | # a parameter like "addr[6 + 2]" because it actually appears | |
2307 | # as "addr[6", "+", "2]" on the parameter list; | |
2308 | # but it's better to maintain the param string unchanged for output, | |
2309 | # so just weaken the string compare in check_sections() to ignore | |
2310 | # "[blah" in a parameter string; | |
2311 | ###$param =~ s/\s*//g; | |
1da177e4 LT |
2312 | push @parameterlist, $param; |
2313 | $parametertypes{$param} = $type; | |
2314 | } | |
2315 | ||
a1d94aa5 RD |
2316 | sub check_sections($$$$$$) { |
2317 | my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_; | |
2318 | my @sects = split ' ', $sectcheck; | |
2319 | my @prms = split ' ', $prmscheck; | |
2320 | my $err; | |
2321 | my ($px, $sx); | |
2322 | my $prm_clean; # strip trailing "[array size]" and/or beginning "*" | |
2323 | ||
2324 | foreach $sx (0 .. $#sects) { | |
2325 | $err = 1; | |
2326 | foreach $px (0 .. $#prms) { | |
2327 | $prm_clean = $prms[$px]; | |
2328 | $prm_clean =~ s/\[.*\]//; | |
1f3a6688 | 2329 | $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; |
e34e7dbb RD |
2330 | # ignore array size in a parameter string; |
2331 | # however, the original param string may contain | |
2332 | # spaces, e.g.: addr[6 + 2] | |
2333 | # and this appears in @prms as "addr[6" since the | |
2334 | # parameter list is split at spaces; | |
2335 | # hence just ignore "[..." for the sections check; | |
2336 | $prm_clean =~ s/\[.*//; | |
2337 | ||
a1d94aa5 RD |
2338 | ##$prm_clean =~ s/^\**//; |
2339 | if ($prm_clean eq $sects[$sx]) { | |
2340 | $err = 0; | |
2341 | last; | |
2342 | } | |
2343 | } | |
2344 | if ($err) { | |
2345 | if ($decl_type eq "function") { | |
d40e1e65 | 2346 | print STDERR "${file}:$.: warning: " . |
a1d94aa5 RD |
2347 | "Excess function parameter " . |
2348 | "'$sects[$sx]' " . | |
2349 | "description in '$decl_name'\n"; | |
2350 | ++$warnings; | |
2351 | } else { | |
2352 | if ($nested !~ m/\Q$sects[$sx]\E/) { | |
d40e1e65 | 2353 | print STDERR "${file}:$.: warning: " . |
a1d94aa5 RD |
2354 | "Excess struct/union/enum/typedef member " . |
2355 | "'$sects[$sx]' " . | |
2356 | "description in '$decl_name'\n"; | |
2357 | ++$warnings; | |
2358 | } | |
2359 | } | |
2360 | } | |
2361 | } | |
2362 | } | |
2363 | ||
4092bac7 YB |
2364 | ## |
2365 | # Checks the section describing the return value of a function. | |
2366 | sub check_return_section { | |
2367 | my $file = shift; | |
2368 | my $declaration_name = shift; | |
2369 | my $return_type = shift; | |
2370 | ||
2371 | # Ignore an empty return type (It's a macro) | |
2372 | # Ignore functions with a "void" return type. (But don't ignore "void *") | |
2373 | if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) { | |
2374 | return; | |
2375 | } | |
2376 | ||
2377 | if (!defined($sections{$section_return}) || | |
2378 | $sections{$section_return} eq "") { | |
d40e1e65 | 2379 | print STDERR "${file}:$.: warning: " . |
4092bac7 YB |
2380 | "No description found for return value of " . |
2381 | "'$declaration_name'\n"; | |
2382 | ++$warnings; | |
2383 | } | |
2384 | } | |
2385 | ||
1da177e4 LT |
2386 | ## |
2387 | # takes a function prototype and the name of the current file being | |
2388 | # processed and spits out all the details stored in the global | |
2389 | # arrays/hashes. | |
2390 | sub dump_function($$) { | |
2391 | my $prototype = shift; | |
2392 | my $file = shift; | |
cbb4d3e6 | 2393 | my $noret = 0; |
1da177e4 LT |
2394 | |
2395 | $prototype =~ s/^static +//; | |
2396 | $prototype =~ s/^extern +//; | |
4dc3b16b | 2397 | $prototype =~ s/^asmlinkage +//; |
1da177e4 LT |
2398 | $prototype =~ s/^inline +//; |
2399 | $prototype =~ s/^__inline__ +//; | |
32e79401 RD |
2400 | $prototype =~ s/^__inline +//; |
2401 | $prototype =~ s/^__always_inline +//; | |
2402 | $prototype =~ s/^noinline +//; | |
74fc5c65 | 2403 | $prototype =~ s/__init +//; |
20072205 | 2404 | $prototype =~ s/__init_or_module +//; |
270a0096 | 2405 | $prototype =~ s/__meminit +//; |
70c95b00 | 2406 | $prototype =~ s/__must_check +//; |
0df7c0e3 | 2407 | $prototype =~ s/__weak +//; |
cbb4d3e6 | 2408 | my $define = $prototype =~ s/^#\s*define\s+//; #ak added |
328d2440 | 2409 | $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//; |
1da177e4 LT |
2410 | |
2411 | # Yes, this truly is vile. We are looking for: | |
2412 | # 1. Return type (may be nothing if we're looking at a macro) | |
2413 | # 2. Function name | |
2414 | # 3. Function parameters. | |
2415 | # | |
2416 | # All the while we have to watch out for function pointer parameters | |
2417 | # (which IIRC is what the two sections are for), C types (these | |
2418 | # regexps don't even start to express all the possibilities), and | |
2419 | # so on. | |
2420 | # | |
2421 | # If you mess with these regexps, it's a good idea to check that | |
2422 | # the following functions' documentation still comes out right: | |
2423 | # - parport_register_device (function pointer parameters) | |
2424 | # - atomic_set (macro) | |
9598f91f | 2425 | # - pci_match_device, __copy_to_user (long return type) |
1da177e4 | 2426 | |
cbb4d3e6 HG |
2427 | if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) { |
2428 | # This is an object-like macro, it has no return type and no parameter | |
2429 | # list. | |
2430 | # Function-like macros are not allowed to have spaces between | |
2431 | # declaration_name and opening parenthesis (notice the \s+). | |
2432 | $return_type = $1; | |
2433 | $declaration_name = $2; | |
2434 | $noret = 1; | |
2435 | } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || | |
1da177e4 LT |
2436 | $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || |
2437 | $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || | |
2438 | $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || | |
94b3e03c | 2439 | $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || |
1da177e4 LT |
2440 | $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || |
2441 | $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || | |
2442 | $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || | |
2443 | $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || | |
2444 | $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || | |
2445 | $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || | |
2446 | $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || | |
2447 | $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || | |
9598f91f MW |
2448 | $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || |
2449 | $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || | |
412ecd77 RD |
2450 | $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || |
2451 | $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) { | |
1da177e4 LT |
2452 | $return_type = $1; |
2453 | $declaration_name = $2; | |
2454 | my $args = $3; | |
2455 | ||
2456 | create_parameterlist($args, ',', $file); | |
2457 | } else { | |
d40e1e65 | 2458 | print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n"; |
1da177e4 LT |
2459 | return; |
2460 | } | |
2461 | ||
a1d94aa5 RD |
2462 | my $prms = join " ", @parameterlist; |
2463 | check_sections($file, $declaration_name, "function", $sectcheck, $prms, ""); | |
2464 | ||
4092bac7 YB |
2465 | # This check emits a lot of warnings at the moment, because many |
2466 | # functions don't have a 'Return' doc section. So until the number | |
2467 | # of warnings goes sufficiently down, the check is only performed in | |
2468 | # verbose mode. | |
2469 | # TODO: always perform the check. | |
cbb4d3e6 | 2470 | if ($verbose && !$noret) { |
4092bac7 YB |
2471 | check_return_section($file, $declaration_name, $return_type); |
2472 | } | |
2473 | ||
3c3b809e | 2474 | output_declaration($declaration_name, |
1da177e4 LT |
2475 | 'function', |
2476 | {'function' => $declaration_name, | |
2477 | 'module' => $modulename, | |
2478 | 'functiontype' => $return_type, | |
2479 | 'parameterlist' => \@parameterlist, | |
2480 | 'parameterdescs' => \%parameterdescs, | |
2481 | 'parametertypes' => \%parametertypes, | |
2482 | 'sectionlist' => \@sectionlist, | |
2483 | 'sections' => \%sections, | |
2484 | 'purpose' => $declaration_purpose | |
2485 | }); | |
2486 | } | |
2487 | ||
1da177e4 LT |
2488 | sub reset_state { |
2489 | $function = ""; | |
2490 | %constants = (); | |
2491 | %parameterdescs = (); | |
2492 | %parametertypes = (); | |
2493 | @parameterlist = (); | |
2494 | %sections = (); | |
2495 | @sectionlist = (); | |
a1d94aa5 RD |
2496 | $sectcheck = ""; |
2497 | $struct_actual = ""; | |
1da177e4 | 2498 | $prototype = ""; |
3c3b809e | 2499 | |
1da177e4 | 2500 | $state = 0; |
a4c6ebed | 2501 | $split_doc_state = 0; |
1da177e4 LT |
2502 | } |
2503 | ||
56afb0f8 JB |
2504 | sub tracepoint_munge($) { |
2505 | my $file = shift; | |
2506 | my $tracepointname = 0; | |
2507 | my $tracepointargs = 0; | |
2508 | ||
3a9089fd | 2509 | if ($prototype =~ m/TRACE_EVENT\((.*?),/) { |
56afb0f8 JB |
2510 | $tracepointname = $1; |
2511 | } | |
3a9089fd JB |
2512 | if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) { |
2513 | $tracepointname = $1; | |
2514 | } | |
2515 | if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) { | |
2516 | $tracepointname = $2; | |
2517 | } | |
2518 | $tracepointname =~ s/^\s+//; #strip leading whitespace | |
2519 | if ($prototype =~ m/TP_PROTO\((.*?)\)/) { | |
56afb0f8 JB |
2520 | $tracepointargs = $1; |
2521 | } | |
2522 | if (($tracepointname eq 0) || ($tracepointargs eq 0)) { | |
d40e1e65 | 2523 | print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n". |
56afb0f8 JB |
2524 | "$prototype\n"; |
2525 | } else { | |
2526 | $prototype = "static inline void trace_$tracepointname($tracepointargs)"; | |
2527 | } | |
2528 | } | |
2529 | ||
b4870bc5 RD |
2530 | sub syscall_munge() { |
2531 | my $void = 0; | |
2532 | ||
2533 | $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs | |
2534 | ## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) { | |
2535 | if ($prototype =~ m/SYSCALL_DEFINE0/) { | |
2536 | $void = 1; | |
2537 | ## $prototype = "long sys_$1(void)"; | |
2538 | } | |
2539 | ||
2540 | $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name | |
2541 | if ($prototype =~ m/long (sys_.*?),/) { | |
2542 | $prototype =~ s/,/\(/; | |
2543 | } elsif ($void) { | |
2544 | $prototype =~ s/\)/\(void\)/; | |
2545 | } | |
2546 | ||
2547 | # now delete all of the odd-number commas in $prototype | |
2548 | # so that arg types & arg names don't have a comma between them | |
2549 | my $count = 0; | |
2550 | my $len = length($prototype); | |
2551 | if ($void) { | |
2552 | $len = 0; # skip the for-loop | |
2553 | } | |
2554 | for (my $ix = 0; $ix < $len; $ix++) { | |
2555 | if (substr($prototype, $ix, 1) eq ',') { | |
2556 | $count++; | |
2557 | if ($count % 2 == 1) { | |
2558 | substr($prototype, $ix, 1) = ' '; | |
2559 | } | |
2560 | } | |
2561 | } | |
2562 | } | |
2563 | ||
3c3b809e | 2564 | sub process_state3_function($$) { |
1da177e4 LT |
2565 | my $x = shift; |
2566 | my $file = shift; | |
2567 | ||
51f5a0c8 RD |
2568 | $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line |
2569 | ||
890c78c2 | 2570 | if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) { |
1da177e4 LT |
2571 | # do nothing |
2572 | } | |
2573 | elsif ($x =~ /([^\{]*)/) { | |
3c308798 | 2574 | $prototype .= $1; |
1da177e4 | 2575 | } |
b4870bc5 | 2576 | |
890c78c2 | 2577 | if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) { |
3c308798 | 2578 | $prototype =~ s@/\*.*?\*/@@gos; # strip comments. |
1da177e4 LT |
2579 | $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. |
2580 | $prototype =~ s@^\s+@@gos; # strip leading spaces | |
b4870bc5 RD |
2581 | if ($prototype =~ /SYSCALL_DEFINE/) { |
2582 | syscall_munge(); | |
2583 | } | |
3a9089fd JB |
2584 | if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ || |
2585 | $prototype =~ /DEFINE_SINGLE_EVENT/) | |
2586 | { | |
56afb0f8 JB |
2587 | tracepoint_munge($file); |
2588 | } | |
b4870bc5 | 2589 | dump_function($prototype, $file); |
1da177e4 LT |
2590 | reset_state(); |
2591 | } | |
2592 | } | |
2593 | ||
3c3b809e | 2594 | sub process_state3_type($$) { |
1da177e4 LT |
2595 | my $x = shift; |
2596 | my $file = shift; | |
2597 | ||
1da177e4 LT |
2598 | $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. |
2599 | $x =~ s@^\s+@@gos; # strip leading spaces | |
2600 | $x =~ s@\s+$@@gos; # strip trailing spaces | |
51f5a0c8 RD |
2601 | $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line |
2602 | ||
1da177e4 LT |
2603 | if ($x =~ /^#/) { |
2604 | # To distinguish preprocessor directive from regular declaration later. | |
2605 | $x .= ";"; | |
2606 | } | |
2607 | ||
2608 | while (1) { | |
3c308798 | 2609 | if ( $x =~ /([^{};]*)([{};])(.*)/ ) { |
1da177e4 LT |
2610 | $prototype .= $1 . $2; |
2611 | ($2 eq '{') && $brcount++; | |
2612 | ($2 eq '}') && $brcount--; | |
2613 | if (($2 eq ';') && ($brcount == 0)) { | |
b9d97328 | 2614 | dump_declaration($prototype, $file); |
1da177e4 | 2615 | reset_state(); |
3c308798 | 2616 | last; |
1da177e4 LT |
2617 | } |
2618 | $x = $3; | |
3c308798 | 2619 | } else { |
1da177e4 LT |
2620 | $prototype .= $x; |
2621 | last; | |
2622 | } | |
2623 | } | |
2624 | } | |
2625 | ||
6b5b55f6 RD |
2626 | # xml_escape: replace <, >, and & in the text stream; |
2627 | # | |
2628 | # however, formatting controls that are generated internally/locally in the | |
2629 | # kernel-doc script are not escaped here; instead, they begin life like | |
2630 | # $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings | |
2631 | # are converted to their mnemonic-expected output, without the 4 * '\' & ':', | |
2632 | # just before actual output; (this is done by local_unescape()) | |
1da177e4 LT |
2633 | sub xml_escape($) { |
2634 | my $text = shift; | |
ecfb251a RD |
2635 | if (($output_mode eq "text") || ($output_mode eq "man")) { |
2636 | return $text; | |
2637 | } | |
1da177e4 LT |
2638 | $text =~ s/\&/\\\\\\amp;/g; |
2639 | $text =~ s/\</\\\\\\lt;/g; | |
2640 | $text =~ s/\>/\\\\\\gt;/g; | |
2641 | return $text; | |
2642 | } | |
2643 | ||
c0d1b6ee JC |
2644 | # xml_unescape: reverse the effects of xml_escape |
2645 | sub xml_unescape($) { | |
2646 | my $text = shift; | |
2647 | if (($output_mode eq "text") || ($output_mode eq "man")) { | |
2648 | return $text; | |
2649 | } | |
2650 | $text =~ s/\\\\\\amp;/\&/g; | |
2651 | $text =~ s/\\\\\\lt;/</g; | |
2652 | $text =~ s/\\\\\\gt;/>/g; | |
2653 | return $text; | |
2654 | } | |
2655 | ||
6b5b55f6 RD |
2656 | # convert local escape strings to html |
2657 | # local escape strings look like: '\\\\menmonic:' (that's 4 backslashes) | |
2658 | sub local_unescape($) { | |
2659 | my $text = shift; | |
2660 | if (($output_mode eq "text") || ($output_mode eq "man")) { | |
2661 | return $text; | |
2662 | } | |
2663 | $text =~ s/\\\\\\\\lt:/</g; | |
2664 | $text =~ s/\\\\\\\\gt:/>/g; | |
2665 | return $text; | |
2666 | } | |
2667 | ||
1da177e4 | 2668 | sub process_file($) { |
2283a117 | 2669 | my $file; |
1da177e4 LT |
2670 | my $identifier; |
2671 | my $func; | |
a21217da | 2672 | my $descr; |
6423133b | 2673 | my $in_purpose = 0; |
1da177e4 | 2674 | my $initial_section_counter = $section_counter; |
68f86662 | 2675 | my ($orig_file) = @_; |
1da177e4 | 2676 | |
2283a117 | 2677 | if (defined($ENV{'SRCTREE'})) { |
68f86662 | 2678 | $file = "$ENV{'SRCTREE'}" . "/" . $orig_file; |
2283a117 RD |
2679 | } |
2680 | else { | |
68f86662 | 2681 | $file = $orig_file; |
2283a117 | 2682 | } |
1da177e4 LT |
2683 | if (defined($source_map{$file})) { |
2684 | $file = $source_map{$file}; | |
2685 | } | |
2686 | ||
2687 | if (!open(IN,"<$file")) { | |
2688 | print STDERR "Error: Cannot open file $file\n"; | |
2689 | ++$errors; | |
2690 | return; | |
2691 | } | |
2692 | ||
86ae2e38 JN |
2693 | # two passes for -export and -internal |
2694 | if ($function_only == 3 || $function_only == 4) { | |
2695 | while (<IN>) { | |
2696 | if (/$export_symbol/o) { | |
2697 | $function_table{$2} = 1; | |
2698 | } | |
2699 | } | |
2700 | seek(IN, 0, 0); | |
2701 | } | |
2702 | ||
a9e7314b ID |
2703 | $. = 1; |
2704 | ||
1da177e4 LT |
2705 | $section_counter = 0; |
2706 | while (<IN>) { | |
65478428 DS |
2707 | while (s/\\\s*$//) { |
2708 | $_ .= <IN>; | |
2709 | } | |
1da177e4 LT |
2710 | if ($state == 0) { |
2711 | if (/$doc_start/o) { | |
2712 | $state = 1; # next line is always the function name | |
850622df | 2713 | $in_doc_sect = 0; |
1da177e4 LT |
2714 | } |
2715 | } elsif ($state == 1) { # this line is the function name (always) | |
2716 | if (/$doc_block/o) { | |
2717 | $state = 4; | |
2718 | $contents = ""; | |
2719 | if ( $1 eq "" ) { | |
2720 | $section = $section_intro; | |
2721 | } else { | |
2722 | $section = $1; | |
2723 | } | |
3c308798 | 2724 | } |
1da177e4 LT |
2725 | elsif (/$doc_decl/o) { |
2726 | $identifier = $1; | |
2727 | if (/\s*([\w\s]+?)\s*-/) { | |
2728 | $identifier = $1; | |
2729 | } | |
2730 | ||
2731 | $state = 2; | |
2732 | if (/-(.*)/) { | |
51f5a0c8 | 2733 | # strip leading/trailing/multiple spaces |
a21217da RD |
2734 | $descr= $1; |
2735 | $descr =~ s/^\s*//; | |
2736 | $descr =~ s/\s*$//; | |
12ae6779 | 2737 | $descr =~ s/\s+/ /g; |
a21217da | 2738 | $declaration_purpose = xml_escape($descr); |
6423133b | 2739 | $in_purpose = 1; |
1da177e4 LT |
2740 | } else { |
2741 | $declaration_purpose = ""; | |
2742 | } | |
77cc23b8 RD |
2743 | |
2744 | if (($declaration_purpose eq "") && $verbose) { | |
d40e1e65 | 2745 | print STDERR "${file}:$.: warning: missing initial short description on line:\n"; |
77cc23b8 RD |
2746 | print STDERR $_; |
2747 | ++$warnings; | |
2748 | } | |
2749 | ||
1da177e4 LT |
2750 | if ($identifier =~ m/^struct/) { |
2751 | $decl_type = 'struct'; | |
2752 | } elsif ($identifier =~ m/^union/) { | |
2753 | $decl_type = 'union'; | |
2754 | } elsif ($identifier =~ m/^enum/) { | |
2755 | $decl_type = 'enum'; | |
2756 | } elsif ($identifier =~ m/^typedef/) { | |
2757 | $decl_type = 'typedef'; | |
2758 | } else { | |
2759 | $decl_type = 'function'; | |
2760 | } | |
2761 | ||
2762 | if ($verbose) { | |
d40e1e65 | 2763 | print STDERR "${file}:$.: info: Scanning doc for $identifier\n"; |
1da177e4 LT |
2764 | } |
2765 | } else { | |
d40e1e65 | 2766 | print STDERR "${file}:$.: warning: Cannot understand $_ on line $.", |
1da177e4 LT |
2767 | " - I thought it was a doc line\n"; |
2768 | ++$warnings; | |
2769 | $state = 0; | |
2770 | } | |
2771 | } elsif ($state == 2) { # look for head: lines, and include content | |
2772 | if (/$doc_sect/o) { | |
2773 | $newsection = $1; | |
2774 | $newcontents = $2; | |
2775 | ||
792aa2f2 | 2776 | if (($contents ne "") && ($contents ne "\n")) { |
850622df | 2777 | if (!$in_doc_sect && $verbose) { |
d40e1e65 | 2778 | print STDERR "${file}:$.: warning: contents before sections\n"; |
850622df RD |
2779 | ++$warnings; |
2780 | } | |
94dc7ad5 | 2781 | dump_section($file, $section, xml_escape($contents)); |
1da177e4 LT |
2782 | $section = $section_default; |
2783 | } | |
2784 | ||
850622df | 2785 | $in_doc_sect = 1; |
6423133b | 2786 | $in_purpose = 0; |
1da177e4 LT |
2787 | $contents = $newcontents; |
2788 | if ($contents ne "") { | |
27205744 RD |
2789 | while ((substr($contents, 0, 1) eq " ") || |
2790 | substr($contents, 0, 1) eq "\t") { | |
2791 | $contents = substr($contents, 1); | |
05189497 | 2792 | } |
1da177e4 LT |
2793 | $contents .= "\n"; |
2794 | } | |
2795 | $section = $newsection; | |
2796 | } elsif (/$doc_end/) { | |
4c98ecaf | 2797 | if (($contents ne "") && ($contents ne "\n")) { |
94dc7ad5 | 2798 | dump_section($file, $section, xml_escape($contents)); |
1da177e4 LT |
2799 | $section = $section_default; |
2800 | $contents = ""; | |
2801 | } | |
46b958eb RD |
2802 | # look for doc_com + <text> + doc_end: |
2803 | if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') { | |
d40e1e65 | 2804 | print STDERR "${file}:$.: warning: suspicious ending line: $_"; |
46b958eb RD |
2805 | ++$warnings; |
2806 | } | |
1da177e4 LT |
2807 | |
2808 | $prototype = ""; | |
2809 | $state = 3; | |
2810 | $brcount = 0; | |
232acbcf | 2811 | # print STDERR "end of doc comment, looking for prototype\n"; |
1da177e4 LT |
2812 | } elsif (/$doc_content/) { |
2813 | # miguel-style comment kludge, look for blank lines after | |
2814 | # @parameter line to signify start of description | |
6423133b JW |
2815 | if ($1 eq "") { |
2816 | if ($section =~ m/^@/ || $section eq $section_context) { | |
2817 | dump_section($file, $section, xml_escape($contents)); | |
2818 | $section = $section_default; | |
2819 | $contents = ""; | |
2820 | } else { | |
2821 | $contents .= "\n"; | |
2822 | } | |
2823 | $in_purpose = 0; | |
2824 | } elsif ($in_purpose == 1) { | |
2825 | # Continued declaration purpose | |
2826 | chomp($declaration_purpose); | |
2827 | $declaration_purpose .= " " . xml_escape($1); | |
12ae6779 | 2828 | $declaration_purpose =~ s/\s+/ /g; |
1da177e4 | 2829 | } else { |
b9d97328 | 2830 | $contents .= $1 . "\n"; |
1da177e4 LT |
2831 | } |
2832 | } else { | |
2833 | # i dont know - bad line? ignore. | |
d40e1e65 | 2834 | print STDERR "${file}:$.: warning: bad line: $_"; |
1da177e4 LT |
2835 | ++$warnings; |
2836 | } | |
a4c6ebed DCLP |
2837 | } elsif ($state == 5) { # scanning for split parameters |
2838 | # First line (state 1) needs to be a @parameter | |
2839 | if ($split_doc_state == 1 && /$doc_split_sect/o) { | |
2840 | $section = $1; | |
2841 | $contents = $2; | |
2842 | if ($contents ne "") { | |
2843 | while ((substr($contents, 0, 1) eq " ") || | |
2844 | substr($contents, 0, 1) eq "\t") { | |
2845 | $contents = substr($contents, 1); | |
2846 | } | |
2847 | $contents .= "\n"; | |
2848 | } | |
2849 | $split_doc_state = 2; | |
2850 | # Documentation block end */ | |
2851 | } elsif (/$doc_split_end/) { | |
2852 | if (($contents ne "") && ($contents ne "\n")) { | |
2853 | dump_section($file, $section, xml_escape($contents)); | |
2854 | $section = $section_default; | |
2855 | $contents = ""; | |
2856 | } | |
2857 | $state = 3; | |
2858 | $split_doc_state = 0; | |
2859 | # Regular text | |
2860 | } elsif (/$doc_content/) { | |
2861 | if ($split_doc_state == 2) { | |
2862 | $contents .= $1 . "\n"; | |
2863 | } elsif ($split_doc_state == 1) { | |
2864 | $split_doc_state = 4; | |
2865 | print STDERR "Warning(${file}:$.): "; | |
2866 | print STDERR "Incorrect use of kernel-doc format: $_"; | |
2867 | ++$warnings; | |
2868 | } | |
2869 | } | |
232acbcf | 2870 | } elsif ($state == 3) { # scanning for function '{' (end of prototype) |
a4c6ebed DCLP |
2871 | if (/$doc_split_start/) { |
2872 | $state = 5; | |
2873 | $split_doc_state = 1; | |
2874 | } elsif ($decl_type eq 'function') { | |
3c308798 | 2875 | process_state3_function($_, $file); |
1da177e4 | 2876 | } else { |
3c308798 | 2877 | process_state3_type($_, $file); |
1da177e4 LT |
2878 | } |
2879 | } elsif ($state == 4) { | |
2880 | # Documentation block | |
3c308798 | 2881 | if (/$doc_block/) { |
94dc7ad5 | 2882 | dump_doc_section($file, $section, xml_escape($contents)); |
1da177e4 LT |
2883 | $contents = ""; |
2884 | $function = ""; | |
2885 | %constants = (); | |
2886 | %parameterdescs = (); | |
2887 | %parametertypes = (); | |
2888 | @parameterlist = (); | |
2889 | %sections = (); | |
2890 | @sectionlist = (); | |
2891 | $prototype = ""; | |
2892 | if ( $1 eq "" ) { | |
2893 | $section = $section_intro; | |
2894 | } else { | |
2895 | $section = $1; | |
2896 | } | |
3c308798 | 2897 | } |
1da177e4 LT |
2898 | elsif (/$doc_end/) |
2899 | { | |
94dc7ad5 | 2900 | dump_doc_section($file, $section, xml_escape($contents)); |
1da177e4 LT |
2901 | $contents = ""; |
2902 | $function = ""; | |
2903 | %constants = (); | |
2904 | %parameterdescs = (); | |
2905 | %parametertypes = (); | |
2906 | @parameterlist = (); | |
2907 | %sections = (); | |
2908 | @sectionlist = (); | |
2909 | $prototype = ""; | |
2910 | $state = 0; | |
2911 | } | |
2912 | elsif (/$doc_content/) | |
2913 | { | |
2914 | if ( $1 eq "" ) | |
2915 | { | |
2916 | $contents .= $blankline; | |
2917 | } | |
2918 | else | |
2919 | { | |
2920 | $contents .= $1 . "\n"; | |
3c3b809e | 2921 | } |
3c308798 RD |
2922 | } |
2923 | } | |
1da177e4 LT |
2924 | } |
2925 | if ($initial_section_counter == $section_counter) { | |
d40e1e65 | 2926 | print STDERR "${file}:1: warning: no structured comments found\n"; |
e946c43a JB |
2927 | if (($function_only == 1) && ($show_not_found == 1)) { |
2928 | print STDERR " Was looking for '$_'.\n" for keys %function_table; | |
2929 | } | |
1da177e4 LT |
2930 | if ($output_mode eq "xml") { |
2931 | # The template wants at least one RefEntry here; make one. | |
2932 | print "<refentry>\n"; | |
2933 | print " <refnamediv>\n"; | |
2934 | print " <refname>\n"; | |
68f86662 | 2935 | print " ${orig_file}\n"; |
1da177e4 LT |
2936 | print " </refname>\n"; |
2937 | print " <refpurpose>\n"; | |
2938 | print " Document generation inconsistency\n"; | |
2939 | print " </refpurpose>\n"; | |
2940 | print " </refnamediv>\n"; | |
2941 | print " <refsect1>\n"; | |
2942 | print " <title>\n"; | |
2943 | print " Oops\n"; | |
2944 | print " </title>\n"; | |
2945 | print " <warning>\n"; | |
2946 | print " <para>\n"; | |
2947 | print " The template for this document tried to insert\n"; | |
2948 | print " the structured comment from the file\n"; | |
68f86662 | 2949 | print " <filename>${orig_file}</filename> at this point,\n"; |
1da177e4 LT |
2950 | print " but none was found.\n"; |
2951 | print " This dummy section is inserted to allow\n"; | |
2952 | print " generation to continue.\n"; | |
2953 | print " </para>\n"; | |
2954 | print " </warning>\n"; | |
2955 | print " </refsect1>\n"; | |
2956 | print "</refentry>\n"; | |
2957 | } | |
2958 | } | |
2959 | } | |
8484baaa RD |
2960 | |
2961 | ||
2962 | $kernelversion = get_kernel_version(); | |
2963 | ||
2964 | # generate a sequence of code that will splice in highlighting information | |
2965 | # using the s// operator. | |
1ef06233 | 2966 | for (my $k = 0; $k < @highlights; $k++) { |
4d732701 DCLP |
2967 | my $pattern = $highlights[$k][0]; |
2968 | my $result = $highlights[$k][1]; | |
2969 | # print STDERR "scanning pattern:$pattern, highlight:($result)\n"; | |
2970 | $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n"; | |
8484baaa RD |
2971 | } |
2972 | ||
2973 | # Read the file that maps relative names to absolute names for | |
2974 | # separate source and object directories and for shadow trees. | |
2975 | if (open(SOURCE_MAP, "<.tmp_filelist.txt")) { | |
2976 | my ($relname, $absname); | |
2977 | while(<SOURCE_MAP>) { | |
2978 | chop(); | |
2979 | ($relname, $absname) = (split())[0..1]; | |
2980 | $relname =~ s:^/+::; | |
2981 | $source_map{$relname} = $absname; | |
2982 | } | |
2983 | close(SOURCE_MAP); | |
2984 | } | |
2985 | ||
2986 | foreach (@ARGV) { | |
2987 | chomp; | |
2988 | process_file($_); | |
2989 | } | |
2990 | if ($verbose && $errors) { | |
2991 | print STDERR "$errors errors\n"; | |
2992 | } | |
2993 | if ($verbose && $warnings) { | |
2994 | print STDERR "$warnings warnings\n"; | |
2995 | } | |
2996 | ||
2997 | exit($errors); |