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 ## 8b9d97328SRandy Dunlap## Copyright (C) 2005-2009 Randy Dunlap ## 91da177e4SLinus Torvalds## ## 101da177e4SLinus Torvalds## #define enhancements by Armin Kuster <akuster@mvista.com> ## 111da177e4SLinus Torvalds## Copyright (c) 2000 MontaVista Software, Inc. ## 121da177e4SLinus Torvalds## ## 131da177e4SLinus Torvalds## This software falls under the GNU General Public License. ## 141da177e4SLinus Torvalds## Please read the COPYING file for more information ## 151da177e4SLinus Torvalds 161da177e4SLinus Torvalds# w.o. 03-11-2000: added the '-filelist' option. 171da177e4SLinus Torvalds 181da177e4SLinus Torvalds# 18/01/2001 - Cleanups 191da177e4SLinus Torvalds# Functions prototyped as foo(void) same as foo() 201da177e4SLinus Torvalds# Stop eval'ing where we don't need to. 211da177e4SLinus Torvalds# -- huggie@earth.li 221da177e4SLinus Torvalds 231da177e4SLinus Torvalds# 27/06/2001 - Allowed whitespace after initial "/**" and 241da177e4SLinus Torvalds# allowed comments before function declarations. 251da177e4SLinus Torvalds# -- Christian Kreibich <ck@whoop.org> 261da177e4SLinus Torvalds 271da177e4SLinus Torvalds# Still to do: 281da177e4SLinus Torvalds# - add perldoc documentation 291da177e4SLinus Torvalds# - Look more closely at some of the scarier bits :) 301da177e4SLinus Torvalds 311da177e4SLinus Torvalds# 26/05/2001 - Support for separate source and object trees. 321da177e4SLinus Torvalds# Return error code. 331da177e4SLinus Torvalds# Keith Owens <kaos@ocs.com.au> 341da177e4SLinus Torvalds 351da177e4SLinus Torvalds# 23/09/2001 - Added support for typedefs, structs, enums and unions 361da177e4SLinus Torvalds# Support for Context section; can be terminated using empty line 371da177e4SLinus Torvalds# Small fixes (like spaces vs. \s in regex) 381da177e4SLinus Torvalds# -- Tim Jansen <tim@tjansen.de> 391da177e4SLinus Torvalds 401da177e4SLinus Torvalds 411da177e4SLinus Torvalds# 421da177e4SLinus Torvalds# This will read a 'c' file and scan for embedded comments in the 431da177e4SLinus Torvalds# style of gnome comments (+minor extensions - see below). 441da177e4SLinus Torvalds# 451da177e4SLinus Torvalds 461da177e4SLinus Torvalds# Note: This only supports 'c'. 471da177e4SLinus Torvalds 481da177e4SLinus Torvalds# usage: 494b44595aSJohannes Berg# kernel-doc [ -docbook | -html | -text | -man ] [ -no-doc-sections ] 501da177e4SLinus Torvalds# [ -function funcname [ -function funcname ...] ] c file(s)s > outputfile 511da177e4SLinus Torvalds# or 521da177e4SLinus Torvalds# [ -nofunction funcname [ -function funcname ...] ] c file(s)s > outputfile 531da177e4SLinus Torvalds# 541da177e4SLinus Torvalds# Set output format using one of -docbook -html -text or -man. Default is man. 551da177e4SLinus Torvalds# 564b44595aSJohannes Berg# -no-doc-sections 574b44595aSJohannes Berg# Do not output DOC: sections 584b44595aSJohannes Berg# 591da177e4SLinus Torvalds# -function funcname 60b112e0f7SJohannes Berg# If set, then only generate documentation for the given function(s) or 61b112e0f7SJohannes Berg# DOC: section titles. All other functions and DOC: sections are ignored. 621da177e4SLinus Torvalds# 631da177e4SLinus Torvalds# -nofunction funcname 64b112e0f7SJohannes Berg# If set, then only generate documentation for the other function(s)/DOC: 65b112e0f7SJohannes Berg# sections. Cannot be used together with -function (yes, that's a bug -- 66b112e0f7SJohannes Berg# perl hackers can fix it 8)) 671da177e4SLinus Torvalds# 681da177e4SLinus Torvalds# c files - list of 'c' files to process 691da177e4SLinus Torvalds# 701da177e4SLinus Torvalds# All output goes to stdout, with errors to stderr. 711da177e4SLinus Torvalds 721da177e4SLinus Torvalds# 731da177e4SLinus Torvalds# format of comments. 741da177e4SLinus Torvalds# In the following table, (...)? signifies optional structure. 751da177e4SLinus Torvalds# (...)* signifies 0 or more structure elements 761da177e4SLinus Torvalds# /** 771da177e4SLinus Torvalds# * function_name(:)? (- short description)? 781da177e4SLinus Torvalds# (* @parameterx: (description of parameter x)?)* 791da177e4SLinus Torvalds# (* a blank line)? 801da177e4SLinus Torvalds# * (Description:)? (Description of function)? 811da177e4SLinus Torvalds# * (section header: (section description)? )* 821da177e4SLinus Torvalds# (*)?*/ 831da177e4SLinus Torvalds# 841da177e4SLinus Torvalds# So .. the trivial example would be: 851da177e4SLinus Torvalds# 861da177e4SLinus Torvalds# /** 871da177e4SLinus Torvalds# * my_function 88b9d97328SRandy Dunlap# */ 891da177e4SLinus Torvalds# 90891dcd2fSRandy Dunlap# If the Description: header tag is omitted, then there must be a blank line 911da177e4SLinus Torvalds# after the last parameter specification. 921da177e4SLinus Torvalds# e.g. 931da177e4SLinus Torvalds# /** 941da177e4SLinus Torvalds# * my_function - does my stuff 951da177e4SLinus Torvalds# * @my_arg: its mine damnit 961da177e4SLinus Torvalds# * 971da177e4SLinus Torvalds# * Does my stuff explained. 981da177e4SLinus Torvalds# */ 991da177e4SLinus Torvalds# 1001da177e4SLinus Torvalds# or, could also use: 1011da177e4SLinus Torvalds# /** 1021da177e4SLinus Torvalds# * my_function - does my stuff 1031da177e4SLinus Torvalds# * @my_arg: its mine damnit 1041da177e4SLinus Torvalds# * Description: Does my stuff explained. 1051da177e4SLinus Torvalds# */ 1061da177e4SLinus Torvalds# etc. 1071da177e4SLinus Torvalds# 108b9d97328SRandy Dunlap# Besides functions you can also write documentation for structs, unions, 1091da177e4SLinus Torvalds# enums and typedefs. Instead of the function name you must write the name 1101da177e4SLinus Torvalds# of the declaration; the struct/union/enum/typedef must always precede 1111da177e4SLinus Torvalds# the name. Nesting of declarations is not supported. 1121da177e4SLinus Torvalds# Use the argument mechanism to document members or constants. 1131da177e4SLinus Torvalds# e.g. 1141da177e4SLinus Torvalds# /** 1151da177e4SLinus Torvalds# * struct my_struct - short description 1161da177e4SLinus Torvalds# * @a: first member 1171da177e4SLinus Torvalds# * @b: second member 1181da177e4SLinus Torvalds# * 1191da177e4SLinus Torvalds# * Longer description 1201da177e4SLinus Torvalds# */ 1211da177e4SLinus Torvalds# struct my_struct { 1221da177e4SLinus Torvalds# int a; 1231da177e4SLinus Torvalds# int b; 124aeec46b9SMartin Waitz# /* private: */ 125aeec46b9SMartin Waitz# int c; 1261da177e4SLinus Torvalds# }; 1271da177e4SLinus Torvalds# 1281da177e4SLinus Torvalds# All descriptions can be multiline, except the short function description. 1291da177e4SLinus Torvalds# 1301da177e4SLinus Torvalds# You can also add additional sections. When documenting kernel functions you 1311da177e4SLinus Torvalds# should document the "Context:" of the function, e.g. whether the functions 1321da177e4SLinus Torvalds# can be called form interrupts. Unlike other sections you can end it with an 1331da177e4SLinus Torvalds# empty line. 1341da177e4SLinus Torvalds# Example-sections should contain the string EXAMPLE so that they are marked 1351da177e4SLinus Torvalds# appropriately in DocBook. 1361da177e4SLinus Torvalds# 1371da177e4SLinus Torvalds# Example: 1381da177e4SLinus Torvalds# /** 1391da177e4SLinus Torvalds# * user_function - function that can only be called in user context 1401da177e4SLinus Torvalds# * @a: some argument 1411da177e4SLinus Torvalds# * Context: !in_interrupt() 1421da177e4SLinus Torvalds# * 1431da177e4SLinus Torvalds# * Some description 1441da177e4SLinus Torvalds# * Example: 1451da177e4SLinus Torvalds# * user_function(22); 1461da177e4SLinus Torvalds# */ 1471da177e4SLinus Torvalds# ... 1481da177e4SLinus Torvalds# 1491da177e4SLinus Torvalds# 1501da177e4SLinus Torvalds# All descriptive text is further processed, scanning for the following special 1511da177e4SLinus Torvalds# patterns, which are highlighted appropriately. 1521da177e4SLinus Torvalds# 1531da177e4SLinus Torvalds# 'funcname()' - function 1541da177e4SLinus Torvalds# '$ENVVAR' - environmental variable 1551da177e4SLinus Torvalds# '&struct_name' - name of a structure (up to two words including 'struct') 1561da177e4SLinus Torvalds# '@parameter' - name of a parameter 1571da177e4SLinus Torvalds# '%CONST' - name of a constant. 1581da177e4SLinus Torvalds 1591da177e4SLinus Torvaldsmy $errors = 0; 1601da177e4SLinus Torvaldsmy $warnings = 0; 1615f8c7c98SRandy Dunlapmy $anon_struct_union = 0; 1621da177e4SLinus Torvalds 1631da177e4SLinus Torvalds# match expressions used to find embedded type information 1641da177e4SLinus Torvaldsmy $type_constant = '\%([-_\w]+)'; 1651da177e4SLinus Torvaldsmy $type_func = '(\w+)\(\)'; 1661da177e4SLinus Torvaldsmy $type_param = '\@(\w+)'; 1673eb014a1SRandy Dunlapmy $type_struct = '\&((struct\s*)*[_\w]+)'; 1686b5b55f6SRandy Dunlapmy $type_struct_xml = '\\&((struct\s*)*[_\w]+)'; 1691da177e4SLinus Torvaldsmy $type_env = '(\$\w+)'; 1701da177e4SLinus Torvalds 1711da177e4SLinus Torvalds# Output conversion substitutions. 1721da177e4SLinus Torvalds# One for each output format 1731da177e4SLinus Torvalds 1741da177e4SLinus Torvalds# these work fairly well 1751da177e4SLinus Torvaldsmy %highlights_html = ( $type_constant, "<i>\$1</i>", 1761da177e4SLinus Torvalds $type_func, "<b>\$1</b>", 1773eb014a1SRandy Dunlap $type_struct_xml, "<i>\$1</i>", 1783eb014a1SRandy Dunlap $type_env, "<b><i>\$1</i></b>", 1791da177e4SLinus Torvalds $type_param, "<tt><b>\$1</b></tt>" ); 1806b5b55f6SRandy Dunlapmy $local_lt = "\\\\\\\\lt:"; 1816b5b55f6SRandy Dunlapmy $local_gt = "\\\\\\\\gt:"; 1826b5b55f6SRandy Dunlapmy $blankline_html = $local_lt . "p" . $local_gt; # was "<p>" 1831da177e4SLinus Torvalds 1841da177e4SLinus Torvalds# XML, docbook format 1851da177e4SLinus Torvaldsmy %highlights_xml = ( "([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>", 1861da177e4SLinus Torvalds $type_constant, "<constant>\$1</constant>", 1871da177e4SLinus Torvalds $type_func, "<function>\$1</function>", 1885c98fc03SJohannes Berg $type_struct_xml, "<structname>\$1</structname>", 1891da177e4SLinus Torvalds $type_env, "<envar>\$1</envar>", 1901da177e4SLinus Torvalds $type_param, "<parameter>\$1</parameter>" ); 1915c98fc03SJohannes Bergmy $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n"; 1921da177e4SLinus Torvalds 1931da177e4SLinus Torvalds# gnome, docbook format 1941da177e4SLinus Torvaldsmy %highlights_gnome = ( $type_constant, "<replaceable class=\"option\">\$1</replaceable>", 1951da177e4SLinus Torvalds $type_func, "<function>\$1</function>", 1961da177e4SLinus Torvalds $type_struct, "<structname>\$1</structname>", 1971da177e4SLinus Torvalds $type_env, "<envar>\$1</envar>", 1981da177e4SLinus Torvalds $type_param, "<parameter>\$1</parameter>" ); 1991da177e4SLinus Torvaldsmy $blankline_gnome = "</para><para>\n"; 2001da177e4SLinus Torvalds 2011da177e4SLinus Torvalds# these are pretty rough 2021da177e4SLinus Torvaldsmy %highlights_man = ( $type_constant, "\$1", 2031da177e4SLinus Torvalds $type_func, "\\\\fB\$1\\\\fP", 2041da177e4SLinus Torvalds $type_struct, "\\\\fI\$1\\\\fP", 2051da177e4SLinus Torvalds $type_param, "\\\\fI\$1\\\\fP" ); 2061da177e4SLinus Torvaldsmy $blankline_man = ""; 2071da177e4SLinus Torvalds 2081da177e4SLinus Torvalds# text-mode 2091da177e4SLinus Torvaldsmy %highlights_text = ( $type_constant, "\$1", 2101da177e4SLinus Torvalds $type_func, "\$1", 2111da177e4SLinus Torvalds $type_struct, "\$1", 2121da177e4SLinus Torvalds $type_param, "\$1" ); 2131da177e4SLinus Torvaldsmy $blankline_text = ""; 2141da177e4SLinus Torvalds 2151da177e4SLinus Torvalds 2161da177e4SLinus Torvaldssub usage { 2174b44595aSJohannes Berg print "Usage: $0 [ -v ] [ -docbook | -html | -text | -man ] [ -no-doc-sections ]\n"; 2181da177e4SLinus Torvalds print " [ -function funcname [ -function funcname ...] ]\n"; 2191da177e4SLinus Torvalds print " [ -nofunction funcname [ -nofunction funcname ...] ]\n"; 2201da177e4SLinus Torvalds print " c source file(s) > outputfile\n"; 22177cc23b8SRandy Dunlap print " -v : verbose output, more warnings & other info listed\n"; 2221da177e4SLinus Torvalds exit 1; 2231da177e4SLinus Torvalds} 2241da177e4SLinus Torvalds 2251da177e4SLinus Torvalds# read arguments 2261da177e4SLinus Torvaldsif ($#ARGV == -1) { 2271da177e4SLinus Torvalds usage(); 2281da177e4SLinus Torvalds} 2291da177e4SLinus Torvalds 2301da177e4SLinus Torvaldsmy $verbose = 0; 2311da177e4SLinus Torvaldsmy $output_mode = "man"; 2324b44595aSJohannes Bergmy $no_doc_sections = 0; 2331da177e4SLinus Torvaldsmy %highlights = %highlights_man; 2341da177e4SLinus Torvaldsmy $blankline = $blankline_man; 2351da177e4SLinus Torvaldsmy $modulename = "Kernel API"; 2361da177e4SLinus Torvaldsmy $function_only = 0; 2371da177e4SLinus Torvaldsmy $man_date = ('January', 'February', 'March', 'April', 'May', 'June', 2381da177e4SLinus Torvalds 'July', 'August', 'September', 'October', 2391da177e4SLinus Torvalds 'November', 'December')[(localtime)[4]] . 2401da177e4SLinus Torvalds " " . ((localtime)[5]+1900); 2411da177e4SLinus Torvalds 2421da177e4SLinus Torvalds# Essentially these are globals 243b9d97328SRandy Dunlap# They probably want to be tidied up, made more localised or something. 244b9d97328SRandy Dunlap# CAVEAT EMPTOR! Some of the others I localised may not want to be, which 2451da177e4SLinus Torvalds# could cause "use of undefined value" or other bugs. 2461da177e4SLinus Torvaldsmy ($function, %function_table, %parametertypes, $declaration_purpose); 2471da177e4SLinus Torvaldsmy ($type, $declaration_name, $return_type); 2481da177e4SLinus Torvaldsmy ($newsection, $newcontents, $prototype, $filelist, $brcount, %source_map); 2491da177e4SLinus Torvalds 250bd0e88e5SRandy Dunlapif (defined($ENV{'KBUILD_VERBOSE'})) { 251bd0e88e5SRandy Dunlap $verbose = "$ENV{'KBUILD_VERBOSE'}"; 252bd0e88e5SRandy Dunlap} 253bd0e88e5SRandy Dunlap 2541da177e4SLinus Torvalds# Generated docbook code is inserted in a template at a point where 2551da177e4SLinus Torvalds# docbook v3.1 requires a non-zero sequence of RefEntry's; see: 2561da177e4SLinus Torvalds# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html 2571da177e4SLinus Torvalds# We keep track of number of generated entries and generate a dummy 2581da177e4SLinus Torvalds# if needs be to ensure the expanded template can be postprocessed 2591da177e4SLinus Torvalds# into html. 2601da177e4SLinus Torvaldsmy $section_counter = 0; 2611da177e4SLinus Torvalds 2621da177e4SLinus Torvaldsmy $lineprefix=""; 2631da177e4SLinus Torvalds 2641da177e4SLinus Torvalds# states 2651da177e4SLinus Torvalds# 0 - normal code 2661da177e4SLinus Torvalds# 1 - looking for function name 2671da177e4SLinus Torvalds# 2 - scanning field start. 2681da177e4SLinus Torvalds# 3 - scanning prototype. 2691da177e4SLinus Torvalds# 4 - documentation block 2701da177e4SLinus Torvaldsmy $state; 271850622dfSRandy Dunlapmy $in_doc_sect; 2721da177e4SLinus Torvalds 2731da177e4SLinus Torvalds#declaration types: can be 2741da177e4SLinus Torvalds# 'function', 'struct', 'union', 'enum', 'typedef' 2751da177e4SLinus Torvaldsmy $decl_type; 2761da177e4SLinus Torvalds 2771da177e4SLinus Torvaldsmy $doc_special = "\@\%\$\&"; 2781da177e4SLinus Torvalds 2791da177e4SLinus Torvaldsmy $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start. 2801da177e4SLinus Torvaldsmy $doc_end = '\*/'; 2811da177e4SLinus Torvaldsmy $doc_com = '\s*\*\s*'; 2821da177e4SLinus Torvaldsmy $doc_decl = $doc_com . '(\w+)'; 283891dcd2fSRandy Dunlapmy $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)'; 2841da177e4SLinus Torvaldsmy $doc_content = $doc_com . '(.*)'; 2851da177e4SLinus Torvaldsmy $doc_block = $doc_com . 'DOC:\s*(.*)?'; 2861da177e4SLinus Torvalds 2871da177e4SLinus Torvaldsmy %constants; 2881da177e4SLinus Torvaldsmy %parameterdescs; 2891da177e4SLinus Torvaldsmy @parameterlist; 2901da177e4SLinus Torvaldsmy %sections; 2911da177e4SLinus Torvaldsmy @sectionlist; 292a1d94aa5SRandy Dunlapmy $sectcheck; 293a1d94aa5SRandy Dunlapmy $struct_actual; 2941da177e4SLinus Torvalds 2951da177e4SLinus Torvaldsmy $contents = ""; 2961da177e4SLinus Torvaldsmy $section_default = "Description"; # default section 2971da177e4SLinus Torvaldsmy $section_intro = "Introduction"; 2981da177e4SLinus Torvaldsmy $section = $section_default; 2991da177e4SLinus Torvaldsmy $section_context = "Context"; 3001da177e4SLinus Torvalds 3011da177e4SLinus Torvaldsmy $undescribed = "-- undescribed --"; 3021da177e4SLinus Torvalds 3031da177e4SLinus Torvaldsreset_state(); 3041da177e4SLinus Torvalds 3051da177e4SLinus Torvaldswhile ($ARGV[0] =~ m/^-(.*)/) { 3061da177e4SLinus Torvalds my $cmd = shift @ARGV; 3071da177e4SLinus Torvalds if ($cmd eq "-html") { 3081da177e4SLinus Torvalds $output_mode = "html"; 3091da177e4SLinus Torvalds %highlights = %highlights_html; 3101da177e4SLinus Torvalds $blankline = $blankline_html; 3111da177e4SLinus Torvalds } elsif ($cmd eq "-man") { 3121da177e4SLinus Torvalds $output_mode = "man"; 3131da177e4SLinus Torvalds %highlights = %highlights_man; 3141da177e4SLinus Torvalds $blankline = $blankline_man; 3151da177e4SLinus Torvalds } elsif ($cmd eq "-text") { 3161da177e4SLinus Torvalds $output_mode = "text"; 3171da177e4SLinus Torvalds %highlights = %highlights_text; 3181da177e4SLinus Torvalds $blankline = $blankline_text; 3191da177e4SLinus Torvalds } elsif ($cmd eq "-docbook") { 3201da177e4SLinus Torvalds $output_mode = "xml"; 3211da177e4SLinus Torvalds %highlights = %highlights_xml; 3221da177e4SLinus Torvalds $blankline = $blankline_xml; 3231da177e4SLinus Torvalds } elsif ($cmd eq "-gnome") { 3241da177e4SLinus Torvalds $output_mode = "gnome"; 3251da177e4SLinus Torvalds %highlights = %highlights_gnome; 3261da177e4SLinus Torvalds $blankline = $blankline_gnome; 3271da177e4SLinus Torvalds } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document 3281da177e4SLinus Torvalds $modulename = shift @ARGV; 3291da177e4SLinus Torvalds } elsif ($cmd eq "-function") { # to only output specific functions 3301da177e4SLinus Torvalds $function_only = 1; 3311da177e4SLinus Torvalds $function = shift @ARGV; 3321da177e4SLinus Torvalds $function_table{$function} = 1; 3331da177e4SLinus Torvalds } elsif ($cmd eq "-nofunction") { # to only output specific functions 3341da177e4SLinus Torvalds $function_only = 2; 3351da177e4SLinus Torvalds $function = shift @ARGV; 3361da177e4SLinus Torvalds $function_table{$function} = 1; 3371da177e4SLinus Torvalds } elsif ($cmd eq "-v") { 3381da177e4SLinus Torvalds $verbose = 1; 3391da177e4SLinus Torvalds } elsif (($cmd eq "-h") || ($cmd eq "--help")) { 3401da177e4SLinus Torvalds usage(); 3411da177e4SLinus Torvalds } elsif ($cmd eq '-filelist') { 3421da177e4SLinus Torvalds $filelist = shift @ARGV; 3434b44595aSJohannes Berg } elsif ($cmd eq '-no-doc-sections') { 3444b44595aSJohannes Berg $no_doc_sections = 1; 3451da177e4SLinus Torvalds } 3461da177e4SLinus Torvalds} 3471da177e4SLinus Torvalds 34853f049faSBorislav Petkov# get kernel version from env 34953f049faSBorislav Petkovsub get_kernel_version() { 3501b9bc22dSJohannes Berg my $version = 'unknown kernel version'; 35153f049faSBorislav Petkov 35253f049faSBorislav Petkov if (defined($ENV{'KERNELVERSION'})) { 35353f049faSBorislav Petkov $version = $ENV{'KERNELVERSION'}; 35453f049faSBorislav Petkov } 35553f049faSBorislav Petkov return $version; 35653f049faSBorislav Petkov} 3570366299bSBorislav Petkovmy $kernelversion = get_kernel_version(); 3581da177e4SLinus Torvalds 3591da177e4SLinus Torvalds# generate a sequence of code that will splice in highlighting information 3601da177e4SLinus Torvalds# using the s// operator. 3611da177e4SLinus Torvaldsmy $dohighlight = ""; 3621da177e4SLinus Torvaldsforeach my $pattern (keys %highlights) { 3633eb014a1SRandy Dunlap# print STDERR "scanning pattern:$pattern, highlight:($highlights{$pattern})\n"; 3641da177e4SLinus Torvalds $dohighlight .= "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n"; 3651da177e4SLinus Torvalds} 3661da177e4SLinus Torvalds 3671da177e4SLinus Torvalds## 3681da177e4SLinus Torvalds# dumps section contents to arrays/hashes intended for that purpose. 3691da177e4SLinus Torvalds# 3701da177e4SLinus Torvaldssub dump_section { 37194dc7ad5SRandy Dunlap my $file = shift; 3721da177e4SLinus Torvalds my $name = shift; 3731da177e4SLinus Torvalds my $contents = join "\n", @_; 3741da177e4SLinus Torvalds 3751da177e4SLinus Torvalds if ($name =~ m/$type_constant/) { 3761da177e4SLinus Torvalds $name = $1; 3771da177e4SLinus Torvalds# print STDERR "constant section '$1' = '$contents'\n"; 3781da177e4SLinus Torvalds $constants{$name} = $contents; 3791da177e4SLinus Torvalds } elsif ($name =~ m/$type_param/) { 3801da177e4SLinus Torvalds# print STDERR "parameter def '$1' = '$contents'\n"; 3811da177e4SLinus Torvalds $name = $1; 3821da177e4SLinus Torvalds $parameterdescs{$name} = $contents; 383a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 384ced69090SRandy Dunlap } elsif ($name eq "@\.\.\.") { 385ced69090SRandy Dunlap# print STDERR "parameter def '...' = '$contents'\n"; 386ced69090SRandy Dunlap $name = "..."; 387ced69090SRandy Dunlap $parameterdescs{$name} = $contents; 388a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 3891da177e4SLinus Torvalds } else { 3901da177e4SLinus Torvalds# print STDERR "other section '$name' = '$contents'\n"; 39194dc7ad5SRandy Dunlap if (defined($sections{$name}) && ($sections{$name} ne "")) { 39294dc7ad5SRandy Dunlap print STDERR "Error(${file}:$.): duplicate section name '$name'\n"; 39394dc7ad5SRandy Dunlap ++$errors; 39494dc7ad5SRandy Dunlap } 3951da177e4SLinus Torvalds $sections{$name} = $contents; 3961da177e4SLinus Torvalds push @sectionlist, $name; 3971da177e4SLinus Torvalds } 3981da177e4SLinus Torvalds} 3991da177e4SLinus Torvalds 4001da177e4SLinus Torvalds## 401b112e0f7SJohannes Berg# dump DOC: section after checking that it should go out 402b112e0f7SJohannes Berg# 403b112e0f7SJohannes Bergsub dump_doc_section { 40494dc7ad5SRandy Dunlap my $file = shift; 405b112e0f7SJohannes Berg my $name = shift; 406b112e0f7SJohannes Berg my $contents = join "\n", @_; 407b112e0f7SJohannes Berg 4084b44595aSJohannes Berg if ($no_doc_sections) { 4094b44595aSJohannes Berg return; 4104b44595aSJohannes Berg } 4114b44595aSJohannes Berg 412b112e0f7SJohannes Berg if (($function_only == 0) || 413b112e0f7SJohannes Berg ( $function_only == 1 && defined($function_table{$name})) || 414b112e0f7SJohannes Berg ( $function_only == 2 && !defined($function_table{$name}))) 415b112e0f7SJohannes Berg { 41694dc7ad5SRandy Dunlap dump_section($file, $name, $contents); 417b112e0f7SJohannes Berg output_blockhead({'sectionlist' => \@sectionlist, 418b112e0f7SJohannes Berg 'sections' => \%sections, 419b112e0f7SJohannes Berg 'module' => $modulename, 420b112e0f7SJohannes Berg 'content-only' => ($function_only != 0), }); 421b112e0f7SJohannes Berg } 422b112e0f7SJohannes Berg} 423b112e0f7SJohannes Berg 424b112e0f7SJohannes Berg## 4251da177e4SLinus Torvalds# output function 4261da177e4SLinus Torvalds# 4271da177e4SLinus Torvalds# parameterdescs, a hash. 4281da177e4SLinus Torvalds# function => "function name" 4291da177e4SLinus Torvalds# parameterlist => @list of parameters 4301da177e4SLinus Torvalds# parameterdescs => %parameter descriptions 4311da177e4SLinus Torvalds# sectionlist => @list of sections 432a21217daSRandy Dunlap# sections => %section descriptions 4331da177e4SLinus Torvalds# 4341da177e4SLinus Torvalds 4351da177e4SLinus Torvaldssub output_highlight { 4361da177e4SLinus Torvalds my $contents = join "\n",@_; 4371da177e4SLinus Torvalds my $line; 4381da177e4SLinus Torvalds 4391da177e4SLinus Torvalds# DEBUG 4401da177e4SLinus Torvalds# if (!defined $contents) { 4411da177e4SLinus Torvalds# use Carp; 4421da177e4SLinus Torvalds# confess "output_highlight got called with no args?\n"; 4431da177e4SLinus Torvalds# } 4441da177e4SLinus Torvalds 4455c98fc03SJohannes Berg if ($output_mode eq "html" || $output_mode eq "xml") { 4466b5b55f6SRandy Dunlap $contents = local_unescape($contents); 4476b5b55f6SRandy Dunlap # convert data read & converted thru xml_escape() into &xyz; format: 4486b5b55f6SRandy Dunlap $contents =~ s/\\\\\\/&/g; 4496b5b55f6SRandy Dunlap } 4503eb014a1SRandy Dunlap# print STDERR "contents b4:$contents\n"; 4511da177e4SLinus Torvalds eval $dohighlight; 4521da177e4SLinus Torvalds die $@ if $@; 4533eb014a1SRandy Dunlap# print STDERR "contents af:$contents\n"; 4543eb014a1SRandy Dunlap 4551da177e4SLinus Torvalds foreach $line (split "\n", $contents) { 4561da177e4SLinus Torvalds if ($line eq ""){ 4576b5b55f6SRandy Dunlap print $lineprefix, local_unescape($blankline); 4581da177e4SLinus Torvalds } else { 4591da177e4SLinus Torvalds $line =~ s/\\\\\\/\&/g; 460cdccb316SRandy Dunlap if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { 461cdccb316SRandy Dunlap print "\\&$line"; 462cdccb316SRandy Dunlap } else { 4631da177e4SLinus Torvalds print $lineprefix, $line; 4641da177e4SLinus Torvalds } 465cdccb316SRandy Dunlap } 4661da177e4SLinus Torvalds print "\n"; 4671da177e4SLinus Torvalds } 4681da177e4SLinus Torvalds} 4691da177e4SLinus Torvalds 4701da177e4SLinus Torvalds#output sections in html 4711da177e4SLinus Torvaldssub output_section_html(%) { 4721da177e4SLinus Torvalds my %args = %{$_[0]}; 4731da177e4SLinus Torvalds my $section; 4741da177e4SLinus Torvalds 4751da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 4761da177e4SLinus Torvalds print "<h3>$section</h3>\n"; 4771da177e4SLinus Torvalds print "<blockquote>\n"; 4781da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 4791da177e4SLinus Torvalds print "</blockquote>\n"; 4801da177e4SLinus Torvalds } 4811da177e4SLinus Torvalds} 4821da177e4SLinus Torvalds 4831da177e4SLinus Torvalds# output enum in html 4841da177e4SLinus Torvaldssub output_enum_html(%) { 4851da177e4SLinus Torvalds my %args = %{$_[0]}; 4861da177e4SLinus Torvalds my ($parameter); 4871da177e4SLinus Torvalds my $count; 4881da177e4SLinus Torvalds print "<h2>enum " . $args{'enum'} . "</h2>\n"; 4891da177e4SLinus Torvalds 4901da177e4SLinus Torvalds print "<b>enum " . $args{'enum'} . "</b> {<br>\n"; 4911da177e4SLinus Torvalds $count = 0; 4921da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 4931da177e4SLinus Torvalds print " <b>" . $parameter . "</b>"; 4941da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 4951da177e4SLinus Torvalds $count++; 4961da177e4SLinus Torvalds print ",\n"; 4971da177e4SLinus Torvalds } 4981da177e4SLinus Torvalds print "<br>"; 4991da177e4SLinus Torvalds } 5001da177e4SLinus Torvalds print "};<br>\n"; 5011da177e4SLinus Torvalds 5021da177e4SLinus Torvalds print "<h3>Constants</h3>\n"; 5031da177e4SLinus Torvalds print "<dl>\n"; 5041da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 5051da177e4SLinus Torvalds print "<dt><b>" . $parameter . "</b>\n"; 5061da177e4SLinus Torvalds print "<dd>"; 5071da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter}); 5081da177e4SLinus Torvalds } 5091da177e4SLinus Torvalds print "</dl>\n"; 5101da177e4SLinus Torvalds output_section_html(@_); 5111da177e4SLinus Torvalds print "<hr>\n"; 5121da177e4SLinus Torvalds} 5131da177e4SLinus Torvalds 514d28bee0cSRandy Dunlap# output typedef in html 5151da177e4SLinus Torvaldssub output_typedef_html(%) { 5161da177e4SLinus Torvalds my %args = %{$_[0]}; 5171da177e4SLinus Torvalds my ($parameter); 5181da177e4SLinus Torvalds my $count; 5191da177e4SLinus Torvalds print "<h2>typedef " . $args{'typedef'} . "</h2>\n"; 5201da177e4SLinus Torvalds 5211da177e4SLinus Torvalds print "<b>typedef " . $args{'typedef'} . "</b>\n"; 5221da177e4SLinus Torvalds output_section_html(@_); 5231da177e4SLinus Torvalds print "<hr>\n"; 5241da177e4SLinus Torvalds} 5251da177e4SLinus Torvalds 5261da177e4SLinus Torvalds# output struct in html 5271da177e4SLinus Torvaldssub output_struct_html(%) { 5281da177e4SLinus Torvalds my %args = %{$_[0]}; 5291da177e4SLinus Torvalds my ($parameter); 5301da177e4SLinus Torvalds 531262d9b01SRandy Dunlap print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n"; 5321da177e4SLinus Torvalds print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n"; 5331da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 5341da177e4SLinus Torvalds if ($parameter =~ /^#/) { 5351da177e4SLinus Torvalds print "$parameter<br>\n"; 5361da177e4SLinus Torvalds next; 5371da177e4SLinus Torvalds } 5381da177e4SLinus Torvalds my $parameter_name = $parameter; 5391da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 5401da177e4SLinus Torvalds 5411da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 5421da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 5431da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 5441da177e4SLinus Torvalds # pointer-to-function 5453eb014a1SRandy Dunlap print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n"; 5461da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 5473eb014a1SRandy Dunlap # bitfield 5483eb014a1SRandy Dunlap print " <i>$1</i> <b>$parameter</b>$2;<br>\n"; 5491da177e4SLinus Torvalds } else { 5503eb014a1SRandy Dunlap print " <i>$type</i> <b>$parameter</b>;<br>\n"; 5511da177e4SLinus Torvalds } 5521da177e4SLinus Torvalds } 5531da177e4SLinus Torvalds print "};<br>\n"; 5541da177e4SLinus Torvalds 5551da177e4SLinus Torvalds print "<h3>Members</h3>\n"; 5561da177e4SLinus Torvalds print "<dl>\n"; 5571da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 5581da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 5591da177e4SLinus Torvalds 5601da177e4SLinus Torvalds my $parameter_name = $parameter; 5611da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 5621da177e4SLinus Torvalds 5631da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 5641da177e4SLinus Torvalds print "<dt><b>" . $parameter . "</b>\n"; 5651da177e4SLinus Torvalds print "<dd>"; 5661da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 5671da177e4SLinus Torvalds } 5681da177e4SLinus Torvalds print "</dl>\n"; 5691da177e4SLinus Torvalds output_section_html(@_); 5701da177e4SLinus Torvalds print "<hr>\n"; 5711da177e4SLinus Torvalds} 5721da177e4SLinus Torvalds 5731da177e4SLinus Torvalds# output function in html 5741da177e4SLinus Torvaldssub output_function_html(%) { 5751da177e4SLinus Torvalds my %args = %{$_[0]}; 5761da177e4SLinus Torvalds my ($parameter, $section); 5771da177e4SLinus Torvalds my $count; 5781da177e4SLinus Torvalds 579262d9b01SRandy Dunlap print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n"; 5801da177e4SLinus Torvalds print "<i>" . $args{'functiontype'} . "</i>\n"; 5811da177e4SLinus Torvalds print "<b>" . $args{'function'} . "</b>\n"; 5821da177e4SLinus Torvalds print "("; 5831da177e4SLinus Torvalds $count = 0; 5841da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 5851da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 5861da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 5871da177e4SLinus Torvalds # pointer-to-function 5881da177e4SLinus Torvalds print "<i>$1</i><b>$parameter</b>) <i>($2)</i>"; 5891da177e4SLinus Torvalds } else { 5901da177e4SLinus Torvalds print "<i>" . $type . "</i> <b>" . $parameter . "</b>"; 5911da177e4SLinus Torvalds } 5921da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 5931da177e4SLinus Torvalds $count++; 5941da177e4SLinus Torvalds print ",\n"; 5951da177e4SLinus Torvalds } 5961da177e4SLinus Torvalds } 5971da177e4SLinus Torvalds print ")\n"; 5981da177e4SLinus Torvalds 5991da177e4SLinus Torvalds print "<h3>Arguments</h3>\n"; 6001da177e4SLinus Torvalds print "<dl>\n"; 6011da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6021da177e4SLinus Torvalds my $parameter_name = $parameter; 6031da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 6041da177e4SLinus Torvalds 6051da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 6061da177e4SLinus Torvalds print "<dt><b>" . $parameter . "</b>\n"; 6071da177e4SLinus Torvalds print "<dd>"; 6081da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 6091da177e4SLinus Torvalds } 6101da177e4SLinus Torvalds print "</dl>\n"; 6111da177e4SLinus Torvalds output_section_html(@_); 6121da177e4SLinus Torvalds print "<hr>\n"; 6131da177e4SLinus Torvalds} 6141da177e4SLinus Torvalds 615b112e0f7SJohannes Berg# output DOC: block header in html 616b112e0f7SJohannes Bergsub output_blockhead_html(%) { 6171da177e4SLinus Torvalds my %args = %{$_[0]}; 6181da177e4SLinus Torvalds my ($parameter, $section); 6191da177e4SLinus Torvalds my $count; 6201da177e4SLinus Torvalds 6211da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 6221da177e4SLinus Torvalds print "<h3>$section</h3>\n"; 6231da177e4SLinus Torvalds print "<ul>\n"; 6241da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 6251da177e4SLinus Torvalds print "</ul>\n"; 6261da177e4SLinus Torvalds } 6271da177e4SLinus Torvalds print "<hr>\n"; 6281da177e4SLinus Torvalds} 6291da177e4SLinus Torvalds 6301da177e4SLinus Torvaldssub output_section_xml(%) { 6311da177e4SLinus Torvalds my %args = %{$_[0]}; 6321da177e4SLinus Torvalds my $section; 6331da177e4SLinus Torvalds # print out each section 6341da177e4SLinus Torvalds $lineprefix=" "; 6351da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 636c73894c1SRich Walker print "<refsect1>\n"; 637c73894c1SRich Walker print "<title>$section</title>\n"; 6381da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 639c73894c1SRich Walker print "<informalexample><programlisting>\n"; 640c73894c1SRich Walker } else { 641c73894c1SRich Walker print "<para>\n"; 6421da177e4SLinus Torvalds } 6431da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 6441da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 645c73894c1SRich Walker print "</programlisting></informalexample>\n"; 646c73894c1SRich Walker } else { 647c73894c1SRich Walker print "</para>\n"; 6481da177e4SLinus Torvalds } 649c73894c1SRich Walker print "</refsect1>\n"; 6501da177e4SLinus Torvalds } 6511da177e4SLinus Torvalds} 6521da177e4SLinus Torvalds 6531da177e4SLinus Torvalds# output function in XML DocBook 6541da177e4SLinus Torvaldssub output_function_xml(%) { 6551da177e4SLinus Torvalds my %args = %{$_[0]}; 6561da177e4SLinus Torvalds my ($parameter, $section); 6571da177e4SLinus Torvalds my $count; 6581da177e4SLinus Torvalds my $id; 6591da177e4SLinus Torvalds 6601da177e4SLinus Torvalds $id = "API-" . $args{'function'}; 6611da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 6621da177e4SLinus Torvalds 6635449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 6648b0c2d98SMartin Waitz print "<refentryinfo>\n"; 6658b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 6668b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 6678b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 6688b0c2d98SMartin Waitz print "</refentryinfo>\n"; 6691da177e4SLinus Torvalds print "<refmeta>\n"; 6705449bc94SPavel Pisa print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n"; 6718b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 6720366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 6731da177e4SLinus Torvalds print "</refmeta>\n"; 6741da177e4SLinus Torvalds print "<refnamediv>\n"; 6751da177e4SLinus Torvalds print " <refname>" . $args{'function'} . "</refname>\n"; 6761da177e4SLinus Torvalds print " <refpurpose>\n"; 6771da177e4SLinus Torvalds print " "; 6781da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 6791da177e4SLinus Torvalds print " </refpurpose>\n"; 6801da177e4SLinus Torvalds print "</refnamediv>\n"; 6811da177e4SLinus Torvalds 6821da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 6831da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 6841da177e4SLinus Torvalds print " <funcsynopsis><funcprototype>\n"; 6851da177e4SLinus Torvalds print " <funcdef>" . $args{'functiontype'} . " "; 6861da177e4SLinus Torvalds print "<function>" . $args{'function'} . " </function></funcdef>\n"; 6871da177e4SLinus Torvalds 6881da177e4SLinus Torvalds $count = 0; 6891da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 6901da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6911da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 6921da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 6931da177e4SLinus Torvalds # pointer-to-function 6941da177e4SLinus Torvalds print " <paramdef>$1<parameter>$parameter</parameter>)\n"; 6951da177e4SLinus Torvalds print " <funcparams>$2</funcparams></paramdef>\n"; 6961da177e4SLinus Torvalds } else { 6971da177e4SLinus Torvalds print " <paramdef>" . $type; 6981da177e4SLinus Torvalds print " <parameter>$parameter</parameter></paramdef>\n"; 6991da177e4SLinus Torvalds } 7001da177e4SLinus Torvalds } 7011da177e4SLinus Torvalds } else { 7026013d544SMartin Waitz print " <void/>\n"; 7031da177e4SLinus Torvalds } 7041da177e4SLinus Torvalds print " </funcprototype></funcsynopsis>\n"; 7051da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 7061da177e4SLinus Torvalds 7071da177e4SLinus Torvalds # print parameters 7081da177e4SLinus Torvalds print "<refsect1>\n <title>Arguments</title>\n"; 7091da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 7101da177e4SLinus Torvalds print " <variablelist>\n"; 7111da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7121da177e4SLinus Torvalds my $parameter_name = $parameter; 7131da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 7141da177e4SLinus Torvalds 7151da177e4SLinus Torvalds print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n"; 7161da177e4SLinus Torvalds print " <listitem>\n <para>\n"; 7171da177e4SLinus Torvalds $lineprefix=" "; 7181da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 7191da177e4SLinus Torvalds print " </para>\n </listitem>\n </varlistentry>\n"; 7201da177e4SLinus Torvalds } 7211da177e4SLinus Torvalds print " </variablelist>\n"; 7221da177e4SLinus Torvalds } else { 7231da177e4SLinus Torvalds print " <para>\n None\n </para>\n"; 7241da177e4SLinus Torvalds } 7251da177e4SLinus Torvalds print "</refsect1>\n"; 7261da177e4SLinus Torvalds 7271da177e4SLinus Torvalds output_section_xml(@_); 7281da177e4SLinus Torvalds print "</refentry>\n\n"; 7291da177e4SLinus Torvalds} 7301da177e4SLinus Torvalds 7311da177e4SLinus Torvalds# output struct in XML DocBook 7321da177e4SLinus Torvaldssub output_struct_xml(%) { 7331da177e4SLinus Torvalds my %args = %{$_[0]}; 7341da177e4SLinus Torvalds my ($parameter, $section); 7351da177e4SLinus Torvalds my $id; 7361da177e4SLinus Torvalds 7371da177e4SLinus Torvalds $id = "API-struct-" . $args{'struct'}; 7381da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 7391da177e4SLinus Torvalds 7405449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 7418b0c2d98SMartin Waitz print "<refentryinfo>\n"; 7428b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 7438b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 7448b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 7458b0c2d98SMartin Waitz print "</refentryinfo>\n"; 7461da177e4SLinus Torvalds print "<refmeta>\n"; 7475449bc94SPavel Pisa print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n"; 7488b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 7490366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 7501da177e4SLinus Torvalds print "</refmeta>\n"; 7511da177e4SLinus Torvalds print "<refnamediv>\n"; 7521da177e4SLinus Torvalds print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n"; 7531da177e4SLinus Torvalds print " <refpurpose>\n"; 7541da177e4SLinus Torvalds print " "; 7551da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 7561da177e4SLinus Torvalds print " </refpurpose>\n"; 7571da177e4SLinus Torvalds print "</refnamediv>\n"; 7581da177e4SLinus Torvalds 7591da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 7601da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 7611da177e4SLinus Torvalds print " <programlisting>\n"; 7621da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n"; 7631da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7641da177e4SLinus Torvalds if ($parameter =~ /^#/) { 7651da177e4SLinus Torvalds print "$parameter\n"; 7661da177e4SLinus Torvalds next; 7671da177e4SLinus Torvalds } 7681da177e4SLinus Torvalds 7691da177e4SLinus Torvalds my $parameter_name = $parameter; 7701da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 7711da177e4SLinus Torvalds 7721da177e4SLinus Torvalds defined($args{'parameterdescs'}{$parameter_name}) || next; 7731da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 7741da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 7751da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 7761da177e4SLinus Torvalds # pointer-to-function 7771da177e4SLinus Torvalds print " $1 $parameter) ($2);\n"; 7781da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 77951f5a0c8SRandy Dunlap # bitfield 7801da177e4SLinus Torvalds print " $1 $parameter$2;\n"; 7811da177e4SLinus Torvalds } else { 7821da177e4SLinus Torvalds print " " . $type . " " . $parameter . ";\n"; 7831da177e4SLinus Torvalds } 7841da177e4SLinus Torvalds } 7851da177e4SLinus Torvalds print "};"; 7861da177e4SLinus Torvalds print " </programlisting>\n"; 7871da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 7881da177e4SLinus Torvalds 7891da177e4SLinus Torvalds print " <refsect1>\n"; 7901da177e4SLinus Torvalds print " <title>Members</title>\n"; 7911da177e4SLinus Torvalds 79239f00c08SRandy Dunlap if ($#{$args{'parameterlist'}} >= 0) { 7931da177e4SLinus Torvalds print " <variablelist>\n"; 7941da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7951da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 7961da177e4SLinus Torvalds 7971da177e4SLinus Torvalds my $parameter_name = $parameter; 7981da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 7991da177e4SLinus Torvalds 8001da177e4SLinus Torvalds defined($args{'parameterdescs'}{$parameter_name}) || next; 8011da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 8021da177e4SLinus Torvalds print " <varlistentry>"; 8031da177e4SLinus Torvalds print " <term>$parameter</term>\n"; 8041da177e4SLinus Torvalds print " <listitem><para>\n"; 8051da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 8061da177e4SLinus Torvalds print " </para></listitem>\n"; 8071da177e4SLinus Torvalds print " </varlistentry>\n"; 8081da177e4SLinus Torvalds } 8091da177e4SLinus Torvalds print " </variablelist>\n"; 81039f00c08SRandy Dunlap } else { 81139f00c08SRandy Dunlap print " <para>\n None\n </para>\n"; 81239f00c08SRandy Dunlap } 8131da177e4SLinus Torvalds print " </refsect1>\n"; 8141da177e4SLinus Torvalds 8151da177e4SLinus Torvalds output_section_xml(@_); 8161da177e4SLinus Torvalds 8171da177e4SLinus Torvalds print "</refentry>\n\n"; 8181da177e4SLinus Torvalds} 8191da177e4SLinus Torvalds 8201da177e4SLinus Torvalds# output enum in XML DocBook 8211da177e4SLinus Torvaldssub output_enum_xml(%) { 8221da177e4SLinus Torvalds my %args = %{$_[0]}; 8231da177e4SLinus Torvalds my ($parameter, $section); 8241da177e4SLinus Torvalds my $count; 8251da177e4SLinus Torvalds my $id; 8261da177e4SLinus Torvalds 8271da177e4SLinus Torvalds $id = "API-enum-" . $args{'enum'}; 8281da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 8291da177e4SLinus Torvalds 8305449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 8318b0c2d98SMartin Waitz print "<refentryinfo>\n"; 8328b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 8338b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 8348b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 8358b0c2d98SMartin Waitz print "</refentryinfo>\n"; 8361da177e4SLinus Torvalds print "<refmeta>\n"; 8375449bc94SPavel Pisa print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n"; 8388b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 8390366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 8401da177e4SLinus Torvalds print "</refmeta>\n"; 8411da177e4SLinus Torvalds print "<refnamediv>\n"; 8421da177e4SLinus Torvalds print " <refname>enum " . $args{'enum'} . "</refname>\n"; 8431da177e4SLinus Torvalds print " <refpurpose>\n"; 8441da177e4SLinus Torvalds print " "; 8451da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 8461da177e4SLinus Torvalds print " </refpurpose>\n"; 8471da177e4SLinus Torvalds print "</refnamediv>\n"; 8481da177e4SLinus Torvalds 8491da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 8501da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 8511da177e4SLinus Torvalds print " <programlisting>\n"; 8521da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 8531da177e4SLinus Torvalds $count = 0; 8541da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 8551da177e4SLinus Torvalds print " $parameter"; 8561da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 8571da177e4SLinus Torvalds $count++; 8581da177e4SLinus Torvalds print ","; 8591da177e4SLinus Torvalds } 8601da177e4SLinus Torvalds print "\n"; 8611da177e4SLinus Torvalds } 8621da177e4SLinus Torvalds print "};"; 8631da177e4SLinus Torvalds print " </programlisting>\n"; 8641da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 8651da177e4SLinus Torvalds 8661da177e4SLinus Torvalds print "<refsect1>\n"; 8671da177e4SLinus Torvalds print " <title>Constants</title>\n"; 8681da177e4SLinus Torvalds print " <variablelist>\n"; 8691da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 8701da177e4SLinus Torvalds my $parameter_name = $parameter; 8711da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 8721da177e4SLinus Torvalds 8731da177e4SLinus Torvalds print " <varlistentry>"; 8741da177e4SLinus Torvalds print " <term>$parameter</term>\n"; 8751da177e4SLinus Torvalds print " <listitem><para>\n"; 8761da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 8771da177e4SLinus Torvalds print " </para></listitem>\n"; 8781da177e4SLinus Torvalds print " </varlistentry>\n"; 8791da177e4SLinus Torvalds } 8801da177e4SLinus Torvalds print " </variablelist>\n"; 8811da177e4SLinus Torvalds print "</refsect1>\n"; 8821da177e4SLinus Torvalds 8831da177e4SLinus Torvalds output_section_xml(@_); 8841da177e4SLinus Torvalds 8851da177e4SLinus Torvalds print "</refentry>\n\n"; 8861da177e4SLinus Torvalds} 8871da177e4SLinus Torvalds 8881da177e4SLinus Torvalds# output typedef in XML DocBook 8891da177e4SLinus Torvaldssub output_typedef_xml(%) { 8901da177e4SLinus Torvalds my %args = %{$_[0]}; 8911da177e4SLinus Torvalds my ($parameter, $section); 8921da177e4SLinus Torvalds my $id; 8931da177e4SLinus Torvalds 8941da177e4SLinus Torvalds $id = "API-typedef-" . $args{'typedef'}; 8951da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 8961da177e4SLinus Torvalds 8975449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 8988b0c2d98SMartin Waitz print "<refentryinfo>\n"; 8998b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 9008b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 9018b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 9028b0c2d98SMartin Waitz print "</refentryinfo>\n"; 9031da177e4SLinus Torvalds print "<refmeta>\n"; 9045449bc94SPavel Pisa print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n"; 9058b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 9061da177e4SLinus Torvalds print "</refmeta>\n"; 9071da177e4SLinus Torvalds print "<refnamediv>\n"; 9081da177e4SLinus Torvalds print " <refname>typedef " . $args{'typedef'} . "</refname>\n"; 9091da177e4SLinus Torvalds print " <refpurpose>\n"; 9101da177e4SLinus Torvalds print " "; 9111da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 9121da177e4SLinus Torvalds print " </refpurpose>\n"; 9131da177e4SLinus Torvalds print "</refnamediv>\n"; 9141da177e4SLinus Torvalds 9151da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 9161da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 9171da177e4SLinus Torvalds print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n"; 9181da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 9191da177e4SLinus Torvalds 9201da177e4SLinus Torvalds output_section_xml(@_); 9211da177e4SLinus Torvalds 9221da177e4SLinus Torvalds print "</refentry>\n\n"; 9231da177e4SLinus Torvalds} 9241da177e4SLinus Torvalds 9251da177e4SLinus Torvalds# output in XML DocBook 926b112e0f7SJohannes Bergsub output_blockhead_xml(%) { 9271da177e4SLinus Torvalds my %args = %{$_[0]}; 9281da177e4SLinus Torvalds my ($parameter, $section); 9291da177e4SLinus Torvalds my $count; 9301da177e4SLinus Torvalds 9311da177e4SLinus Torvalds my $id = $args{'module'}; 9321da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 9331da177e4SLinus Torvalds 9341da177e4SLinus Torvalds # print out each section 9351da177e4SLinus Torvalds $lineprefix=" "; 9361da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 937b112e0f7SJohannes Berg if (!$args{'content-only'}) { 938b112e0f7SJohannes Berg print "<refsect1>\n <title>$section</title>\n"; 939b112e0f7SJohannes Berg } 9401da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 9411da177e4SLinus Torvalds print "<example><para>\n"; 942b112e0f7SJohannes Berg } else { 943b112e0f7SJohannes Berg print "<para>\n"; 9441da177e4SLinus Torvalds } 9451da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 9461da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 9471da177e4SLinus Torvalds print "</para></example>\n"; 948b112e0f7SJohannes Berg } else { 949b112e0f7SJohannes Berg print "</para>"; 9501da177e4SLinus Torvalds } 951b112e0f7SJohannes Berg if (!$args{'content-only'}) { 952b112e0f7SJohannes Berg print "\n</refsect1>\n"; 953b112e0f7SJohannes Berg } 9541da177e4SLinus Torvalds } 9551da177e4SLinus Torvalds 9561da177e4SLinus Torvalds print "\n\n"; 9571da177e4SLinus Torvalds} 9581da177e4SLinus Torvalds 9591da177e4SLinus Torvalds# output in XML DocBook 9601da177e4SLinus Torvaldssub output_function_gnome { 9611da177e4SLinus Torvalds my %args = %{$_[0]}; 9621da177e4SLinus Torvalds my ($parameter, $section); 9631da177e4SLinus Torvalds my $count; 9641da177e4SLinus Torvalds my $id; 9651da177e4SLinus Torvalds 9661da177e4SLinus Torvalds $id = $args{'module'} . "-" . $args{'function'}; 9671da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 9681da177e4SLinus Torvalds 9691da177e4SLinus Torvalds print "<sect2>\n"; 9701da177e4SLinus Torvalds print " <title id=\"$id\">" . $args{'function'} . "</title>\n"; 9711da177e4SLinus Torvalds 9721da177e4SLinus Torvalds print " <funcsynopsis>\n"; 9731da177e4SLinus Torvalds print " <funcdef>" . $args{'functiontype'} . " "; 9741da177e4SLinus Torvalds print "<function>" . $args{'function'} . " "; 9751da177e4SLinus Torvalds print "</function></funcdef>\n"; 9761da177e4SLinus Torvalds 9771da177e4SLinus Torvalds $count = 0; 9781da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 9791da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 9801da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 9811da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 9821da177e4SLinus Torvalds # pointer-to-function 9831da177e4SLinus Torvalds print " <paramdef>$1 <parameter>$parameter</parameter>)\n"; 9841da177e4SLinus Torvalds print " <funcparams>$2</funcparams></paramdef>\n"; 9851da177e4SLinus Torvalds } else { 9861da177e4SLinus Torvalds print " <paramdef>" . $type; 9871da177e4SLinus Torvalds print " <parameter>$parameter</parameter></paramdef>\n"; 9881da177e4SLinus Torvalds } 9891da177e4SLinus Torvalds } 9901da177e4SLinus Torvalds } else { 9911da177e4SLinus Torvalds print " <void>\n"; 9921da177e4SLinus Torvalds } 9931da177e4SLinus Torvalds print " </funcsynopsis>\n"; 9941da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 9951da177e4SLinus Torvalds print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n"; 9961da177e4SLinus Torvalds print "<tgroup cols=\"2\">\n"; 9971da177e4SLinus Torvalds print "<colspec colwidth=\"2*\">\n"; 9981da177e4SLinus Torvalds print "<colspec colwidth=\"8*\">\n"; 9991da177e4SLinus Torvalds print "<tbody>\n"; 10001da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 10011da177e4SLinus Torvalds my $parameter_name = $parameter; 10021da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 10031da177e4SLinus Torvalds 10041da177e4SLinus Torvalds print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n"; 10051da177e4SLinus Torvalds print " <entry>\n"; 10061da177e4SLinus Torvalds $lineprefix=" "; 10071da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 10081da177e4SLinus Torvalds print " </entry></row>\n"; 10091da177e4SLinus Torvalds } 10101da177e4SLinus Torvalds print " </tbody></tgroup></informaltable>\n"; 10111da177e4SLinus Torvalds } else { 10121da177e4SLinus Torvalds print " <para>\n None\n </para>\n"; 10131da177e4SLinus Torvalds } 10141da177e4SLinus Torvalds 10151da177e4SLinus Torvalds # print out each section 10161da177e4SLinus Torvalds $lineprefix=" "; 10171da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 10181da177e4SLinus Torvalds print "<simplesect>\n <title>$section</title>\n"; 10191da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 10201da177e4SLinus Torvalds print "<example><programlisting>\n"; 10211da177e4SLinus Torvalds } else { 10221da177e4SLinus Torvalds } 10231da177e4SLinus Torvalds print "<para>\n"; 10241da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 10251da177e4SLinus Torvalds print "</para>\n"; 10261da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 10271da177e4SLinus Torvalds print "</programlisting></example>\n"; 10281da177e4SLinus Torvalds } else { 10291da177e4SLinus Torvalds } 10301da177e4SLinus Torvalds print " </simplesect>\n"; 10311da177e4SLinus Torvalds } 10321da177e4SLinus Torvalds 10331da177e4SLinus Torvalds print "</sect2>\n\n"; 10341da177e4SLinus Torvalds} 10351da177e4SLinus Torvalds 10361da177e4SLinus Torvalds## 10371da177e4SLinus Torvalds# output function in man 10381da177e4SLinus Torvaldssub output_function_man(%) { 10391da177e4SLinus Torvalds my %args = %{$_[0]}; 10401da177e4SLinus Torvalds my ($parameter, $section); 10411da177e4SLinus Torvalds my $count; 10421da177e4SLinus Torvalds 10431da177e4SLinus Torvalds print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; 10441da177e4SLinus Torvalds 10451da177e4SLinus Torvalds print ".SH NAME\n"; 10461da177e4SLinus Torvalds print $args{'function'} . " \\- " . $args{'purpose'} . "\n"; 10471da177e4SLinus Torvalds 10481da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 1049a21217daSRandy Dunlap if ($args{'functiontype'} ne "") { 10501da177e4SLinus Torvalds print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n"; 1051a21217daSRandy Dunlap } else { 1052a21217daSRandy Dunlap print ".B \"" . $args{'function'} . "\n"; 1053a21217daSRandy Dunlap } 10541da177e4SLinus Torvalds $count = 0; 10551da177e4SLinus Torvalds my $parenth = "("; 10561da177e4SLinus Torvalds my $post = ","; 10571da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 10581da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 10591da177e4SLinus Torvalds $post = ");"; 10601da177e4SLinus Torvalds } 10611da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 10621da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 10631da177e4SLinus Torvalds # pointer-to-function 10641da177e4SLinus Torvalds print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n"; 10651da177e4SLinus Torvalds } else { 10661da177e4SLinus Torvalds $type =~ s/([^\*])$/$1 /; 10671da177e4SLinus Torvalds print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n"; 10681da177e4SLinus Torvalds } 10691da177e4SLinus Torvalds $count++; 10701da177e4SLinus Torvalds $parenth = ""; 10711da177e4SLinus Torvalds } 10721da177e4SLinus Torvalds 10731da177e4SLinus Torvalds print ".SH ARGUMENTS\n"; 10741da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 10751da177e4SLinus Torvalds my $parameter_name = $parameter; 10761da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 10771da177e4SLinus Torvalds 10781da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 10791da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 10801da177e4SLinus Torvalds } 10811da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 10821da177e4SLinus Torvalds print ".SH \"", uc $section, "\"\n"; 10831da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 10841da177e4SLinus Torvalds } 10851da177e4SLinus Torvalds} 10861da177e4SLinus Torvalds 10871da177e4SLinus Torvalds## 10881da177e4SLinus Torvalds# output enum in man 10891da177e4SLinus Torvaldssub output_enum_man(%) { 10901da177e4SLinus Torvalds my %args = %{$_[0]}; 10911da177e4SLinus Torvalds my ($parameter, $section); 10921da177e4SLinus Torvalds my $count; 10931da177e4SLinus Torvalds 10941da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n"; 10951da177e4SLinus Torvalds 10961da177e4SLinus Torvalds print ".SH NAME\n"; 10971da177e4SLinus Torvalds print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n"; 10981da177e4SLinus Torvalds 10991da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 11001da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 11011da177e4SLinus Torvalds $count = 0; 11021da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 11031da177e4SLinus Torvalds print ".br\n.BI \" $parameter\"\n"; 11041da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 11051da177e4SLinus Torvalds print "\n};\n"; 11061da177e4SLinus Torvalds last; 11071da177e4SLinus Torvalds } 11081da177e4SLinus Torvalds else { 11091da177e4SLinus Torvalds print ", \n.br\n"; 11101da177e4SLinus Torvalds } 11111da177e4SLinus Torvalds $count++; 11121da177e4SLinus Torvalds } 11131da177e4SLinus Torvalds 11141da177e4SLinus Torvalds print ".SH Constants\n"; 11151da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 11161da177e4SLinus Torvalds my $parameter_name = $parameter; 11171da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 11181da177e4SLinus Torvalds 11191da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 11201da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 11211da177e4SLinus Torvalds } 11221da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 11231da177e4SLinus Torvalds print ".SH \"$section\"\n"; 11241da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 11251da177e4SLinus Torvalds } 11261da177e4SLinus Torvalds} 11271da177e4SLinus Torvalds 11281da177e4SLinus Torvalds## 11291da177e4SLinus Torvalds# output struct in man 11301da177e4SLinus Torvaldssub output_struct_man(%) { 11311da177e4SLinus Torvalds my %args = %{$_[0]}; 11321da177e4SLinus Torvalds my ($parameter, $section); 11331da177e4SLinus Torvalds 11341da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n"; 11351da177e4SLinus Torvalds 11361da177e4SLinus Torvalds print ".SH NAME\n"; 11371da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n"; 11381da177e4SLinus Torvalds 11391da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 11401da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n.br\n"; 11411da177e4SLinus Torvalds 11421da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 11431da177e4SLinus Torvalds if ($parameter =~ /^#/) { 11441da177e4SLinus Torvalds print ".BI \"$parameter\"\n.br\n"; 11451da177e4SLinus Torvalds next; 11461da177e4SLinus Torvalds } 11471da177e4SLinus Torvalds my $parameter_name = $parameter; 11481da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 11491da177e4SLinus Torvalds 11501da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 11511da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 11521da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 11531da177e4SLinus Torvalds # pointer-to-function 11541da177e4SLinus Torvalds print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n"; 11551da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 11561d7e1d45SRandy.Dunlap # bitfield 11571d7e1d45SRandy.Dunlap print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n"; 11581da177e4SLinus Torvalds } else { 11591da177e4SLinus Torvalds $type =~ s/([^\*])$/$1 /; 11601da177e4SLinus Torvalds print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n"; 11611da177e4SLinus Torvalds } 11621da177e4SLinus Torvalds print "\n.br\n"; 11631da177e4SLinus Torvalds } 11641da177e4SLinus Torvalds print "};\n.br\n"; 11651da177e4SLinus Torvalds 1166c51d3dacSRandy Dunlap print ".SH Members\n"; 11671da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 11681da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 11691da177e4SLinus Torvalds 11701da177e4SLinus Torvalds my $parameter_name = $parameter; 11711da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 11721da177e4SLinus Torvalds 11731da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 11741da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 11751da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 11761da177e4SLinus Torvalds } 11771da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 11781da177e4SLinus Torvalds print ".SH \"$section\"\n"; 11791da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 11801da177e4SLinus Torvalds } 11811da177e4SLinus Torvalds} 11821da177e4SLinus Torvalds 11831da177e4SLinus Torvalds## 11841da177e4SLinus Torvalds# output typedef in man 11851da177e4SLinus Torvaldssub output_typedef_man(%) { 11861da177e4SLinus Torvalds my %args = %{$_[0]}; 11871da177e4SLinus Torvalds my ($parameter, $section); 11881da177e4SLinus Torvalds 11891da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n"; 11901da177e4SLinus Torvalds 11911da177e4SLinus Torvalds print ".SH NAME\n"; 11921da177e4SLinus Torvalds print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n"; 11931da177e4SLinus Torvalds 11941da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 11951da177e4SLinus Torvalds print ".SH \"$section\"\n"; 11961da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 11971da177e4SLinus Torvalds } 11981da177e4SLinus Torvalds} 11991da177e4SLinus Torvalds 1200b112e0f7SJohannes Bergsub output_blockhead_man(%) { 12011da177e4SLinus Torvalds my %args = %{$_[0]}; 12021da177e4SLinus Torvalds my ($parameter, $section); 12031da177e4SLinus Torvalds my $count; 12041da177e4SLinus Torvalds 12051da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; 12061da177e4SLinus Torvalds 12071da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 12081da177e4SLinus Torvalds print ".SH \"$section\"\n"; 12091da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 12101da177e4SLinus Torvalds } 12111da177e4SLinus Torvalds} 12121da177e4SLinus Torvalds 12131da177e4SLinus Torvalds## 12141da177e4SLinus Torvalds# output in text 12151da177e4SLinus Torvaldssub output_function_text(%) { 12161da177e4SLinus Torvalds my %args = %{$_[0]}; 12171da177e4SLinus Torvalds my ($parameter, $section); 1218a21217daSRandy Dunlap my $start; 12191da177e4SLinus Torvalds 1220f47634b2SRandy Dunlap print "Name:\n\n"; 1221f47634b2SRandy Dunlap print $args{'function'} . " - " . $args{'purpose'} . "\n"; 1222f47634b2SRandy Dunlap 1223f47634b2SRandy Dunlap print "\nSynopsis:\n\n"; 1224a21217daSRandy Dunlap if ($args{'functiontype'} ne "") { 1225a21217daSRandy Dunlap $start = $args{'functiontype'} . " " . $args{'function'} . " ("; 1226a21217daSRandy Dunlap } else { 1227a21217daSRandy Dunlap $start = $args{'function'} . " ("; 1228a21217daSRandy Dunlap } 12291da177e4SLinus Torvalds print $start; 1230a21217daSRandy Dunlap 12311da177e4SLinus Torvalds my $count = 0; 12321da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 12331da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 12341da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 12351da177e4SLinus Torvalds # pointer-to-function 12361da177e4SLinus Torvalds print $1 . $parameter . ") (" . $2; 12371da177e4SLinus Torvalds } else { 12381da177e4SLinus Torvalds print $type . " " . $parameter; 12391da177e4SLinus Torvalds } 12401da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 12411da177e4SLinus Torvalds $count++; 12421da177e4SLinus Torvalds print ",\n"; 12431da177e4SLinus Torvalds print " " x length($start); 12441da177e4SLinus Torvalds } else { 12451da177e4SLinus Torvalds print ");\n\n"; 12461da177e4SLinus Torvalds } 12471da177e4SLinus Torvalds } 12481da177e4SLinus Torvalds 12491da177e4SLinus Torvalds print "Arguments:\n\n"; 12501da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 12511da177e4SLinus Torvalds my $parameter_name = $parameter; 12521da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 12531da177e4SLinus Torvalds 12541da177e4SLinus Torvalds print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n"; 12551da177e4SLinus Torvalds } 12561da177e4SLinus Torvalds output_section_text(@_); 12571da177e4SLinus Torvalds} 12581da177e4SLinus Torvalds 12591da177e4SLinus Torvalds#output sections in text 12601da177e4SLinus Torvaldssub output_section_text(%) { 12611da177e4SLinus Torvalds my %args = %{$_[0]}; 12621da177e4SLinus Torvalds my $section; 12631da177e4SLinus Torvalds 12641da177e4SLinus Torvalds print "\n"; 12651da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 12661da177e4SLinus Torvalds print "$section:\n\n"; 12671da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 12681da177e4SLinus Torvalds } 12691da177e4SLinus Torvalds print "\n\n"; 12701da177e4SLinus Torvalds} 12711da177e4SLinus Torvalds 12721da177e4SLinus Torvalds# output enum in text 12731da177e4SLinus Torvaldssub output_enum_text(%) { 12741da177e4SLinus Torvalds my %args = %{$_[0]}; 12751da177e4SLinus Torvalds my ($parameter); 12761da177e4SLinus Torvalds my $count; 12771da177e4SLinus Torvalds print "Enum:\n\n"; 12781da177e4SLinus Torvalds 12791d7e1d45SRandy.Dunlap print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n"; 12801da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 12811da177e4SLinus Torvalds $count = 0; 12821da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 12831da177e4SLinus Torvalds print "\t$parameter"; 12841da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 12851da177e4SLinus Torvalds $count++; 12861da177e4SLinus Torvalds print ","; 12871da177e4SLinus Torvalds } 12881da177e4SLinus Torvalds print "\n"; 12891da177e4SLinus Torvalds } 12901da177e4SLinus Torvalds print "};\n\n"; 12911da177e4SLinus Torvalds 12921da177e4SLinus Torvalds print "Constants:\n\n"; 12931da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 12941da177e4SLinus Torvalds print "$parameter\n\t"; 12951da177e4SLinus Torvalds print $args{'parameterdescs'}{$parameter} . "\n"; 12961da177e4SLinus Torvalds } 12971da177e4SLinus Torvalds 12981da177e4SLinus Torvalds output_section_text(@_); 12991da177e4SLinus Torvalds} 13001da177e4SLinus Torvalds 13011da177e4SLinus Torvalds# output typedef in text 13021da177e4SLinus Torvaldssub output_typedef_text(%) { 13031da177e4SLinus Torvalds my %args = %{$_[0]}; 13041da177e4SLinus Torvalds my ($parameter); 13051da177e4SLinus Torvalds my $count; 13061da177e4SLinus Torvalds print "Typedef:\n\n"; 13071da177e4SLinus Torvalds 13081d7e1d45SRandy.Dunlap print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n"; 13091da177e4SLinus Torvalds output_section_text(@_); 13101da177e4SLinus Torvalds} 13111da177e4SLinus Torvalds 13121da177e4SLinus Torvalds# output struct as text 13131da177e4SLinus Torvaldssub output_struct_text(%) { 13141da177e4SLinus Torvalds my %args = %{$_[0]}; 13151da177e4SLinus Torvalds my ($parameter); 13161da177e4SLinus Torvalds 13171d7e1d45SRandy.Dunlap print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n"; 13181da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n"; 13191da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 13201da177e4SLinus Torvalds if ($parameter =~ /^#/) { 13211da177e4SLinus Torvalds print "$parameter\n"; 13221da177e4SLinus Torvalds next; 13231da177e4SLinus Torvalds } 13241da177e4SLinus Torvalds 13251da177e4SLinus Torvalds my $parameter_name = $parameter; 13261da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 13271da177e4SLinus Torvalds 13281da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 13291da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 13301da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 13311da177e4SLinus Torvalds # pointer-to-function 13321da177e4SLinus Torvalds print "\t$1 $parameter) ($2);\n"; 13331da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 133451f5a0c8SRandy Dunlap # bitfield 13351da177e4SLinus Torvalds print "\t$1 $parameter$2;\n"; 13361da177e4SLinus Torvalds } else { 13371da177e4SLinus Torvalds print "\t" . $type . " " . $parameter . ";\n"; 13381da177e4SLinus Torvalds } 13391da177e4SLinus Torvalds } 13401da177e4SLinus Torvalds print "};\n\n"; 13411da177e4SLinus Torvalds 13421da177e4SLinus Torvalds print "Members:\n\n"; 13431da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 13441da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 13451da177e4SLinus Torvalds 13461da177e4SLinus Torvalds my $parameter_name = $parameter; 13471da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 13481da177e4SLinus Torvalds 13491da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 13501da177e4SLinus Torvalds print "$parameter\n\t"; 13511da177e4SLinus Torvalds print $args{'parameterdescs'}{$parameter_name} . "\n"; 13521da177e4SLinus Torvalds } 13531da177e4SLinus Torvalds print "\n"; 13541da177e4SLinus Torvalds output_section_text(@_); 13551da177e4SLinus Torvalds} 13561da177e4SLinus Torvalds 1357b112e0f7SJohannes Bergsub output_blockhead_text(%) { 13581da177e4SLinus Torvalds my %args = %{$_[0]}; 13591da177e4SLinus Torvalds my ($parameter, $section); 13601da177e4SLinus Torvalds 13611da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 13621da177e4SLinus Torvalds print " $section:\n"; 13631da177e4SLinus Torvalds print " -> "; 13641da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 13651da177e4SLinus Torvalds } 13661da177e4SLinus Torvalds} 13671da177e4SLinus Torvalds 13681da177e4SLinus Torvalds## 136927205744SRandy Dunlap# generic output function for all types (function, struct/union, typedef, enum); 137027205744SRandy Dunlap# calls the generated, variable output_ function name based on 137127205744SRandy Dunlap# functype and output_mode 13721da177e4SLinus Torvaldssub output_declaration { 13731da177e4SLinus Torvalds no strict 'refs'; 13741da177e4SLinus Torvalds my $name = shift; 13751da177e4SLinus Torvalds my $functype = shift; 13761da177e4SLinus Torvalds my $func = "output_${functype}_$output_mode"; 13771da177e4SLinus Torvalds if (($function_only==0) || 13781da177e4SLinus Torvalds ( $function_only == 1 && defined($function_table{$name})) || 13791da177e4SLinus Torvalds ( $function_only == 2 && !defined($function_table{$name}))) 13801da177e4SLinus Torvalds { 13811da177e4SLinus Torvalds &$func(@_); 13821da177e4SLinus Torvalds $section_counter++; 13831da177e4SLinus Torvalds } 13841da177e4SLinus Torvalds} 13851da177e4SLinus Torvalds 13861da177e4SLinus Torvalds## 138727205744SRandy Dunlap# generic output function - calls the right one based on current output mode. 1388b112e0f7SJohannes Bergsub output_blockhead { 13891da177e4SLinus Torvalds no strict 'refs'; 1390b112e0f7SJohannes Berg my $func = "output_blockhead_" . $output_mode; 13911da177e4SLinus Torvalds &$func(@_); 13921da177e4SLinus Torvalds $section_counter++; 13931da177e4SLinus Torvalds} 13941da177e4SLinus Torvalds 13951da177e4SLinus Torvalds## 13961da177e4SLinus Torvalds# takes a declaration (struct, union, enum, typedef) and 13971da177e4SLinus Torvalds# invokes the right handler. NOT called for functions. 13981da177e4SLinus Torvaldssub dump_declaration($$) { 13991da177e4SLinus Torvalds no strict 'refs'; 14001da177e4SLinus Torvalds my ($prototype, $file) = @_; 14011da177e4SLinus Torvalds my $func = "dump_" . $decl_type; 14021da177e4SLinus Torvalds &$func(@_); 14031da177e4SLinus Torvalds} 14041da177e4SLinus Torvalds 14051da177e4SLinus Torvaldssub dump_union($$) { 14061da177e4SLinus Torvalds dump_struct(@_); 14071da177e4SLinus Torvalds} 14081da177e4SLinus Torvalds 14091da177e4SLinus Torvaldssub dump_struct($$) { 14101da177e4SLinus Torvalds my $x = shift; 14111da177e4SLinus Torvalds my $file = shift; 1412a1d94aa5SRandy Dunlap my $nested; 14131da177e4SLinus Torvalds 14141da177e4SLinus Torvalds if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) { 141552dc5aecSRandy Dunlap #my $decl_type = $1; 14161da177e4SLinus Torvalds $declaration_name = $2; 14171da177e4SLinus Torvalds my $members = $3; 14181da177e4SLinus Torvalds 14191da177e4SLinus Torvalds # ignore embedded structs or unions 1420a1d94aa5SRandy Dunlap $members =~ s/({.*})//g; 1421a1d94aa5SRandy Dunlap $nested = $1; 14221da177e4SLinus Torvalds 1423aeec46b9SMartin Waitz # ignore members marked private: 142452dc5aecSRandy Dunlap $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gos; 142552dc5aecSRandy Dunlap $members =~ s/\/\*\s*private:.*//gos; 1426aeec46b9SMartin Waitz # strip comments: 1427aeec46b9SMartin Waitz $members =~ s/\/\*.*?\*\///gos; 1428a1d94aa5SRandy Dunlap $nested =~ s/\/\*.*?\*\///gos; 1429*d960eea9SRandy Dunlap # strip kmemcheck_bitfield_{begin,end}.*; 1430*d960eea9SRandy Dunlap $members =~ s/kmemcheck_bitfield_.*?;//gos; 1431aeec46b9SMartin Waitz 14321da177e4SLinus Torvalds create_parameterlist($members, ';', $file); 1433a1d94aa5SRandy Dunlap check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested); 14341da177e4SLinus Torvalds 14351da177e4SLinus Torvalds output_declaration($declaration_name, 14361da177e4SLinus Torvalds 'struct', 14371da177e4SLinus Torvalds {'struct' => $declaration_name, 14381da177e4SLinus Torvalds 'module' => $modulename, 14391da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 14401da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 14411da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 14421da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 14431da177e4SLinus Torvalds 'sections' => \%sections, 14441da177e4SLinus Torvalds 'purpose' => $declaration_purpose, 14451da177e4SLinus Torvalds 'type' => $decl_type 14461da177e4SLinus Torvalds }); 14471da177e4SLinus Torvalds } 14481da177e4SLinus Torvalds else { 14491da177e4SLinus Torvalds print STDERR "Error(${file}:$.): Cannot parse struct or union!\n"; 14501da177e4SLinus Torvalds ++$errors; 14511da177e4SLinus Torvalds } 14521da177e4SLinus Torvalds} 14531da177e4SLinus Torvalds 14541da177e4SLinus Torvaldssub dump_enum($$) { 14551da177e4SLinus Torvalds my $x = shift; 14561da177e4SLinus Torvalds my $file = shift; 14571da177e4SLinus Torvalds 1458aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 14591da177e4SLinus Torvalds if ($x =~ /enum\s+(\w+)\s*{(.*)}/) { 14601da177e4SLinus Torvalds $declaration_name = $1; 14611da177e4SLinus Torvalds my $members = $2; 14621da177e4SLinus Torvalds 14631da177e4SLinus Torvalds foreach my $arg (split ',', $members) { 14641da177e4SLinus Torvalds $arg =~ s/^\s*(\w+).*/$1/; 14651da177e4SLinus Torvalds push @parameterlist, $arg; 14661da177e4SLinus Torvalds if (!$parameterdescs{$arg}) { 14671da177e4SLinus Torvalds $parameterdescs{$arg} = $undescribed; 14681da177e4SLinus Torvalds print STDERR "Warning(${file}:$.): Enum value '$arg' ". 14691da177e4SLinus Torvalds "not described in enum '$declaration_name'\n"; 14701da177e4SLinus Torvalds } 14711da177e4SLinus Torvalds 14721da177e4SLinus Torvalds } 14731da177e4SLinus Torvalds 14741da177e4SLinus Torvalds output_declaration($declaration_name, 14751da177e4SLinus Torvalds 'enum', 14761da177e4SLinus Torvalds {'enum' => $declaration_name, 14771da177e4SLinus Torvalds 'module' => $modulename, 14781da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 14791da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 14801da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 14811da177e4SLinus Torvalds 'sections' => \%sections, 14821da177e4SLinus Torvalds 'purpose' => $declaration_purpose 14831da177e4SLinus Torvalds }); 14841da177e4SLinus Torvalds } 14851da177e4SLinus Torvalds else { 14861da177e4SLinus Torvalds print STDERR "Error(${file}:$.): Cannot parse enum!\n"; 14871da177e4SLinus Torvalds ++$errors; 14881da177e4SLinus Torvalds } 14891da177e4SLinus Torvalds} 14901da177e4SLinus Torvalds 14911da177e4SLinus Torvaldssub dump_typedef($$) { 14921da177e4SLinus Torvalds my $x = shift; 14931da177e4SLinus Torvalds my $file = shift; 14941da177e4SLinus Torvalds 1495aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 14961da177e4SLinus Torvalds while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { 14971da177e4SLinus Torvalds $x =~ s/\(*.\)\s*;$/;/; 14981da177e4SLinus Torvalds $x =~ s/\[*.\]\s*;$/;/; 14991da177e4SLinus Torvalds } 15001da177e4SLinus Torvalds 15011da177e4SLinus Torvalds if ($x =~ /typedef.*\s+(\w+)\s*;/) { 15021da177e4SLinus Torvalds $declaration_name = $1; 15031da177e4SLinus Torvalds 15041da177e4SLinus Torvalds output_declaration($declaration_name, 15051da177e4SLinus Torvalds 'typedef', 15061da177e4SLinus Torvalds {'typedef' => $declaration_name, 15071da177e4SLinus Torvalds 'module' => $modulename, 15081da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 15091da177e4SLinus Torvalds 'sections' => \%sections, 15101da177e4SLinus Torvalds 'purpose' => $declaration_purpose 15111da177e4SLinus Torvalds }); 15121da177e4SLinus Torvalds } 15131da177e4SLinus Torvalds else { 15141da177e4SLinus Torvalds print STDERR "Error(${file}:$.): Cannot parse typedef!\n"; 15151da177e4SLinus Torvalds ++$errors; 15161da177e4SLinus Torvalds } 15171da177e4SLinus Torvalds} 15181da177e4SLinus Torvalds 1519a1d94aa5SRandy Dunlapsub save_struct_actual($) { 1520a1d94aa5SRandy Dunlap my $actual = shift; 1521a1d94aa5SRandy Dunlap 1522a1d94aa5SRandy Dunlap # strip all spaces from the actual param so that it looks like one string item 1523a1d94aa5SRandy Dunlap $actual =~ s/\s*//g; 1524a1d94aa5SRandy Dunlap $struct_actual = $struct_actual . $actual . " "; 1525a1d94aa5SRandy Dunlap} 1526a1d94aa5SRandy Dunlap 15271da177e4SLinus Torvaldssub create_parameterlist($$$) { 15281da177e4SLinus Torvalds my $args = shift; 15291da177e4SLinus Torvalds my $splitter = shift; 15301da177e4SLinus Torvalds my $file = shift; 15311da177e4SLinus Torvalds my $type; 15321da177e4SLinus Torvalds my $param; 15331da177e4SLinus Torvalds 1534a6d3fe77SMartin Waitz # temporarily replace commas inside function pointer definition 15351da177e4SLinus Torvalds while ($args =~ /(\([^\),]+),/) { 15361da177e4SLinus Torvalds $args =~ s/(\([^\),]+),/$1#/g; 15371da177e4SLinus Torvalds } 15381da177e4SLinus Torvalds 15391da177e4SLinus Torvalds foreach my $arg (split($splitter, $args)) { 15401da177e4SLinus Torvalds # strip comments 15411da177e4SLinus Torvalds $arg =~ s/\/\*.*\*\///; 15421da177e4SLinus Torvalds # strip leading/trailing spaces 15431da177e4SLinus Torvalds $arg =~ s/^\s*//; 15441da177e4SLinus Torvalds $arg =~ s/\s*$//; 15451da177e4SLinus Torvalds $arg =~ s/\s+/ /; 15461da177e4SLinus Torvalds 15471da177e4SLinus Torvalds if ($arg =~ /^#/) { 15481da177e4SLinus Torvalds # Treat preprocessor directive as a typeless variable just to fill 15491da177e4SLinus Torvalds # corresponding data structures "correctly". Catch it later in 15501da177e4SLinus Torvalds # output_* subs. 15511da177e4SLinus Torvalds push_parameter($arg, "", $file); 155200d62961SRichard Kennedy } elsif ($arg =~ m/\(.+\)\s*\(/) { 15531da177e4SLinus Torvalds # pointer-to-function 15541da177e4SLinus Torvalds $arg =~ tr/#/,/; 155500d62961SRichard Kennedy $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/; 15561da177e4SLinus Torvalds $param = $1; 15571da177e4SLinus Torvalds $type = $arg; 155800d62961SRichard Kennedy $type =~ s/([^\(]+\(\*?)\s*$param/$1/; 1559a1d94aa5SRandy Dunlap save_struct_actual($param); 15601da177e4SLinus Torvalds push_parameter($param, $type, $file); 1561aeec46b9SMartin Waitz } elsif ($arg) { 15621da177e4SLinus Torvalds $arg =~ s/\s*:\s*/:/g; 15631da177e4SLinus Torvalds $arg =~ s/\s*\[/\[/g; 15641da177e4SLinus Torvalds 15651da177e4SLinus Torvalds my @args = split('\s*,\s*', $arg); 15661da177e4SLinus Torvalds if ($args[0] =~ m/\*/) { 15671da177e4SLinus Torvalds $args[0] =~ s/(\*+)\s*/ $1/; 15681da177e4SLinus Torvalds } 1569884f2810SBorislav Petkov 1570884f2810SBorislav Petkov my @first_arg; 1571884f2810SBorislav Petkov if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) { 1572884f2810SBorislav Petkov shift @args; 1573884f2810SBorislav Petkov push(@first_arg, split('\s+', $1)); 1574884f2810SBorislav Petkov push(@first_arg, $2); 1575884f2810SBorislav Petkov } else { 1576884f2810SBorislav Petkov @first_arg = split('\s+', shift @args); 1577884f2810SBorislav Petkov } 1578884f2810SBorislav Petkov 15791da177e4SLinus Torvalds unshift(@args, pop @first_arg); 15801da177e4SLinus Torvalds $type = join " ", @first_arg; 15811da177e4SLinus Torvalds 15821da177e4SLinus Torvalds foreach $param (@args) { 15831da177e4SLinus Torvalds if ($param =~ m/^(\*+)\s*(.*)/) { 1584a1d94aa5SRandy Dunlap save_struct_actual($2); 15851da177e4SLinus Torvalds push_parameter($2, "$type $1", $file); 15861da177e4SLinus Torvalds } 15871da177e4SLinus Torvalds elsif ($param =~ m/(.*?):(\d+)/) { 15887b97887eSRandy Dunlap if ($type ne "") { # skip unnamed bit-fields 1589a1d94aa5SRandy Dunlap save_struct_actual($1); 15901da177e4SLinus Torvalds push_parameter($1, "$type:$2", $file) 15911da177e4SLinus Torvalds } 15927b97887eSRandy Dunlap } 15931da177e4SLinus Torvalds else { 1594a1d94aa5SRandy Dunlap save_struct_actual($param); 15951da177e4SLinus Torvalds push_parameter($param, $type, $file); 15961da177e4SLinus Torvalds } 15971da177e4SLinus Torvalds } 15981da177e4SLinus Torvalds } 15991da177e4SLinus Torvalds } 16001da177e4SLinus Torvalds} 16011da177e4SLinus Torvalds 16021da177e4SLinus Torvaldssub push_parameter($$$) { 16031da177e4SLinus Torvalds my $param = shift; 16041da177e4SLinus Torvalds my $type = shift; 16051da177e4SLinus Torvalds my $file = shift; 16061da177e4SLinus Torvalds 16075f8c7c98SRandy Dunlap if (($anon_struct_union == 1) && ($type eq "") && 16085f8c7c98SRandy Dunlap ($param eq "}")) { 16095f8c7c98SRandy Dunlap return; # ignore the ending }; from anon. struct/union 16105f8c7c98SRandy Dunlap } 16115f8c7c98SRandy Dunlap 16125f8c7c98SRandy Dunlap $anon_struct_union = 0; 16131da177e4SLinus Torvalds my $param_name = $param; 16141da177e4SLinus Torvalds $param_name =~ s/\[.*//; 16151da177e4SLinus Torvalds 1616a6d3fe77SMartin Waitz if ($type eq "" && $param =~ /\.\.\.$/) 16171da177e4SLinus Torvalds { 1618ced69090SRandy Dunlap if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { 1619a6d3fe77SMartin Waitz $parameterdescs{$param} = "variable arguments"; 16201da177e4SLinus Torvalds } 1621ced69090SRandy Dunlap } 16221da177e4SLinus Torvalds elsif ($type eq "" && ($param eq "" or $param eq "void")) 16231da177e4SLinus Torvalds { 16241da177e4SLinus Torvalds $param="void"; 16251da177e4SLinus Torvalds $parameterdescs{void} = "no arguments"; 16261da177e4SLinus Torvalds } 1627134fe01bSRandy Dunlap elsif ($type eq "" && ($param eq "struct" or $param eq "union")) 1628134fe01bSRandy Dunlap # handle unnamed (anonymous) union or struct: 1629134fe01bSRandy Dunlap { 1630134fe01bSRandy Dunlap $type = $param; 1631134fe01bSRandy Dunlap $param = "{unnamed_" . $param . "}"; 1632134fe01bSRandy Dunlap $parameterdescs{$param} = "anonymous\n"; 16335f8c7c98SRandy Dunlap $anon_struct_union = 1; 1634134fe01bSRandy Dunlap } 1635134fe01bSRandy Dunlap 1636a6d3fe77SMartin Waitz # warn if parameter has no description 1637134fe01bSRandy Dunlap # (but ignore ones starting with # as these are not parameters 1638134fe01bSRandy Dunlap # but inline preprocessor statements); 1639134fe01bSRandy Dunlap # also ignore unnamed structs/unions; 16405f8c7c98SRandy Dunlap if (!$anon_struct_union) { 1641a6d3fe77SMartin Waitz if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) { 1642a6d3fe77SMartin Waitz 16431da177e4SLinus Torvalds $parameterdescs{$param_name} = $undescribed; 16441da177e4SLinus Torvalds 16451da177e4SLinus Torvalds if (($type eq 'function') || ($type eq 'enum')) { 16461da177e4SLinus Torvalds print STDERR "Warning(${file}:$.): Function parameter ". 16471da177e4SLinus Torvalds "or member '$param' not " . 16481da177e4SLinus Torvalds "described in '$declaration_name'\n"; 16491da177e4SLinus Torvalds } 16501da177e4SLinus Torvalds print STDERR "Warning(${file}:$.):" . 16511da177e4SLinus Torvalds " No description found for parameter '$param'\n"; 16521da177e4SLinus Torvalds ++$warnings; 16531da177e4SLinus Torvalds } 1654134fe01bSRandy Dunlap } 16551da177e4SLinus Torvalds 1656e34e7dbbSRandy Dunlap # strip spaces from $param so that it is one continous string 1657e34e7dbbSRandy Dunlap # on @parameterlist; 1658e34e7dbbSRandy Dunlap # this fixes a problem where check_sections() cannot find 1659e34e7dbbSRandy Dunlap # a parameter like "addr[6 + 2]" because it actually appears 1660e34e7dbbSRandy Dunlap # as "addr[6", "+", "2]" on the parameter list; 1661e34e7dbbSRandy Dunlap # but it's better to maintain the param string unchanged for output, 1662e34e7dbbSRandy Dunlap # so just weaken the string compare in check_sections() to ignore 1663e34e7dbbSRandy Dunlap # "[blah" in a parameter string; 1664e34e7dbbSRandy Dunlap ###$param =~ s/\s*//g; 16651da177e4SLinus Torvalds push @parameterlist, $param; 16661da177e4SLinus Torvalds $parametertypes{$param} = $type; 16671da177e4SLinus Torvalds} 16681da177e4SLinus Torvalds 1669a1d94aa5SRandy Dunlapsub check_sections($$$$$$) { 1670a1d94aa5SRandy Dunlap my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_; 1671a1d94aa5SRandy Dunlap my @sects = split ' ', $sectcheck; 1672a1d94aa5SRandy Dunlap my @prms = split ' ', $prmscheck; 1673a1d94aa5SRandy Dunlap my $err; 1674a1d94aa5SRandy Dunlap my ($px, $sx); 1675a1d94aa5SRandy Dunlap my $prm_clean; # strip trailing "[array size]" and/or beginning "*" 1676a1d94aa5SRandy Dunlap 1677a1d94aa5SRandy Dunlap foreach $sx (0 .. $#sects) { 1678a1d94aa5SRandy Dunlap $err = 1; 1679a1d94aa5SRandy Dunlap foreach $px (0 .. $#prms) { 1680a1d94aa5SRandy Dunlap $prm_clean = $prms[$px]; 1681a1d94aa5SRandy Dunlap $prm_clean =~ s/\[.*\]//; 1682a1d94aa5SRandy Dunlap $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//; 1683e34e7dbbSRandy Dunlap # ignore array size in a parameter string; 1684e34e7dbbSRandy Dunlap # however, the original param string may contain 1685e34e7dbbSRandy Dunlap # spaces, e.g.: addr[6 + 2] 1686e34e7dbbSRandy Dunlap # and this appears in @prms as "addr[6" since the 1687e34e7dbbSRandy Dunlap # parameter list is split at spaces; 1688e34e7dbbSRandy Dunlap # hence just ignore "[..." for the sections check; 1689e34e7dbbSRandy Dunlap $prm_clean =~ s/\[.*//; 1690e34e7dbbSRandy Dunlap 1691a1d94aa5SRandy Dunlap ##$prm_clean =~ s/^\**//; 1692a1d94aa5SRandy Dunlap if ($prm_clean eq $sects[$sx]) { 1693a1d94aa5SRandy Dunlap $err = 0; 1694a1d94aa5SRandy Dunlap last; 1695a1d94aa5SRandy Dunlap } 1696a1d94aa5SRandy Dunlap } 1697a1d94aa5SRandy Dunlap if ($err) { 1698a1d94aa5SRandy Dunlap if ($decl_type eq "function") { 1699a1d94aa5SRandy Dunlap print STDERR "Warning(${file}:$.): " . 1700a1d94aa5SRandy Dunlap "Excess function parameter " . 1701a1d94aa5SRandy Dunlap "'$sects[$sx]' " . 1702a1d94aa5SRandy Dunlap "description in '$decl_name'\n"; 1703a1d94aa5SRandy Dunlap ++$warnings; 1704a1d94aa5SRandy Dunlap } else { 1705a1d94aa5SRandy Dunlap if ($nested !~ m/\Q$sects[$sx]\E/) { 1706a1d94aa5SRandy Dunlap print STDERR "Warning(${file}:$.): " . 1707a1d94aa5SRandy Dunlap "Excess struct/union/enum/typedef member " . 1708a1d94aa5SRandy Dunlap "'$sects[$sx]' " . 1709a1d94aa5SRandy Dunlap "description in '$decl_name'\n"; 1710a1d94aa5SRandy Dunlap ++$warnings; 1711a1d94aa5SRandy Dunlap } 1712a1d94aa5SRandy Dunlap } 1713a1d94aa5SRandy Dunlap } 1714a1d94aa5SRandy Dunlap } 1715a1d94aa5SRandy Dunlap} 1716a1d94aa5SRandy Dunlap 17171da177e4SLinus Torvalds## 17181da177e4SLinus Torvalds# takes a function prototype and the name of the current file being 17191da177e4SLinus Torvalds# processed and spits out all the details stored in the global 17201da177e4SLinus Torvalds# arrays/hashes. 17211da177e4SLinus Torvaldssub dump_function($$) { 17221da177e4SLinus Torvalds my $prototype = shift; 17231da177e4SLinus Torvalds my $file = shift; 17241da177e4SLinus Torvalds 17251da177e4SLinus Torvalds $prototype =~ s/^static +//; 17261da177e4SLinus Torvalds $prototype =~ s/^extern +//; 17274dc3b16bSPavel Pisa $prototype =~ s/^asmlinkage +//; 17281da177e4SLinus Torvalds $prototype =~ s/^inline +//; 17291da177e4SLinus Torvalds $prototype =~ s/^__inline__ +//; 173032e79401SRandy Dunlap $prototype =~ s/^__inline +//; 173132e79401SRandy Dunlap $prototype =~ s/^__always_inline +//; 173232e79401SRandy Dunlap $prototype =~ s/^noinline +//; 17330129a057SRandy Dunlap $prototype =~ s/__devinit +//; 173474fc5c65SRandy Dunlap $prototype =~ s/__init +//; 1735890c78c2SRandy Dunlap $prototype =~ s/^#\s*define\s+//; #ak added 1736328d2440SRandy Dunlap $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//; 17371da177e4SLinus Torvalds 17381da177e4SLinus Torvalds # Yes, this truly is vile. We are looking for: 17391da177e4SLinus Torvalds # 1. Return type (may be nothing if we're looking at a macro) 17401da177e4SLinus Torvalds # 2. Function name 17411da177e4SLinus Torvalds # 3. Function parameters. 17421da177e4SLinus Torvalds # 17431da177e4SLinus Torvalds # All the while we have to watch out for function pointer parameters 17441da177e4SLinus Torvalds # (which IIRC is what the two sections are for), C types (these 17451da177e4SLinus Torvalds # regexps don't even start to express all the possibilities), and 17461da177e4SLinus Torvalds # so on. 17471da177e4SLinus Torvalds # 17481da177e4SLinus Torvalds # If you mess with these regexps, it's a good idea to check that 17491da177e4SLinus Torvalds # the following functions' documentation still comes out right: 17501da177e4SLinus Torvalds # - parport_register_device (function pointer parameters) 17511da177e4SLinus Torvalds # - atomic_set (macro) 17529598f91fSMartin Waitz # - pci_match_device, __copy_to_user (long return type) 17531da177e4SLinus Torvalds 17541da177e4SLinus Torvalds if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 17551da177e4SLinus Torvalds $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 17561da177e4SLinus Torvalds $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 17571da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 175894b3e03cSRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 17591da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 17601da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 17611da177e4SLinus Torvalds $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 17621da177e4SLinus Torvalds $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 17631da177e4SLinus Torvalds $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 17641da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 17651da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 17661da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 17679598f91fSMartin Waitz $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 17689598f91fSMartin Waitz $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 1769412ecd77SRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 1770412ecd77SRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) { 17711da177e4SLinus Torvalds $return_type = $1; 17721da177e4SLinus Torvalds $declaration_name = $2; 17731da177e4SLinus Torvalds my $args = $3; 17741da177e4SLinus Torvalds 17751da177e4SLinus Torvalds create_parameterlist($args, ',', $file); 17761da177e4SLinus Torvalds } else { 17771da177e4SLinus Torvalds print STDERR "Error(${file}:$.): cannot understand prototype: '$prototype'\n"; 17781da177e4SLinus Torvalds ++$errors; 17791da177e4SLinus Torvalds return; 17801da177e4SLinus Torvalds } 17811da177e4SLinus Torvalds 1782a1d94aa5SRandy Dunlap my $prms = join " ", @parameterlist; 1783a1d94aa5SRandy Dunlap check_sections($file, $declaration_name, "function", $sectcheck, $prms, ""); 1784a1d94aa5SRandy Dunlap 17851da177e4SLinus Torvalds output_declaration($declaration_name, 17861da177e4SLinus Torvalds 'function', 17871da177e4SLinus Torvalds {'function' => $declaration_name, 17881da177e4SLinus Torvalds 'module' => $modulename, 17891da177e4SLinus Torvalds 'functiontype' => $return_type, 17901da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 17911da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 17921da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 17931da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 17941da177e4SLinus Torvalds 'sections' => \%sections, 17951da177e4SLinus Torvalds 'purpose' => $declaration_purpose 17961da177e4SLinus Torvalds }); 17971da177e4SLinus Torvalds} 17981da177e4SLinus Torvalds 17991da177e4SLinus Torvaldssub process_file($); 18001da177e4SLinus Torvalds 18011da177e4SLinus Torvalds# Read the file that maps relative names to absolute names for 18021da177e4SLinus Torvalds# separate source and object directories and for shadow trees. 18031da177e4SLinus Torvaldsif (open(SOURCE_MAP, "<.tmp_filelist.txt")) { 18041da177e4SLinus Torvalds my ($relname, $absname); 18051da177e4SLinus Torvalds while(<SOURCE_MAP>) { 18061da177e4SLinus Torvalds chop(); 18071da177e4SLinus Torvalds ($relname, $absname) = (split())[0..1]; 18081da177e4SLinus Torvalds $relname =~ s:^/+::; 18091da177e4SLinus Torvalds $source_map{$relname} = $absname; 18101da177e4SLinus Torvalds } 18111da177e4SLinus Torvalds close(SOURCE_MAP); 18121da177e4SLinus Torvalds} 18131da177e4SLinus Torvalds 18141da177e4SLinus Torvaldsif ($filelist) { 18151da177e4SLinus Torvalds open(FLIST,"<$filelist") or die "Can't open file list $filelist"; 18161da177e4SLinus Torvalds while(<FLIST>) { 18171da177e4SLinus Torvalds chop; 18181da177e4SLinus Torvalds process_file($_); 18191da177e4SLinus Torvalds } 18201da177e4SLinus Torvalds} 18211da177e4SLinus Torvalds 18221da177e4SLinus Torvaldsforeach (@ARGV) { 18231da177e4SLinus Torvalds chomp; 18241da177e4SLinus Torvalds process_file($_); 18251da177e4SLinus Torvalds} 18261da177e4SLinus Torvaldsif ($verbose && $errors) { 18271da177e4SLinus Torvalds print STDERR "$errors errors\n"; 18281da177e4SLinus Torvalds} 18291da177e4SLinus Torvaldsif ($verbose && $warnings) { 18301da177e4SLinus Torvalds print STDERR "$warnings warnings\n"; 18311da177e4SLinus Torvalds} 18321da177e4SLinus Torvalds 18331da177e4SLinus Torvaldsexit($errors); 18341da177e4SLinus Torvalds 18351da177e4SLinus Torvaldssub reset_state { 18361da177e4SLinus Torvalds $function = ""; 18371da177e4SLinus Torvalds %constants = (); 18381da177e4SLinus Torvalds %parameterdescs = (); 18391da177e4SLinus Torvalds %parametertypes = (); 18401da177e4SLinus Torvalds @parameterlist = (); 18411da177e4SLinus Torvalds %sections = (); 18421da177e4SLinus Torvalds @sectionlist = (); 1843a1d94aa5SRandy Dunlap $sectcheck = ""; 1844a1d94aa5SRandy Dunlap $struct_actual = ""; 18451da177e4SLinus Torvalds $prototype = ""; 18461da177e4SLinus Torvalds 18471da177e4SLinus Torvalds $state = 0; 18481da177e4SLinus Torvalds} 18491da177e4SLinus Torvalds 185056afb0f8SJason Baronsub tracepoint_munge($) { 185156afb0f8SJason Baron my $file = shift; 185256afb0f8SJason Baron my $tracepointname = 0; 185356afb0f8SJason Baron my $tracepointargs = 0; 185456afb0f8SJason Baron 185556afb0f8SJason Baron if($prototype =~ m/TRACE_EVENT\((.*?),/) { 185656afb0f8SJason Baron $tracepointname = $1; 185756afb0f8SJason Baron } 185856afb0f8SJason Baron if($prototype =~ m/TP_PROTO\((.*?)\)/) { 185956afb0f8SJason Baron $tracepointargs = $1; 186056afb0f8SJason Baron } 186156afb0f8SJason Baron if (($tracepointname eq 0) || ($tracepointargs eq 0)) { 186256afb0f8SJason Baron print STDERR "Warning(${file}:$.): Unrecognized tracepoint format: \n". 186356afb0f8SJason Baron "$prototype\n"; 186456afb0f8SJason Baron } else { 186556afb0f8SJason Baron $prototype = "static inline void trace_$tracepointname($tracepointargs)"; 186656afb0f8SJason Baron } 186756afb0f8SJason Baron} 186856afb0f8SJason Baron 1869b4870bc5SRandy Dunlapsub syscall_munge() { 1870b4870bc5SRandy Dunlap my $void = 0; 1871b4870bc5SRandy Dunlap 1872b4870bc5SRandy Dunlap $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs 1873b4870bc5SRandy Dunlap## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) { 1874b4870bc5SRandy Dunlap if ($prototype =~ m/SYSCALL_DEFINE0/) { 1875b4870bc5SRandy Dunlap $void = 1; 1876b4870bc5SRandy Dunlap## $prototype = "long sys_$1(void)"; 1877b4870bc5SRandy Dunlap } 1878b4870bc5SRandy Dunlap 1879b4870bc5SRandy Dunlap $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name 1880b4870bc5SRandy Dunlap if ($prototype =~ m/long (sys_.*?),/) { 1881b4870bc5SRandy Dunlap $prototype =~ s/,/\(/; 1882b4870bc5SRandy Dunlap } elsif ($void) { 1883b4870bc5SRandy Dunlap $prototype =~ s/\)/\(void\)/; 1884b4870bc5SRandy Dunlap } 1885b4870bc5SRandy Dunlap 1886b4870bc5SRandy Dunlap # now delete all of the odd-number commas in $prototype 1887b4870bc5SRandy Dunlap # so that arg types & arg names don't have a comma between them 1888b4870bc5SRandy Dunlap my $count = 0; 1889b4870bc5SRandy Dunlap my $len = length($prototype); 1890b4870bc5SRandy Dunlap if ($void) { 1891b4870bc5SRandy Dunlap $len = 0; # skip the for-loop 1892b4870bc5SRandy Dunlap } 1893b4870bc5SRandy Dunlap for (my $ix = 0; $ix < $len; $ix++) { 1894b4870bc5SRandy Dunlap if (substr($prototype, $ix, 1) eq ',') { 1895b4870bc5SRandy Dunlap $count++; 1896b4870bc5SRandy Dunlap if ($count % 2 == 1) { 1897b4870bc5SRandy Dunlap substr($prototype, $ix, 1) = ' '; 1898b4870bc5SRandy Dunlap } 1899b4870bc5SRandy Dunlap } 1900b4870bc5SRandy Dunlap } 1901b4870bc5SRandy Dunlap} 1902b4870bc5SRandy Dunlap 19031da177e4SLinus Torvaldssub process_state3_function($$) { 19041da177e4SLinus Torvalds my $x = shift; 19051da177e4SLinus Torvalds my $file = shift; 19061da177e4SLinus Torvalds 190751f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 190851f5a0c8SRandy Dunlap 1909890c78c2SRandy Dunlap if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) { 19101da177e4SLinus Torvalds # do nothing 19111da177e4SLinus Torvalds } 19121da177e4SLinus Torvalds elsif ($x =~ /([^\{]*)/) { 19131da177e4SLinus Torvalds $prototype .= $1; 19141da177e4SLinus Torvalds } 1915b4870bc5SRandy Dunlap 1916890c78c2SRandy Dunlap if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) { 19171da177e4SLinus Torvalds $prototype =~ s@/\*.*?\*/@@gos; # strip comments. 19181da177e4SLinus Torvalds $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 19191da177e4SLinus Torvalds $prototype =~ s@^\s+@@gos; # strip leading spaces 1920b4870bc5SRandy Dunlap if ($prototype =~ /SYSCALL_DEFINE/) { 1921b4870bc5SRandy Dunlap syscall_munge(); 1922b4870bc5SRandy Dunlap } 192356afb0f8SJason Baron if ($prototype =~ /TRACE_EVENT/) { 192456afb0f8SJason Baron tracepoint_munge($file); 192556afb0f8SJason Baron } 19261da177e4SLinus Torvalds dump_function($prototype, $file); 19271da177e4SLinus Torvalds reset_state(); 19281da177e4SLinus Torvalds } 19291da177e4SLinus Torvalds} 19301da177e4SLinus Torvalds 19311da177e4SLinus Torvaldssub process_state3_type($$) { 19321da177e4SLinus Torvalds my $x = shift; 19331da177e4SLinus Torvalds my $file = shift; 19341da177e4SLinus Torvalds 19351da177e4SLinus Torvalds $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 19361da177e4SLinus Torvalds $x =~ s@^\s+@@gos; # strip leading spaces 19371da177e4SLinus Torvalds $x =~ s@\s+$@@gos; # strip trailing spaces 193851f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 193951f5a0c8SRandy Dunlap 19401da177e4SLinus Torvalds if ($x =~ /^#/) { 19411da177e4SLinus Torvalds # To distinguish preprocessor directive from regular declaration later. 19421da177e4SLinus Torvalds $x .= ";"; 19431da177e4SLinus Torvalds } 19441da177e4SLinus Torvalds 19451da177e4SLinus Torvalds while (1) { 19461da177e4SLinus Torvalds if ( $x =~ /([^{};]*)([{};])(.*)/ ) { 19471da177e4SLinus Torvalds $prototype .= $1 . $2; 19481da177e4SLinus Torvalds ($2 eq '{') && $brcount++; 19491da177e4SLinus Torvalds ($2 eq '}') && $brcount--; 19501da177e4SLinus Torvalds if (($2 eq ';') && ($brcount == 0)) { 19511da177e4SLinus Torvalds dump_declaration($prototype, $file); 19521da177e4SLinus Torvalds reset_state(); 19531da177e4SLinus Torvalds last; 19541da177e4SLinus Torvalds } 19551da177e4SLinus Torvalds $x = $3; 19561da177e4SLinus Torvalds } else { 19571da177e4SLinus Torvalds $prototype .= $x; 19581da177e4SLinus Torvalds last; 19591da177e4SLinus Torvalds } 19601da177e4SLinus Torvalds } 19611da177e4SLinus Torvalds} 19621da177e4SLinus Torvalds 19636b5b55f6SRandy Dunlap# xml_escape: replace <, >, and & in the text stream; 19646b5b55f6SRandy Dunlap# 19656b5b55f6SRandy Dunlap# however, formatting controls that are generated internally/locally in the 19666b5b55f6SRandy Dunlap# kernel-doc script are not escaped here; instead, they begin life like 19676b5b55f6SRandy Dunlap# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings 19686b5b55f6SRandy Dunlap# are converted to their mnemonic-expected output, without the 4 * '\' & ':', 19696b5b55f6SRandy Dunlap# just before actual output; (this is done by local_unescape()) 19701da177e4SLinus Torvaldssub xml_escape($) { 19711da177e4SLinus Torvalds my $text = shift; 1972ecfb251aSRandy Dunlap if (($output_mode eq "text") || ($output_mode eq "man")) { 1973ecfb251aSRandy Dunlap return $text; 1974ecfb251aSRandy Dunlap } 19751da177e4SLinus Torvalds $text =~ s/\&/\\\\\\amp;/g; 19761da177e4SLinus Torvalds $text =~ s/\</\\\\\\lt;/g; 19771da177e4SLinus Torvalds $text =~ s/\>/\\\\\\gt;/g; 19781da177e4SLinus Torvalds return $text; 19791da177e4SLinus Torvalds} 19801da177e4SLinus Torvalds 19816b5b55f6SRandy Dunlap# convert local escape strings to html 19826b5b55f6SRandy Dunlap# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes) 19836b5b55f6SRandy Dunlapsub local_unescape($) { 19846b5b55f6SRandy Dunlap my $text = shift; 19856b5b55f6SRandy Dunlap if (($output_mode eq "text") || ($output_mode eq "man")) { 19866b5b55f6SRandy Dunlap return $text; 19876b5b55f6SRandy Dunlap } 19886b5b55f6SRandy Dunlap $text =~ s/\\\\\\\\lt:/</g; 19896b5b55f6SRandy Dunlap $text =~ s/\\\\\\\\gt:/>/g; 19906b5b55f6SRandy Dunlap return $text; 19916b5b55f6SRandy Dunlap} 19926b5b55f6SRandy Dunlap 19931da177e4SLinus Torvaldssub process_file($) { 19942283a117SRandy Dunlap my $file; 19951da177e4SLinus Torvalds my $identifier; 19961da177e4SLinus Torvalds my $func; 1997a21217daSRandy Dunlap my $descr; 19981da177e4SLinus Torvalds my $initial_section_counter = $section_counter; 19991da177e4SLinus Torvalds 20002283a117SRandy Dunlap if (defined($ENV{'SRCTREE'})) { 20012283a117SRandy Dunlap $file = "$ENV{'SRCTREE'}" . "/" . "@_"; 20022283a117SRandy Dunlap } 20032283a117SRandy Dunlap else { 20042283a117SRandy Dunlap $file = "@_"; 20052283a117SRandy Dunlap } 20061da177e4SLinus Torvalds if (defined($source_map{$file})) { 20071da177e4SLinus Torvalds $file = $source_map{$file}; 20081da177e4SLinus Torvalds } 20091da177e4SLinus Torvalds 20101da177e4SLinus Torvalds if (!open(IN,"<$file")) { 20111da177e4SLinus Torvalds print STDERR "Error: Cannot open file $file\n"; 20121da177e4SLinus Torvalds ++$errors; 20131da177e4SLinus Torvalds return; 20141da177e4SLinus Torvalds } 20151da177e4SLinus Torvalds 20161da177e4SLinus Torvalds $section_counter = 0; 20171da177e4SLinus Torvalds while (<IN>) { 20181da177e4SLinus Torvalds if ($state == 0) { 20191da177e4SLinus Torvalds if (/$doc_start/o) { 20201da177e4SLinus Torvalds $state = 1; # next line is always the function name 2021850622dfSRandy Dunlap $in_doc_sect = 0; 20221da177e4SLinus Torvalds } 20231da177e4SLinus Torvalds } elsif ($state == 1) { # this line is the function name (always) 20241da177e4SLinus Torvalds if (/$doc_block/o) { 20251da177e4SLinus Torvalds $state = 4; 20261da177e4SLinus Torvalds $contents = ""; 20271da177e4SLinus Torvalds if ( $1 eq "" ) { 20281da177e4SLinus Torvalds $section = $section_intro; 20291da177e4SLinus Torvalds } else { 20301da177e4SLinus Torvalds $section = $1; 20311da177e4SLinus Torvalds } 20321da177e4SLinus Torvalds } 20331da177e4SLinus Torvalds elsif (/$doc_decl/o) { 20341da177e4SLinus Torvalds $identifier = $1; 20351da177e4SLinus Torvalds if (/\s*([\w\s]+?)\s*-/) { 20361da177e4SLinus Torvalds $identifier = $1; 20371da177e4SLinus Torvalds } 20381da177e4SLinus Torvalds 20391da177e4SLinus Torvalds $state = 2; 20401da177e4SLinus Torvalds if (/-(.*)/) { 204151f5a0c8SRandy Dunlap # strip leading/trailing/multiple spaces 2042a21217daSRandy Dunlap $descr= $1; 2043a21217daSRandy Dunlap $descr =~ s/^\s*//; 2044a21217daSRandy Dunlap $descr =~ s/\s*$//; 2045a21217daSRandy Dunlap $descr =~ s/\s+/ /; 2046a21217daSRandy Dunlap $declaration_purpose = xml_escape($descr); 20471da177e4SLinus Torvalds } else { 20481da177e4SLinus Torvalds $declaration_purpose = ""; 20491da177e4SLinus Torvalds } 205077cc23b8SRandy Dunlap 205177cc23b8SRandy Dunlap if (($declaration_purpose eq "") && $verbose) { 205277cc23b8SRandy Dunlap print STDERR "Warning(${file}:$.): missing initial short description on line:\n"; 205377cc23b8SRandy Dunlap print STDERR $_; 205477cc23b8SRandy Dunlap ++$warnings; 205577cc23b8SRandy Dunlap } 205677cc23b8SRandy Dunlap 20571da177e4SLinus Torvalds if ($identifier =~ m/^struct/) { 20581da177e4SLinus Torvalds $decl_type = 'struct'; 20591da177e4SLinus Torvalds } elsif ($identifier =~ m/^union/) { 20601da177e4SLinus Torvalds $decl_type = 'union'; 20611da177e4SLinus Torvalds } elsif ($identifier =~ m/^enum/) { 20621da177e4SLinus Torvalds $decl_type = 'enum'; 20631da177e4SLinus Torvalds } elsif ($identifier =~ m/^typedef/) { 20641da177e4SLinus Torvalds $decl_type = 'typedef'; 20651da177e4SLinus Torvalds } else { 20661da177e4SLinus Torvalds $decl_type = 'function'; 20671da177e4SLinus Torvalds } 20681da177e4SLinus Torvalds 20691da177e4SLinus Torvalds if ($verbose) { 20701da177e4SLinus Torvalds print STDERR "Info(${file}:$.): Scanning doc for $identifier\n"; 20711da177e4SLinus Torvalds } 20721da177e4SLinus Torvalds } else { 20731da177e4SLinus Torvalds print STDERR "Warning(${file}:$.): Cannot understand $_ on line $.", 20741da177e4SLinus Torvalds " - I thought it was a doc line\n"; 20751da177e4SLinus Torvalds ++$warnings; 20761da177e4SLinus Torvalds $state = 0; 20771da177e4SLinus Torvalds } 20781da177e4SLinus Torvalds } elsif ($state == 2) { # look for head: lines, and include content 20791da177e4SLinus Torvalds if (/$doc_sect/o) { 20801da177e4SLinus Torvalds $newsection = $1; 20811da177e4SLinus Torvalds $newcontents = $2; 20821da177e4SLinus Torvalds 2083792aa2f2SRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 2084850622dfSRandy Dunlap if (!$in_doc_sect && $verbose) { 2085850622dfSRandy Dunlap print STDERR "Warning(${file}:$.): contents before sections\n"; 2086850622dfSRandy Dunlap ++$warnings; 2087850622dfSRandy Dunlap } 208894dc7ad5SRandy Dunlap dump_section($file, $section, xml_escape($contents)); 20891da177e4SLinus Torvalds $section = $section_default; 20901da177e4SLinus Torvalds } 20911da177e4SLinus Torvalds 2092850622dfSRandy Dunlap $in_doc_sect = 1; 20931da177e4SLinus Torvalds $contents = $newcontents; 20941da177e4SLinus Torvalds if ($contents ne "") { 209527205744SRandy Dunlap while ((substr($contents, 0, 1) eq " ") || 209627205744SRandy Dunlap substr($contents, 0, 1) eq "\t") { 209705189497SRandy Dunlap $contents = substr($contents, 1); 209805189497SRandy Dunlap } 20991da177e4SLinus Torvalds $contents .= "\n"; 21001da177e4SLinus Torvalds } 21011da177e4SLinus Torvalds $section = $newsection; 21021da177e4SLinus Torvalds } elsif (/$doc_end/) { 21031da177e4SLinus Torvalds 21041da177e4SLinus Torvalds if ($contents ne "") { 210594dc7ad5SRandy Dunlap dump_section($file, $section, xml_escape($contents)); 21061da177e4SLinus Torvalds $section = $section_default; 21071da177e4SLinus Torvalds $contents = ""; 21081da177e4SLinus Torvalds } 210946b958ebSRandy Dunlap # look for doc_com + <text> + doc_end: 211046b958ebSRandy Dunlap if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') { 211146b958ebSRandy Dunlap print STDERR "Warning(${file}:$.): suspicious ending line: $_"; 211246b958ebSRandy Dunlap ++$warnings; 211346b958ebSRandy Dunlap } 21141da177e4SLinus Torvalds 21151da177e4SLinus Torvalds $prototype = ""; 21161da177e4SLinus Torvalds $state = 3; 21171da177e4SLinus Torvalds $brcount = 0; 21181da177e4SLinus Torvalds# print STDERR "end of doc comment, looking for prototype\n"; 21191da177e4SLinus Torvalds } elsif (/$doc_content/) { 21201da177e4SLinus Torvalds # miguel-style comment kludge, look for blank lines after 21211da177e4SLinus Torvalds # @parameter line to signify start of description 21221da177e4SLinus Torvalds if ($1 eq "" && 21231da177e4SLinus Torvalds ($section =~ m/^@/ || $section eq $section_context)) { 212494dc7ad5SRandy Dunlap dump_section($file, $section, xml_escape($contents)); 21251da177e4SLinus Torvalds $section = $section_default; 21261da177e4SLinus Torvalds $contents = ""; 21271da177e4SLinus Torvalds } else { 21281da177e4SLinus Torvalds $contents .= $1 . "\n"; 21291da177e4SLinus Torvalds } 21301da177e4SLinus Torvalds } else { 21311da177e4SLinus Torvalds # i dont know - bad line? ignore. 21321da177e4SLinus Torvalds print STDERR "Warning(${file}:$.): bad line: $_"; 21331da177e4SLinus Torvalds ++$warnings; 21341da177e4SLinus Torvalds } 2135232acbcfSRandy Dunlap } elsif ($state == 3) { # scanning for function '{' (end of prototype) 21361da177e4SLinus Torvalds if ($decl_type eq 'function') { 21371da177e4SLinus Torvalds process_state3_function($_, $file); 21381da177e4SLinus Torvalds } else { 21391da177e4SLinus Torvalds process_state3_type($_, $file); 21401da177e4SLinus Torvalds } 21411da177e4SLinus Torvalds } elsif ($state == 4) { 21421da177e4SLinus Torvalds # Documentation block 21431da177e4SLinus Torvalds if (/$doc_block/) { 214494dc7ad5SRandy Dunlap dump_doc_section($file, $section, xml_escape($contents)); 21451da177e4SLinus Torvalds $contents = ""; 21461da177e4SLinus Torvalds $function = ""; 21471da177e4SLinus Torvalds %constants = (); 21481da177e4SLinus Torvalds %parameterdescs = (); 21491da177e4SLinus Torvalds %parametertypes = (); 21501da177e4SLinus Torvalds @parameterlist = (); 21511da177e4SLinus Torvalds %sections = (); 21521da177e4SLinus Torvalds @sectionlist = (); 21531da177e4SLinus Torvalds $prototype = ""; 21541da177e4SLinus Torvalds if ( $1 eq "" ) { 21551da177e4SLinus Torvalds $section = $section_intro; 21561da177e4SLinus Torvalds } else { 21571da177e4SLinus Torvalds $section = $1; 21581da177e4SLinus Torvalds } 21591da177e4SLinus Torvalds } 21601da177e4SLinus Torvalds elsif (/$doc_end/) 21611da177e4SLinus Torvalds { 216294dc7ad5SRandy Dunlap dump_doc_section($file, $section, xml_escape($contents)); 21631da177e4SLinus Torvalds $contents = ""; 21641da177e4SLinus Torvalds $function = ""; 21651da177e4SLinus Torvalds %constants = (); 21661da177e4SLinus Torvalds %parameterdescs = (); 21671da177e4SLinus Torvalds %parametertypes = (); 21681da177e4SLinus Torvalds @parameterlist = (); 21691da177e4SLinus Torvalds %sections = (); 21701da177e4SLinus Torvalds @sectionlist = (); 21711da177e4SLinus Torvalds $prototype = ""; 21721da177e4SLinus Torvalds $state = 0; 21731da177e4SLinus Torvalds } 21741da177e4SLinus Torvalds elsif (/$doc_content/) 21751da177e4SLinus Torvalds { 21761da177e4SLinus Torvalds if ( $1 eq "" ) 21771da177e4SLinus Torvalds { 21781da177e4SLinus Torvalds $contents .= $blankline; 21791da177e4SLinus Torvalds } 21801da177e4SLinus Torvalds else 21811da177e4SLinus Torvalds { 21821da177e4SLinus Torvalds $contents .= $1 . "\n"; 21831da177e4SLinus Torvalds } 21841da177e4SLinus Torvalds } 21851da177e4SLinus Torvalds } 21861da177e4SLinus Torvalds } 21871da177e4SLinus Torvalds if ($initial_section_counter == $section_counter) { 21881da177e4SLinus Torvalds print STDERR "Warning(${file}): no structured comments found\n"; 21891da177e4SLinus Torvalds if ($output_mode eq "xml") { 21901da177e4SLinus Torvalds # The template wants at least one RefEntry here; make one. 21911da177e4SLinus Torvalds print "<refentry>\n"; 21921da177e4SLinus Torvalds print " <refnamediv>\n"; 21931da177e4SLinus Torvalds print " <refname>\n"; 21941da177e4SLinus Torvalds print " ${file}\n"; 21951da177e4SLinus Torvalds print " </refname>\n"; 21961da177e4SLinus Torvalds print " <refpurpose>\n"; 21971da177e4SLinus Torvalds print " Document generation inconsistency\n"; 21981da177e4SLinus Torvalds print " </refpurpose>\n"; 21991da177e4SLinus Torvalds print " </refnamediv>\n"; 22001da177e4SLinus Torvalds print " <refsect1>\n"; 22011da177e4SLinus Torvalds print " <title>\n"; 22021da177e4SLinus Torvalds print " Oops\n"; 22031da177e4SLinus Torvalds print " </title>\n"; 22041da177e4SLinus Torvalds print " <warning>\n"; 22051da177e4SLinus Torvalds print " <para>\n"; 22061da177e4SLinus Torvalds print " The template for this document tried to insert\n"; 22071da177e4SLinus Torvalds print " the structured comment from the file\n"; 22081da177e4SLinus Torvalds print " <filename>${file}</filename> at this point,\n"; 22091da177e4SLinus Torvalds print " but none was found.\n"; 22101da177e4SLinus Torvalds print " This dummy section is inserted to allow\n"; 22111da177e4SLinus Torvalds print " generation to continue.\n"; 22121da177e4SLinus Torvalds print " </para>\n"; 22131da177e4SLinus Torvalds print " </warning>\n"; 22141da177e4SLinus Torvalds print " </refsect1>\n"; 22151da177e4SLinus Torvalds print "</refentry>\n"; 22161da177e4SLinus Torvalds } 22171da177e4SLinus Torvalds } 22181da177e4SLinus Torvalds} 2219