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