11da177e4SLinus Torvalds#!/usr/bin/perl -w 21da177e4SLinus Torvalds 31da177e4SLinus Torvaldsuse strict; 41da177e4SLinus Torvalds 51da177e4SLinus Torvalds## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ## 61da177e4SLinus Torvalds## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ## 71da177e4SLinus Torvalds## Copyright (C) 2001 Simon Huggins ## 8*6b5b55f6SRandy Dunlap## Copyright (C) 2005-2007 Randy Dunlap ## 91da177e4SLinus Torvalds## ## 101da177e4SLinus Torvalds## #define enhancements by Armin Kuster <akuster@mvista.com> ## 111da177e4SLinus Torvalds## Copyright (c) 2000 MontaVista Software, Inc. ## 121da177e4SLinus Torvalds## ## 131da177e4SLinus Torvalds## This software falls under the GNU General Public License. ## 141da177e4SLinus Torvalds## Please read the COPYING file for more information ## 151da177e4SLinus Torvalds 161da177e4SLinus Torvalds# w.o. 03-11-2000: added the '-filelist' option. 171da177e4SLinus Torvalds 181da177e4SLinus Torvalds# 18/01/2001 - Cleanups 191da177e4SLinus Torvalds# Functions prototyped as foo(void) same as foo() 201da177e4SLinus Torvalds# Stop eval'ing where we don't need to. 211da177e4SLinus Torvalds# -- huggie@earth.li 221da177e4SLinus Torvalds 231da177e4SLinus Torvalds# 27/06/2001 - Allowed whitespace after initial "/**" and 241da177e4SLinus Torvalds# allowed comments before function declarations. 251da177e4SLinus Torvalds# -- Christian Kreibich <ck@whoop.org> 261da177e4SLinus Torvalds 271da177e4SLinus Torvalds# Still to do: 281da177e4SLinus Torvalds# - add perldoc documentation 291da177e4SLinus Torvalds# - Look more closely at some of the scarier bits :) 301da177e4SLinus Torvalds 311da177e4SLinus Torvalds# 26/05/2001 - Support for separate source and object trees. 321da177e4SLinus Torvalds# Return error code. 331da177e4SLinus Torvalds# Keith Owens <kaos@ocs.com.au> 341da177e4SLinus Torvalds 351da177e4SLinus Torvalds# 23/09/2001 - Added support for typedefs, structs, enums and unions 361da177e4SLinus Torvalds# Support for Context section; can be terminated using empty line 371da177e4SLinus Torvalds# Small fixes (like spaces vs. \s in regex) 381da177e4SLinus Torvalds# -- Tim Jansen <tim@tjansen.de> 391da177e4SLinus Torvalds 401da177e4SLinus Torvalds 411da177e4SLinus Torvalds# 421da177e4SLinus Torvalds# This will read a 'c' file and scan for embedded comments in the 431da177e4SLinus Torvalds# style of gnome comments (+minor extensions - see below). 441da177e4SLinus Torvalds# 451da177e4SLinus Torvalds 461da177e4SLinus Torvalds# Note: This only supports 'c'. 471da177e4SLinus Torvalds 481da177e4SLinus Torvalds# usage: 49d28bee0cSRandy Dunlap# kernel-doc [ -docbook | -html | -text | -man ] 501da177e4SLinus Torvalds# [ -function funcname [ -function funcname ...] ] c file(s)s > outputfile 511da177e4SLinus Torvalds# or 521da177e4SLinus Torvalds# [ -nofunction funcname [ -function funcname ...] ] c file(s)s > outputfile 531da177e4SLinus Torvalds# 541da177e4SLinus Torvalds# Set output format using one of -docbook -html -text or -man. Default is man. 551da177e4SLinus Torvalds# 561da177e4SLinus Torvalds# -function funcname 571da177e4SLinus Torvalds# If set, then only generate documentation for the given function(s). All 581da177e4SLinus Torvalds# other functions are ignored. 591da177e4SLinus Torvalds# 601da177e4SLinus Torvalds# -nofunction funcname 61a073a8bdSRolf Eike Beer# If set, then only generate documentation for the other function(s). 62a073a8bdSRolf Eike Beer# Cannot be used together with -function 63d28bee0cSRandy Dunlap# (yes, that's a bug -- perl hackers can fix it 8)) 641da177e4SLinus Torvalds# 651da177e4SLinus Torvalds# c files - list of 'c' files to process 661da177e4SLinus Torvalds# 671da177e4SLinus Torvalds# All output goes to stdout, with errors to stderr. 681da177e4SLinus Torvalds 691da177e4SLinus Torvalds# 701da177e4SLinus Torvalds# format of comments. 711da177e4SLinus Torvalds# In the following table, (...)? signifies optional structure. 721da177e4SLinus Torvalds# (...)* signifies 0 or more structure elements 731da177e4SLinus Torvalds# /** 741da177e4SLinus Torvalds# * function_name(:)? (- short description)? 751da177e4SLinus Torvalds# (* @parameterx: (description of parameter x)?)* 761da177e4SLinus Torvalds# (* a blank line)? 771da177e4SLinus Torvalds# * (Description:)? (Description of function)? 781da177e4SLinus Torvalds# * (section header: (section description)? )* 791da177e4SLinus Torvalds# (*)?*/ 801da177e4SLinus Torvalds# 811da177e4SLinus Torvalds# So .. the trivial example would be: 821da177e4SLinus Torvalds# 831da177e4SLinus Torvalds# /** 841da177e4SLinus Torvalds# * my_function 851da177e4SLinus Torvalds# **/ 861da177e4SLinus Torvalds# 87891dcd2fSRandy Dunlap# If the Description: header tag is omitted, then there must be a blank line 881da177e4SLinus Torvalds# after the last parameter specification. 891da177e4SLinus Torvalds# e.g. 901da177e4SLinus Torvalds# /** 911da177e4SLinus Torvalds# * my_function - does my stuff 921da177e4SLinus Torvalds# * @my_arg: its mine damnit 931da177e4SLinus Torvalds# * 941da177e4SLinus Torvalds# * Does my stuff explained. 951da177e4SLinus Torvalds# */ 961da177e4SLinus Torvalds# 971da177e4SLinus Torvalds# or, could also use: 981da177e4SLinus Torvalds# /** 991da177e4SLinus Torvalds# * my_function - does my stuff 1001da177e4SLinus Torvalds# * @my_arg: its mine damnit 1011da177e4SLinus Torvalds# * Description: Does my stuff explained. 1021da177e4SLinus Torvalds# */ 1031da177e4SLinus Torvalds# etc. 1041da177e4SLinus Torvalds# 1051da177e4SLinus Torvalds# Beside functions you can also write documentation for structs, unions, 1061da177e4SLinus Torvalds# enums and typedefs. Instead of the function name you must write the name 1071da177e4SLinus Torvalds# of the declaration; the struct/union/enum/typedef must always precede 1081da177e4SLinus Torvalds# the name. Nesting of declarations is not supported. 1091da177e4SLinus Torvalds# Use the argument mechanism to document members or constants. 1101da177e4SLinus Torvalds# e.g. 1111da177e4SLinus Torvalds# /** 1121da177e4SLinus Torvalds# * struct my_struct - short description 1131da177e4SLinus Torvalds# * @a: first member 1141da177e4SLinus Torvalds# * @b: second member 1151da177e4SLinus Torvalds# * 1161da177e4SLinus Torvalds# * Longer description 1171da177e4SLinus Torvalds# */ 1181da177e4SLinus Torvalds# struct my_struct { 1191da177e4SLinus Torvalds# int a; 1201da177e4SLinus Torvalds# int b; 121aeec46b9SMartin Waitz# /* private: */ 122aeec46b9SMartin Waitz# int c; 1231da177e4SLinus Torvalds# }; 1241da177e4SLinus Torvalds# 1251da177e4SLinus Torvalds# All descriptions can be multiline, except the short function description. 1261da177e4SLinus Torvalds# 1271da177e4SLinus Torvalds# You can also add additional sections. When documenting kernel functions you 1281da177e4SLinus Torvalds# should document the "Context:" of the function, e.g. whether the functions 1291da177e4SLinus Torvalds# can be called form interrupts. Unlike other sections you can end it with an 1301da177e4SLinus Torvalds# empty line. 1311da177e4SLinus Torvalds# Example-sections should contain the string EXAMPLE so that they are marked 1321da177e4SLinus Torvalds# appropriately in DocBook. 1331da177e4SLinus Torvalds# 1341da177e4SLinus Torvalds# Example: 1351da177e4SLinus Torvalds# /** 1361da177e4SLinus Torvalds# * user_function - function that can only be called in user context 1371da177e4SLinus Torvalds# * @a: some argument 1381da177e4SLinus Torvalds# * Context: !in_interrupt() 1391da177e4SLinus Torvalds# * 1401da177e4SLinus Torvalds# * Some description 1411da177e4SLinus Torvalds# * Example: 1421da177e4SLinus Torvalds# * user_function(22); 1431da177e4SLinus Torvalds# */ 1441da177e4SLinus Torvalds# ... 1451da177e4SLinus Torvalds# 1461da177e4SLinus Torvalds# 1471da177e4SLinus Torvalds# All descriptive text is further processed, scanning for the following special 1481da177e4SLinus Torvalds# patterns, which are highlighted appropriately. 1491da177e4SLinus Torvalds# 1501da177e4SLinus Torvalds# 'funcname()' - function 1511da177e4SLinus Torvalds# '$ENVVAR' - environmental variable 1521da177e4SLinus Torvalds# '&struct_name' - name of a structure (up to two words including 'struct') 1531da177e4SLinus Torvalds# '@parameter' - name of a parameter 1541da177e4SLinus Torvalds# '%CONST' - name of a constant. 1551da177e4SLinus Torvalds 1561da177e4SLinus Torvaldsmy $errors = 0; 1571da177e4SLinus Torvaldsmy $warnings = 0; 1585f8c7c98SRandy Dunlapmy $anon_struct_union = 0; 1591da177e4SLinus Torvalds 1601da177e4SLinus Torvalds# match expressions used to find embedded type information 1611da177e4SLinus Torvaldsmy $type_constant = '\%([-_\w]+)'; 1621da177e4SLinus Torvaldsmy $type_func = '(\w+)\(\)'; 1631da177e4SLinus Torvaldsmy $type_param = '\@(\w+)'; 1643eb014a1SRandy Dunlapmy $type_struct = '\&((struct\s*)*[_\w]+)'; 165*6b5b55f6SRandy Dunlapmy $type_struct_xml = '\\&((struct\s*)*[_\w]+)'; 1661da177e4SLinus Torvaldsmy $type_env = '(\$\w+)'; 1671da177e4SLinus Torvalds 1681da177e4SLinus Torvalds# Output conversion substitutions. 1691da177e4SLinus Torvalds# One for each output format 1701da177e4SLinus Torvalds 1711da177e4SLinus Torvalds# these work fairly well 1721da177e4SLinus Torvaldsmy %highlights_html = ( $type_constant, "<i>\$1</i>", 1731da177e4SLinus Torvalds $type_func, "<b>\$1</b>", 1743eb014a1SRandy Dunlap $type_struct_xml, "<i>\$1</i>", 1753eb014a1SRandy Dunlap $type_env, "<b><i>\$1</i></b>", 1761da177e4SLinus Torvalds $type_param, "<tt><b>\$1</b></tt>" ); 177*6b5b55f6SRandy Dunlapmy $local_lt = "\\\\\\\\lt:"; 178*6b5b55f6SRandy Dunlapmy $local_gt = "\\\\\\\\gt:"; 179*6b5b55f6SRandy Dunlapmy $blankline_html = $local_lt . "p" . $local_gt; # was "<p>" 1801da177e4SLinus Torvalds 1811da177e4SLinus Torvalds# XML, docbook format 1821da177e4SLinus Torvaldsmy %highlights_xml = ( "([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>", 1831da177e4SLinus Torvalds $type_constant, "<constant>\$1</constant>", 1841da177e4SLinus Torvalds $type_func, "<function>\$1</function>", 1851da177e4SLinus Torvalds $type_struct, "<structname>\$1</structname>", 1861da177e4SLinus Torvalds $type_env, "<envar>\$1</envar>", 1871da177e4SLinus Torvalds $type_param, "<parameter>\$1</parameter>" ); 1881da177e4SLinus Torvaldsmy $blankline_xml = "</para><para>\n"; 1891da177e4SLinus Torvalds 1901da177e4SLinus Torvalds# gnome, docbook format 1911da177e4SLinus Torvaldsmy %highlights_gnome = ( $type_constant, "<replaceable class=\"option\">\$1</replaceable>", 1921da177e4SLinus Torvalds $type_func, "<function>\$1</function>", 1931da177e4SLinus Torvalds $type_struct, "<structname>\$1</structname>", 1941da177e4SLinus Torvalds $type_env, "<envar>\$1</envar>", 1951da177e4SLinus Torvalds $type_param, "<parameter>\$1</parameter>" ); 1961da177e4SLinus Torvaldsmy $blankline_gnome = "</para><para>\n"; 1971da177e4SLinus Torvalds 1981da177e4SLinus Torvalds# these are pretty rough 1991da177e4SLinus Torvaldsmy %highlights_man = ( $type_constant, "\$1", 2001da177e4SLinus Torvalds $type_func, "\\\\fB\$1\\\\fP", 2011da177e4SLinus Torvalds $type_struct, "\\\\fI\$1\\\\fP", 2021da177e4SLinus Torvalds $type_param, "\\\\fI\$1\\\\fP" ); 2031da177e4SLinus Torvaldsmy $blankline_man = ""; 2041da177e4SLinus Torvalds 2051da177e4SLinus Torvalds# text-mode 2061da177e4SLinus Torvaldsmy %highlights_text = ( $type_constant, "\$1", 2071da177e4SLinus Torvalds $type_func, "\$1", 2081da177e4SLinus Torvalds $type_struct, "\$1", 2091da177e4SLinus Torvalds $type_param, "\$1" ); 2101da177e4SLinus Torvaldsmy $blankline_text = ""; 2111da177e4SLinus Torvalds 2121da177e4SLinus Torvalds 2131da177e4SLinus Torvaldssub usage { 2141da177e4SLinus Torvalds print "Usage: $0 [ -v ] [ -docbook | -html | -text | -man ]\n"; 2151da177e4SLinus Torvalds print " [ -function funcname [ -function funcname ...] ]\n"; 2161da177e4SLinus Torvalds print " [ -nofunction funcname [ -nofunction funcname ...] ]\n"; 2171da177e4SLinus Torvalds print " c source file(s) > outputfile\n"; 2181da177e4SLinus Torvalds exit 1; 2191da177e4SLinus Torvalds} 2201da177e4SLinus Torvalds 2211da177e4SLinus Torvalds# read arguments 2221da177e4SLinus Torvaldsif ($#ARGV==-1) { 2231da177e4SLinus Torvalds usage(); 2241da177e4SLinus Torvalds} 2251da177e4SLinus Torvalds 2261da177e4SLinus Torvaldsmy $verbose = 0; 2271da177e4SLinus Torvaldsmy $output_mode = "man"; 2281da177e4SLinus Torvaldsmy %highlights = %highlights_man; 2291da177e4SLinus Torvaldsmy $blankline = $blankline_man; 2301da177e4SLinus Torvaldsmy $modulename = "Kernel API"; 2311da177e4SLinus Torvaldsmy $function_only = 0; 2321da177e4SLinus Torvaldsmy $man_date = ('January', 'February', 'March', 'April', 'May', 'June', 2331da177e4SLinus Torvalds 'July', 'August', 'September', 'October', 2341da177e4SLinus Torvalds 'November', 'December')[(localtime)[4]] . 2351da177e4SLinus Torvalds " " . ((localtime)[5]+1900); 2361da177e4SLinus Torvalds 2371da177e4SLinus Torvalds# Essentially these are globals 2381da177e4SLinus Torvalds# They probably want to be tidied up made more localised or summat. 2391da177e4SLinus Torvalds# CAVEAT EMPTOR! Some of the others I localised may not want to be which 2401da177e4SLinus Torvalds# could cause "use of undefined value" or other bugs. 2411da177e4SLinus Torvaldsmy ($function, %function_table,%parametertypes,$declaration_purpose); 2421da177e4SLinus Torvaldsmy ($type,$declaration_name,$return_type); 2431da177e4SLinus Torvaldsmy ($newsection,$newcontents,$prototype,$filelist, $brcount, %source_map); 2441da177e4SLinus Torvalds 2451da177e4SLinus Torvalds# Generated docbook code is inserted in a template at a point where 2461da177e4SLinus Torvalds# docbook v3.1 requires a non-zero sequence of RefEntry's; see: 2471da177e4SLinus Torvalds# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html 2481da177e4SLinus Torvalds# We keep track of number of generated entries and generate a dummy 2491da177e4SLinus Torvalds# if needs be to ensure the expanded template can be postprocessed 2501da177e4SLinus Torvalds# into html. 2511da177e4SLinus Torvaldsmy $section_counter = 0; 2521da177e4SLinus Torvalds 2531da177e4SLinus Torvaldsmy $lineprefix=""; 2541da177e4SLinus Torvalds 2551da177e4SLinus Torvalds# states 2561da177e4SLinus Torvalds# 0 - normal code 2571da177e4SLinus Torvalds# 1 - looking for function name 2581da177e4SLinus Torvalds# 2 - scanning field start. 2591da177e4SLinus Torvalds# 3 - scanning prototype. 2601da177e4SLinus Torvalds# 4 - documentation block 2611da177e4SLinus Torvaldsmy $state; 262850622dfSRandy Dunlapmy $in_doc_sect; 2631da177e4SLinus Torvalds 2641da177e4SLinus Torvalds#declaration types: can be 2651da177e4SLinus Torvalds# 'function', 'struct', 'union', 'enum', 'typedef' 2661da177e4SLinus Torvaldsmy $decl_type; 2671da177e4SLinus Torvalds 2681da177e4SLinus Torvaldsmy $doc_special = "\@\%\$\&"; 2691da177e4SLinus Torvalds 2701da177e4SLinus Torvaldsmy $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start. 2711da177e4SLinus Torvaldsmy $doc_end = '\*/'; 2721da177e4SLinus Torvaldsmy $doc_com = '\s*\*\s*'; 2731da177e4SLinus Torvaldsmy $doc_decl = $doc_com.'(\w+)'; 274891dcd2fSRandy Dunlapmy $doc_sect = $doc_com.'(['.$doc_special.']?[\w\s]+):(.*)'; 2751da177e4SLinus Torvaldsmy $doc_content = $doc_com.'(.*)'; 2761da177e4SLinus Torvaldsmy $doc_block = $doc_com.'DOC:\s*(.*)?'; 2771da177e4SLinus Torvalds 2781da177e4SLinus Torvaldsmy %constants; 2791da177e4SLinus Torvaldsmy %parameterdescs; 2801da177e4SLinus Torvaldsmy @parameterlist; 2811da177e4SLinus Torvaldsmy %sections; 2821da177e4SLinus Torvaldsmy @sectionlist; 2831da177e4SLinus Torvalds 2841da177e4SLinus Torvaldsmy $contents = ""; 2851da177e4SLinus Torvaldsmy $section_default = "Description"; # default section 2861da177e4SLinus Torvaldsmy $section_intro = "Introduction"; 2871da177e4SLinus Torvaldsmy $section = $section_default; 2881da177e4SLinus Torvaldsmy $section_context = "Context"; 2891da177e4SLinus Torvalds 2901da177e4SLinus Torvaldsmy $undescribed = "-- undescribed --"; 2911da177e4SLinus Torvalds 2921da177e4SLinus Torvaldsreset_state(); 2931da177e4SLinus Torvalds 2941da177e4SLinus Torvaldswhile ($ARGV[0] =~ m/^-(.*)/) { 2951da177e4SLinus Torvalds my $cmd = shift @ARGV; 2961da177e4SLinus Torvalds if ($cmd eq "-html") { 2971da177e4SLinus Torvalds $output_mode = "html"; 2981da177e4SLinus Torvalds %highlights = %highlights_html; 2991da177e4SLinus Torvalds $blankline = $blankline_html; 3001da177e4SLinus Torvalds } elsif ($cmd eq "-man") { 3011da177e4SLinus Torvalds $output_mode = "man"; 3021da177e4SLinus Torvalds %highlights = %highlights_man; 3031da177e4SLinus Torvalds $blankline = $blankline_man; 3041da177e4SLinus Torvalds } elsif ($cmd eq "-text") { 3051da177e4SLinus Torvalds $output_mode = "text"; 3061da177e4SLinus Torvalds %highlights = %highlights_text; 3071da177e4SLinus Torvalds $blankline = $blankline_text; 3081da177e4SLinus Torvalds } elsif ($cmd eq "-docbook") { 3091da177e4SLinus Torvalds $output_mode = "xml"; 3101da177e4SLinus Torvalds %highlights = %highlights_xml; 3111da177e4SLinus Torvalds $blankline = $blankline_xml; 3121da177e4SLinus Torvalds } elsif ($cmd eq "-gnome") { 3131da177e4SLinus Torvalds $output_mode = "gnome"; 3141da177e4SLinus Torvalds %highlights = %highlights_gnome; 3151da177e4SLinus Torvalds $blankline = $blankline_gnome; 3161da177e4SLinus Torvalds } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document 3171da177e4SLinus Torvalds $modulename = shift @ARGV; 3181da177e4SLinus Torvalds } elsif ($cmd eq "-function") { # to only output specific functions 3191da177e4SLinus Torvalds $function_only = 1; 3201da177e4SLinus Torvalds $function = shift @ARGV; 3211da177e4SLinus Torvalds $function_table{$function} = 1; 3221da177e4SLinus Torvalds } elsif ($cmd eq "-nofunction") { # to only output specific functions 3231da177e4SLinus Torvalds $function_only = 2; 3241da177e4SLinus Torvalds $function = shift @ARGV; 3251da177e4SLinus Torvalds $function_table{$function} = 1; 3261da177e4SLinus Torvalds } elsif ($cmd eq "-v") { 3271da177e4SLinus Torvalds $verbose = 1; 3281da177e4SLinus Torvalds } elsif (($cmd eq "-h") || ($cmd eq "--help")) { 3291da177e4SLinus Torvalds usage(); 3301da177e4SLinus Torvalds } elsif ($cmd eq '-filelist') { 3311da177e4SLinus Torvalds $filelist = shift @ARGV; 3321da177e4SLinus Torvalds } 3331da177e4SLinus Torvalds} 3341da177e4SLinus Torvalds 33553f049faSBorislav Petkov# get kernel version from env 33653f049faSBorislav Petkovsub get_kernel_version() { 33753f049faSBorislav Petkov my $version; 33853f049faSBorislav Petkov 33953f049faSBorislav Petkov if (defined($ENV{'KERNELVERSION'})) { 34053f049faSBorislav Petkov $version = $ENV{'KERNELVERSION'}; 34153f049faSBorislav Petkov } 34253f049faSBorislav Petkov return $version; 34353f049faSBorislav Petkov} 3440366299bSBorislav Petkovmy $kernelversion = get_kernel_version(); 3451da177e4SLinus Torvalds 3461da177e4SLinus Torvalds# generate a sequence of code that will splice in highlighting information 3471da177e4SLinus Torvalds# using the s// operator. 3481da177e4SLinus Torvaldsmy $dohighlight = ""; 3491da177e4SLinus Torvaldsforeach my $pattern (keys %highlights) { 3503eb014a1SRandy Dunlap# print STDERR "scanning pattern:$pattern, highlight:($highlights{$pattern})\n"; 3511da177e4SLinus Torvalds $dohighlight .= "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n"; 3521da177e4SLinus Torvalds} 3531da177e4SLinus Torvalds 3541da177e4SLinus Torvalds## 3551da177e4SLinus Torvalds# dumps section contents to arrays/hashes intended for that purpose. 3561da177e4SLinus Torvalds# 3571da177e4SLinus Torvaldssub dump_section { 3581da177e4SLinus Torvalds my $name = shift; 3591da177e4SLinus Torvalds my $contents = join "\n", @_; 3601da177e4SLinus Torvalds 3611da177e4SLinus Torvalds if ($name =~ m/$type_constant/) { 3621da177e4SLinus Torvalds $name = $1; 3631da177e4SLinus Torvalds# print STDERR "constant section '$1' = '$contents'\n"; 3641da177e4SLinus Torvalds $constants{$name} = $contents; 3651da177e4SLinus Torvalds } elsif ($name =~ m/$type_param/) { 3661da177e4SLinus Torvalds# print STDERR "parameter def '$1' = '$contents'\n"; 3671da177e4SLinus Torvalds $name = $1; 3681da177e4SLinus Torvalds $parameterdescs{$name} = $contents; 3691da177e4SLinus Torvalds } else { 3701da177e4SLinus Torvalds# print STDERR "other section '$name' = '$contents'\n"; 3711da177e4SLinus Torvalds $sections{$name} = $contents; 3721da177e4SLinus Torvalds push @sectionlist, $name; 3731da177e4SLinus Torvalds } 3741da177e4SLinus Torvalds} 3751da177e4SLinus Torvalds 3761da177e4SLinus Torvalds## 3771da177e4SLinus Torvalds# output function 3781da177e4SLinus Torvalds# 3791da177e4SLinus Torvalds# parameterdescs, a hash. 3801da177e4SLinus Torvalds# function => "function name" 3811da177e4SLinus Torvalds# parameterlist => @list of parameters 3821da177e4SLinus Torvalds# parameterdescs => %parameter descriptions 3831da177e4SLinus Torvalds# sectionlist => @list of sections 384a21217daSRandy Dunlap# sections => %section descriptions 3851da177e4SLinus Torvalds# 3861da177e4SLinus Torvalds 3871da177e4SLinus Torvaldssub output_highlight { 3881da177e4SLinus Torvalds my $contents = join "\n",@_; 3891da177e4SLinus Torvalds my $line; 3901da177e4SLinus Torvalds 3911da177e4SLinus Torvalds# DEBUG 3921da177e4SLinus Torvalds# if (!defined $contents) { 3931da177e4SLinus Torvalds# use Carp; 3941da177e4SLinus Torvalds# confess "output_highlight got called with no args?\n"; 3951da177e4SLinus Torvalds# } 3961da177e4SLinus Torvalds 397*6b5b55f6SRandy Dunlap if ($output_mode eq "html") { 398*6b5b55f6SRandy Dunlap $contents = local_unescape($contents); 399*6b5b55f6SRandy Dunlap # convert data read & converted thru xml_escape() into &xyz; format: 400*6b5b55f6SRandy Dunlap $contents =~ s/\\\\\\/&/g; 401*6b5b55f6SRandy Dunlap } 4023eb014a1SRandy Dunlap# print STDERR "contents b4:$contents\n"; 4031da177e4SLinus Torvalds eval $dohighlight; 4041da177e4SLinus Torvalds die $@ if $@; 4053eb014a1SRandy Dunlap# print STDERR "contents af:$contents\n"; 4063eb014a1SRandy Dunlap 4071da177e4SLinus Torvalds foreach $line (split "\n", $contents) { 4081da177e4SLinus Torvalds if ($line eq ""){ 409*6b5b55f6SRandy Dunlap print $lineprefix, local_unescape($blankline); 4101da177e4SLinus Torvalds } else { 4111da177e4SLinus Torvalds $line =~ s/\\\\\\/\&/g; 412cdccb316SRandy Dunlap if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { 413cdccb316SRandy Dunlap print "\\&$line"; 414cdccb316SRandy Dunlap } else { 4151da177e4SLinus Torvalds print $lineprefix, $line; 4161da177e4SLinus Torvalds } 417cdccb316SRandy Dunlap } 4181da177e4SLinus Torvalds print "\n"; 4191da177e4SLinus Torvalds } 4201da177e4SLinus Torvalds} 4211da177e4SLinus Torvalds 4221da177e4SLinus Torvalds#output sections in html 4231da177e4SLinus Torvaldssub output_section_html(%) { 4241da177e4SLinus Torvalds my %args = %{$_[0]}; 4251da177e4SLinus Torvalds my $section; 4261da177e4SLinus Torvalds 4271da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 4281da177e4SLinus Torvalds print "<h3>$section</h3>\n"; 4291da177e4SLinus Torvalds print "<blockquote>\n"; 4301da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 4311da177e4SLinus Torvalds print "</blockquote>\n"; 4321da177e4SLinus Torvalds } 4331da177e4SLinus Torvalds} 4341da177e4SLinus Torvalds 4351da177e4SLinus Torvalds# output enum in html 4361da177e4SLinus Torvaldssub output_enum_html(%) { 4371da177e4SLinus Torvalds my %args = %{$_[0]}; 4381da177e4SLinus Torvalds my ($parameter); 4391da177e4SLinus Torvalds my $count; 4401da177e4SLinus Torvalds print "<h2>enum ".$args{'enum'}."</h2>\n"; 4411da177e4SLinus Torvalds 4421da177e4SLinus Torvalds print "<b>enum ".$args{'enum'}."</b> {<br>\n"; 4431da177e4SLinus Torvalds $count = 0; 4441da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 4451da177e4SLinus Torvalds print " <b>".$parameter."</b>"; 4461da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 4471da177e4SLinus Torvalds $count++; 4481da177e4SLinus Torvalds print ",\n"; 4491da177e4SLinus Torvalds } 4501da177e4SLinus Torvalds print "<br>"; 4511da177e4SLinus Torvalds } 4521da177e4SLinus Torvalds print "};<br>\n"; 4531da177e4SLinus Torvalds 4541da177e4SLinus Torvalds print "<h3>Constants</h3>\n"; 4551da177e4SLinus Torvalds print "<dl>\n"; 4561da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 4571da177e4SLinus Torvalds print "<dt><b>".$parameter."</b>\n"; 4581da177e4SLinus Torvalds print "<dd>"; 4591da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter}); 4601da177e4SLinus Torvalds } 4611da177e4SLinus Torvalds print "</dl>\n"; 4621da177e4SLinus Torvalds output_section_html(@_); 4631da177e4SLinus Torvalds print "<hr>\n"; 4641da177e4SLinus Torvalds} 4651da177e4SLinus Torvalds 466d28bee0cSRandy Dunlap# output typedef in html 4671da177e4SLinus Torvaldssub output_typedef_html(%) { 4681da177e4SLinus Torvalds my %args = %{$_[0]}; 4691da177e4SLinus Torvalds my ($parameter); 4701da177e4SLinus Torvalds my $count; 4711da177e4SLinus Torvalds print "<h2>typedef ".$args{'typedef'}."</h2>\n"; 4721da177e4SLinus Torvalds 4731da177e4SLinus Torvalds print "<b>typedef ".$args{'typedef'}."</b>\n"; 4741da177e4SLinus Torvalds output_section_html(@_); 4751da177e4SLinus Torvalds print "<hr>\n"; 4761da177e4SLinus Torvalds} 4771da177e4SLinus Torvalds 4781da177e4SLinus Torvalds# output struct in html 4791da177e4SLinus Torvaldssub output_struct_html(%) { 4801da177e4SLinus Torvalds my %args = %{$_[0]}; 4811da177e4SLinus Torvalds my ($parameter); 4821da177e4SLinus Torvalds 483262d9b01SRandy Dunlap print "<h2>".$args{'type'}." ".$args{'struct'}. " - " .$args{'purpose'}."</h2>\n"; 4841da177e4SLinus Torvalds print "<b>".$args{'type'}." ".$args{'struct'}."</b> {<br>\n"; 4851da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 4861da177e4SLinus Torvalds if ($parameter =~ /^#/) { 4871da177e4SLinus Torvalds print "$parameter<br>\n"; 4881da177e4SLinus Torvalds next; 4891da177e4SLinus Torvalds } 4901da177e4SLinus Torvalds my $parameter_name = $parameter; 4911da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 4921da177e4SLinus Torvalds 4931da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 4941da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 4951da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 4961da177e4SLinus Torvalds # pointer-to-function 4973eb014a1SRandy Dunlap print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n"; 4981da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 4993eb014a1SRandy Dunlap # bitfield 5003eb014a1SRandy Dunlap print " <i>$1</i> <b>$parameter</b>$2;<br>\n"; 5011da177e4SLinus Torvalds } else { 5023eb014a1SRandy Dunlap print " <i>$type</i> <b>$parameter</b>;<br>\n"; 5031da177e4SLinus Torvalds } 5041da177e4SLinus Torvalds } 5051da177e4SLinus Torvalds print "};<br>\n"; 5061da177e4SLinus Torvalds 5071da177e4SLinus Torvalds print "<h3>Members</h3>\n"; 5081da177e4SLinus Torvalds print "<dl>\n"; 5091da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 5101da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 5111da177e4SLinus Torvalds 5121da177e4SLinus Torvalds my $parameter_name = $parameter; 5131da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 5141da177e4SLinus Torvalds 5151da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 5161da177e4SLinus Torvalds print "<dt><b>".$parameter."</b>\n"; 5171da177e4SLinus Torvalds print "<dd>"; 5181da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 5191da177e4SLinus Torvalds } 5201da177e4SLinus Torvalds print "</dl>\n"; 5211da177e4SLinus Torvalds output_section_html(@_); 5221da177e4SLinus Torvalds print "<hr>\n"; 5231da177e4SLinus Torvalds} 5241da177e4SLinus Torvalds 5251da177e4SLinus Torvalds# output function in html 5261da177e4SLinus Torvaldssub output_function_html(%) { 5271da177e4SLinus Torvalds my %args = %{$_[0]}; 5281da177e4SLinus Torvalds my ($parameter, $section); 5291da177e4SLinus Torvalds my $count; 5301da177e4SLinus Torvalds 531262d9b01SRandy Dunlap print "<h2>" .$args{'function'}." - ".$args{'purpose'}."</h2>\n"; 5321da177e4SLinus Torvalds print "<i>".$args{'functiontype'}."</i>\n"; 5331da177e4SLinus Torvalds print "<b>".$args{'function'}."</b>\n"; 5341da177e4SLinus Torvalds print "("; 5351da177e4SLinus Torvalds $count = 0; 5361da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 5371da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 5381da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 5391da177e4SLinus Torvalds # pointer-to-function 5401da177e4SLinus Torvalds print "<i>$1</i><b>$parameter</b>) <i>($2)</i>"; 5411da177e4SLinus Torvalds } else { 5421da177e4SLinus Torvalds print "<i>".$type."</i> <b>".$parameter."</b>"; 5431da177e4SLinus Torvalds } 5441da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 5451da177e4SLinus Torvalds $count++; 5461da177e4SLinus Torvalds print ",\n"; 5471da177e4SLinus Torvalds } 5481da177e4SLinus Torvalds } 5491da177e4SLinus Torvalds print ")\n"; 5501da177e4SLinus Torvalds 5511da177e4SLinus Torvalds print "<h3>Arguments</h3>\n"; 5521da177e4SLinus Torvalds print "<dl>\n"; 5531da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 5541da177e4SLinus Torvalds my $parameter_name = $parameter; 5551da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 5561da177e4SLinus Torvalds 5571da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 5581da177e4SLinus Torvalds print "<dt><b>".$parameter."</b>\n"; 5591da177e4SLinus Torvalds print "<dd>"; 5601da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 5611da177e4SLinus Torvalds } 5621da177e4SLinus Torvalds print "</dl>\n"; 5631da177e4SLinus Torvalds output_section_html(@_); 5641da177e4SLinus Torvalds print "<hr>\n"; 5651da177e4SLinus Torvalds} 5661da177e4SLinus Torvalds 5671da177e4SLinus Torvalds# output intro in html 5681da177e4SLinus Torvaldssub output_intro_html(%) { 5691da177e4SLinus Torvalds my %args = %{$_[0]}; 5701da177e4SLinus Torvalds my ($parameter, $section); 5711da177e4SLinus Torvalds my $count; 5721da177e4SLinus Torvalds 5731da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 5741da177e4SLinus Torvalds print "<h3>$section</h3>\n"; 5751da177e4SLinus Torvalds print "<ul>\n"; 5761da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 5771da177e4SLinus Torvalds print "</ul>\n"; 5781da177e4SLinus Torvalds } 5791da177e4SLinus Torvalds print "<hr>\n"; 5801da177e4SLinus Torvalds} 5811da177e4SLinus Torvalds 5821da177e4SLinus Torvaldssub output_section_xml(%) { 5831da177e4SLinus Torvalds my %args = %{$_[0]}; 5841da177e4SLinus Torvalds my $section; 5851da177e4SLinus Torvalds # print out each section 5861da177e4SLinus Torvalds $lineprefix=" "; 5871da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 588c73894c1SRich Walker print "<refsect1>\n"; 589c73894c1SRich Walker print "<title>$section</title>\n"; 5901da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 591c73894c1SRich Walker print "<informalexample><programlisting>\n"; 592c73894c1SRich Walker } else { 593c73894c1SRich Walker print "<para>\n"; 5941da177e4SLinus Torvalds } 5951da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 5961da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 597c73894c1SRich Walker print "</programlisting></informalexample>\n"; 598c73894c1SRich Walker } else { 599c73894c1SRich Walker print "</para>\n"; 6001da177e4SLinus Torvalds } 601c73894c1SRich Walker print "</refsect1>\n"; 6021da177e4SLinus Torvalds } 6031da177e4SLinus Torvalds} 6041da177e4SLinus Torvalds 6051da177e4SLinus Torvalds# output function in XML DocBook 6061da177e4SLinus Torvaldssub output_function_xml(%) { 6071da177e4SLinus Torvalds my %args = %{$_[0]}; 6081da177e4SLinus Torvalds my ($parameter, $section); 6091da177e4SLinus Torvalds my $count; 6101da177e4SLinus Torvalds my $id; 6111da177e4SLinus Torvalds 6121da177e4SLinus Torvalds $id = "API-".$args{'function'}; 6131da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 6141da177e4SLinus Torvalds 6155449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 6168b0c2d98SMartin Waitz print "<refentryinfo>\n"; 6178b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 6188b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 6198b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 6208b0c2d98SMartin Waitz print "</refentryinfo>\n"; 6211da177e4SLinus Torvalds print "<refmeta>\n"; 6225449bc94SPavel Pisa print " <refentrytitle><phrase>".$args{'function'}."</phrase></refentrytitle>\n"; 6238b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 6240366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 6251da177e4SLinus Torvalds print "</refmeta>\n"; 6261da177e4SLinus Torvalds print "<refnamediv>\n"; 6271da177e4SLinus Torvalds print " <refname>".$args{'function'}."</refname>\n"; 6281da177e4SLinus Torvalds print " <refpurpose>\n"; 6291da177e4SLinus Torvalds print " "; 6301da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 6311da177e4SLinus Torvalds print " </refpurpose>\n"; 6321da177e4SLinus Torvalds print "</refnamediv>\n"; 6331da177e4SLinus Torvalds 6341da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 6351da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 6361da177e4SLinus Torvalds print " <funcsynopsis><funcprototype>\n"; 6371da177e4SLinus Torvalds print " <funcdef>".$args{'functiontype'}." "; 6381da177e4SLinus Torvalds print "<function>".$args{'function'}." </function></funcdef>\n"; 6391da177e4SLinus Torvalds 6401da177e4SLinus Torvalds $count = 0; 6411da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 6421da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6431da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 6441da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 6451da177e4SLinus Torvalds # pointer-to-function 6461da177e4SLinus Torvalds print " <paramdef>$1<parameter>$parameter</parameter>)\n"; 6471da177e4SLinus Torvalds print " <funcparams>$2</funcparams></paramdef>\n"; 6481da177e4SLinus Torvalds } else { 6491da177e4SLinus Torvalds print " <paramdef>".$type; 6501da177e4SLinus Torvalds print " <parameter>$parameter</parameter></paramdef>\n"; 6511da177e4SLinus Torvalds } 6521da177e4SLinus Torvalds } 6531da177e4SLinus Torvalds } else { 6546013d544SMartin Waitz print " <void/>\n"; 6551da177e4SLinus Torvalds } 6561da177e4SLinus Torvalds print " </funcprototype></funcsynopsis>\n"; 6571da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 6581da177e4SLinus Torvalds 6591da177e4SLinus Torvalds # print parameters 6601da177e4SLinus Torvalds print "<refsect1>\n <title>Arguments</title>\n"; 6611da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 6621da177e4SLinus Torvalds print " <variablelist>\n"; 6631da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6641da177e4SLinus Torvalds my $parameter_name = $parameter; 6651da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 6661da177e4SLinus Torvalds 6671da177e4SLinus Torvalds print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n"; 6681da177e4SLinus Torvalds print " <listitem>\n <para>\n"; 6691da177e4SLinus Torvalds $lineprefix=" "; 6701da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 6711da177e4SLinus Torvalds print " </para>\n </listitem>\n </varlistentry>\n"; 6721da177e4SLinus Torvalds } 6731da177e4SLinus Torvalds print " </variablelist>\n"; 6741da177e4SLinus Torvalds } else { 6751da177e4SLinus Torvalds print " <para>\n None\n </para>\n"; 6761da177e4SLinus Torvalds } 6771da177e4SLinus Torvalds print "</refsect1>\n"; 6781da177e4SLinus Torvalds 6791da177e4SLinus Torvalds output_section_xml(@_); 6801da177e4SLinus Torvalds print "</refentry>\n\n"; 6811da177e4SLinus Torvalds} 6821da177e4SLinus Torvalds 6831da177e4SLinus Torvalds# output struct in XML DocBook 6841da177e4SLinus Torvaldssub output_struct_xml(%) { 6851da177e4SLinus Torvalds my %args = %{$_[0]}; 6861da177e4SLinus Torvalds my ($parameter, $section); 6871da177e4SLinus Torvalds my $id; 6881da177e4SLinus Torvalds 6891da177e4SLinus Torvalds $id = "API-struct-".$args{'struct'}; 6901da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 6911da177e4SLinus Torvalds 6925449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 6938b0c2d98SMartin Waitz print "<refentryinfo>\n"; 6948b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 6958b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 6968b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 6978b0c2d98SMartin Waitz print "</refentryinfo>\n"; 6981da177e4SLinus Torvalds print "<refmeta>\n"; 6995449bc94SPavel Pisa print " <refentrytitle><phrase>".$args{'type'}." ".$args{'struct'}."</phrase></refentrytitle>\n"; 7008b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 7010366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 7021da177e4SLinus Torvalds print "</refmeta>\n"; 7031da177e4SLinus Torvalds print "<refnamediv>\n"; 7041da177e4SLinus Torvalds print " <refname>".$args{'type'}." ".$args{'struct'}."</refname>\n"; 7051da177e4SLinus Torvalds print " <refpurpose>\n"; 7061da177e4SLinus Torvalds print " "; 7071da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 7081da177e4SLinus Torvalds print " </refpurpose>\n"; 7091da177e4SLinus Torvalds print "</refnamediv>\n"; 7101da177e4SLinus Torvalds 7111da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 7121da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 7131da177e4SLinus Torvalds print " <programlisting>\n"; 7141da177e4SLinus Torvalds print $args{'type'}." ".$args{'struct'}." {\n"; 7151da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7161da177e4SLinus Torvalds if ($parameter =~ /^#/) { 7171da177e4SLinus Torvalds print "$parameter\n"; 7181da177e4SLinus Torvalds next; 7191da177e4SLinus Torvalds } 7201da177e4SLinus Torvalds 7211da177e4SLinus Torvalds my $parameter_name = $parameter; 7221da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 7231da177e4SLinus Torvalds 7241da177e4SLinus Torvalds defined($args{'parameterdescs'}{$parameter_name}) || next; 7251da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 7261da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 7271da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 7281da177e4SLinus Torvalds # pointer-to-function 7291da177e4SLinus Torvalds print " $1 $parameter) ($2);\n"; 7301da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 73151f5a0c8SRandy Dunlap # bitfield 7321da177e4SLinus Torvalds print " $1 $parameter$2;\n"; 7331da177e4SLinus Torvalds } else { 7341da177e4SLinus Torvalds print " ".$type." ".$parameter.";\n"; 7351da177e4SLinus Torvalds } 7361da177e4SLinus Torvalds } 7371da177e4SLinus Torvalds print "};"; 7381da177e4SLinus Torvalds print " </programlisting>\n"; 7391da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 7401da177e4SLinus Torvalds 7411da177e4SLinus Torvalds print " <refsect1>\n"; 7421da177e4SLinus Torvalds print " <title>Members</title>\n"; 7431da177e4SLinus Torvalds 7441da177e4SLinus Torvalds print " <variablelist>\n"; 7451da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7461da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 7471da177e4SLinus Torvalds 7481da177e4SLinus Torvalds my $parameter_name = $parameter; 7491da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 7501da177e4SLinus Torvalds 7511da177e4SLinus Torvalds defined($args{'parameterdescs'}{$parameter_name}) || next; 7521da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 7531da177e4SLinus Torvalds print " <varlistentry>"; 7541da177e4SLinus Torvalds print " <term>$parameter</term>\n"; 7551da177e4SLinus Torvalds print " <listitem><para>\n"; 7561da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 7571da177e4SLinus Torvalds print " </para></listitem>\n"; 7581da177e4SLinus Torvalds print " </varlistentry>\n"; 7591da177e4SLinus Torvalds } 7601da177e4SLinus Torvalds print " </variablelist>\n"; 7611da177e4SLinus Torvalds print " </refsect1>\n"; 7621da177e4SLinus Torvalds 7631da177e4SLinus Torvalds output_section_xml(@_); 7641da177e4SLinus Torvalds 7651da177e4SLinus Torvalds print "</refentry>\n\n"; 7661da177e4SLinus Torvalds} 7671da177e4SLinus Torvalds 7681da177e4SLinus Torvalds# output enum in XML DocBook 7691da177e4SLinus Torvaldssub output_enum_xml(%) { 7701da177e4SLinus Torvalds my %args = %{$_[0]}; 7711da177e4SLinus Torvalds my ($parameter, $section); 7721da177e4SLinus Torvalds my $count; 7731da177e4SLinus Torvalds my $id; 7741da177e4SLinus Torvalds 7751da177e4SLinus Torvalds $id = "API-enum-".$args{'enum'}; 7761da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 7771da177e4SLinus Torvalds 7785449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 7798b0c2d98SMartin Waitz print "<refentryinfo>\n"; 7808b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 7818b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 7828b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 7838b0c2d98SMartin Waitz print "</refentryinfo>\n"; 7841da177e4SLinus Torvalds print "<refmeta>\n"; 7855449bc94SPavel Pisa print " <refentrytitle><phrase>enum ".$args{'enum'}."</phrase></refentrytitle>\n"; 7868b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 7870366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 7881da177e4SLinus Torvalds print "</refmeta>\n"; 7891da177e4SLinus Torvalds print "<refnamediv>\n"; 7901da177e4SLinus Torvalds print " <refname>enum ".$args{'enum'}."</refname>\n"; 7911da177e4SLinus Torvalds print " <refpurpose>\n"; 7921da177e4SLinus Torvalds print " "; 7931da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 7941da177e4SLinus Torvalds print " </refpurpose>\n"; 7951da177e4SLinus Torvalds print "</refnamediv>\n"; 7961da177e4SLinus Torvalds 7971da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 7981da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 7991da177e4SLinus Torvalds print " <programlisting>\n"; 8001da177e4SLinus Torvalds print "enum ".$args{'enum'}." {\n"; 8011da177e4SLinus Torvalds $count = 0; 8021da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 8031da177e4SLinus Torvalds print " $parameter"; 8041da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 8051da177e4SLinus Torvalds $count++; 8061da177e4SLinus Torvalds print ","; 8071da177e4SLinus Torvalds } 8081da177e4SLinus Torvalds print "\n"; 8091da177e4SLinus Torvalds } 8101da177e4SLinus Torvalds print "};"; 8111da177e4SLinus Torvalds print " </programlisting>\n"; 8121da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 8131da177e4SLinus Torvalds 8141da177e4SLinus Torvalds print "<refsect1>\n"; 8151da177e4SLinus Torvalds print " <title>Constants</title>\n"; 8161da177e4SLinus Torvalds print " <variablelist>\n"; 8171da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 8181da177e4SLinus Torvalds my $parameter_name = $parameter; 8191da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 8201da177e4SLinus Torvalds 8211da177e4SLinus Torvalds print " <varlistentry>"; 8221da177e4SLinus Torvalds print " <term>$parameter</term>\n"; 8231da177e4SLinus Torvalds print " <listitem><para>\n"; 8241da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 8251da177e4SLinus Torvalds print " </para></listitem>\n"; 8261da177e4SLinus Torvalds print " </varlistentry>\n"; 8271da177e4SLinus Torvalds } 8281da177e4SLinus Torvalds print " </variablelist>\n"; 8291da177e4SLinus Torvalds print "</refsect1>\n"; 8301da177e4SLinus Torvalds 8311da177e4SLinus Torvalds output_section_xml(@_); 8321da177e4SLinus Torvalds 8331da177e4SLinus Torvalds print "</refentry>\n\n"; 8341da177e4SLinus Torvalds} 8351da177e4SLinus Torvalds 8361da177e4SLinus Torvalds# output typedef in XML DocBook 8371da177e4SLinus Torvaldssub output_typedef_xml(%) { 8381da177e4SLinus Torvalds my %args = %{$_[0]}; 8391da177e4SLinus Torvalds my ($parameter, $section); 8401da177e4SLinus Torvalds my $id; 8411da177e4SLinus Torvalds 8421da177e4SLinus Torvalds $id = "API-typedef-".$args{'typedef'}; 8431da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 8441da177e4SLinus Torvalds 8455449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 8468b0c2d98SMartin Waitz print "<refentryinfo>\n"; 8478b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 8488b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 8498b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 8508b0c2d98SMartin Waitz print "</refentryinfo>\n"; 8511da177e4SLinus Torvalds print "<refmeta>\n"; 8525449bc94SPavel Pisa print " <refentrytitle><phrase>typedef ".$args{'typedef'}."</phrase></refentrytitle>\n"; 8538b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 8541da177e4SLinus Torvalds print "</refmeta>\n"; 8551da177e4SLinus Torvalds print "<refnamediv>\n"; 8561da177e4SLinus Torvalds print " <refname>typedef ".$args{'typedef'}."</refname>\n"; 8571da177e4SLinus Torvalds print " <refpurpose>\n"; 8581da177e4SLinus Torvalds print " "; 8591da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 8601da177e4SLinus Torvalds print " </refpurpose>\n"; 8611da177e4SLinus Torvalds print "</refnamediv>\n"; 8621da177e4SLinus Torvalds 8631da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 8641da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 8651da177e4SLinus Torvalds print " <synopsis>typedef ".$args{'typedef'}.";</synopsis>\n"; 8661da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 8671da177e4SLinus Torvalds 8681da177e4SLinus Torvalds output_section_xml(@_); 8691da177e4SLinus Torvalds 8701da177e4SLinus Torvalds print "</refentry>\n\n"; 8711da177e4SLinus Torvalds} 8721da177e4SLinus Torvalds 8731da177e4SLinus Torvalds# output in XML DocBook 8741da177e4SLinus Torvaldssub output_intro_xml(%) { 8751da177e4SLinus Torvalds my %args = %{$_[0]}; 8761da177e4SLinus Torvalds my ($parameter, $section); 8771da177e4SLinus Torvalds my $count; 8781da177e4SLinus Torvalds 8791da177e4SLinus Torvalds my $id = $args{'module'}; 8801da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 8811da177e4SLinus Torvalds 8821da177e4SLinus Torvalds # print out each section 8831da177e4SLinus Torvalds $lineprefix=" "; 8841da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 8851da177e4SLinus Torvalds print "<refsect1>\n <title>$section</title>\n <para>\n"; 8861da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 8871da177e4SLinus Torvalds print "<example><para>\n"; 8881da177e4SLinus Torvalds } 8891da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 8901da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 8911da177e4SLinus Torvalds print "</para></example>\n"; 8921da177e4SLinus Torvalds } 8931da177e4SLinus Torvalds print " </para>\n</refsect1>\n"; 8941da177e4SLinus Torvalds } 8951da177e4SLinus Torvalds 8961da177e4SLinus Torvalds print "\n\n"; 8971da177e4SLinus Torvalds} 8981da177e4SLinus Torvalds 8991da177e4SLinus Torvalds# output in XML DocBook 9001da177e4SLinus Torvaldssub output_function_gnome { 9011da177e4SLinus Torvalds my %args = %{$_[0]}; 9021da177e4SLinus Torvalds my ($parameter, $section); 9031da177e4SLinus Torvalds my $count; 9041da177e4SLinus Torvalds my $id; 9051da177e4SLinus Torvalds 9061da177e4SLinus Torvalds $id = $args{'module'}."-".$args{'function'}; 9071da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 9081da177e4SLinus Torvalds 9091da177e4SLinus Torvalds print "<sect2>\n"; 9101da177e4SLinus Torvalds print " <title id=\"$id\">".$args{'function'}."</title>\n"; 9111da177e4SLinus Torvalds 9121da177e4SLinus Torvalds print " <funcsynopsis>\n"; 9131da177e4SLinus Torvalds print " <funcdef>".$args{'functiontype'}." "; 9141da177e4SLinus Torvalds print "<function>".$args{'function'}." "; 9151da177e4SLinus Torvalds print "</function></funcdef>\n"; 9161da177e4SLinus Torvalds 9171da177e4SLinus Torvalds $count = 0; 9181da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 9191da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 9201da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 9211da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 9221da177e4SLinus Torvalds # pointer-to-function 9231da177e4SLinus Torvalds print " <paramdef>$1 <parameter>$parameter</parameter>)\n"; 9241da177e4SLinus Torvalds print " <funcparams>$2</funcparams></paramdef>\n"; 9251da177e4SLinus Torvalds } else { 9261da177e4SLinus Torvalds print " <paramdef>".$type; 9271da177e4SLinus Torvalds print " <parameter>$parameter</parameter></paramdef>\n"; 9281da177e4SLinus Torvalds } 9291da177e4SLinus Torvalds } 9301da177e4SLinus Torvalds } else { 9311da177e4SLinus Torvalds print " <void>\n"; 9321da177e4SLinus Torvalds } 9331da177e4SLinus Torvalds print " </funcsynopsis>\n"; 9341da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 9351da177e4SLinus Torvalds print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n"; 9361da177e4SLinus Torvalds print "<tgroup cols=\"2\">\n"; 9371da177e4SLinus Torvalds print "<colspec colwidth=\"2*\">\n"; 9381da177e4SLinus Torvalds print "<colspec colwidth=\"8*\">\n"; 9391da177e4SLinus Torvalds print "<tbody>\n"; 9401da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 9411da177e4SLinus Torvalds my $parameter_name = $parameter; 9421da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 9431da177e4SLinus Torvalds 9441da177e4SLinus Torvalds print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n"; 9451da177e4SLinus Torvalds print " <entry>\n"; 9461da177e4SLinus Torvalds $lineprefix=" "; 9471da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 9481da177e4SLinus Torvalds print " </entry></row>\n"; 9491da177e4SLinus Torvalds } 9501da177e4SLinus Torvalds print " </tbody></tgroup></informaltable>\n"; 9511da177e4SLinus Torvalds } else { 9521da177e4SLinus Torvalds print " <para>\n None\n </para>\n"; 9531da177e4SLinus Torvalds } 9541da177e4SLinus Torvalds 9551da177e4SLinus Torvalds # print out each section 9561da177e4SLinus Torvalds $lineprefix=" "; 9571da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 9581da177e4SLinus Torvalds print "<simplesect>\n <title>$section</title>\n"; 9591da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 9601da177e4SLinus Torvalds print "<example><programlisting>\n"; 9611da177e4SLinus Torvalds } else { 9621da177e4SLinus Torvalds } 9631da177e4SLinus Torvalds print "<para>\n"; 9641da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 9651da177e4SLinus Torvalds print "</para>\n"; 9661da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 9671da177e4SLinus Torvalds print "</programlisting></example>\n"; 9681da177e4SLinus Torvalds } else { 9691da177e4SLinus Torvalds } 9701da177e4SLinus Torvalds print " </simplesect>\n"; 9711da177e4SLinus Torvalds } 9721da177e4SLinus Torvalds 9731da177e4SLinus Torvalds print "</sect2>\n\n"; 9741da177e4SLinus Torvalds} 9751da177e4SLinus Torvalds 9761da177e4SLinus Torvalds## 9771da177e4SLinus Torvalds# output function in man 9781da177e4SLinus Torvaldssub output_function_man(%) { 9791da177e4SLinus Torvalds my %args = %{$_[0]}; 9801da177e4SLinus Torvalds my ($parameter, $section); 9811da177e4SLinus Torvalds my $count; 9821da177e4SLinus Torvalds 9831da177e4SLinus Torvalds print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; 9841da177e4SLinus Torvalds 9851da177e4SLinus Torvalds print ".SH NAME\n"; 9861da177e4SLinus Torvalds print $args{'function'}." \\- ".$args{'purpose'}."\n"; 9871da177e4SLinus Torvalds 9881da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 989a21217daSRandy Dunlap if ($args{'functiontype'} ne "") { 9901da177e4SLinus Torvalds print ".B \"".$args{'functiontype'}."\" ".$args{'function'}."\n"; 991a21217daSRandy Dunlap } else { 992a21217daSRandy Dunlap print ".B \"".$args{'function'}."\n"; 993a21217daSRandy Dunlap } 9941da177e4SLinus Torvalds $count = 0; 9951da177e4SLinus Torvalds my $parenth = "("; 9961da177e4SLinus Torvalds my $post = ","; 9971da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 9981da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 9991da177e4SLinus Torvalds $post = ");"; 10001da177e4SLinus Torvalds } 10011da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 10021da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 10031da177e4SLinus Torvalds # pointer-to-function 10041da177e4SLinus Torvalds print ".BI \"".$parenth.$1."\" ".$parameter." \") (".$2.")".$post."\"\n"; 10051da177e4SLinus Torvalds } else { 10061da177e4SLinus Torvalds $type =~ s/([^\*])$/$1 /; 10071da177e4SLinus Torvalds print ".BI \"".$parenth.$type."\" ".$parameter." \"".$post."\"\n"; 10081da177e4SLinus Torvalds } 10091da177e4SLinus Torvalds $count++; 10101da177e4SLinus Torvalds $parenth = ""; 10111da177e4SLinus Torvalds } 10121da177e4SLinus Torvalds 10131da177e4SLinus Torvalds print ".SH ARGUMENTS\n"; 10141da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 10151da177e4SLinus Torvalds my $parameter_name = $parameter; 10161da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 10171da177e4SLinus Torvalds 10181da177e4SLinus Torvalds print ".IP \"".$parameter."\" 12\n"; 10191da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 10201da177e4SLinus Torvalds } 10211da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 10221da177e4SLinus Torvalds print ".SH \"", uc $section, "\"\n"; 10231da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 10241da177e4SLinus Torvalds } 10251da177e4SLinus Torvalds} 10261da177e4SLinus Torvalds 10271da177e4SLinus Torvalds## 10281da177e4SLinus Torvalds# output enum in man 10291da177e4SLinus Torvaldssub output_enum_man(%) { 10301da177e4SLinus Torvalds my %args = %{$_[0]}; 10311da177e4SLinus Torvalds my ($parameter, $section); 10321da177e4SLinus Torvalds my $count; 10331da177e4SLinus Torvalds 10341da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n"; 10351da177e4SLinus Torvalds 10361da177e4SLinus Torvalds print ".SH NAME\n"; 10371da177e4SLinus Torvalds print "enum ".$args{'enum'}." \\- ".$args{'purpose'}."\n"; 10381da177e4SLinus Torvalds 10391da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 10401da177e4SLinus Torvalds print "enum ".$args{'enum'}." {\n"; 10411da177e4SLinus Torvalds $count = 0; 10421da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 10431da177e4SLinus Torvalds print ".br\n.BI \" $parameter\"\n"; 10441da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 10451da177e4SLinus Torvalds print "\n};\n"; 10461da177e4SLinus Torvalds last; 10471da177e4SLinus Torvalds } 10481da177e4SLinus Torvalds else { 10491da177e4SLinus Torvalds print ", \n.br\n"; 10501da177e4SLinus Torvalds } 10511da177e4SLinus Torvalds $count++; 10521da177e4SLinus Torvalds } 10531da177e4SLinus Torvalds 10541da177e4SLinus Torvalds print ".SH Constants\n"; 10551da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 10561da177e4SLinus Torvalds my $parameter_name = $parameter; 10571da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 10581da177e4SLinus Torvalds 10591da177e4SLinus Torvalds print ".IP \"".$parameter."\" 12\n"; 10601da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 10611da177e4SLinus Torvalds } 10621da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 10631da177e4SLinus Torvalds print ".SH \"$section\"\n"; 10641da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 10651da177e4SLinus Torvalds } 10661da177e4SLinus Torvalds} 10671da177e4SLinus Torvalds 10681da177e4SLinus Torvalds## 10691da177e4SLinus Torvalds# output struct in man 10701da177e4SLinus Torvaldssub output_struct_man(%) { 10711da177e4SLinus Torvalds my %args = %{$_[0]}; 10721da177e4SLinus Torvalds my ($parameter, $section); 10731da177e4SLinus Torvalds 10741da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"".$args{'type'}." ".$args{'struct'}."\" \"$man_date\" \"API Manual\" LINUX\n"; 10751da177e4SLinus Torvalds 10761da177e4SLinus Torvalds print ".SH NAME\n"; 10771da177e4SLinus Torvalds print $args{'type'}." ".$args{'struct'}." \\- ".$args{'purpose'}."\n"; 10781da177e4SLinus Torvalds 10791da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 10801da177e4SLinus Torvalds print $args{'type'}." ".$args{'struct'}." {\n.br\n"; 10811da177e4SLinus Torvalds 10821da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 10831da177e4SLinus Torvalds if ($parameter =~ /^#/) { 10841da177e4SLinus Torvalds print ".BI \"$parameter\"\n.br\n"; 10851da177e4SLinus Torvalds next; 10861da177e4SLinus Torvalds } 10871da177e4SLinus Torvalds my $parameter_name = $parameter; 10881da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 10891da177e4SLinus Torvalds 10901da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 10911da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 10921da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 10931da177e4SLinus Torvalds # pointer-to-function 10941da177e4SLinus Torvalds print ".BI \" ".$1."\" ".$parameter." \") (".$2.")"."\"\n;\n"; 10951da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 10961d7e1d45SRandy.Dunlap # bitfield 10971d7e1d45SRandy.Dunlap print ".BI \" ".$1."\ \" ".$parameter.$2." \""."\"\n;\n"; 10981da177e4SLinus Torvalds } else { 10991da177e4SLinus Torvalds $type =~ s/([^\*])$/$1 /; 11001da177e4SLinus Torvalds print ".BI \" ".$type."\" ".$parameter." \""."\"\n;\n"; 11011da177e4SLinus Torvalds } 11021da177e4SLinus Torvalds print "\n.br\n"; 11031da177e4SLinus Torvalds } 11041da177e4SLinus Torvalds print "};\n.br\n"; 11051da177e4SLinus Torvalds 1106c51d3dacSRandy Dunlap print ".SH Members\n"; 11071da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 11081da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 11091da177e4SLinus Torvalds 11101da177e4SLinus Torvalds my $parameter_name = $parameter; 11111da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 11121da177e4SLinus Torvalds 11131da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 11141da177e4SLinus Torvalds print ".IP \"".$parameter."\" 12\n"; 11151da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 11161da177e4SLinus Torvalds } 11171da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 11181da177e4SLinus Torvalds print ".SH \"$section\"\n"; 11191da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 11201da177e4SLinus Torvalds } 11211da177e4SLinus Torvalds} 11221da177e4SLinus Torvalds 11231da177e4SLinus Torvalds## 11241da177e4SLinus Torvalds# output typedef in man 11251da177e4SLinus Torvaldssub output_typedef_man(%) { 11261da177e4SLinus Torvalds my %args = %{$_[0]}; 11271da177e4SLinus Torvalds my ($parameter, $section); 11281da177e4SLinus Torvalds 11291da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n"; 11301da177e4SLinus Torvalds 11311da177e4SLinus Torvalds print ".SH NAME\n"; 11321da177e4SLinus Torvalds print "typedef ".$args{'typedef'}." \\- ".$args{'purpose'}."\n"; 11331da177e4SLinus Torvalds 11341da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 11351da177e4SLinus Torvalds print ".SH \"$section\"\n"; 11361da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 11371da177e4SLinus Torvalds } 11381da177e4SLinus Torvalds} 11391da177e4SLinus Torvalds 11401da177e4SLinus Torvaldssub output_intro_man(%) { 11411da177e4SLinus Torvalds my %args = %{$_[0]}; 11421da177e4SLinus Torvalds my ($parameter, $section); 11431da177e4SLinus Torvalds my $count; 11441da177e4SLinus Torvalds 11451da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; 11461da177e4SLinus Torvalds 11471da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 11481da177e4SLinus Torvalds print ".SH \"$section\"\n"; 11491da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 11501da177e4SLinus Torvalds } 11511da177e4SLinus Torvalds} 11521da177e4SLinus Torvalds 11531da177e4SLinus Torvalds## 11541da177e4SLinus Torvalds# output in text 11551da177e4SLinus Torvaldssub output_function_text(%) { 11561da177e4SLinus Torvalds my %args = %{$_[0]}; 11571da177e4SLinus Torvalds my ($parameter, $section); 1158a21217daSRandy Dunlap my $start; 11591da177e4SLinus Torvalds 1160f47634b2SRandy Dunlap print "Name:\n\n"; 1161f47634b2SRandy Dunlap print $args{'function'}." - ".$args{'purpose'}."\n"; 1162f47634b2SRandy Dunlap 1163f47634b2SRandy Dunlap print "\nSynopsis:\n\n"; 1164a21217daSRandy Dunlap if ($args{'functiontype'} ne "") { 1165a21217daSRandy Dunlap $start = $args{'functiontype'}." ".$args{'function'}." ("; 1166a21217daSRandy Dunlap } else { 1167a21217daSRandy Dunlap $start = $args{'function'}." ("; 1168a21217daSRandy Dunlap } 11691da177e4SLinus Torvalds print $start; 1170a21217daSRandy Dunlap 11711da177e4SLinus Torvalds my $count = 0; 11721da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 11731da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 11741da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 11751da177e4SLinus Torvalds # pointer-to-function 11761da177e4SLinus Torvalds print $1.$parameter.") (".$2; 11771da177e4SLinus Torvalds } else { 11781da177e4SLinus Torvalds print $type." ".$parameter; 11791da177e4SLinus Torvalds } 11801da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 11811da177e4SLinus Torvalds $count++; 11821da177e4SLinus Torvalds print ",\n"; 11831da177e4SLinus Torvalds print " " x length($start); 11841da177e4SLinus Torvalds } else { 11851da177e4SLinus Torvalds print ");\n\n"; 11861da177e4SLinus Torvalds } 11871da177e4SLinus Torvalds } 11881da177e4SLinus Torvalds 11891da177e4SLinus Torvalds print "Arguments:\n\n"; 11901da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 11911da177e4SLinus Torvalds my $parameter_name = $parameter; 11921da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 11931da177e4SLinus Torvalds 11941da177e4SLinus Torvalds print $parameter."\n\t".$args{'parameterdescs'}{$parameter_name}."\n"; 11951da177e4SLinus Torvalds } 11961da177e4SLinus Torvalds output_section_text(@_); 11971da177e4SLinus Torvalds} 11981da177e4SLinus Torvalds 11991da177e4SLinus Torvalds#output sections in text 12001da177e4SLinus Torvaldssub output_section_text(%) { 12011da177e4SLinus Torvalds my %args = %{$_[0]}; 12021da177e4SLinus Torvalds my $section; 12031da177e4SLinus Torvalds 12041da177e4SLinus Torvalds print "\n"; 12051da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 12061da177e4SLinus Torvalds print "$section:\n\n"; 12071da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 12081da177e4SLinus Torvalds } 12091da177e4SLinus Torvalds print "\n\n"; 12101da177e4SLinus Torvalds} 12111da177e4SLinus Torvalds 12121da177e4SLinus Torvalds# output enum in text 12131da177e4SLinus Torvaldssub output_enum_text(%) { 12141da177e4SLinus Torvalds my %args = %{$_[0]}; 12151da177e4SLinus Torvalds my ($parameter); 12161da177e4SLinus Torvalds my $count; 12171da177e4SLinus Torvalds print "Enum:\n\n"; 12181da177e4SLinus Torvalds 12191d7e1d45SRandy.Dunlap print "enum ".$args{'enum'}." - ".$args{'purpose'}."\n\n"; 12201da177e4SLinus Torvalds print "enum ".$args{'enum'}." {\n"; 12211da177e4SLinus Torvalds $count = 0; 12221da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 12231da177e4SLinus Torvalds print "\t$parameter"; 12241da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 12251da177e4SLinus Torvalds $count++; 12261da177e4SLinus Torvalds print ","; 12271da177e4SLinus Torvalds } 12281da177e4SLinus Torvalds print "\n"; 12291da177e4SLinus Torvalds } 12301da177e4SLinus Torvalds print "};\n\n"; 12311da177e4SLinus Torvalds 12321da177e4SLinus Torvalds print "Constants:\n\n"; 12331da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 12341da177e4SLinus Torvalds print "$parameter\n\t"; 12351da177e4SLinus Torvalds print $args{'parameterdescs'}{$parameter}."\n"; 12361da177e4SLinus Torvalds } 12371da177e4SLinus Torvalds 12381da177e4SLinus Torvalds output_section_text(@_); 12391da177e4SLinus Torvalds} 12401da177e4SLinus Torvalds 12411da177e4SLinus Torvalds# output typedef in text 12421da177e4SLinus Torvaldssub output_typedef_text(%) { 12431da177e4SLinus Torvalds my %args = %{$_[0]}; 12441da177e4SLinus Torvalds my ($parameter); 12451da177e4SLinus Torvalds my $count; 12461da177e4SLinus Torvalds print "Typedef:\n\n"; 12471da177e4SLinus Torvalds 12481d7e1d45SRandy.Dunlap print "typedef ".$args{'typedef'}." - ".$args{'purpose'}."\n"; 12491da177e4SLinus Torvalds output_section_text(@_); 12501da177e4SLinus Torvalds} 12511da177e4SLinus Torvalds 12521da177e4SLinus Torvalds# output struct as text 12531da177e4SLinus Torvaldssub output_struct_text(%) { 12541da177e4SLinus Torvalds my %args = %{$_[0]}; 12551da177e4SLinus Torvalds my ($parameter); 12561da177e4SLinus Torvalds 12571d7e1d45SRandy.Dunlap print $args{'type'}." ".$args{'struct'}." - ".$args{'purpose'}."\n\n"; 12581da177e4SLinus Torvalds print $args{'type'}." ".$args{'struct'}." {\n"; 12591da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 12601da177e4SLinus Torvalds if ($parameter =~ /^#/) { 12611da177e4SLinus Torvalds print "$parameter\n"; 12621da177e4SLinus Torvalds next; 12631da177e4SLinus Torvalds } 12641da177e4SLinus Torvalds 12651da177e4SLinus Torvalds my $parameter_name = $parameter; 12661da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 12671da177e4SLinus Torvalds 12681da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 12691da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 12701da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 12711da177e4SLinus Torvalds # pointer-to-function 12721da177e4SLinus Torvalds print "\t$1 $parameter) ($2);\n"; 12731da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 127451f5a0c8SRandy Dunlap # bitfield 12751da177e4SLinus Torvalds print "\t$1 $parameter$2;\n"; 12761da177e4SLinus Torvalds } else { 12771da177e4SLinus Torvalds print "\t".$type." ".$parameter.";\n"; 12781da177e4SLinus Torvalds } 12791da177e4SLinus Torvalds } 12801da177e4SLinus Torvalds print "};\n\n"; 12811da177e4SLinus Torvalds 12821da177e4SLinus Torvalds print "Members:\n\n"; 12831da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 12841da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 12851da177e4SLinus Torvalds 12861da177e4SLinus Torvalds my $parameter_name = $parameter; 12871da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 12881da177e4SLinus Torvalds 12891da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 12901da177e4SLinus Torvalds print "$parameter\n\t"; 12911da177e4SLinus Torvalds print $args{'parameterdescs'}{$parameter_name}."\n"; 12921da177e4SLinus Torvalds } 12931da177e4SLinus Torvalds print "\n"; 12941da177e4SLinus Torvalds output_section_text(@_); 12951da177e4SLinus Torvalds} 12961da177e4SLinus Torvalds 12971da177e4SLinus Torvaldssub output_intro_text(%) { 12981da177e4SLinus Torvalds my %args = %{$_[0]}; 12991da177e4SLinus Torvalds my ($parameter, $section); 13001da177e4SLinus Torvalds 13011da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 13021da177e4SLinus Torvalds print " $section:\n"; 13031da177e4SLinus Torvalds print " -> "; 13041da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 13051da177e4SLinus Torvalds } 13061da177e4SLinus Torvalds} 13071da177e4SLinus Torvalds 13081da177e4SLinus Torvalds## 130927205744SRandy Dunlap# generic output function for all types (function, struct/union, typedef, enum); 131027205744SRandy Dunlap# calls the generated, variable output_ function name based on 131127205744SRandy Dunlap# functype and output_mode 13121da177e4SLinus Torvaldssub output_declaration { 13131da177e4SLinus Torvalds no strict 'refs'; 13141da177e4SLinus Torvalds my $name = shift; 13151da177e4SLinus Torvalds my $functype = shift; 13161da177e4SLinus Torvalds my $func = "output_${functype}_$output_mode"; 13171da177e4SLinus Torvalds if (($function_only==0) || 13181da177e4SLinus Torvalds ( $function_only == 1 && defined($function_table{$name})) || 13191da177e4SLinus Torvalds ( $function_only == 2 && !defined($function_table{$name}))) 13201da177e4SLinus Torvalds { 13211da177e4SLinus Torvalds &$func(@_); 13221da177e4SLinus Torvalds $section_counter++; 13231da177e4SLinus Torvalds } 13241da177e4SLinus Torvalds} 13251da177e4SLinus Torvalds 13261da177e4SLinus Torvalds## 132727205744SRandy Dunlap# generic output function - calls the right one based on current output mode. 13281da177e4SLinus Torvaldssub output_intro { 13291da177e4SLinus Torvalds no strict 'refs'; 13301da177e4SLinus Torvalds my $func = "output_intro_".$output_mode; 13311da177e4SLinus Torvalds &$func(@_); 13321da177e4SLinus Torvalds $section_counter++; 13331da177e4SLinus Torvalds} 13341da177e4SLinus Torvalds 13351da177e4SLinus Torvalds## 13361da177e4SLinus Torvalds# takes a declaration (struct, union, enum, typedef) and 13371da177e4SLinus Torvalds# invokes the right handler. NOT called for functions. 13381da177e4SLinus Torvaldssub dump_declaration($$) { 13391da177e4SLinus Torvalds no strict 'refs'; 13401da177e4SLinus Torvalds my ($prototype, $file) = @_; 13411da177e4SLinus Torvalds my $func = "dump_".$decl_type; 13421da177e4SLinus Torvalds &$func(@_); 13431da177e4SLinus Torvalds} 13441da177e4SLinus Torvalds 13451da177e4SLinus Torvaldssub dump_union($$) { 13461da177e4SLinus Torvalds dump_struct(@_); 13471da177e4SLinus Torvalds} 13481da177e4SLinus Torvalds 13491da177e4SLinus Torvaldssub dump_struct($$) { 13501da177e4SLinus Torvalds my $x = shift; 13511da177e4SLinus Torvalds my $file = shift; 13521da177e4SLinus Torvalds 13531da177e4SLinus Torvalds if ($x =~/(struct|union)\s+(\w+)\s*{(.*)}/) { 13541da177e4SLinus Torvalds $declaration_name = $2; 13551da177e4SLinus Torvalds my $members = $3; 13561da177e4SLinus Torvalds 13571da177e4SLinus Torvalds # ignore embedded structs or unions 13581da177e4SLinus Torvalds $members =~ s/{.*?}//g; 13591da177e4SLinus Torvalds 1360aeec46b9SMartin Waitz # ignore members marked private: 1361aeec46b9SMartin Waitz $members =~ s/\/\*.*?private:.*?public:.*?\*\///gos; 1362aeec46b9SMartin Waitz $members =~ s/\/\*.*?private:.*//gos; 1363aeec46b9SMartin Waitz # strip comments: 1364aeec46b9SMartin Waitz $members =~ s/\/\*.*?\*\///gos; 1365aeec46b9SMartin Waitz 13661da177e4SLinus Torvalds create_parameterlist($members, ';', $file); 13671da177e4SLinus Torvalds 13681da177e4SLinus Torvalds output_declaration($declaration_name, 13691da177e4SLinus Torvalds 'struct', 13701da177e4SLinus Torvalds {'struct' => $declaration_name, 13711da177e4SLinus Torvalds 'module' => $modulename, 13721da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 13731da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 13741da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 13751da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 13761da177e4SLinus Torvalds 'sections' => \%sections, 13771da177e4SLinus Torvalds 'purpose' => $declaration_purpose, 13781da177e4SLinus Torvalds 'type' => $decl_type 13791da177e4SLinus Torvalds }); 13801da177e4SLinus Torvalds } 13811da177e4SLinus Torvalds else { 13821da177e4SLinus Torvalds print STDERR "Error(${file}:$.): Cannot parse struct or union!\n"; 13831da177e4SLinus Torvalds ++$errors; 13841da177e4SLinus Torvalds } 13851da177e4SLinus Torvalds} 13861da177e4SLinus Torvalds 13871da177e4SLinus Torvaldssub dump_enum($$) { 13881da177e4SLinus Torvalds my $x = shift; 13891da177e4SLinus Torvalds my $file = shift; 13901da177e4SLinus Torvalds 1391aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 13921da177e4SLinus Torvalds if ($x =~ /enum\s+(\w+)\s*{(.*)}/) { 13931da177e4SLinus Torvalds $declaration_name = $1; 13941da177e4SLinus Torvalds my $members = $2; 13951da177e4SLinus Torvalds 13961da177e4SLinus Torvalds foreach my $arg (split ',', $members) { 13971da177e4SLinus Torvalds $arg =~ s/^\s*(\w+).*/$1/; 13981da177e4SLinus Torvalds push @parameterlist, $arg; 13991da177e4SLinus Torvalds if (!$parameterdescs{$arg}) { 14001da177e4SLinus Torvalds $parameterdescs{$arg} = $undescribed; 14011da177e4SLinus Torvalds print STDERR "Warning(${file}:$.): Enum value '$arg' ". 14021da177e4SLinus Torvalds "not described in enum '$declaration_name'\n"; 14031da177e4SLinus Torvalds } 14041da177e4SLinus Torvalds 14051da177e4SLinus Torvalds } 14061da177e4SLinus Torvalds 14071da177e4SLinus Torvalds output_declaration($declaration_name, 14081da177e4SLinus Torvalds 'enum', 14091da177e4SLinus Torvalds {'enum' => $declaration_name, 14101da177e4SLinus Torvalds 'module' => $modulename, 14111da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 14121da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 14131da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 14141da177e4SLinus Torvalds 'sections' => \%sections, 14151da177e4SLinus Torvalds 'purpose' => $declaration_purpose 14161da177e4SLinus Torvalds }); 14171da177e4SLinus Torvalds } 14181da177e4SLinus Torvalds else { 14191da177e4SLinus Torvalds print STDERR "Error(${file}:$.): Cannot parse enum!\n"; 14201da177e4SLinus Torvalds ++$errors; 14211da177e4SLinus Torvalds } 14221da177e4SLinus Torvalds} 14231da177e4SLinus Torvalds 14241da177e4SLinus Torvaldssub dump_typedef($$) { 14251da177e4SLinus Torvalds my $x = shift; 14261da177e4SLinus Torvalds my $file = shift; 14271da177e4SLinus Torvalds 1428aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 14291da177e4SLinus Torvalds while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { 14301da177e4SLinus Torvalds $x =~ s/\(*.\)\s*;$/;/; 14311da177e4SLinus Torvalds $x =~ s/\[*.\]\s*;$/;/; 14321da177e4SLinus Torvalds } 14331da177e4SLinus Torvalds 14341da177e4SLinus Torvalds if ($x =~ /typedef.*\s+(\w+)\s*;/) { 14351da177e4SLinus Torvalds $declaration_name = $1; 14361da177e4SLinus Torvalds 14371da177e4SLinus Torvalds output_declaration($declaration_name, 14381da177e4SLinus Torvalds 'typedef', 14391da177e4SLinus Torvalds {'typedef' => $declaration_name, 14401da177e4SLinus Torvalds 'module' => $modulename, 14411da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 14421da177e4SLinus Torvalds 'sections' => \%sections, 14431da177e4SLinus Torvalds 'purpose' => $declaration_purpose 14441da177e4SLinus Torvalds }); 14451da177e4SLinus Torvalds } 14461da177e4SLinus Torvalds else { 14471da177e4SLinus Torvalds print STDERR "Error(${file}:$.): Cannot parse typedef!\n"; 14481da177e4SLinus Torvalds ++$errors; 14491da177e4SLinus Torvalds } 14501da177e4SLinus Torvalds} 14511da177e4SLinus Torvalds 14521da177e4SLinus Torvaldssub create_parameterlist($$$) { 14531da177e4SLinus Torvalds my $args = shift; 14541da177e4SLinus Torvalds my $splitter = shift; 14551da177e4SLinus Torvalds my $file = shift; 14561da177e4SLinus Torvalds my $type; 14571da177e4SLinus Torvalds my $param; 14581da177e4SLinus Torvalds 1459a6d3fe77SMartin Waitz # temporarily replace commas inside function pointer definition 14601da177e4SLinus Torvalds while ($args =~ /(\([^\),]+),/) { 14611da177e4SLinus Torvalds $args =~ s/(\([^\),]+),/$1#/g; 14621da177e4SLinus Torvalds } 14631da177e4SLinus Torvalds 14641da177e4SLinus Torvalds foreach my $arg (split($splitter, $args)) { 14651da177e4SLinus Torvalds # strip comments 14661da177e4SLinus Torvalds $arg =~ s/\/\*.*\*\///; 14671da177e4SLinus Torvalds # strip leading/trailing spaces 14681da177e4SLinus Torvalds $arg =~ s/^\s*//; 14691da177e4SLinus Torvalds $arg =~ s/\s*$//; 14701da177e4SLinus Torvalds $arg =~ s/\s+/ /; 14711da177e4SLinus Torvalds 14721da177e4SLinus Torvalds if ($arg =~ /^#/) { 14731da177e4SLinus Torvalds # Treat preprocessor directive as a typeless variable just to fill 14741da177e4SLinus Torvalds # corresponding data structures "correctly". Catch it later in 14751da177e4SLinus Torvalds # output_* subs. 14761da177e4SLinus Torvalds push_parameter($arg, "", $file); 1477ea82c740SRandy Dunlap } elsif ($arg =~ m/\(.*\*/) { 14781da177e4SLinus Torvalds # pointer-to-function 14791da177e4SLinus Torvalds $arg =~ tr/#/,/; 1480996a07bcSRandy Dunlap $arg =~ m/[^\(]+\(\*\s*([^\)]+)\)/; 14811da177e4SLinus Torvalds $param = $1; 14821da177e4SLinus Torvalds $type = $arg; 14831da177e4SLinus Torvalds $type =~ s/([^\(]+\(\*)$param/$1/; 14841da177e4SLinus Torvalds push_parameter($param, $type, $file); 1485aeec46b9SMartin Waitz } elsif ($arg) { 14861da177e4SLinus Torvalds $arg =~ s/\s*:\s*/:/g; 14871da177e4SLinus Torvalds $arg =~ s/\s*\[/\[/g; 14881da177e4SLinus Torvalds 14891da177e4SLinus Torvalds my @args = split('\s*,\s*', $arg); 14901da177e4SLinus Torvalds if ($args[0] =~ m/\*/) { 14911da177e4SLinus Torvalds $args[0] =~ s/(\*+)\s*/ $1/; 14921da177e4SLinus Torvalds } 1493884f2810SBorislav Petkov 1494884f2810SBorislav Petkov my @first_arg; 1495884f2810SBorislav Petkov if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) { 1496884f2810SBorislav Petkov shift @args; 1497884f2810SBorislav Petkov push(@first_arg, split('\s+', $1)); 1498884f2810SBorislav Petkov push(@first_arg, $2); 1499884f2810SBorislav Petkov } else { 1500884f2810SBorislav Petkov @first_arg = split('\s+', shift @args); 1501884f2810SBorislav Petkov } 1502884f2810SBorislav Petkov 15031da177e4SLinus Torvalds unshift(@args, pop @first_arg); 15041da177e4SLinus Torvalds $type = join " ", @first_arg; 15051da177e4SLinus Torvalds 15061da177e4SLinus Torvalds foreach $param (@args) { 15071da177e4SLinus Torvalds if ($param =~ m/^(\*+)\s*(.*)/) { 15081da177e4SLinus Torvalds push_parameter($2, "$type $1", $file); 15091da177e4SLinus Torvalds } 15101da177e4SLinus Torvalds elsif ($param =~ m/(.*?):(\d+)/) { 15111da177e4SLinus Torvalds push_parameter($1, "$type:$2", $file) 15121da177e4SLinus Torvalds } 15131da177e4SLinus Torvalds else { 15141da177e4SLinus Torvalds push_parameter($param, $type, $file); 15151da177e4SLinus Torvalds } 15161da177e4SLinus Torvalds } 15171da177e4SLinus Torvalds } 15181da177e4SLinus Torvalds } 15191da177e4SLinus Torvalds} 15201da177e4SLinus Torvalds 15211da177e4SLinus Torvaldssub push_parameter($$$) { 15221da177e4SLinus Torvalds my $param = shift; 15231da177e4SLinus Torvalds my $type = shift; 15241da177e4SLinus Torvalds my $file = shift; 15251da177e4SLinus Torvalds 15265f8c7c98SRandy Dunlap if (($anon_struct_union == 1) && ($type eq "") && 15275f8c7c98SRandy Dunlap ($param eq "}")) { 15285f8c7c98SRandy Dunlap return; # ignore the ending }; from anon. struct/union 15295f8c7c98SRandy Dunlap } 15305f8c7c98SRandy Dunlap 15315f8c7c98SRandy Dunlap $anon_struct_union = 0; 15321da177e4SLinus Torvalds my $param_name = $param; 15331da177e4SLinus Torvalds $param_name =~ s/\[.*//; 15341da177e4SLinus Torvalds 1535a6d3fe77SMartin Waitz if ($type eq "" && $param =~ /\.\.\.$/) 15361da177e4SLinus Torvalds { 15371da177e4SLinus Torvalds $type=""; 1538a6d3fe77SMartin Waitz $parameterdescs{$param} = "variable arguments"; 15391da177e4SLinus Torvalds } 15401da177e4SLinus Torvalds elsif ($type eq "" && ($param eq "" or $param eq "void")) 15411da177e4SLinus Torvalds { 15421da177e4SLinus Torvalds $type=""; 15431da177e4SLinus Torvalds $param="void"; 15441da177e4SLinus Torvalds $parameterdescs{void} = "no arguments"; 15451da177e4SLinus Torvalds } 1546134fe01bSRandy Dunlap elsif ($type eq "" && ($param eq "struct" or $param eq "union")) 1547134fe01bSRandy Dunlap # handle unnamed (anonymous) union or struct: 1548134fe01bSRandy Dunlap { 1549134fe01bSRandy Dunlap $type = $param; 1550134fe01bSRandy Dunlap $param = "{unnamed_" . $param . "}"; 1551134fe01bSRandy Dunlap $parameterdescs{$param} = "anonymous\n"; 15525f8c7c98SRandy Dunlap $anon_struct_union = 1; 1553134fe01bSRandy Dunlap } 1554134fe01bSRandy Dunlap 1555a6d3fe77SMartin Waitz # warn if parameter has no description 1556134fe01bSRandy Dunlap # (but ignore ones starting with # as these are not parameters 1557134fe01bSRandy Dunlap # but inline preprocessor statements); 1558134fe01bSRandy Dunlap # also ignore unnamed structs/unions; 15595f8c7c98SRandy Dunlap if (!$anon_struct_union) { 1560a6d3fe77SMartin Waitz if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) { 1561a6d3fe77SMartin Waitz 15621da177e4SLinus Torvalds $parameterdescs{$param_name} = $undescribed; 15631da177e4SLinus Torvalds 15641da177e4SLinus Torvalds if (($type eq 'function') || ($type eq 'enum')) { 15651da177e4SLinus Torvalds print STDERR "Warning(${file}:$.): Function parameter ". 15661da177e4SLinus Torvalds "or member '$param' not " . 15671da177e4SLinus Torvalds "described in '$declaration_name'\n"; 15681da177e4SLinus Torvalds } 15691da177e4SLinus Torvalds print STDERR "Warning(${file}:$.):". 15701da177e4SLinus Torvalds " No description found for parameter '$param'\n"; 15711da177e4SLinus Torvalds ++$warnings; 15721da177e4SLinus Torvalds } 1573134fe01bSRandy Dunlap } 15741da177e4SLinus Torvalds 15751da177e4SLinus Torvalds push @parameterlist, $param; 15761da177e4SLinus Torvalds $parametertypes{$param} = $type; 15771da177e4SLinus Torvalds} 15781da177e4SLinus Torvalds 15791da177e4SLinus Torvalds## 15801da177e4SLinus Torvalds# takes a function prototype and the name of the current file being 15811da177e4SLinus Torvalds# processed and spits out all the details stored in the global 15821da177e4SLinus Torvalds# arrays/hashes. 15831da177e4SLinus Torvaldssub dump_function($$) { 15841da177e4SLinus Torvalds my $prototype = shift; 15851da177e4SLinus Torvalds my $file = shift; 15861da177e4SLinus Torvalds 15871da177e4SLinus Torvalds $prototype =~ s/^static +//; 15881da177e4SLinus Torvalds $prototype =~ s/^extern +//; 15894dc3b16bSPavel Pisa $prototype =~ s/^fastcall +//; 15904dc3b16bSPavel Pisa $prototype =~ s/^asmlinkage +//; 15911da177e4SLinus Torvalds $prototype =~ s/^inline +//; 15921da177e4SLinus Torvalds $prototype =~ s/^__inline__ +//; 159332e79401SRandy Dunlap $prototype =~ s/^__inline +//; 159432e79401SRandy Dunlap $prototype =~ s/^__always_inline +//; 159532e79401SRandy Dunlap $prototype =~ s/^noinline +//; 15960129a057SRandy Dunlap $prototype =~ s/__devinit +//; 1597996a07bcSRandy Dunlap $prototype =~ s/^#define\s+//; #ak added 1598328d2440SRandy Dunlap $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//; 15991da177e4SLinus Torvalds 16001da177e4SLinus Torvalds # Yes, this truly is vile. We are looking for: 16011da177e4SLinus Torvalds # 1. Return type (may be nothing if we're looking at a macro) 16021da177e4SLinus Torvalds # 2. Function name 16031da177e4SLinus Torvalds # 3. Function parameters. 16041da177e4SLinus Torvalds # 16051da177e4SLinus Torvalds # All the while we have to watch out for function pointer parameters 16061da177e4SLinus Torvalds # (which IIRC is what the two sections are for), C types (these 16071da177e4SLinus Torvalds # regexps don't even start to express all the possibilities), and 16081da177e4SLinus Torvalds # so on. 16091da177e4SLinus Torvalds # 16101da177e4SLinus Torvalds # If you mess with these regexps, it's a good idea to check that 16111da177e4SLinus Torvalds # the following functions' documentation still comes out right: 16121da177e4SLinus Torvalds # - parport_register_device (function pointer parameters) 16131da177e4SLinus Torvalds # - atomic_set (macro) 16149598f91fSMartin Waitz # - pci_match_device, __copy_to_user (long return type) 16151da177e4SLinus Torvalds 16161da177e4SLinus Torvalds if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 16171da177e4SLinus Torvalds $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 16181da177e4SLinus Torvalds $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 16191da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 16201da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 16211da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 16221da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 16231da177e4SLinus Torvalds $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 16241da177e4SLinus Torvalds $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 16251da177e4SLinus Torvalds $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 16261da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 16271da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 16281da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 16299598f91fSMartin Waitz $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 16309598f91fSMartin Waitz $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 1631412ecd77SRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 1632412ecd77SRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) { 16331da177e4SLinus Torvalds $return_type = $1; 16341da177e4SLinus Torvalds $declaration_name = $2; 16351da177e4SLinus Torvalds my $args = $3; 16361da177e4SLinus Torvalds 16371da177e4SLinus Torvalds create_parameterlist($args, ',', $file); 16381da177e4SLinus Torvalds } else { 16391da177e4SLinus Torvalds print STDERR "Error(${file}:$.): cannot understand prototype: '$prototype'\n"; 16401da177e4SLinus Torvalds ++$errors; 16411da177e4SLinus Torvalds return; 16421da177e4SLinus Torvalds } 16431da177e4SLinus Torvalds 16441da177e4SLinus Torvalds output_declaration($declaration_name, 16451da177e4SLinus Torvalds 'function', 16461da177e4SLinus Torvalds {'function' => $declaration_name, 16471da177e4SLinus Torvalds 'module' => $modulename, 16481da177e4SLinus Torvalds 'functiontype' => $return_type, 16491da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 16501da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 16511da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 16521da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 16531da177e4SLinus Torvalds 'sections' => \%sections, 16541da177e4SLinus Torvalds 'purpose' => $declaration_purpose 16551da177e4SLinus Torvalds }); 16561da177e4SLinus Torvalds} 16571da177e4SLinus Torvalds 16581da177e4SLinus Torvaldssub process_file($); 16591da177e4SLinus Torvalds 16601da177e4SLinus Torvalds# Read the file that maps relative names to absolute names for 16611da177e4SLinus Torvalds# separate source and object directories and for shadow trees. 16621da177e4SLinus Torvaldsif (open(SOURCE_MAP, "<.tmp_filelist.txt")) { 16631da177e4SLinus Torvalds my ($relname, $absname); 16641da177e4SLinus Torvalds while(<SOURCE_MAP>) { 16651da177e4SLinus Torvalds chop(); 16661da177e4SLinus Torvalds ($relname, $absname) = (split())[0..1]; 16671da177e4SLinus Torvalds $relname =~ s:^/+::; 16681da177e4SLinus Torvalds $source_map{$relname} = $absname; 16691da177e4SLinus Torvalds } 16701da177e4SLinus Torvalds close(SOURCE_MAP); 16711da177e4SLinus Torvalds} 16721da177e4SLinus Torvalds 16731da177e4SLinus Torvaldsif ($filelist) { 16741da177e4SLinus Torvalds open(FLIST,"<$filelist") or die "Can't open file list $filelist"; 16751da177e4SLinus Torvalds while(<FLIST>) { 16761da177e4SLinus Torvalds chop; 16771da177e4SLinus Torvalds process_file($_); 16781da177e4SLinus Torvalds } 16791da177e4SLinus Torvalds} 16801da177e4SLinus Torvalds 16811da177e4SLinus Torvaldsforeach (@ARGV) { 16821da177e4SLinus Torvalds chomp; 16831da177e4SLinus Torvalds process_file($_); 16841da177e4SLinus Torvalds} 16851da177e4SLinus Torvaldsif ($verbose && $errors) { 16861da177e4SLinus Torvalds print STDERR "$errors errors\n"; 16871da177e4SLinus Torvalds} 16881da177e4SLinus Torvaldsif ($verbose && $warnings) { 16891da177e4SLinus Torvalds print STDERR "$warnings warnings\n"; 16901da177e4SLinus Torvalds} 16911da177e4SLinus Torvalds 16921da177e4SLinus Torvaldsexit($errors); 16931da177e4SLinus Torvalds 16941da177e4SLinus Torvaldssub reset_state { 16951da177e4SLinus Torvalds $function = ""; 16961da177e4SLinus Torvalds %constants = (); 16971da177e4SLinus Torvalds %parameterdescs = (); 16981da177e4SLinus Torvalds %parametertypes = (); 16991da177e4SLinus Torvalds @parameterlist = (); 17001da177e4SLinus Torvalds %sections = (); 17011da177e4SLinus Torvalds @sectionlist = (); 17021da177e4SLinus Torvalds $prototype = ""; 17031da177e4SLinus Torvalds 17041da177e4SLinus Torvalds $state = 0; 17051da177e4SLinus Torvalds} 17061da177e4SLinus Torvalds 17071da177e4SLinus Torvaldssub process_state3_function($$) { 17081da177e4SLinus Torvalds my $x = shift; 17091da177e4SLinus Torvalds my $file = shift; 17101da177e4SLinus Torvalds 171151f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 171251f5a0c8SRandy Dunlap 17131da177e4SLinus Torvalds if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#define/)) { 17141da177e4SLinus Torvalds # do nothing 17151da177e4SLinus Torvalds } 17161da177e4SLinus Torvalds elsif ($x =~ /([^\{]*)/) { 17171da177e4SLinus Torvalds $prototype .= $1; 17181da177e4SLinus Torvalds } 17191da177e4SLinus Torvalds if (($x =~ /\{/) || ($x =~ /\#define/) || ($x =~ /;/)) { 17201da177e4SLinus Torvalds $prototype =~ s@/\*.*?\*/@@gos; # strip comments. 17211da177e4SLinus Torvalds $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 17221da177e4SLinus Torvalds $prototype =~ s@^\s+@@gos; # strip leading spaces 17231da177e4SLinus Torvalds dump_function($prototype,$file); 17241da177e4SLinus Torvalds reset_state(); 17251da177e4SLinus Torvalds } 17261da177e4SLinus Torvalds} 17271da177e4SLinus Torvalds 17281da177e4SLinus Torvaldssub process_state3_type($$) { 17291da177e4SLinus Torvalds my $x = shift; 17301da177e4SLinus Torvalds my $file = shift; 17311da177e4SLinus Torvalds 17321da177e4SLinus Torvalds $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 17331da177e4SLinus Torvalds $x =~ s@^\s+@@gos; # strip leading spaces 17341da177e4SLinus Torvalds $x =~ s@\s+$@@gos; # strip trailing spaces 173551f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 173651f5a0c8SRandy Dunlap 17371da177e4SLinus Torvalds if ($x =~ /^#/) { 17381da177e4SLinus Torvalds # To distinguish preprocessor directive from regular declaration later. 17391da177e4SLinus Torvalds $x .= ";"; 17401da177e4SLinus Torvalds } 17411da177e4SLinus Torvalds 17421da177e4SLinus Torvalds while (1) { 17431da177e4SLinus Torvalds if ( $x =~ /([^{};]*)([{};])(.*)/ ) { 17441da177e4SLinus Torvalds $prototype .= $1 . $2; 17451da177e4SLinus Torvalds ($2 eq '{') && $brcount++; 17461da177e4SLinus Torvalds ($2 eq '}') && $brcount--; 17471da177e4SLinus Torvalds if (($2 eq ';') && ($brcount == 0)) { 17481da177e4SLinus Torvalds dump_declaration($prototype,$file); 17491da177e4SLinus Torvalds reset_state(); 17501da177e4SLinus Torvalds last; 17511da177e4SLinus Torvalds } 17521da177e4SLinus Torvalds $x = $3; 17531da177e4SLinus Torvalds } else { 17541da177e4SLinus Torvalds $prototype .= $x; 17551da177e4SLinus Torvalds last; 17561da177e4SLinus Torvalds } 17571da177e4SLinus Torvalds } 17581da177e4SLinus Torvalds} 17591da177e4SLinus Torvalds 1760*6b5b55f6SRandy Dunlap# xml_escape: replace <, >, and & in the text stream; 1761*6b5b55f6SRandy Dunlap# 1762*6b5b55f6SRandy Dunlap# however, formatting controls that are generated internally/locally in the 1763*6b5b55f6SRandy Dunlap# kernel-doc script are not escaped here; instead, they begin life like 1764*6b5b55f6SRandy Dunlap# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings 1765*6b5b55f6SRandy Dunlap# are converted to their mnemonic-expected output, without the 4 * '\' & ':', 1766*6b5b55f6SRandy Dunlap# just before actual output; (this is done by local_unescape()) 17671da177e4SLinus Torvaldssub xml_escape($) { 17681da177e4SLinus Torvalds my $text = shift; 1769ecfb251aSRandy Dunlap if (($output_mode eq "text") || ($output_mode eq "man")) { 1770ecfb251aSRandy Dunlap return $text; 1771ecfb251aSRandy Dunlap } 17721da177e4SLinus Torvalds $text =~ s/\&/\\\\\\amp;/g; 17731da177e4SLinus Torvalds $text =~ s/\</\\\\\\lt;/g; 17741da177e4SLinus Torvalds $text =~ s/\>/\\\\\\gt;/g; 17751da177e4SLinus Torvalds return $text; 17761da177e4SLinus Torvalds} 17771da177e4SLinus Torvalds 1778*6b5b55f6SRandy Dunlap# convert local escape strings to html 1779*6b5b55f6SRandy Dunlap# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes) 1780*6b5b55f6SRandy Dunlapsub local_unescape($) { 1781*6b5b55f6SRandy Dunlap my $text = shift; 1782*6b5b55f6SRandy Dunlap if (($output_mode eq "text") || ($output_mode eq "man")) { 1783*6b5b55f6SRandy Dunlap return $text; 1784*6b5b55f6SRandy Dunlap } 1785*6b5b55f6SRandy Dunlap $text =~ s/\\\\\\\\lt:/</g; 1786*6b5b55f6SRandy Dunlap $text =~ s/\\\\\\\\gt:/>/g; 1787*6b5b55f6SRandy Dunlap return $text; 1788*6b5b55f6SRandy Dunlap} 1789*6b5b55f6SRandy Dunlap 17901da177e4SLinus Torvaldssub process_file($) { 17912283a117SRandy Dunlap my $file; 17921da177e4SLinus Torvalds my $identifier; 17931da177e4SLinus Torvalds my $func; 1794a21217daSRandy Dunlap my $descr; 17951da177e4SLinus Torvalds my $initial_section_counter = $section_counter; 17961da177e4SLinus Torvalds 17972283a117SRandy Dunlap if (defined($ENV{'SRCTREE'})) { 17982283a117SRandy Dunlap $file = "$ENV{'SRCTREE'}" . "/" . "@_"; 17992283a117SRandy Dunlap } 18002283a117SRandy Dunlap else { 18012283a117SRandy Dunlap $file = "@_"; 18022283a117SRandy Dunlap } 18031da177e4SLinus Torvalds if (defined($source_map{$file})) { 18041da177e4SLinus Torvalds $file = $source_map{$file}; 18051da177e4SLinus Torvalds } 18061da177e4SLinus Torvalds 18071da177e4SLinus Torvalds if (!open(IN,"<$file")) { 18081da177e4SLinus Torvalds print STDERR "Error: Cannot open file $file\n"; 18091da177e4SLinus Torvalds ++$errors; 18101da177e4SLinus Torvalds return; 18111da177e4SLinus Torvalds } 18121da177e4SLinus Torvalds 18131da177e4SLinus Torvalds $section_counter = 0; 18141da177e4SLinus Torvalds while (<IN>) { 18151da177e4SLinus Torvalds if ($state == 0) { 18161da177e4SLinus Torvalds if (/$doc_start/o) { 18171da177e4SLinus Torvalds $state = 1; # next line is always the function name 1818850622dfSRandy Dunlap $in_doc_sect = 0; 18191da177e4SLinus Torvalds } 18201da177e4SLinus Torvalds } elsif ($state == 1) { # this line is the function name (always) 18211da177e4SLinus Torvalds if (/$doc_block/o) { 18221da177e4SLinus Torvalds $state = 4; 18231da177e4SLinus Torvalds $contents = ""; 18241da177e4SLinus Torvalds if ( $1 eq "" ) { 18251da177e4SLinus Torvalds $section = $section_intro; 18261da177e4SLinus Torvalds } else { 18271da177e4SLinus Torvalds $section = $1; 18281da177e4SLinus Torvalds } 18291da177e4SLinus Torvalds } 18301da177e4SLinus Torvalds elsif (/$doc_decl/o) { 18311da177e4SLinus Torvalds $identifier = $1; 18321da177e4SLinus Torvalds if (/\s*([\w\s]+?)\s*-/) { 18331da177e4SLinus Torvalds $identifier = $1; 18341da177e4SLinus Torvalds } 18351da177e4SLinus Torvalds 18361da177e4SLinus Torvalds $state = 2; 18371da177e4SLinus Torvalds if (/-(.*)/) { 183851f5a0c8SRandy Dunlap # strip leading/trailing/multiple spaces 1839a21217daSRandy Dunlap $descr= $1; 1840a21217daSRandy Dunlap $descr =~ s/^\s*//; 1841a21217daSRandy Dunlap $descr =~ s/\s*$//; 1842a21217daSRandy Dunlap $descr =~ s/\s+/ /; 1843a21217daSRandy Dunlap $declaration_purpose = xml_escape($descr); 18441da177e4SLinus Torvalds } else { 18451da177e4SLinus Torvalds $declaration_purpose = ""; 18461da177e4SLinus Torvalds } 18471da177e4SLinus Torvalds if ($identifier =~ m/^struct/) { 18481da177e4SLinus Torvalds $decl_type = 'struct'; 18491da177e4SLinus Torvalds } elsif ($identifier =~ m/^union/) { 18501da177e4SLinus Torvalds $decl_type = 'union'; 18511da177e4SLinus Torvalds } elsif ($identifier =~ m/^enum/) { 18521da177e4SLinus Torvalds $decl_type = 'enum'; 18531da177e4SLinus Torvalds } elsif ($identifier =~ m/^typedef/) { 18541da177e4SLinus Torvalds $decl_type = 'typedef'; 18551da177e4SLinus Torvalds } else { 18561da177e4SLinus Torvalds $decl_type = 'function'; 18571da177e4SLinus Torvalds } 18581da177e4SLinus Torvalds 18591da177e4SLinus Torvalds if ($verbose) { 18601da177e4SLinus Torvalds print STDERR "Info(${file}:$.): Scanning doc for $identifier\n"; 18611da177e4SLinus Torvalds } 18621da177e4SLinus Torvalds } else { 18631da177e4SLinus Torvalds print STDERR "Warning(${file}:$.): Cannot understand $_ on line $.", 18641da177e4SLinus Torvalds " - I thought it was a doc line\n"; 18651da177e4SLinus Torvalds ++$warnings; 18661da177e4SLinus Torvalds $state = 0; 18671da177e4SLinus Torvalds } 18681da177e4SLinus Torvalds } elsif ($state == 2) { # look for head: lines, and include content 18691da177e4SLinus Torvalds if (/$doc_sect/o) { 18701da177e4SLinus Torvalds $newsection = $1; 18711da177e4SLinus Torvalds $newcontents = $2; 18721da177e4SLinus Torvalds 18731da177e4SLinus Torvalds if ($contents ne "") { 1874850622dfSRandy Dunlap if (!$in_doc_sect && $verbose) { 1875850622dfSRandy Dunlap print STDERR "Warning(${file}:$.): contents before sections\n"; 1876850622dfSRandy Dunlap ++$warnings; 1877850622dfSRandy Dunlap } 18781da177e4SLinus Torvalds dump_section($section, xml_escape($contents)); 18791da177e4SLinus Torvalds $section = $section_default; 18801da177e4SLinus Torvalds } 18811da177e4SLinus Torvalds 1882850622dfSRandy Dunlap $in_doc_sect = 1; 18831da177e4SLinus Torvalds $contents = $newcontents; 18841da177e4SLinus Torvalds if ($contents ne "") { 188527205744SRandy Dunlap while ((substr($contents, 0, 1) eq " ") || 188627205744SRandy Dunlap substr($contents, 0, 1) eq "\t") { 188705189497SRandy Dunlap $contents = substr($contents, 1); 188805189497SRandy Dunlap } 18891da177e4SLinus Torvalds $contents .= "\n"; 18901da177e4SLinus Torvalds } 18911da177e4SLinus Torvalds $section = $newsection; 18921da177e4SLinus Torvalds } elsif (/$doc_end/) { 18931da177e4SLinus Torvalds 18941da177e4SLinus Torvalds if ($contents ne "") { 18951da177e4SLinus Torvalds dump_section($section, xml_escape($contents)); 18961da177e4SLinus Torvalds $section = $section_default; 18971da177e4SLinus Torvalds $contents = ""; 18981da177e4SLinus Torvalds } 18991da177e4SLinus Torvalds 19001da177e4SLinus Torvalds $prototype = ""; 19011da177e4SLinus Torvalds $state = 3; 19021da177e4SLinus Torvalds $brcount = 0; 19031da177e4SLinus Torvalds# print STDERR "end of doc comment, looking for prototype\n"; 19041da177e4SLinus Torvalds } elsif (/$doc_content/) { 19051da177e4SLinus Torvalds # miguel-style comment kludge, look for blank lines after 19061da177e4SLinus Torvalds # @parameter line to signify start of description 19071da177e4SLinus Torvalds if ($1 eq "" && 19081da177e4SLinus Torvalds ($section =~ m/^@/ || $section eq $section_context)) { 19091da177e4SLinus Torvalds dump_section($section, xml_escape($contents)); 19101da177e4SLinus Torvalds $section = $section_default; 19111da177e4SLinus Torvalds $contents = ""; 19121da177e4SLinus Torvalds } else { 19131da177e4SLinus Torvalds $contents .= $1."\n"; 19141da177e4SLinus Torvalds } 19151da177e4SLinus Torvalds } else { 19161da177e4SLinus Torvalds # i dont know - bad line? ignore. 19171da177e4SLinus Torvalds print STDERR "Warning(${file}:$.): bad line: $_"; 19181da177e4SLinus Torvalds ++$warnings; 19191da177e4SLinus Torvalds } 1920232acbcfSRandy Dunlap } elsif ($state == 3) { # scanning for function '{' (end of prototype) 19211da177e4SLinus Torvalds if ($decl_type eq 'function') { 19221da177e4SLinus Torvalds process_state3_function($_, $file); 19231da177e4SLinus Torvalds } else { 19241da177e4SLinus Torvalds process_state3_type($_, $file); 19251da177e4SLinus Torvalds } 19261da177e4SLinus Torvalds } elsif ($state == 4) { 19271da177e4SLinus Torvalds # Documentation block 19281da177e4SLinus Torvalds if (/$doc_block/) { 1929*6b5b55f6SRandy Dunlap dump_section($section, xml_escape($contents)); 19301da177e4SLinus Torvalds output_intro({'sectionlist' => \@sectionlist, 19311da177e4SLinus Torvalds 'sections' => \%sections }); 19321da177e4SLinus Torvalds $contents = ""; 19331da177e4SLinus Torvalds $function = ""; 19341da177e4SLinus Torvalds %constants = (); 19351da177e4SLinus Torvalds %parameterdescs = (); 19361da177e4SLinus Torvalds %parametertypes = (); 19371da177e4SLinus Torvalds @parameterlist = (); 19381da177e4SLinus Torvalds %sections = (); 19391da177e4SLinus Torvalds @sectionlist = (); 19401da177e4SLinus Torvalds $prototype = ""; 19411da177e4SLinus Torvalds if ( $1 eq "" ) { 19421da177e4SLinus Torvalds $section = $section_intro; 19431da177e4SLinus Torvalds } else { 19441da177e4SLinus Torvalds $section = $1; 19451da177e4SLinus Torvalds } 19461da177e4SLinus Torvalds } 19471da177e4SLinus Torvalds elsif (/$doc_end/) 19481da177e4SLinus Torvalds { 1949*6b5b55f6SRandy Dunlap dump_section($section, xml_escape($contents)); 19501da177e4SLinus Torvalds output_intro({'sectionlist' => \@sectionlist, 19511da177e4SLinus Torvalds 'sections' => \%sections }); 19521da177e4SLinus Torvalds $contents = ""; 19531da177e4SLinus Torvalds $function = ""; 19541da177e4SLinus Torvalds %constants = (); 19551da177e4SLinus Torvalds %parameterdescs = (); 19561da177e4SLinus Torvalds %parametertypes = (); 19571da177e4SLinus Torvalds @parameterlist = (); 19581da177e4SLinus Torvalds %sections = (); 19591da177e4SLinus Torvalds @sectionlist = (); 19601da177e4SLinus Torvalds $prototype = ""; 19611da177e4SLinus Torvalds $state = 0; 19621da177e4SLinus Torvalds } 19631da177e4SLinus Torvalds elsif (/$doc_content/) 19641da177e4SLinus Torvalds { 19651da177e4SLinus Torvalds if ( $1 eq "" ) 19661da177e4SLinus Torvalds { 19671da177e4SLinus Torvalds $contents .= $blankline; 19681da177e4SLinus Torvalds } 19691da177e4SLinus Torvalds else 19701da177e4SLinus Torvalds { 19711da177e4SLinus Torvalds $contents .= $1 . "\n"; 19721da177e4SLinus Torvalds } 19731da177e4SLinus Torvalds } 19741da177e4SLinus Torvalds } 19751da177e4SLinus Torvalds } 19761da177e4SLinus Torvalds if ($initial_section_counter == $section_counter) { 19771da177e4SLinus Torvalds print STDERR "Warning(${file}): no structured comments found\n"; 19781da177e4SLinus Torvalds if ($output_mode eq "xml") { 19791da177e4SLinus Torvalds # The template wants at least one RefEntry here; make one. 19801da177e4SLinus Torvalds print "<refentry>\n"; 19811da177e4SLinus Torvalds print " <refnamediv>\n"; 19821da177e4SLinus Torvalds print " <refname>\n"; 19831da177e4SLinus Torvalds print " ${file}\n"; 19841da177e4SLinus Torvalds print " </refname>\n"; 19851da177e4SLinus Torvalds print " <refpurpose>\n"; 19861da177e4SLinus Torvalds print " Document generation inconsistency\n"; 19871da177e4SLinus Torvalds print " </refpurpose>\n"; 19881da177e4SLinus Torvalds print " </refnamediv>\n"; 19891da177e4SLinus Torvalds print " <refsect1>\n"; 19901da177e4SLinus Torvalds print " <title>\n"; 19911da177e4SLinus Torvalds print " Oops\n"; 19921da177e4SLinus Torvalds print " </title>\n"; 19931da177e4SLinus Torvalds print " <warning>\n"; 19941da177e4SLinus Torvalds print " <para>\n"; 19951da177e4SLinus Torvalds print " The template for this document tried to insert\n"; 19961da177e4SLinus Torvalds print " the structured comment from the file\n"; 19971da177e4SLinus Torvalds print " <filename>${file}</filename> at this point,\n"; 19981da177e4SLinus Torvalds print " but none was found.\n"; 19991da177e4SLinus Torvalds print " This dummy section is inserted to allow\n"; 20001da177e4SLinus Torvalds print " generation to continue.\n"; 20011da177e4SLinus Torvalds print " </para>\n"; 20021da177e4SLinus Torvalds print " </warning>\n"; 20031da177e4SLinus Torvalds print " </refsect1>\n"; 20041da177e4SLinus Torvalds print "</refentry>\n"; 20051da177e4SLinus Torvalds } 20061da177e4SLinus Torvalds } 20071da177e4SLinus Torvalds} 2008