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 ## 870c95b00SRandy Dunlap## Copyright (C) 2005-2012 Randy Dunlap ## 91b40c194SDan Luedtke## Copyright (C) 2012 Dan Luedtke ## 101da177e4SLinus Torvalds## ## 111da177e4SLinus Torvalds## #define enhancements by Armin Kuster <akuster@mvista.com> ## 121da177e4SLinus Torvalds## Copyright (c) 2000 MontaVista Software, Inc. ## 131da177e4SLinus Torvalds## ## 141da177e4SLinus Torvalds## This software falls under the GNU General Public License. ## 151da177e4SLinus Torvalds## Please read the COPYING file for more information ## 161da177e4SLinus Torvalds 171da177e4SLinus Torvalds# 18/01/2001 - Cleanups 181da177e4SLinus Torvalds# Functions prototyped as foo(void) same as foo() 191da177e4SLinus Torvalds# Stop eval'ing where we don't need to. 201da177e4SLinus Torvalds# -- huggie@earth.li 211da177e4SLinus Torvalds 221da177e4SLinus Torvalds# 27/06/2001 - Allowed whitespace after initial "/**" and 231da177e4SLinus Torvalds# allowed comments before function declarations. 241da177e4SLinus Torvalds# -- Christian Kreibich <ck@whoop.org> 251da177e4SLinus Torvalds 261da177e4SLinus Torvalds# Still to do: 271da177e4SLinus Torvalds# - add perldoc documentation 281da177e4SLinus Torvalds# - Look more closely at some of the scarier bits :) 291da177e4SLinus Torvalds 301da177e4SLinus Torvalds# 26/05/2001 - Support for separate source and object trees. 311da177e4SLinus Torvalds# Return error code. 321da177e4SLinus Torvalds# Keith Owens <kaos@ocs.com.au> 331da177e4SLinus Torvalds 341da177e4SLinus Torvalds# 23/09/2001 - Added support for typedefs, structs, enums and unions 351da177e4SLinus Torvalds# Support for Context section; can be terminated using empty line 361da177e4SLinus Torvalds# Small fixes (like spaces vs. \s in regex) 371da177e4SLinus Torvalds# -- Tim Jansen <tim@tjansen.de> 381da177e4SLinus Torvalds 391b40c194SDan Luedtke# 25/07/2012 - Added support for HTML5 401b40c194SDan Luedtke# -- Dan Luedtke <mail@danrl.de> 411da177e4SLinus Torvalds 421da177e4SLinus Torvalds# 431da177e4SLinus Torvalds# This will read a 'c' file and scan for embedded comments in the 441da177e4SLinus Torvalds# style of gnome comments (+minor extensions - see below). 451da177e4SLinus Torvalds# 461da177e4SLinus Torvalds 471da177e4SLinus Torvalds# Note: This only supports 'c'. 481da177e4SLinus Torvalds 491da177e4SLinus Torvalds# usage: 501b40c194SDan Luedtke# kernel-doc [ -docbook | -html | -html5 | -text | -man | -list ] 511b40c194SDan Luedtke# [ -no-doc-sections ] 521b40c194SDan Luedtke# [ -function funcname [ -function funcname ...] ] 531b40c194SDan Luedtke# c file(s)s > outputfile 541da177e4SLinus Torvalds# or 551b40c194SDan Luedtke# [ -nofunction funcname [ -function funcname ...] ] 561b40c194SDan Luedtke# c file(s)s > outputfile 571da177e4SLinus Torvalds# 581b40c194SDan Luedtke# Set output format using one of -docbook -html -html5 -text or -man. 591b40c194SDan Luedtke# Default is man. 60eda603f6SJohannes Berg# The -list format is for internal use by docproc. 611da177e4SLinus Torvalds# 624b44595aSJohannes Berg# -no-doc-sections 634b44595aSJohannes Berg# Do not output DOC: sections 644b44595aSJohannes Berg# 651da177e4SLinus Torvalds# -function funcname 66b112e0f7SJohannes Berg# If set, then only generate documentation for the given function(s) or 67b112e0f7SJohannes Berg# DOC: section titles. All other functions and DOC: sections are ignored. 681da177e4SLinus Torvalds# 691da177e4SLinus Torvalds# -nofunction funcname 70b112e0f7SJohannes Berg# If set, then only generate documentation for the other function(s)/DOC: 71b112e0f7SJohannes Berg# sections. Cannot be used together with -function (yes, that's a bug -- 72b112e0f7SJohannes Berg# perl hackers can fix it 8)) 731da177e4SLinus Torvalds# 741da177e4SLinus Torvalds# c files - list of 'c' files to process 751da177e4SLinus Torvalds# 761da177e4SLinus Torvalds# All output goes to stdout, with errors to stderr. 771da177e4SLinus Torvalds 781da177e4SLinus Torvalds# 791da177e4SLinus Torvalds# format of comments. 801da177e4SLinus Torvalds# In the following table, (...)? signifies optional structure. 811da177e4SLinus Torvalds# (...)* signifies 0 or more structure elements 821da177e4SLinus Torvalds# /** 831da177e4SLinus Torvalds# * function_name(:)? (- short description)? 841da177e4SLinus Torvalds# (* @parameterx: (description of parameter x)?)* 851da177e4SLinus Torvalds# (* a blank line)? 861da177e4SLinus Torvalds# * (Description:)? (Description of function)? 871da177e4SLinus Torvalds# * (section header: (section description)? )* 881da177e4SLinus Torvalds# (*)?*/ 891da177e4SLinus Torvalds# 901da177e4SLinus Torvalds# So .. the trivial example would be: 911da177e4SLinus Torvalds# 921da177e4SLinus Torvalds# /** 931da177e4SLinus Torvalds# * my_function 94b9d97328SRandy Dunlap# */ 951da177e4SLinus Torvalds# 96891dcd2fSRandy Dunlap# If the Description: header tag is omitted, then there must be a blank line 971da177e4SLinus Torvalds# after the last parameter specification. 981da177e4SLinus Torvalds# e.g. 991da177e4SLinus Torvalds# /** 1001da177e4SLinus Torvalds# * my_function - does my stuff 1011da177e4SLinus Torvalds# * @my_arg: its mine damnit 1021da177e4SLinus Torvalds# * 1031da177e4SLinus Torvalds# * Does my stuff explained. 1041da177e4SLinus Torvalds# */ 1051da177e4SLinus Torvalds# 1061da177e4SLinus Torvalds# or, could also use: 1071da177e4SLinus Torvalds# /** 1081da177e4SLinus Torvalds# * my_function - does my stuff 1091da177e4SLinus Torvalds# * @my_arg: its mine damnit 1101da177e4SLinus Torvalds# * Description: Does my stuff explained. 1111da177e4SLinus Torvalds# */ 1121da177e4SLinus Torvalds# etc. 1131da177e4SLinus Torvalds# 114b9d97328SRandy Dunlap# Besides functions you can also write documentation for structs, unions, 1151da177e4SLinus Torvalds# enums and typedefs. Instead of the function name you must write the name 1161da177e4SLinus Torvalds# of the declaration; the struct/union/enum/typedef must always precede 1171da177e4SLinus Torvalds# the name. Nesting of declarations is not supported. 1181da177e4SLinus Torvalds# Use the argument mechanism to document members or constants. 1191da177e4SLinus Torvalds# e.g. 1201da177e4SLinus Torvalds# /** 1211da177e4SLinus Torvalds# * struct my_struct - short description 1221da177e4SLinus Torvalds# * @a: first member 1231da177e4SLinus Torvalds# * @b: second member 1241da177e4SLinus Torvalds# * 1251da177e4SLinus Torvalds# * Longer description 1261da177e4SLinus Torvalds# */ 1271da177e4SLinus Torvalds# struct my_struct { 1281da177e4SLinus Torvalds# int a; 1291da177e4SLinus Torvalds# int b; 130aeec46b9SMartin Waitz# /* private: */ 131aeec46b9SMartin Waitz# int c; 1321da177e4SLinus Torvalds# }; 1331da177e4SLinus Torvalds# 1341da177e4SLinus Torvalds# All descriptions can be multiline, except the short function description. 1351da177e4SLinus Torvalds# 1361da177e4SLinus Torvalds# You can also add additional sections. When documenting kernel functions you 1371da177e4SLinus Torvalds# should document the "Context:" of the function, e.g. whether the functions 1381da177e4SLinus Torvalds# can be called form interrupts. Unlike other sections you can end it with an 1391da177e4SLinus Torvalds# empty line. 1404092bac7SYacine Belkadi# A non-void function should have a "Return:" section describing the return 1414092bac7SYacine Belkadi# value(s). 1421da177e4SLinus Torvalds# Example-sections should contain the string EXAMPLE so that they are marked 1431da177e4SLinus Torvalds# appropriately in DocBook. 1441da177e4SLinus Torvalds# 1451da177e4SLinus Torvalds# Example: 1461da177e4SLinus Torvalds# /** 1471da177e4SLinus Torvalds# * user_function - function that can only be called in user context 1481da177e4SLinus Torvalds# * @a: some argument 1491da177e4SLinus Torvalds# * Context: !in_interrupt() 1501da177e4SLinus Torvalds# * 1511da177e4SLinus Torvalds# * Some description 1521da177e4SLinus Torvalds# * Example: 1531da177e4SLinus Torvalds# * user_function(22); 1541da177e4SLinus Torvalds# */ 1551da177e4SLinus Torvalds# ... 1561da177e4SLinus Torvalds# 1571da177e4SLinus Torvalds# 1581da177e4SLinus Torvalds# All descriptive text is further processed, scanning for the following special 1591da177e4SLinus Torvalds# patterns, which are highlighted appropriately. 1601da177e4SLinus Torvalds# 1611da177e4SLinus Torvalds# 'funcname()' - function 1621da177e4SLinus Torvalds# '$ENVVAR' - environmental variable 1631da177e4SLinus Torvalds# '&struct_name' - name of a structure (up to two words including 'struct') 1641da177e4SLinus Torvalds# '@parameter' - name of a parameter 1651da177e4SLinus Torvalds# '%CONST' - name of a constant. 1661da177e4SLinus Torvalds 1678484baaaSRandy Dunlap## init lots of data 1688484baaaSRandy Dunlap 1691da177e4SLinus Torvaldsmy $errors = 0; 1701da177e4SLinus Torvaldsmy $warnings = 0; 1715f8c7c98SRandy Dunlapmy $anon_struct_union = 0; 1721da177e4SLinus Torvalds 1731da177e4SLinus Torvalds# match expressions used to find embedded type information 1741da177e4SLinus Torvaldsmy $type_constant = '\%([-_\w]+)'; 1751da177e4SLinus Torvaldsmy $type_func = '(\w+)\(\)'; 1761da177e4SLinus Torvaldsmy $type_param = '\@(\w+)'; 1773eb014a1SRandy Dunlapmy $type_struct = '\&((struct\s*)*[_\w]+)'; 1786b5b55f6SRandy Dunlapmy $type_struct_xml = '\\&((struct\s*)*[_\w]+)'; 1791da177e4SLinus Torvaldsmy $type_env = '(\$\w+)'; 1801da177e4SLinus Torvalds 1811da177e4SLinus Torvalds# Output conversion substitutions. 1821da177e4SLinus Torvalds# One for each output format 1831da177e4SLinus Torvalds 1841da177e4SLinus Torvalds# these work fairly well 1851da177e4SLinus Torvaldsmy %highlights_html = ( $type_constant, "<i>\$1</i>", 1861da177e4SLinus Torvalds $type_func, "<b>\$1</b>", 1873eb014a1SRandy Dunlap $type_struct_xml, "<i>\$1</i>", 1883eb014a1SRandy Dunlap $type_env, "<b><i>\$1</i></b>", 1891da177e4SLinus Torvalds $type_param, "<tt><b>\$1</b></tt>" ); 1906b5b55f6SRandy Dunlapmy $local_lt = "\\\\\\\\lt:"; 1916b5b55f6SRandy Dunlapmy $local_gt = "\\\\\\\\gt:"; 1926b5b55f6SRandy Dunlapmy $blankline_html = $local_lt . "p" . $local_gt; # was "<p>" 1931da177e4SLinus Torvalds 1941b40c194SDan Luedtke# html version 5 1951b40c194SDan Luedtkemy %highlights_html5 = ( $type_constant, "<span class=\"const\">\$1</span>", 1961b40c194SDan Luedtke $type_func, "<span class=\"func\">\$1</span>", 1971b40c194SDan Luedtke $type_struct_xml, "<span class=\"struct\">\$1</span>", 1981b40c194SDan Luedtke $type_env, "<span class=\"env\">\$1</span>", 1991b40c194SDan Luedtke $type_param, "<span class=\"param\">\$1</span>" ); 2001b40c194SDan Luedtkemy $blankline_html5 = $local_lt . "br /" . $local_gt; 2011b40c194SDan Luedtke 2021da177e4SLinus Torvalds# XML, docbook format 2031da177e4SLinus Torvaldsmy %highlights_xml = ( "([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>", 2041da177e4SLinus Torvalds $type_constant, "<constant>\$1</constant>", 2051da177e4SLinus Torvalds $type_func, "<function>\$1</function>", 2065c98fc03SJohannes Berg $type_struct_xml, "<structname>\$1</structname>", 2071da177e4SLinus Torvalds $type_env, "<envar>\$1</envar>", 2081da177e4SLinus Torvalds $type_param, "<parameter>\$1</parameter>" ); 2095c98fc03SJohannes Bergmy $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n"; 2101da177e4SLinus Torvalds 2111da177e4SLinus Torvalds# gnome, docbook format 2121da177e4SLinus Torvaldsmy %highlights_gnome = ( $type_constant, "<replaceable class=\"option\">\$1</replaceable>", 2131da177e4SLinus Torvalds $type_func, "<function>\$1</function>", 2141da177e4SLinus Torvalds $type_struct, "<structname>\$1</structname>", 2151da177e4SLinus Torvalds $type_env, "<envar>\$1</envar>", 2161da177e4SLinus Torvalds $type_param, "<parameter>\$1</parameter>" ); 2171da177e4SLinus Torvaldsmy $blankline_gnome = "</para><para>\n"; 2181da177e4SLinus Torvalds 2191da177e4SLinus Torvalds# these are pretty rough 2201da177e4SLinus Torvaldsmy %highlights_man = ( $type_constant, "\$1", 2211da177e4SLinus Torvalds $type_func, "\\\\fB\$1\\\\fP", 2221da177e4SLinus Torvalds $type_struct, "\\\\fI\$1\\\\fP", 2231da177e4SLinus Torvalds $type_param, "\\\\fI\$1\\\\fP" ); 2241da177e4SLinus Torvaldsmy $blankline_man = ""; 2251da177e4SLinus Torvalds 2261da177e4SLinus Torvalds# text-mode 2271da177e4SLinus Torvaldsmy %highlights_text = ( $type_constant, "\$1", 2281da177e4SLinus Torvalds $type_func, "\$1", 2291da177e4SLinus Torvalds $type_struct, "\$1", 2301da177e4SLinus Torvalds $type_param, "\$1" ); 2311da177e4SLinus Torvaldsmy $blankline_text = ""; 2321da177e4SLinus Torvalds 233eda603f6SJohannes Berg# list mode 234eda603f6SJohannes Bergmy %highlights_list = ( $type_constant, "\$1", 235eda603f6SJohannes Berg $type_func, "\$1", 236eda603f6SJohannes Berg $type_struct, "\$1", 237eda603f6SJohannes Berg $type_param, "\$1" ); 238eda603f6SJohannes Bergmy $blankline_list = ""; 2391da177e4SLinus Torvalds 2401da177e4SLinus Torvalds# read arguments 2411da177e4SLinus Torvaldsif ($#ARGV == -1) { 2421da177e4SLinus Torvalds usage(); 2431da177e4SLinus Torvalds} 2441da177e4SLinus Torvalds 2458484baaaSRandy Dunlapmy $kernelversion; 2468484baaaSRandy Dunlapmy $dohighlight = ""; 2478484baaaSRandy Dunlap 2481da177e4SLinus Torvaldsmy $verbose = 0; 2491da177e4SLinus Torvaldsmy $output_mode = "man"; 250e314ba31SDaniel Santosmy $output_preformatted = 0; 2514b44595aSJohannes Bergmy $no_doc_sections = 0; 2521da177e4SLinus Torvaldsmy %highlights = %highlights_man; 2531da177e4SLinus Torvaldsmy $blankline = $blankline_man; 2541da177e4SLinus Torvaldsmy $modulename = "Kernel API"; 2551da177e4SLinus Torvaldsmy $function_only = 0; 256*b2c4105bSBen Hutchingsmy $show_not_found = 0; 257*b2c4105bSBen Hutchings 258*b2c4105bSBen Hutchingsmy @build_time; 259*b2c4105bSBen Hutchingsif (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) && 260*b2c4105bSBen Hutchings (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') { 261*b2c4105bSBen Hutchings @build_time = gmtime($seconds); 262*b2c4105bSBen Hutchings} else { 263*b2c4105bSBen Hutchings @build_time = localtime; 264*b2c4105bSBen Hutchings} 265*b2c4105bSBen Hutchings 2661da177e4SLinus Torvaldsmy $man_date = ('January', 'February', 'March', 'April', 'May', 'June', 2671da177e4SLinus Torvalds 'July', 'August', 'September', 'October', 268*b2c4105bSBen Hutchings 'November', 'December')[$build_time[4]] . 269*b2c4105bSBen Hutchings " " . ($build_time[5]+1900); 2701da177e4SLinus Torvalds 2718484baaaSRandy Dunlap# Essentially these are globals. 272b9d97328SRandy Dunlap# They probably want to be tidied up, made more localised or something. 273b9d97328SRandy Dunlap# CAVEAT EMPTOR! Some of the others I localised may not want to be, which 2741da177e4SLinus Torvalds# could cause "use of undefined value" or other bugs. 2751da177e4SLinus Torvaldsmy ($function, %function_table, %parametertypes, $declaration_purpose); 2761da177e4SLinus Torvaldsmy ($type, $declaration_name, $return_type); 2771c32fd0cSIlya Dryomovmy ($newsection, $newcontents, $prototype, $brcount, %source_map); 2781da177e4SLinus Torvalds 279bd0e88e5SRandy Dunlapif (defined($ENV{'KBUILD_VERBOSE'})) { 280bd0e88e5SRandy Dunlap $verbose = "$ENV{'KBUILD_VERBOSE'}"; 281bd0e88e5SRandy Dunlap} 282bd0e88e5SRandy Dunlap 2831da177e4SLinus Torvalds# Generated docbook code is inserted in a template at a point where 2841da177e4SLinus Torvalds# docbook v3.1 requires a non-zero sequence of RefEntry's; see: 2851da177e4SLinus Torvalds# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html 2861da177e4SLinus Torvalds# We keep track of number of generated entries and generate a dummy 2871da177e4SLinus Torvalds# if needs be to ensure the expanded template can be postprocessed 2881da177e4SLinus Torvalds# into html. 2891da177e4SLinus Torvaldsmy $section_counter = 0; 2901da177e4SLinus Torvalds 2911da177e4SLinus Torvaldsmy $lineprefix=""; 2921da177e4SLinus Torvalds 2931da177e4SLinus Torvalds# states 2941da177e4SLinus Torvalds# 0 - normal code 2951da177e4SLinus Torvalds# 1 - looking for function name 2961da177e4SLinus Torvalds# 2 - scanning field start. 2971da177e4SLinus Torvalds# 3 - scanning prototype. 2981da177e4SLinus Torvalds# 4 - documentation block 2991da177e4SLinus Torvaldsmy $state; 300850622dfSRandy Dunlapmy $in_doc_sect; 3011da177e4SLinus Torvalds 3021da177e4SLinus Torvalds#declaration types: can be 3031da177e4SLinus Torvalds# 'function', 'struct', 'union', 'enum', 'typedef' 3041da177e4SLinus Torvaldsmy $decl_type; 3051da177e4SLinus Torvalds 3061da177e4SLinus Torvaldsmy $doc_special = "\@\%\$\&"; 3071da177e4SLinus Torvalds 3081da177e4SLinus Torvaldsmy $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start. 3091da177e4SLinus Torvaldsmy $doc_end = '\*/'; 3101da177e4SLinus Torvaldsmy $doc_com = '\s*\*\s*'; 31112ae6779SDaniel Santosmy $doc_com_body = '\s*\* ?'; 3121da177e4SLinus Torvaldsmy $doc_decl = $doc_com . '(\w+)'; 313891dcd2fSRandy Dunlapmy $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)'; 31412ae6779SDaniel Santosmy $doc_content = $doc_com_body . '(.*)'; 3151da177e4SLinus Torvaldsmy $doc_block = $doc_com . 'DOC:\s*(.*)?'; 3161da177e4SLinus Torvalds 3171da177e4SLinus Torvaldsmy %constants; 3181da177e4SLinus Torvaldsmy %parameterdescs; 3191da177e4SLinus Torvaldsmy @parameterlist; 3201da177e4SLinus Torvaldsmy %sections; 3211da177e4SLinus Torvaldsmy @sectionlist; 322a1d94aa5SRandy Dunlapmy $sectcheck; 323a1d94aa5SRandy Dunlapmy $struct_actual; 3241da177e4SLinus Torvalds 3251da177e4SLinus Torvaldsmy $contents = ""; 3261da177e4SLinus Torvaldsmy $section_default = "Description"; # default section 3271da177e4SLinus Torvaldsmy $section_intro = "Introduction"; 3281da177e4SLinus Torvaldsmy $section = $section_default; 3291da177e4SLinus Torvaldsmy $section_context = "Context"; 3304092bac7SYacine Belkadimy $section_return = "Return"; 3311da177e4SLinus Torvalds 3321da177e4SLinus Torvaldsmy $undescribed = "-- undescribed --"; 3331da177e4SLinus Torvalds 3341da177e4SLinus Torvaldsreset_state(); 3351da177e4SLinus Torvalds 3361da177e4SLinus Torvaldswhile ($ARGV[0] =~ m/^-(.*)/) { 3371da177e4SLinus Torvalds my $cmd = shift @ARGV; 3381da177e4SLinus Torvalds if ($cmd eq "-html") { 3391da177e4SLinus Torvalds $output_mode = "html"; 3401da177e4SLinus Torvalds %highlights = %highlights_html; 3411da177e4SLinus Torvalds $blankline = $blankline_html; 3421b40c194SDan Luedtke } elsif ($cmd eq "-html5") { 3431b40c194SDan Luedtke $output_mode = "html5"; 3441b40c194SDan Luedtke %highlights = %highlights_html5; 3451b40c194SDan Luedtke $blankline = $blankline_html5; 3461da177e4SLinus Torvalds } elsif ($cmd eq "-man") { 3471da177e4SLinus Torvalds $output_mode = "man"; 3481da177e4SLinus Torvalds %highlights = %highlights_man; 3491da177e4SLinus Torvalds $blankline = $blankline_man; 3501da177e4SLinus Torvalds } elsif ($cmd eq "-text") { 3511da177e4SLinus Torvalds $output_mode = "text"; 3521da177e4SLinus Torvalds %highlights = %highlights_text; 3531da177e4SLinus Torvalds $blankline = $blankline_text; 3541da177e4SLinus Torvalds } elsif ($cmd eq "-docbook") { 3551da177e4SLinus Torvalds $output_mode = "xml"; 3561da177e4SLinus Torvalds %highlights = %highlights_xml; 3571da177e4SLinus Torvalds $blankline = $blankline_xml; 358eda603f6SJohannes Berg } elsif ($cmd eq "-list") { 359eda603f6SJohannes Berg $output_mode = "list"; 360eda603f6SJohannes Berg %highlights = %highlights_list; 361eda603f6SJohannes Berg $blankline = $blankline_list; 3621da177e4SLinus Torvalds } elsif ($cmd eq "-gnome") { 3631da177e4SLinus Torvalds $output_mode = "gnome"; 3641da177e4SLinus Torvalds %highlights = %highlights_gnome; 3651da177e4SLinus Torvalds $blankline = $blankline_gnome; 3661da177e4SLinus Torvalds } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document 3671da177e4SLinus Torvalds $modulename = shift @ARGV; 3681da177e4SLinus Torvalds } elsif ($cmd eq "-function") { # to only output specific functions 3691da177e4SLinus Torvalds $function_only = 1; 3701da177e4SLinus Torvalds $function = shift @ARGV; 3711da177e4SLinus Torvalds $function_table{$function} = 1; 3721da177e4SLinus Torvalds } elsif ($cmd eq "-nofunction") { # to only output specific functions 3731da177e4SLinus Torvalds $function_only = 2; 3741da177e4SLinus Torvalds $function = shift @ARGV; 3751da177e4SLinus Torvalds $function_table{$function} = 1; 3761da177e4SLinus Torvalds } elsif ($cmd eq "-v") { 3771da177e4SLinus Torvalds $verbose = 1; 3781da177e4SLinus Torvalds } elsif (($cmd eq "-h") || ($cmd eq "--help")) { 3791da177e4SLinus Torvalds usage(); 3804b44595aSJohannes Berg } elsif ($cmd eq '-no-doc-sections') { 3814b44595aSJohannes Berg $no_doc_sections = 1; 382e946c43aSJohannes Berg } elsif ($cmd eq '-show-not-found') { 383e946c43aSJohannes Berg $show_not_found = 1; 3841da177e4SLinus Torvalds } 3851da177e4SLinus Torvalds} 3861da177e4SLinus Torvalds 3878484baaaSRandy Dunlap# continue execution near EOF; 3888484baaaSRandy Dunlap 3898484baaaSRandy Dunlapsub usage { 3901b40c194SDan Luedtke print "Usage: $0 [ -docbook | -html | -html5 | -text | -man | -list ]\n"; 3918484baaaSRandy Dunlap print " [ -no-doc-sections ]\n"; 3928484baaaSRandy Dunlap print " [ -function funcname [ -function funcname ...] ]\n"; 3938484baaaSRandy Dunlap print " [ -nofunction funcname [ -nofunction funcname ...] ]\n"; 3941b40c194SDan Luedtke print " [ -v ]\n"; 3958484baaaSRandy Dunlap print " c source file(s) > outputfile\n"; 3968484baaaSRandy Dunlap print " -v : verbose output, more warnings & other info listed\n"; 3978484baaaSRandy Dunlap exit 1; 3988484baaaSRandy Dunlap} 3998484baaaSRandy Dunlap 40053f049faSBorislav Petkov# get kernel version from env 40153f049faSBorislav Petkovsub get_kernel_version() { 4021b9bc22dSJohannes Berg my $version = 'unknown kernel version'; 40353f049faSBorislav Petkov 40453f049faSBorislav Petkov if (defined($ENV{'KERNELVERSION'})) { 40553f049faSBorislav Petkov $version = $ENV{'KERNELVERSION'}; 40653f049faSBorislav Petkov } 40753f049faSBorislav Petkov return $version; 40853f049faSBorislav Petkov} 4091da177e4SLinus Torvalds 4101da177e4SLinus Torvalds## 4111da177e4SLinus Torvalds# dumps section contents to arrays/hashes intended for that purpose. 4121da177e4SLinus Torvalds# 4131da177e4SLinus Torvaldssub dump_section { 41494dc7ad5SRandy Dunlap my $file = shift; 4151da177e4SLinus Torvalds my $name = shift; 4161da177e4SLinus Torvalds my $contents = join "\n", @_; 4171da177e4SLinus Torvalds 4181da177e4SLinus Torvalds if ($name =~ m/$type_constant/) { 4191da177e4SLinus Torvalds $name = $1; 4201da177e4SLinus Torvalds# print STDERR "constant section '$1' = '$contents'\n"; 4211da177e4SLinus Torvalds $constants{$name} = $contents; 4221da177e4SLinus Torvalds } elsif ($name =~ m/$type_param/) { 4231da177e4SLinus Torvalds# print STDERR "parameter def '$1' = '$contents'\n"; 4241da177e4SLinus Torvalds $name = $1; 4251da177e4SLinus Torvalds $parameterdescs{$name} = $contents; 426a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 427ced69090SRandy Dunlap } elsif ($name eq "@\.\.\.") { 428ced69090SRandy Dunlap# print STDERR "parameter def '...' = '$contents'\n"; 429ced69090SRandy Dunlap $name = "..."; 430ced69090SRandy Dunlap $parameterdescs{$name} = $contents; 431a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 4321da177e4SLinus Torvalds } else { 4331da177e4SLinus Torvalds# print STDERR "other section '$name' = '$contents'\n"; 43494dc7ad5SRandy Dunlap if (defined($sections{$name}) && ($sections{$name} ne "")) { 43594dc7ad5SRandy Dunlap print STDERR "Error(${file}:$.): duplicate section name '$name'\n"; 43694dc7ad5SRandy Dunlap ++$errors; 43794dc7ad5SRandy Dunlap } 4381da177e4SLinus Torvalds $sections{$name} = $contents; 4391da177e4SLinus Torvalds push @sectionlist, $name; 4401da177e4SLinus Torvalds } 4411da177e4SLinus Torvalds} 4421da177e4SLinus Torvalds 4431da177e4SLinus Torvalds## 444b112e0f7SJohannes Berg# dump DOC: section after checking that it should go out 445b112e0f7SJohannes Berg# 446b112e0f7SJohannes Bergsub dump_doc_section { 44794dc7ad5SRandy Dunlap my $file = shift; 448b112e0f7SJohannes Berg my $name = shift; 449b112e0f7SJohannes Berg my $contents = join "\n", @_; 450b112e0f7SJohannes Berg 4514b44595aSJohannes Berg if ($no_doc_sections) { 4524b44595aSJohannes Berg return; 4534b44595aSJohannes Berg } 4544b44595aSJohannes Berg 455b112e0f7SJohannes Berg if (($function_only == 0) || 456b112e0f7SJohannes Berg ( $function_only == 1 && defined($function_table{$name})) || 457b112e0f7SJohannes Berg ( $function_only == 2 && !defined($function_table{$name}))) 458b112e0f7SJohannes Berg { 45994dc7ad5SRandy Dunlap dump_section($file, $name, $contents); 460b112e0f7SJohannes Berg output_blockhead({'sectionlist' => \@sectionlist, 461b112e0f7SJohannes Berg 'sections' => \%sections, 462b112e0f7SJohannes Berg 'module' => $modulename, 463b112e0f7SJohannes Berg 'content-only' => ($function_only != 0), }); 464b112e0f7SJohannes Berg } 465b112e0f7SJohannes Berg} 466b112e0f7SJohannes Berg 467b112e0f7SJohannes Berg## 4681da177e4SLinus Torvalds# output function 4691da177e4SLinus Torvalds# 4701da177e4SLinus Torvalds# parameterdescs, a hash. 4711da177e4SLinus Torvalds# function => "function name" 4721da177e4SLinus Torvalds# parameterlist => @list of parameters 4731da177e4SLinus Torvalds# parameterdescs => %parameter descriptions 4741da177e4SLinus Torvalds# sectionlist => @list of sections 475a21217daSRandy Dunlap# sections => %section descriptions 4761da177e4SLinus Torvalds# 4771da177e4SLinus Torvalds 4781da177e4SLinus Torvaldssub output_highlight { 4791da177e4SLinus Torvalds my $contents = join "\n",@_; 4801da177e4SLinus Torvalds my $line; 4811da177e4SLinus Torvalds 4821da177e4SLinus Torvalds# DEBUG 4831da177e4SLinus Torvalds# if (!defined $contents) { 4841da177e4SLinus Torvalds# use Carp; 4851da177e4SLinus Torvalds# confess "output_highlight got called with no args?\n"; 4861da177e4SLinus Torvalds# } 4871da177e4SLinus Torvalds 4881b40c194SDan Luedtke if ($output_mode eq "html" || $output_mode eq "html5" || 4891b40c194SDan Luedtke $output_mode eq "xml") { 4906b5b55f6SRandy Dunlap $contents = local_unescape($contents); 4916b5b55f6SRandy Dunlap # convert data read & converted thru xml_escape() into &xyz; format: 4922b35f4d9SRandy Dunlap $contents =~ s/\\\\\\/\&/g; 4936b5b55f6SRandy Dunlap } 4943eb014a1SRandy Dunlap# print STDERR "contents b4:$contents\n"; 4951da177e4SLinus Torvalds eval $dohighlight; 4961da177e4SLinus Torvalds die $@ if $@; 4973eb014a1SRandy Dunlap# print STDERR "contents af:$contents\n"; 4983eb014a1SRandy Dunlap 4991b40c194SDan Luedtke# strip whitespaces when generating html5 5001b40c194SDan Luedtke if ($output_mode eq "html5") { 5011b40c194SDan Luedtke $contents =~ s/^\s+//; 5021b40c194SDan Luedtke $contents =~ s/\s+$//; 5031b40c194SDan Luedtke } 5041da177e4SLinus Torvalds foreach $line (split "\n", $contents) { 50512ae6779SDaniel Santos if (! $output_preformatted) { 50612ae6779SDaniel Santos $line =~ s/^\s*//; 50712ae6779SDaniel Santos } 5081da177e4SLinus Torvalds if ($line eq ""){ 509e314ba31SDaniel Santos if (! $output_preformatted) { 5106b5b55f6SRandy Dunlap print $lineprefix, local_unescape($blankline); 511e314ba31SDaniel Santos } 5121da177e4SLinus Torvalds } else { 5131da177e4SLinus Torvalds $line =~ s/\\\\\\/\&/g; 514cdccb316SRandy Dunlap if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { 515cdccb316SRandy Dunlap print "\\&$line"; 516cdccb316SRandy Dunlap } else { 5171da177e4SLinus Torvalds print $lineprefix, $line; 5181da177e4SLinus Torvalds } 519cdccb316SRandy Dunlap } 5201da177e4SLinus Torvalds print "\n"; 5211da177e4SLinus Torvalds } 5221da177e4SLinus Torvalds} 5231da177e4SLinus Torvalds 5241da177e4SLinus Torvalds# output sections in html 5251da177e4SLinus Torvaldssub output_section_html(%) { 5261da177e4SLinus Torvalds my %args = %{$_[0]}; 5271da177e4SLinus Torvalds my $section; 5281da177e4SLinus Torvalds 5291da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 5301da177e4SLinus Torvalds print "<h3>$section</h3>\n"; 5311da177e4SLinus Torvalds print "<blockquote>\n"; 5321da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 5331da177e4SLinus Torvalds print "</blockquote>\n"; 5341da177e4SLinus Torvalds } 5351da177e4SLinus Torvalds} 5361da177e4SLinus Torvalds 5371da177e4SLinus Torvalds# output enum in html 5381da177e4SLinus Torvaldssub output_enum_html(%) { 5391da177e4SLinus Torvalds my %args = %{$_[0]}; 5401da177e4SLinus Torvalds my ($parameter); 5411da177e4SLinus Torvalds my $count; 5421da177e4SLinus Torvalds print "<h2>enum " . $args{'enum'} . "</h2>\n"; 5431da177e4SLinus Torvalds 5441da177e4SLinus Torvalds print "<b>enum " . $args{'enum'} . "</b> {<br>\n"; 5451da177e4SLinus Torvalds $count = 0; 5461da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 5471da177e4SLinus Torvalds print " <b>" . $parameter . "</b>"; 5481da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 5491da177e4SLinus Torvalds $count++; 5501da177e4SLinus Torvalds print ",\n"; 5511da177e4SLinus Torvalds } 5521da177e4SLinus Torvalds print "<br>"; 5531da177e4SLinus Torvalds } 5541da177e4SLinus Torvalds print "};<br>\n"; 5551da177e4SLinus Torvalds 5561da177e4SLinus Torvalds print "<h3>Constants</h3>\n"; 5571da177e4SLinus Torvalds print "<dl>\n"; 5581da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 5591da177e4SLinus Torvalds print "<dt><b>" . $parameter . "</b>\n"; 5601da177e4SLinus Torvalds print "<dd>"; 5611da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter}); 5621da177e4SLinus Torvalds } 5631da177e4SLinus Torvalds print "</dl>\n"; 5641da177e4SLinus Torvalds output_section_html(@_); 5651da177e4SLinus Torvalds print "<hr>\n"; 5661da177e4SLinus Torvalds} 5671da177e4SLinus Torvalds 568d28bee0cSRandy Dunlap# output typedef in html 5691da177e4SLinus Torvaldssub output_typedef_html(%) { 5701da177e4SLinus Torvalds my %args = %{$_[0]}; 5711da177e4SLinus Torvalds my ($parameter); 5721da177e4SLinus Torvalds my $count; 5731da177e4SLinus Torvalds print "<h2>typedef " . $args{'typedef'} . "</h2>\n"; 5741da177e4SLinus Torvalds 5751da177e4SLinus Torvalds print "<b>typedef " . $args{'typedef'} . "</b>\n"; 5761da177e4SLinus Torvalds output_section_html(@_); 5771da177e4SLinus Torvalds print "<hr>\n"; 5781da177e4SLinus Torvalds} 5791da177e4SLinus Torvalds 5801da177e4SLinus Torvalds# output struct in html 5811da177e4SLinus Torvaldssub output_struct_html(%) { 5821da177e4SLinus Torvalds my %args = %{$_[0]}; 5831da177e4SLinus Torvalds my ($parameter); 5841da177e4SLinus Torvalds 585262d9b01SRandy Dunlap print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n"; 5861da177e4SLinus Torvalds print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n"; 5871da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 5881da177e4SLinus Torvalds if ($parameter =~ /^#/) { 5891da177e4SLinus Torvalds print "$parameter<br>\n"; 5901da177e4SLinus Torvalds next; 5911da177e4SLinus Torvalds } 5921da177e4SLinus Torvalds my $parameter_name = $parameter; 5931da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 5941da177e4SLinus Torvalds 5951da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 5961da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 5971da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 5981da177e4SLinus Torvalds # pointer-to-function 5993eb014a1SRandy Dunlap print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n"; 6001da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 6013eb014a1SRandy Dunlap # bitfield 6023eb014a1SRandy Dunlap print " <i>$1</i> <b>$parameter</b>$2;<br>\n"; 6031da177e4SLinus Torvalds } else { 6043eb014a1SRandy Dunlap print " <i>$type</i> <b>$parameter</b>;<br>\n"; 6051da177e4SLinus Torvalds } 6061da177e4SLinus Torvalds } 6071da177e4SLinus Torvalds print "};<br>\n"; 6081da177e4SLinus Torvalds 6091da177e4SLinus Torvalds print "<h3>Members</h3>\n"; 6101da177e4SLinus Torvalds print "<dl>\n"; 6111da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6121da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 6131da177e4SLinus Torvalds 6141da177e4SLinus Torvalds my $parameter_name = $parameter; 6151da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 6161da177e4SLinus Torvalds 6171da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 6181da177e4SLinus Torvalds print "<dt><b>" . $parameter . "</b>\n"; 6191da177e4SLinus Torvalds print "<dd>"; 6201da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 6211da177e4SLinus Torvalds } 6221da177e4SLinus Torvalds print "</dl>\n"; 6231da177e4SLinus Torvalds output_section_html(@_); 6241da177e4SLinus Torvalds print "<hr>\n"; 6251da177e4SLinus Torvalds} 6261da177e4SLinus Torvalds 6271da177e4SLinus Torvalds# output function in html 6281da177e4SLinus Torvaldssub output_function_html(%) { 6291da177e4SLinus Torvalds my %args = %{$_[0]}; 6301da177e4SLinus Torvalds my ($parameter, $section); 6311da177e4SLinus Torvalds my $count; 6321da177e4SLinus Torvalds 633262d9b01SRandy Dunlap print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n"; 6341da177e4SLinus Torvalds print "<i>" . $args{'functiontype'} . "</i>\n"; 6351da177e4SLinus Torvalds print "<b>" . $args{'function'} . "</b>\n"; 6361da177e4SLinus Torvalds print "("; 6371da177e4SLinus Torvalds $count = 0; 6381da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6391da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 6401da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 6411da177e4SLinus Torvalds # pointer-to-function 6421da177e4SLinus Torvalds print "<i>$1</i><b>$parameter</b>) <i>($2)</i>"; 6431da177e4SLinus Torvalds } else { 6441da177e4SLinus Torvalds print "<i>" . $type . "</i> <b>" . $parameter . "</b>"; 6451da177e4SLinus Torvalds } 6461da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 6471da177e4SLinus Torvalds $count++; 6481da177e4SLinus Torvalds print ",\n"; 6491da177e4SLinus Torvalds } 6501da177e4SLinus Torvalds } 6511da177e4SLinus Torvalds print ")\n"; 6521da177e4SLinus Torvalds 6531da177e4SLinus Torvalds print "<h3>Arguments</h3>\n"; 6541da177e4SLinus Torvalds print "<dl>\n"; 6551da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6561da177e4SLinus Torvalds my $parameter_name = $parameter; 6571da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 6581da177e4SLinus Torvalds 6591da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 6601da177e4SLinus Torvalds print "<dt><b>" . $parameter . "</b>\n"; 6611da177e4SLinus Torvalds print "<dd>"; 6621da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 6631da177e4SLinus Torvalds } 6641da177e4SLinus Torvalds print "</dl>\n"; 6651da177e4SLinus Torvalds output_section_html(@_); 6661da177e4SLinus Torvalds print "<hr>\n"; 6671da177e4SLinus Torvalds} 6681da177e4SLinus Torvalds 669b112e0f7SJohannes Berg# output DOC: block header in html 670b112e0f7SJohannes Bergsub output_blockhead_html(%) { 6711da177e4SLinus Torvalds my %args = %{$_[0]}; 6721da177e4SLinus Torvalds my ($parameter, $section); 6731da177e4SLinus Torvalds my $count; 6741da177e4SLinus Torvalds 6751da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 6761da177e4SLinus Torvalds print "<h3>$section</h3>\n"; 6771da177e4SLinus Torvalds print "<ul>\n"; 6781da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 6791da177e4SLinus Torvalds print "</ul>\n"; 6801da177e4SLinus Torvalds } 6811da177e4SLinus Torvalds print "<hr>\n"; 6821da177e4SLinus Torvalds} 6831da177e4SLinus Torvalds 6841b40c194SDan Luedtke# output sections in html5 6851b40c194SDan Luedtkesub output_section_html5(%) { 6861b40c194SDan Luedtke my %args = %{$_[0]}; 6871b40c194SDan Luedtke my $section; 6881b40c194SDan Luedtke 6891b40c194SDan Luedtke foreach $section (@{$args{'sectionlist'}}) { 6901b40c194SDan Luedtke print "<section>\n"; 6911b40c194SDan Luedtke print "<h1>$section</h1>\n"; 6921b40c194SDan Luedtke print "<p>\n"; 6931b40c194SDan Luedtke output_highlight($args{'sections'}{$section}); 6941b40c194SDan Luedtke print "</p>\n"; 6951b40c194SDan Luedtke print "</section>\n"; 6961b40c194SDan Luedtke } 6971b40c194SDan Luedtke} 6981b40c194SDan Luedtke 6991b40c194SDan Luedtke# output enum in html5 7001b40c194SDan Luedtkesub output_enum_html5(%) { 7011b40c194SDan Luedtke my %args = %{$_[0]}; 7021b40c194SDan Luedtke my ($parameter); 7031b40c194SDan Luedtke my $count; 7041b40c194SDan Luedtke my $html5id; 7051b40c194SDan Luedtke 7061b40c194SDan Luedtke $html5id = $args{'enum'}; 7071b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 7081b40c194SDan Luedtke print "<article class=\"enum\" id=\"enum:". $html5id . "\">"; 7091b40c194SDan Luedtke print "<h1>enum " . $args{'enum'} . "</h1>\n"; 7101b40c194SDan Luedtke print "<ol class=\"code\">\n"; 7111b40c194SDan Luedtke print "<li>"; 7121b40c194SDan Luedtke print "<span class=\"keyword\">enum</span> "; 7131b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'enum'} . "</span> {"; 7141b40c194SDan Luedtke print "</li>\n"; 7151b40c194SDan Luedtke $count = 0; 7161b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 7171b40c194SDan Luedtke print "<li class=\"indent\">"; 7181b40c194SDan Luedtke print "<span class=\"param\">" . $parameter . "</span>"; 7191b40c194SDan Luedtke if ($count != $#{$args{'parameterlist'}}) { 7201b40c194SDan Luedtke $count++; 7211b40c194SDan Luedtke print ","; 7221b40c194SDan Luedtke } 7231b40c194SDan Luedtke print "</li>\n"; 7241b40c194SDan Luedtke } 7251b40c194SDan Luedtke print "<li>};</li>\n"; 7261b40c194SDan Luedtke print "</ol>\n"; 7271b40c194SDan Luedtke 7281b40c194SDan Luedtke print "<section>\n"; 7291b40c194SDan Luedtke print "<h1>Constants</h1>\n"; 7301b40c194SDan Luedtke print "<dl>\n"; 7311b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 7321b40c194SDan Luedtke print "<dt>" . $parameter . "</dt>\n"; 7331b40c194SDan Luedtke print "<dd>"; 7341b40c194SDan Luedtke output_highlight($args{'parameterdescs'}{$parameter}); 7351b40c194SDan Luedtke print "</dd>\n"; 7361b40c194SDan Luedtke } 7371b40c194SDan Luedtke print "</dl>\n"; 7381b40c194SDan Luedtke print "</section>\n"; 7391b40c194SDan Luedtke output_section_html5(@_); 7401b40c194SDan Luedtke print "</article>\n"; 7411b40c194SDan Luedtke} 7421b40c194SDan Luedtke 7431b40c194SDan Luedtke# output typedef in html5 7441b40c194SDan Luedtkesub output_typedef_html5(%) { 7451b40c194SDan Luedtke my %args = %{$_[0]}; 7461b40c194SDan Luedtke my ($parameter); 7471b40c194SDan Luedtke my $count; 7481b40c194SDan Luedtke my $html5id; 7491b40c194SDan Luedtke 7501b40c194SDan Luedtke $html5id = $args{'typedef'}; 7511b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 7521b40c194SDan Luedtke print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n"; 7531b40c194SDan Luedtke print "<h1>typedef " . $args{'typedef'} . "</h1>\n"; 7541b40c194SDan Luedtke 7551b40c194SDan Luedtke print "<ol class=\"code\">\n"; 7561b40c194SDan Luedtke print "<li>"; 7571b40c194SDan Luedtke print "<span class=\"keyword\">typedef</span> "; 7581b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'typedef'} . "</span>"; 7591b40c194SDan Luedtke print "</li>\n"; 7601b40c194SDan Luedtke print "</ol>\n"; 7611b40c194SDan Luedtke output_section_html5(@_); 7621b40c194SDan Luedtke print "</article>\n"; 7631b40c194SDan Luedtke} 7641b40c194SDan Luedtke 7651b40c194SDan Luedtke# output struct in html5 7661b40c194SDan Luedtkesub output_struct_html5(%) { 7671b40c194SDan Luedtke my %args = %{$_[0]}; 7681b40c194SDan Luedtke my ($parameter); 7691b40c194SDan Luedtke my $html5id; 7701b40c194SDan Luedtke 7711b40c194SDan Luedtke $html5id = $args{'struct'}; 7721b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 7731b40c194SDan Luedtke print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n"; 7741b40c194SDan Luedtke print "<hgroup>\n"; 7751b40c194SDan Luedtke print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>"; 7761b40c194SDan Luedtke print "<h2>". $args{'purpose'} . "</h2>\n"; 7771b40c194SDan Luedtke print "</hgroup>\n"; 7781b40c194SDan Luedtke print "<ol class=\"code\">\n"; 7791b40c194SDan Luedtke print "<li>"; 7801b40c194SDan Luedtke print "<span class=\"type\">" . $args{'type'} . "</span> "; 7811b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'struct'} . "</span> {"; 7821b40c194SDan Luedtke print "</li>\n"; 7831b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 7841b40c194SDan Luedtke print "<li class=\"indent\">"; 7851b40c194SDan Luedtke if ($parameter =~ /^#/) { 7861b40c194SDan Luedtke print "<span class=\"param\">" . $parameter ."</span>\n"; 7871b40c194SDan Luedtke print "</li>\n"; 7881b40c194SDan Luedtke next; 7891b40c194SDan Luedtke } 7901b40c194SDan Luedtke my $parameter_name = $parameter; 7911b40c194SDan Luedtke $parameter_name =~ s/\[.*//; 7921b40c194SDan Luedtke 7931b40c194SDan Luedtke ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 7941b40c194SDan Luedtke $type = $args{'parametertypes'}{$parameter}; 7951b40c194SDan Luedtke if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 7961b40c194SDan Luedtke # pointer-to-function 7971b40c194SDan Luedtke print "<span class=\"type\">$1</span> "; 7981b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 7991b40c194SDan Luedtke print "<span class=\"type\">)</span> "; 8001b40c194SDan Luedtke print "(<span class=\"args\">$2</span>);"; 8011b40c194SDan Luedtke } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 8021b40c194SDan Luedtke # bitfield 8031b40c194SDan Luedtke print "<span class=\"type\">$1</span> "; 8041b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 8051b40c194SDan Luedtke print "<span class=\"bits\">$2</span>;"; 8061b40c194SDan Luedtke } else { 8071b40c194SDan Luedtke print "<span class=\"type\">$type</span> "; 8081b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>;"; 8091b40c194SDan Luedtke } 8101b40c194SDan Luedtke print "</li>\n"; 8111b40c194SDan Luedtke } 8121b40c194SDan Luedtke print "<li>};</li>\n"; 8131b40c194SDan Luedtke print "</ol>\n"; 8141b40c194SDan Luedtke 8151b40c194SDan Luedtke print "<section>\n"; 8161b40c194SDan Luedtke print "<h1>Members</h1>\n"; 8171b40c194SDan Luedtke print "<dl>\n"; 8181b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 8191b40c194SDan Luedtke ($parameter =~ /^#/) && next; 8201b40c194SDan Luedtke 8211b40c194SDan Luedtke my $parameter_name = $parameter; 8221b40c194SDan Luedtke $parameter_name =~ s/\[.*//; 8231b40c194SDan Luedtke 8241b40c194SDan Luedtke ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 8251b40c194SDan Luedtke print "<dt>" . $parameter . "</dt>\n"; 8261b40c194SDan Luedtke print "<dd>"; 8271b40c194SDan Luedtke output_highlight($args{'parameterdescs'}{$parameter_name}); 8281b40c194SDan Luedtke print "</dd>\n"; 8291b40c194SDan Luedtke } 8301b40c194SDan Luedtke print "</dl>\n"; 8311b40c194SDan Luedtke print "</section>\n"; 8321b40c194SDan Luedtke output_section_html5(@_); 8331b40c194SDan Luedtke print "</article>\n"; 8341b40c194SDan Luedtke} 8351b40c194SDan Luedtke 8361b40c194SDan Luedtke# output function in html5 8371b40c194SDan Luedtkesub output_function_html5(%) { 8381b40c194SDan Luedtke my %args = %{$_[0]}; 8391b40c194SDan Luedtke my ($parameter, $section); 8401b40c194SDan Luedtke my $count; 8411b40c194SDan Luedtke my $html5id; 8421b40c194SDan Luedtke 8431b40c194SDan Luedtke $html5id = $args{'function'}; 8441b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 8451b40c194SDan Luedtke print "<article class=\"function\" id=\"func:". $html5id . "\">\n"; 8461b40c194SDan Luedtke print "<hgroup>\n"; 8471b40c194SDan Luedtke print "<h1>" . $args{'function'} . "</h1>"; 8481b40c194SDan Luedtke print "<h2>" . $args{'purpose'} . "</h2>\n"; 8491b40c194SDan Luedtke print "</hgroup>\n"; 8501b40c194SDan Luedtke print "<ol class=\"code\">\n"; 8511b40c194SDan Luedtke print "<li>"; 8521b40c194SDan Luedtke print "<span class=\"type\">" . $args{'functiontype'} . "</span> "; 8531b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'function'} . "</span> ("; 8541b40c194SDan Luedtke print "</li>"; 8551b40c194SDan Luedtke $count = 0; 8561b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 8571b40c194SDan Luedtke print "<li class=\"indent\">"; 8581b40c194SDan Luedtke $type = $args{'parametertypes'}{$parameter}; 8591b40c194SDan Luedtke if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 8601b40c194SDan Luedtke # pointer-to-function 8611b40c194SDan Luedtke print "<span class=\"type\">$1</span> "; 8621b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 8631b40c194SDan Luedtke print "<span class=\"type\">)</span> "; 8641b40c194SDan Luedtke print "(<span class=\"args\">$2</span>)"; 8651b40c194SDan Luedtke } else { 8661b40c194SDan Luedtke print "<span class=\"type\">$type</span> "; 8671b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 8681b40c194SDan Luedtke } 8691b40c194SDan Luedtke if ($count != $#{$args{'parameterlist'}}) { 8701b40c194SDan Luedtke $count++; 8711b40c194SDan Luedtke print ","; 8721b40c194SDan Luedtke } 8731b40c194SDan Luedtke print "</li>\n"; 8741b40c194SDan Luedtke } 8751b40c194SDan Luedtke print "<li>)</li>\n"; 8761b40c194SDan Luedtke print "</ol>\n"; 8771b40c194SDan Luedtke 8781b40c194SDan Luedtke print "<section>\n"; 8791b40c194SDan Luedtke print "<h1>Arguments</h1>\n"; 8801b40c194SDan Luedtke print "<p>\n"; 8811b40c194SDan Luedtke print "<dl>\n"; 8821b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 8831b40c194SDan Luedtke my $parameter_name = $parameter; 8841b40c194SDan Luedtke $parameter_name =~ s/\[.*//; 8851b40c194SDan Luedtke 8861b40c194SDan Luedtke ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 8871b40c194SDan Luedtke print "<dt>" . $parameter . "</dt>\n"; 8881b40c194SDan Luedtke print "<dd>"; 8891b40c194SDan Luedtke output_highlight($args{'parameterdescs'}{$parameter_name}); 8901b40c194SDan Luedtke print "</dd>\n"; 8911b40c194SDan Luedtke } 8921b40c194SDan Luedtke print "</dl>\n"; 8931b40c194SDan Luedtke print "</section>\n"; 8941b40c194SDan Luedtke output_section_html5(@_); 8951b40c194SDan Luedtke print "</article>\n"; 8961b40c194SDan Luedtke} 8971b40c194SDan Luedtke 8981b40c194SDan Luedtke# output DOC: block header in html5 8991b40c194SDan Luedtkesub output_blockhead_html5(%) { 9001b40c194SDan Luedtke my %args = %{$_[0]}; 9011b40c194SDan Luedtke my ($parameter, $section); 9021b40c194SDan Luedtke my $count; 9031b40c194SDan Luedtke my $html5id; 9041b40c194SDan Luedtke 9051b40c194SDan Luedtke foreach $section (@{$args{'sectionlist'}}) { 9061b40c194SDan Luedtke $html5id = $section; 9071b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 9081b40c194SDan Luedtke print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n"; 9091b40c194SDan Luedtke print "<h1>$section</h1>\n"; 9101b40c194SDan Luedtke print "<p>\n"; 9111b40c194SDan Luedtke output_highlight($args{'sections'}{$section}); 9121b40c194SDan Luedtke print "</p>\n"; 9131b40c194SDan Luedtke } 9141b40c194SDan Luedtke print "</article>\n"; 9151b40c194SDan Luedtke} 9161b40c194SDan Luedtke 9171da177e4SLinus Torvaldssub output_section_xml(%) { 9181da177e4SLinus Torvalds my %args = %{$_[0]}; 9191da177e4SLinus Torvalds my $section; 9201da177e4SLinus Torvalds # print out each section 9211da177e4SLinus Torvalds $lineprefix=" "; 9221da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 923c73894c1SRich Walker print "<refsect1>\n"; 924c73894c1SRich Walker print "<title>$section</title>\n"; 9251da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 926c73894c1SRich Walker print "<informalexample><programlisting>\n"; 927e314ba31SDaniel Santos $output_preformatted = 1; 928c73894c1SRich Walker } else { 929c73894c1SRich Walker print "<para>\n"; 9301da177e4SLinus Torvalds } 9311da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 932e314ba31SDaniel Santos $output_preformatted = 0; 9331da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 934c73894c1SRich Walker print "</programlisting></informalexample>\n"; 935c73894c1SRich Walker } else { 936c73894c1SRich Walker print "</para>\n"; 9371da177e4SLinus Torvalds } 938c73894c1SRich Walker print "</refsect1>\n"; 9391da177e4SLinus Torvalds } 9401da177e4SLinus Torvalds} 9411da177e4SLinus Torvalds 9421da177e4SLinus Torvalds# output function in XML DocBook 9431da177e4SLinus Torvaldssub output_function_xml(%) { 9441da177e4SLinus Torvalds my %args = %{$_[0]}; 9451da177e4SLinus Torvalds my ($parameter, $section); 9461da177e4SLinus Torvalds my $count; 9471da177e4SLinus Torvalds my $id; 9481da177e4SLinus Torvalds 9491da177e4SLinus Torvalds $id = "API-" . $args{'function'}; 9501da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 9511da177e4SLinus Torvalds 9525449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 9538b0c2d98SMartin Waitz print "<refentryinfo>\n"; 9548b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 9558b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 9568b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 9578b0c2d98SMartin Waitz print "</refentryinfo>\n"; 9581da177e4SLinus Torvalds print "<refmeta>\n"; 9595449bc94SPavel Pisa print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n"; 9608b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 9610366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 9621da177e4SLinus Torvalds print "</refmeta>\n"; 9631da177e4SLinus Torvalds print "<refnamediv>\n"; 9641da177e4SLinus Torvalds print " <refname>" . $args{'function'} . "</refname>\n"; 9651da177e4SLinus Torvalds print " <refpurpose>\n"; 9661da177e4SLinus Torvalds print " "; 9671da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 9681da177e4SLinus Torvalds print " </refpurpose>\n"; 9691da177e4SLinus Torvalds print "</refnamediv>\n"; 9701da177e4SLinus Torvalds 9711da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 9721da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 9731da177e4SLinus Torvalds print " <funcsynopsis><funcprototype>\n"; 9741da177e4SLinus Torvalds print " <funcdef>" . $args{'functiontype'} . " "; 9751da177e4SLinus Torvalds print "<function>" . $args{'function'} . " </function></funcdef>\n"; 9761da177e4SLinus Torvalds 9771da177e4SLinus Torvalds $count = 0; 9781da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 9791da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 9801da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 9811da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 9821da177e4SLinus Torvalds # pointer-to-function 9831da177e4SLinus Torvalds print " <paramdef>$1<parameter>$parameter</parameter>)\n"; 9841da177e4SLinus Torvalds print " <funcparams>$2</funcparams></paramdef>\n"; 9851da177e4SLinus Torvalds } else { 9861da177e4SLinus Torvalds print " <paramdef>" . $type; 9871da177e4SLinus Torvalds print " <parameter>$parameter</parameter></paramdef>\n"; 9881da177e4SLinus Torvalds } 9891da177e4SLinus Torvalds } 9901da177e4SLinus Torvalds } else { 9916013d544SMartin Waitz print " <void/>\n"; 9921da177e4SLinus Torvalds } 9931da177e4SLinus Torvalds print " </funcprototype></funcsynopsis>\n"; 9941da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 9951da177e4SLinus Torvalds 9961da177e4SLinus Torvalds # print parameters 9971da177e4SLinus Torvalds print "<refsect1>\n <title>Arguments</title>\n"; 9981da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 9991da177e4SLinus Torvalds print " <variablelist>\n"; 10001da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 10011da177e4SLinus Torvalds my $parameter_name = $parameter; 10021da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 10031da177e4SLinus Torvalds 10041da177e4SLinus Torvalds print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n"; 10051da177e4SLinus Torvalds print " <listitem>\n <para>\n"; 10061da177e4SLinus Torvalds $lineprefix=" "; 10071da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 10081da177e4SLinus Torvalds print " </para>\n </listitem>\n </varlistentry>\n"; 10091da177e4SLinus Torvalds } 10101da177e4SLinus Torvalds print " </variablelist>\n"; 10111da177e4SLinus Torvalds } else { 10121da177e4SLinus Torvalds print " <para>\n None\n </para>\n"; 10131da177e4SLinus Torvalds } 10141da177e4SLinus Torvalds print "</refsect1>\n"; 10151da177e4SLinus Torvalds 10161da177e4SLinus Torvalds output_section_xml(@_); 10171da177e4SLinus Torvalds print "</refentry>\n\n"; 10181da177e4SLinus Torvalds} 10191da177e4SLinus Torvalds 10201da177e4SLinus Torvalds# output struct in XML DocBook 10211da177e4SLinus Torvaldssub output_struct_xml(%) { 10221da177e4SLinus Torvalds my %args = %{$_[0]}; 10231da177e4SLinus Torvalds my ($parameter, $section); 10241da177e4SLinus Torvalds my $id; 10251da177e4SLinus Torvalds 10261da177e4SLinus Torvalds $id = "API-struct-" . $args{'struct'}; 10271da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 10281da177e4SLinus Torvalds 10295449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 10308b0c2d98SMartin Waitz print "<refentryinfo>\n"; 10318b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 10328b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 10338b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 10348b0c2d98SMartin Waitz print "</refentryinfo>\n"; 10351da177e4SLinus Torvalds print "<refmeta>\n"; 10365449bc94SPavel Pisa print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n"; 10378b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 10380366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 10391da177e4SLinus Torvalds print "</refmeta>\n"; 10401da177e4SLinus Torvalds print "<refnamediv>\n"; 10411da177e4SLinus Torvalds print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n"; 10421da177e4SLinus Torvalds print " <refpurpose>\n"; 10431da177e4SLinus Torvalds print " "; 10441da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 10451da177e4SLinus Torvalds print " </refpurpose>\n"; 10461da177e4SLinus Torvalds print "</refnamediv>\n"; 10471da177e4SLinus Torvalds 10481da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 10491da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 10501da177e4SLinus Torvalds print " <programlisting>\n"; 10511da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n"; 10521da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 10531da177e4SLinus Torvalds if ($parameter =~ /^#/) { 10542b35f4d9SRandy Dunlap my $prm = $parameter; 10552b35f4d9SRandy Dunlap # convert data read & converted thru xml_escape() into &xyz; format: 10562b35f4d9SRandy Dunlap # This allows us to have #define macros interspersed in a struct. 10572b35f4d9SRandy Dunlap $prm =~ s/\\\\\\/\&/g; 10582b35f4d9SRandy Dunlap print "$prm\n"; 10591da177e4SLinus Torvalds next; 10601da177e4SLinus Torvalds } 10611da177e4SLinus Torvalds 10621da177e4SLinus Torvalds my $parameter_name = $parameter; 10631da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 10641da177e4SLinus Torvalds 10651da177e4SLinus Torvalds defined($args{'parameterdescs'}{$parameter_name}) || next; 10661da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 10671da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 10681da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 10691da177e4SLinus Torvalds # pointer-to-function 10701da177e4SLinus Torvalds print " $1 $parameter) ($2);\n"; 10711da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 107251f5a0c8SRandy Dunlap # bitfield 10731da177e4SLinus Torvalds print " $1 $parameter$2;\n"; 10741da177e4SLinus Torvalds } else { 10751da177e4SLinus Torvalds print " " . $type . " " . $parameter . ";\n"; 10761da177e4SLinus Torvalds } 10771da177e4SLinus Torvalds } 10781da177e4SLinus Torvalds print "};"; 10791da177e4SLinus Torvalds print " </programlisting>\n"; 10801da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 10811da177e4SLinus Torvalds 10821da177e4SLinus Torvalds print " <refsect1>\n"; 10831da177e4SLinus Torvalds print " <title>Members</title>\n"; 10841da177e4SLinus Torvalds 108539f00c08SRandy Dunlap if ($#{$args{'parameterlist'}} >= 0) { 10861da177e4SLinus Torvalds print " <variablelist>\n"; 10871da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 10881da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 10891da177e4SLinus Torvalds 10901da177e4SLinus Torvalds my $parameter_name = $parameter; 10911da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 10921da177e4SLinus Torvalds 10931da177e4SLinus Torvalds defined($args{'parameterdescs'}{$parameter_name}) || next; 10941da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 10951da177e4SLinus Torvalds print " <varlistentry>"; 10961da177e4SLinus Torvalds print " <term>$parameter</term>\n"; 10971da177e4SLinus Torvalds print " <listitem><para>\n"; 10981da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 10991da177e4SLinus Torvalds print " </para></listitem>\n"; 11001da177e4SLinus Torvalds print " </varlistentry>\n"; 11011da177e4SLinus Torvalds } 11021da177e4SLinus Torvalds print " </variablelist>\n"; 110339f00c08SRandy Dunlap } else { 110439f00c08SRandy Dunlap print " <para>\n None\n </para>\n"; 110539f00c08SRandy Dunlap } 11061da177e4SLinus Torvalds print " </refsect1>\n"; 11071da177e4SLinus Torvalds 11081da177e4SLinus Torvalds output_section_xml(@_); 11091da177e4SLinus Torvalds 11101da177e4SLinus Torvalds print "</refentry>\n\n"; 11111da177e4SLinus Torvalds} 11121da177e4SLinus Torvalds 11131da177e4SLinus Torvalds# output enum in XML DocBook 11141da177e4SLinus Torvaldssub output_enum_xml(%) { 11151da177e4SLinus Torvalds my %args = %{$_[0]}; 11161da177e4SLinus Torvalds my ($parameter, $section); 11171da177e4SLinus Torvalds my $count; 11181da177e4SLinus Torvalds my $id; 11191da177e4SLinus Torvalds 11201da177e4SLinus Torvalds $id = "API-enum-" . $args{'enum'}; 11211da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 11221da177e4SLinus Torvalds 11235449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 11248b0c2d98SMartin Waitz print "<refentryinfo>\n"; 11258b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 11268b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 11278b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 11288b0c2d98SMartin Waitz print "</refentryinfo>\n"; 11291da177e4SLinus Torvalds print "<refmeta>\n"; 11305449bc94SPavel Pisa print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n"; 11318b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 11320366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 11331da177e4SLinus Torvalds print "</refmeta>\n"; 11341da177e4SLinus Torvalds print "<refnamediv>\n"; 11351da177e4SLinus Torvalds print " <refname>enum " . $args{'enum'} . "</refname>\n"; 11361da177e4SLinus Torvalds print " <refpurpose>\n"; 11371da177e4SLinus Torvalds print " "; 11381da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 11391da177e4SLinus Torvalds print " </refpurpose>\n"; 11401da177e4SLinus Torvalds print "</refnamediv>\n"; 11411da177e4SLinus Torvalds 11421da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 11431da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 11441da177e4SLinus Torvalds print " <programlisting>\n"; 11451da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 11461da177e4SLinus Torvalds $count = 0; 11471da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 11481da177e4SLinus Torvalds print " $parameter"; 11491da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 11501da177e4SLinus Torvalds $count++; 11511da177e4SLinus Torvalds print ","; 11521da177e4SLinus Torvalds } 11531da177e4SLinus Torvalds print "\n"; 11541da177e4SLinus Torvalds } 11551da177e4SLinus Torvalds print "};"; 11561da177e4SLinus Torvalds print " </programlisting>\n"; 11571da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 11581da177e4SLinus Torvalds 11591da177e4SLinus Torvalds print "<refsect1>\n"; 11601da177e4SLinus Torvalds print " <title>Constants</title>\n"; 11611da177e4SLinus Torvalds print " <variablelist>\n"; 11621da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 11631da177e4SLinus Torvalds my $parameter_name = $parameter; 11641da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 11651da177e4SLinus Torvalds 11661da177e4SLinus Torvalds print " <varlistentry>"; 11671da177e4SLinus Torvalds print " <term>$parameter</term>\n"; 11681da177e4SLinus Torvalds print " <listitem><para>\n"; 11691da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 11701da177e4SLinus Torvalds print " </para></listitem>\n"; 11711da177e4SLinus Torvalds print " </varlistentry>\n"; 11721da177e4SLinus Torvalds } 11731da177e4SLinus Torvalds print " </variablelist>\n"; 11741da177e4SLinus Torvalds print "</refsect1>\n"; 11751da177e4SLinus Torvalds 11761da177e4SLinus Torvalds output_section_xml(@_); 11771da177e4SLinus Torvalds 11781da177e4SLinus Torvalds print "</refentry>\n\n"; 11791da177e4SLinus Torvalds} 11801da177e4SLinus Torvalds 11811da177e4SLinus Torvalds# output typedef in XML DocBook 11821da177e4SLinus Torvaldssub output_typedef_xml(%) { 11831da177e4SLinus Torvalds my %args = %{$_[0]}; 11841da177e4SLinus Torvalds my ($parameter, $section); 11851da177e4SLinus Torvalds my $id; 11861da177e4SLinus Torvalds 11871da177e4SLinus Torvalds $id = "API-typedef-" . $args{'typedef'}; 11881da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 11891da177e4SLinus Torvalds 11905449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 11918b0c2d98SMartin Waitz print "<refentryinfo>\n"; 11928b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 11938b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 11948b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 11958b0c2d98SMartin Waitz print "</refentryinfo>\n"; 11961da177e4SLinus Torvalds print "<refmeta>\n"; 11975449bc94SPavel Pisa print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n"; 11988b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 11991da177e4SLinus Torvalds print "</refmeta>\n"; 12001da177e4SLinus Torvalds print "<refnamediv>\n"; 12011da177e4SLinus Torvalds print " <refname>typedef " . $args{'typedef'} . "</refname>\n"; 12021da177e4SLinus Torvalds print " <refpurpose>\n"; 12031da177e4SLinus Torvalds print " "; 12041da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 12051da177e4SLinus Torvalds print " </refpurpose>\n"; 12061da177e4SLinus Torvalds print "</refnamediv>\n"; 12071da177e4SLinus Torvalds 12081da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 12091da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 12101da177e4SLinus Torvalds print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n"; 12111da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 12121da177e4SLinus Torvalds 12131da177e4SLinus Torvalds output_section_xml(@_); 12141da177e4SLinus Torvalds 12151da177e4SLinus Torvalds print "</refentry>\n\n"; 12161da177e4SLinus Torvalds} 12171da177e4SLinus Torvalds 12181da177e4SLinus Torvalds# output in XML DocBook 1219b112e0f7SJohannes Bergsub output_blockhead_xml(%) { 12201da177e4SLinus Torvalds my %args = %{$_[0]}; 12211da177e4SLinus Torvalds my ($parameter, $section); 12221da177e4SLinus Torvalds my $count; 12231da177e4SLinus Torvalds 12241da177e4SLinus Torvalds my $id = $args{'module'}; 12251da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 12261da177e4SLinus Torvalds 12271da177e4SLinus Torvalds # print out each section 12281da177e4SLinus Torvalds $lineprefix=" "; 12291da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 1230b112e0f7SJohannes Berg if (!$args{'content-only'}) { 1231b112e0f7SJohannes Berg print "<refsect1>\n <title>$section</title>\n"; 1232b112e0f7SJohannes Berg } 12331da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 12341da177e4SLinus Torvalds print "<example><para>\n"; 1235e314ba31SDaniel Santos $output_preformatted = 1; 1236b112e0f7SJohannes Berg } else { 1237b112e0f7SJohannes Berg print "<para>\n"; 12381da177e4SLinus Torvalds } 12391da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 1240e314ba31SDaniel Santos $output_preformatted = 0; 12411da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 12421da177e4SLinus Torvalds print "</para></example>\n"; 1243b112e0f7SJohannes Berg } else { 1244b112e0f7SJohannes Berg print "</para>"; 12451da177e4SLinus Torvalds } 1246b112e0f7SJohannes Berg if (!$args{'content-only'}) { 1247b112e0f7SJohannes Berg print "\n</refsect1>\n"; 1248b112e0f7SJohannes Berg } 12491da177e4SLinus Torvalds } 12501da177e4SLinus Torvalds 12511da177e4SLinus Torvalds print "\n\n"; 12521da177e4SLinus Torvalds} 12531da177e4SLinus Torvalds 12541da177e4SLinus Torvalds# output in XML DocBook 12551da177e4SLinus Torvaldssub output_function_gnome { 12561da177e4SLinus Torvalds my %args = %{$_[0]}; 12571da177e4SLinus Torvalds my ($parameter, $section); 12581da177e4SLinus Torvalds my $count; 12591da177e4SLinus Torvalds my $id; 12601da177e4SLinus Torvalds 12611da177e4SLinus Torvalds $id = $args{'module'} . "-" . $args{'function'}; 12621da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 12631da177e4SLinus Torvalds 12641da177e4SLinus Torvalds print "<sect2>\n"; 12651da177e4SLinus Torvalds print " <title id=\"$id\">" . $args{'function'} . "</title>\n"; 12661da177e4SLinus Torvalds 12671da177e4SLinus Torvalds print " <funcsynopsis>\n"; 12681da177e4SLinus Torvalds print " <funcdef>" . $args{'functiontype'} . " "; 12691da177e4SLinus Torvalds print "<function>" . $args{'function'} . " "; 12701da177e4SLinus Torvalds print "</function></funcdef>\n"; 12711da177e4SLinus Torvalds 12721da177e4SLinus Torvalds $count = 0; 12731da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 12741da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 12751da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 12761da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 12771da177e4SLinus Torvalds # pointer-to-function 12781da177e4SLinus Torvalds print " <paramdef>$1 <parameter>$parameter</parameter>)\n"; 12791da177e4SLinus Torvalds print " <funcparams>$2</funcparams></paramdef>\n"; 12801da177e4SLinus Torvalds } else { 12811da177e4SLinus Torvalds print " <paramdef>" . $type; 12821da177e4SLinus Torvalds print " <parameter>$parameter</parameter></paramdef>\n"; 12831da177e4SLinus Torvalds } 12841da177e4SLinus Torvalds } 12851da177e4SLinus Torvalds } else { 12861da177e4SLinus Torvalds print " <void>\n"; 12871da177e4SLinus Torvalds } 12881da177e4SLinus Torvalds print " </funcsynopsis>\n"; 12891da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 12901da177e4SLinus Torvalds print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n"; 12911da177e4SLinus Torvalds print "<tgroup cols=\"2\">\n"; 12921da177e4SLinus Torvalds print "<colspec colwidth=\"2*\">\n"; 12931da177e4SLinus Torvalds print "<colspec colwidth=\"8*\">\n"; 12941da177e4SLinus Torvalds print "<tbody>\n"; 12951da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 12961da177e4SLinus Torvalds my $parameter_name = $parameter; 12971da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 12981da177e4SLinus Torvalds 12991da177e4SLinus Torvalds print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n"; 13001da177e4SLinus Torvalds print " <entry>\n"; 13011da177e4SLinus Torvalds $lineprefix=" "; 13021da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 13031da177e4SLinus Torvalds print " </entry></row>\n"; 13041da177e4SLinus Torvalds } 13051da177e4SLinus Torvalds print " </tbody></tgroup></informaltable>\n"; 13061da177e4SLinus Torvalds } else { 13071da177e4SLinus Torvalds print " <para>\n None\n </para>\n"; 13081da177e4SLinus Torvalds } 13091da177e4SLinus Torvalds 13101da177e4SLinus Torvalds # print out each section 13111da177e4SLinus Torvalds $lineprefix=" "; 13121da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 13131da177e4SLinus Torvalds print "<simplesect>\n <title>$section</title>\n"; 13141da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 13151da177e4SLinus Torvalds print "<example><programlisting>\n"; 1316e314ba31SDaniel Santos $output_preformatted = 1; 13171da177e4SLinus Torvalds } else { 13181da177e4SLinus Torvalds } 13191da177e4SLinus Torvalds print "<para>\n"; 13201da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 1321e314ba31SDaniel Santos $output_preformatted = 0; 13221da177e4SLinus Torvalds print "</para>\n"; 13231da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 13241da177e4SLinus Torvalds print "</programlisting></example>\n"; 13251da177e4SLinus Torvalds } else { 13261da177e4SLinus Torvalds } 13271da177e4SLinus Torvalds print " </simplesect>\n"; 13281da177e4SLinus Torvalds } 13291da177e4SLinus Torvalds 13301da177e4SLinus Torvalds print "</sect2>\n\n"; 13311da177e4SLinus Torvalds} 13321da177e4SLinus Torvalds 13331da177e4SLinus Torvalds## 13341da177e4SLinus Torvalds# output function in man 13351da177e4SLinus Torvaldssub output_function_man(%) { 13361da177e4SLinus Torvalds my %args = %{$_[0]}; 13371da177e4SLinus Torvalds my ($parameter, $section); 13381da177e4SLinus Torvalds my $count; 13391da177e4SLinus Torvalds 13401da177e4SLinus Torvalds print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; 13411da177e4SLinus Torvalds 13421da177e4SLinus Torvalds print ".SH NAME\n"; 13431da177e4SLinus Torvalds print $args{'function'} . " \\- " . $args{'purpose'} . "\n"; 13441da177e4SLinus Torvalds 13451da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 1346a21217daSRandy Dunlap if ($args{'functiontype'} ne "") { 13471da177e4SLinus Torvalds print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n"; 1348a21217daSRandy Dunlap } else { 1349a21217daSRandy Dunlap print ".B \"" . $args{'function'} . "\n"; 1350a21217daSRandy Dunlap } 13511da177e4SLinus Torvalds $count = 0; 13521da177e4SLinus Torvalds my $parenth = "("; 13531da177e4SLinus Torvalds my $post = ","; 13541da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 13551da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 13561da177e4SLinus Torvalds $post = ");"; 13571da177e4SLinus Torvalds } 13581da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 13591da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 13601da177e4SLinus Torvalds # pointer-to-function 13611da177e4SLinus Torvalds print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n"; 13621da177e4SLinus Torvalds } else { 13631da177e4SLinus Torvalds $type =~ s/([^\*])$/$1 /; 13641da177e4SLinus Torvalds print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n"; 13651da177e4SLinus Torvalds } 13661da177e4SLinus Torvalds $count++; 13671da177e4SLinus Torvalds $parenth = ""; 13681da177e4SLinus Torvalds } 13691da177e4SLinus Torvalds 13701da177e4SLinus Torvalds print ".SH ARGUMENTS\n"; 13711da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 13721da177e4SLinus Torvalds my $parameter_name = $parameter; 13731da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 13741da177e4SLinus Torvalds 13751da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 13761da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 13771da177e4SLinus Torvalds } 13781da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 13791da177e4SLinus Torvalds print ".SH \"", uc $section, "\"\n"; 13801da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 13811da177e4SLinus Torvalds } 13821da177e4SLinus Torvalds} 13831da177e4SLinus Torvalds 13841da177e4SLinus Torvalds## 13851da177e4SLinus Torvalds# output enum in man 13861da177e4SLinus Torvaldssub output_enum_man(%) { 13871da177e4SLinus Torvalds my %args = %{$_[0]}; 13881da177e4SLinus Torvalds my ($parameter, $section); 13891da177e4SLinus Torvalds my $count; 13901da177e4SLinus Torvalds 13911da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n"; 13921da177e4SLinus Torvalds 13931da177e4SLinus Torvalds print ".SH NAME\n"; 13941da177e4SLinus Torvalds print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n"; 13951da177e4SLinus Torvalds 13961da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 13971da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 13981da177e4SLinus Torvalds $count = 0; 13991da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 14001da177e4SLinus Torvalds print ".br\n.BI \" $parameter\"\n"; 14011da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 14021da177e4SLinus Torvalds print "\n};\n"; 14031da177e4SLinus Torvalds last; 14041da177e4SLinus Torvalds } 14051da177e4SLinus Torvalds else { 14061da177e4SLinus Torvalds print ", \n.br\n"; 14071da177e4SLinus Torvalds } 14081da177e4SLinus Torvalds $count++; 14091da177e4SLinus Torvalds } 14101da177e4SLinus Torvalds 14111da177e4SLinus Torvalds print ".SH Constants\n"; 14121da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 14131da177e4SLinus Torvalds my $parameter_name = $parameter; 14141da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 14151da177e4SLinus Torvalds 14161da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 14171da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 14181da177e4SLinus Torvalds } 14191da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 14201da177e4SLinus Torvalds print ".SH \"$section\"\n"; 14211da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 14221da177e4SLinus Torvalds } 14231da177e4SLinus Torvalds} 14241da177e4SLinus Torvalds 14251da177e4SLinus Torvalds## 14261da177e4SLinus Torvalds# output struct in man 14271da177e4SLinus Torvaldssub output_struct_man(%) { 14281da177e4SLinus Torvalds my %args = %{$_[0]}; 14291da177e4SLinus Torvalds my ($parameter, $section); 14301da177e4SLinus Torvalds 14311da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n"; 14321da177e4SLinus Torvalds 14331da177e4SLinus Torvalds print ".SH NAME\n"; 14341da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n"; 14351da177e4SLinus Torvalds 14361da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 14371da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n.br\n"; 14381da177e4SLinus Torvalds 14391da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 14401da177e4SLinus Torvalds if ($parameter =~ /^#/) { 14411da177e4SLinus Torvalds print ".BI \"$parameter\"\n.br\n"; 14421da177e4SLinus Torvalds next; 14431da177e4SLinus Torvalds } 14441da177e4SLinus Torvalds my $parameter_name = $parameter; 14451da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 14461da177e4SLinus Torvalds 14471da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 14481da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 14491da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 14501da177e4SLinus Torvalds # pointer-to-function 14511da177e4SLinus Torvalds print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n"; 14521da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 14531d7e1d45SRandy.Dunlap # bitfield 14541d7e1d45SRandy.Dunlap print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n"; 14551da177e4SLinus Torvalds } else { 14561da177e4SLinus Torvalds $type =~ s/([^\*])$/$1 /; 14571da177e4SLinus Torvalds print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n"; 14581da177e4SLinus Torvalds } 14591da177e4SLinus Torvalds print "\n.br\n"; 14601da177e4SLinus Torvalds } 14611da177e4SLinus Torvalds print "};\n.br\n"; 14621da177e4SLinus Torvalds 1463c51d3dacSRandy Dunlap print ".SH Members\n"; 14641da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 14651da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 14661da177e4SLinus Torvalds 14671da177e4SLinus Torvalds my $parameter_name = $parameter; 14681da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 14691da177e4SLinus Torvalds 14701da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 14711da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 14721da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 14731da177e4SLinus Torvalds } 14741da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 14751da177e4SLinus Torvalds print ".SH \"$section\"\n"; 14761da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 14771da177e4SLinus Torvalds } 14781da177e4SLinus Torvalds} 14791da177e4SLinus Torvalds 14801da177e4SLinus Torvalds## 14811da177e4SLinus Torvalds# output typedef in man 14821da177e4SLinus Torvaldssub output_typedef_man(%) { 14831da177e4SLinus Torvalds my %args = %{$_[0]}; 14841da177e4SLinus Torvalds my ($parameter, $section); 14851da177e4SLinus Torvalds 14861da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n"; 14871da177e4SLinus Torvalds 14881da177e4SLinus Torvalds print ".SH NAME\n"; 14891da177e4SLinus Torvalds print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n"; 14901da177e4SLinus Torvalds 14911da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 14921da177e4SLinus Torvalds print ".SH \"$section\"\n"; 14931da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 14941da177e4SLinus Torvalds } 14951da177e4SLinus Torvalds} 14961da177e4SLinus Torvalds 1497b112e0f7SJohannes Bergsub output_blockhead_man(%) { 14981da177e4SLinus Torvalds my %args = %{$_[0]}; 14991da177e4SLinus Torvalds my ($parameter, $section); 15001da177e4SLinus Torvalds my $count; 15011da177e4SLinus Torvalds 15021da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; 15031da177e4SLinus Torvalds 15041da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 15051da177e4SLinus Torvalds print ".SH \"$section\"\n"; 15061da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 15071da177e4SLinus Torvalds } 15081da177e4SLinus Torvalds} 15091da177e4SLinus Torvalds 15101da177e4SLinus Torvalds## 15111da177e4SLinus Torvalds# output in text 15121da177e4SLinus Torvaldssub output_function_text(%) { 15131da177e4SLinus Torvalds my %args = %{$_[0]}; 15141da177e4SLinus Torvalds my ($parameter, $section); 1515a21217daSRandy Dunlap my $start; 15161da177e4SLinus Torvalds 1517f47634b2SRandy Dunlap print "Name:\n\n"; 1518f47634b2SRandy Dunlap print $args{'function'} . " - " . $args{'purpose'} . "\n"; 1519f47634b2SRandy Dunlap 1520f47634b2SRandy Dunlap print "\nSynopsis:\n\n"; 1521a21217daSRandy Dunlap if ($args{'functiontype'} ne "") { 1522a21217daSRandy Dunlap $start = $args{'functiontype'} . " " . $args{'function'} . " ("; 1523a21217daSRandy Dunlap } else { 1524a21217daSRandy Dunlap $start = $args{'function'} . " ("; 1525a21217daSRandy Dunlap } 15261da177e4SLinus Torvalds print $start; 1527a21217daSRandy Dunlap 15281da177e4SLinus Torvalds my $count = 0; 15291da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 15301da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 15311da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 15321da177e4SLinus Torvalds # pointer-to-function 15331da177e4SLinus Torvalds print $1 . $parameter . ") (" . $2; 15341da177e4SLinus Torvalds } else { 15351da177e4SLinus Torvalds print $type . " " . $parameter; 15361da177e4SLinus Torvalds } 15371da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 15381da177e4SLinus Torvalds $count++; 15391da177e4SLinus Torvalds print ",\n"; 15401da177e4SLinus Torvalds print " " x length($start); 15411da177e4SLinus Torvalds } else { 15421da177e4SLinus Torvalds print ");\n\n"; 15431da177e4SLinus Torvalds } 15441da177e4SLinus Torvalds } 15451da177e4SLinus Torvalds 15461da177e4SLinus Torvalds print "Arguments:\n\n"; 15471da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 15481da177e4SLinus Torvalds my $parameter_name = $parameter; 15491da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 15501da177e4SLinus Torvalds 15511da177e4SLinus Torvalds print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n"; 15521da177e4SLinus Torvalds } 15531da177e4SLinus Torvalds output_section_text(@_); 15541da177e4SLinus Torvalds} 15551da177e4SLinus Torvalds 15561da177e4SLinus Torvalds#output sections in text 15571da177e4SLinus Torvaldssub output_section_text(%) { 15581da177e4SLinus Torvalds my %args = %{$_[0]}; 15591da177e4SLinus Torvalds my $section; 15601da177e4SLinus Torvalds 15611da177e4SLinus Torvalds print "\n"; 15621da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 15631da177e4SLinus Torvalds print "$section:\n\n"; 15641da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 15651da177e4SLinus Torvalds } 15661da177e4SLinus Torvalds print "\n\n"; 15671da177e4SLinus Torvalds} 15681da177e4SLinus Torvalds 15691da177e4SLinus Torvalds# output enum in text 15701da177e4SLinus Torvaldssub output_enum_text(%) { 15711da177e4SLinus Torvalds my %args = %{$_[0]}; 15721da177e4SLinus Torvalds my ($parameter); 15731da177e4SLinus Torvalds my $count; 15741da177e4SLinus Torvalds print "Enum:\n\n"; 15751da177e4SLinus Torvalds 15761d7e1d45SRandy.Dunlap print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n"; 15771da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 15781da177e4SLinus Torvalds $count = 0; 15791da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 15801da177e4SLinus Torvalds print "\t$parameter"; 15811da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 15821da177e4SLinus Torvalds $count++; 15831da177e4SLinus Torvalds print ","; 15841da177e4SLinus Torvalds } 15851da177e4SLinus Torvalds print "\n"; 15861da177e4SLinus Torvalds } 15871da177e4SLinus Torvalds print "};\n\n"; 15881da177e4SLinus Torvalds 15891da177e4SLinus Torvalds print "Constants:\n\n"; 15901da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 15911da177e4SLinus Torvalds print "$parameter\n\t"; 15921da177e4SLinus Torvalds print $args{'parameterdescs'}{$parameter} . "\n"; 15931da177e4SLinus Torvalds } 15941da177e4SLinus Torvalds 15951da177e4SLinus Torvalds output_section_text(@_); 15961da177e4SLinus Torvalds} 15971da177e4SLinus Torvalds 15981da177e4SLinus Torvalds# output typedef in text 15991da177e4SLinus Torvaldssub output_typedef_text(%) { 16001da177e4SLinus Torvalds my %args = %{$_[0]}; 16011da177e4SLinus Torvalds my ($parameter); 16021da177e4SLinus Torvalds my $count; 16031da177e4SLinus Torvalds print "Typedef:\n\n"; 16041da177e4SLinus Torvalds 16051d7e1d45SRandy.Dunlap print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n"; 16061da177e4SLinus Torvalds output_section_text(@_); 16071da177e4SLinus Torvalds} 16081da177e4SLinus Torvalds 16091da177e4SLinus Torvalds# output struct as text 16101da177e4SLinus Torvaldssub output_struct_text(%) { 16111da177e4SLinus Torvalds my %args = %{$_[0]}; 16121da177e4SLinus Torvalds my ($parameter); 16131da177e4SLinus Torvalds 16141d7e1d45SRandy.Dunlap print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n"; 16151da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n"; 16161da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 16171da177e4SLinus Torvalds if ($parameter =~ /^#/) { 16181da177e4SLinus Torvalds print "$parameter\n"; 16191da177e4SLinus Torvalds next; 16201da177e4SLinus Torvalds } 16211da177e4SLinus Torvalds 16221da177e4SLinus Torvalds my $parameter_name = $parameter; 16231da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 16241da177e4SLinus Torvalds 16251da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 16261da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 16271da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 16281da177e4SLinus Torvalds # pointer-to-function 16291da177e4SLinus Torvalds print "\t$1 $parameter) ($2);\n"; 16301da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 163151f5a0c8SRandy Dunlap # bitfield 16321da177e4SLinus Torvalds print "\t$1 $parameter$2;\n"; 16331da177e4SLinus Torvalds } else { 16341da177e4SLinus Torvalds print "\t" . $type . " " . $parameter . ";\n"; 16351da177e4SLinus Torvalds } 16361da177e4SLinus Torvalds } 16371da177e4SLinus Torvalds print "};\n\n"; 16381da177e4SLinus Torvalds 16391da177e4SLinus Torvalds print "Members:\n\n"; 16401da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 16411da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 16421da177e4SLinus Torvalds 16431da177e4SLinus Torvalds my $parameter_name = $parameter; 16441da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 16451da177e4SLinus Torvalds 16461da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 16471da177e4SLinus Torvalds print "$parameter\n\t"; 16481da177e4SLinus Torvalds print $args{'parameterdescs'}{$parameter_name} . "\n"; 16491da177e4SLinus Torvalds } 16501da177e4SLinus Torvalds print "\n"; 16511da177e4SLinus Torvalds output_section_text(@_); 16521da177e4SLinus Torvalds} 16531da177e4SLinus Torvalds 1654b112e0f7SJohannes Bergsub output_blockhead_text(%) { 16551da177e4SLinus Torvalds my %args = %{$_[0]}; 16561da177e4SLinus Torvalds my ($parameter, $section); 16571da177e4SLinus Torvalds 16581da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 16591da177e4SLinus Torvalds print " $section:\n"; 16601da177e4SLinus Torvalds print " -> "; 16611da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 16621da177e4SLinus Torvalds } 16631da177e4SLinus Torvalds} 16641da177e4SLinus Torvalds 1665eda603f6SJohannes Berg## list mode output functions 1666eda603f6SJohannes Berg 1667eda603f6SJohannes Bergsub output_function_list(%) { 1668eda603f6SJohannes Berg my %args = %{$_[0]}; 1669eda603f6SJohannes Berg 1670eda603f6SJohannes Berg print $args{'function'} . "\n"; 1671eda603f6SJohannes Berg} 1672eda603f6SJohannes Berg 1673eda603f6SJohannes Berg# output enum in list 1674eda603f6SJohannes Bergsub output_enum_list(%) { 1675eda603f6SJohannes Berg my %args = %{$_[0]}; 1676eda603f6SJohannes Berg print $args{'enum'} . "\n"; 1677eda603f6SJohannes Berg} 1678eda603f6SJohannes Berg 1679eda603f6SJohannes Berg# output typedef in list 1680eda603f6SJohannes Bergsub output_typedef_list(%) { 1681eda603f6SJohannes Berg my %args = %{$_[0]}; 1682eda603f6SJohannes Berg print $args{'typedef'} . "\n"; 1683eda603f6SJohannes Berg} 1684eda603f6SJohannes Berg 1685eda603f6SJohannes Berg# output struct as list 1686eda603f6SJohannes Bergsub output_struct_list(%) { 1687eda603f6SJohannes Berg my %args = %{$_[0]}; 1688eda603f6SJohannes Berg 1689eda603f6SJohannes Berg print $args{'struct'} . "\n"; 1690eda603f6SJohannes Berg} 1691eda603f6SJohannes Berg 1692eda603f6SJohannes Bergsub output_blockhead_list(%) { 1693eda603f6SJohannes Berg my %args = %{$_[0]}; 1694eda603f6SJohannes Berg my ($parameter, $section); 1695eda603f6SJohannes Berg 1696eda603f6SJohannes Berg foreach $section (@{$args{'sectionlist'}}) { 1697eda603f6SJohannes Berg print "DOC: $section\n"; 1698eda603f6SJohannes Berg } 1699eda603f6SJohannes Berg} 1700eda603f6SJohannes Berg 17011da177e4SLinus Torvalds## 170227205744SRandy Dunlap# generic output function for all types (function, struct/union, typedef, enum); 170327205744SRandy Dunlap# calls the generated, variable output_ function name based on 170427205744SRandy Dunlap# functype and output_mode 17051da177e4SLinus Torvaldssub output_declaration { 17061da177e4SLinus Torvalds no strict 'refs'; 17071da177e4SLinus Torvalds my $name = shift; 17081da177e4SLinus Torvalds my $functype = shift; 17091da177e4SLinus Torvalds my $func = "output_${functype}_$output_mode"; 17101da177e4SLinus Torvalds if (($function_only==0) || 17111da177e4SLinus Torvalds ( $function_only == 1 && defined($function_table{$name})) || 17121da177e4SLinus Torvalds ( $function_only == 2 && !defined($function_table{$name}))) 17131da177e4SLinus Torvalds { 17141da177e4SLinus Torvalds &$func(@_); 17151da177e4SLinus Torvalds $section_counter++; 17161da177e4SLinus Torvalds } 17171da177e4SLinus Torvalds} 17181da177e4SLinus Torvalds 17191da177e4SLinus Torvalds## 172027205744SRandy Dunlap# generic output function - calls the right one based on current output mode. 1721b112e0f7SJohannes Bergsub output_blockhead { 17221da177e4SLinus Torvalds no strict 'refs'; 1723b112e0f7SJohannes Berg my $func = "output_blockhead_" . $output_mode; 17241da177e4SLinus Torvalds &$func(@_); 17251da177e4SLinus Torvalds $section_counter++; 17261da177e4SLinus Torvalds} 17271da177e4SLinus Torvalds 17281da177e4SLinus Torvalds## 17291da177e4SLinus Torvalds# takes a declaration (struct, union, enum, typedef) and 17301da177e4SLinus Torvalds# invokes the right handler. NOT called for functions. 17311da177e4SLinus Torvaldssub dump_declaration($$) { 17321da177e4SLinus Torvalds no strict 'refs'; 17331da177e4SLinus Torvalds my ($prototype, $file) = @_; 17341da177e4SLinus Torvalds my $func = "dump_" . $decl_type; 17351da177e4SLinus Torvalds &$func(@_); 17361da177e4SLinus Torvalds} 17371da177e4SLinus Torvalds 17381da177e4SLinus Torvaldssub dump_union($$) { 17391da177e4SLinus Torvalds dump_struct(@_); 17401da177e4SLinus Torvalds} 17411da177e4SLinus Torvalds 17421da177e4SLinus Torvaldssub dump_struct($$) { 17431da177e4SLinus Torvalds my $x = shift; 17441da177e4SLinus Torvalds my $file = shift; 1745a1d94aa5SRandy Dunlap my $nested; 17461da177e4SLinus Torvalds 17471da177e4SLinus Torvalds if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) { 174852dc5aecSRandy Dunlap #my $decl_type = $1; 17491da177e4SLinus Torvalds $declaration_name = $2; 17501da177e4SLinus Torvalds my $members = $3; 17511da177e4SLinus Torvalds 17521da177e4SLinus Torvalds # ignore embedded structs or unions 1753a1d94aa5SRandy Dunlap $members =~ s/({.*})//g; 1754a1d94aa5SRandy Dunlap $nested = $1; 17551da177e4SLinus Torvalds 1756aeec46b9SMartin Waitz # ignore members marked private: 175752dc5aecSRandy Dunlap $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gos; 175852dc5aecSRandy Dunlap $members =~ s/\/\*\s*private:.*//gos; 1759aeec46b9SMartin Waitz # strip comments: 1760aeec46b9SMartin Waitz $members =~ s/\/\*.*?\*\///gos; 1761a1d94aa5SRandy Dunlap $nested =~ s/\/\*.*?\*\///gos; 1762d960eea9SRandy Dunlap # strip kmemcheck_bitfield_{begin,end}.*; 1763d960eea9SRandy Dunlap $members =~ s/kmemcheck_bitfield_.*?;//gos; 1764ef5da59fSRandy Dunlap # strip attributes 17657b990789SJohannes Berg $members =~ s/__aligned\s*\([^;]*\)//gos; 1766aeec46b9SMartin Waitz 17671da177e4SLinus Torvalds create_parameterlist($members, ';', $file); 1768a1d94aa5SRandy Dunlap check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested); 17691da177e4SLinus Torvalds 17701da177e4SLinus Torvalds output_declaration($declaration_name, 17711da177e4SLinus Torvalds 'struct', 17721da177e4SLinus Torvalds {'struct' => $declaration_name, 17731da177e4SLinus Torvalds 'module' => $modulename, 17741da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 17751da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 17761da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 17771da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 17781da177e4SLinus Torvalds 'sections' => \%sections, 17791da177e4SLinus Torvalds 'purpose' => $declaration_purpose, 17801da177e4SLinus Torvalds 'type' => $decl_type 17811da177e4SLinus Torvalds }); 17821da177e4SLinus Torvalds } 17831da177e4SLinus Torvalds else { 17841da177e4SLinus Torvalds print STDERR "Error(${file}:$.): Cannot parse struct or union!\n"; 17851da177e4SLinus Torvalds ++$errors; 17861da177e4SLinus Torvalds } 17871da177e4SLinus Torvalds} 17881da177e4SLinus Torvalds 17891da177e4SLinus Torvaldssub dump_enum($$) { 17901da177e4SLinus Torvalds my $x = shift; 17911da177e4SLinus Torvalds my $file = shift; 17921da177e4SLinus Torvalds 1793aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 1794b6d676dbSRandy Dunlap $x =~ s/^#\s*define\s+.*$//; # strip #define macros inside enums 1795b6d676dbSRandy Dunlap 17961da177e4SLinus Torvalds if ($x =~ /enum\s+(\w+)\s*{(.*)}/) { 17971da177e4SLinus Torvalds $declaration_name = $1; 17981da177e4SLinus Torvalds my $members = $2; 17991da177e4SLinus Torvalds 18001da177e4SLinus Torvalds foreach my $arg (split ',', $members) { 18011da177e4SLinus Torvalds $arg =~ s/^\s*(\w+).*/$1/; 18021da177e4SLinus Torvalds push @parameterlist, $arg; 18031da177e4SLinus Torvalds if (!$parameterdescs{$arg}) { 18041da177e4SLinus Torvalds $parameterdescs{$arg} = $undescribed; 18051da177e4SLinus Torvalds print STDERR "Warning(${file}:$.): Enum value '$arg' ". 18061da177e4SLinus Torvalds "not described in enum '$declaration_name'\n"; 18071da177e4SLinus Torvalds } 18081da177e4SLinus Torvalds 18091da177e4SLinus Torvalds } 18101da177e4SLinus Torvalds 18111da177e4SLinus Torvalds output_declaration($declaration_name, 18121da177e4SLinus Torvalds 'enum', 18131da177e4SLinus Torvalds {'enum' => $declaration_name, 18141da177e4SLinus Torvalds 'module' => $modulename, 18151da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 18161da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 18171da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 18181da177e4SLinus Torvalds 'sections' => \%sections, 18191da177e4SLinus Torvalds 'purpose' => $declaration_purpose 18201da177e4SLinus Torvalds }); 18211da177e4SLinus Torvalds } 18221da177e4SLinus Torvalds else { 18231da177e4SLinus Torvalds print STDERR "Error(${file}:$.): Cannot parse enum!\n"; 18241da177e4SLinus Torvalds ++$errors; 18251da177e4SLinus Torvalds } 18261da177e4SLinus Torvalds} 18271da177e4SLinus Torvalds 18281da177e4SLinus Torvaldssub dump_typedef($$) { 18291da177e4SLinus Torvalds my $x = shift; 18301da177e4SLinus Torvalds my $file = shift; 18311da177e4SLinus Torvalds 1832aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 18331da177e4SLinus Torvalds while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { 18341da177e4SLinus Torvalds $x =~ s/\(*.\)\s*;$/;/; 18351da177e4SLinus Torvalds $x =~ s/\[*.\]\s*;$/;/; 18361da177e4SLinus Torvalds } 18371da177e4SLinus Torvalds 18381da177e4SLinus Torvalds if ($x =~ /typedef.*\s+(\w+)\s*;/) { 18391da177e4SLinus Torvalds $declaration_name = $1; 18401da177e4SLinus Torvalds 18411da177e4SLinus Torvalds output_declaration($declaration_name, 18421da177e4SLinus Torvalds 'typedef', 18431da177e4SLinus Torvalds {'typedef' => $declaration_name, 18441da177e4SLinus Torvalds 'module' => $modulename, 18451da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 18461da177e4SLinus Torvalds 'sections' => \%sections, 18471da177e4SLinus Torvalds 'purpose' => $declaration_purpose 18481da177e4SLinus Torvalds }); 18491da177e4SLinus Torvalds } 18501da177e4SLinus Torvalds else { 18511da177e4SLinus Torvalds print STDERR "Error(${file}:$.): Cannot parse typedef!\n"; 18521da177e4SLinus Torvalds ++$errors; 18531da177e4SLinus Torvalds } 18541da177e4SLinus Torvalds} 18551da177e4SLinus Torvalds 1856a1d94aa5SRandy Dunlapsub save_struct_actual($) { 1857a1d94aa5SRandy Dunlap my $actual = shift; 1858a1d94aa5SRandy Dunlap 1859a1d94aa5SRandy Dunlap # strip all spaces from the actual param so that it looks like one string item 1860a1d94aa5SRandy Dunlap $actual =~ s/\s*//g; 1861a1d94aa5SRandy Dunlap $struct_actual = $struct_actual . $actual . " "; 1862a1d94aa5SRandy Dunlap} 1863a1d94aa5SRandy Dunlap 18641da177e4SLinus Torvaldssub create_parameterlist($$$) { 18651da177e4SLinus Torvalds my $args = shift; 18661da177e4SLinus Torvalds my $splitter = shift; 18671da177e4SLinus Torvalds my $file = shift; 18681da177e4SLinus Torvalds my $type; 18691da177e4SLinus Torvalds my $param; 18701da177e4SLinus Torvalds 1871a6d3fe77SMartin Waitz # temporarily replace commas inside function pointer definition 18721da177e4SLinus Torvalds while ($args =~ /(\([^\),]+),/) { 18731da177e4SLinus Torvalds $args =~ s/(\([^\),]+),/$1#/g; 18741da177e4SLinus Torvalds } 18751da177e4SLinus Torvalds 18761da177e4SLinus Torvalds foreach my $arg (split($splitter, $args)) { 18771da177e4SLinus Torvalds # strip comments 18781da177e4SLinus Torvalds $arg =~ s/\/\*.*\*\///; 18791da177e4SLinus Torvalds # strip leading/trailing spaces 18801da177e4SLinus Torvalds $arg =~ s/^\s*//; 18811da177e4SLinus Torvalds $arg =~ s/\s*$//; 18821da177e4SLinus Torvalds $arg =~ s/\s+/ /; 18831da177e4SLinus Torvalds 18841da177e4SLinus Torvalds if ($arg =~ /^#/) { 18851da177e4SLinus Torvalds # Treat preprocessor directive as a typeless variable just to fill 18861da177e4SLinus Torvalds # corresponding data structures "correctly". Catch it later in 18871da177e4SLinus Torvalds # output_* subs. 18881da177e4SLinus Torvalds push_parameter($arg, "", $file); 188900d62961SRichard Kennedy } elsif ($arg =~ m/\(.+\)\s*\(/) { 18901da177e4SLinus Torvalds # pointer-to-function 18911da177e4SLinus Torvalds $arg =~ tr/#/,/; 189200d62961SRichard Kennedy $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/; 18931da177e4SLinus Torvalds $param = $1; 18941da177e4SLinus Torvalds $type = $arg; 189500d62961SRichard Kennedy $type =~ s/([^\(]+\(\*?)\s*$param/$1/; 1896a1d94aa5SRandy Dunlap save_struct_actual($param); 18971da177e4SLinus Torvalds push_parameter($param, $type, $file); 1898aeec46b9SMartin Waitz } elsif ($arg) { 18991da177e4SLinus Torvalds $arg =~ s/\s*:\s*/:/g; 19001da177e4SLinus Torvalds $arg =~ s/\s*\[/\[/g; 19011da177e4SLinus Torvalds 19021da177e4SLinus Torvalds my @args = split('\s*,\s*', $arg); 19031da177e4SLinus Torvalds if ($args[0] =~ m/\*/) { 19041da177e4SLinus Torvalds $args[0] =~ s/(\*+)\s*/ $1/; 19051da177e4SLinus Torvalds } 1906884f2810SBorislav Petkov 1907884f2810SBorislav Petkov my @first_arg; 1908884f2810SBorislav Petkov if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) { 1909884f2810SBorislav Petkov shift @args; 1910884f2810SBorislav Petkov push(@first_arg, split('\s+', $1)); 1911884f2810SBorislav Petkov push(@first_arg, $2); 1912884f2810SBorislav Petkov } else { 1913884f2810SBorislav Petkov @first_arg = split('\s+', shift @args); 1914884f2810SBorislav Petkov } 1915884f2810SBorislav Petkov 19161da177e4SLinus Torvalds unshift(@args, pop @first_arg); 19171da177e4SLinus Torvalds $type = join " ", @first_arg; 19181da177e4SLinus Torvalds 19191da177e4SLinus Torvalds foreach $param (@args) { 19201da177e4SLinus Torvalds if ($param =~ m/^(\*+)\s*(.*)/) { 1921a1d94aa5SRandy Dunlap save_struct_actual($2); 19221da177e4SLinus Torvalds push_parameter($2, "$type $1", $file); 19231da177e4SLinus Torvalds } 19241da177e4SLinus Torvalds elsif ($param =~ m/(.*?):(\d+)/) { 19257b97887eSRandy Dunlap if ($type ne "") { # skip unnamed bit-fields 1926a1d94aa5SRandy Dunlap save_struct_actual($1); 19271da177e4SLinus Torvalds push_parameter($1, "$type:$2", $file) 19281da177e4SLinus Torvalds } 19297b97887eSRandy Dunlap } 19301da177e4SLinus Torvalds else { 1931a1d94aa5SRandy Dunlap save_struct_actual($param); 19321da177e4SLinus Torvalds push_parameter($param, $type, $file); 19331da177e4SLinus Torvalds } 19341da177e4SLinus Torvalds } 19351da177e4SLinus Torvalds } 19361da177e4SLinus Torvalds } 19371da177e4SLinus Torvalds} 19381da177e4SLinus Torvalds 19391da177e4SLinus Torvaldssub push_parameter($$$) { 19401da177e4SLinus Torvalds my $param = shift; 19411da177e4SLinus Torvalds my $type = shift; 19421da177e4SLinus Torvalds my $file = shift; 19431da177e4SLinus Torvalds 19445f8c7c98SRandy Dunlap if (($anon_struct_union == 1) && ($type eq "") && 19455f8c7c98SRandy Dunlap ($param eq "}")) { 19465f8c7c98SRandy Dunlap return; # ignore the ending }; from anon. struct/union 19475f8c7c98SRandy Dunlap } 19485f8c7c98SRandy Dunlap 19495f8c7c98SRandy Dunlap $anon_struct_union = 0; 19501da177e4SLinus Torvalds my $param_name = $param; 19511da177e4SLinus Torvalds $param_name =~ s/\[.*//; 19521da177e4SLinus Torvalds 1953a6d3fe77SMartin Waitz if ($type eq "" && $param =~ /\.\.\.$/) 19541da177e4SLinus Torvalds { 1955ced69090SRandy Dunlap if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { 1956a6d3fe77SMartin Waitz $parameterdescs{$param} = "variable arguments"; 19571da177e4SLinus Torvalds } 1958ced69090SRandy Dunlap } 19591da177e4SLinus Torvalds elsif ($type eq "" && ($param eq "" or $param eq "void")) 19601da177e4SLinus Torvalds { 19611da177e4SLinus Torvalds $param="void"; 19621da177e4SLinus Torvalds $parameterdescs{void} = "no arguments"; 19631da177e4SLinus Torvalds } 1964134fe01bSRandy Dunlap elsif ($type eq "" && ($param eq "struct" or $param eq "union")) 1965134fe01bSRandy Dunlap # handle unnamed (anonymous) union or struct: 1966134fe01bSRandy Dunlap { 1967134fe01bSRandy Dunlap $type = $param; 1968134fe01bSRandy Dunlap $param = "{unnamed_" . $param . "}"; 1969134fe01bSRandy Dunlap $parameterdescs{$param} = "anonymous\n"; 19705f8c7c98SRandy Dunlap $anon_struct_union = 1; 1971134fe01bSRandy Dunlap } 1972134fe01bSRandy Dunlap 1973a6d3fe77SMartin Waitz # warn if parameter has no description 1974134fe01bSRandy Dunlap # (but ignore ones starting with # as these are not parameters 1975134fe01bSRandy Dunlap # but inline preprocessor statements); 1976134fe01bSRandy Dunlap # also ignore unnamed structs/unions; 19775f8c7c98SRandy Dunlap if (!$anon_struct_union) { 1978a6d3fe77SMartin Waitz if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) { 1979a6d3fe77SMartin Waitz 19801da177e4SLinus Torvalds $parameterdescs{$param_name} = $undescribed; 19811da177e4SLinus Torvalds 19821da177e4SLinus Torvalds if (($type eq 'function') || ($type eq 'enum')) { 19831da177e4SLinus Torvalds print STDERR "Warning(${file}:$.): Function parameter ". 19841da177e4SLinus Torvalds "or member '$param' not " . 19851da177e4SLinus Torvalds "described in '$declaration_name'\n"; 19861da177e4SLinus Torvalds } 19871da177e4SLinus Torvalds print STDERR "Warning(${file}:$.):" . 19881da177e4SLinus Torvalds " No description found for parameter '$param'\n"; 19891da177e4SLinus Torvalds ++$warnings; 19901da177e4SLinus Torvalds } 1991134fe01bSRandy Dunlap } 19921da177e4SLinus Torvalds 19932b35f4d9SRandy Dunlap $param = xml_escape($param); 19942b35f4d9SRandy Dunlap 199525985edcSLucas De Marchi # strip spaces from $param so that it is one continuous string 1996e34e7dbbSRandy Dunlap # on @parameterlist; 1997e34e7dbbSRandy Dunlap # this fixes a problem where check_sections() cannot find 1998e34e7dbbSRandy Dunlap # a parameter like "addr[6 + 2]" because it actually appears 1999e34e7dbbSRandy Dunlap # as "addr[6", "+", "2]" on the parameter list; 2000e34e7dbbSRandy Dunlap # but it's better to maintain the param string unchanged for output, 2001e34e7dbbSRandy Dunlap # so just weaken the string compare in check_sections() to ignore 2002e34e7dbbSRandy Dunlap # "[blah" in a parameter string; 2003e34e7dbbSRandy Dunlap ###$param =~ s/\s*//g; 20041da177e4SLinus Torvalds push @parameterlist, $param; 20051da177e4SLinus Torvalds $parametertypes{$param} = $type; 20061da177e4SLinus Torvalds} 20071da177e4SLinus Torvalds 2008a1d94aa5SRandy Dunlapsub check_sections($$$$$$) { 2009a1d94aa5SRandy Dunlap my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_; 2010a1d94aa5SRandy Dunlap my @sects = split ' ', $sectcheck; 2011a1d94aa5SRandy Dunlap my @prms = split ' ', $prmscheck; 2012a1d94aa5SRandy Dunlap my $err; 2013a1d94aa5SRandy Dunlap my ($px, $sx); 2014a1d94aa5SRandy Dunlap my $prm_clean; # strip trailing "[array size]" and/or beginning "*" 2015a1d94aa5SRandy Dunlap 2016a1d94aa5SRandy Dunlap foreach $sx (0 .. $#sects) { 2017a1d94aa5SRandy Dunlap $err = 1; 2018a1d94aa5SRandy Dunlap foreach $px (0 .. $#prms) { 2019a1d94aa5SRandy Dunlap $prm_clean = $prms[$px]; 2020a1d94aa5SRandy Dunlap $prm_clean =~ s/\[.*\]//; 20211f3a6688SJohannes Berg $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; 2022e34e7dbbSRandy Dunlap # ignore array size in a parameter string; 2023e34e7dbbSRandy Dunlap # however, the original param string may contain 2024e34e7dbbSRandy Dunlap # spaces, e.g.: addr[6 + 2] 2025e34e7dbbSRandy Dunlap # and this appears in @prms as "addr[6" since the 2026e34e7dbbSRandy Dunlap # parameter list is split at spaces; 2027e34e7dbbSRandy Dunlap # hence just ignore "[..." for the sections check; 2028e34e7dbbSRandy Dunlap $prm_clean =~ s/\[.*//; 2029e34e7dbbSRandy Dunlap 2030a1d94aa5SRandy Dunlap ##$prm_clean =~ s/^\**//; 2031a1d94aa5SRandy Dunlap if ($prm_clean eq $sects[$sx]) { 2032a1d94aa5SRandy Dunlap $err = 0; 2033a1d94aa5SRandy Dunlap last; 2034a1d94aa5SRandy Dunlap } 2035a1d94aa5SRandy Dunlap } 2036a1d94aa5SRandy Dunlap if ($err) { 2037a1d94aa5SRandy Dunlap if ($decl_type eq "function") { 2038a1d94aa5SRandy Dunlap print STDERR "Warning(${file}:$.): " . 2039a1d94aa5SRandy Dunlap "Excess function parameter " . 2040a1d94aa5SRandy Dunlap "'$sects[$sx]' " . 2041a1d94aa5SRandy Dunlap "description in '$decl_name'\n"; 2042a1d94aa5SRandy Dunlap ++$warnings; 2043a1d94aa5SRandy Dunlap } else { 2044a1d94aa5SRandy Dunlap if ($nested !~ m/\Q$sects[$sx]\E/) { 2045a1d94aa5SRandy Dunlap print STDERR "Warning(${file}:$.): " . 2046a1d94aa5SRandy Dunlap "Excess struct/union/enum/typedef member " . 2047a1d94aa5SRandy Dunlap "'$sects[$sx]' " . 2048a1d94aa5SRandy Dunlap "description in '$decl_name'\n"; 2049a1d94aa5SRandy Dunlap ++$warnings; 2050a1d94aa5SRandy Dunlap } 2051a1d94aa5SRandy Dunlap } 2052a1d94aa5SRandy Dunlap } 2053a1d94aa5SRandy Dunlap } 2054a1d94aa5SRandy Dunlap} 2055a1d94aa5SRandy Dunlap 20561da177e4SLinus Torvalds## 20574092bac7SYacine Belkadi# Checks the section describing the return value of a function. 20584092bac7SYacine Belkadisub check_return_section { 20594092bac7SYacine Belkadi my $file = shift; 20604092bac7SYacine Belkadi my $declaration_name = shift; 20614092bac7SYacine Belkadi my $return_type = shift; 20624092bac7SYacine Belkadi 20634092bac7SYacine Belkadi # Ignore an empty return type (It's a macro) 20644092bac7SYacine Belkadi # Ignore functions with a "void" return type. (But don't ignore "void *") 20654092bac7SYacine Belkadi if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) { 20664092bac7SYacine Belkadi return; 20674092bac7SYacine Belkadi } 20684092bac7SYacine Belkadi 20694092bac7SYacine Belkadi if (!defined($sections{$section_return}) || 20704092bac7SYacine Belkadi $sections{$section_return} eq "") { 20714092bac7SYacine Belkadi print STDERR "Warning(${file}:$.): " . 20724092bac7SYacine Belkadi "No description found for return value of " . 20734092bac7SYacine Belkadi "'$declaration_name'\n"; 20744092bac7SYacine Belkadi ++$warnings; 20754092bac7SYacine Belkadi } 20764092bac7SYacine Belkadi} 20774092bac7SYacine Belkadi 20784092bac7SYacine Belkadi## 20791da177e4SLinus Torvalds# takes a function prototype and the name of the current file being 20801da177e4SLinus Torvalds# processed and spits out all the details stored in the global 20811da177e4SLinus Torvalds# arrays/hashes. 20821da177e4SLinus Torvaldssub dump_function($$) { 20831da177e4SLinus Torvalds my $prototype = shift; 20841da177e4SLinus Torvalds my $file = shift; 2085cbb4d3e6SHoria Geanta my $noret = 0; 20861da177e4SLinus Torvalds 20871da177e4SLinus Torvalds $prototype =~ s/^static +//; 20881da177e4SLinus Torvalds $prototype =~ s/^extern +//; 20894dc3b16bSPavel Pisa $prototype =~ s/^asmlinkage +//; 20901da177e4SLinus Torvalds $prototype =~ s/^inline +//; 20911da177e4SLinus Torvalds $prototype =~ s/^__inline__ +//; 209232e79401SRandy Dunlap $prototype =~ s/^__inline +//; 209332e79401SRandy Dunlap $prototype =~ s/^__always_inline +//; 209432e79401SRandy Dunlap $prototype =~ s/^noinline +//; 209574fc5c65SRandy Dunlap $prototype =~ s/__init +//; 209620072205SRandy Dunlap $prototype =~ s/__init_or_module +//; 2097270a0096SRandy Dunlap $prototype =~ s/__meminit +//; 209870c95b00SRandy Dunlap $prototype =~ s/__must_check +//; 20990df7c0e3SRandy Dunlap $prototype =~ s/__weak +//; 2100cbb4d3e6SHoria Geanta my $define = $prototype =~ s/^#\s*define\s+//; #ak added 2101328d2440SRandy Dunlap $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//; 21021da177e4SLinus Torvalds 21031da177e4SLinus Torvalds # Yes, this truly is vile. We are looking for: 21041da177e4SLinus Torvalds # 1. Return type (may be nothing if we're looking at a macro) 21051da177e4SLinus Torvalds # 2. Function name 21061da177e4SLinus Torvalds # 3. Function parameters. 21071da177e4SLinus Torvalds # 21081da177e4SLinus Torvalds # All the while we have to watch out for function pointer parameters 21091da177e4SLinus Torvalds # (which IIRC is what the two sections are for), C types (these 21101da177e4SLinus Torvalds # regexps don't even start to express all the possibilities), and 21111da177e4SLinus Torvalds # so on. 21121da177e4SLinus Torvalds # 21131da177e4SLinus Torvalds # If you mess with these regexps, it's a good idea to check that 21141da177e4SLinus Torvalds # the following functions' documentation still comes out right: 21151da177e4SLinus Torvalds # - parport_register_device (function pointer parameters) 21161da177e4SLinus Torvalds # - atomic_set (macro) 21179598f91fSMartin Waitz # - pci_match_device, __copy_to_user (long return type) 21181da177e4SLinus Torvalds 2119cbb4d3e6SHoria Geanta if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) { 2120cbb4d3e6SHoria Geanta # This is an object-like macro, it has no return type and no parameter 2121cbb4d3e6SHoria Geanta # list. 2122cbb4d3e6SHoria Geanta # Function-like macros are not allowed to have spaces between 2123cbb4d3e6SHoria Geanta # declaration_name and opening parenthesis (notice the \s+). 2124cbb4d3e6SHoria Geanta $return_type = $1; 2125cbb4d3e6SHoria Geanta $declaration_name = $2; 2126cbb4d3e6SHoria Geanta $noret = 1; 2127cbb4d3e6SHoria Geanta } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 21281da177e4SLinus Torvalds $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 21291da177e4SLinus Torvalds $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 21301da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 213194b3e03cSRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 21321da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 21331da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 21341da177e4SLinus Torvalds $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 21351da177e4SLinus Torvalds $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 21361da177e4SLinus Torvalds $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 21371da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 21381da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 21391da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 21409598f91fSMartin Waitz $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 21419598f91fSMartin Waitz $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 2142412ecd77SRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 2143412ecd77SRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) { 21441da177e4SLinus Torvalds $return_type = $1; 21451da177e4SLinus Torvalds $declaration_name = $2; 21461da177e4SLinus Torvalds my $args = $3; 21471da177e4SLinus Torvalds 21481da177e4SLinus Torvalds create_parameterlist($args, ',', $file); 21491da177e4SLinus Torvalds } else { 21509645ae84SRandy Dunlap print STDERR "Warning(${file}:$.): cannot understand function prototype: '$prototype'\n"; 21511da177e4SLinus Torvalds return; 21521da177e4SLinus Torvalds } 21531da177e4SLinus Torvalds 2154a1d94aa5SRandy Dunlap my $prms = join " ", @parameterlist; 2155a1d94aa5SRandy Dunlap check_sections($file, $declaration_name, "function", $sectcheck, $prms, ""); 2156a1d94aa5SRandy Dunlap 21574092bac7SYacine Belkadi # This check emits a lot of warnings at the moment, because many 21584092bac7SYacine Belkadi # functions don't have a 'Return' doc section. So until the number 21594092bac7SYacine Belkadi # of warnings goes sufficiently down, the check is only performed in 21604092bac7SYacine Belkadi # verbose mode. 21614092bac7SYacine Belkadi # TODO: always perform the check. 2162cbb4d3e6SHoria Geanta if ($verbose && !$noret) { 21634092bac7SYacine Belkadi check_return_section($file, $declaration_name, $return_type); 21644092bac7SYacine Belkadi } 21654092bac7SYacine Belkadi 21661da177e4SLinus Torvalds output_declaration($declaration_name, 21671da177e4SLinus Torvalds 'function', 21681da177e4SLinus Torvalds {'function' => $declaration_name, 21691da177e4SLinus Torvalds 'module' => $modulename, 21701da177e4SLinus Torvalds 'functiontype' => $return_type, 21711da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 21721da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 21731da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 21741da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 21751da177e4SLinus Torvalds 'sections' => \%sections, 21761da177e4SLinus Torvalds 'purpose' => $declaration_purpose 21771da177e4SLinus Torvalds }); 21781da177e4SLinus Torvalds} 21791da177e4SLinus Torvalds 21801da177e4SLinus Torvaldssub reset_state { 21811da177e4SLinus Torvalds $function = ""; 21821da177e4SLinus Torvalds %constants = (); 21831da177e4SLinus Torvalds %parameterdescs = (); 21841da177e4SLinus Torvalds %parametertypes = (); 21851da177e4SLinus Torvalds @parameterlist = (); 21861da177e4SLinus Torvalds %sections = (); 21871da177e4SLinus Torvalds @sectionlist = (); 2188a1d94aa5SRandy Dunlap $sectcheck = ""; 2189a1d94aa5SRandy Dunlap $struct_actual = ""; 21901da177e4SLinus Torvalds $prototype = ""; 21911da177e4SLinus Torvalds 21921da177e4SLinus Torvalds $state = 0; 21931da177e4SLinus Torvalds} 21941da177e4SLinus Torvalds 219556afb0f8SJason Baronsub tracepoint_munge($) { 219656afb0f8SJason Baron my $file = shift; 219756afb0f8SJason Baron my $tracepointname = 0; 219856afb0f8SJason Baron my $tracepointargs = 0; 219956afb0f8SJason Baron 220056afb0f8SJason Baron if ($prototype =~ m/TRACE_EVENT\((.*?),/) { 220156afb0f8SJason Baron $tracepointname = $1; 220256afb0f8SJason Baron } 22033a9089fdSJason Baron if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) { 22043a9089fdSJason Baron $tracepointname = $1; 22053a9089fdSJason Baron } 22063a9089fdSJason Baron if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) { 22073a9089fdSJason Baron $tracepointname = $2; 22083a9089fdSJason Baron } 22093a9089fdSJason Baron $tracepointname =~ s/^\s+//; #strip leading whitespace 221056afb0f8SJason Baron if ($prototype =~ m/TP_PROTO\((.*?)\)/) { 221156afb0f8SJason Baron $tracepointargs = $1; 221256afb0f8SJason Baron } 221356afb0f8SJason Baron if (($tracepointname eq 0) || ($tracepointargs eq 0)) { 221456afb0f8SJason Baron print STDERR "Warning(${file}:$.): Unrecognized tracepoint format: \n". 221556afb0f8SJason Baron "$prototype\n"; 221656afb0f8SJason Baron } else { 221756afb0f8SJason Baron $prototype = "static inline void trace_$tracepointname($tracepointargs)"; 221856afb0f8SJason Baron } 221956afb0f8SJason Baron} 222056afb0f8SJason Baron 2221b4870bc5SRandy Dunlapsub syscall_munge() { 2222b4870bc5SRandy Dunlap my $void = 0; 2223b4870bc5SRandy Dunlap 2224b4870bc5SRandy Dunlap $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs 2225b4870bc5SRandy Dunlap## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) { 2226b4870bc5SRandy Dunlap if ($prototype =~ m/SYSCALL_DEFINE0/) { 2227b4870bc5SRandy Dunlap $void = 1; 2228b4870bc5SRandy Dunlap## $prototype = "long sys_$1(void)"; 2229b4870bc5SRandy Dunlap } 2230b4870bc5SRandy Dunlap 2231b4870bc5SRandy Dunlap $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name 2232b4870bc5SRandy Dunlap if ($prototype =~ m/long (sys_.*?),/) { 2233b4870bc5SRandy Dunlap $prototype =~ s/,/\(/; 2234b4870bc5SRandy Dunlap } elsif ($void) { 2235b4870bc5SRandy Dunlap $prototype =~ s/\)/\(void\)/; 2236b4870bc5SRandy Dunlap } 2237b4870bc5SRandy Dunlap 2238b4870bc5SRandy Dunlap # now delete all of the odd-number commas in $prototype 2239b4870bc5SRandy Dunlap # so that arg types & arg names don't have a comma between them 2240b4870bc5SRandy Dunlap my $count = 0; 2241b4870bc5SRandy Dunlap my $len = length($prototype); 2242b4870bc5SRandy Dunlap if ($void) { 2243b4870bc5SRandy Dunlap $len = 0; # skip the for-loop 2244b4870bc5SRandy Dunlap } 2245b4870bc5SRandy Dunlap for (my $ix = 0; $ix < $len; $ix++) { 2246b4870bc5SRandy Dunlap if (substr($prototype, $ix, 1) eq ',') { 2247b4870bc5SRandy Dunlap $count++; 2248b4870bc5SRandy Dunlap if ($count % 2 == 1) { 2249b4870bc5SRandy Dunlap substr($prototype, $ix, 1) = ' '; 2250b4870bc5SRandy Dunlap } 2251b4870bc5SRandy Dunlap } 2252b4870bc5SRandy Dunlap } 2253b4870bc5SRandy Dunlap} 2254b4870bc5SRandy Dunlap 22551da177e4SLinus Torvaldssub process_state3_function($$) { 22561da177e4SLinus Torvalds my $x = shift; 22571da177e4SLinus Torvalds my $file = shift; 22581da177e4SLinus Torvalds 225951f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 226051f5a0c8SRandy Dunlap 2261890c78c2SRandy Dunlap if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) { 22621da177e4SLinus Torvalds # do nothing 22631da177e4SLinus Torvalds } 22641da177e4SLinus Torvalds elsif ($x =~ /([^\{]*)/) { 22651da177e4SLinus Torvalds $prototype .= $1; 22661da177e4SLinus Torvalds } 2267b4870bc5SRandy Dunlap 2268890c78c2SRandy Dunlap if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) { 22691da177e4SLinus Torvalds $prototype =~ s@/\*.*?\*/@@gos; # strip comments. 22701da177e4SLinus Torvalds $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 22711da177e4SLinus Torvalds $prototype =~ s@^\s+@@gos; # strip leading spaces 2272b4870bc5SRandy Dunlap if ($prototype =~ /SYSCALL_DEFINE/) { 2273b4870bc5SRandy Dunlap syscall_munge(); 2274b4870bc5SRandy Dunlap } 22753a9089fdSJason Baron if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ || 22763a9089fdSJason Baron $prototype =~ /DEFINE_SINGLE_EVENT/) 22773a9089fdSJason Baron { 227856afb0f8SJason Baron tracepoint_munge($file); 227956afb0f8SJason Baron } 22801da177e4SLinus Torvalds dump_function($prototype, $file); 22811da177e4SLinus Torvalds reset_state(); 22821da177e4SLinus Torvalds } 22831da177e4SLinus Torvalds} 22841da177e4SLinus Torvalds 22851da177e4SLinus Torvaldssub process_state3_type($$) { 22861da177e4SLinus Torvalds my $x = shift; 22871da177e4SLinus Torvalds my $file = shift; 22881da177e4SLinus Torvalds 22891da177e4SLinus Torvalds $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 22901da177e4SLinus Torvalds $x =~ s@^\s+@@gos; # strip leading spaces 22911da177e4SLinus Torvalds $x =~ s@\s+$@@gos; # strip trailing spaces 229251f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 229351f5a0c8SRandy Dunlap 22941da177e4SLinus Torvalds if ($x =~ /^#/) { 22951da177e4SLinus Torvalds # To distinguish preprocessor directive from regular declaration later. 22961da177e4SLinus Torvalds $x .= ";"; 22971da177e4SLinus Torvalds } 22981da177e4SLinus Torvalds 22991da177e4SLinus Torvalds while (1) { 23001da177e4SLinus Torvalds if ( $x =~ /([^{};]*)([{};])(.*)/ ) { 23011da177e4SLinus Torvalds $prototype .= $1 . $2; 23021da177e4SLinus Torvalds ($2 eq '{') && $brcount++; 23031da177e4SLinus Torvalds ($2 eq '}') && $brcount--; 23041da177e4SLinus Torvalds if (($2 eq ';') && ($brcount == 0)) { 23051da177e4SLinus Torvalds dump_declaration($prototype, $file); 23061da177e4SLinus Torvalds reset_state(); 23071da177e4SLinus Torvalds last; 23081da177e4SLinus Torvalds } 23091da177e4SLinus Torvalds $x = $3; 23101da177e4SLinus Torvalds } else { 23111da177e4SLinus Torvalds $prototype .= $x; 23121da177e4SLinus Torvalds last; 23131da177e4SLinus Torvalds } 23141da177e4SLinus Torvalds } 23151da177e4SLinus Torvalds} 23161da177e4SLinus Torvalds 23176b5b55f6SRandy Dunlap# xml_escape: replace <, >, and & in the text stream; 23186b5b55f6SRandy Dunlap# 23196b5b55f6SRandy Dunlap# however, formatting controls that are generated internally/locally in the 23206b5b55f6SRandy Dunlap# kernel-doc script are not escaped here; instead, they begin life like 23216b5b55f6SRandy Dunlap# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings 23226b5b55f6SRandy Dunlap# are converted to their mnemonic-expected output, without the 4 * '\' & ':', 23236b5b55f6SRandy Dunlap# just before actual output; (this is done by local_unescape()) 23241da177e4SLinus Torvaldssub xml_escape($) { 23251da177e4SLinus Torvalds my $text = shift; 2326ecfb251aSRandy Dunlap if (($output_mode eq "text") || ($output_mode eq "man")) { 2327ecfb251aSRandy Dunlap return $text; 2328ecfb251aSRandy Dunlap } 23291da177e4SLinus Torvalds $text =~ s/\&/\\\\\\amp;/g; 23301da177e4SLinus Torvalds $text =~ s/\</\\\\\\lt;/g; 23311da177e4SLinus Torvalds $text =~ s/\>/\\\\\\gt;/g; 23321da177e4SLinus Torvalds return $text; 23331da177e4SLinus Torvalds} 23341da177e4SLinus Torvalds 23356b5b55f6SRandy Dunlap# convert local escape strings to html 23366b5b55f6SRandy Dunlap# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes) 23376b5b55f6SRandy Dunlapsub local_unescape($) { 23386b5b55f6SRandy Dunlap my $text = shift; 23396b5b55f6SRandy Dunlap if (($output_mode eq "text") || ($output_mode eq "man")) { 23406b5b55f6SRandy Dunlap return $text; 23416b5b55f6SRandy Dunlap } 23426b5b55f6SRandy Dunlap $text =~ s/\\\\\\\\lt:/</g; 23436b5b55f6SRandy Dunlap $text =~ s/\\\\\\\\gt:/>/g; 23446b5b55f6SRandy Dunlap return $text; 23456b5b55f6SRandy Dunlap} 23466b5b55f6SRandy Dunlap 23471da177e4SLinus Torvaldssub process_file($) { 23482283a117SRandy Dunlap my $file; 23491da177e4SLinus Torvalds my $identifier; 23501da177e4SLinus Torvalds my $func; 2351a21217daSRandy Dunlap my $descr; 23526423133bSJohannes Weiner my $in_purpose = 0; 23531da177e4SLinus Torvalds my $initial_section_counter = $section_counter; 23541da177e4SLinus Torvalds 23552283a117SRandy Dunlap if (defined($ENV{'SRCTREE'})) { 23562283a117SRandy Dunlap $file = "$ENV{'SRCTREE'}" . "/" . "@_"; 23572283a117SRandy Dunlap } 23582283a117SRandy Dunlap else { 23592283a117SRandy Dunlap $file = "@_"; 23602283a117SRandy Dunlap } 23611da177e4SLinus Torvalds if (defined($source_map{$file})) { 23621da177e4SLinus Torvalds $file = $source_map{$file}; 23631da177e4SLinus Torvalds } 23641da177e4SLinus Torvalds 23651da177e4SLinus Torvalds if (!open(IN,"<$file")) { 23661da177e4SLinus Torvalds print STDERR "Error: Cannot open file $file\n"; 23671da177e4SLinus Torvalds ++$errors; 23681da177e4SLinus Torvalds return; 23691da177e4SLinus Torvalds } 23701da177e4SLinus Torvalds 2371a9e7314bSIlya Dryomov $. = 1; 2372a9e7314bSIlya Dryomov 23731da177e4SLinus Torvalds $section_counter = 0; 23741da177e4SLinus Torvalds while (<IN>) { 237565478428SDaniel Santos while (s/\\\s*$//) { 237665478428SDaniel Santos $_ .= <IN>; 237765478428SDaniel Santos } 23781da177e4SLinus Torvalds if ($state == 0) { 23791da177e4SLinus Torvalds if (/$doc_start/o) { 23801da177e4SLinus Torvalds $state = 1; # next line is always the function name 2381850622dfSRandy Dunlap $in_doc_sect = 0; 23821da177e4SLinus Torvalds } 23831da177e4SLinus Torvalds } elsif ($state == 1) { # this line is the function name (always) 23841da177e4SLinus Torvalds if (/$doc_block/o) { 23851da177e4SLinus Torvalds $state = 4; 23861da177e4SLinus Torvalds $contents = ""; 23871da177e4SLinus Torvalds if ( $1 eq "" ) { 23881da177e4SLinus Torvalds $section = $section_intro; 23891da177e4SLinus Torvalds } else { 23901da177e4SLinus Torvalds $section = $1; 23911da177e4SLinus Torvalds } 23921da177e4SLinus Torvalds } 23931da177e4SLinus Torvalds elsif (/$doc_decl/o) { 23941da177e4SLinus Torvalds $identifier = $1; 23951da177e4SLinus Torvalds if (/\s*([\w\s]+?)\s*-/) { 23961da177e4SLinus Torvalds $identifier = $1; 23971da177e4SLinus Torvalds } 23981da177e4SLinus Torvalds 23991da177e4SLinus Torvalds $state = 2; 24001da177e4SLinus Torvalds if (/-(.*)/) { 240151f5a0c8SRandy Dunlap # strip leading/trailing/multiple spaces 2402a21217daSRandy Dunlap $descr= $1; 2403a21217daSRandy Dunlap $descr =~ s/^\s*//; 2404a21217daSRandy Dunlap $descr =~ s/\s*$//; 240512ae6779SDaniel Santos $descr =~ s/\s+/ /g; 2406a21217daSRandy Dunlap $declaration_purpose = xml_escape($descr); 24076423133bSJohannes Weiner $in_purpose = 1; 24081da177e4SLinus Torvalds } else { 24091da177e4SLinus Torvalds $declaration_purpose = ""; 24101da177e4SLinus Torvalds } 241177cc23b8SRandy Dunlap 241277cc23b8SRandy Dunlap if (($declaration_purpose eq "") && $verbose) { 241377cc23b8SRandy Dunlap print STDERR "Warning(${file}:$.): missing initial short description on line:\n"; 241477cc23b8SRandy Dunlap print STDERR $_; 241577cc23b8SRandy Dunlap ++$warnings; 241677cc23b8SRandy Dunlap } 241777cc23b8SRandy Dunlap 24181da177e4SLinus Torvalds if ($identifier =~ m/^struct/) { 24191da177e4SLinus Torvalds $decl_type = 'struct'; 24201da177e4SLinus Torvalds } elsif ($identifier =~ m/^union/) { 24211da177e4SLinus Torvalds $decl_type = 'union'; 24221da177e4SLinus Torvalds } elsif ($identifier =~ m/^enum/) { 24231da177e4SLinus Torvalds $decl_type = 'enum'; 24241da177e4SLinus Torvalds } elsif ($identifier =~ m/^typedef/) { 24251da177e4SLinus Torvalds $decl_type = 'typedef'; 24261da177e4SLinus Torvalds } else { 24271da177e4SLinus Torvalds $decl_type = 'function'; 24281da177e4SLinus Torvalds } 24291da177e4SLinus Torvalds 24301da177e4SLinus Torvalds if ($verbose) { 24311da177e4SLinus Torvalds print STDERR "Info(${file}:$.): Scanning doc for $identifier\n"; 24321da177e4SLinus Torvalds } 24331da177e4SLinus Torvalds } else { 24341da177e4SLinus Torvalds print STDERR "Warning(${file}:$.): Cannot understand $_ on line $.", 24351da177e4SLinus Torvalds " - I thought it was a doc line\n"; 24361da177e4SLinus Torvalds ++$warnings; 24371da177e4SLinus Torvalds $state = 0; 24381da177e4SLinus Torvalds } 24391da177e4SLinus Torvalds } elsif ($state == 2) { # look for head: lines, and include content 24401da177e4SLinus Torvalds if (/$doc_sect/o) { 24411da177e4SLinus Torvalds $newsection = $1; 24421da177e4SLinus Torvalds $newcontents = $2; 24431da177e4SLinus Torvalds 2444792aa2f2SRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 2445850622dfSRandy Dunlap if (!$in_doc_sect && $verbose) { 2446850622dfSRandy Dunlap print STDERR "Warning(${file}:$.): contents before sections\n"; 2447850622dfSRandy Dunlap ++$warnings; 2448850622dfSRandy Dunlap } 244994dc7ad5SRandy Dunlap dump_section($file, $section, xml_escape($contents)); 24501da177e4SLinus Torvalds $section = $section_default; 24511da177e4SLinus Torvalds } 24521da177e4SLinus Torvalds 2453850622dfSRandy Dunlap $in_doc_sect = 1; 24546423133bSJohannes Weiner $in_purpose = 0; 24551da177e4SLinus Torvalds $contents = $newcontents; 24561da177e4SLinus Torvalds if ($contents ne "") { 245727205744SRandy Dunlap while ((substr($contents, 0, 1) eq " ") || 245827205744SRandy Dunlap substr($contents, 0, 1) eq "\t") { 245905189497SRandy Dunlap $contents = substr($contents, 1); 246005189497SRandy Dunlap } 24611da177e4SLinus Torvalds $contents .= "\n"; 24621da177e4SLinus Torvalds } 24631da177e4SLinus Torvalds $section = $newsection; 24641da177e4SLinus Torvalds } elsif (/$doc_end/) { 24651da177e4SLinus Torvalds 24664c98ecafSRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 246794dc7ad5SRandy Dunlap dump_section($file, $section, xml_escape($contents)); 24681da177e4SLinus Torvalds $section = $section_default; 24691da177e4SLinus Torvalds $contents = ""; 24701da177e4SLinus Torvalds } 247146b958ebSRandy Dunlap # look for doc_com + <text> + doc_end: 247246b958ebSRandy Dunlap if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') { 247346b958ebSRandy Dunlap print STDERR "Warning(${file}:$.): suspicious ending line: $_"; 247446b958ebSRandy Dunlap ++$warnings; 247546b958ebSRandy Dunlap } 24761da177e4SLinus Torvalds 24771da177e4SLinus Torvalds $prototype = ""; 24781da177e4SLinus Torvalds $state = 3; 24791da177e4SLinus Torvalds $brcount = 0; 24801da177e4SLinus Torvalds# print STDERR "end of doc comment, looking for prototype\n"; 24811da177e4SLinus Torvalds } elsif (/$doc_content/) { 24821da177e4SLinus Torvalds # miguel-style comment kludge, look for blank lines after 24831da177e4SLinus Torvalds # @parameter line to signify start of description 24846423133bSJohannes Weiner if ($1 eq "") { 24856423133bSJohannes Weiner if ($section =~ m/^@/ || $section eq $section_context) { 248694dc7ad5SRandy Dunlap dump_section($file, $section, xml_escape($contents)); 24871da177e4SLinus Torvalds $section = $section_default; 24881da177e4SLinus Torvalds $contents = ""; 24891da177e4SLinus Torvalds } else { 24906423133bSJohannes Weiner $contents .= "\n"; 24916423133bSJohannes Weiner } 24926423133bSJohannes Weiner $in_purpose = 0; 24936423133bSJohannes Weiner } elsif ($in_purpose == 1) { 24946423133bSJohannes Weiner # Continued declaration purpose 24956423133bSJohannes Weiner chomp($declaration_purpose); 24966423133bSJohannes Weiner $declaration_purpose .= " " . xml_escape($1); 249712ae6779SDaniel Santos $declaration_purpose =~ s/\s+/ /g; 24986423133bSJohannes Weiner } else { 24991da177e4SLinus Torvalds $contents .= $1 . "\n"; 25001da177e4SLinus Torvalds } 25011da177e4SLinus Torvalds } else { 25021da177e4SLinus Torvalds # i dont know - bad line? ignore. 25031da177e4SLinus Torvalds print STDERR "Warning(${file}:$.): bad line: $_"; 25041da177e4SLinus Torvalds ++$warnings; 25051da177e4SLinus Torvalds } 2506232acbcfSRandy Dunlap } elsif ($state == 3) { # scanning for function '{' (end of prototype) 25071da177e4SLinus Torvalds if ($decl_type eq 'function') { 25081da177e4SLinus Torvalds process_state3_function($_, $file); 25091da177e4SLinus Torvalds } else { 25101da177e4SLinus Torvalds process_state3_type($_, $file); 25111da177e4SLinus Torvalds } 25121da177e4SLinus Torvalds } elsif ($state == 4) { 25131da177e4SLinus Torvalds # Documentation block 25141da177e4SLinus Torvalds if (/$doc_block/) { 251594dc7ad5SRandy Dunlap dump_doc_section($file, $section, xml_escape($contents)); 25161da177e4SLinus Torvalds $contents = ""; 25171da177e4SLinus Torvalds $function = ""; 25181da177e4SLinus Torvalds %constants = (); 25191da177e4SLinus Torvalds %parameterdescs = (); 25201da177e4SLinus Torvalds %parametertypes = (); 25211da177e4SLinus Torvalds @parameterlist = (); 25221da177e4SLinus Torvalds %sections = (); 25231da177e4SLinus Torvalds @sectionlist = (); 25241da177e4SLinus Torvalds $prototype = ""; 25251da177e4SLinus Torvalds if ( $1 eq "" ) { 25261da177e4SLinus Torvalds $section = $section_intro; 25271da177e4SLinus Torvalds } else { 25281da177e4SLinus Torvalds $section = $1; 25291da177e4SLinus Torvalds } 25301da177e4SLinus Torvalds } 25311da177e4SLinus Torvalds elsif (/$doc_end/) 25321da177e4SLinus Torvalds { 253394dc7ad5SRandy Dunlap dump_doc_section($file, $section, xml_escape($contents)); 25341da177e4SLinus Torvalds $contents = ""; 25351da177e4SLinus Torvalds $function = ""; 25361da177e4SLinus Torvalds %constants = (); 25371da177e4SLinus Torvalds %parameterdescs = (); 25381da177e4SLinus Torvalds %parametertypes = (); 25391da177e4SLinus Torvalds @parameterlist = (); 25401da177e4SLinus Torvalds %sections = (); 25411da177e4SLinus Torvalds @sectionlist = (); 25421da177e4SLinus Torvalds $prototype = ""; 25431da177e4SLinus Torvalds $state = 0; 25441da177e4SLinus Torvalds } 25451da177e4SLinus Torvalds elsif (/$doc_content/) 25461da177e4SLinus Torvalds { 25471da177e4SLinus Torvalds if ( $1 eq "" ) 25481da177e4SLinus Torvalds { 25491da177e4SLinus Torvalds $contents .= $blankline; 25501da177e4SLinus Torvalds } 25511da177e4SLinus Torvalds else 25521da177e4SLinus Torvalds { 25531da177e4SLinus Torvalds $contents .= $1 . "\n"; 25541da177e4SLinus Torvalds } 25551da177e4SLinus Torvalds } 25561da177e4SLinus Torvalds } 25571da177e4SLinus Torvalds } 25581da177e4SLinus Torvalds if ($initial_section_counter == $section_counter) { 25591da177e4SLinus Torvalds print STDERR "Warning(${file}): no structured comments found\n"; 2560e946c43aSJohannes Berg if (($function_only == 1) && ($show_not_found == 1)) { 2561e946c43aSJohannes Berg print STDERR " Was looking for '$_'.\n" for keys %function_table; 2562e946c43aSJohannes Berg } 25631da177e4SLinus Torvalds if ($output_mode eq "xml") { 25641da177e4SLinus Torvalds # The template wants at least one RefEntry here; make one. 25651da177e4SLinus Torvalds print "<refentry>\n"; 25661da177e4SLinus Torvalds print " <refnamediv>\n"; 25671da177e4SLinus Torvalds print " <refname>\n"; 25681da177e4SLinus Torvalds print " ${file}\n"; 25691da177e4SLinus Torvalds print " </refname>\n"; 25701da177e4SLinus Torvalds print " <refpurpose>\n"; 25711da177e4SLinus Torvalds print " Document generation inconsistency\n"; 25721da177e4SLinus Torvalds print " </refpurpose>\n"; 25731da177e4SLinus Torvalds print " </refnamediv>\n"; 25741da177e4SLinus Torvalds print " <refsect1>\n"; 25751da177e4SLinus Torvalds print " <title>\n"; 25761da177e4SLinus Torvalds print " Oops\n"; 25771da177e4SLinus Torvalds print " </title>\n"; 25781da177e4SLinus Torvalds print " <warning>\n"; 25791da177e4SLinus Torvalds print " <para>\n"; 25801da177e4SLinus Torvalds print " The template for this document tried to insert\n"; 25811da177e4SLinus Torvalds print " the structured comment from the file\n"; 25821da177e4SLinus Torvalds print " <filename>${file}</filename> at this point,\n"; 25831da177e4SLinus Torvalds print " but none was found.\n"; 25841da177e4SLinus Torvalds print " This dummy section is inserted to allow\n"; 25851da177e4SLinus Torvalds print " generation to continue.\n"; 25861da177e4SLinus Torvalds print " </para>\n"; 25871da177e4SLinus Torvalds print " </warning>\n"; 25881da177e4SLinus Torvalds print " </refsect1>\n"; 25891da177e4SLinus Torvalds print "</refentry>\n"; 25901da177e4SLinus Torvalds } 25911da177e4SLinus Torvalds } 25921da177e4SLinus Torvalds} 25938484baaaSRandy Dunlap 25948484baaaSRandy Dunlap 25958484baaaSRandy Dunlap$kernelversion = get_kernel_version(); 25968484baaaSRandy Dunlap 25978484baaaSRandy Dunlap# generate a sequence of code that will splice in highlighting information 25988484baaaSRandy Dunlap# using the s// operator. 25992e106e4dSJérémy Bobbioforeach my $pattern (sort keys %highlights) { 26008484baaaSRandy Dunlap# print STDERR "scanning pattern:$pattern, highlight:($highlights{$pattern})\n"; 26018484baaaSRandy Dunlap $dohighlight .= "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n"; 26028484baaaSRandy Dunlap} 26038484baaaSRandy Dunlap 26048484baaaSRandy Dunlap# Read the file that maps relative names to absolute names for 26058484baaaSRandy Dunlap# separate source and object directories and for shadow trees. 26068484baaaSRandy Dunlapif (open(SOURCE_MAP, "<.tmp_filelist.txt")) { 26078484baaaSRandy Dunlap my ($relname, $absname); 26088484baaaSRandy Dunlap while(<SOURCE_MAP>) { 26098484baaaSRandy Dunlap chop(); 26108484baaaSRandy Dunlap ($relname, $absname) = (split())[0..1]; 26118484baaaSRandy Dunlap $relname =~ s:^/+::; 26128484baaaSRandy Dunlap $source_map{$relname} = $absname; 26138484baaaSRandy Dunlap } 26148484baaaSRandy Dunlap close(SOURCE_MAP); 26158484baaaSRandy Dunlap} 26168484baaaSRandy Dunlap 26178484baaaSRandy Dunlapforeach (@ARGV) { 26188484baaaSRandy Dunlap chomp; 26198484baaaSRandy Dunlap process_file($_); 26208484baaaSRandy Dunlap} 26218484baaaSRandy Dunlapif ($verbose && $errors) { 26228484baaaSRandy Dunlap print STDERR "$errors errors\n"; 26238484baaaSRandy Dunlap} 26248484baaaSRandy Dunlapif ($verbose && $warnings) { 26258484baaaSRandy Dunlap print STDERR "$warnings warnings\n"; 26268484baaaSRandy Dunlap} 26278484baaaSRandy Dunlap 26288484baaaSRandy Dunlapexit($errors); 2629