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