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; 2561da177e4SLinus Torvaldsmy $man_date = ('January', 'February', 'March', 'April', 'May', 'June', 2571da177e4SLinus Torvalds 'July', 'August', 'September', 'October', 2581da177e4SLinus Torvalds 'November', 'December')[(localtime)[4]] . 2591da177e4SLinus Torvalds " " . ((localtime)[5]+1900); 260e946c43aSJohannes Bergmy $show_not_found = 0; 2611da177e4SLinus Torvalds 2628484baaaSRandy Dunlap# Essentially these are globals. 263b9d97328SRandy Dunlap# They probably want to be tidied up, made more localised or something. 264b9d97328SRandy Dunlap# CAVEAT EMPTOR! Some of the others I localised may not want to be, which 2651da177e4SLinus Torvalds# could cause "use of undefined value" or other bugs. 2661da177e4SLinus Torvaldsmy ($function, %function_table, %parametertypes, $declaration_purpose); 2671da177e4SLinus Torvaldsmy ($type, $declaration_name, $return_type); 2681c32fd0cSIlya Dryomovmy ($newsection, $newcontents, $prototype, $brcount, %source_map); 2691da177e4SLinus Torvalds 270bd0e88e5SRandy Dunlapif (defined($ENV{'KBUILD_VERBOSE'})) { 271bd0e88e5SRandy Dunlap $verbose = "$ENV{'KBUILD_VERBOSE'}"; 272bd0e88e5SRandy Dunlap} 273bd0e88e5SRandy Dunlap 2741da177e4SLinus Torvalds# Generated docbook code is inserted in a template at a point where 2751da177e4SLinus Torvalds# docbook v3.1 requires a non-zero sequence of RefEntry's; see: 2761da177e4SLinus Torvalds# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html 2771da177e4SLinus Torvalds# We keep track of number of generated entries and generate a dummy 2781da177e4SLinus Torvalds# if needs be to ensure the expanded template can be postprocessed 2791da177e4SLinus Torvalds# into html. 2801da177e4SLinus Torvaldsmy $section_counter = 0; 2811da177e4SLinus Torvalds 2821da177e4SLinus Torvaldsmy $lineprefix=""; 2831da177e4SLinus Torvalds 2841da177e4SLinus Torvalds# states 2851da177e4SLinus Torvalds# 0 - normal code 2861da177e4SLinus Torvalds# 1 - looking for function name 2871da177e4SLinus Torvalds# 2 - scanning field start. 2881da177e4SLinus Torvalds# 3 - scanning prototype. 2891da177e4SLinus Torvalds# 4 - documentation block 2901da177e4SLinus Torvaldsmy $state; 291850622dfSRandy Dunlapmy $in_doc_sect; 2921da177e4SLinus Torvalds 2931da177e4SLinus Torvalds#declaration types: can be 2941da177e4SLinus Torvalds# 'function', 'struct', 'union', 'enum', 'typedef' 2951da177e4SLinus Torvaldsmy $decl_type; 2961da177e4SLinus Torvalds 2971da177e4SLinus Torvaldsmy $doc_special = "\@\%\$\&"; 2981da177e4SLinus Torvalds 2991da177e4SLinus Torvaldsmy $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start. 3001da177e4SLinus Torvaldsmy $doc_end = '\*/'; 3011da177e4SLinus Torvaldsmy $doc_com = '\s*\*\s*'; 30212ae6779SDaniel Santosmy $doc_com_body = '\s*\* ?'; 3031da177e4SLinus Torvaldsmy $doc_decl = $doc_com . '(\w+)'; 304891dcd2fSRandy Dunlapmy $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)'; 30512ae6779SDaniel Santosmy $doc_content = $doc_com_body . '(.*)'; 3061da177e4SLinus Torvaldsmy $doc_block = $doc_com . 'DOC:\s*(.*)?'; 3071da177e4SLinus Torvalds 3081da177e4SLinus Torvaldsmy %constants; 3091da177e4SLinus Torvaldsmy %parameterdescs; 3101da177e4SLinus Torvaldsmy @parameterlist; 3111da177e4SLinus Torvaldsmy %sections; 3121da177e4SLinus Torvaldsmy @sectionlist; 313a1d94aa5SRandy Dunlapmy $sectcheck; 314a1d94aa5SRandy Dunlapmy $struct_actual; 3151da177e4SLinus Torvalds 3161da177e4SLinus Torvaldsmy $contents = ""; 3171da177e4SLinus Torvaldsmy $section_default = "Description"; # default section 3181da177e4SLinus Torvaldsmy $section_intro = "Introduction"; 3191da177e4SLinus Torvaldsmy $section = $section_default; 3201da177e4SLinus Torvaldsmy $section_context = "Context"; 3214092bac7SYacine Belkadimy $section_return = "Return"; 3221da177e4SLinus Torvalds 3231da177e4SLinus Torvaldsmy $undescribed = "-- undescribed --"; 3241da177e4SLinus Torvalds 3251da177e4SLinus Torvaldsreset_state(); 3261da177e4SLinus Torvalds 3271da177e4SLinus Torvaldswhile ($ARGV[0] =~ m/^-(.*)/) { 3281da177e4SLinus Torvalds my $cmd = shift @ARGV; 3291da177e4SLinus Torvalds if ($cmd eq "-html") { 3301da177e4SLinus Torvalds $output_mode = "html"; 3311da177e4SLinus Torvalds %highlights = %highlights_html; 3321da177e4SLinus Torvalds $blankline = $blankline_html; 3331b40c194SDan Luedtke } elsif ($cmd eq "-html5") { 3341b40c194SDan Luedtke $output_mode = "html5"; 3351b40c194SDan Luedtke %highlights = %highlights_html5; 3361b40c194SDan Luedtke $blankline = $blankline_html5; 3371da177e4SLinus Torvalds } elsif ($cmd eq "-man") { 3381da177e4SLinus Torvalds $output_mode = "man"; 3391da177e4SLinus Torvalds %highlights = %highlights_man; 3401da177e4SLinus Torvalds $blankline = $blankline_man; 3411da177e4SLinus Torvalds } elsif ($cmd eq "-text") { 3421da177e4SLinus Torvalds $output_mode = "text"; 3431da177e4SLinus Torvalds %highlights = %highlights_text; 3441da177e4SLinus Torvalds $blankline = $blankline_text; 3451da177e4SLinus Torvalds } elsif ($cmd eq "-docbook") { 3461da177e4SLinus Torvalds $output_mode = "xml"; 3471da177e4SLinus Torvalds %highlights = %highlights_xml; 3481da177e4SLinus Torvalds $blankline = $blankline_xml; 349eda603f6SJohannes Berg } elsif ($cmd eq "-list") { 350eda603f6SJohannes Berg $output_mode = "list"; 351eda603f6SJohannes Berg %highlights = %highlights_list; 352eda603f6SJohannes Berg $blankline = $blankline_list; 3531da177e4SLinus Torvalds } elsif ($cmd eq "-gnome") { 3541da177e4SLinus Torvalds $output_mode = "gnome"; 3551da177e4SLinus Torvalds %highlights = %highlights_gnome; 3561da177e4SLinus Torvalds $blankline = $blankline_gnome; 3571da177e4SLinus Torvalds } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document 3581da177e4SLinus Torvalds $modulename = shift @ARGV; 3591da177e4SLinus Torvalds } elsif ($cmd eq "-function") { # to only output specific functions 3601da177e4SLinus Torvalds $function_only = 1; 3611da177e4SLinus Torvalds $function = shift @ARGV; 3621da177e4SLinus Torvalds $function_table{$function} = 1; 3631da177e4SLinus Torvalds } elsif ($cmd eq "-nofunction") { # to only output specific functions 3641da177e4SLinus Torvalds $function_only = 2; 3651da177e4SLinus Torvalds $function = shift @ARGV; 3661da177e4SLinus Torvalds $function_table{$function} = 1; 3671da177e4SLinus Torvalds } elsif ($cmd eq "-v") { 3681da177e4SLinus Torvalds $verbose = 1; 3691da177e4SLinus Torvalds } elsif (($cmd eq "-h") || ($cmd eq "--help")) { 3701da177e4SLinus Torvalds usage(); 3714b44595aSJohannes Berg } elsif ($cmd eq '-no-doc-sections') { 3724b44595aSJohannes Berg $no_doc_sections = 1; 373e946c43aSJohannes Berg } elsif ($cmd eq '-show-not-found') { 374e946c43aSJohannes Berg $show_not_found = 1; 3751da177e4SLinus Torvalds } 3761da177e4SLinus Torvalds} 3771da177e4SLinus Torvalds 3788484baaaSRandy Dunlap# continue execution near EOF; 3798484baaaSRandy Dunlap 3808484baaaSRandy Dunlapsub usage { 3811b40c194SDan Luedtke print "Usage: $0 [ -docbook | -html | -html5 | -text | -man | -list ]\n"; 3828484baaaSRandy Dunlap print " [ -no-doc-sections ]\n"; 3838484baaaSRandy Dunlap print " [ -function funcname [ -function funcname ...] ]\n"; 3848484baaaSRandy Dunlap print " [ -nofunction funcname [ -nofunction funcname ...] ]\n"; 3851b40c194SDan Luedtke print " [ -v ]\n"; 3868484baaaSRandy Dunlap print " c source file(s) > outputfile\n"; 3878484baaaSRandy Dunlap print " -v : verbose output, more warnings & other info listed\n"; 3888484baaaSRandy Dunlap exit 1; 3898484baaaSRandy Dunlap} 3908484baaaSRandy Dunlap 39153f049faSBorislav Petkov# get kernel version from env 39253f049faSBorislav Petkovsub get_kernel_version() { 3931b9bc22dSJohannes Berg my $version = 'unknown kernel version'; 39453f049faSBorislav Petkov 39553f049faSBorislav Petkov if (defined($ENV{'KERNELVERSION'})) { 39653f049faSBorislav Petkov $version = $ENV{'KERNELVERSION'}; 39753f049faSBorislav Petkov } 39853f049faSBorislav Petkov return $version; 39953f049faSBorislav Petkov} 4001da177e4SLinus Torvalds 4011da177e4SLinus Torvalds## 4021da177e4SLinus Torvalds# dumps section contents to arrays/hashes intended for that purpose. 4031da177e4SLinus Torvalds# 4041da177e4SLinus Torvaldssub dump_section { 40594dc7ad5SRandy Dunlap my $file = shift; 4061da177e4SLinus Torvalds my $name = shift; 4071da177e4SLinus Torvalds my $contents = join "\n", @_; 4081da177e4SLinus Torvalds 4091da177e4SLinus Torvalds if ($name =~ m/$type_constant/) { 4101da177e4SLinus Torvalds $name = $1; 4111da177e4SLinus Torvalds# print STDERR "constant section '$1' = '$contents'\n"; 4121da177e4SLinus Torvalds $constants{$name} = $contents; 4131da177e4SLinus Torvalds } elsif ($name =~ m/$type_param/) { 4141da177e4SLinus Torvalds# print STDERR "parameter def '$1' = '$contents'\n"; 4151da177e4SLinus Torvalds $name = $1; 4161da177e4SLinus Torvalds $parameterdescs{$name} = $contents; 417a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 418ced69090SRandy Dunlap } elsif ($name eq "@\.\.\.") { 419ced69090SRandy Dunlap# print STDERR "parameter def '...' = '$contents'\n"; 420ced69090SRandy Dunlap $name = "..."; 421ced69090SRandy Dunlap $parameterdescs{$name} = $contents; 422a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 4231da177e4SLinus Torvalds } else { 4241da177e4SLinus Torvalds# print STDERR "other section '$name' = '$contents'\n"; 42594dc7ad5SRandy Dunlap if (defined($sections{$name}) && ($sections{$name} ne "")) { 42694dc7ad5SRandy Dunlap print STDERR "Error(${file}:$.): duplicate section name '$name'\n"; 42794dc7ad5SRandy Dunlap ++$errors; 42894dc7ad5SRandy Dunlap } 4291da177e4SLinus Torvalds $sections{$name} = $contents; 4301da177e4SLinus Torvalds push @sectionlist, $name; 4311da177e4SLinus Torvalds } 4321da177e4SLinus Torvalds} 4331da177e4SLinus Torvalds 4341da177e4SLinus Torvalds## 435b112e0f7SJohannes Berg# dump DOC: section after checking that it should go out 436b112e0f7SJohannes Berg# 437b112e0f7SJohannes Bergsub dump_doc_section { 43894dc7ad5SRandy Dunlap my $file = shift; 439b112e0f7SJohannes Berg my $name = shift; 440b112e0f7SJohannes Berg my $contents = join "\n", @_; 441b112e0f7SJohannes Berg 4424b44595aSJohannes Berg if ($no_doc_sections) { 4434b44595aSJohannes Berg return; 4444b44595aSJohannes Berg } 4454b44595aSJohannes Berg 446b112e0f7SJohannes Berg if (($function_only == 0) || 447b112e0f7SJohannes Berg ( $function_only == 1 && defined($function_table{$name})) || 448b112e0f7SJohannes Berg ( $function_only == 2 && !defined($function_table{$name}))) 449b112e0f7SJohannes Berg { 45094dc7ad5SRandy Dunlap dump_section($file, $name, $contents); 451b112e0f7SJohannes Berg output_blockhead({'sectionlist' => \@sectionlist, 452b112e0f7SJohannes Berg 'sections' => \%sections, 453b112e0f7SJohannes Berg 'module' => $modulename, 454b112e0f7SJohannes Berg 'content-only' => ($function_only != 0), }); 455b112e0f7SJohannes Berg } 456b112e0f7SJohannes Berg} 457b112e0f7SJohannes Berg 458b112e0f7SJohannes Berg## 4591da177e4SLinus Torvalds# output function 4601da177e4SLinus Torvalds# 4611da177e4SLinus Torvalds# parameterdescs, a hash. 4621da177e4SLinus Torvalds# function => "function name" 4631da177e4SLinus Torvalds# parameterlist => @list of parameters 4641da177e4SLinus Torvalds# parameterdescs => %parameter descriptions 4651da177e4SLinus Torvalds# sectionlist => @list of sections 466a21217daSRandy Dunlap# sections => %section descriptions 4671da177e4SLinus Torvalds# 4681da177e4SLinus Torvalds 4691da177e4SLinus Torvaldssub output_highlight { 4701da177e4SLinus Torvalds my $contents = join "\n",@_; 4711da177e4SLinus Torvalds my $line; 4721da177e4SLinus Torvalds 4731da177e4SLinus Torvalds# DEBUG 4741da177e4SLinus Torvalds# if (!defined $contents) { 4751da177e4SLinus Torvalds# use Carp; 4761da177e4SLinus Torvalds# confess "output_highlight got called with no args?\n"; 4771da177e4SLinus Torvalds# } 4781da177e4SLinus Torvalds 4791b40c194SDan Luedtke if ($output_mode eq "html" || $output_mode eq "html5" || 4801b40c194SDan Luedtke $output_mode eq "xml") { 4816b5b55f6SRandy Dunlap $contents = local_unescape($contents); 4826b5b55f6SRandy Dunlap # convert data read & converted thru xml_escape() into &xyz; format: 4832b35f4d9SRandy Dunlap $contents =~ s/\\\\\\/\&/g; 4846b5b55f6SRandy Dunlap } 4853eb014a1SRandy Dunlap# print STDERR "contents b4:$contents\n"; 4861da177e4SLinus Torvalds eval $dohighlight; 4871da177e4SLinus Torvalds die $@ if $@; 4883eb014a1SRandy Dunlap# print STDERR "contents af:$contents\n"; 4893eb014a1SRandy Dunlap 4901b40c194SDan Luedtke# strip whitespaces when generating html5 4911b40c194SDan Luedtke if ($output_mode eq "html5") { 4921b40c194SDan Luedtke $contents =~ s/^\s+//; 4931b40c194SDan Luedtke $contents =~ s/\s+$//; 4941b40c194SDan Luedtke } 4951da177e4SLinus Torvalds foreach $line (split "\n", $contents) { 49612ae6779SDaniel Santos if (! $output_preformatted) { 49712ae6779SDaniel Santos $line =~ s/^\s*//; 49812ae6779SDaniel Santos } 4991da177e4SLinus Torvalds if ($line eq ""){ 500e314ba31SDaniel Santos if (! $output_preformatted) { 5016b5b55f6SRandy Dunlap print $lineprefix, local_unescape($blankline); 502e314ba31SDaniel Santos } 5031da177e4SLinus Torvalds } else { 5041da177e4SLinus Torvalds $line =~ s/\\\\\\/\&/g; 505cdccb316SRandy Dunlap if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { 506cdccb316SRandy Dunlap print "\\&$line"; 507cdccb316SRandy Dunlap } else { 5081da177e4SLinus Torvalds print $lineprefix, $line; 5091da177e4SLinus Torvalds } 510cdccb316SRandy Dunlap } 5111da177e4SLinus Torvalds print "\n"; 5121da177e4SLinus Torvalds } 5131da177e4SLinus Torvalds} 5141da177e4SLinus Torvalds 5151da177e4SLinus Torvalds# output sections in html 5161da177e4SLinus Torvaldssub output_section_html(%) { 5171da177e4SLinus Torvalds my %args = %{$_[0]}; 5181da177e4SLinus Torvalds my $section; 5191da177e4SLinus Torvalds 5201da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 5211da177e4SLinus Torvalds print "<h3>$section</h3>\n"; 5221da177e4SLinus Torvalds print "<blockquote>\n"; 5231da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 5241da177e4SLinus Torvalds print "</blockquote>\n"; 5251da177e4SLinus Torvalds } 5261da177e4SLinus Torvalds} 5271da177e4SLinus Torvalds 5281da177e4SLinus Torvalds# output enum in html 5291da177e4SLinus Torvaldssub output_enum_html(%) { 5301da177e4SLinus Torvalds my %args = %{$_[0]}; 5311da177e4SLinus Torvalds my ($parameter); 5321da177e4SLinus Torvalds my $count; 5331da177e4SLinus Torvalds print "<h2>enum " . $args{'enum'} . "</h2>\n"; 5341da177e4SLinus Torvalds 5351da177e4SLinus Torvalds print "<b>enum " . $args{'enum'} . "</b> {<br>\n"; 5361da177e4SLinus Torvalds $count = 0; 5371da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 5381da177e4SLinus Torvalds print " <b>" . $parameter . "</b>"; 5391da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 5401da177e4SLinus Torvalds $count++; 5411da177e4SLinus Torvalds print ",\n"; 5421da177e4SLinus Torvalds } 5431da177e4SLinus Torvalds print "<br>"; 5441da177e4SLinus Torvalds } 5451da177e4SLinus Torvalds print "};<br>\n"; 5461da177e4SLinus Torvalds 5471da177e4SLinus Torvalds print "<h3>Constants</h3>\n"; 5481da177e4SLinus Torvalds print "<dl>\n"; 5491da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 5501da177e4SLinus Torvalds print "<dt><b>" . $parameter . "</b>\n"; 5511da177e4SLinus Torvalds print "<dd>"; 5521da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter}); 5531da177e4SLinus Torvalds } 5541da177e4SLinus Torvalds print "</dl>\n"; 5551da177e4SLinus Torvalds output_section_html(@_); 5561da177e4SLinus Torvalds print "<hr>\n"; 5571da177e4SLinus Torvalds} 5581da177e4SLinus Torvalds 559d28bee0cSRandy Dunlap# output typedef in html 5601da177e4SLinus Torvaldssub output_typedef_html(%) { 5611da177e4SLinus Torvalds my %args = %{$_[0]}; 5621da177e4SLinus Torvalds my ($parameter); 5631da177e4SLinus Torvalds my $count; 5641da177e4SLinus Torvalds print "<h2>typedef " . $args{'typedef'} . "</h2>\n"; 5651da177e4SLinus Torvalds 5661da177e4SLinus Torvalds print "<b>typedef " . $args{'typedef'} . "</b>\n"; 5671da177e4SLinus Torvalds output_section_html(@_); 5681da177e4SLinus Torvalds print "<hr>\n"; 5691da177e4SLinus Torvalds} 5701da177e4SLinus Torvalds 5711da177e4SLinus Torvalds# output struct in html 5721da177e4SLinus Torvaldssub output_struct_html(%) { 5731da177e4SLinus Torvalds my %args = %{$_[0]}; 5741da177e4SLinus Torvalds my ($parameter); 5751da177e4SLinus Torvalds 576262d9b01SRandy Dunlap print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n"; 5771da177e4SLinus Torvalds print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n"; 5781da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 5791da177e4SLinus Torvalds if ($parameter =~ /^#/) { 5801da177e4SLinus Torvalds print "$parameter<br>\n"; 5811da177e4SLinus Torvalds next; 5821da177e4SLinus Torvalds } 5831da177e4SLinus Torvalds my $parameter_name = $parameter; 5841da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 5851da177e4SLinus Torvalds 5861da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 5871da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 5881da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 5891da177e4SLinus Torvalds # pointer-to-function 5903eb014a1SRandy Dunlap print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n"; 5911da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 5923eb014a1SRandy Dunlap # bitfield 5933eb014a1SRandy Dunlap print " <i>$1</i> <b>$parameter</b>$2;<br>\n"; 5941da177e4SLinus Torvalds } else { 5953eb014a1SRandy Dunlap print " <i>$type</i> <b>$parameter</b>;<br>\n"; 5961da177e4SLinus Torvalds } 5971da177e4SLinus Torvalds } 5981da177e4SLinus Torvalds print "};<br>\n"; 5991da177e4SLinus Torvalds 6001da177e4SLinus Torvalds print "<h3>Members</h3>\n"; 6011da177e4SLinus Torvalds print "<dl>\n"; 6021da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6031da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 6041da177e4SLinus Torvalds 6051da177e4SLinus Torvalds my $parameter_name = $parameter; 6061da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 6071da177e4SLinus Torvalds 6081da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 6091da177e4SLinus Torvalds print "<dt><b>" . $parameter . "</b>\n"; 6101da177e4SLinus Torvalds print "<dd>"; 6111da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 6121da177e4SLinus Torvalds } 6131da177e4SLinus Torvalds print "</dl>\n"; 6141da177e4SLinus Torvalds output_section_html(@_); 6151da177e4SLinus Torvalds print "<hr>\n"; 6161da177e4SLinus Torvalds} 6171da177e4SLinus Torvalds 6181da177e4SLinus Torvalds# output function in html 6191da177e4SLinus Torvaldssub output_function_html(%) { 6201da177e4SLinus Torvalds my %args = %{$_[0]}; 6211da177e4SLinus Torvalds my ($parameter, $section); 6221da177e4SLinus Torvalds my $count; 6231da177e4SLinus Torvalds 624262d9b01SRandy Dunlap print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n"; 6251da177e4SLinus Torvalds print "<i>" . $args{'functiontype'} . "</i>\n"; 6261da177e4SLinus Torvalds print "<b>" . $args{'function'} . "</b>\n"; 6271da177e4SLinus Torvalds print "("; 6281da177e4SLinus Torvalds $count = 0; 6291da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6301da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 6311da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 6321da177e4SLinus Torvalds # pointer-to-function 6331da177e4SLinus Torvalds print "<i>$1</i><b>$parameter</b>) <i>($2)</i>"; 6341da177e4SLinus Torvalds } else { 6351da177e4SLinus Torvalds print "<i>" . $type . "</i> <b>" . $parameter . "</b>"; 6361da177e4SLinus Torvalds } 6371da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 6381da177e4SLinus Torvalds $count++; 6391da177e4SLinus Torvalds print ",\n"; 6401da177e4SLinus Torvalds } 6411da177e4SLinus Torvalds } 6421da177e4SLinus Torvalds print ")\n"; 6431da177e4SLinus Torvalds 6441da177e4SLinus Torvalds print "<h3>Arguments</h3>\n"; 6451da177e4SLinus Torvalds print "<dl>\n"; 6461da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6471da177e4SLinus Torvalds my $parameter_name = $parameter; 6481da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 6491da177e4SLinus Torvalds 6501da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 6511da177e4SLinus Torvalds print "<dt><b>" . $parameter . "</b>\n"; 6521da177e4SLinus Torvalds print "<dd>"; 6531da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 6541da177e4SLinus Torvalds } 6551da177e4SLinus Torvalds print "</dl>\n"; 6561da177e4SLinus Torvalds output_section_html(@_); 6571da177e4SLinus Torvalds print "<hr>\n"; 6581da177e4SLinus Torvalds} 6591da177e4SLinus Torvalds 660b112e0f7SJohannes Berg# output DOC: block header in html 661b112e0f7SJohannes Bergsub output_blockhead_html(%) { 6621da177e4SLinus Torvalds my %args = %{$_[0]}; 6631da177e4SLinus Torvalds my ($parameter, $section); 6641da177e4SLinus Torvalds my $count; 6651da177e4SLinus Torvalds 6661da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 6671da177e4SLinus Torvalds print "<h3>$section</h3>\n"; 6681da177e4SLinus Torvalds print "<ul>\n"; 6691da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 6701da177e4SLinus Torvalds print "</ul>\n"; 6711da177e4SLinus Torvalds } 6721da177e4SLinus Torvalds print "<hr>\n"; 6731da177e4SLinus Torvalds} 6741da177e4SLinus Torvalds 6751b40c194SDan Luedtke# output sections in html5 6761b40c194SDan Luedtkesub output_section_html5(%) { 6771b40c194SDan Luedtke my %args = %{$_[0]}; 6781b40c194SDan Luedtke my $section; 6791b40c194SDan Luedtke 6801b40c194SDan Luedtke foreach $section (@{$args{'sectionlist'}}) { 6811b40c194SDan Luedtke print "<section>\n"; 6821b40c194SDan Luedtke print "<h1>$section</h1>\n"; 6831b40c194SDan Luedtke print "<p>\n"; 6841b40c194SDan Luedtke output_highlight($args{'sections'}{$section}); 6851b40c194SDan Luedtke print "</p>\n"; 6861b40c194SDan Luedtke print "</section>\n"; 6871b40c194SDan Luedtke } 6881b40c194SDan Luedtke} 6891b40c194SDan Luedtke 6901b40c194SDan Luedtke# output enum in html5 6911b40c194SDan Luedtkesub output_enum_html5(%) { 6921b40c194SDan Luedtke my %args = %{$_[0]}; 6931b40c194SDan Luedtke my ($parameter); 6941b40c194SDan Luedtke my $count; 6951b40c194SDan Luedtke my $html5id; 6961b40c194SDan Luedtke 6971b40c194SDan Luedtke $html5id = $args{'enum'}; 6981b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 6991b40c194SDan Luedtke print "<article class=\"enum\" id=\"enum:". $html5id . "\">"; 7001b40c194SDan Luedtke print "<h1>enum " . $args{'enum'} . "</h1>\n"; 7011b40c194SDan Luedtke print "<ol class=\"code\">\n"; 7021b40c194SDan Luedtke print "<li>"; 7031b40c194SDan Luedtke print "<span class=\"keyword\">enum</span> "; 7041b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'enum'} . "</span> {"; 7051b40c194SDan Luedtke print "</li>\n"; 7061b40c194SDan Luedtke $count = 0; 7071b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 7081b40c194SDan Luedtke print "<li class=\"indent\">"; 7091b40c194SDan Luedtke print "<span class=\"param\">" . $parameter . "</span>"; 7101b40c194SDan Luedtke if ($count != $#{$args{'parameterlist'}}) { 7111b40c194SDan Luedtke $count++; 7121b40c194SDan Luedtke print ","; 7131b40c194SDan Luedtke } 7141b40c194SDan Luedtke print "</li>\n"; 7151b40c194SDan Luedtke } 7161b40c194SDan Luedtke print "<li>};</li>\n"; 7171b40c194SDan Luedtke print "</ol>\n"; 7181b40c194SDan Luedtke 7191b40c194SDan Luedtke print "<section>\n"; 7201b40c194SDan Luedtke print "<h1>Constants</h1>\n"; 7211b40c194SDan Luedtke print "<dl>\n"; 7221b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 7231b40c194SDan Luedtke print "<dt>" . $parameter . "</dt>\n"; 7241b40c194SDan Luedtke print "<dd>"; 7251b40c194SDan Luedtke output_highlight($args{'parameterdescs'}{$parameter}); 7261b40c194SDan Luedtke print "</dd>\n"; 7271b40c194SDan Luedtke } 7281b40c194SDan Luedtke print "</dl>\n"; 7291b40c194SDan Luedtke print "</section>\n"; 7301b40c194SDan Luedtke output_section_html5(@_); 7311b40c194SDan Luedtke print "</article>\n"; 7321b40c194SDan Luedtke} 7331b40c194SDan Luedtke 7341b40c194SDan Luedtke# output typedef in html5 7351b40c194SDan Luedtkesub output_typedef_html5(%) { 7361b40c194SDan Luedtke my %args = %{$_[0]}; 7371b40c194SDan Luedtke my ($parameter); 7381b40c194SDan Luedtke my $count; 7391b40c194SDan Luedtke my $html5id; 7401b40c194SDan Luedtke 7411b40c194SDan Luedtke $html5id = $args{'typedef'}; 7421b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 7431b40c194SDan Luedtke print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n"; 7441b40c194SDan Luedtke print "<h1>typedef " . $args{'typedef'} . "</h1>\n"; 7451b40c194SDan Luedtke 7461b40c194SDan Luedtke print "<ol class=\"code\">\n"; 7471b40c194SDan Luedtke print "<li>"; 7481b40c194SDan Luedtke print "<span class=\"keyword\">typedef</span> "; 7491b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'typedef'} . "</span>"; 7501b40c194SDan Luedtke print "</li>\n"; 7511b40c194SDan Luedtke print "</ol>\n"; 7521b40c194SDan Luedtke output_section_html5(@_); 7531b40c194SDan Luedtke print "</article>\n"; 7541b40c194SDan Luedtke} 7551b40c194SDan Luedtke 7561b40c194SDan Luedtke# output struct in html5 7571b40c194SDan Luedtkesub output_struct_html5(%) { 7581b40c194SDan Luedtke my %args = %{$_[0]}; 7591b40c194SDan Luedtke my ($parameter); 7601b40c194SDan Luedtke my $html5id; 7611b40c194SDan Luedtke 7621b40c194SDan Luedtke $html5id = $args{'struct'}; 7631b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 7641b40c194SDan Luedtke print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n"; 7651b40c194SDan Luedtke print "<hgroup>\n"; 7661b40c194SDan Luedtke print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>"; 7671b40c194SDan Luedtke print "<h2>". $args{'purpose'} . "</h2>\n"; 7681b40c194SDan Luedtke print "</hgroup>\n"; 7691b40c194SDan Luedtke print "<ol class=\"code\">\n"; 7701b40c194SDan Luedtke print "<li>"; 7711b40c194SDan Luedtke print "<span class=\"type\">" . $args{'type'} . "</span> "; 7721b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'struct'} . "</span> {"; 7731b40c194SDan Luedtke print "</li>\n"; 7741b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 7751b40c194SDan Luedtke print "<li class=\"indent\">"; 7761b40c194SDan Luedtke if ($parameter =~ /^#/) { 7771b40c194SDan Luedtke print "<span class=\"param\">" . $parameter ."</span>\n"; 7781b40c194SDan Luedtke print "</li>\n"; 7791b40c194SDan Luedtke next; 7801b40c194SDan Luedtke } 7811b40c194SDan Luedtke my $parameter_name = $parameter; 7821b40c194SDan Luedtke $parameter_name =~ s/\[.*//; 7831b40c194SDan Luedtke 7841b40c194SDan Luedtke ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 7851b40c194SDan Luedtke $type = $args{'parametertypes'}{$parameter}; 7861b40c194SDan Luedtke if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 7871b40c194SDan Luedtke # pointer-to-function 7881b40c194SDan Luedtke print "<span class=\"type\">$1</span> "; 7891b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 7901b40c194SDan Luedtke print "<span class=\"type\">)</span> "; 7911b40c194SDan Luedtke print "(<span class=\"args\">$2</span>);"; 7921b40c194SDan Luedtke } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 7931b40c194SDan Luedtke # bitfield 7941b40c194SDan Luedtke print "<span class=\"type\">$1</span> "; 7951b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 7961b40c194SDan Luedtke print "<span class=\"bits\">$2</span>;"; 7971b40c194SDan Luedtke } else { 7981b40c194SDan Luedtke print "<span class=\"type\">$type</span> "; 7991b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>;"; 8001b40c194SDan Luedtke } 8011b40c194SDan Luedtke print "</li>\n"; 8021b40c194SDan Luedtke } 8031b40c194SDan Luedtke print "<li>};</li>\n"; 8041b40c194SDan Luedtke print "</ol>\n"; 8051b40c194SDan Luedtke 8061b40c194SDan Luedtke print "<section>\n"; 8071b40c194SDan Luedtke print "<h1>Members</h1>\n"; 8081b40c194SDan Luedtke print "<dl>\n"; 8091b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 8101b40c194SDan Luedtke ($parameter =~ /^#/) && next; 8111b40c194SDan Luedtke 8121b40c194SDan Luedtke my $parameter_name = $parameter; 8131b40c194SDan Luedtke $parameter_name =~ s/\[.*//; 8141b40c194SDan Luedtke 8151b40c194SDan Luedtke ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 8161b40c194SDan Luedtke print "<dt>" . $parameter . "</dt>\n"; 8171b40c194SDan Luedtke print "<dd>"; 8181b40c194SDan Luedtke output_highlight($args{'parameterdescs'}{$parameter_name}); 8191b40c194SDan Luedtke print "</dd>\n"; 8201b40c194SDan Luedtke } 8211b40c194SDan Luedtke print "</dl>\n"; 8221b40c194SDan Luedtke print "</section>\n"; 8231b40c194SDan Luedtke output_section_html5(@_); 8241b40c194SDan Luedtke print "</article>\n"; 8251b40c194SDan Luedtke} 8261b40c194SDan Luedtke 8271b40c194SDan Luedtke# output function in html5 8281b40c194SDan Luedtkesub output_function_html5(%) { 8291b40c194SDan Luedtke my %args = %{$_[0]}; 8301b40c194SDan Luedtke my ($parameter, $section); 8311b40c194SDan Luedtke my $count; 8321b40c194SDan Luedtke my $html5id; 8331b40c194SDan Luedtke 8341b40c194SDan Luedtke $html5id = $args{'function'}; 8351b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 8361b40c194SDan Luedtke print "<article class=\"function\" id=\"func:". $html5id . "\">\n"; 8371b40c194SDan Luedtke print "<hgroup>\n"; 8381b40c194SDan Luedtke print "<h1>" . $args{'function'} . "</h1>"; 8391b40c194SDan Luedtke print "<h2>" . $args{'purpose'} . "</h2>\n"; 8401b40c194SDan Luedtke print "</hgroup>\n"; 8411b40c194SDan Luedtke print "<ol class=\"code\">\n"; 8421b40c194SDan Luedtke print "<li>"; 8431b40c194SDan Luedtke print "<span class=\"type\">" . $args{'functiontype'} . "</span> "; 8441b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'function'} . "</span> ("; 8451b40c194SDan Luedtke print "</li>"; 8461b40c194SDan Luedtke $count = 0; 8471b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 8481b40c194SDan Luedtke print "<li class=\"indent\">"; 8491b40c194SDan Luedtke $type = $args{'parametertypes'}{$parameter}; 8501b40c194SDan Luedtke if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 8511b40c194SDan Luedtke # pointer-to-function 8521b40c194SDan Luedtke print "<span class=\"type\">$1</span> "; 8531b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 8541b40c194SDan Luedtke print "<span class=\"type\">)</span> "; 8551b40c194SDan Luedtke print "(<span class=\"args\">$2</span>)"; 8561b40c194SDan Luedtke } else { 8571b40c194SDan Luedtke print "<span class=\"type\">$type</span> "; 8581b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 8591b40c194SDan Luedtke } 8601b40c194SDan Luedtke if ($count != $#{$args{'parameterlist'}}) { 8611b40c194SDan Luedtke $count++; 8621b40c194SDan Luedtke print ","; 8631b40c194SDan Luedtke } 8641b40c194SDan Luedtke print "</li>\n"; 8651b40c194SDan Luedtke } 8661b40c194SDan Luedtke print "<li>)</li>\n"; 8671b40c194SDan Luedtke print "</ol>\n"; 8681b40c194SDan Luedtke 8691b40c194SDan Luedtke print "<section>\n"; 8701b40c194SDan Luedtke print "<h1>Arguments</h1>\n"; 8711b40c194SDan Luedtke print "<p>\n"; 8721b40c194SDan Luedtke print "<dl>\n"; 8731b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 8741b40c194SDan Luedtke my $parameter_name = $parameter; 8751b40c194SDan Luedtke $parameter_name =~ s/\[.*//; 8761b40c194SDan Luedtke 8771b40c194SDan Luedtke ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 8781b40c194SDan Luedtke print "<dt>" . $parameter . "</dt>\n"; 8791b40c194SDan Luedtke print "<dd>"; 8801b40c194SDan Luedtke output_highlight($args{'parameterdescs'}{$parameter_name}); 8811b40c194SDan Luedtke print "</dd>\n"; 8821b40c194SDan Luedtke } 8831b40c194SDan Luedtke print "</dl>\n"; 8841b40c194SDan Luedtke print "</section>\n"; 8851b40c194SDan Luedtke output_section_html5(@_); 8861b40c194SDan Luedtke print "</article>\n"; 8871b40c194SDan Luedtke} 8881b40c194SDan Luedtke 8891b40c194SDan Luedtke# output DOC: block header in html5 8901b40c194SDan Luedtkesub output_blockhead_html5(%) { 8911b40c194SDan Luedtke my %args = %{$_[0]}; 8921b40c194SDan Luedtke my ($parameter, $section); 8931b40c194SDan Luedtke my $count; 8941b40c194SDan Luedtke my $html5id; 8951b40c194SDan Luedtke 8961b40c194SDan Luedtke foreach $section (@{$args{'sectionlist'}}) { 8971b40c194SDan Luedtke $html5id = $section; 8981b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 8991b40c194SDan Luedtke print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n"; 9001b40c194SDan Luedtke print "<h1>$section</h1>\n"; 9011b40c194SDan Luedtke print "<p>\n"; 9021b40c194SDan Luedtke output_highlight($args{'sections'}{$section}); 9031b40c194SDan Luedtke print "</p>\n"; 9041b40c194SDan Luedtke } 9051b40c194SDan Luedtke print "</article>\n"; 9061b40c194SDan Luedtke} 9071b40c194SDan Luedtke 9081da177e4SLinus Torvaldssub output_section_xml(%) { 9091da177e4SLinus Torvalds my %args = %{$_[0]}; 9101da177e4SLinus Torvalds my $section; 9111da177e4SLinus Torvalds # print out each section 9121da177e4SLinus Torvalds $lineprefix=" "; 9131da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 914c73894c1SRich Walker print "<refsect1>\n"; 915c73894c1SRich Walker print "<title>$section</title>\n"; 9161da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 917c73894c1SRich Walker print "<informalexample><programlisting>\n"; 918e314ba31SDaniel Santos $output_preformatted = 1; 919c73894c1SRich Walker } else { 920c73894c1SRich Walker print "<para>\n"; 9211da177e4SLinus Torvalds } 9221da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 923e314ba31SDaniel Santos $output_preformatted = 0; 9241da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 925c73894c1SRich Walker print "</programlisting></informalexample>\n"; 926c73894c1SRich Walker } else { 927c73894c1SRich Walker print "</para>\n"; 9281da177e4SLinus Torvalds } 929c73894c1SRich Walker print "</refsect1>\n"; 9301da177e4SLinus Torvalds } 9311da177e4SLinus Torvalds} 9321da177e4SLinus Torvalds 9331da177e4SLinus Torvalds# output function in XML DocBook 9341da177e4SLinus Torvaldssub output_function_xml(%) { 9351da177e4SLinus Torvalds my %args = %{$_[0]}; 9361da177e4SLinus Torvalds my ($parameter, $section); 9371da177e4SLinus Torvalds my $count; 9381da177e4SLinus Torvalds my $id; 9391da177e4SLinus Torvalds 9401da177e4SLinus Torvalds $id = "API-" . $args{'function'}; 9411da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 9421da177e4SLinus Torvalds 9435449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 9448b0c2d98SMartin Waitz print "<refentryinfo>\n"; 9458b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 9468b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 9478b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 9488b0c2d98SMartin Waitz print "</refentryinfo>\n"; 9491da177e4SLinus Torvalds print "<refmeta>\n"; 9505449bc94SPavel Pisa print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n"; 9518b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 9520366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 9531da177e4SLinus Torvalds print "</refmeta>\n"; 9541da177e4SLinus Torvalds print "<refnamediv>\n"; 9551da177e4SLinus Torvalds print " <refname>" . $args{'function'} . "</refname>\n"; 9561da177e4SLinus Torvalds print " <refpurpose>\n"; 9571da177e4SLinus Torvalds print " "; 9581da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 9591da177e4SLinus Torvalds print " </refpurpose>\n"; 9601da177e4SLinus Torvalds print "</refnamediv>\n"; 9611da177e4SLinus Torvalds 9621da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 9631da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 9641da177e4SLinus Torvalds print " <funcsynopsis><funcprototype>\n"; 9651da177e4SLinus Torvalds print " <funcdef>" . $args{'functiontype'} . " "; 9661da177e4SLinus Torvalds print "<function>" . $args{'function'} . " </function></funcdef>\n"; 9671da177e4SLinus Torvalds 9681da177e4SLinus Torvalds $count = 0; 9691da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 9701da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 9711da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 9721da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 9731da177e4SLinus Torvalds # pointer-to-function 9741da177e4SLinus Torvalds print " <paramdef>$1<parameter>$parameter</parameter>)\n"; 9751da177e4SLinus Torvalds print " <funcparams>$2</funcparams></paramdef>\n"; 9761da177e4SLinus Torvalds } else { 9771da177e4SLinus Torvalds print " <paramdef>" . $type; 9781da177e4SLinus Torvalds print " <parameter>$parameter</parameter></paramdef>\n"; 9791da177e4SLinus Torvalds } 9801da177e4SLinus Torvalds } 9811da177e4SLinus Torvalds } else { 9826013d544SMartin Waitz print " <void/>\n"; 9831da177e4SLinus Torvalds } 9841da177e4SLinus Torvalds print " </funcprototype></funcsynopsis>\n"; 9851da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 9861da177e4SLinus Torvalds 9871da177e4SLinus Torvalds # print parameters 9881da177e4SLinus Torvalds print "<refsect1>\n <title>Arguments</title>\n"; 9891da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 9901da177e4SLinus Torvalds print " <variablelist>\n"; 9911da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 9921da177e4SLinus Torvalds my $parameter_name = $parameter; 9931da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 9941da177e4SLinus Torvalds 9951da177e4SLinus Torvalds print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n"; 9961da177e4SLinus Torvalds print " <listitem>\n <para>\n"; 9971da177e4SLinus Torvalds $lineprefix=" "; 9981da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 9991da177e4SLinus Torvalds print " </para>\n </listitem>\n </varlistentry>\n"; 10001da177e4SLinus Torvalds } 10011da177e4SLinus Torvalds print " </variablelist>\n"; 10021da177e4SLinus Torvalds } else { 10031da177e4SLinus Torvalds print " <para>\n None\n </para>\n"; 10041da177e4SLinus Torvalds } 10051da177e4SLinus Torvalds print "</refsect1>\n"; 10061da177e4SLinus Torvalds 10071da177e4SLinus Torvalds output_section_xml(@_); 10081da177e4SLinus Torvalds print "</refentry>\n\n"; 10091da177e4SLinus Torvalds} 10101da177e4SLinus Torvalds 10111da177e4SLinus Torvalds# output struct in XML DocBook 10121da177e4SLinus Torvaldssub output_struct_xml(%) { 10131da177e4SLinus Torvalds my %args = %{$_[0]}; 10141da177e4SLinus Torvalds my ($parameter, $section); 10151da177e4SLinus Torvalds my $id; 10161da177e4SLinus Torvalds 10171da177e4SLinus Torvalds $id = "API-struct-" . $args{'struct'}; 10181da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 10191da177e4SLinus Torvalds 10205449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 10218b0c2d98SMartin Waitz print "<refentryinfo>\n"; 10228b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 10238b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 10248b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 10258b0c2d98SMartin Waitz print "</refentryinfo>\n"; 10261da177e4SLinus Torvalds print "<refmeta>\n"; 10275449bc94SPavel Pisa print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n"; 10288b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 10290366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 10301da177e4SLinus Torvalds print "</refmeta>\n"; 10311da177e4SLinus Torvalds print "<refnamediv>\n"; 10321da177e4SLinus Torvalds print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n"; 10331da177e4SLinus Torvalds print " <refpurpose>\n"; 10341da177e4SLinus Torvalds print " "; 10351da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 10361da177e4SLinus Torvalds print " </refpurpose>\n"; 10371da177e4SLinus Torvalds print "</refnamediv>\n"; 10381da177e4SLinus Torvalds 10391da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 10401da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 10411da177e4SLinus Torvalds print " <programlisting>\n"; 10421da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n"; 10431da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 10441da177e4SLinus Torvalds if ($parameter =~ /^#/) { 10452b35f4d9SRandy Dunlap my $prm = $parameter; 10462b35f4d9SRandy Dunlap # convert data read & converted thru xml_escape() into &xyz; format: 10472b35f4d9SRandy Dunlap # This allows us to have #define macros interspersed in a struct. 10482b35f4d9SRandy Dunlap $prm =~ s/\\\\\\/\&/g; 10492b35f4d9SRandy Dunlap print "$prm\n"; 10501da177e4SLinus Torvalds next; 10511da177e4SLinus Torvalds } 10521da177e4SLinus Torvalds 10531da177e4SLinus Torvalds my $parameter_name = $parameter; 10541da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 10551da177e4SLinus Torvalds 10561da177e4SLinus Torvalds defined($args{'parameterdescs'}{$parameter_name}) || next; 10571da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 10581da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 10591da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 10601da177e4SLinus Torvalds # pointer-to-function 10611da177e4SLinus Torvalds print " $1 $parameter) ($2);\n"; 10621da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 106351f5a0c8SRandy Dunlap # bitfield 10641da177e4SLinus Torvalds print " $1 $parameter$2;\n"; 10651da177e4SLinus Torvalds } else { 10661da177e4SLinus Torvalds print " " . $type . " " . $parameter . ";\n"; 10671da177e4SLinus Torvalds } 10681da177e4SLinus Torvalds } 10691da177e4SLinus Torvalds print "};"; 10701da177e4SLinus Torvalds print " </programlisting>\n"; 10711da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 10721da177e4SLinus Torvalds 10731da177e4SLinus Torvalds print " <refsect1>\n"; 10741da177e4SLinus Torvalds print " <title>Members</title>\n"; 10751da177e4SLinus Torvalds 107639f00c08SRandy Dunlap if ($#{$args{'parameterlist'}} >= 0) { 10771da177e4SLinus Torvalds print " <variablelist>\n"; 10781da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 10791da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 10801da177e4SLinus Torvalds 10811da177e4SLinus Torvalds my $parameter_name = $parameter; 10821da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 10831da177e4SLinus Torvalds 10841da177e4SLinus Torvalds defined($args{'parameterdescs'}{$parameter_name}) || next; 10851da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 10861da177e4SLinus Torvalds print " <varlistentry>"; 10871da177e4SLinus Torvalds print " <term>$parameter</term>\n"; 10881da177e4SLinus Torvalds print " <listitem><para>\n"; 10891da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 10901da177e4SLinus Torvalds print " </para></listitem>\n"; 10911da177e4SLinus Torvalds print " </varlistentry>\n"; 10921da177e4SLinus Torvalds } 10931da177e4SLinus Torvalds print " </variablelist>\n"; 109439f00c08SRandy Dunlap } else { 109539f00c08SRandy Dunlap print " <para>\n None\n </para>\n"; 109639f00c08SRandy Dunlap } 10971da177e4SLinus Torvalds print " </refsect1>\n"; 10981da177e4SLinus Torvalds 10991da177e4SLinus Torvalds output_section_xml(@_); 11001da177e4SLinus Torvalds 11011da177e4SLinus Torvalds print "</refentry>\n\n"; 11021da177e4SLinus Torvalds} 11031da177e4SLinus Torvalds 11041da177e4SLinus Torvalds# output enum in XML DocBook 11051da177e4SLinus Torvaldssub output_enum_xml(%) { 11061da177e4SLinus Torvalds my %args = %{$_[0]}; 11071da177e4SLinus Torvalds my ($parameter, $section); 11081da177e4SLinus Torvalds my $count; 11091da177e4SLinus Torvalds my $id; 11101da177e4SLinus Torvalds 11111da177e4SLinus Torvalds $id = "API-enum-" . $args{'enum'}; 11121da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 11131da177e4SLinus Torvalds 11145449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 11158b0c2d98SMartin Waitz print "<refentryinfo>\n"; 11168b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 11178b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 11188b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 11198b0c2d98SMartin Waitz print "</refentryinfo>\n"; 11201da177e4SLinus Torvalds print "<refmeta>\n"; 11215449bc94SPavel Pisa print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n"; 11228b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 11230366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 11241da177e4SLinus Torvalds print "</refmeta>\n"; 11251da177e4SLinus Torvalds print "<refnamediv>\n"; 11261da177e4SLinus Torvalds print " <refname>enum " . $args{'enum'} . "</refname>\n"; 11271da177e4SLinus Torvalds print " <refpurpose>\n"; 11281da177e4SLinus Torvalds print " "; 11291da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 11301da177e4SLinus Torvalds print " </refpurpose>\n"; 11311da177e4SLinus Torvalds print "</refnamediv>\n"; 11321da177e4SLinus Torvalds 11331da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 11341da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 11351da177e4SLinus Torvalds print " <programlisting>\n"; 11361da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 11371da177e4SLinus Torvalds $count = 0; 11381da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 11391da177e4SLinus Torvalds print " $parameter"; 11401da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 11411da177e4SLinus Torvalds $count++; 11421da177e4SLinus Torvalds print ","; 11431da177e4SLinus Torvalds } 11441da177e4SLinus Torvalds print "\n"; 11451da177e4SLinus Torvalds } 11461da177e4SLinus Torvalds print "};"; 11471da177e4SLinus Torvalds print " </programlisting>\n"; 11481da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 11491da177e4SLinus Torvalds 11501da177e4SLinus Torvalds print "<refsect1>\n"; 11511da177e4SLinus Torvalds print " <title>Constants</title>\n"; 11521da177e4SLinus Torvalds print " <variablelist>\n"; 11531da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 11541da177e4SLinus Torvalds my $parameter_name = $parameter; 11551da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 11561da177e4SLinus Torvalds 11571da177e4SLinus Torvalds print " <varlistentry>"; 11581da177e4SLinus Torvalds print " <term>$parameter</term>\n"; 11591da177e4SLinus Torvalds print " <listitem><para>\n"; 11601da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 11611da177e4SLinus Torvalds print " </para></listitem>\n"; 11621da177e4SLinus Torvalds print " </varlistentry>\n"; 11631da177e4SLinus Torvalds } 11641da177e4SLinus Torvalds print " </variablelist>\n"; 11651da177e4SLinus Torvalds print "</refsect1>\n"; 11661da177e4SLinus Torvalds 11671da177e4SLinus Torvalds output_section_xml(@_); 11681da177e4SLinus Torvalds 11691da177e4SLinus Torvalds print "</refentry>\n\n"; 11701da177e4SLinus Torvalds} 11711da177e4SLinus Torvalds 11721da177e4SLinus Torvalds# output typedef in XML DocBook 11731da177e4SLinus Torvaldssub output_typedef_xml(%) { 11741da177e4SLinus Torvalds my %args = %{$_[0]}; 11751da177e4SLinus Torvalds my ($parameter, $section); 11761da177e4SLinus Torvalds my $id; 11771da177e4SLinus Torvalds 11781da177e4SLinus Torvalds $id = "API-typedef-" . $args{'typedef'}; 11791da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 11801da177e4SLinus Torvalds 11815449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 11828b0c2d98SMartin Waitz print "<refentryinfo>\n"; 11838b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 11848b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 11858b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 11868b0c2d98SMartin Waitz print "</refentryinfo>\n"; 11871da177e4SLinus Torvalds print "<refmeta>\n"; 11885449bc94SPavel Pisa print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n"; 11898b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 11901da177e4SLinus Torvalds print "</refmeta>\n"; 11911da177e4SLinus Torvalds print "<refnamediv>\n"; 11921da177e4SLinus Torvalds print " <refname>typedef " . $args{'typedef'} . "</refname>\n"; 11931da177e4SLinus Torvalds print " <refpurpose>\n"; 11941da177e4SLinus Torvalds print " "; 11951da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 11961da177e4SLinus Torvalds print " </refpurpose>\n"; 11971da177e4SLinus Torvalds print "</refnamediv>\n"; 11981da177e4SLinus Torvalds 11991da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 12001da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 12011da177e4SLinus Torvalds print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n"; 12021da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 12031da177e4SLinus Torvalds 12041da177e4SLinus Torvalds output_section_xml(@_); 12051da177e4SLinus Torvalds 12061da177e4SLinus Torvalds print "</refentry>\n\n"; 12071da177e4SLinus Torvalds} 12081da177e4SLinus Torvalds 12091da177e4SLinus Torvalds# output in XML DocBook 1210b112e0f7SJohannes Bergsub output_blockhead_xml(%) { 12111da177e4SLinus Torvalds my %args = %{$_[0]}; 12121da177e4SLinus Torvalds my ($parameter, $section); 12131da177e4SLinus Torvalds my $count; 12141da177e4SLinus Torvalds 12151da177e4SLinus Torvalds my $id = $args{'module'}; 12161da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 12171da177e4SLinus Torvalds 12181da177e4SLinus Torvalds # print out each section 12191da177e4SLinus Torvalds $lineprefix=" "; 12201da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 1221b112e0f7SJohannes Berg if (!$args{'content-only'}) { 1222b112e0f7SJohannes Berg print "<refsect1>\n <title>$section</title>\n"; 1223b112e0f7SJohannes Berg } 12241da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 12251da177e4SLinus Torvalds print "<example><para>\n"; 1226e314ba31SDaniel Santos $output_preformatted = 1; 1227b112e0f7SJohannes Berg } else { 1228b112e0f7SJohannes Berg print "<para>\n"; 12291da177e4SLinus Torvalds } 12301da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 1231e314ba31SDaniel Santos $output_preformatted = 0; 12321da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 12331da177e4SLinus Torvalds print "</para></example>\n"; 1234b112e0f7SJohannes Berg } else { 1235b112e0f7SJohannes Berg print "</para>"; 12361da177e4SLinus Torvalds } 1237b112e0f7SJohannes Berg if (!$args{'content-only'}) { 1238b112e0f7SJohannes Berg print "\n</refsect1>\n"; 1239b112e0f7SJohannes Berg } 12401da177e4SLinus Torvalds } 12411da177e4SLinus Torvalds 12421da177e4SLinus Torvalds print "\n\n"; 12431da177e4SLinus Torvalds} 12441da177e4SLinus Torvalds 12451da177e4SLinus Torvalds# output in XML DocBook 12461da177e4SLinus Torvaldssub output_function_gnome { 12471da177e4SLinus Torvalds my %args = %{$_[0]}; 12481da177e4SLinus Torvalds my ($parameter, $section); 12491da177e4SLinus Torvalds my $count; 12501da177e4SLinus Torvalds my $id; 12511da177e4SLinus Torvalds 12521da177e4SLinus Torvalds $id = $args{'module'} . "-" . $args{'function'}; 12531da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 12541da177e4SLinus Torvalds 12551da177e4SLinus Torvalds print "<sect2>\n"; 12561da177e4SLinus Torvalds print " <title id=\"$id\">" . $args{'function'} . "</title>\n"; 12571da177e4SLinus Torvalds 12581da177e4SLinus Torvalds print " <funcsynopsis>\n"; 12591da177e4SLinus Torvalds print " <funcdef>" . $args{'functiontype'} . " "; 12601da177e4SLinus Torvalds print "<function>" . $args{'function'} . " "; 12611da177e4SLinus Torvalds print "</function></funcdef>\n"; 12621da177e4SLinus Torvalds 12631da177e4SLinus Torvalds $count = 0; 12641da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 12651da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 12661da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 12671da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 12681da177e4SLinus Torvalds # pointer-to-function 12691da177e4SLinus Torvalds print " <paramdef>$1 <parameter>$parameter</parameter>)\n"; 12701da177e4SLinus Torvalds print " <funcparams>$2</funcparams></paramdef>\n"; 12711da177e4SLinus Torvalds } else { 12721da177e4SLinus Torvalds print " <paramdef>" . $type; 12731da177e4SLinus Torvalds print " <parameter>$parameter</parameter></paramdef>\n"; 12741da177e4SLinus Torvalds } 12751da177e4SLinus Torvalds } 12761da177e4SLinus Torvalds } else { 12771da177e4SLinus Torvalds print " <void>\n"; 12781da177e4SLinus Torvalds } 12791da177e4SLinus Torvalds print " </funcsynopsis>\n"; 12801da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 12811da177e4SLinus Torvalds print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n"; 12821da177e4SLinus Torvalds print "<tgroup cols=\"2\">\n"; 12831da177e4SLinus Torvalds print "<colspec colwidth=\"2*\">\n"; 12841da177e4SLinus Torvalds print "<colspec colwidth=\"8*\">\n"; 12851da177e4SLinus Torvalds print "<tbody>\n"; 12861da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 12871da177e4SLinus Torvalds my $parameter_name = $parameter; 12881da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 12891da177e4SLinus Torvalds 12901da177e4SLinus Torvalds print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n"; 12911da177e4SLinus Torvalds print " <entry>\n"; 12921da177e4SLinus Torvalds $lineprefix=" "; 12931da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 12941da177e4SLinus Torvalds print " </entry></row>\n"; 12951da177e4SLinus Torvalds } 12961da177e4SLinus Torvalds print " </tbody></tgroup></informaltable>\n"; 12971da177e4SLinus Torvalds } else { 12981da177e4SLinus Torvalds print " <para>\n None\n </para>\n"; 12991da177e4SLinus Torvalds } 13001da177e4SLinus Torvalds 13011da177e4SLinus Torvalds # print out each section 13021da177e4SLinus Torvalds $lineprefix=" "; 13031da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 13041da177e4SLinus Torvalds print "<simplesect>\n <title>$section</title>\n"; 13051da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 13061da177e4SLinus Torvalds print "<example><programlisting>\n"; 1307e314ba31SDaniel Santos $output_preformatted = 1; 13081da177e4SLinus Torvalds } else { 13091da177e4SLinus Torvalds } 13101da177e4SLinus Torvalds print "<para>\n"; 13111da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 1312e314ba31SDaniel Santos $output_preformatted = 0; 13131da177e4SLinus Torvalds print "</para>\n"; 13141da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 13151da177e4SLinus Torvalds print "</programlisting></example>\n"; 13161da177e4SLinus Torvalds } else { 13171da177e4SLinus Torvalds } 13181da177e4SLinus Torvalds print " </simplesect>\n"; 13191da177e4SLinus Torvalds } 13201da177e4SLinus Torvalds 13211da177e4SLinus Torvalds print "</sect2>\n\n"; 13221da177e4SLinus Torvalds} 13231da177e4SLinus Torvalds 13241da177e4SLinus Torvalds## 13251da177e4SLinus Torvalds# output function in man 13261da177e4SLinus Torvaldssub output_function_man(%) { 13271da177e4SLinus Torvalds my %args = %{$_[0]}; 13281da177e4SLinus Torvalds my ($parameter, $section); 13291da177e4SLinus Torvalds my $count; 13301da177e4SLinus Torvalds 13311da177e4SLinus Torvalds print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; 13321da177e4SLinus Torvalds 13331da177e4SLinus Torvalds print ".SH NAME\n"; 13341da177e4SLinus Torvalds print $args{'function'} . " \\- " . $args{'purpose'} . "\n"; 13351da177e4SLinus Torvalds 13361da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 1337a21217daSRandy Dunlap if ($args{'functiontype'} ne "") { 13381da177e4SLinus Torvalds print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n"; 1339a21217daSRandy Dunlap } else { 1340a21217daSRandy Dunlap print ".B \"" . $args{'function'} . "\n"; 1341a21217daSRandy Dunlap } 13421da177e4SLinus Torvalds $count = 0; 13431da177e4SLinus Torvalds my $parenth = "("; 13441da177e4SLinus Torvalds my $post = ","; 13451da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 13461da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 13471da177e4SLinus Torvalds $post = ");"; 13481da177e4SLinus Torvalds } 13491da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 13501da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 13511da177e4SLinus Torvalds # pointer-to-function 13521da177e4SLinus Torvalds print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n"; 13531da177e4SLinus Torvalds } else { 13541da177e4SLinus Torvalds $type =~ s/([^\*])$/$1 /; 13551da177e4SLinus Torvalds print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n"; 13561da177e4SLinus Torvalds } 13571da177e4SLinus Torvalds $count++; 13581da177e4SLinus Torvalds $parenth = ""; 13591da177e4SLinus Torvalds } 13601da177e4SLinus Torvalds 13611da177e4SLinus Torvalds print ".SH ARGUMENTS\n"; 13621da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 13631da177e4SLinus Torvalds my $parameter_name = $parameter; 13641da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 13651da177e4SLinus Torvalds 13661da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 13671da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 13681da177e4SLinus Torvalds } 13691da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 13701da177e4SLinus Torvalds print ".SH \"", uc $section, "\"\n"; 13711da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 13721da177e4SLinus Torvalds } 13731da177e4SLinus Torvalds} 13741da177e4SLinus Torvalds 13751da177e4SLinus Torvalds## 13761da177e4SLinus Torvalds# output enum in man 13771da177e4SLinus Torvaldssub output_enum_man(%) { 13781da177e4SLinus Torvalds my %args = %{$_[0]}; 13791da177e4SLinus Torvalds my ($parameter, $section); 13801da177e4SLinus Torvalds my $count; 13811da177e4SLinus Torvalds 13821da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n"; 13831da177e4SLinus Torvalds 13841da177e4SLinus Torvalds print ".SH NAME\n"; 13851da177e4SLinus Torvalds print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n"; 13861da177e4SLinus Torvalds 13871da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 13881da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 13891da177e4SLinus Torvalds $count = 0; 13901da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 13911da177e4SLinus Torvalds print ".br\n.BI \" $parameter\"\n"; 13921da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 13931da177e4SLinus Torvalds print "\n};\n"; 13941da177e4SLinus Torvalds last; 13951da177e4SLinus Torvalds } 13961da177e4SLinus Torvalds else { 13971da177e4SLinus Torvalds print ", \n.br\n"; 13981da177e4SLinus Torvalds } 13991da177e4SLinus Torvalds $count++; 14001da177e4SLinus Torvalds } 14011da177e4SLinus Torvalds 14021da177e4SLinus Torvalds print ".SH Constants\n"; 14031da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 14041da177e4SLinus Torvalds my $parameter_name = $parameter; 14051da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 14061da177e4SLinus Torvalds 14071da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 14081da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 14091da177e4SLinus Torvalds } 14101da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 14111da177e4SLinus Torvalds print ".SH \"$section\"\n"; 14121da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 14131da177e4SLinus Torvalds } 14141da177e4SLinus Torvalds} 14151da177e4SLinus Torvalds 14161da177e4SLinus Torvalds## 14171da177e4SLinus Torvalds# output struct in man 14181da177e4SLinus Torvaldssub output_struct_man(%) { 14191da177e4SLinus Torvalds my %args = %{$_[0]}; 14201da177e4SLinus Torvalds my ($parameter, $section); 14211da177e4SLinus Torvalds 14221da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n"; 14231da177e4SLinus Torvalds 14241da177e4SLinus Torvalds print ".SH NAME\n"; 14251da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n"; 14261da177e4SLinus Torvalds 14271da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 14281da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n.br\n"; 14291da177e4SLinus Torvalds 14301da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 14311da177e4SLinus Torvalds if ($parameter =~ /^#/) { 14321da177e4SLinus Torvalds print ".BI \"$parameter\"\n.br\n"; 14331da177e4SLinus Torvalds next; 14341da177e4SLinus Torvalds } 14351da177e4SLinus Torvalds my $parameter_name = $parameter; 14361da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 14371da177e4SLinus Torvalds 14381da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 14391da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 14401da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 14411da177e4SLinus Torvalds # pointer-to-function 14421da177e4SLinus Torvalds print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n"; 14431da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 14441d7e1d45SRandy.Dunlap # bitfield 14451d7e1d45SRandy.Dunlap print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n"; 14461da177e4SLinus Torvalds } else { 14471da177e4SLinus Torvalds $type =~ s/([^\*])$/$1 /; 14481da177e4SLinus Torvalds print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n"; 14491da177e4SLinus Torvalds } 14501da177e4SLinus Torvalds print "\n.br\n"; 14511da177e4SLinus Torvalds } 14521da177e4SLinus Torvalds print "};\n.br\n"; 14531da177e4SLinus Torvalds 1454c51d3dacSRandy Dunlap print ".SH Members\n"; 14551da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 14561da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 14571da177e4SLinus Torvalds 14581da177e4SLinus Torvalds my $parameter_name = $parameter; 14591da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 14601da177e4SLinus Torvalds 14611da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 14621da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 14631da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 14641da177e4SLinus Torvalds } 14651da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 14661da177e4SLinus Torvalds print ".SH \"$section\"\n"; 14671da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 14681da177e4SLinus Torvalds } 14691da177e4SLinus Torvalds} 14701da177e4SLinus Torvalds 14711da177e4SLinus Torvalds## 14721da177e4SLinus Torvalds# output typedef in man 14731da177e4SLinus Torvaldssub output_typedef_man(%) { 14741da177e4SLinus Torvalds my %args = %{$_[0]}; 14751da177e4SLinus Torvalds my ($parameter, $section); 14761da177e4SLinus Torvalds 14771da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n"; 14781da177e4SLinus Torvalds 14791da177e4SLinus Torvalds print ".SH NAME\n"; 14801da177e4SLinus Torvalds print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n"; 14811da177e4SLinus Torvalds 14821da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 14831da177e4SLinus Torvalds print ".SH \"$section\"\n"; 14841da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 14851da177e4SLinus Torvalds } 14861da177e4SLinus Torvalds} 14871da177e4SLinus Torvalds 1488b112e0f7SJohannes Bergsub output_blockhead_man(%) { 14891da177e4SLinus Torvalds my %args = %{$_[0]}; 14901da177e4SLinus Torvalds my ($parameter, $section); 14911da177e4SLinus Torvalds my $count; 14921da177e4SLinus Torvalds 14931da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; 14941da177e4SLinus Torvalds 14951da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 14961da177e4SLinus Torvalds print ".SH \"$section\"\n"; 14971da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 14981da177e4SLinus Torvalds } 14991da177e4SLinus Torvalds} 15001da177e4SLinus Torvalds 15011da177e4SLinus Torvalds## 15021da177e4SLinus Torvalds# output in text 15031da177e4SLinus Torvaldssub output_function_text(%) { 15041da177e4SLinus Torvalds my %args = %{$_[0]}; 15051da177e4SLinus Torvalds my ($parameter, $section); 1506a21217daSRandy Dunlap my $start; 15071da177e4SLinus Torvalds 1508f47634b2SRandy Dunlap print "Name:\n\n"; 1509f47634b2SRandy Dunlap print $args{'function'} . " - " . $args{'purpose'} . "\n"; 1510f47634b2SRandy Dunlap 1511f47634b2SRandy Dunlap print "\nSynopsis:\n\n"; 1512a21217daSRandy Dunlap if ($args{'functiontype'} ne "") { 1513a21217daSRandy Dunlap $start = $args{'functiontype'} . " " . $args{'function'} . " ("; 1514a21217daSRandy Dunlap } else { 1515a21217daSRandy Dunlap $start = $args{'function'} . " ("; 1516a21217daSRandy Dunlap } 15171da177e4SLinus Torvalds print $start; 1518a21217daSRandy Dunlap 15191da177e4SLinus Torvalds my $count = 0; 15201da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 15211da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 15221da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 15231da177e4SLinus Torvalds # pointer-to-function 15241da177e4SLinus Torvalds print $1 . $parameter . ") (" . $2; 15251da177e4SLinus Torvalds } else { 15261da177e4SLinus Torvalds print $type . " " . $parameter; 15271da177e4SLinus Torvalds } 15281da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 15291da177e4SLinus Torvalds $count++; 15301da177e4SLinus Torvalds print ",\n"; 15311da177e4SLinus Torvalds print " " x length($start); 15321da177e4SLinus Torvalds } else { 15331da177e4SLinus Torvalds print ");\n\n"; 15341da177e4SLinus Torvalds } 15351da177e4SLinus Torvalds } 15361da177e4SLinus Torvalds 15371da177e4SLinus Torvalds print "Arguments:\n\n"; 15381da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 15391da177e4SLinus Torvalds my $parameter_name = $parameter; 15401da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 15411da177e4SLinus Torvalds 15421da177e4SLinus Torvalds print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n"; 15431da177e4SLinus Torvalds } 15441da177e4SLinus Torvalds output_section_text(@_); 15451da177e4SLinus Torvalds} 15461da177e4SLinus Torvalds 15471da177e4SLinus Torvalds#output sections in text 15481da177e4SLinus Torvaldssub output_section_text(%) { 15491da177e4SLinus Torvalds my %args = %{$_[0]}; 15501da177e4SLinus Torvalds my $section; 15511da177e4SLinus Torvalds 15521da177e4SLinus Torvalds print "\n"; 15531da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 15541da177e4SLinus Torvalds print "$section:\n\n"; 15551da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 15561da177e4SLinus Torvalds } 15571da177e4SLinus Torvalds print "\n\n"; 15581da177e4SLinus Torvalds} 15591da177e4SLinus Torvalds 15601da177e4SLinus Torvalds# output enum in text 15611da177e4SLinus Torvaldssub output_enum_text(%) { 15621da177e4SLinus Torvalds my %args = %{$_[0]}; 15631da177e4SLinus Torvalds my ($parameter); 15641da177e4SLinus Torvalds my $count; 15651da177e4SLinus Torvalds print "Enum:\n\n"; 15661da177e4SLinus Torvalds 15671d7e1d45SRandy.Dunlap print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n"; 15681da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 15691da177e4SLinus Torvalds $count = 0; 15701da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 15711da177e4SLinus Torvalds print "\t$parameter"; 15721da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 15731da177e4SLinus Torvalds $count++; 15741da177e4SLinus Torvalds print ","; 15751da177e4SLinus Torvalds } 15761da177e4SLinus Torvalds print "\n"; 15771da177e4SLinus Torvalds } 15781da177e4SLinus Torvalds print "};\n\n"; 15791da177e4SLinus Torvalds 15801da177e4SLinus Torvalds print "Constants:\n\n"; 15811da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 15821da177e4SLinus Torvalds print "$parameter\n\t"; 15831da177e4SLinus Torvalds print $args{'parameterdescs'}{$parameter} . "\n"; 15841da177e4SLinus Torvalds } 15851da177e4SLinus Torvalds 15861da177e4SLinus Torvalds output_section_text(@_); 15871da177e4SLinus Torvalds} 15881da177e4SLinus Torvalds 15891da177e4SLinus Torvalds# output typedef in text 15901da177e4SLinus Torvaldssub output_typedef_text(%) { 15911da177e4SLinus Torvalds my %args = %{$_[0]}; 15921da177e4SLinus Torvalds my ($parameter); 15931da177e4SLinus Torvalds my $count; 15941da177e4SLinus Torvalds print "Typedef:\n\n"; 15951da177e4SLinus Torvalds 15961d7e1d45SRandy.Dunlap print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n"; 15971da177e4SLinus Torvalds output_section_text(@_); 15981da177e4SLinus Torvalds} 15991da177e4SLinus Torvalds 16001da177e4SLinus Torvalds# output struct as text 16011da177e4SLinus Torvaldssub output_struct_text(%) { 16021da177e4SLinus Torvalds my %args = %{$_[0]}; 16031da177e4SLinus Torvalds my ($parameter); 16041da177e4SLinus Torvalds 16051d7e1d45SRandy.Dunlap print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n"; 16061da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n"; 16071da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 16081da177e4SLinus Torvalds if ($parameter =~ /^#/) { 16091da177e4SLinus Torvalds print "$parameter\n"; 16101da177e4SLinus Torvalds next; 16111da177e4SLinus Torvalds } 16121da177e4SLinus Torvalds 16131da177e4SLinus Torvalds my $parameter_name = $parameter; 16141da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 16151da177e4SLinus Torvalds 16161da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 16171da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 16181da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 16191da177e4SLinus Torvalds # pointer-to-function 16201da177e4SLinus Torvalds print "\t$1 $parameter) ($2);\n"; 16211da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 162251f5a0c8SRandy Dunlap # bitfield 16231da177e4SLinus Torvalds print "\t$1 $parameter$2;\n"; 16241da177e4SLinus Torvalds } else { 16251da177e4SLinus Torvalds print "\t" . $type . " " . $parameter . ";\n"; 16261da177e4SLinus Torvalds } 16271da177e4SLinus Torvalds } 16281da177e4SLinus Torvalds print "};\n\n"; 16291da177e4SLinus Torvalds 16301da177e4SLinus Torvalds print "Members:\n\n"; 16311da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 16321da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 16331da177e4SLinus Torvalds 16341da177e4SLinus Torvalds my $parameter_name = $parameter; 16351da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 16361da177e4SLinus Torvalds 16371da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 16381da177e4SLinus Torvalds print "$parameter\n\t"; 16391da177e4SLinus Torvalds print $args{'parameterdescs'}{$parameter_name} . "\n"; 16401da177e4SLinus Torvalds } 16411da177e4SLinus Torvalds print "\n"; 16421da177e4SLinus Torvalds output_section_text(@_); 16431da177e4SLinus Torvalds} 16441da177e4SLinus Torvalds 1645b112e0f7SJohannes Bergsub output_blockhead_text(%) { 16461da177e4SLinus Torvalds my %args = %{$_[0]}; 16471da177e4SLinus Torvalds my ($parameter, $section); 16481da177e4SLinus Torvalds 16491da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 16501da177e4SLinus Torvalds print " $section:\n"; 16511da177e4SLinus Torvalds print " -> "; 16521da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 16531da177e4SLinus Torvalds } 16541da177e4SLinus Torvalds} 16551da177e4SLinus Torvalds 1656eda603f6SJohannes Berg## list mode output functions 1657eda603f6SJohannes Berg 1658eda603f6SJohannes Bergsub output_function_list(%) { 1659eda603f6SJohannes Berg my %args = %{$_[0]}; 1660eda603f6SJohannes Berg 1661eda603f6SJohannes Berg print $args{'function'} . "\n"; 1662eda603f6SJohannes Berg} 1663eda603f6SJohannes Berg 1664eda603f6SJohannes Berg# output enum in list 1665eda603f6SJohannes Bergsub output_enum_list(%) { 1666eda603f6SJohannes Berg my %args = %{$_[0]}; 1667eda603f6SJohannes Berg print $args{'enum'} . "\n"; 1668eda603f6SJohannes Berg} 1669eda603f6SJohannes Berg 1670eda603f6SJohannes Berg# output typedef in list 1671eda603f6SJohannes Bergsub output_typedef_list(%) { 1672eda603f6SJohannes Berg my %args = %{$_[0]}; 1673eda603f6SJohannes Berg print $args{'typedef'} . "\n"; 1674eda603f6SJohannes Berg} 1675eda603f6SJohannes Berg 1676eda603f6SJohannes Berg# output struct as list 1677eda603f6SJohannes Bergsub output_struct_list(%) { 1678eda603f6SJohannes Berg my %args = %{$_[0]}; 1679eda603f6SJohannes Berg 1680eda603f6SJohannes Berg print $args{'struct'} . "\n"; 1681eda603f6SJohannes Berg} 1682eda603f6SJohannes Berg 1683eda603f6SJohannes Bergsub output_blockhead_list(%) { 1684eda603f6SJohannes Berg my %args = %{$_[0]}; 1685eda603f6SJohannes Berg my ($parameter, $section); 1686eda603f6SJohannes Berg 1687eda603f6SJohannes Berg foreach $section (@{$args{'sectionlist'}}) { 1688eda603f6SJohannes Berg print "DOC: $section\n"; 1689eda603f6SJohannes Berg } 1690eda603f6SJohannes Berg} 1691eda603f6SJohannes Berg 16921da177e4SLinus Torvalds## 169327205744SRandy Dunlap# generic output function for all types (function, struct/union, typedef, enum); 169427205744SRandy Dunlap# calls the generated, variable output_ function name based on 169527205744SRandy Dunlap# functype and output_mode 16961da177e4SLinus Torvaldssub output_declaration { 16971da177e4SLinus Torvalds no strict 'refs'; 16981da177e4SLinus Torvalds my $name = shift; 16991da177e4SLinus Torvalds my $functype = shift; 17001da177e4SLinus Torvalds my $func = "output_${functype}_$output_mode"; 17011da177e4SLinus Torvalds if (($function_only==0) || 17021da177e4SLinus Torvalds ( $function_only == 1 && defined($function_table{$name})) || 17031da177e4SLinus Torvalds ( $function_only == 2 && !defined($function_table{$name}))) 17041da177e4SLinus Torvalds { 17051da177e4SLinus Torvalds &$func(@_); 17061da177e4SLinus Torvalds $section_counter++; 17071da177e4SLinus Torvalds } 17081da177e4SLinus Torvalds} 17091da177e4SLinus Torvalds 17101da177e4SLinus Torvalds## 171127205744SRandy Dunlap# generic output function - calls the right one based on current output mode. 1712b112e0f7SJohannes Bergsub output_blockhead { 17131da177e4SLinus Torvalds no strict 'refs'; 1714b112e0f7SJohannes Berg my $func = "output_blockhead_" . $output_mode; 17151da177e4SLinus Torvalds &$func(@_); 17161da177e4SLinus Torvalds $section_counter++; 17171da177e4SLinus Torvalds} 17181da177e4SLinus Torvalds 17191da177e4SLinus Torvalds## 17201da177e4SLinus Torvalds# takes a declaration (struct, union, enum, typedef) and 17211da177e4SLinus Torvalds# invokes the right handler. NOT called for functions. 17221da177e4SLinus Torvaldssub dump_declaration($$) { 17231da177e4SLinus Torvalds no strict 'refs'; 17241da177e4SLinus Torvalds my ($prototype, $file) = @_; 17251da177e4SLinus Torvalds my $func = "dump_" . $decl_type; 17261da177e4SLinus Torvalds &$func(@_); 17271da177e4SLinus Torvalds} 17281da177e4SLinus Torvalds 17291da177e4SLinus Torvaldssub dump_union($$) { 17301da177e4SLinus Torvalds dump_struct(@_); 17311da177e4SLinus Torvalds} 17321da177e4SLinus Torvalds 17331da177e4SLinus Torvaldssub dump_struct($$) { 17341da177e4SLinus Torvalds my $x = shift; 17351da177e4SLinus Torvalds my $file = shift; 1736a1d94aa5SRandy Dunlap my $nested; 17371da177e4SLinus Torvalds 17381da177e4SLinus Torvalds if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) { 173952dc5aecSRandy Dunlap #my $decl_type = $1; 17401da177e4SLinus Torvalds $declaration_name = $2; 17411da177e4SLinus Torvalds my $members = $3; 17421da177e4SLinus Torvalds 17431da177e4SLinus Torvalds # ignore embedded structs or unions 1744a1d94aa5SRandy Dunlap $members =~ s/({.*})//g; 1745a1d94aa5SRandy Dunlap $nested = $1; 17461da177e4SLinus Torvalds 1747aeec46b9SMartin Waitz # ignore members marked private: 174852dc5aecSRandy Dunlap $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gos; 174952dc5aecSRandy Dunlap $members =~ s/\/\*\s*private:.*//gos; 1750aeec46b9SMartin Waitz # strip comments: 1751aeec46b9SMartin Waitz $members =~ s/\/\*.*?\*\///gos; 1752a1d94aa5SRandy Dunlap $nested =~ s/\/\*.*?\*\///gos; 1753d960eea9SRandy Dunlap # strip kmemcheck_bitfield_{begin,end}.*; 1754d960eea9SRandy Dunlap $members =~ s/kmemcheck_bitfield_.*?;//gos; 1755ef5da59fSRandy Dunlap # strip attributes 1756*7b990789SJohannes Berg $members =~ s/__aligned\s*\([^;]*\)//gos; 1757aeec46b9SMartin Waitz 17581da177e4SLinus Torvalds create_parameterlist($members, ';', $file); 1759a1d94aa5SRandy Dunlap check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested); 17601da177e4SLinus Torvalds 17611da177e4SLinus Torvalds output_declaration($declaration_name, 17621da177e4SLinus Torvalds 'struct', 17631da177e4SLinus Torvalds {'struct' => $declaration_name, 17641da177e4SLinus Torvalds 'module' => $modulename, 17651da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 17661da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 17671da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 17681da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 17691da177e4SLinus Torvalds 'sections' => \%sections, 17701da177e4SLinus Torvalds 'purpose' => $declaration_purpose, 17711da177e4SLinus Torvalds 'type' => $decl_type 17721da177e4SLinus Torvalds }); 17731da177e4SLinus Torvalds } 17741da177e4SLinus Torvalds else { 17751da177e4SLinus Torvalds print STDERR "Error(${file}:$.): Cannot parse struct or union!\n"; 17761da177e4SLinus Torvalds ++$errors; 17771da177e4SLinus Torvalds } 17781da177e4SLinus Torvalds} 17791da177e4SLinus Torvalds 17801da177e4SLinus Torvaldssub dump_enum($$) { 17811da177e4SLinus Torvalds my $x = shift; 17821da177e4SLinus Torvalds my $file = shift; 17831da177e4SLinus Torvalds 1784aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 1785b6d676dbSRandy Dunlap $x =~ s/^#\s*define\s+.*$//; # strip #define macros inside enums 1786b6d676dbSRandy Dunlap 17871da177e4SLinus Torvalds if ($x =~ /enum\s+(\w+)\s*{(.*)}/) { 17881da177e4SLinus Torvalds $declaration_name = $1; 17891da177e4SLinus Torvalds my $members = $2; 17901da177e4SLinus Torvalds 17911da177e4SLinus Torvalds foreach my $arg (split ',', $members) { 17921da177e4SLinus Torvalds $arg =~ s/^\s*(\w+).*/$1/; 17931da177e4SLinus Torvalds push @parameterlist, $arg; 17941da177e4SLinus Torvalds if (!$parameterdescs{$arg}) { 17951da177e4SLinus Torvalds $parameterdescs{$arg} = $undescribed; 17961da177e4SLinus Torvalds print STDERR "Warning(${file}:$.): Enum value '$arg' ". 17971da177e4SLinus Torvalds "not described in enum '$declaration_name'\n"; 17981da177e4SLinus Torvalds } 17991da177e4SLinus Torvalds 18001da177e4SLinus Torvalds } 18011da177e4SLinus Torvalds 18021da177e4SLinus Torvalds output_declaration($declaration_name, 18031da177e4SLinus Torvalds 'enum', 18041da177e4SLinus Torvalds {'enum' => $declaration_name, 18051da177e4SLinus Torvalds 'module' => $modulename, 18061da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 18071da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 18081da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 18091da177e4SLinus Torvalds 'sections' => \%sections, 18101da177e4SLinus Torvalds 'purpose' => $declaration_purpose 18111da177e4SLinus Torvalds }); 18121da177e4SLinus Torvalds } 18131da177e4SLinus Torvalds else { 18141da177e4SLinus Torvalds print STDERR "Error(${file}:$.): Cannot parse enum!\n"; 18151da177e4SLinus Torvalds ++$errors; 18161da177e4SLinus Torvalds } 18171da177e4SLinus Torvalds} 18181da177e4SLinus Torvalds 18191da177e4SLinus Torvaldssub dump_typedef($$) { 18201da177e4SLinus Torvalds my $x = shift; 18211da177e4SLinus Torvalds my $file = shift; 18221da177e4SLinus Torvalds 1823aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 18241da177e4SLinus Torvalds while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { 18251da177e4SLinus Torvalds $x =~ s/\(*.\)\s*;$/;/; 18261da177e4SLinus Torvalds $x =~ s/\[*.\]\s*;$/;/; 18271da177e4SLinus Torvalds } 18281da177e4SLinus Torvalds 18291da177e4SLinus Torvalds if ($x =~ /typedef.*\s+(\w+)\s*;/) { 18301da177e4SLinus Torvalds $declaration_name = $1; 18311da177e4SLinus Torvalds 18321da177e4SLinus Torvalds output_declaration($declaration_name, 18331da177e4SLinus Torvalds 'typedef', 18341da177e4SLinus Torvalds {'typedef' => $declaration_name, 18351da177e4SLinus Torvalds 'module' => $modulename, 18361da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 18371da177e4SLinus Torvalds 'sections' => \%sections, 18381da177e4SLinus Torvalds 'purpose' => $declaration_purpose 18391da177e4SLinus Torvalds }); 18401da177e4SLinus Torvalds } 18411da177e4SLinus Torvalds else { 18421da177e4SLinus Torvalds print STDERR "Error(${file}:$.): Cannot parse typedef!\n"; 18431da177e4SLinus Torvalds ++$errors; 18441da177e4SLinus Torvalds } 18451da177e4SLinus Torvalds} 18461da177e4SLinus Torvalds 1847a1d94aa5SRandy Dunlapsub save_struct_actual($) { 1848a1d94aa5SRandy Dunlap my $actual = shift; 1849a1d94aa5SRandy Dunlap 1850a1d94aa5SRandy Dunlap # strip all spaces from the actual param so that it looks like one string item 1851a1d94aa5SRandy Dunlap $actual =~ s/\s*//g; 1852a1d94aa5SRandy Dunlap $struct_actual = $struct_actual . $actual . " "; 1853a1d94aa5SRandy Dunlap} 1854a1d94aa5SRandy Dunlap 18551da177e4SLinus Torvaldssub create_parameterlist($$$) { 18561da177e4SLinus Torvalds my $args = shift; 18571da177e4SLinus Torvalds my $splitter = shift; 18581da177e4SLinus Torvalds my $file = shift; 18591da177e4SLinus Torvalds my $type; 18601da177e4SLinus Torvalds my $param; 18611da177e4SLinus Torvalds 1862a6d3fe77SMartin Waitz # temporarily replace commas inside function pointer definition 18631da177e4SLinus Torvalds while ($args =~ /(\([^\),]+),/) { 18641da177e4SLinus Torvalds $args =~ s/(\([^\),]+),/$1#/g; 18651da177e4SLinus Torvalds } 18661da177e4SLinus Torvalds 18671da177e4SLinus Torvalds foreach my $arg (split($splitter, $args)) { 18681da177e4SLinus Torvalds # strip comments 18691da177e4SLinus Torvalds $arg =~ s/\/\*.*\*\///; 18701da177e4SLinus Torvalds # strip leading/trailing spaces 18711da177e4SLinus Torvalds $arg =~ s/^\s*//; 18721da177e4SLinus Torvalds $arg =~ s/\s*$//; 18731da177e4SLinus Torvalds $arg =~ s/\s+/ /; 18741da177e4SLinus Torvalds 18751da177e4SLinus Torvalds if ($arg =~ /^#/) { 18761da177e4SLinus Torvalds # Treat preprocessor directive as a typeless variable just to fill 18771da177e4SLinus Torvalds # corresponding data structures "correctly". Catch it later in 18781da177e4SLinus Torvalds # output_* subs. 18791da177e4SLinus Torvalds push_parameter($arg, "", $file); 188000d62961SRichard Kennedy } elsif ($arg =~ m/\(.+\)\s*\(/) { 18811da177e4SLinus Torvalds # pointer-to-function 18821da177e4SLinus Torvalds $arg =~ tr/#/,/; 188300d62961SRichard Kennedy $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/; 18841da177e4SLinus Torvalds $param = $1; 18851da177e4SLinus Torvalds $type = $arg; 188600d62961SRichard Kennedy $type =~ s/([^\(]+\(\*?)\s*$param/$1/; 1887a1d94aa5SRandy Dunlap save_struct_actual($param); 18881da177e4SLinus Torvalds push_parameter($param, $type, $file); 1889aeec46b9SMartin Waitz } elsif ($arg) { 18901da177e4SLinus Torvalds $arg =~ s/\s*:\s*/:/g; 18911da177e4SLinus Torvalds $arg =~ s/\s*\[/\[/g; 18921da177e4SLinus Torvalds 18931da177e4SLinus Torvalds my @args = split('\s*,\s*', $arg); 18941da177e4SLinus Torvalds if ($args[0] =~ m/\*/) { 18951da177e4SLinus Torvalds $args[0] =~ s/(\*+)\s*/ $1/; 18961da177e4SLinus Torvalds } 1897884f2810SBorislav Petkov 1898884f2810SBorislav Petkov my @first_arg; 1899884f2810SBorislav Petkov if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) { 1900884f2810SBorislav Petkov shift @args; 1901884f2810SBorislav Petkov push(@first_arg, split('\s+', $1)); 1902884f2810SBorislav Petkov push(@first_arg, $2); 1903884f2810SBorislav Petkov } else { 1904884f2810SBorislav Petkov @first_arg = split('\s+', shift @args); 1905884f2810SBorislav Petkov } 1906884f2810SBorislav Petkov 19071da177e4SLinus Torvalds unshift(@args, pop @first_arg); 19081da177e4SLinus Torvalds $type = join " ", @first_arg; 19091da177e4SLinus Torvalds 19101da177e4SLinus Torvalds foreach $param (@args) { 19111da177e4SLinus Torvalds if ($param =~ m/^(\*+)\s*(.*)/) { 1912a1d94aa5SRandy Dunlap save_struct_actual($2); 19131da177e4SLinus Torvalds push_parameter($2, "$type $1", $file); 19141da177e4SLinus Torvalds } 19151da177e4SLinus Torvalds elsif ($param =~ m/(.*?):(\d+)/) { 19167b97887eSRandy Dunlap if ($type ne "") { # skip unnamed bit-fields 1917a1d94aa5SRandy Dunlap save_struct_actual($1); 19181da177e4SLinus Torvalds push_parameter($1, "$type:$2", $file) 19191da177e4SLinus Torvalds } 19207b97887eSRandy Dunlap } 19211da177e4SLinus Torvalds else { 1922a1d94aa5SRandy Dunlap save_struct_actual($param); 19231da177e4SLinus Torvalds push_parameter($param, $type, $file); 19241da177e4SLinus Torvalds } 19251da177e4SLinus Torvalds } 19261da177e4SLinus Torvalds } 19271da177e4SLinus Torvalds } 19281da177e4SLinus Torvalds} 19291da177e4SLinus Torvalds 19301da177e4SLinus Torvaldssub push_parameter($$$) { 19311da177e4SLinus Torvalds my $param = shift; 19321da177e4SLinus Torvalds my $type = shift; 19331da177e4SLinus Torvalds my $file = shift; 19341da177e4SLinus Torvalds 19355f8c7c98SRandy Dunlap if (($anon_struct_union == 1) && ($type eq "") && 19365f8c7c98SRandy Dunlap ($param eq "}")) { 19375f8c7c98SRandy Dunlap return; # ignore the ending }; from anon. struct/union 19385f8c7c98SRandy Dunlap } 19395f8c7c98SRandy Dunlap 19405f8c7c98SRandy Dunlap $anon_struct_union = 0; 19411da177e4SLinus Torvalds my $param_name = $param; 19421da177e4SLinus Torvalds $param_name =~ s/\[.*//; 19431da177e4SLinus Torvalds 1944a6d3fe77SMartin Waitz if ($type eq "" && $param =~ /\.\.\.$/) 19451da177e4SLinus Torvalds { 1946ced69090SRandy Dunlap if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { 1947a6d3fe77SMartin Waitz $parameterdescs{$param} = "variable arguments"; 19481da177e4SLinus Torvalds } 1949ced69090SRandy Dunlap } 19501da177e4SLinus Torvalds elsif ($type eq "" && ($param eq "" or $param eq "void")) 19511da177e4SLinus Torvalds { 19521da177e4SLinus Torvalds $param="void"; 19531da177e4SLinus Torvalds $parameterdescs{void} = "no arguments"; 19541da177e4SLinus Torvalds } 1955134fe01bSRandy Dunlap elsif ($type eq "" && ($param eq "struct" or $param eq "union")) 1956134fe01bSRandy Dunlap # handle unnamed (anonymous) union or struct: 1957134fe01bSRandy Dunlap { 1958134fe01bSRandy Dunlap $type = $param; 1959134fe01bSRandy Dunlap $param = "{unnamed_" . $param . "}"; 1960134fe01bSRandy Dunlap $parameterdescs{$param} = "anonymous\n"; 19615f8c7c98SRandy Dunlap $anon_struct_union = 1; 1962134fe01bSRandy Dunlap } 1963134fe01bSRandy Dunlap 1964a6d3fe77SMartin Waitz # warn if parameter has no description 1965134fe01bSRandy Dunlap # (but ignore ones starting with # as these are not parameters 1966134fe01bSRandy Dunlap # but inline preprocessor statements); 1967134fe01bSRandy Dunlap # also ignore unnamed structs/unions; 19685f8c7c98SRandy Dunlap if (!$anon_struct_union) { 1969a6d3fe77SMartin Waitz if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) { 1970a6d3fe77SMartin Waitz 19711da177e4SLinus Torvalds $parameterdescs{$param_name} = $undescribed; 19721da177e4SLinus Torvalds 19731da177e4SLinus Torvalds if (($type eq 'function') || ($type eq 'enum')) { 19741da177e4SLinus Torvalds print STDERR "Warning(${file}:$.): Function parameter ". 19751da177e4SLinus Torvalds "or member '$param' not " . 19761da177e4SLinus Torvalds "described in '$declaration_name'\n"; 19771da177e4SLinus Torvalds } 19781da177e4SLinus Torvalds print STDERR "Warning(${file}:$.):" . 19791da177e4SLinus Torvalds " No description found for parameter '$param'\n"; 19801da177e4SLinus Torvalds ++$warnings; 19811da177e4SLinus Torvalds } 1982134fe01bSRandy Dunlap } 19831da177e4SLinus Torvalds 19842b35f4d9SRandy Dunlap $param = xml_escape($param); 19852b35f4d9SRandy Dunlap 198625985edcSLucas De Marchi # strip spaces from $param so that it is one continuous string 1987e34e7dbbSRandy Dunlap # on @parameterlist; 1988e34e7dbbSRandy Dunlap # this fixes a problem where check_sections() cannot find 1989e34e7dbbSRandy Dunlap # a parameter like "addr[6 + 2]" because it actually appears 1990e34e7dbbSRandy Dunlap # as "addr[6", "+", "2]" on the parameter list; 1991e34e7dbbSRandy Dunlap # but it's better to maintain the param string unchanged for output, 1992e34e7dbbSRandy Dunlap # so just weaken the string compare in check_sections() to ignore 1993e34e7dbbSRandy Dunlap # "[blah" in a parameter string; 1994e34e7dbbSRandy Dunlap ###$param =~ s/\s*//g; 19951da177e4SLinus Torvalds push @parameterlist, $param; 19961da177e4SLinus Torvalds $parametertypes{$param} = $type; 19971da177e4SLinus Torvalds} 19981da177e4SLinus Torvalds 1999a1d94aa5SRandy Dunlapsub check_sections($$$$$$) { 2000a1d94aa5SRandy Dunlap my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_; 2001a1d94aa5SRandy Dunlap my @sects = split ' ', $sectcheck; 2002a1d94aa5SRandy Dunlap my @prms = split ' ', $prmscheck; 2003a1d94aa5SRandy Dunlap my $err; 2004a1d94aa5SRandy Dunlap my ($px, $sx); 2005a1d94aa5SRandy Dunlap my $prm_clean; # strip trailing "[array size]" and/or beginning "*" 2006a1d94aa5SRandy Dunlap 2007a1d94aa5SRandy Dunlap foreach $sx (0 .. $#sects) { 2008a1d94aa5SRandy Dunlap $err = 1; 2009a1d94aa5SRandy Dunlap foreach $px (0 .. $#prms) { 2010a1d94aa5SRandy Dunlap $prm_clean = $prms[$px]; 2011a1d94aa5SRandy Dunlap $prm_clean =~ s/\[.*\]//; 20121f3a6688SJohannes Berg $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; 2013e34e7dbbSRandy Dunlap # ignore array size in a parameter string; 2014e34e7dbbSRandy Dunlap # however, the original param string may contain 2015e34e7dbbSRandy Dunlap # spaces, e.g.: addr[6 + 2] 2016e34e7dbbSRandy Dunlap # and this appears in @prms as "addr[6" since the 2017e34e7dbbSRandy Dunlap # parameter list is split at spaces; 2018e34e7dbbSRandy Dunlap # hence just ignore "[..." for the sections check; 2019e34e7dbbSRandy Dunlap $prm_clean =~ s/\[.*//; 2020e34e7dbbSRandy Dunlap 2021a1d94aa5SRandy Dunlap ##$prm_clean =~ s/^\**//; 2022a1d94aa5SRandy Dunlap if ($prm_clean eq $sects[$sx]) { 2023a1d94aa5SRandy Dunlap $err = 0; 2024a1d94aa5SRandy Dunlap last; 2025a1d94aa5SRandy Dunlap } 2026a1d94aa5SRandy Dunlap } 2027a1d94aa5SRandy Dunlap if ($err) { 2028a1d94aa5SRandy Dunlap if ($decl_type eq "function") { 2029a1d94aa5SRandy Dunlap print STDERR "Warning(${file}:$.): " . 2030a1d94aa5SRandy Dunlap "Excess function parameter " . 2031a1d94aa5SRandy Dunlap "'$sects[$sx]' " . 2032a1d94aa5SRandy Dunlap "description in '$decl_name'\n"; 2033a1d94aa5SRandy Dunlap ++$warnings; 2034a1d94aa5SRandy Dunlap } else { 2035a1d94aa5SRandy Dunlap if ($nested !~ m/\Q$sects[$sx]\E/) { 2036a1d94aa5SRandy Dunlap print STDERR "Warning(${file}:$.): " . 2037a1d94aa5SRandy Dunlap "Excess struct/union/enum/typedef member " . 2038a1d94aa5SRandy Dunlap "'$sects[$sx]' " . 2039a1d94aa5SRandy Dunlap "description in '$decl_name'\n"; 2040a1d94aa5SRandy Dunlap ++$warnings; 2041a1d94aa5SRandy Dunlap } 2042a1d94aa5SRandy Dunlap } 2043a1d94aa5SRandy Dunlap } 2044a1d94aa5SRandy Dunlap } 2045a1d94aa5SRandy Dunlap} 2046a1d94aa5SRandy Dunlap 20471da177e4SLinus Torvalds## 20484092bac7SYacine Belkadi# Checks the section describing the return value of a function. 20494092bac7SYacine Belkadisub check_return_section { 20504092bac7SYacine Belkadi my $file = shift; 20514092bac7SYacine Belkadi my $declaration_name = shift; 20524092bac7SYacine Belkadi my $return_type = shift; 20534092bac7SYacine Belkadi 20544092bac7SYacine Belkadi # Ignore an empty return type (It's a macro) 20554092bac7SYacine Belkadi # Ignore functions with a "void" return type. (But don't ignore "void *") 20564092bac7SYacine Belkadi if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) { 20574092bac7SYacine Belkadi return; 20584092bac7SYacine Belkadi } 20594092bac7SYacine Belkadi 20604092bac7SYacine Belkadi if (!defined($sections{$section_return}) || 20614092bac7SYacine Belkadi $sections{$section_return} eq "") { 20624092bac7SYacine Belkadi print STDERR "Warning(${file}:$.): " . 20634092bac7SYacine Belkadi "No description found for return value of " . 20644092bac7SYacine Belkadi "'$declaration_name'\n"; 20654092bac7SYacine Belkadi ++$warnings; 20664092bac7SYacine Belkadi } 20674092bac7SYacine Belkadi} 20684092bac7SYacine Belkadi 20694092bac7SYacine Belkadi## 20701da177e4SLinus Torvalds# takes a function prototype and the name of the current file being 20711da177e4SLinus Torvalds# processed and spits out all the details stored in the global 20721da177e4SLinus Torvalds# arrays/hashes. 20731da177e4SLinus Torvaldssub dump_function($$) { 20741da177e4SLinus Torvalds my $prototype = shift; 20751da177e4SLinus Torvalds my $file = shift; 2076cbb4d3e6SHoria Geanta my $noret = 0; 20771da177e4SLinus Torvalds 20781da177e4SLinus Torvalds $prototype =~ s/^static +//; 20791da177e4SLinus Torvalds $prototype =~ s/^extern +//; 20804dc3b16bSPavel Pisa $prototype =~ s/^asmlinkage +//; 20811da177e4SLinus Torvalds $prototype =~ s/^inline +//; 20821da177e4SLinus Torvalds $prototype =~ s/^__inline__ +//; 208332e79401SRandy Dunlap $prototype =~ s/^__inline +//; 208432e79401SRandy Dunlap $prototype =~ s/^__always_inline +//; 208532e79401SRandy Dunlap $prototype =~ s/^noinline +//; 208674fc5c65SRandy Dunlap $prototype =~ s/__init +//; 208720072205SRandy Dunlap $prototype =~ s/__init_or_module +//; 2088270a0096SRandy Dunlap $prototype =~ s/__meminit +//; 208970c95b00SRandy Dunlap $prototype =~ s/__must_check +//; 20900df7c0e3SRandy Dunlap $prototype =~ s/__weak +//; 2091cbb4d3e6SHoria Geanta my $define = $prototype =~ s/^#\s*define\s+//; #ak added 2092328d2440SRandy Dunlap $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//; 20931da177e4SLinus Torvalds 20941da177e4SLinus Torvalds # Yes, this truly is vile. We are looking for: 20951da177e4SLinus Torvalds # 1. Return type (may be nothing if we're looking at a macro) 20961da177e4SLinus Torvalds # 2. Function name 20971da177e4SLinus Torvalds # 3. Function parameters. 20981da177e4SLinus Torvalds # 20991da177e4SLinus Torvalds # All the while we have to watch out for function pointer parameters 21001da177e4SLinus Torvalds # (which IIRC is what the two sections are for), C types (these 21011da177e4SLinus Torvalds # regexps don't even start to express all the possibilities), and 21021da177e4SLinus Torvalds # so on. 21031da177e4SLinus Torvalds # 21041da177e4SLinus Torvalds # If you mess with these regexps, it's a good idea to check that 21051da177e4SLinus Torvalds # the following functions' documentation still comes out right: 21061da177e4SLinus Torvalds # - parport_register_device (function pointer parameters) 21071da177e4SLinus Torvalds # - atomic_set (macro) 21089598f91fSMartin Waitz # - pci_match_device, __copy_to_user (long return type) 21091da177e4SLinus Torvalds 2110cbb4d3e6SHoria Geanta if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) { 2111cbb4d3e6SHoria Geanta # This is an object-like macro, it has no return type and no parameter 2112cbb4d3e6SHoria Geanta # list. 2113cbb4d3e6SHoria Geanta # Function-like macros are not allowed to have spaces between 2114cbb4d3e6SHoria Geanta # declaration_name and opening parenthesis (notice the \s+). 2115cbb4d3e6SHoria Geanta $return_type = $1; 2116cbb4d3e6SHoria Geanta $declaration_name = $2; 2117cbb4d3e6SHoria Geanta $noret = 1; 2118cbb4d3e6SHoria Geanta } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 21191da177e4SLinus Torvalds $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 21201da177e4SLinus Torvalds $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 21211da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 212294b3e03cSRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 21231da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 21241da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 21251da177e4SLinus Torvalds $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 21261da177e4SLinus Torvalds $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 21271da177e4SLinus Torvalds $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 21281da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 21291da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 21301da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 21319598f91fSMartin Waitz $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 21329598f91fSMartin Waitz $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 2133412ecd77SRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 2134412ecd77SRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) { 21351da177e4SLinus Torvalds $return_type = $1; 21361da177e4SLinus Torvalds $declaration_name = $2; 21371da177e4SLinus Torvalds my $args = $3; 21381da177e4SLinus Torvalds 21391da177e4SLinus Torvalds create_parameterlist($args, ',', $file); 21401da177e4SLinus Torvalds } else { 21419645ae84SRandy Dunlap print STDERR "Warning(${file}:$.): cannot understand function prototype: '$prototype'\n"; 21421da177e4SLinus Torvalds return; 21431da177e4SLinus Torvalds } 21441da177e4SLinus Torvalds 2145a1d94aa5SRandy Dunlap my $prms = join " ", @parameterlist; 2146a1d94aa5SRandy Dunlap check_sections($file, $declaration_name, "function", $sectcheck, $prms, ""); 2147a1d94aa5SRandy Dunlap 21484092bac7SYacine Belkadi # This check emits a lot of warnings at the moment, because many 21494092bac7SYacine Belkadi # functions don't have a 'Return' doc section. So until the number 21504092bac7SYacine Belkadi # of warnings goes sufficiently down, the check is only performed in 21514092bac7SYacine Belkadi # verbose mode. 21524092bac7SYacine Belkadi # TODO: always perform the check. 2153cbb4d3e6SHoria Geanta if ($verbose && !$noret) { 21544092bac7SYacine Belkadi check_return_section($file, $declaration_name, $return_type); 21554092bac7SYacine Belkadi } 21564092bac7SYacine Belkadi 21571da177e4SLinus Torvalds output_declaration($declaration_name, 21581da177e4SLinus Torvalds 'function', 21591da177e4SLinus Torvalds {'function' => $declaration_name, 21601da177e4SLinus Torvalds 'module' => $modulename, 21611da177e4SLinus Torvalds 'functiontype' => $return_type, 21621da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 21631da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 21641da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 21651da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 21661da177e4SLinus Torvalds 'sections' => \%sections, 21671da177e4SLinus Torvalds 'purpose' => $declaration_purpose 21681da177e4SLinus Torvalds }); 21691da177e4SLinus Torvalds} 21701da177e4SLinus Torvalds 21711da177e4SLinus Torvaldssub reset_state { 21721da177e4SLinus Torvalds $function = ""; 21731da177e4SLinus Torvalds %constants = (); 21741da177e4SLinus Torvalds %parameterdescs = (); 21751da177e4SLinus Torvalds %parametertypes = (); 21761da177e4SLinus Torvalds @parameterlist = (); 21771da177e4SLinus Torvalds %sections = (); 21781da177e4SLinus Torvalds @sectionlist = (); 2179a1d94aa5SRandy Dunlap $sectcheck = ""; 2180a1d94aa5SRandy Dunlap $struct_actual = ""; 21811da177e4SLinus Torvalds $prototype = ""; 21821da177e4SLinus Torvalds 21831da177e4SLinus Torvalds $state = 0; 21841da177e4SLinus Torvalds} 21851da177e4SLinus Torvalds 218656afb0f8SJason Baronsub tracepoint_munge($) { 218756afb0f8SJason Baron my $file = shift; 218856afb0f8SJason Baron my $tracepointname = 0; 218956afb0f8SJason Baron my $tracepointargs = 0; 219056afb0f8SJason Baron 219156afb0f8SJason Baron if ($prototype =~ m/TRACE_EVENT\((.*?),/) { 219256afb0f8SJason Baron $tracepointname = $1; 219356afb0f8SJason Baron } 21943a9089fdSJason Baron if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) { 21953a9089fdSJason Baron $tracepointname = $1; 21963a9089fdSJason Baron } 21973a9089fdSJason Baron if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) { 21983a9089fdSJason Baron $tracepointname = $2; 21993a9089fdSJason Baron } 22003a9089fdSJason Baron $tracepointname =~ s/^\s+//; #strip leading whitespace 220156afb0f8SJason Baron if ($prototype =~ m/TP_PROTO\((.*?)\)/) { 220256afb0f8SJason Baron $tracepointargs = $1; 220356afb0f8SJason Baron } 220456afb0f8SJason Baron if (($tracepointname eq 0) || ($tracepointargs eq 0)) { 220556afb0f8SJason Baron print STDERR "Warning(${file}:$.): Unrecognized tracepoint format: \n". 220656afb0f8SJason Baron "$prototype\n"; 220756afb0f8SJason Baron } else { 220856afb0f8SJason Baron $prototype = "static inline void trace_$tracepointname($tracepointargs)"; 220956afb0f8SJason Baron } 221056afb0f8SJason Baron} 221156afb0f8SJason Baron 2212b4870bc5SRandy Dunlapsub syscall_munge() { 2213b4870bc5SRandy Dunlap my $void = 0; 2214b4870bc5SRandy Dunlap 2215b4870bc5SRandy Dunlap $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs 2216b4870bc5SRandy Dunlap## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) { 2217b4870bc5SRandy Dunlap if ($prototype =~ m/SYSCALL_DEFINE0/) { 2218b4870bc5SRandy Dunlap $void = 1; 2219b4870bc5SRandy Dunlap## $prototype = "long sys_$1(void)"; 2220b4870bc5SRandy Dunlap } 2221b4870bc5SRandy Dunlap 2222b4870bc5SRandy Dunlap $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name 2223b4870bc5SRandy Dunlap if ($prototype =~ m/long (sys_.*?),/) { 2224b4870bc5SRandy Dunlap $prototype =~ s/,/\(/; 2225b4870bc5SRandy Dunlap } elsif ($void) { 2226b4870bc5SRandy Dunlap $prototype =~ s/\)/\(void\)/; 2227b4870bc5SRandy Dunlap } 2228b4870bc5SRandy Dunlap 2229b4870bc5SRandy Dunlap # now delete all of the odd-number commas in $prototype 2230b4870bc5SRandy Dunlap # so that arg types & arg names don't have a comma between them 2231b4870bc5SRandy Dunlap my $count = 0; 2232b4870bc5SRandy Dunlap my $len = length($prototype); 2233b4870bc5SRandy Dunlap if ($void) { 2234b4870bc5SRandy Dunlap $len = 0; # skip the for-loop 2235b4870bc5SRandy Dunlap } 2236b4870bc5SRandy Dunlap for (my $ix = 0; $ix < $len; $ix++) { 2237b4870bc5SRandy Dunlap if (substr($prototype, $ix, 1) eq ',') { 2238b4870bc5SRandy Dunlap $count++; 2239b4870bc5SRandy Dunlap if ($count % 2 == 1) { 2240b4870bc5SRandy Dunlap substr($prototype, $ix, 1) = ' '; 2241b4870bc5SRandy Dunlap } 2242b4870bc5SRandy Dunlap } 2243b4870bc5SRandy Dunlap } 2244b4870bc5SRandy Dunlap} 2245b4870bc5SRandy Dunlap 22461da177e4SLinus Torvaldssub process_state3_function($$) { 22471da177e4SLinus Torvalds my $x = shift; 22481da177e4SLinus Torvalds my $file = shift; 22491da177e4SLinus Torvalds 225051f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 225151f5a0c8SRandy Dunlap 2252890c78c2SRandy Dunlap if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) { 22531da177e4SLinus Torvalds # do nothing 22541da177e4SLinus Torvalds } 22551da177e4SLinus Torvalds elsif ($x =~ /([^\{]*)/) { 22561da177e4SLinus Torvalds $prototype .= $1; 22571da177e4SLinus Torvalds } 2258b4870bc5SRandy Dunlap 2259890c78c2SRandy Dunlap if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) { 22601da177e4SLinus Torvalds $prototype =~ s@/\*.*?\*/@@gos; # strip comments. 22611da177e4SLinus Torvalds $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 22621da177e4SLinus Torvalds $prototype =~ s@^\s+@@gos; # strip leading spaces 2263b4870bc5SRandy Dunlap if ($prototype =~ /SYSCALL_DEFINE/) { 2264b4870bc5SRandy Dunlap syscall_munge(); 2265b4870bc5SRandy Dunlap } 22663a9089fdSJason Baron if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ || 22673a9089fdSJason Baron $prototype =~ /DEFINE_SINGLE_EVENT/) 22683a9089fdSJason Baron { 226956afb0f8SJason Baron tracepoint_munge($file); 227056afb0f8SJason Baron } 22711da177e4SLinus Torvalds dump_function($prototype, $file); 22721da177e4SLinus Torvalds reset_state(); 22731da177e4SLinus Torvalds } 22741da177e4SLinus Torvalds} 22751da177e4SLinus Torvalds 22761da177e4SLinus Torvaldssub process_state3_type($$) { 22771da177e4SLinus Torvalds my $x = shift; 22781da177e4SLinus Torvalds my $file = shift; 22791da177e4SLinus Torvalds 22801da177e4SLinus Torvalds $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 22811da177e4SLinus Torvalds $x =~ s@^\s+@@gos; # strip leading spaces 22821da177e4SLinus Torvalds $x =~ s@\s+$@@gos; # strip trailing spaces 228351f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 228451f5a0c8SRandy Dunlap 22851da177e4SLinus Torvalds if ($x =~ /^#/) { 22861da177e4SLinus Torvalds # To distinguish preprocessor directive from regular declaration later. 22871da177e4SLinus Torvalds $x .= ";"; 22881da177e4SLinus Torvalds } 22891da177e4SLinus Torvalds 22901da177e4SLinus Torvalds while (1) { 22911da177e4SLinus Torvalds if ( $x =~ /([^{};]*)([{};])(.*)/ ) { 22921da177e4SLinus Torvalds $prototype .= $1 . $2; 22931da177e4SLinus Torvalds ($2 eq '{') && $brcount++; 22941da177e4SLinus Torvalds ($2 eq '}') && $brcount--; 22951da177e4SLinus Torvalds if (($2 eq ';') && ($brcount == 0)) { 22961da177e4SLinus Torvalds dump_declaration($prototype, $file); 22971da177e4SLinus Torvalds reset_state(); 22981da177e4SLinus Torvalds last; 22991da177e4SLinus Torvalds } 23001da177e4SLinus Torvalds $x = $3; 23011da177e4SLinus Torvalds } else { 23021da177e4SLinus Torvalds $prototype .= $x; 23031da177e4SLinus Torvalds last; 23041da177e4SLinus Torvalds } 23051da177e4SLinus Torvalds } 23061da177e4SLinus Torvalds} 23071da177e4SLinus Torvalds 23086b5b55f6SRandy Dunlap# xml_escape: replace <, >, and & in the text stream; 23096b5b55f6SRandy Dunlap# 23106b5b55f6SRandy Dunlap# however, formatting controls that are generated internally/locally in the 23116b5b55f6SRandy Dunlap# kernel-doc script are not escaped here; instead, they begin life like 23126b5b55f6SRandy Dunlap# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings 23136b5b55f6SRandy Dunlap# are converted to their mnemonic-expected output, without the 4 * '\' & ':', 23146b5b55f6SRandy Dunlap# just before actual output; (this is done by local_unescape()) 23151da177e4SLinus Torvaldssub xml_escape($) { 23161da177e4SLinus Torvalds my $text = shift; 2317ecfb251aSRandy Dunlap if (($output_mode eq "text") || ($output_mode eq "man")) { 2318ecfb251aSRandy Dunlap return $text; 2319ecfb251aSRandy Dunlap } 23201da177e4SLinus Torvalds $text =~ s/\&/\\\\\\amp;/g; 23211da177e4SLinus Torvalds $text =~ s/\</\\\\\\lt;/g; 23221da177e4SLinus Torvalds $text =~ s/\>/\\\\\\gt;/g; 23231da177e4SLinus Torvalds return $text; 23241da177e4SLinus Torvalds} 23251da177e4SLinus Torvalds 23266b5b55f6SRandy Dunlap# convert local escape strings to html 23276b5b55f6SRandy Dunlap# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes) 23286b5b55f6SRandy Dunlapsub local_unescape($) { 23296b5b55f6SRandy Dunlap my $text = shift; 23306b5b55f6SRandy Dunlap if (($output_mode eq "text") || ($output_mode eq "man")) { 23316b5b55f6SRandy Dunlap return $text; 23326b5b55f6SRandy Dunlap } 23336b5b55f6SRandy Dunlap $text =~ s/\\\\\\\\lt:/</g; 23346b5b55f6SRandy Dunlap $text =~ s/\\\\\\\\gt:/>/g; 23356b5b55f6SRandy Dunlap return $text; 23366b5b55f6SRandy Dunlap} 23376b5b55f6SRandy Dunlap 23381da177e4SLinus Torvaldssub process_file($) { 23392283a117SRandy Dunlap my $file; 23401da177e4SLinus Torvalds my $identifier; 23411da177e4SLinus Torvalds my $func; 2342a21217daSRandy Dunlap my $descr; 23436423133bSJohannes Weiner my $in_purpose = 0; 23441da177e4SLinus Torvalds my $initial_section_counter = $section_counter; 23451da177e4SLinus Torvalds 23462283a117SRandy Dunlap if (defined($ENV{'SRCTREE'})) { 23472283a117SRandy Dunlap $file = "$ENV{'SRCTREE'}" . "/" . "@_"; 23482283a117SRandy Dunlap } 23492283a117SRandy Dunlap else { 23502283a117SRandy Dunlap $file = "@_"; 23512283a117SRandy Dunlap } 23521da177e4SLinus Torvalds if (defined($source_map{$file})) { 23531da177e4SLinus Torvalds $file = $source_map{$file}; 23541da177e4SLinus Torvalds } 23551da177e4SLinus Torvalds 23561da177e4SLinus Torvalds if (!open(IN,"<$file")) { 23571da177e4SLinus Torvalds print STDERR "Error: Cannot open file $file\n"; 23581da177e4SLinus Torvalds ++$errors; 23591da177e4SLinus Torvalds return; 23601da177e4SLinus Torvalds } 23611da177e4SLinus Torvalds 2362a9e7314bSIlya Dryomov $. = 1; 2363a9e7314bSIlya Dryomov 23641da177e4SLinus Torvalds $section_counter = 0; 23651da177e4SLinus Torvalds while (<IN>) { 236665478428SDaniel Santos while (s/\\\s*$//) { 236765478428SDaniel Santos $_ .= <IN>; 236865478428SDaniel Santos } 23691da177e4SLinus Torvalds if ($state == 0) { 23701da177e4SLinus Torvalds if (/$doc_start/o) { 23711da177e4SLinus Torvalds $state = 1; # next line is always the function name 2372850622dfSRandy Dunlap $in_doc_sect = 0; 23731da177e4SLinus Torvalds } 23741da177e4SLinus Torvalds } elsif ($state == 1) { # this line is the function name (always) 23751da177e4SLinus Torvalds if (/$doc_block/o) { 23761da177e4SLinus Torvalds $state = 4; 23771da177e4SLinus Torvalds $contents = ""; 23781da177e4SLinus Torvalds if ( $1 eq "" ) { 23791da177e4SLinus Torvalds $section = $section_intro; 23801da177e4SLinus Torvalds } else { 23811da177e4SLinus Torvalds $section = $1; 23821da177e4SLinus Torvalds } 23831da177e4SLinus Torvalds } 23841da177e4SLinus Torvalds elsif (/$doc_decl/o) { 23851da177e4SLinus Torvalds $identifier = $1; 23861da177e4SLinus Torvalds if (/\s*([\w\s]+?)\s*-/) { 23871da177e4SLinus Torvalds $identifier = $1; 23881da177e4SLinus Torvalds } 23891da177e4SLinus Torvalds 23901da177e4SLinus Torvalds $state = 2; 23911da177e4SLinus Torvalds if (/-(.*)/) { 239251f5a0c8SRandy Dunlap # strip leading/trailing/multiple spaces 2393a21217daSRandy Dunlap $descr= $1; 2394a21217daSRandy Dunlap $descr =~ s/^\s*//; 2395a21217daSRandy Dunlap $descr =~ s/\s*$//; 239612ae6779SDaniel Santos $descr =~ s/\s+/ /g; 2397a21217daSRandy Dunlap $declaration_purpose = xml_escape($descr); 23986423133bSJohannes Weiner $in_purpose = 1; 23991da177e4SLinus Torvalds } else { 24001da177e4SLinus Torvalds $declaration_purpose = ""; 24011da177e4SLinus Torvalds } 240277cc23b8SRandy Dunlap 240377cc23b8SRandy Dunlap if (($declaration_purpose eq "") && $verbose) { 240477cc23b8SRandy Dunlap print STDERR "Warning(${file}:$.): missing initial short description on line:\n"; 240577cc23b8SRandy Dunlap print STDERR $_; 240677cc23b8SRandy Dunlap ++$warnings; 240777cc23b8SRandy Dunlap } 240877cc23b8SRandy Dunlap 24091da177e4SLinus Torvalds if ($identifier =~ m/^struct/) { 24101da177e4SLinus Torvalds $decl_type = 'struct'; 24111da177e4SLinus Torvalds } elsif ($identifier =~ m/^union/) { 24121da177e4SLinus Torvalds $decl_type = 'union'; 24131da177e4SLinus Torvalds } elsif ($identifier =~ m/^enum/) { 24141da177e4SLinus Torvalds $decl_type = 'enum'; 24151da177e4SLinus Torvalds } elsif ($identifier =~ m/^typedef/) { 24161da177e4SLinus Torvalds $decl_type = 'typedef'; 24171da177e4SLinus Torvalds } else { 24181da177e4SLinus Torvalds $decl_type = 'function'; 24191da177e4SLinus Torvalds } 24201da177e4SLinus Torvalds 24211da177e4SLinus Torvalds if ($verbose) { 24221da177e4SLinus Torvalds print STDERR "Info(${file}:$.): Scanning doc for $identifier\n"; 24231da177e4SLinus Torvalds } 24241da177e4SLinus Torvalds } else { 24251da177e4SLinus Torvalds print STDERR "Warning(${file}:$.): Cannot understand $_ on line $.", 24261da177e4SLinus Torvalds " - I thought it was a doc line\n"; 24271da177e4SLinus Torvalds ++$warnings; 24281da177e4SLinus Torvalds $state = 0; 24291da177e4SLinus Torvalds } 24301da177e4SLinus Torvalds } elsif ($state == 2) { # look for head: lines, and include content 24311da177e4SLinus Torvalds if (/$doc_sect/o) { 24321da177e4SLinus Torvalds $newsection = $1; 24331da177e4SLinus Torvalds $newcontents = $2; 24341da177e4SLinus Torvalds 2435792aa2f2SRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 2436850622dfSRandy Dunlap if (!$in_doc_sect && $verbose) { 2437850622dfSRandy Dunlap print STDERR "Warning(${file}:$.): contents before sections\n"; 2438850622dfSRandy Dunlap ++$warnings; 2439850622dfSRandy Dunlap } 244094dc7ad5SRandy Dunlap dump_section($file, $section, xml_escape($contents)); 24411da177e4SLinus Torvalds $section = $section_default; 24421da177e4SLinus Torvalds } 24431da177e4SLinus Torvalds 2444850622dfSRandy Dunlap $in_doc_sect = 1; 24456423133bSJohannes Weiner $in_purpose = 0; 24461da177e4SLinus Torvalds $contents = $newcontents; 24471da177e4SLinus Torvalds if ($contents ne "") { 244827205744SRandy Dunlap while ((substr($contents, 0, 1) eq " ") || 244927205744SRandy Dunlap substr($contents, 0, 1) eq "\t") { 245005189497SRandy Dunlap $contents = substr($contents, 1); 245105189497SRandy Dunlap } 24521da177e4SLinus Torvalds $contents .= "\n"; 24531da177e4SLinus Torvalds } 24541da177e4SLinus Torvalds $section = $newsection; 24551da177e4SLinus Torvalds } elsif (/$doc_end/) { 24561da177e4SLinus Torvalds 24574c98ecafSRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 245894dc7ad5SRandy Dunlap dump_section($file, $section, xml_escape($contents)); 24591da177e4SLinus Torvalds $section = $section_default; 24601da177e4SLinus Torvalds $contents = ""; 24611da177e4SLinus Torvalds } 246246b958ebSRandy Dunlap # look for doc_com + <text> + doc_end: 246346b958ebSRandy Dunlap if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') { 246446b958ebSRandy Dunlap print STDERR "Warning(${file}:$.): suspicious ending line: $_"; 246546b958ebSRandy Dunlap ++$warnings; 246646b958ebSRandy Dunlap } 24671da177e4SLinus Torvalds 24681da177e4SLinus Torvalds $prototype = ""; 24691da177e4SLinus Torvalds $state = 3; 24701da177e4SLinus Torvalds $brcount = 0; 24711da177e4SLinus Torvalds# print STDERR "end of doc comment, looking for prototype\n"; 24721da177e4SLinus Torvalds } elsif (/$doc_content/) { 24731da177e4SLinus Torvalds # miguel-style comment kludge, look for blank lines after 24741da177e4SLinus Torvalds # @parameter line to signify start of description 24756423133bSJohannes Weiner if ($1 eq "") { 24766423133bSJohannes Weiner if ($section =~ m/^@/ || $section eq $section_context) { 247794dc7ad5SRandy Dunlap dump_section($file, $section, xml_escape($contents)); 24781da177e4SLinus Torvalds $section = $section_default; 24791da177e4SLinus Torvalds $contents = ""; 24801da177e4SLinus Torvalds } else { 24816423133bSJohannes Weiner $contents .= "\n"; 24826423133bSJohannes Weiner } 24836423133bSJohannes Weiner $in_purpose = 0; 24846423133bSJohannes Weiner } elsif ($in_purpose == 1) { 24856423133bSJohannes Weiner # Continued declaration purpose 24866423133bSJohannes Weiner chomp($declaration_purpose); 24876423133bSJohannes Weiner $declaration_purpose .= " " . xml_escape($1); 248812ae6779SDaniel Santos $declaration_purpose =~ s/\s+/ /g; 24896423133bSJohannes Weiner } else { 24901da177e4SLinus Torvalds $contents .= $1 . "\n"; 24911da177e4SLinus Torvalds } 24921da177e4SLinus Torvalds } else { 24931da177e4SLinus Torvalds # i dont know - bad line? ignore. 24941da177e4SLinus Torvalds print STDERR "Warning(${file}:$.): bad line: $_"; 24951da177e4SLinus Torvalds ++$warnings; 24961da177e4SLinus Torvalds } 2497232acbcfSRandy Dunlap } elsif ($state == 3) { # scanning for function '{' (end of prototype) 24981da177e4SLinus Torvalds if ($decl_type eq 'function') { 24991da177e4SLinus Torvalds process_state3_function($_, $file); 25001da177e4SLinus Torvalds } else { 25011da177e4SLinus Torvalds process_state3_type($_, $file); 25021da177e4SLinus Torvalds } 25031da177e4SLinus Torvalds } elsif ($state == 4) { 25041da177e4SLinus Torvalds # Documentation block 25051da177e4SLinus Torvalds if (/$doc_block/) { 250694dc7ad5SRandy Dunlap dump_doc_section($file, $section, xml_escape($contents)); 25071da177e4SLinus Torvalds $contents = ""; 25081da177e4SLinus Torvalds $function = ""; 25091da177e4SLinus Torvalds %constants = (); 25101da177e4SLinus Torvalds %parameterdescs = (); 25111da177e4SLinus Torvalds %parametertypes = (); 25121da177e4SLinus Torvalds @parameterlist = (); 25131da177e4SLinus Torvalds %sections = (); 25141da177e4SLinus Torvalds @sectionlist = (); 25151da177e4SLinus Torvalds $prototype = ""; 25161da177e4SLinus Torvalds if ( $1 eq "" ) { 25171da177e4SLinus Torvalds $section = $section_intro; 25181da177e4SLinus Torvalds } else { 25191da177e4SLinus Torvalds $section = $1; 25201da177e4SLinus Torvalds } 25211da177e4SLinus Torvalds } 25221da177e4SLinus Torvalds elsif (/$doc_end/) 25231da177e4SLinus Torvalds { 252494dc7ad5SRandy Dunlap dump_doc_section($file, $section, xml_escape($contents)); 25251da177e4SLinus Torvalds $contents = ""; 25261da177e4SLinus Torvalds $function = ""; 25271da177e4SLinus Torvalds %constants = (); 25281da177e4SLinus Torvalds %parameterdescs = (); 25291da177e4SLinus Torvalds %parametertypes = (); 25301da177e4SLinus Torvalds @parameterlist = (); 25311da177e4SLinus Torvalds %sections = (); 25321da177e4SLinus Torvalds @sectionlist = (); 25331da177e4SLinus Torvalds $prototype = ""; 25341da177e4SLinus Torvalds $state = 0; 25351da177e4SLinus Torvalds } 25361da177e4SLinus Torvalds elsif (/$doc_content/) 25371da177e4SLinus Torvalds { 25381da177e4SLinus Torvalds if ( $1 eq "" ) 25391da177e4SLinus Torvalds { 25401da177e4SLinus Torvalds $contents .= $blankline; 25411da177e4SLinus Torvalds } 25421da177e4SLinus Torvalds else 25431da177e4SLinus Torvalds { 25441da177e4SLinus Torvalds $contents .= $1 . "\n"; 25451da177e4SLinus Torvalds } 25461da177e4SLinus Torvalds } 25471da177e4SLinus Torvalds } 25481da177e4SLinus Torvalds } 25491da177e4SLinus Torvalds if ($initial_section_counter == $section_counter) { 25501da177e4SLinus Torvalds print STDERR "Warning(${file}): no structured comments found\n"; 2551e946c43aSJohannes Berg if (($function_only == 1) && ($show_not_found == 1)) { 2552e946c43aSJohannes Berg print STDERR " Was looking for '$_'.\n" for keys %function_table; 2553e946c43aSJohannes Berg } 25541da177e4SLinus Torvalds if ($output_mode eq "xml") { 25551da177e4SLinus Torvalds # The template wants at least one RefEntry here; make one. 25561da177e4SLinus Torvalds print "<refentry>\n"; 25571da177e4SLinus Torvalds print " <refnamediv>\n"; 25581da177e4SLinus Torvalds print " <refname>\n"; 25591da177e4SLinus Torvalds print " ${file}\n"; 25601da177e4SLinus Torvalds print " </refname>\n"; 25611da177e4SLinus Torvalds print " <refpurpose>\n"; 25621da177e4SLinus Torvalds print " Document generation inconsistency\n"; 25631da177e4SLinus Torvalds print " </refpurpose>\n"; 25641da177e4SLinus Torvalds print " </refnamediv>\n"; 25651da177e4SLinus Torvalds print " <refsect1>\n"; 25661da177e4SLinus Torvalds print " <title>\n"; 25671da177e4SLinus Torvalds print " Oops\n"; 25681da177e4SLinus Torvalds print " </title>\n"; 25691da177e4SLinus Torvalds print " <warning>\n"; 25701da177e4SLinus Torvalds print " <para>\n"; 25711da177e4SLinus Torvalds print " The template for this document tried to insert\n"; 25721da177e4SLinus Torvalds print " the structured comment from the file\n"; 25731da177e4SLinus Torvalds print " <filename>${file}</filename> at this point,\n"; 25741da177e4SLinus Torvalds print " but none was found.\n"; 25751da177e4SLinus Torvalds print " This dummy section is inserted to allow\n"; 25761da177e4SLinus Torvalds print " generation to continue.\n"; 25771da177e4SLinus Torvalds print " </para>\n"; 25781da177e4SLinus Torvalds print " </warning>\n"; 25791da177e4SLinus Torvalds print " </refsect1>\n"; 25801da177e4SLinus Torvalds print "</refentry>\n"; 25811da177e4SLinus Torvalds } 25821da177e4SLinus Torvalds } 25831da177e4SLinus Torvalds} 25848484baaaSRandy Dunlap 25858484baaaSRandy Dunlap 25868484baaaSRandy Dunlap$kernelversion = get_kernel_version(); 25878484baaaSRandy Dunlap 25888484baaaSRandy Dunlap# generate a sequence of code that will splice in highlighting information 25898484baaaSRandy Dunlap# using the s// operator. 25908484baaaSRandy Dunlapforeach my $pattern (keys %highlights) { 25918484baaaSRandy Dunlap# print STDERR "scanning pattern:$pattern, highlight:($highlights{$pattern})\n"; 25928484baaaSRandy Dunlap $dohighlight .= "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n"; 25938484baaaSRandy Dunlap} 25948484baaaSRandy Dunlap 25958484baaaSRandy Dunlap# Read the file that maps relative names to absolute names for 25968484baaaSRandy Dunlap# separate source and object directories and for shadow trees. 25978484baaaSRandy Dunlapif (open(SOURCE_MAP, "<.tmp_filelist.txt")) { 25988484baaaSRandy Dunlap my ($relname, $absname); 25998484baaaSRandy Dunlap while(<SOURCE_MAP>) { 26008484baaaSRandy Dunlap chop(); 26018484baaaSRandy Dunlap ($relname, $absname) = (split())[0..1]; 26028484baaaSRandy Dunlap $relname =~ s:^/+::; 26038484baaaSRandy Dunlap $source_map{$relname} = $absname; 26048484baaaSRandy Dunlap } 26058484baaaSRandy Dunlap close(SOURCE_MAP); 26068484baaaSRandy Dunlap} 26078484baaaSRandy Dunlap 26088484baaaSRandy Dunlapforeach (@ARGV) { 26098484baaaSRandy Dunlap chomp; 26108484baaaSRandy Dunlap process_file($_); 26118484baaaSRandy Dunlap} 26128484baaaSRandy Dunlapif ($verbose && $errors) { 26138484baaaSRandy Dunlap print STDERR "$errors errors\n"; 26148484baaaSRandy Dunlap} 26158484baaaSRandy Dunlapif ($verbose && $warnings) { 26168484baaaSRandy Dunlap print STDERR "$warnings warnings\n"; 26178484baaaSRandy Dunlap} 26188484baaaSRandy Dunlap 26198484baaaSRandy Dunlapexit($errors); 2620