]>
Commit | Line | Data |
---|---|---|
cb77f0d6 | 1 | #!/usr/bin/env perl |
1da177e4 | 2 | |
cb77f0d6 | 3 | use warnings; |
1da177e4 LT |
4 | use strict; |
5 | ||
6 | ## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ## | |
7 | ## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ## | |
8 | ## Copyright (C) 2001 Simon Huggins ## | |
70c95b00 | 9 | ## Copyright (C) 2005-2012 Randy Dunlap ## |
1b40c194 | 10 | ## Copyright (C) 2012 Dan Luedtke ## |
1da177e4 LT |
11 | ## ## |
12 | ## #define enhancements by Armin Kuster <akuster@mvista.com> ## | |
13 | ## Copyright (c) 2000 MontaVista Software, Inc. ## | |
14 | ## ## | |
15 | ## This software falls under the GNU General Public License. ## | |
16 | ## Please read the COPYING file for more information ## | |
17 | ||
1da177e4 LT |
18 | # 18/01/2001 - Cleanups |
19 | # Functions prototyped as foo(void) same as foo() | |
20 | # Stop eval'ing where we don't need to. | |
21 | # -- huggie@earth.li | |
22 | ||
23 | # 27/06/2001 - Allowed whitespace after initial "/**" and | |
24 | # allowed comments before function declarations. | |
25 | # -- Christian Kreibich <ck@whoop.org> | |
26 | ||
27 | # Still to do: | |
28 | # - add perldoc documentation | |
29 | # - Look more closely at some of the scarier bits :) | |
30 | ||
31 | # 26/05/2001 - Support for separate source and object trees. | |
32 | # Return error code. | |
33 | # Keith Owens <kaos@ocs.com.au> | |
34 | ||
35 | # 23/09/2001 - Added support for typedefs, structs, enums and unions | |
36 | # Support for Context section; can be terminated using empty line | |
37 | # Small fixes (like spaces vs. \s in regex) | |
38 | # -- Tim Jansen <tim@tjansen.de> | |
39 | ||
1b40c194 DL |
40 | # 25/07/2012 - Added support for HTML5 |
41 | # -- Dan Luedtke <mail@danrl.de> | |
1da177e4 | 42 | |
fadc0b31 JN |
43 | sub usage { |
44 | my $message = <<"EOF"; | |
45 | Usage: $0 [OPTION ...] FILE ... | |
46 | ||
47 | Read C language source or header FILEs, extract embedded documentation comments, | |
48 | and print formatted documentation to standard output. | |
49 | ||
50 | The documentation comments are identified by "/**" opening comment mark. See | |
857af3b7 | 51 | Documentation/doc-guide/kernel-doc.rst for the documentation comment syntax. |
fadc0b31 JN |
52 | |
53 | Output format selection (mutually exclusive): | |
fadc0b31 | 54 | -man Output troff manual page format. This is the default. |
c0d1b6ee | 55 | -rst Output reStructuredText format. |
3a025e1d | 56 | -none Do not output documentation, only warnings. |
fadc0b31 JN |
57 | |
58 | Output selection (mutually exclusive): | |
86ae2e38 JN |
59 | -export Only output documentation for symbols that have been |
60 | exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() | |
c9b2cfb3 | 61 | in any input FILE or -export-file FILE. |
86ae2e38 JN |
62 | -internal Only output documentation for symbols that have NOT been |
63 | exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() | |
c9b2cfb3 | 64 | in any input FILE or -export-file FILE. |
fadc0b31 JN |
65 | -function NAME Only output documentation for the given function(s) |
66 | or DOC: section title(s). All other functions and DOC: | |
67 | sections are ignored. May be specified multiple times. | |
68 | -nofunction NAME Do NOT output documentation for the given function(s); | |
69 | only output documentation for the other functions and | |
70 | DOC: sections. May be specified multiple times. | |
71 | ||
72 | Output selection modifiers: | |
73 | -no-doc-sections Do not output DOC: sections. | |
0b0f5f29 SV |
74 | -enable-lineno Enable output of #define LINENO lines. Only works with |
75 | reStructuredText format. | |
88c2b57d JN |
76 | -export-file FILE Specify an additional FILE in which to look for |
77 | EXPORT_SYMBOL() and EXPORT_SYMBOL_GPL(). To be used with | |
78 | -export or -internal. May be specified multiple times. | |
fadc0b31 JN |
79 | |
80 | Other parameters: | |
81 | -v Verbose output, more warnings and other information. | |
82 | -h Print this help. | |
83 | ||
84 | EOF | |
85 | print $message; | |
86 | exit 1; | |
87 | } | |
1da177e4 LT |
88 | |
89 | # | |
90 | # format of comments. | |
91 | # In the following table, (...)? signifies optional structure. | |
92 | # (...)* signifies 0 or more structure elements | |
93 | # /** | |
94 | # * function_name(:)? (- short description)? | |
95 | # (* @parameterx: (description of parameter x)?)* | |
96 | # (* a blank line)? | |
97 | # * (Description:)? (Description of function)? | |
98 | # * (section header: (section description)? )* | |
99 | # (*)?*/ | |
100 | # | |
101 | # So .. the trivial example would be: | |
102 | # | |
103 | # /** | |
104 | # * my_function | |
b9d97328 | 105 | # */ |
1da177e4 | 106 | # |
891dcd2f | 107 | # If the Description: header tag is omitted, then there must be a blank line |
1da177e4 LT |
108 | # after the last parameter specification. |
109 | # e.g. | |
110 | # /** | |
111 | # * my_function - does my stuff | |
112 | # * @my_arg: its mine damnit | |
113 | # * | |
3c3b809e | 114 | # * Does my stuff explained. |
1da177e4 LT |
115 | # */ |
116 | # | |
117 | # or, could also use: | |
118 | # /** | |
119 | # * my_function - does my stuff | |
120 | # * @my_arg: its mine damnit | |
3c3b809e | 121 | # * Description: Does my stuff explained. |
1da177e4 LT |
122 | # */ |
123 | # etc. | |
124 | # | |
b9d97328 | 125 | # Besides functions you can also write documentation for structs, unions, |
3c3b809e RD |
126 | # enums and typedefs. Instead of the function name you must write the name |
127 | # of the declaration; the struct/union/enum/typedef must always precede | |
128 | # the name. Nesting of declarations is not supported. | |
1da177e4 LT |
129 | # Use the argument mechanism to document members or constants. |
130 | # e.g. | |
131 | # /** | |
132 | # * struct my_struct - short description | |
133 | # * @a: first member | |
134 | # * @b: second member | |
3c3b809e | 135 | # * |
1da177e4 LT |
136 | # * Longer description |
137 | # */ | |
138 | # struct my_struct { | |
139 | # int a; | |
140 | # int b; | |
aeec46b9 MW |
141 | # /* private: */ |
142 | # int c; | |
1da177e4 LT |
143 | # }; |
144 | # | |
145 | # All descriptions can be multiline, except the short function description. | |
3c3b809e | 146 | # |
a4c6ebed DCLP |
147 | # For really longs structs, you can also describe arguments inside the |
148 | # body of the struct. | |
149 | # eg. | |
150 | # /** | |
151 | # * struct my_struct - short description | |
152 | # * @a: first member | |
153 | # * @b: second member | |
154 | # * | |
155 | # * Longer description | |
156 | # */ | |
157 | # struct my_struct { | |
158 | # int a; | |
159 | # int b; | |
160 | # /** | |
161 | # * @c: This is longer description of C | |
162 | # * | |
163 | # * You can use paragraphs to describe arguments | |
164 | # * using this method. | |
165 | # */ | |
166 | # int c; | |
167 | # }; | |
168 | # | |
169 | # This should be use only for struct/enum members. | |
170 | # | |
3c3b809e RD |
171 | # You can also add additional sections. When documenting kernel functions you |
172 | # should document the "Context:" of the function, e.g. whether the functions | |
1da177e4 | 173 | # can be called form interrupts. Unlike other sections you can end it with an |
3c3b809e | 174 | # empty line. |
4092bac7 YB |
175 | # A non-void function should have a "Return:" section describing the return |
176 | # value(s). | |
3c3b809e | 177 | # Example-sections should contain the string EXAMPLE so that they are marked |
1da177e4 LT |
178 | # appropriately in DocBook. |
179 | # | |
180 | # Example: | |
181 | # /** | |
182 | # * user_function - function that can only be called in user context | |
183 | # * @a: some argument | |
184 | # * Context: !in_interrupt() | |
3c3b809e | 185 | # * |
1da177e4 LT |
186 | # * Some description |
187 | # * Example: | |
188 | # * user_function(22); | |
189 | # */ | |
190 | # ... | |
191 | # | |
192 | # | |
193 | # All descriptive text is further processed, scanning for the following special | |
194 | # patterns, which are highlighted appropriately. | |
195 | # | |
196 | # 'funcname()' - function | |
197 | # '$ENVVAR' - environmental variable | |
198 | # '&struct_name' - name of a structure (up to two words including 'struct') | |
5267dd35 | 199 | # '&struct_name.member' - name of a structure member |
1da177e4 LT |
200 | # '@parameter' - name of a parameter |
201 | # '%CONST' - name of a constant. | |
b97f193a | 202 | # '``LITERAL``' - literal string without any spaces on it. |
1da177e4 | 203 | |
8484baaa RD |
204 | ## init lots of data |
205 | ||
1da177e4 LT |
206 | my $errors = 0; |
207 | my $warnings = 0; | |
5f8c7c98 | 208 | my $anon_struct_union = 0; |
1da177e4 LT |
209 | |
210 | # match expressions used to find embedded type information | |
b97f193a MCC |
211 | my $type_constant = '\b``([^\`]+)``\b'; |
212 | my $type_constant2 = '\%([-_\w]+)'; | |
1da177e4 | 213 | my $type_func = '(\w+)\(\)'; |
8ad72163 | 214 | my $type_param = '\@(\w*(\.\w+)*(\.\.\.)?)'; |
5219f18a | 215 | my $type_fp_param = '\@(\w+)\(\)'; # Special RST handling for func ptr params |
1da177e4 | 216 | my $type_env = '(\$\w+)'; |
df31175b PB |
217 | my $type_enum = '\&(enum\s*([_\w]+))'; |
218 | my $type_struct = '\&(struct\s*([_\w]+))'; | |
219 | my $type_typedef = '\&(typedef\s*([_\w]+))'; | |
220 | my $type_union = '\&(union\s*([_\w]+))'; | |
5267dd35 | 221 | my $type_member = '\&([_\w]+)(\.|->)([_\w]+)'; |
df31175b | 222 | my $type_fallback = '\&([_\w]+)'; |
f3341dcf | 223 | my $type_member_func = $type_member . '\(\)'; |
1da177e4 LT |
224 | |
225 | # Output conversion substitutions. | |
226 | # One for each output format | |
227 | ||
1da177e4 | 228 | # these are pretty rough |
4d732701 DCLP |
229 | my @highlights_man = ( |
230 | [$type_constant, "\$1"], | |
b97f193a | 231 | [$type_constant2, "\$1"], |
4d732701 | 232 | [$type_func, "\\\\fB\$1\\\\fP"], |
df31175b | 233 | [$type_enum, "\\\\fI\$1\\\\fP"], |
4d732701 | 234 | [$type_struct, "\\\\fI\$1\\\\fP"], |
df31175b PB |
235 | [$type_typedef, "\\\\fI\$1\\\\fP"], |
236 | [$type_union, "\\\\fI\$1\\\\fP"], | |
5267dd35 | 237 | [$type_param, "\\\\fI\$1\\\\fP"], |
df31175b PB |
238 | [$type_member, "\\\\fI\$1\$2\$3\\\\fP"], |
239 | [$type_fallback, "\\\\fI\$1\\\\fP"] | |
4d732701 | 240 | ); |
1da177e4 LT |
241 | my $blankline_man = ""; |
242 | ||
c0d1b6ee JC |
243 | # rst-mode |
244 | my @highlights_rst = ( | |
245 | [$type_constant, "``\$1``"], | |
b97f193a | 246 | [$type_constant2, "``\$1``"], |
f3341dcf | 247 | # Note: need to escape () to avoid func matching later |
5267dd35 PB |
248 | [$type_member_func, "\\:c\\:type\\:`\$1\$2\$3\\\\(\\\\) <\$1>`"], |
249 | [$type_member, "\\:c\\:type\\:`\$1\$2\$3 <\$1>`"], | |
5219f18a | 250 | [$type_fp_param, "**\$1\\\\(\\\\)**"], |
a19bce64 | 251 | [$type_func, "\\:c\\:func\\:`\$1()`"], |
df31175b PB |
252 | [$type_enum, "\\:c\\:type\\:`\$1 <\$2>`"], |
253 | [$type_struct, "\\:c\\:type\\:`\$1 <\$2>`"], | |
254 | [$type_typedef, "\\:c\\:type\\:`\$1 <\$2>`"], | |
255 | [$type_union, "\\:c\\:type\\:`\$1 <\$2>`"], | |
a7291e7e | 256 | # in rst this can refer to any type |
df31175b | 257 | [$type_fallback, "\\:c\\:type\\:`\$1`"], |
c0d1b6ee JC |
258 | [$type_param, "**\$1**"] |
259 | ); | |
260 | my $blankline_rst = "\n"; | |
261 | ||
1da177e4 | 262 | # read arguments |
b9d97328 | 263 | if ($#ARGV == -1) { |
1da177e4 LT |
264 | usage(); |
265 | } | |
266 | ||
8484baaa RD |
267 | my $kernelversion; |
268 | my $dohighlight = ""; | |
269 | ||
1da177e4 | 270 | my $verbose = 0; |
bdfe2be3 | 271 | my $output_mode = "rst"; |
e314ba31 | 272 | my $output_preformatted = 0; |
4b44595a | 273 | my $no_doc_sections = 0; |
0b0f5f29 | 274 | my $enable_lineno = 0; |
bdfe2be3 MCC |
275 | my @highlights = @highlights_rst; |
276 | my $blankline = $blankline_rst; | |
1da177e4 | 277 | my $modulename = "Kernel API"; |
b6c3f456 JN |
278 | |
279 | use constant { | |
280 | OUTPUT_ALL => 0, # output all symbols and doc sections | |
281 | OUTPUT_INCLUDE => 1, # output only specified symbols | |
282 | OUTPUT_EXCLUDE => 2, # output everything except specified symbols | |
283 | OUTPUT_EXPORTED => 3, # output exported symbols | |
284 | OUTPUT_INTERNAL => 4, # output non-exported symbols | |
285 | }; | |
286 | my $output_selection = OUTPUT_ALL; | |
b2c4105b BH |
287 | my $show_not_found = 0; |
288 | ||
88c2b57d JN |
289 | my @export_file_list; |
290 | ||
b2c4105b BH |
291 | my @build_time; |
292 | if (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) && | |
293 | (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') { | |
294 | @build_time = gmtime($seconds); | |
295 | } else { | |
296 | @build_time = localtime; | |
297 | } | |
298 | ||
3c3b809e RD |
299 | my $man_date = ('January', 'February', 'March', 'April', 'May', 'June', |
300 | 'July', 'August', 'September', 'October', | |
b2c4105b BH |
301 | 'November', 'December')[$build_time[4]] . |
302 | " " . ($build_time[5]+1900); | |
1da177e4 | 303 | |
8484baaa | 304 | # Essentially these are globals. |
b9d97328 RD |
305 | # They probably want to be tidied up, made more localised or something. |
306 | # CAVEAT EMPTOR! Some of the others I localised may not want to be, which | |
1da177e4 | 307 | # could cause "use of undefined value" or other bugs. |
b9d97328 | 308 | my ($function, %function_table, %parametertypes, $declaration_purpose); |
0b0f5f29 | 309 | my $declaration_start_line; |
b9d97328 | 310 | my ($type, $declaration_name, $return_type); |
1c32fd0c | 311 | my ($newsection, $newcontents, $prototype, $brcount, %source_map); |
1da177e4 | 312 | |
bd0e88e5 RD |
313 | if (defined($ENV{'KBUILD_VERBOSE'})) { |
314 | $verbose = "$ENV{'KBUILD_VERBOSE'}"; | |
315 | } | |
316 | ||
3c3b809e | 317 | # Generated docbook code is inserted in a template at a point where |
1da177e4 LT |
318 | # docbook v3.1 requires a non-zero sequence of RefEntry's; see: |
319 | # http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html | |
320 | # We keep track of number of generated entries and generate a dummy | |
321 | # if needs be to ensure the expanded template can be postprocessed | |
322 | # into html. | |
323 | my $section_counter = 0; | |
324 | ||
325 | my $lineprefix=""; | |
326 | ||
48af606a JN |
327 | # Parser states |
328 | use constant { | |
329 | STATE_NORMAL => 0, # normal code | |
330 | STATE_NAME => 1, # looking for function name | |
17b78717 JC |
331 | STATE_BODY_MAYBE => 2, # body - or maybe more description |
332 | STATE_BODY => 3, # the body of the comment | |
333 | STATE_PROTO => 4, # scanning prototype | |
334 | STATE_DOCBLOCK => 5, # documentation block | |
335 | STATE_INLINE => 6, # gathering documentation outside main block | |
48af606a | 336 | }; |
1da177e4 | 337 | my $state; |
850622df | 338 | my $in_doc_sect; |
1da177e4 | 339 | |
48af606a JN |
340 | # Inline documentation state |
341 | use constant { | |
342 | STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE) | |
343 | STATE_INLINE_NAME => 1, # looking for member name (@foo:) | |
344 | STATE_INLINE_TEXT => 2, # looking for member documentation | |
345 | STATE_INLINE_END => 3, # done | |
346 | STATE_INLINE_ERROR => 4, # error - Comment without header was found. | |
347 | # Spit a warning as it's not | |
348 | # proper kernel-doc and ignore the rest. | |
349 | }; | |
350 | my $inline_doc_state; | |
a4c6ebed | 351 | |
1da177e4 LT |
352 | #declaration types: can be |
353 | # 'function', 'struct', 'union', 'enum', 'typedef' | |
354 | my $decl_type; | |
355 | ||
1da177e4 LT |
356 | my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start. |
357 | my $doc_end = '\*/'; | |
358 | my $doc_com = '\s*\*\s*'; | |
12ae6779 | 359 | my $doc_com_body = '\s*\* ?'; |
b9d97328 | 360 | my $doc_decl = $doc_com . '(\w+)'; |
f624adef | 361 | # @params and a strictly limited set of supported section names |
8569de68 | 362 | my $doc_sect = $doc_com . |
ef00028b | 363 | '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:(.*)'; |
12ae6779 | 364 | my $doc_content = $doc_com_body . '(.*)'; |
b9d97328 | 365 | my $doc_block = $doc_com . 'DOC:\s*(.*)?'; |
48af606a JN |
366 | my $doc_inline_start = '^\s*/\*\*\s*$'; |
367 | my $doc_inline_sect = '\s*\*\s*(@[\w\s]+):(.*)'; | |
368 | my $doc_inline_end = '^\s*\*/\s*$'; | |
0c9aa209 | 369 | my $doc_inline_oneline = '^\s*/\*\*\s*(@[\w\s]+):\s*(.*)\s*\*/\s*$'; |
86ae2e38 | 370 | my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;'; |
1da177e4 | 371 | |
1da177e4 | 372 | my %parameterdescs; |
0b0f5f29 | 373 | my %parameterdesc_start_lines; |
1da177e4 LT |
374 | my @parameterlist; |
375 | my %sections; | |
376 | my @sectionlist; | |
0b0f5f29 | 377 | my %section_start_lines; |
a1d94aa5 RD |
378 | my $sectcheck; |
379 | my $struct_actual; | |
1da177e4 LT |
380 | |
381 | my $contents = ""; | |
0b0f5f29 | 382 | my $new_start_line = 0; |
f624adef JN |
383 | |
384 | # the canonical section names. see also $doc_sect above. | |
1da177e4 LT |
385 | my $section_default = "Description"; # default section |
386 | my $section_intro = "Introduction"; | |
387 | my $section = $section_default; | |
388 | my $section_context = "Context"; | |
4092bac7 | 389 | my $section_return = "Return"; |
1da177e4 LT |
390 | |
391 | my $undescribed = "-- undescribed --"; | |
392 | ||
393 | reset_state(); | |
394 | ||
b031ac4e MCC |
395 | while ($ARGV[0] =~ m/^--?(.*)/) { |
396 | my $cmd = $1; | |
397 | shift @ARGV; | |
398 | if ($cmd eq "man") { | |
1da177e4 | 399 | $output_mode = "man"; |
4d732701 | 400 | @highlights = @highlights_man; |
1da177e4 | 401 | $blankline = $blankline_man; |
b031ac4e | 402 | } elsif ($cmd eq "rst") { |
c0d1b6ee JC |
403 | $output_mode = "rst"; |
404 | @highlights = @highlights_rst; | |
405 | $blankline = $blankline_rst; | |
b031ac4e | 406 | } elsif ($cmd eq "none") { |
3a025e1d | 407 | $output_mode = "none"; |
b031ac4e | 408 | } elsif ($cmd eq "module") { # not needed for XML, inherits from calling document |
1da177e4 | 409 | $modulename = shift @ARGV; |
b031ac4e | 410 | } elsif ($cmd eq "function") { # to only output specific functions |
b6c3f456 | 411 | $output_selection = OUTPUT_INCLUDE; |
1da177e4 LT |
412 | $function = shift @ARGV; |
413 | $function_table{$function} = 1; | |
b031ac4e | 414 | } elsif ($cmd eq "nofunction") { # output all except specific functions |
b6c3f456 | 415 | $output_selection = OUTPUT_EXCLUDE; |
1da177e4 LT |
416 | $function = shift @ARGV; |
417 | $function_table{$function} = 1; | |
b031ac4e | 418 | } elsif ($cmd eq "export") { # only exported symbols |
b6c3f456 | 419 | $output_selection = OUTPUT_EXPORTED; |
da9726ec | 420 | %function_table = (); |
b031ac4e | 421 | } elsif ($cmd eq "internal") { # only non-exported symbols |
b6c3f456 | 422 | $output_selection = OUTPUT_INTERNAL; |
da9726ec | 423 | %function_table = (); |
b031ac4e | 424 | } elsif ($cmd eq "export-file") { |
88c2b57d JN |
425 | my $file = shift @ARGV; |
426 | push(@export_file_list, $file); | |
b031ac4e | 427 | } elsif ($cmd eq "v") { |
1da177e4 | 428 | $verbose = 1; |
b031ac4e | 429 | } elsif (($cmd eq "h") || ($cmd eq "help")) { |
1da177e4 | 430 | usage(); |
b031ac4e | 431 | } elsif ($cmd eq 'no-doc-sections') { |
4b44595a | 432 | $no_doc_sections = 1; |
b031ac4e | 433 | } elsif ($cmd eq 'enable-lineno') { |
0b0f5f29 | 434 | $enable_lineno = 1; |
b031ac4e | 435 | } elsif ($cmd eq 'show-not-found') { |
e946c43a | 436 | $show_not_found = 1; |
b031ac4e MCC |
437 | } else { |
438 | # Unknown argument | |
439 | usage(); | |
1da177e4 LT |
440 | } |
441 | } | |
442 | ||
8484baaa RD |
443 | # continue execution near EOF; |
444 | ||
53f049fa BP |
445 | # get kernel version from env |
446 | sub get_kernel_version() { | |
1b9bc22d | 447 | my $version = 'unknown kernel version'; |
53f049fa BP |
448 | |
449 | if (defined($ENV{'KERNELVERSION'})) { | |
450 | $version = $ENV{'KERNELVERSION'}; | |
451 | } | |
452 | return $version; | |
453 | } | |
1da177e4 | 454 | |
0b0f5f29 SV |
455 | # |
456 | sub print_lineno { | |
457 | my $lineno = shift; | |
458 | if ($enable_lineno && defined($lineno)) { | |
459 | print "#define LINENO " . $lineno . "\n"; | |
460 | } | |
461 | } | |
1da177e4 LT |
462 | ## |
463 | # dumps section contents to arrays/hashes intended for that purpose. | |
464 | # | |
465 | sub dump_section { | |
94dc7ad5 | 466 | my $file = shift; |
1da177e4 LT |
467 | my $name = shift; |
468 | my $contents = join "\n", @_; | |
469 | ||
13901ef2 | 470 | if ($name =~ m/$type_param/) { |
1da177e4 LT |
471 | $name = $1; |
472 | $parameterdescs{$name} = $contents; | |
a1d94aa5 | 473 | $sectcheck = $sectcheck . $name . " "; |
0b0f5f29 SV |
474 | $parameterdesc_start_lines{$name} = $new_start_line; |
475 | $new_start_line = 0; | |
ced69090 | 476 | } elsif ($name eq "@\.\.\.") { |
ced69090 RD |
477 | $name = "..."; |
478 | $parameterdescs{$name} = $contents; | |
a1d94aa5 | 479 | $sectcheck = $sectcheck . $name . " "; |
0b0f5f29 SV |
480 | $parameterdesc_start_lines{$name} = $new_start_line; |
481 | $new_start_line = 0; | |
1da177e4 | 482 | } else { |
94dc7ad5 | 483 | if (defined($sections{$name}) && ($sections{$name} ne "")) { |
95b6be9d JN |
484 | # Only warn on user specified duplicate section names. |
485 | if ($name ne $section_default) { | |
486 | print STDERR "${file}:$.: warning: duplicate section name '$name'\n"; | |
487 | ++$warnings; | |
488 | } | |
32217761 JN |
489 | $sections{$name} .= $contents; |
490 | } else { | |
491 | $sections{$name} = $contents; | |
492 | push @sectionlist, $name; | |
0b0f5f29 SV |
493 | $section_start_lines{$name} = $new_start_line; |
494 | $new_start_line = 0; | |
94dc7ad5 | 495 | } |
1da177e4 LT |
496 | } |
497 | } | |
498 | ||
b112e0f7 JB |
499 | ## |
500 | # dump DOC: section after checking that it should go out | |
501 | # | |
502 | sub dump_doc_section { | |
94dc7ad5 | 503 | my $file = shift; |
b112e0f7 JB |
504 | my $name = shift; |
505 | my $contents = join "\n", @_; | |
506 | ||
4b44595a JB |
507 | if ($no_doc_sections) { |
508 | return; | |
509 | } | |
510 | ||
b6c3f456 JN |
511 | if (($output_selection == OUTPUT_ALL) || |
512 | ($output_selection == OUTPUT_INCLUDE && | |
513 | defined($function_table{$name})) || | |
514 | ($output_selection == OUTPUT_EXCLUDE && | |
515 | !defined($function_table{$name}))) | |
b112e0f7 | 516 | { |
94dc7ad5 | 517 | dump_section($file, $name, $contents); |
b112e0f7 JB |
518 | output_blockhead({'sectionlist' => \@sectionlist, |
519 | 'sections' => \%sections, | |
520 | 'module' => $modulename, | |
b6c3f456 | 521 | 'content-only' => ($output_selection != OUTPUT_ALL), }); |
b112e0f7 JB |
522 | } |
523 | } | |
524 | ||
1da177e4 LT |
525 | ## |
526 | # output function | |
527 | # | |
528 | # parameterdescs, a hash. | |
529 | # function => "function name" | |
530 | # parameterlist => @list of parameters | |
531 | # parameterdescs => %parameter descriptions | |
532 | # sectionlist => @list of sections | |
a21217da | 533 | # sections => %section descriptions |
3c3b809e | 534 | # |
1da177e4 LT |
535 | |
536 | sub output_highlight { | |
537 | my $contents = join "\n",@_; | |
538 | my $line; | |
539 | ||
540 | # DEBUG | |
541 | # if (!defined $contents) { | |
542 | # use Carp; | |
543 | # confess "output_highlight got called with no args?\n"; | |
544 | # } | |
545 | ||
3eb014a1 | 546 | # print STDERR "contents b4:$contents\n"; |
1da177e4 LT |
547 | eval $dohighlight; |
548 | die $@ if $@; | |
3eb014a1 RD |
549 | # print STDERR "contents af:$contents\n"; |
550 | ||
1da177e4 | 551 | foreach $line (split "\n", $contents) { |
12ae6779 DS |
552 | if (! $output_preformatted) { |
553 | $line =~ s/^\s*//; | |
554 | } | |
3c308798 | 555 | if ($line eq ""){ |
e314ba31 | 556 | if (! $output_preformatted) { |
0bba924c | 557 | print $lineprefix, $blankline; |
e314ba31 | 558 | } |
1da177e4 | 559 | } else { |
cdccb316 RD |
560 | if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { |
561 | print "\\&$line"; | |
562 | } else { | |
563 | print $lineprefix, $line; | |
564 | } | |
1da177e4 LT |
565 | } |
566 | print "\n"; | |
567 | } | |
568 | } | |
569 | ||
1da177e4 LT |
570 | ## |
571 | # output function in man | |
572 | sub output_function_man(%) { | |
573 | my %args = %{$_[0]}; | |
574 | my ($parameter, $section); | |
575 | my $count; | |
576 | ||
577 | print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; | |
578 | ||
579 | print ".SH NAME\n"; | |
b9d97328 | 580 | print $args{'function'} . " \\- " . $args{'purpose'} . "\n"; |
1da177e4 LT |
581 | |
582 | print ".SH SYNOPSIS\n"; | |
a21217da | 583 | if ($args{'functiontype'} ne "") { |
b9d97328 | 584 | print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n"; |
a21217da | 585 | } else { |
b9d97328 | 586 | print ".B \"" . $args{'function'} . "\n"; |
a21217da | 587 | } |
1da177e4 LT |
588 | $count = 0; |
589 | my $parenth = "("; | |
590 | my $post = ","; | |
591 | foreach my $parameter (@{$args{'parameterlist'}}) { | |
592 | if ($count == $#{$args{'parameterlist'}}) { | |
593 | $post = ");"; | |
594 | } | |
595 | $type = $args{'parametertypes'}{$parameter}; | |
596 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { | |
597 | # pointer-to-function | |
b9d97328 | 598 | print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n"; |
1da177e4 LT |
599 | } else { |
600 | $type =~ s/([^\*])$/$1 /; | |
b9d97328 | 601 | print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n"; |
1da177e4 LT |
602 | } |
603 | $count++; | |
604 | $parenth = ""; | |
605 | } | |
606 | ||
607 | print ".SH ARGUMENTS\n"; | |
608 | foreach $parameter (@{$args{'parameterlist'}}) { | |
609 | my $parameter_name = $parameter; | |
610 | $parameter_name =~ s/\[.*//; | |
611 | ||
b9d97328 | 612 | print ".IP \"" . $parameter . "\" 12\n"; |
1da177e4 LT |
613 | output_highlight($args{'parameterdescs'}{$parameter_name}); |
614 | } | |
615 | foreach $section (@{$args{'sectionlist'}}) { | |
616 | print ".SH \"", uc $section, "\"\n"; | |
617 | output_highlight($args{'sections'}{$section}); | |
618 | } | |
619 | } | |
620 | ||
621 | ## | |
622 | # output enum in man | |
623 | sub output_enum_man(%) { | |
624 | my %args = %{$_[0]}; | |
625 | my ($parameter, $section); | |
626 | my $count; | |
627 | ||
628 | print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n"; | |
629 | ||
630 | print ".SH NAME\n"; | |
b9d97328 | 631 | print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n"; |
1da177e4 LT |
632 | |
633 | print ".SH SYNOPSIS\n"; | |
b9d97328 | 634 | print "enum " . $args{'enum'} . " {\n"; |
1da177e4 LT |
635 | $count = 0; |
636 | foreach my $parameter (@{$args{'parameterlist'}}) { | |
3c308798 | 637 | print ".br\n.BI \" $parameter\"\n"; |
1da177e4 LT |
638 | if ($count == $#{$args{'parameterlist'}}) { |
639 | print "\n};\n"; | |
640 | last; | |
641 | } | |
642 | else { | |
643 | print ", \n.br\n"; | |
644 | } | |
645 | $count++; | |
646 | } | |
647 | ||
648 | print ".SH Constants\n"; | |
649 | foreach $parameter (@{$args{'parameterlist'}}) { | |
650 | my $parameter_name = $parameter; | |
651 | $parameter_name =~ s/\[.*//; | |
652 | ||
b9d97328 | 653 | print ".IP \"" . $parameter . "\" 12\n"; |
1da177e4 LT |
654 | output_highlight($args{'parameterdescs'}{$parameter_name}); |
655 | } | |
656 | foreach $section (@{$args{'sectionlist'}}) { | |
657 | print ".SH \"$section\"\n"; | |
658 | output_highlight($args{'sections'}{$section}); | |
659 | } | |
660 | } | |
661 | ||
662 | ## | |
663 | # output struct in man | |
664 | sub output_struct_man(%) { | |
665 | my %args = %{$_[0]}; | |
666 | my ($parameter, $section); | |
667 | ||
b9d97328 | 668 | print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n"; |
1da177e4 LT |
669 | |
670 | print ".SH NAME\n"; | |
b9d97328 | 671 | print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n"; |
1da177e4 | 672 | |
8ad72163 MCC |
673 | my $declaration = $args{'definition'}; |
674 | $declaration =~ s/\t/ /g; | |
675 | $declaration =~ s/\n/"\n.br\n.BI \"/g; | |
1da177e4 | 676 | print ".SH SYNOPSIS\n"; |
b9d97328 | 677 | print $args{'type'} . " " . $args{'struct'} . " {\n.br\n"; |
8ad72163 | 678 | print ".BI \"$declaration\n};\n.br\n\n"; |
1da177e4 | 679 | |
c51d3dac | 680 | print ".SH Members\n"; |
1da177e4 LT |
681 | foreach $parameter (@{$args{'parameterlist'}}) { |
682 | ($parameter =~ /^#/) && next; | |
683 | ||
684 | my $parameter_name = $parameter; | |
685 | $parameter_name =~ s/\[.*//; | |
686 | ||
3c308798 | 687 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
b9d97328 | 688 | print ".IP \"" . $parameter . "\" 12\n"; |
1da177e4 LT |
689 | output_highlight($args{'parameterdescs'}{$parameter_name}); |
690 | } | |
691 | foreach $section (@{$args{'sectionlist'}}) { | |
692 | print ".SH \"$section\"\n"; | |
693 | output_highlight($args{'sections'}{$section}); | |
694 | } | |
695 | } | |
696 | ||
697 | ## | |
698 | # output typedef in man | |
699 | sub output_typedef_man(%) { | |
700 | my %args = %{$_[0]}; | |
701 | my ($parameter, $section); | |
702 | ||
703 | print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n"; | |
704 | ||
705 | print ".SH NAME\n"; | |
b9d97328 | 706 | print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n"; |
1da177e4 LT |
707 | |
708 | foreach $section (@{$args{'sectionlist'}}) { | |
709 | print ".SH \"$section\"\n"; | |
710 | output_highlight($args{'sections'}{$section}); | |
711 | } | |
712 | } | |
713 | ||
b112e0f7 | 714 | sub output_blockhead_man(%) { |
1da177e4 LT |
715 | my %args = %{$_[0]}; |
716 | my ($parameter, $section); | |
717 | my $count; | |
718 | ||
719 | print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; | |
720 | ||
721 | foreach $section (@{$args{'sectionlist'}}) { | |
722 | print ".SH \"$section\"\n"; | |
723 | output_highlight($args{'sections'}{$section}); | |
724 | } | |
725 | } | |
726 | ||
c0d1b6ee JC |
727 | ## |
728 | # output in restructured text | |
729 | # | |
730 | ||
731 | # | |
732 | # This could use some work; it's used to output the DOC: sections, and | |
733 | # starts by putting out the name of the doc section itself, but that tends | |
734 | # to duplicate a header already in the template file. | |
735 | # | |
736 | sub output_blockhead_rst(%) { | |
737 | my %args = %{$_[0]}; | |
738 | my ($parameter, $section); | |
739 | ||
740 | foreach $section (@{$args{'sectionlist'}}) { | |
9e72184b JN |
741 | if ($output_selection != OUTPUT_INCLUDE) { |
742 | print "**$section**\n\n"; | |
743 | } | |
0b0f5f29 | 744 | print_lineno($section_start_lines{$section}); |
c0d1b6ee JC |
745 | output_highlight_rst($args{'sections'}{$section}); |
746 | print "\n"; | |
747 | } | |
748 | } | |
749 | ||
750 | sub output_highlight_rst { | |
751 | my $contents = join "\n",@_; | |
752 | my $line; | |
753 | ||
c0d1b6ee JC |
754 | eval $dohighlight; |
755 | die $@ if $@; | |
756 | ||
757 | foreach $line (split "\n", $contents) { | |
830066a7 | 758 | print $lineprefix . $line . "\n"; |
c0d1b6ee JC |
759 | } |
760 | } | |
761 | ||
762 | sub output_function_rst(%) { | |
763 | my %args = %{$_[0]}; | |
764 | my ($parameter, $section); | |
c099ff69 | 765 | my $oldprefix = $lineprefix; |
82801d06 MCC |
766 | my $start = ""; |
767 | ||
768 | if ($args{'typedef'}) { | |
769 | print ".. c:type:: ". $args{'function'} . "\n\n"; | |
770 | print_lineno($declaration_start_line); | |
771 | print " **Typedef**: "; | |
772 | $lineprefix = ""; | |
773 | output_highlight_rst($args{'purpose'}); | |
774 | $start = "\n\n**Syntax**\n\n ``"; | |
775 | } else { | |
776 | print ".. c:function:: "; | |
777 | } | |
c0d1b6ee | 778 | if ($args{'functiontype'} ne "") { |
82801d06 | 779 | $start .= $args{'functiontype'} . " " . $args{'function'} . " ("; |
c0d1b6ee | 780 | } else { |
82801d06 | 781 | $start .= $args{'function'} . " ("; |
c0d1b6ee JC |
782 | } |
783 | print $start; | |
784 | ||
785 | my $count = 0; | |
786 | foreach my $parameter (@{$args{'parameterlist'}}) { | |
787 | if ($count ne 0) { | |
788 | print ", "; | |
789 | } | |
790 | $count++; | |
791 | $type = $args{'parametertypes'}{$parameter}; | |
a88b1672 | 792 | |
c0d1b6ee JC |
793 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { |
794 | # pointer-to-function | |
795 | print $1 . $parameter . ") (" . $2; | |
796 | } else { | |
797 | print $type . " " . $parameter; | |
798 | } | |
799 | } | |
82801d06 MCC |
800 | if ($args{'typedef'}) { |
801 | print ");``\n\n"; | |
802 | } else { | |
803 | print ")\n\n"; | |
804 | print_lineno($declaration_start_line); | |
805 | $lineprefix = " "; | |
806 | output_highlight_rst($args{'purpose'}); | |
807 | print "\n"; | |
808 | } | |
c0d1b6ee | 809 | |
ecbcfba1 JN |
810 | print "**Parameters**\n\n"; |
811 | $lineprefix = " "; | |
c0d1b6ee JC |
812 | foreach $parameter (@{$args{'parameterlist'}}) { |
813 | my $parameter_name = $parameter; | |
ada5f446 | 814 | $parameter_name =~ s/\[.*//; |
c0d1b6ee JC |
815 | $type = $args{'parametertypes'}{$parameter}; |
816 | ||
817 | if ($type ne "") { | |
ecbcfba1 | 818 | print "``$type $parameter``\n"; |
c0d1b6ee | 819 | } else { |
ecbcfba1 | 820 | print "``$parameter``\n"; |
c0d1b6ee | 821 | } |
0b0f5f29 SV |
822 | |
823 | print_lineno($parameterdesc_start_lines{$parameter_name}); | |
824 | ||
5e64fa9c JN |
825 | if (defined($args{'parameterdescs'}{$parameter_name}) && |
826 | $args{'parameterdescs'}{$parameter_name} ne $undescribed) { | |
c0d1b6ee | 827 | output_highlight_rst($args{'parameterdescs'}{$parameter_name}); |
c0d1b6ee | 828 | } else { |
d4b08e0c | 829 | print " *undescribed*\n"; |
c0d1b6ee JC |
830 | } |
831 | print "\n"; | |
832 | } | |
c099ff69 JN |
833 | |
834 | $lineprefix = $oldprefix; | |
c0d1b6ee JC |
835 | output_section_rst(@_); |
836 | } | |
837 | ||
838 | sub output_section_rst(%) { | |
839 | my %args = %{$_[0]}; | |
840 | my $section; | |
841 | my $oldprefix = $lineprefix; | |
ecbcfba1 | 842 | $lineprefix = ""; |
c0d1b6ee JC |
843 | |
844 | foreach $section (@{$args{'sectionlist'}}) { | |
ecbcfba1 | 845 | print "**$section**\n\n"; |
0b0f5f29 | 846 | print_lineno($section_start_lines{$section}); |
c0d1b6ee JC |
847 | output_highlight_rst($args{'sections'}{$section}); |
848 | print "\n"; | |
849 | } | |
850 | print "\n"; | |
851 | $lineprefix = $oldprefix; | |
852 | } | |
853 | ||
854 | sub output_enum_rst(%) { | |
855 | my %args = %{$_[0]}; | |
856 | my ($parameter); | |
c099ff69 | 857 | my $oldprefix = $lineprefix; |
c0d1b6ee | 858 | my $count; |
c0d1b6ee | 859 | my $name = "enum " . $args{'enum'}; |
62850976 JN |
860 | |
861 | print "\n\n.. c:type:: " . $name . "\n\n"; | |
0b0f5f29 | 862 | print_lineno($declaration_start_line); |
c099ff69 JN |
863 | $lineprefix = " "; |
864 | output_highlight_rst($args{'purpose'}); | |
865 | print "\n"; | |
c0d1b6ee | 866 | |
ecbcfba1 JN |
867 | print "**Constants**\n\n"; |
868 | $lineprefix = " "; | |
c0d1b6ee | 869 | foreach $parameter (@{$args{'parameterlist'}}) { |
ecbcfba1 | 870 | print "``$parameter``\n"; |
c0d1b6ee JC |
871 | if ($args{'parameterdescs'}{$parameter} ne $undescribed) { |
872 | output_highlight_rst($args{'parameterdescs'}{$parameter}); | |
873 | } else { | |
d4b08e0c | 874 | print " *undescribed*\n"; |
c0d1b6ee JC |
875 | } |
876 | print "\n"; | |
877 | } | |
c099ff69 | 878 | |
c0d1b6ee JC |
879 | $lineprefix = $oldprefix; |
880 | output_section_rst(@_); | |
881 | } | |
882 | ||
883 | sub output_typedef_rst(%) { | |
884 | my %args = %{$_[0]}; | |
885 | my ($parameter); | |
c099ff69 | 886 | my $oldprefix = $lineprefix; |
c0d1b6ee JC |
887 | my $name = "typedef " . $args{'typedef'}; |
888 | ||
62850976 | 889 | print "\n\n.. c:type:: " . $name . "\n\n"; |
0b0f5f29 | 890 | print_lineno($declaration_start_line); |
c099ff69 JN |
891 | $lineprefix = " "; |
892 | output_highlight_rst($args{'purpose'}); | |
893 | print "\n"; | |
c0d1b6ee | 894 | |
c099ff69 | 895 | $lineprefix = $oldprefix; |
c0d1b6ee JC |
896 | output_section_rst(@_); |
897 | } | |
898 | ||
899 | sub output_struct_rst(%) { | |
900 | my %args = %{$_[0]}; | |
901 | my ($parameter); | |
c099ff69 | 902 | my $oldprefix = $lineprefix; |
c0d1b6ee JC |
903 | my $name = $args{'type'} . " " . $args{'struct'}; |
904 | ||
62850976 | 905 | print "\n\n.. c:type:: " . $name . "\n\n"; |
0b0f5f29 | 906 | print_lineno($declaration_start_line); |
c099ff69 JN |
907 | $lineprefix = " "; |
908 | output_highlight_rst($args{'purpose'}); | |
909 | print "\n"; | |
c0d1b6ee | 910 | |
ecbcfba1 JN |
911 | print "**Definition**\n\n"; |
912 | print "::\n\n"; | |
8ad72163 MCC |
913 | my $declaration = $args{'definition'}; |
914 | $declaration =~ s/\t/ /g; | |
915 | print " " . $args{'type'} . " " . $args{'struct'} . " {\n$declaration };\n\n"; | |
c0d1b6ee | 916 | |
ecbcfba1 JN |
917 | print "**Members**\n\n"; |
918 | $lineprefix = " "; | |
c0d1b6ee JC |
919 | foreach $parameter (@{$args{'parameterlist'}}) { |
920 | ($parameter =~ /^#/) && next; | |
921 | ||
922 | my $parameter_name = $parameter; | |
923 | $parameter_name =~ s/\[.*//; | |
924 | ||
925 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; | |
926 | $type = $args{'parametertypes'}{$parameter}; | |
0b0f5f29 | 927 | print_lineno($parameterdesc_start_lines{$parameter_name}); |
6d232c80 | 928 | print "``" . $parameter . "``\n"; |
c0d1b6ee | 929 | output_highlight_rst($args{'parameterdescs'}{$parameter_name}); |
c0d1b6ee JC |
930 | print "\n"; |
931 | } | |
932 | print "\n"; | |
c099ff69 JN |
933 | |
934 | $lineprefix = $oldprefix; | |
c0d1b6ee JC |
935 | output_section_rst(@_); |
936 | } | |
937 | ||
3a025e1d MW |
938 | ## none mode output functions |
939 | ||
940 | sub output_function_none(%) { | |
941 | } | |
942 | ||
943 | sub output_enum_none(%) { | |
944 | } | |
945 | ||
946 | sub output_typedef_none(%) { | |
947 | } | |
948 | ||
949 | sub output_struct_none(%) { | |
950 | } | |
951 | ||
952 | sub output_blockhead_none(%) { | |
953 | } | |
954 | ||
1da177e4 | 955 | ## |
27205744 RD |
956 | # generic output function for all types (function, struct/union, typedef, enum); |
957 | # calls the generated, variable output_ function name based on | |
958 | # functype and output_mode | |
1da177e4 LT |
959 | sub output_declaration { |
960 | no strict 'refs'; | |
961 | my $name = shift; | |
962 | my $functype = shift; | |
963 | my $func = "output_${functype}_$output_mode"; | |
b6c3f456 JN |
964 | if (($output_selection == OUTPUT_ALL) || |
965 | (($output_selection == OUTPUT_INCLUDE || | |
966 | $output_selection == OUTPUT_EXPORTED) && | |
967 | defined($function_table{$name})) || | |
968 | (($output_selection == OUTPUT_EXCLUDE || | |
969 | $output_selection == OUTPUT_INTERNAL) && | |
970 | !($functype eq "function" && defined($function_table{$name})))) | |
1da177e4 | 971 | { |
3c308798 | 972 | &$func(@_); |
1da177e4 LT |
973 | $section_counter++; |
974 | } | |
975 | } | |
976 | ||
977 | ## | |
27205744 | 978 | # generic output function - calls the right one based on current output mode. |
b112e0f7 | 979 | sub output_blockhead { |
1da177e4 | 980 | no strict 'refs'; |
b9d97328 | 981 | my $func = "output_blockhead_" . $output_mode; |
1da177e4 LT |
982 | &$func(@_); |
983 | $section_counter++; | |
984 | } | |
985 | ||
986 | ## | |
3c3b809e | 987 | # takes a declaration (struct, union, enum, typedef) and |
1da177e4 LT |
988 | # invokes the right handler. NOT called for functions. |
989 | sub dump_declaration($$) { | |
990 | no strict 'refs'; | |
991 | my ($prototype, $file) = @_; | |
b9d97328 | 992 | my $func = "dump_" . $decl_type; |
1da177e4 LT |
993 | &$func(@_); |
994 | } | |
995 | ||
996 | sub dump_union($$) { | |
997 | dump_struct(@_); | |
998 | } | |
999 | ||
1000 | sub dump_struct($$) { | |
1001 | my $x = shift; | |
1002 | my $file = shift; | |
1003 | ||
52dc5aec | 1004 | if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) { |
5cb5c31c | 1005 | my $decl_type = $1; |
3c308798 RD |
1006 | $declaration_name = $2; |
1007 | my $members = $3; | |
1da177e4 | 1008 | |
aeec46b9 | 1009 | # ignore members marked private: |
0d8c39e6 MCC |
1010 | $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi; |
1011 | $members =~ s/\/\*\s*private:.*//gosi; | |
aeec46b9 MW |
1012 | # strip comments: |
1013 | $members =~ s/\/\*.*?\*\///gos; | |
ef5da59f | 1014 | # strip attributes |
f0074929 | 1015 | $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; |
7b990789 | 1016 | $members =~ s/__aligned\s*\([^;]*\)//gos; |
f0074929 | 1017 | $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos; |
b22b5a9e | 1018 | # replace DECLARE_BITMAP |
45005b27 | 1019 | $members =~ s/DECLARE_BITMAP\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos; |
1cb566ba | 1020 | # replace DECLARE_HASHTABLE |
45005b27 MCC |
1021 | $members =~ s/DECLARE_HASHTABLE\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[1 << (($2) - 1)\]/gos; |
1022 | # replace DECLARE_KFIFO | |
1023 | $members =~ s/DECLARE_KFIFO\s*\(([^,)]+),\s*([^,)]+),\s*([^,)]+)\)/$2 \*$1/gos; | |
1024 | # replace DECLARE_KFIFO_PTR | |
1025 | $members =~ s/DECLARE_KFIFO_PTR\s*\(([^,)]+),\s*([^,)]+)\)/$2 \*$1/gos; | |
aeec46b9 | 1026 | |
8ad72163 MCC |
1027 | my $declaration = $members; |
1028 | ||
1029 | # Split nested struct/union elements as newer ones | |
84ce5b98 MCC |
1030 | while ($members =~ m/(struct|union)([^\{\};]+)\{([^\{\}]*)\}([^\{\}\;]*)\;/) { |
1031 | my $newmember; | |
1032 | my $maintype = $1; | |
1033 | my $ids = $4; | |
1034 | my $content = $3; | |
1035 | foreach my $id(split /,/, $ids) { | |
1036 | $newmember .= "$maintype $id; "; | |
1037 | ||
8ad72163 | 1038 | $id =~ s/[:\[].*//; |
84ce5b98 | 1039 | $id =~ s/^\s*\**(\S+)\s*/$1/; |
8ad72163 MCC |
1040 | foreach my $arg (split /;/, $content) { |
1041 | next if ($arg =~ m/^\s*$/); | |
7c0d7e87 MCC |
1042 | if ($arg =~ m/^([^\(]+\(\*?\s*)([\w\.]*)(\s*\).*)/) { |
1043 | # pointer-to-function | |
1044 | my $type = $1; | |
1045 | my $name = $2; | |
1046 | my $extra = $3; | |
1047 | next if (!$name); | |
1048 | if ($id =~ m/^\s*$/) { | |
1049 | # anonymous struct/union | |
84ce5b98 | 1050 | $newmember .= "$type$name$extra; "; |
7c0d7e87 | 1051 | } else { |
84ce5b98 | 1052 | $newmember .= "$type$id.$name$extra; "; |
7c0d7e87 | 1053 | } |
8ad72163 | 1054 | } else { |
84ce5b98 MCC |
1055 | my $type; |
1056 | my $names; | |
1057 | $arg =~ s/^\s+//; | |
1058 | $arg =~ s/\s+$//; | |
1059 | # Handle bitmaps | |
1060 | $arg =~ s/:\s*\d+\s*//g; | |
1061 | # Handle arrays | |
1062 | $arg =~ s/\[\S+\]//g; | |
1063 | # The type may have multiple words, | |
1064 | # and multiple IDs can be defined, like: | |
1065 | # const struct foo, *bar, foobar | |
1066 | # So, we remove spaces when parsing the | |
1067 | # names, in order to match just names | |
1068 | # and commas for the names | |
1069 | $arg =~ s/\s*,\s*/,/g; | |
1070 | if ($arg =~ m/(.*)\s+([\S+,]+)/) { | |
1071 | $type = $1; | |
1072 | $names = $2; | |
7c0d7e87 | 1073 | } else { |
84ce5b98 MCC |
1074 | $newmember .= "$arg; "; |
1075 | next; | |
1076 | } | |
1077 | foreach my $name (split /,/, $names) { | |
1078 | $name =~ s/^\s*\**(\S+)\s*/$1/; | |
1079 | next if (($name =~ m/^\s*$/)); | |
1080 | if ($id =~ m/^\s*$/) { | |
1081 | # anonymous struct/union | |
1082 | $newmember .= "$type $name; "; | |
1083 | } else { | |
1084 | $newmember .= "$type $id.$name; "; | |
1085 | } | |
7c0d7e87 | 1086 | } |
8ad72163 MCC |
1087 | } |
1088 | } | |
84ce5b98 MCC |
1089 | } |
1090 | $members =~ s/(struct|union)([^\{\};]+)\{([^\{\}]*)}([^\{\}\;]*)\;/$newmember/; | |
1091 | } | |
8ad72163 MCC |
1092 | |
1093 | # Ignore other nested elements, like enums | |
1094 | $members =~ s/({[^\{\}]*})//g; | |
8ad72163 | 1095 | |
151c468b | 1096 | create_parameterlist($members, ';', $file, $declaration_name); |
1081de2d | 1097 | check_sections($file, $declaration_name, $decl_type, $sectcheck, $struct_actual); |
1da177e4 | 1098 | |
8ad72163 MCC |
1099 | # Adjust declaration for better display |
1100 | $declaration =~ s/([{;])/$1\n/g; | |
1101 | $declaration =~ s/}\s+;/};/g; | |
1102 | # Better handle inlined enums | |
1103 | do {} while ($declaration =~ s/(enum\s+{[^}]+),([^\n])/$1,\n$2/); | |
1104 | ||
1105 | my @def_args = split /\n/, $declaration; | |
1106 | my $level = 1; | |
1107 | $declaration = ""; | |
1108 | foreach my $clause (@def_args) { | |
1109 | $clause =~ s/^\s+//; | |
1110 | $clause =~ s/\s+$//; | |
1111 | $clause =~ s/\s+/ /; | |
1112 | next if (!$clause); | |
1113 | $level-- if ($clause =~ m/(})/ && $level > 1); | |
1114 | if (!($clause =~ m/^\s*#/)) { | |
1115 | $declaration .= "\t" x $level; | |
1116 | } | |
1117 | $declaration .= "\t" . $clause . "\n"; | |
1118 | $level++ if ($clause =~ m/({)/ && !($clause =~m/}/)); | |
1119 | } | |
1da177e4 LT |
1120 | output_declaration($declaration_name, |
1121 | 'struct', | |
1122 | {'struct' => $declaration_name, | |
1123 | 'module' => $modulename, | |
8ad72163 | 1124 | 'definition' => $declaration, |
1da177e4 LT |
1125 | 'parameterlist' => \@parameterlist, |
1126 | 'parameterdescs' => \%parameterdescs, | |
1127 | 'parametertypes' => \%parametertypes, | |
1128 | 'sectionlist' => \@sectionlist, | |
1129 | 'sections' => \%sections, | |
1130 | 'purpose' => $declaration_purpose, | |
1131 | 'type' => $decl_type | |
1132 | }); | |
1133 | } | |
1134 | else { | |
d40e1e65 | 1135 | print STDERR "${file}:$.: error: Cannot parse struct or union!\n"; |
1da177e4 LT |
1136 | ++$errors; |
1137 | } | |
1138 | } | |
1139 | ||
85afe608 MCC |
1140 | |
1141 | sub show_warnings($$) { | |
1142 | my $functype = shift; | |
1143 | my $name = shift; | |
1144 | ||
1145 | return 1 if ($output_selection == OUTPUT_ALL); | |
1146 | ||
1147 | if ($output_selection == OUTPUT_EXPORTED) { | |
1148 | if (defined($function_table{$name})) { | |
1149 | return 1; | |
1150 | } else { | |
1151 | return 0; | |
1152 | } | |
1153 | } | |
1154 | if ($output_selection == OUTPUT_INTERNAL) { | |
1155 | if (!($functype eq "function" && defined($function_table{$name}))) { | |
1156 | return 1; | |
1157 | } else { | |
1158 | return 0; | |
1159 | } | |
1160 | } | |
1161 | if ($output_selection == OUTPUT_INCLUDE) { | |
1162 | if (defined($function_table{$name})) { | |
1163 | return 1; | |
1164 | } else { | |
1165 | return 0; | |
1166 | } | |
1167 | } | |
1168 | if ($output_selection == OUTPUT_EXCLUDE) { | |
1169 | if (!defined($function_table{$name})) { | |
1170 | return 1; | |
1171 | } else { | |
1172 | return 0; | |
1173 | } | |
1174 | } | |
1175 | die("Please add the new output type at show_warnings()"); | |
1176 | } | |
1177 | ||
1da177e4 LT |
1178 | sub dump_enum($$) { |
1179 | my $x = shift; | |
1180 | my $file = shift; | |
1181 | ||
aeec46b9 | 1182 | $x =~ s@/\*.*?\*/@@gos; # strip comments. |
4468e21e CN |
1183 | # strip #define macros inside enums |
1184 | $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos; | |
b6d676db | 1185 | |
1da177e4 | 1186 | if ($x =~ /enum\s+(\w+)\s*{(.*)}/) { |
3c308798 RD |
1187 | $declaration_name = $1; |
1188 | my $members = $2; | |
5cb5c31c JB |
1189 | my %_members; |
1190 | ||
463a0fdc | 1191 | $members =~ s/\s+$//; |
1da177e4 LT |
1192 | |
1193 | foreach my $arg (split ',', $members) { | |
1194 | $arg =~ s/^\s*(\w+).*/$1/; | |
1195 | push @parameterlist, $arg; | |
1196 | if (!$parameterdescs{$arg}) { | |
3c308798 | 1197 | $parameterdescs{$arg} = $undescribed; |
85afe608 | 1198 | if (show_warnings("enum", $declaration_name)) { |
2defb272 MCC |
1199 | print STDERR "${file}:$.: warning: Enum value '$arg' not described in enum '$declaration_name'\n"; |
1200 | } | |
1da177e4 | 1201 | } |
5cb5c31c | 1202 | $_members{$arg} = 1; |
1da177e4 | 1203 | } |
3c3b809e | 1204 | |
5cb5c31c JB |
1205 | while (my ($k, $v) = each %parameterdescs) { |
1206 | if (!exists($_members{$k})) { | |
85afe608 | 1207 | if (show_warnings("enum", $declaration_name)) { |
2defb272 MCC |
1208 | print STDERR "${file}:$.: warning: Excess enum value '$k' description in '$declaration_name'\n"; |
1209 | } | |
5cb5c31c JB |
1210 | } |
1211 | } | |
1212 | ||
1da177e4 LT |
1213 | output_declaration($declaration_name, |
1214 | 'enum', | |
1215 | {'enum' => $declaration_name, | |
1216 | 'module' => $modulename, | |
1217 | 'parameterlist' => \@parameterlist, | |
1218 | 'parameterdescs' => \%parameterdescs, | |
1219 | 'sectionlist' => \@sectionlist, | |
1220 | 'sections' => \%sections, | |
1221 | 'purpose' => $declaration_purpose | |
1222 | }); | |
1223 | } | |
1224 | else { | |
d40e1e65 | 1225 | print STDERR "${file}:$.: error: Cannot parse enum!\n"; |
1da177e4 LT |
1226 | ++$errors; |
1227 | } | |
1228 | } | |
1229 | ||
1230 | sub dump_typedef($$) { | |
1231 | my $x = shift; | |
1232 | my $file = shift; | |
1233 | ||
aeec46b9 | 1234 | $x =~ s@/\*.*?\*/@@gos; # strip comments. |
1da177e4 | 1235 | |
83766452 | 1236 | # Parse function prototypes |
d37c43ce MCC |
1237 | if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/ || |
1238 | $x =~ /typedef\s+(\w+)\s*(\w\S+)\s*\s*\((.*)\);/) { | |
1239 | ||
83766452 MCC |
1240 | # Function typedefs |
1241 | $return_type = $1; | |
1242 | $declaration_name = $2; | |
1243 | my $args = $3; | |
1244 | ||
151c468b | 1245 | create_parameterlist($args, ',', $file, $declaration_name); |
1da177e4 LT |
1246 | |
1247 | output_declaration($declaration_name, | |
83766452 MCC |
1248 | 'function', |
1249 | {'function' => $declaration_name, | |
82801d06 | 1250 | 'typedef' => 1, |
1da177e4 | 1251 | 'module' => $modulename, |
83766452 MCC |
1252 | 'functiontype' => $return_type, |
1253 | 'parameterlist' => \@parameterlist, | |
1254 | 'parameterdescs' => \%parameterdescs, | |
1255 | 'parametertypes' => \%parametertypes, | |
1da177e4 LT |
1256 | 'sectionlist' => \@sectionlist, |
1257 | 'sections' => \%sections, | |
1258 | 'purpose' => $declaration_purpose | |
1259 | }); | |
83766452 MCC |
1260 | return; |
1261 | } | |
1262 | ||
1263 | while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { | |
1264 | $x =~ s/\(*.\)\s*;$/;/; | |
1265 | $x =~ s/\[*.\]\s*;$/;/; | |
1da177e4 | 1266 | } |
83766452 MCC |
1267 | |
1268 | if ($x =~ /typedef.*\s+(\w+)\s*;/) { | |
3a80a766 MCC |
1269 | $declaration_name = $1; |
1270 | ||
1271 | output_declaration($declaration_name, | |
1272 | 'typedef', | |
1273 | {'typedef' => $declaration_name, | |
1274 | 'module' => $modulename, | |
1275 | 'sectionlist' => \@sectionlist, | |
1276 | 'sections' => \%sections, | |
1277 | 'purpose' => $declaration_purpose | |
1278 | }); | |
1279 | } | |
1da177e4 | 1280 | else { |
d40e1e65 | 1281 | print STDERR "${file}:$.: error: Cannot parse typedef!\n"; |
1da177e4 LT |
1282 | ++$errors; |
1283 | } | |
1284 | } | |
1285 | ||
a1d94aa5 RD |
1286 | sub save_struct_actual($) { |
1287 | my $actual = shift; | |
1288 | ||
1289 | # strip all spaces from the actual param so that it looks like one string item | |
1290 | $actual =~ s/\s*//g; | |
1291 | $struct_actual = $struct_actual . $actual . " "; | |
1292 | } | |
1293 | ||
151c468b | 1294 | sub create_parameterlist($$$$) { |
1da177e4 LT |
1295 | my $args = shift; |
1296 | my $splitter = shift; | |
1297 | my $file = shift; | |
151c468b | 1298 | my $declaration_name = shift; |
1da177e4 LT |
1299 | my $type; |
1300 | my $param; | |
1301 | ||
a6d3fe77 | 1302 | # temporarily replace commas inside function pointer definition |
1da177e4 | 1303 | while ($args =~ /(\([^\),]+),/) { |
3c308798 | 1304 | $args =~ s/(\([^\),]+),/$1#/g; |
1da177e4 | 1305 | } |
3c3b809e | 1306 | |
1da177e4 LT |
1307 | foreach my $arg (split($splitter, $args)) { |
1308 | # strip comments | |
1309 | $arg =~ s/\/\*.*\*\///; | |
3c308798 RD |
1310 | # strip leading/trailing spaces |
1311 | $arg =~ s/^\s*//; | |
1da177e4 LT |
1312 | $arg =~ s/\s*$//; |
1313 | $arg =~ s/\s+/ /; | |
1314 | ||
1315 | if ($arg =~ /^#/) { | |
1316 | # Treat preprocessor directive as a typeless variable just to fill | |
1317 | # corresponding data structures "correctly". Catch it later in | |
1318 | # output_* subs. | |
1319 | push_parameter($arg, "", $file); | |
00d62961 | 1320 | } elsif ($arg =~ m/\(.+\)\s*\(/) { |
1da177e4 LT |
1321 | # pointer-to-function |
1322 | $arg =~ tr/#/,/; | |
7c0d7e87 | 1323 | $arg =~ m/[^\(]+\(\*?\s*([\w\.]*)\s*\)/; |
1da177e4 LT |
1324 | $param = $1; |
1325 | $type = $arg; | |
00d62961 | 1326 | $type =~ s/([^\(]+\(\*?)\s*$param/$1/; |
a1d94aa5 | 1327 | save_struct_actual($param); |
151c468b | 1328 | push_parameter($param, $type, $file, $declaration_name); |
aeec46b9 | 1329 | } elsif ($arg) { |
1da177e4 LT |
1330 | $arg =~ s/\s*:\s*/:/g; |
1331 | $arg =~ s/\s*\[/\[/g; | |
1332 | ||
1333 | my @args = split('\s*,\s*', $arg); | |
1334 | if ($args[0] =~ m/\*/) { | |
1335 | $args[0] =~ s/(\*+)\s*/ $1/; | |
1336 | } | |
884f2810 BP |
1337 | |
1338 | my @first_arg; | |
1339 | if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) { | |
1340 | shift @args; | |
1341 | push(@first_arg, split('\s+', $1)); | |
1342 | push(@first_arg, $2); | |
1343 | } else { | |
1344 | @first_arg = split('\s+', shift @args); | |
1345 | } | |
1346 | ||
1da177e4 LT |
1347 | unshift(@args, pop @first_arg); |
1348 | $type = join " ", @first_arg; | |
1349 | ||
1350 | foreach $param (@args) { | |
1351 | if ($param =~ m/^(\*+)\s*(.*)/) { | |
a1d94aa5 | 1352 | save_struct_actual($2); |
151c468b | 1353 | push_parameter($2, "$type $1", $file, $declaration_name); |
1da177e4 LT |
1354 | } |
1355 | elsif ($param =~ m/(.*?):(\d+)/) { | |
7b97887e | 1356 | if ($type ne "") { # skip unnamed bit-fields |
a1d94aa5 | 1357 | save_struct_actual($1); |
151c468b | 1358 | push_parameter($1, "$type:$2", $file, $declaration_name) |
7b97887e | 1359 | } |
1da177e4 LT |
1360 | } |
1361 | else { | |
a1d94aa5 | 1362 | save_struct_actual($param); |
151c468b | 1363 | push_parameter($param, $type, $file, $declaration_name); |
1da177e4 LT |
1364 | } |
1365 | } | |
1366 | } | |
1367 | } | |
1368 | } | |
1369 | ||
151c468b | 1370 | sub push_parameter($$$$) { |
1da177e4 LT |
1371 | my $param = shift; |
1372 | my $type = shift; | |
1373 | my $file = shift; | |
151c468b | 1374 | my $declaration_name = shift; |
1da177e4 | 1375 | |
5f8c7c98 RD |
1376 | if (($anon_struct_union == 1) && ($type eq "") && |
1377 | ($param eq "}")) { | |
1378 | return; # ignore the ending }; from anon. struct/union | |
1379 | } | |
1380 | ||
1381 | $anon_struct_union = 0; | |
f9b5c530 | 1382 | $param =~ s/[\[\)].*//; |
1da177e4 | 1383 | |
a6d3fe77 | 1384 | if ($type eq "" && $param =~ /\.\.\.$/) |
1da177e4 | 1385 | { |
c950a173 SF |
1386 | if (!$param =~ /\w\.\.\.$/) { |
1387 | # handles unnamed variable parameters | |
1388 | $param = "..."; | |
1389 | } | |
ced69090 RD |
1390 | if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { |
1391 | $parameterdescs{$param} = "variable arguments"; | |
1392 | } | |
1da177e4 LT |
1393 | } |
1394 | elsif ($type eq "" && ($param eq "" or $param eq "void")) | |
1395 | { | |
1da177e4 LT |
1396 | $param="void"; |
1397 | $parameterdescs{void} = "no arguments"; | |
1398 | } | |
134fe01b RD |
1399 | elsif ($type eq "" && ($param eq "struct" or $param eq "union")) |
1400 | # handle unnamed (anonymous) union or struct: | |
1401 | { | |
1402 | $type = $param; | |
5f8c7c98 | 1403 | $param = "{unnamed_" . $param . "}"; |
134fe01b | 1404 | $parameterdescs{$param} = "anonymous\n"; |
5f8c7c98 | 1405 | $anon_struct_union = 1; |
134fe01b RD |
1406 | } |
1407 | ||
a6d3fe77 | 1408 | # warn if parameter has no description |
134fe01b RD |
1409 | # (but ignore ones starting with # as these are not parameters |
1410 | # but inline preprocessor statements); | |
151c468b | 1411 | # Note: It will also ignore void params and unnamed structs/unions |
f9b5c530 | 1412 | if (!defined $parameterdescs{$param} && $param !~ /^#/) { |
151c468b | 1413 | $parameterdescs{$param} = $undescribed; |
a6d3fe77 | 1414 | |
85afe608 | 1415 | if (show_warnings($type, $declaration_name)) { |
2defb272 MCC |
1416 | print STDERR |
1417 | "${file}:$.: warning: Function parameter or member '$param' not described in '$declaration_name'\n"; | |
1418 | ++$warnings; | |
1419 | } | |
3c308798 | 1420 | } |
1da177e4 | 1421 | |
25985edc | 1422 | # strip spaces from $param so that it is one continuous string |
e34e7dbb RD |
1423 | # on @parameterlist; |
1424 | # this fixes a problem where check_sections() cannot find | |
1425 | # a parameter like "addr[6 + 2]" because it actually appears | |
1426 | # as "addr[6", "+", "2]" on the parameter list; | |
1427 | # but it's better to maintain the param string unchanged for output, | |
1428 | # so just weaken the string compare in check_sections() to ignore | |
1429 | # "[blah" in a parameter string; | |
1430 | ###$param =~ s/\s*//g; | |
1da177e4 | 1431 | push @parameterlist, $param; |
02a4f4fe | 1432 | $type =~ s/\s\s+/ /g; |
1da177e4 LT |
1433 | $parametertypes{$param} = $type; |
1434 | } | |
1435 | ||
1081de2d MCC |
1436 | sub check_sections($$$$$) { |
1437 | my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck) = @_; | |
a1d94aa5 RD |
1438 | my @sects = split ' ', $sectcheck; |
1439 | my @prms = split ' ', $prmscheck; | |
1440 | my $err; | |
1441 | my ($px, $sx); | |
1442 | my $prm_clean; # strip trailing "[array size]" and/or beginning "*" | |
1443 | ||
1444 | foreach $sx (0 .. $#sects) { | |
1445 | $err = 1; | |
1446 | foreach $px (0 .. $#prms) { | |
1447 | $prm_clean = $prms[$px]; | |
1448 | $prm_clean =~ s/\[.*\]//; | |
1f3a6688 | 1449 | $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; |
e34e7dbb RD |
1450 | # ignore array size in a parameter string; |
1451 | # however, the original param string may contain | |
1452 | # spaces, e.g.: addr[6 + 2] | |
1453 | # and this appears in @prms as "addr[6" since the | |
1454 | # parameter list is split at spaces; | |
1455 | # hence just ignore "[..." for the sections check; | |
1456 | $prm_clean =~ s/\[.*//; | |
1457 | ||
a1d94aa5 RD |
1458 | ##$prm_clean =~ s/^\**//; |
1459 | if ($prm_clean eq $sects[$sx]) { | |
1460 | $err = 0; | |
1461 | last; | |
1462 | } | |
1463 | } | |
1464 | if ($err) { | |
1465 | if ($decl_type eq "function") { | |
d40e1e65 | 1466 | print STDERR "${file}:$.: warning: " . |
a1d94aa5 RD |
1467 | "Excess function parameter " . |
1468 | "'$sects[$sx]' " . | |
1469 | "description in '$decl_name'\n"; | |
1470 | ++$warnings; | |
a1d94aa5 RD |
1471 | } |
1472 | } | |
1473 | } | |
1474 | } | |
1475 | ||
4092bac7 YB |
1476 | ## |
1477 | # Checks the section describing the return value of a function. | |
1478 | sub check_return_section { | |
1479 | my $file = shift; | |
1480 | my $declaration_name = shift; | |
1481 | my $return_type = shift; | |
1482 | ||
1483 | # Ignore an empty return type (It's a macro) | |
1484 | # Ignore functions with a "void" return type. (But don't ignore "void *") | |
1485 | if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) { | |
1486 | return; | |
1487 | } | |
1488 | ||
1489 | if (!defined($sections{$section_return}) || | |
1490 | $sections{$section_return} eq "") { | |
d40e1e65 | 1491 | print STDERR "${file}:$.: warning: " . |
4092bac7 YB |
1492 | "No description found for return value of " . |
1493 | "'$declaration_name'\n"; | |
1494 | ++$warnings; | |
1495 | } | |
1496 | } | |
1497 | ||
1da177e4 LT |
1498 | ## |
1499 | # takes a function prototype and the name of the current file being | |
1500 | # processed and spits out all the details stored in the global | |
1501 | # arrays/hashes. | |
1502 | sub dump_function($$) { | |
1503 | my $prototype = shift; | |
1504 | my $file = shift; | |
cbb4d3e6 | 1505 | my $noret = 0; |
1da177e4 LT |
1506 | |
1507 | $prototype =~ s/^static +//; | |
1508 | $prototype =~ s/^extern +//; | |
4dc3b16b | 1509 | $prototype =~ s/^asmlinkage +//; |
1da177e4 LT |
1510 | $prototype =~ s/^inline +//; |
1511 | $prototype =~ s/^__inline__ +//; | |
32e79401 RD |
1512 | $prototype =~ s/^__inline +//; |
1513 | $prototype =~ s/^__always_inline +//; | |
1514 | $prototype =~ s/^noinline +//; | |
74fc5c65 | 1515 | $prototype =~ s/__init +//; |
20072205 | 1516 | $prototype =~ s/__init_or_module +//; |
270a0096 | 1517 | $prototype =~ s/__meminit +//; |
70c95b00 | 1518 | $prototype =~ s/__must_check +//; |
0df7c0e3 | 1519 | $prototype =~ s/__weak +//; |
cbb4d3e6 | 1520 | my $define = $prototype =~ s/^#\s*define\s+//; #ak added |
b1aaa546 PB |
1521 | $prototype =~ s/__attribute__\s*\(\( |
1522 | (?: | |
1523 | [\w\s]++ # attribute name | |
1524 | (?:\([^)]*+\))? # attribute arguments | |
1525 | \s*+,? # optional comma at the end | |
1526 | )+ | |
1527 | \)\)\s+//x; | |
1da177e4 LT |
1528 | |
1529 | # Yes, this truly is vile. We are looking for: | |
1530 | # 1. Return type (may be nothing if we're looking at a macro) | |
1531 | # 2. Function name | |
1532 | # 3. Function parameters. | |
1533 | # | |
1534 | # All the while we have to watch out for function pointer parameters | |
1535 | # (which IIRC is what the two sections are for), C types (these | |
1536 | # regexps don't even start to express all the possibilities), and | |
1537 | # so on. | |
1538 | # | |
1539 | # If you mess with these regexps, it's a good idea to check that | |
1540 | # the following functions' documentation still comes out right: | |
1541 | # - parport_register_device (function pointer parameters) | |
1542 | # - atomic_set (macro) | |
9598f91f | 1543 | # - pci_match_device, __copy_to_user (long return type) |
1da177e4 | 1544 | |
cbb4d3e6 HG |
1545 | if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) { |
1546 | # This is an object-like macro, it has no return type and no parameter | |
1547 | # list. | |
1548 | # Function-like macros are not allowed to have spaces between | |
1549 | # declaration_name and opening parenthesis (notice the \s+). | |
1550 | $return_type = $1; | |
1551 | $declaration_name = $2; | |
1552 | $noret = 1; | |
1553 | } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || | |
1da177e4 | 1554 | $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || |
5a0bc578 | 1555 | $prototype =~ m/^(\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || |
1da177e4 | 1556 | $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || |
94b3e03c | 1557 | $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || |
1da177e4 | 1558 | $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || |
5a0bc578 | 1559 | $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || |
1da177e4 LT |
1560 | $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || |
1561 | $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || | |
5a0bc578 | 1562 | $prototype =~ m/^(\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || |
1da177e4 | 1563 | $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || |
5a0bc578 | 1564 | $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || |
1da177e4 | 1565 | $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || |
5a0bc578 | 1566 | $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || |
9598f91f | 1567 | $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || |
5a0bc578 MW |
1568 | $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || |
1569 | $prototype =~ m/^(\w+\s+\w+\s*\*+\s*\w+\s*\*+\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) { | |
1da177e4 LT |
1570 | $return_type = $1; |
1571 | $declaration_name = $2; | |
1572 | my $args = $3; | |
1573 | ||
151c468b | 1574 | create_parameterlist($args, ',', $file, $declaration_name); |
1da177e4 | 1575 | } else { |
d40e1e65 | 1576 | print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n"; |
1da177e4 LT |
1577 | return; |
1578 | } | |
1579 | ||
a1d94aa5 | 1580 | my $prms = join " ", @parameterlist; |
1081de2d | 1581 | check_sections($file, $declaration_name, "function", $sectcheck, $prms); |
a1d94aa5 | 1582 | |
4092bac7 YB |
1583 | # This check emits a lot of warnings at the moment, because many |
1584 | # functions don't have a 'Return' doc section. So until the number | |
1585 | # of warnings goes sufficiently down, the check is only performed in | |
1586 | # verbose mode. | |
1587 | # TODO: always perform the check. | |
cbb4d3e6 | 1588 | if ($verbose && !$noret) { |
4092bac7 YB |
1589 | check_return_section($file, $declaration_name, $return_type); |
1590 | } | |
1591 | ||
3c3b809e | 1592 | output_declaration($declaration_name, |
1da177e4 LT |
1593 | 'function', |
1594 | {'function' => $declaration_name, | |
1595 | 'module' => $modulename, | |
1596 | 'functiontype' => $return_type, | |
1597 | 'parameterlist' => \@parameterlist, | |
1598 | 'parameterdescs' => \%parameterdescs, | |
1599 | 'parametertypes' => \%parametertypes, | |
1600 | 'sectionlist' => \@sectionlist, | |
1601 | 'sections' => \%sections, | |
1602 | 'purpose' => $declaration_purpose | |
1603 | }); | |
1604 | } | |
1605 | ||
1da177e4 LT |
1606 | sub reset_state { |
1607 | $function = ""; | |
1da177e4 LT |
1608 | %parameterdescs = (); |
1609 | %parametertypes = (); | |
1610 | @parameterlist = (); | |
1611 | %sections = (); | |
1612 | @sectionlist = (); | |
a1d94aa5 RD |
1613 | $sectcheck = ""; |
1614 | $struct_actual = ""; | |
1da177e4 | 1615 | $prototype = ""; |
3c3b809e | 1616 | |
48af606a JN |
1617 | $state = STATE_NORMAL; |
1618 | $inline_doc_state = STATE_INLINE_NA; | |
1da177e4 LT |
1619 | } |
1620 | ||
56afb0f8 JB |
1621 | sub tracepoint_munge($) { |
1622 | my $file = shift; | |
1623 | my $tracepointname = 0; | |
1624 | my $tracepointargs = 0; | |
1625 | ||
3a9089fd | 1626 | if ($prototype =~ m/TRACE_EVENT\((.*?),/) { |
56afb0f8 JB |
1627 | $tracepointname = $1; |
1628 | } | |
3a9089fd JB |
1629 | if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) { |
1630 | $tracepointname = $1; | |
1631 | } | |
1632 | if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) { | |
1633 | $tracepointname = $2; | |
1634 | } | |
1635 | $tracepointname =~ s/^\s+//; #strip leading whitespace | |
1636 | if ($prototype =~ m/TP_PROTO\((.*?)\)/) { | |
56afb0f8 JB |
1637 | $tracepointargs = $1; |
1638 | } | |
1639 | if (($tracepointname eq 0) || ($tracepointargs eq 0)) { | |
d40e1e65 | 1640 | print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n". |
56afb0f8 JB |
1641 | "$prototype\n"; |
1642 | } else { | |
1643 | $prototype = "static inline void trace_$tracepointname($tracepointargs)"; | |
1644 | } | |
1645 | } | |
1646 | ||
b4870bc5 RD |
1647 | sub syscall_munge() { |
1648 | my $void = 0; | |
1649 | ||
7c9aa015 | 1650 | $prototype =~ s@[\r\n]+@ @gos; # strip newlines/CR's |
b4870bc5 RD |
1651 | ## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) { |
1652 | if ($prototype =~ m/SYSCALL_DEFINE0/) { | |
1653 | $void = 1; | |
1654 | ## $prototype = "long sys_$1(void)"; | |
1655 | } | |
1656 | ||
1657 | $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name | |
1658 | if ($prototype =~ m/long (sys_.*?),/) { | |
1659 | $prototype =~ s/,/\(/; | |
1660 | } elsif ($void) { | |
1661 | $prototype =~ s/\)/\(void\)/; | |
1662 | } | |
1663 | ||
1664 | # now delete all of the odd-number commas in $prototype | |
1665 | # so that arg types & arg names don't have a comma between them | |
1666 | my $count = 0; | |
1667 | my $len = length($prototype); | |
1668 | if ($void) { | |
1669 | $len = 0; # skip the for-loop | |
1670 | } | |
1671 | for (my $ix = 0; $ix < $len; $ix++) { | |
1672 | if (substr($prototype, $ix, 1) eq ',') { | |
1673 | $count++; | |
1674 | if ($count % 2 == 1) { | |
1675 | substr($prototype, $ix, 1) = ' '; | |
1676 | } | |
1677 | } | |
1678 | } | |
1679 | } | |
1680 | ||
b7afa92b | 1681 | sub process_proto_function($$) { |
1da177e4 LT |
1682 | my $x = shift; |
1683 | my $file = shift; | |
1684 | ||
51f5a0c8 RD |
1685 | $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line |
1686 | ||
890c78c2 | 1687 | if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) { |
1da177e4 LT |
1688 | # do nothing |
1689 | } | |
1690 | elsif ($x =~ /([^\{]*)/) { | |
3c308798 | 1691 | $prototype .= $1; |
1da177e4 | 1692 | } |
b4870bc5 | 1693 | |
890c78c2 | 1694 | if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) { |
3c308798 | 1695 | $prototype =~ s@/\*.*?\*/@@gos; # strip comments. |
1da177e4 LT |
1696 | $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. |
1697 | $prototype =~ s@^\s+@@gos; # strip leading spaces | |
b4870bc5 RD |
1698 | if ($prototype =~ /SYSCALL_DEFINE/) { |
1699 | syscall_munge(); | |
1700 | } | |
3a9089fd JB |
1701 | if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ || |
1702 | $prototype =~ /DEFINE_SINGLE_EVENT/) | |
1703 | { | |
56afb0f8 JB |
1704 | tracepoint_munge($file); |
1705 | } | |
b4870bc5 | 1706 | dump_function($prototype, $file); |
1da177e4 LT |
1707 | reset_state(); |
1708 | } | |
1709 | } | |
1710 | ||
b7afa92b | 1711 | sub process_proto_type($$) { |
1da177e4 LT |
1712 | my $x = shift; |
1713 | my $file = shift; | |
1714 | ||
1da177e4 LT |
1715 | $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. |
1716 | $x =~ s@^\s+@@gos; # strip leading spaces | |
1717 | $x =~ s@\s+$@@gos; # strip trailing spaces | |
51f5a0c8 RD |
1718 | $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line |
1719 | ||
1da177e4 LT |
1720 | if ($x =~ /^#/) { |
1721 | # To distinguish preprocessor directive from regular declaration later. | |
1722 | $x .= ";"; | |
1723 | } | |
1724 | ||
1725 | while (1) { | |
3c308798 | 1726 | if ( $x =~ /([^{};]*)([{};])(.*)/ ) { |
463a0fdc MH |
1727 | if( length $prototype ) { |
1728 | $prototype .= " " | |
1729 | } | |
1da177e4 LT |
1730 | $prototype .= $1 . $2; |
1731 | ($2 eq '{') && $brcount++; | |
1732 | ($2 eq '}') && $brcount--; | |
1733 | if (($2 eq ';') && ($brcount == 0)) { | |
b9d97328 | 1734 | dump_declaration($prototype, $file); |
1da177e4 | 1735 | reset_state(); |
3c308798 | 1736 | last; |
1da177e4 LT |
1737 | } |
1738 | $x = $3; | |
3c308798 | 1739 | } else { |
1da177e4 LT |
1740 | $prototype .= $x; |
1741 | last; | |
1742 | } | |
1743 | } | |
1744 | } | |
1745 | ||
6b5b55f6 | 1746 | |
1ad560e4 | 1747 | sub map_filename($) { |
2283a117 | 1748 | my $file; |
68f86662 | 1749 | my ($orig_file) = @_; |
1da177e4 | 1750 | |
2283a117 | 1751 | if (defined($ENV{'SRCTREE'})) { |
68f86662 | 1752 | $file = "$ENV{'SRCTREE'}" . "/" . $orig_file; |
1ad560e4 | 1753 | } else { |
68f86662 | 1754 | $file = $orig_file; |
2283a117 | 1755 | } |
1ad560e4 | 1756 | |
1da177e4 LT |
1757 | if (defined($source_map{$file})) { |
1758 | $file = $source_map{$file}; | |
1759 | } | |
1760 | ||
1ad560e4 JN |
1761 | return $file; |
1762 | } | |
1763 | ||
88c2b57d JN |
1764 | sub process_export_file($) { |
1765 | my ($orig_file) = @_; | |
1766 | my $file = map_filename($orig_file); | |
1767 | ||
1768 | if (!open(IN,"<$file")) { | |
1769 | print STDERR "Error: Cannot open file $file\n"; | |
1770 | ++$errors; | |
1771 | return; | |
1772 | } | |
1773 | ||
1774 | while (<IN>) { | |
1775 | if (/$export_symbol/) { | |
1776 | $function_table{$2} = 1; | |
1777 | } | |
1778 | } | |
1779 | ||
1780 | close(IN); | |
1781 | } | |
1782 | ||
1ad560e4 JN |
1783 | sub process_file($) { |
1784 | my $file; | |
1785 | my $identifier; | |
1786 | my $func; | |
1787 | my $descr; | |
1ad560e4 JN |
1788 | my $initial_section_counter = $section_counter; |
1789 | my ($orig_file) = @_; | |
1790 | my $leading_space; | |
1791 | ||
1792 | $file = map_filename($orig_file); | |
1793 | ||
1da177e4 LT |
1794 | if (!open(IN,"<$file")) { |
1795 | print STDERR "Error: Cannot open file $file\n"; | |
1796 | ++$errors; | |
1797 | return; | |
1798 | } | |
1799 | ||
a9e7314b ID |
1800 | $. = 1; |
1801 | ||
1da177e4 LT |
1802 | $section_counter = 0; |
1803 | while (<IN>) { | |
65478428 DS |
1804 | while (s/\\\s*$//) { |
1805 | $_ .= <IN>; | |
1806 | } | |
7c9aa015 MCC |
1807 | # Replace tabs by spaces |
1808 | while ($_ =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {}; | |
48af606a | 1809 | if ($state == STATE_NORMAL) { |
1da177e4 | 1810 | if (/$doc_start/o) { |
48af606a | 1811 | $state = STATE_NAME; # next line is always the function name |
850622df | 1812 | $in_doc_sect = 0; |
0b0f5f29 | 1813 | $declaration_start_line = $. + 1; |
1da177e4 | 1814 | } |
48af606a | 1815 | } elsif ($state == STATE_NAME) {# this line is the function name (always) |
1da177e4 | 1816 | if (/$doc_block/o) { |
48af606a | 1817 | $state = STATE_DOCBLOCK; |
1da177e4 | 1818 | $contents = ""; |
0b0f5f29 SV |
1819 | $new_start_line = $. + 1; |
1820 | ||
1da177e4 LT |
1821 | if ( $1 eq "" ) { |
1822 | $section = $section_intro; | |
1823 | } else { | |
1824 | $section = $1; | |
1825 | } | |
3c308798 | 1826 | } |
1da177e4 LT |
1827 | elsif (/$doc_decl/o) { |
1828 | $identifier = $1; | |
1829 | if (/\s*([\w\s]+?)\s*-/) { | |
1830 | $identifier = $1; | |
1831 | } | |
1832 | ||
17b78717 | 1833 | $state = STATE_BODY; |
0b0f5f29 SV |
1834 | # if there's no @param blocks need to set up default section |
1835 | # here | |
2f4ad40a JN |
1836 | $contents = ""; |
1837 | $section = $section_default; | |
0b0f5f29 | 1838 | $new_start_line = $. + 1; |
1da177e4 | 1839 | if (/-(.*)/) { |
51f5a0c8 | 1840 | # strip leading/trailing/multiple spaces |
a21217da RD |
1841 | $descr= $1; |
1842 | $descr =~ s/^\s*//; | |
1843 | $descr =~ s/\s*$//; | |
12ae6779 | 1844 | $descr =~ s/\s+/ /g; |
0bba924c | 1845 | $declaration_purpose = $descr; |
17b78717 | 1846 | $state = STATE_BODY_MAYBE; |
1da177e4 LT |
1847 | } else { |
1848 | $declaration_purpose = ""; | |
1849 | } | |
77cc23b8 RD |
1850 | |
1851 | if (($declaration_purpose eq "") && $verbose) { | |
d40e1e65 | 1852 | print STDERR "${file}:$.: warning: missing initial short description on line:\n"; |
77cc23b8 RD |
1853 | print STDERR $_; |
1854 | ++$warnings; | |
1855 | } | |
1856 | ||
1da177e4 LT |
1857 | if ($identifier =~ m/^struct/) { |
1858 | $decl_type = 'struct'; | |
1859 | } elsif ($identifier =~ m/^union/) { | |
1860 | $decl_type = 'union'; | |
1861 | } elsif ($identifier =~ m/^enum/) { | |
1862 | $decl_type = 'enum'; | |
1863 | } elsif ($identifier =~ m/^typedef/) { | |
1864 | $decl_type = 'typedef'; | |
1865 | } else { | |
1866 | $decl_type = 'function'; | |
1867 | } | |
1868 | ||
1869 | if ($verbose) { | |
d40e1e65 | 1870 | print STDERR "${file}:$.: info: Scanning doc for $identifier\n"; |
1da177e4 LT |
1871 | } |
1872 | } else { | |
d40e1e65 | 1873 | print STDERR "${file}:$.: warning: Cannot understand $_ on line $.", |
1da177e4 LT |
1874 | " - I thought it was a doc line\n"; |
1875 | ++$warnings; | |
48af606a | 1876 | $state = STATE_NORMAL; |
1da177e4 | 1877 | } |
17b78717 | 1878 | } elsif ($state == STATE_BODY || $state == STATE_BODY_MAYBE) { |
f624adef | 1879 | if (/$doc_sect/i) { # case insensitive for supported section names |
1da177e4 LT |
1880 | $newsection = $1; |
1881 | $newcontents = $2; | |
1882 | ||
f624adef JN |
1883 | # map the supported section names to the canonical names |
1884 | if ($newsection =~ m/^description$/i) { | |
1885 | $newsection = $section_default; | |
1886 | } elsif ($newsection =~ m/^context$/i) { | |
1887 | $newsection = $section_context; | |
1888 | } elsif ($newsection =~ m/^returns?$/i) { | |
1889 | $newsection = $section_return; | |
1890 | } elsif ($newsection =~ m/^\@return$/) { | |
1891 | # special: @return is a section, not a param description | |
1892 | $newsection = $section_return; | |
1893 | } | |
1894 | ||
792aa2f2 | 1895 | if (($contents ne "") && ($contents ne "\n")) { |
850622df | 1896 | if (!$in_doc_sect && $verbose) { |
d40e1e65 | 1897 | print STDERR "${file}:$.: warning: contents before sections\n"; |
850622df RD |
1898 | ++$warnings; |
1899 | } | |
0bba924c | 1900 | dump_section($file, $section, $contents); |
1da177e4 LT |
1901 | $section = $section_default; |
1902 | } | |
1903 | ||
850622df | 1904 | $in_doc_sect = 1; |
17b78717 | 1905 | $state = STATE_BODY; |
1da177e4 | 1906 | $contents = $newcontents; |
0b0f5f29 | 1907 | $new_start_line = $.; |
7c9aa015 | 1908 | while (substr($contents, 0, 1) eq " ") { |
0a726301 JN |
1909 | $contents = substr($contents, 1); |
1910 | } | |
1da177e4 LT |
1911 | if ($contents ne "") { |
1912 | $contents .= "\n"; | |
1913 | } | |
1914 | $section = $newsection; | |
b7886de4 | 1915 | $leading_space = undef; |
1da177e4 | 1916 | } elsif (/$doc_end/) { |
4c98ecaf | 1917 | if (($contents ne "") && ($contents ne "\n")) { |
0bba924c | 1918 | dump_section($file, $section, $contents); |
1da177e4 LT |
1919 | $section = $section_default; |
1920 | $contents = ""; | |
1921 | } | |
46b958eb RD |
1922 | # look for doc_com + <text> + doc_end: |
1923 | if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') { | |
d40e1e65 | 1924 | print STDERR "${file}:$.: warning: suspicious ending line: $_"; |
46b958eb RD |
1925 | ++$warnings; |
1926 | } | |
1da177e4 LT |
1927 | |
1928 | $prototype = ""; | |
48af606a | 1929 | $state = STATE_PROTO; |
1da177e4 | 1930 | $brcount = 0; |
232acbcf | 1931 | # print STDERR "end of doc comment, looking for prototype\n"; |
1da177e4 LT |
1932 | } elsif (/$doc_content/) { |
1933 | # miguel-style comment kludge, look for blank lines after | |
1934 | # @parameter line to signify start of description | |
6423133b JW |
1935 | if ($1 eq "") { |
1936 | if ($section =~ m/^@/ || $section eq $section_context) { | |
0bba924c | 1937 | dump_section($file, $section, $contents); |
6423133b JW |
1938 | $section = $section_default; |
1939 | $contents = ""; | |
0b0f5f29 | 1940 | $new_start_line = $.; |
6423133b JW |
1941 | } else { |
1942 | $contents .= "\n"; | |
1943 | } | |
17b78717 JC |
1944 | $state = STATE_BODY; |
1945 | } elsif ($state == STATE_BODY_MAYBE) { | |
6423133b JW |
1946 | # Continued declaration purpose |
1947 | chomp($declaration_purpose); | |
0bba924c | 1948 | $declaration_purpose .= " " . $1; |
12ae6779 | 1949 | $declaration_purpose =~ s/\s+/ /g; |
1da177e4 | 1950 | } else { |
b7886de4 JN |
1951 | my $cont = $1; |
1952 | if ($section =~ m/^@/ || $section eq $section_context) { | |
1953 | if (!defined $leading_space) { | |
1954 | if ($cont =~ m/^(\s+)/) { | |
1955 | $leading_space = $1; | |
1956 | } else { | |
1957 | $leading_space = ""; | |
1958 | } | |
1959 | } | |
1960 | ||
1961 | $cont =~ s/^$leading_space//; | |
1962 | } | |
1963 | $contents .= $cont . "\n"; | |
1da177e4 LT |
1964 | } |
1965 | } else { | |
1966 | # i dont know - bad line? ignore. | |
d40e1e65 | 1967 | print STDERR "${file}:$.: warning: bad line: $_"; |
1da177e4 LT |
1968 | ++$warnings; |
1969 | } | |
48af606a | 1970 | } elsif ($state == STATE_INLINE) { # scanning for inline parameters |
a4c6ebed | 1971 | # First line (state 1) needs to be a @parameter |
48af606a | 1972 | if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) { |
a4c6ebed DCLP |
1973 | $section = $1; |
1974 | $contents = $2; | |
0b0f5f29 | 1975 | $new_start_line = $.; |
a4c6ebed | 1976 | if ($contents ne "") { |
7c9aa015 | 1977 | while (substr($contents, 0, 1) eq " ") { |
a4c6ebed DCLP |
1978 | $contents = substr($contents, 1); |
1979 | } | |
a0b96c2d | 1980 | $contents .= "\n"; |
a4c6ebed | 1981 | } |
48af606a | 1982 | $inline_doc_state = STATE_INLINE_TEXT; |
a4c6ebed | 1983 | # Documentation block end */ |
48af606a | 1984 | } elsif (/$doc_inline_end/) { |
a4c6ebed | 1985 | if (($contents ne "") && ($contents ne "\n")) { |
0bba924c | 1986 | dump_section($file, $section, $contents); |
a4c6ebed DCLP |
1987 | $section = $section_default; |
1988 | $contents = ""; | |
1989 | } | |
48af606a JN |
1990 | $state = STATE_PROTO; |
1991 | $inline_doc_state = STATE_INLINE_NA; | |
a4c6ebed DCLP |
1992 | # Regular text |
1993 | } elsif (/$doc_content/) { | |
48af606a | 1994 | if ($inline_doc_state == STATE_INLINE_TEXT) { |
a4c6ebed | 1995 | $contents .= $1 . "\n"; |
6450c895 JN |
1996 | # nuke leading blank lines |
1997 | if ($contents =~ /^\s*$/) { | |
1998 | $contents = ""; | |
1999 | } | |
48af606a JN |
2000 | } elsif ($inline_doc_state == STATE_INLINE_NAME) { |
2001 | $inline_doc_state = STATE_INLINE_ERROR; | |
e7ca311e | 2002 | print STDERR "${file}:$.: warning: "; |
a4c6ebed DCLP |
2003 | print STDERR "Incorrect use of kernel-doc format: $_"; |
2004 | ++$warnings; | |
2005 | } | |
2006 | } | |
48af606a | 2007 | } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype) |
0c9aa209 JN |
2008 | if (/$doc_inline_oneline/) { |
2009 | $section = $1; | |
2010 | $contents = $2; | |
2011 | if ($contents ne "") { | |
2012 | $contents .= "\n"; | |
0bba924c | 2013 | dump_section($file, $section, $contents); |
0c9aa209 JN |
2014 | $section = $section_default; |
2015 | $contents = ""; | |
2016 | } | |
2017 | } elsif (/$doc_inline_start/) { | |
48af606a JN |
2018 | $state = STATE_INLINE; |
2019 | $inline_doc_state = STATE_INLINE_NAME; | |
a4c6ebed | 2020 | } elsif ($decl_type eq 'function') { |
b7afa92b | 2021 | process_proto_function($_, $file); |
1da177e4 | 2022 | } else { |
b7afa92b | 2023 | process_proto_type($_, $file); |
1da177e4 | 2024 | } |
48af606a | 2025 | } elsif ($state == STATE_DOCBLOCK) { |
ebff7f92 | 2026 | if (/$doc_end/) |
1da177e4 | 2027 | { |
0bba924c | 2028 | dump_doc_section($file, $section, $contents); |
2f4ad40a | 2029 | $section = $section_default; |
1da177e4 LT |
2030 | $contents = ""; |
2031 | $function = ""; | |
1da177e4 LT |
2032 | %parameterdescs = (); |
2033 | %parametertypes = (); | |
2034 | @parameterlist = (); | |
2035 | %sections = (); | |
2036 | @sectionlist = (); | |
2037 | $prototype = ""; | |
48af606a | 2038 | $state = STATE_NORMAL; |
1da177e4 LT |
2039 | } |
2040 | elsif (/$doc_content/) | |
2041 | { | |
2042 | if ( $1 eq "" ) | |
2043 | { | |
2044 | $contents .= $blankline; | |
2045 | } | |
2046 | else | |
2047 | { | |
2048 | $contents .= $1 . "\n"; | |
3c3b809e | 2049 | } |
3c308798 RD |
2050 | } |
2051 | } | |
1da177e4 LT |
2052 | } |
2053 | if ($initial_section_counter == $section_counter) { | |
3a025e1d MW |
2054 | if ($output_mode ne "none") { |
2055 | print STDERR "${file}:1: warning: no structured comments found\n"; | |
2056 | } | |
b6c3f456 | 2057 | if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) { |
e946c43a JB |
2058 | print STDERR " Was looking for '$_'.\n" for keys %function_table; |
2059 | } | |
1da177e4 LT |
2060 | } |
2061 | } | |
8484baaa RD |
2062 | |
2063 | ||
2064 | $kernelversion = get_kernel_version(); | |
2065 | ||
2066 | # generate a sequence of code that will splice in highlighting information | |
2067 | # using the s// operator. | |
1ef06233 | 2068 | for (my $k = 0; $k < @highlights; $k++) { |
4d732701 DCLP |
2069 | my $pattern = $highlights[$k][0]; |
2070 | my $result = $highlights[$k][1]; | |
2071 | # print STDERR "scanning pattern:$pattern, highlight:($result)\n"; | |
2072 | $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n"; | |
8484baaa RD |
2073 | } |
2074 | ||
2075 | # Read the file that maps relative names to absolute names for | |
2076 | # separate source and object directories and for shadow trees. | |
2077 | if (open(SOURCE_MAP, "<.tmp_filelist.txt")) { | |
2078 | my ($relname, $absname); | |
2079 | while(<SOURCE_MAP>) { | |
2080 | chop(); | |
2081 | ($relname, $absname) = (split())[0..1]; | |
2082 | $relname =~ s:^/+::; | |
2083 | $source_map{$relname} = $absname; | |
2084 | } | |
2085 | close(SOURCE_MAP); | |
2086 | } | |
2087 | ||
88c2b57d JN |
2088 | if ($output_selection == OUTPUT_EXPORTED || |
2089 | $output_selection == OUTPUT_INTERNAL) { | |
c9b2cfb3 JN |
2090 | |
2091 | push(@export_file_list, @ARGV); | |
2092 | ||
88c2b57d JN |
2093 | foreach (@export_file_list) { |
2094 | chomp; | |
2095 | process_export_file($_); | |
2096 | } | |
2097 | } | |
2098 | ||
8484baaa RD |
2099 | foreach (@ARGV) { |
2100 | chomp; | |
2101 | process_file($_); | |
2102 | } | |
2103 | if ($verbose && $errors) { | |
2104 | print STDERR "$errors errors\n"; | |
2105 | } | |
2106 | if ($verbose && $warnings) { | |
2107 | print STDERR "$warnings warnings\n"; | |
2108 | } | |
2109 | ||
e814bccb | 2110 | exit($output_mode eq "none" ? 0 : $errors); |