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 ## 81da177e4SLinus Torvalds## ## 91da177e4SLinus Torvalds## #define enhancements by Armin Kuster <akuster@mvista.com> ## 101da177e4SLinus Torvalds## Copyright (c) 2000 MontaVista Software, Inc. ## 111da177e4SLinus Torvalds## ## 121da177e4SLinus Torvalds## This software falls under the GNU General Public License. ## 131da177e4SLinus Torvalds## Please read the COPYING file for more information ## 141da177e4SLinus Torvalds 151da177e4SLinus Torvalds# w.o. 03-11-2000: added the '-filelist' option. 161da177e4SLinus Torvalds 171da177e4SLinus Torvalds# 18/01/2001 - Cleanups 181da177e4SLinus Torvalds# Functions prototyped as foo(void) same as foo() 191da177e4SLinus Torvalds# Stop eval'ing where we don't need to. 201da177e4SLinus Torvalds# -- huggie@earth.li 211da177e4SLinus Torvalds 221da177e4SLinus Torvalds# 27/06/2001 - Allowed whitespace after initial "/**" and 231da177e4SLinus Torvalds# allowed comments before function declarations. 241da177e4SLinus Torvalds# -- Christian Kreibich <ck@whoop.org> 251da177e4SLinus Torvalds 261da177e4SLinus Torvalds# Still to do: 271da177e4SLinus Torvalds# - add perldoc documentation 281da177e4SLinus Torvalds# - Look more closely at some of the scarier bits :) 291da177e4SLinus Torvalds 301da177e4SLinus Torvalds# 26/05/2001 - Support for separate source and object trees. 311da177e4SLinus Torvalds# Return error code. 321da177e4SLinus Torvalds# Keith Owens <kaos@ocs.com.au> 331da177e4SLinus Torvalds 341da177e4SLinus Torvalds# 23/09/2001 - Added support for typedefs, structs, enums and unions 351da177e4SLinus Torvalds# Support for Context section; can be terminated using empty line 361da177e4SLinus Torvalds# Small fixes (like spaces vs. \s in regex) 371da177e4SLinus Torvalds# -- Tim Jansen <tim@tjansen.de> 381da177e4SLinus Torvalds 391da177e4SLinus Torvalds 401da177e4SLinus Torvalds# 411da177e4SLinus Torvalds# This will read a 'c' file and scan for embedded comments in the 421da177e4SLinus Torvalds# style of gnome comments (+minor extensions - see below). 431da177e4SLinus Torvalds# 441da177e4SLinus Torvalds 451da177e4SLinus Torvalds# Note: This only supports 'c'. 461da177e4SLinus Torvalds 471da177e4SLinus Torvalds# usage: 481da177e4SLinus Torvalds# kerneldoc [ -docbook | -html | -text | -man ] 491da177e4SLinus Torvalds# [ -function funcname [ -function funcname ...] ] c file(s)s > outputfile 501da177e4SLinus Torvalds# or 511da177e4SLinus Torvalds# [ -nofunction funcname [ -function funcname ...] ] c file(s)s > outputfile 521da177e4SLinus Torvalds# 531da177e4SLinus Torvalds# Set output format using one of -docbook -html -text or -man. Default is man. 541da177e4SLinus Torvalds# 551da177e4SLinus Torvalds# -function funcname 561da177e4SLinus Torvalds# If set, then only generate documentation for the given function(s). All 571da177e4SLinus Torvalds# other functions are ignored. 581da177e4SLinus Torvalds# 591da177e4SLinus Torvalds# -nofunction funcname 601da177e4SLinus Torvalds# If set, then only generate documentation for the other function(s). All 611da177e4SLinus Torvalds# other functions are ignored. Cannot be used with -function together 621da177e4SLinus Torvalds# (yes thats a bug - perl hackers can fix it 8)) 631da177e4SLinus Torvalds# 641da177e4SLinus Torvalds# c files - list of 'c' files to process 651da177e4SLinus Torvalds# 661da177e4SLinus Torvalds# All output goes to stdout, with errors to stderr. 671da177e4SLinus Torvalds 681da177e4SLinus Torvalds# 691da177e4SLinus Torvalds# format of comments. 701da177e4SLinus Torvalds# In the following table, (...)? signifies optional structure. 711da177e4SLinus Torvalds# (...)* signifies 0 or more structure elements 721da177e4SLinus Torvalds# /** 731da177e4SLinus Torvalds# * function_name(:)? (- short description)? 741da177e4SLinus Torvalds# (* @parameterx: (description of parameter x)?)* 751da177e4SLinus Torvalds# (* a blank line)? 761da177e4SLinus Torvalds# * (Description:)? (Description of function)? 771da177e4SLinus Torvalds# * (section header: (section description)? )* 781da177e4SLinus Torvalds# (*)?*/ 791da177e4SLinus Torvalds# 801da177e4SLinus Torvalds# So .. the trivial example would be: 811da177e4SLinus Torvalds# 821da177e4SLinus Torvalds# /** 831da177e4SLinus Torvalds# * my_function 841da177e4SLinus Torvalds# **/ 851da177e4SLinus Torvalds# 861da177e4SLinus Torvalds# If the Description: header tag is ommitted, then there must be a blank line 871da177e4SLinus Torvalds# after the last parameter specification. 881da177e4SLinus Torvalds# e.g. 891da177e4SLinus Torvalds# /** 901da177e4SLinus Torvalds# * my_function - does my stuff 911da177e4SLinus Torvalds# * @my_arg: its mine damnit 921da177e4SLinus Torvalds# * 931da177e4SLinus Torvalds# * Does my stuff explained. 941da177e4SLinus Torvalds# */ 951da177e4SLinus Torvalds# 961da177e4SLinus Torvalds# or, could also use: 971da177e4SLinus Torvalds# /** 981da177e4SLinus Torvalds# * my_function - does my stuff 991da177e4SLinus Torvalds# * @my_arg: its mine damnit 1001da177e4SLinus Torvalds# * Description: Does my stuff explained. 1011da177e4SLinus Torvalds# */ 1021da177e4SLinus Torvalds# etc. 1031da177e4SLinus Torvalds# 1041da177e4SLinus Torvalds# Beside functions you can also write documentation for structs, unions, 1051da177e4SLinus Torvalds# enums and typedefs. Instead of the function name you must write the name 1061da177e4SLinus Torvalds# of the declaration; the struct/union/enum/typedef must always precede 1071da177e4SLinus Torvalds# the name. Nesting of declarations is not supported. 1081da177e4SLinus Torvalds# Use the argument mechanism to document members or constants. 1091da177e4SLinus Torvalds# e.g. 1101da177e4SLinus Torvalds# /** 1111da177e4SLinus Torvalds# * struct my_struct - short description 1121da177e4SLinus Torvalds# * @a: first member 1131da177e4SLinus Torvalds# * @b: second member 1141da177e4SLinus Torvalds# * 1151da177e4SLinus Torvalds# * Longer description 1161da177e4SLinus Torvalds# */ 1171da177e4SLinus Torvalds# struct my_struct { 1181da177e4SLinus Torvalds# int a; 1191da177e4SLinus Torvalds# int b; 1201da177e4SLinus Torvalds# }; 1211da177e4SLinus Torvalds# 1221da177e4SLinus Torvalds# All descriptions can be multiline, except the short function description. 1231da177e4SLinus Torvalds# 1241da177e4SLinus Torvalds# You can also add additional sections. When documenting kernel functions you 1251da177e4SLinus Torvalds# should document the "Context:" of the function, e.g. whether the functions 1261da177e4SLinus Torvalds# can be called form interrupts. Unlike other sections you can end it with an 1271da177e4SLinus Torvalds# empty line. 1281da177e4SLinus Torvalds# Example-sections should contain the string EXAMPLE so that they are marked 1291da177e4SLinus Torvalds# appropriately in DocBook. 1301da177e4SLinus Torvalds# 1311da177e4SLinus Torvalds# Example: 1321da177e4SLinus Torvalds# /** 1331da177e4SLinus Torvalds# * user_function - function that can only be called in user context 1341da177e4SLinus Torvalds# * @a: some argument 1351da177e4SLinus Torvalds# * Context: !in_interrupt() 1361da177e4SLinus Torvalds# * 1371da177e4SLinus Torvalds# * Some description 1381da177e4SLinus Torvalds# * Example: 1391da177e4SLinus Torvalds# * user_function(22); 1401da177e4SLinus Torvalds# */ 1411da177e4SLinus Torvalds# ... 1421da177e4SLinus Torvalds# 1431da177e4SLinus Torvalds# 1441da177e4SLinus Torvalds# All descriptive text is further processed, scanning for the following special 1451da177e4SLinus Torvalds# patterns, which are highlighted appropriately. 1461da177e4SLinus Torvalds# 1471da177e4SLinus Torvalds# 'funcname()' - function 1481da177e4SLinus Torvalds# '$ENVVAR' - environmental variable 1491da177e4SLinus Torvalds# '&struct_name' - name of a structure (up to two words including 'struct') 1501da177e4SLinus Torvalds# '@parameter' - name of a parameter 1511da177e4SLinus Torvalds# '%CONST' - name of a constant. 1521da177e4SLinus Torvalds 1531da177e4SLinus Torvaldsmy $errors = 0; 1541da177e4SLinus Torvaldsmy $warnings = 0; 1551da177e4SLinus Torvalds 1561da177e4SLinus Torvalds# match expressions used to find embedded type information 1571da177e4SLinus Torvaldsmy $type_constant = '\%([-_\w]+)'; 1581da177e4SLinus Torvaldsmy $type_func = '(\w+)\(\)'; 1591da177e4SLinus Torvaldsmy $type_param = '\@(\w+)'; 1601da177e4SLinus Torvaldsmy $type_struct = '\&((struct\s*)?[_\w]+)'; 1611da177e4SLinus Torvaldsmy $type_env = '(\$\w+)'; 1621da177e4SLinus Torvalds 1631da177e4SLinus Torvalds# Output conversion substitutions. 1641da177e4SLinus Torvalds# One for each output format 1651da177e4SLinus Torvalds 1661da177e4SLinus Torvalds# these work fairly well 1671da177e4SLinus Torvaldsmy %highlights_html = ( $type_constant, "<i>\$1</i>", 1681da177e4SLinus Torvalds $type_func, "<b>\$1</b>", 1691da177e4SLinus Torvalds $type_struct, "<i>\$1</i>", 1701da177e4SLinus Torvalds $type_param, "<tt><b>\$1</b></tt>" ); 1711da177e4SLinus Torvaldsmy $blankline_html = "<p>"; 1721da177e4SLinus Torvalds 1731da177e4SLinus Torvalds# XML, docbook format 1741da177e4SLinus Torvaldsmy %highlights_xml = ( "([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>", 1751da177e4SLinus Torvalds $type_constant, "<constant>\$1</constant>", 1761da177e4SLinus Torvalds $type_func, "<function>\$1</function>", 1771da177e4SLinus Torvalds $type_struct, "<structname>\$1</structname>", 1781da177e4SLinus Torvalds $type_env, "<envar>\$1</envar>", 1791da177e4SLinus Torvalds $type_param, "<parameter>\$1</parameter>" ); 1801da177e4SLinus Torvaldsmy $blankline_xml = "</para><para>\n"; 1811da177e4SLinus Torvalds 1821da177e4SLinus Torvalds# gnome, docbook format 1831da177e4SLinus Torvaldsmy %highlights_gnome = ( $type_constant, "<replaceable class=\"option\">\$1</replaceable>", 1841da177e4SLinus Torvalds $type_func, "<function>\$1</function>", 1851da177e4SLinus Torvalds $type_struct, "<structname>\$1</structname>", 1861da177e4SLinus Torvalds $type_env, "<envar>\$1</envar>", 1871da177e4SLinus Torvalds $type_param, "<parameter>\$1</parameter>" ); 1881da177e4SLinus Torvaldsmy $blankline_gnome = "</para><para>\n"; 1891da177e4SLinus Torvalds 1901da177e4SLinus Torvalds# these are pretty rough 1911da177e4SLinus Torvaldsmy %highlights_man = ( $type_constant, "\$1", 1921da177e4SLinus Torvalds $type_func, "\\\\fB\$1\\\\fP", 1931da177e4SLinus Torvalds $type_struct, "\\\\fI\$1\\\\fP", 1941da177e4SLinus Torvalds $type_param, "\\\\fI\$1\\\\fP" ); 1951da177e4SLinus Torvaldsmy $blankline_man = ""; 1961da177e4SLinus Torvalds 1971da177e4SLinus Torvalds# text-mode 1981da177e4SLinus Torvaldsmy %highlights_text = ( $type_constant, "\$1", 1991da177e4SLinus Torvalds $type_func, "\$1", 2001da177e4SLinus Torvalds $type_struct, "\$1", 2011da177e4SLinus Torvalds $type_param, "\$1" ); 2021da177e4SLinus Torvaldsmy $blankline_text = ""; 2031da177e4SLinus Torvalds 2041da177e4SLinus Torvalds 2051da177e4SLinus Torvaldssub usage { 2061da177e4SLinus Torvalds print "Usage: $0 [ -v ] [ -docbook | -html | -text | -man ]\n"; 2071da177e4SLinus Torvalds print " [ -function funcname [ -function funcname ...] ]\n"; 2081da177e4SLinus Torvalds print " [ -nofunction funcname [ -nofunction funcname ...] ]\n"; 2091da177e4SLinus Torvalds print " c source file(s) > outputfile\n"; 2101da177e4SLinus Torvalds exit 1; 2111da177e4SLinus Torvalds} 2121da177e4SLinus Torvalds 2131da177e4SLinus Torvalds# read arguments 2141da177e4SLinus Torvaldsif ($#ARGV==-1) { 2151da177e4SLinus Torvalds usage(); 2161da177e4SLinus Torvalds} 2171da177e4SLinus Torvalds 2181da177e4SLinus Torvaldsmy $verbose = 0; 2191da177e4SLinus Torvaldsmy $output_mode = "man"; 2201da177e4SLinus Torvaldsmy %highlights = %highlights_man; 2211da177e4SLinus Torvaldsmy $blankline = $blankline_man; 2221da177e4SLinus Torvaldsmy $modulename = "Kernel API"; 2231da177e4SLinus Torvaldsmy $function_only = 0; 2241da177e4SLinus Torvaldsmy $man_date = ('January', 'February', 'March', 'April', 'May', 'June', 2251da177e4SLinus Torvalds 'July', 'August', 'September', 'October', 2261da177e4SLinus Torvalds 'November', 'December')[(localtime)[4]] . 2271da177e4SLinus Torvalds " " . ((localtime)[5]+1900); 2281da177e4SLinus Torvalds 2291da177e4SLinus Torvalds# Essentially these are globals 2301da177e4SLinus Torvalds# They probably want to be tidied up made more localised or summat. 2311da177e4SLinus Torvalds# CAVEAT EMPTOR! Some of the others I localised may not want to be which 2321da177e4SLinus Torvalds# could cause "use of undefined value" or other bugs. 2331da177e4SLinus Torvaldsmy ($function, %function_table,%parametertypes,$declaration_purpose); 2341da177e4SLinus Torvaldsmy ($type,$declaration_name,$return_type); 2351da177e4SLinus Torvaldsmy ($newsection,$newcontents,$prototype,$filelist, $brcount, %source_map); 2361da177e4SLinus Torvalds 2371da177e4SLinus Torvalds# Generated docbook code is inserted in a template at a point where 2381da177e4SLinus Torvalds# docbook v3.1 requires a non-zero sequence of RefEntry's; see: 2391da177e4SLinus Torvalds# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html 2401da177e4SLinus Torvalds# We keep track of number of generated entries and generate a dummy 2411da177e4SLinus Torvalds# if needs be to ensure the expanded template can be postprocessed 2421da177e4SLinus Torvalds# into html. 2431da177e4SLinus Torvaldsmy $section_counter = 0; 2441da177e4SLinus Torvalds 2451da177e4SLinus Torvaldsmy $lineprefix=""; 2461da177e4SLinus Torvalds 2471da177e4SLinus Torvalds# states 2481da177e4SLinus Torvalds# 0 - normal code 2491da177e4SLinus Torvalds# 1 - looking for function name 2501da177e4SLinus Torvalds# 2 - scanning field start. 2511da177e4SLinus Torvalds# 3 - scanning prototype. 2521da177e4SLinus Torvalds# 4 - documentation block 2531da177e4SLinus Torvaldsmy $state; 2541da177e4SLinus Torvalds 2551da177e4SLinus Torvalds#declaration types: can be 2561da177e4SLinus Torvalds# 'function', 'struct', 'union', 'enum', 'typedef' 2571da177e4SLinus Torvaldsmy $decl_type; 2581da177e4SLinus Torvalds 2591da177e4SLinus Torvaldsmy $doc_special = "\@\%\$\&"; 2601da177e4SLinus Torvalds 2611da177e4SLinus Torvaldsmy $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start. 2621da177e4SLinus Torvaldsmy $doc_end = '\*/'; 2631da177e4SLinus Torvaldsmy $doc_com = '\s*\*\s*'; 2641da177e4SLinus Torvaldsmy $doc_decl = $doc_com.'(\w+)'; 2651da177e4SLinus Torvaldsmy $doc_sect = $doc_com.'(['.$doc_special.']?[\w ]+):(.*)'; 2661da177e4SLinus Torvaldsmy $doc_content = $doc_com.'(.*)'; 2671da177e4SLinus Torvaldsmy $doc_block = $doc_com.'DOC:\s*(.*)?'; 2681da177e4SLinus Torvalds 2691da177e4SLinus Torvaldsmy %constants; 2701da177e4SLinus Torvaldsmy %parameterdescs; 2711da177e4SLinus Torvaldsmy @parameterlist; 2721da177e4SLinus Torvaldsmy %sections; 2731da177e4SLinus Torvaldsmy @sectionlist; 2741da177e4SLinus Torvalds 2751da177e4SLinus Torvaldsmy $contents = ""; 2761da177e4SLinus Torvaldsmy $section_default = "Description"; # default section 2771da177e4SLinus Torvaldsmy $section_intro = "Introduction"; 2781da177e4SLinus Torvaldsmy $section = $section_default; 2791da177e4SLinus Torvaldsmy $section_context = "Context"; 2801da177e4SLinus Torvalds 2811da177e4SLinus Torvaldsmy $undescribed = "-- undescribed --"; 2821da177e4SLinus Torvalds 2831da177e4SLinus Torvaldsreset_state(); 2841da177e4SLinus Torvalds 2851da177e4SLinus Torvaldswhile ($ARGV[0] =~ m/^-(.*)/) { 2861da177e4SLinus Torvalds my $cmd = shift @ARGV; 2871da177e4SLinus Torvalds if ($cmd eq "-html") { 2881da177e4SLinus Torvalds $output_mode = "html"; 2891da177e4SLinus Torvalds %highlights = %highlights_html; 2901da177e4SLinus Torvalds $blankline = $blankline_html; 2911da177e4SLinus Torvalds } elsif ($cmd eq "-man") { 2921da177e4SLinus Torvalds $output_mode = "man"; 2931da177e4SLinus Torvalds %highlights = %highlights_man; 2941da177e4SLinus Torvalds $blankline = $blankline_man; 2951da177e4SLinus Torvalds } elsif ($cmd eq "-text") { 2961da177e4SLinus Torvalds $output_mode = "text"; 2971da177e4SLinus Torvalds %highlights = %highlights_text; 2981da177e4SLinus Torvalds $blankline = $blankline_text; 2991da177e4SLinus Torvalds } elsif ($cmd eq "-docbook") { 3001da177e4SLinus Torvalds $output_mode = "xml"; 3011da177e4SLinus Torvalds %highlights = %highlights_xml; 3021da177e4SLinus Torvalds $blankline = $blankline_xml; 3031da177e4SLinus Torvalds } elsif ($cmd eq "-gnome") { 3041da177e4SLinus Torvalds $output_mode = "gnome"; 3051da177e4SLinus Torvalds %highlights = %highlights_gnome; 3061da177e4SLinus Torvalds $blankline = $blankline_gnome; 3071da177e4SLinus Torvalds } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document 3081da177e4SLinus Torvalds $modulename = shift @ARGV; 3091da177e4SLinus Torvalds } elsif ($cmd eq "-function") { # to only output specific functions 3101da177e4SLinus Torvalds $function_only = 1; 3111da177e4SLinus Torvalds $function = shift @ARGV; 3121da177e4SLinus Torvalds $function_table{$function} = 1; 3131da177e4SLinus Torvalds } elsif ($cmd eq "-nofunction") { # to only output specific functions 3141da177e4SLinus Torvalds $function_only = 2; 3151da177e4SLinus Torvalds $function = shift @ARGV; 3161da177e4SLinus Torvalds $function_table{$function} = 1; 3171da177e4SLinus Torvalds } elsif ($cmd eq "-v") { 3181da177e4SLinus Torvalds $verbose = 1; 3191da177e4SLinus Torvalds } elsif (($cmd eq "-h") || ($cmd eq "--help")) { 3201da177e4SLinus Torvalds usage(); 3211da177e4SLinus Torvalds } elsif ($cmd eq '-filelist') { 3221da177e4SLinus Torvalds $filelist = shift @ARGV; 3231da177e4SLinus Torvalds } 3241da177e4SLinus Torvalds} 3251da177e4SLinus Torvalds 3261da177e4SLinus Torvalds 3271da177e4SLinus Torvalds# generate a sequence of code that will splice in highlighting information 3281da177e4SLinus Torvalds# using the s// operator. 3291da177e4SLinus Torvaldsmy $dohighlight = ""; 3301da177e4SLinus Torvaldsforeach my $pattern (keys %highlights) { 3311da177e4SLinus Torvalds# print "scanning pattern $pattern ($highlights{$pattern})\n"; 3321da177e4SLinus Torvalds $dohighlight .= "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n"; 3331da177e4SLinus Torvalds} 3341da177e4SLinus Torvalds 3351da177e4SLinus Torvalds## 3361da177e4SLinus Torvalds# dumps section contents to arrays/hashes intended for that purpose. 3371da177e4SLinus Torvalds# 3381da177e4SLinus Torvaldssub dump_section { 3391da177e4SLinus Torvalds my $name = shift; 3401da177e4SLinus Torvalds my $contents = join "\n", @_; 3411da177e4SLinus Torvalds 3421da177e4SLinus Torvalds if ($name =~ m/$type_constant/) { 3431da177e4SLinus Torvalds $name = $1; 3441da177e4SLinus Torvalds# print STDERR "constant section '$1' = '$contents'\n"; 3451da177e4SLinus Torvalds $constants{$name} = $contents; 3461da177e4SLinus Torvalds } elsif ($name =~ m/$type_param/) { 3471da177e4SLinus Torvalds# print STDERR "parameter def '$1' = '$contents'\n"; 3481da177e4SLinus Torvalds $name = $1; 3491da177e4SLinus Torvalds $parameterdescs{$name} = $contents; 3501da177e4SLinus Torvalds } else { 3511da177e4SLinus Torvalds# print STDERR "other section '$name' = '$contents'\n"; 3521da177e4SLinus Torvalds $sections{$name} = $contents; 3531da177e4SLinus Torvalds push @sectionlist, $name; 3541da177e4SLinus Torvalds } 3551da177e4SLinus Torvalds} 3561da177e4SLinus Torvalds 3571da177e4SLinus Torvalds## 3581da177e4SLinus Torvalds# output function 3591da177e4SLinus Torvalds# 3601da177e4SLinus Torvalds# parameterdescs, a hash. 3611da177e4SLinus Torvalds# function => "function name" 3621da177e4SLinus Torvalds# parameterlist => @list of parameters 3631da177e4SLinus Torvalds# parameterdescs => %parameter descriptions 3641da177e4SLinus Torvalds# sectionlist => @list of sections 3651da177e4SLinus Torvalds# sections => %descriont descriptions 3661da177e4SLinus Torvalds# 3671da177e4SLinus Torvalds 3681da177e4SLinus Torvaldssub output_highlight { 3691da177e4SLinus Torvalds my $contents = join "\n",@_; 3701da177e4SLinus Torvalds my $line; 3711da177e4SLinus Torvalds 3721da177e4SLinus Torvalds# DEBUG 3731da177e4SLinus Torvalds# if (!defined $contents) { 3741da177e4SLinus Torvalds# use Carp; 3751da177e4SLinus Torvalds# confess "output_highlight got called with no args?\n"; 3761da177e4SLinus Torvalds# } 3771da177e4SLinus Torvalds 3781da177e4SLinus Torvalds eval $dohighlight; 3791da177e4SLinus Torvalds die $@ if $@; 3801da177e4SLinus Torvalds foreach $line (split "\n", $contents) { 3811da177e4SLinus Torvalds if ($line eq ""){ 3821da177e4SLinus Torvalds print $lineprefix, $blankline; 3831da177e4SLinus Torvalds } else { 3841da177e4SLinus Torvalds $line =~ s/\\\\\\/\&/g; 3851da177e4SLinus Torvalds print $lineprefix, $line; 3861da177e4SLinus Torvalds } 3871da177e4SLinus Torvalds print "\n"; 3881da177e4SLinus Torvalds } 3891da177e4SLinus Torvalds} 3901da177e4SLinus Torvalds 3911da177e4SLinus Torvalds#output sections in html 3921da177e4SLinus Torvaldssub output_section_html(%) { 3931da177e4SLinus Torvalds my %args = %{$_[0]}; 3941da177e4SLinus Torvalds my $section; 3951da177e4SLinus Torvalds 3961da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 3971da177e4SLinus Torvalds print "<h3>$section</h3>\n"; 3981da177e4SLinus Torvalds print "<blockquote>\n"; 3991da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 4001da177e4SLinus Torvalds print "</blockquote>\n"; 4011da177e4SLinus Torvalds } 4021da177e4SLinus Torvalds} 4031da177e4SLinus Torvalds 4041da177e4SLinus Torvalds# output enum in html 4051da177e4SLinus Torvaldssub output_enum_html(%) { 4061da177e4SLinus Torvalds my %args = %{$_[0]}; 4071da177e4SLinus Torvalds my ($parameter); 4081da177e4SLinus Torvalds my $count; 4091da177e4SLinus Torvalds print "<h2>enum ".$args{'enum'}."</h2>\n"; 4101da177e4SLinus Torvalds 4111da177e4SLinus Torvalds print "<b>enum ".$args{'enum'}."</b> {<br>\n"; 4121da177e4SLinus Torvalds $count = 0; 4131da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 4141da177e4SLinus Torvalds print " <b>".$parameter."</b>"; 4151da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 4161da177e4SLinus Torvalds $count++; 4171da177e4SLinus Torvalds print ",\n"; 4181da177e4SLinus Torvalds } 4191da177e4SLinus Torvalds print "<br>"; 4201da177e4SLinus Torvalds } 4211da177e4SLinus Torvalds print "};<br>\n"; 4221da177e4SLinus Torvalds 4231da177e4SLinus Torvalds print "<h3>Constants</h3>\n"; 4241da177e4SLinus Torvalds print "<dl>\n"; 4251da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 4261da177e4SLinus Torvalds print "<dt><b>".$parameter."</b>\n"; 4271da177e4SLinus Torvalds print "<dd>"; 4281da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter}); 4291da177e4SLinus Torvalds } 4301da177e4SLinus Torvalds print "</dl>\n"; 4311da177e4SLinus Torvalds output_section_html(@_); 4321da177e4SLinus Torvalds print "<hr>\n"; 4331da177e4SLinus Torvalds} 4341da177e4SLinus Torvalds 4351da177e4SLinus Torvalds# output tyepdef in html 4361da177e4SLinus Torvaldssub output_typedef_html(%) { 4371da177e4SLinus Torvalds my %args = %{$_[0]}; 4381da177e4SLinus Torvalds my ($parameter); 4391da177e4SLinus Torvalds my $count; 4401da177e4SLinus Torvalds print "<h2>typedef ".$args{'typedef'}."</h2>\n"; 4411da177e4SLinus Torvalds 4421da177e4SLinus Torvalds print "<b>typedef ".$args{'typedef'}."</b>\n"; 4431da177e4SLinus Torvalds output_section_html(@_); 4441da177e4SLinus Torvalds print "<hr>\n"; 4451da177e4SLinus Torvalds} 4461da177e4SLinus Torvalds 4471da177e4SLinus Torvalds# output struct in html 4481da177e4SLinus Torvaldssub output_struct_html(%) { 4491da177e4SLinus Torvalds my %args = %{$_[0]}; 4501da177e4SLinus Torvalds my ($parameter); 4511da177e4SLinus Torvalds 4521da177e4SLinus Torvalds print "<h2>".$args{'type'}." ".$args{'struct'}."</h2>\n"; 4531da177e4SLinus Torvalds print "<b>".$args{'type'}." ".$args{'struct'}."</b> {<br>\n"; 4541da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 4551da177e4SLinus Torvalds if ($parameter =~ /^#/) { 4561da177e4SLinus Torvalds print "$parameter<br>\n"; 4571da177e4SLinus Torvalds next; 4581da177e4SLinus Torvalds } 4591da177e4SLinus Torvalds my $parameter_name = $parameter; 4601da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 4611da177e4SLinus Torvalds 4621da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 4631da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 4641da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 4651da177e4SLinus Torvalds # pointer-to-function 4661da177e4SLinus Torvalds print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n"; 4671da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 4681da177e4SLinus Torvalds print " <i>$1</i> <b>$parameter</b>$2;<br>\n"; 4691da177e4SLinus Torvalds } else { 4701da177e4SLinus Torvalds print " <i>$type</i> <b>$parameter</b>;<br>\n"; 4711da177e4SLinus Torvalds } 4721da177e4SLinus Torvalds } 4731da177e4SLinus Torvalds print "};<br>\n"; 4741da177e4SLinus Torvalds 4751da177e4SLinus Torvalds print "<h3>Members</h3>\n"; 4761da177e4SLinus Torvalds print "<dl>\n"; 4771da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 4781da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 4791da177e4SLinus Torvalds 4801da177e4SLinus Torvalds my $parameter_name = $parameter; 4811da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 4821da177e4SLinus Torvalds 4831da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 4841da177e4SLinus Torvalds print "<dt><b>".$parameter."</b>\n"; 4851da177e4SLinus Torvalds print "<dd>"; 4861da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 4871da177e4SLinus Torvalds } 4881da177e4SLinus Torvalds print "</dl>\n"; 4891da177e4SLinus Torvalds output_section_html(@_); 4901da177e4SLinus Torvalds print "<hr>\n"; 4911da177e4SLinus Torvalds} 4921da177e4SLinus Torvalds 4931da177e4SLinus Torvalds# output function in html 4941da177e4SLinus Torvaldssub output_function_html(%) { 4951da177e4SLinus Torvalds my %args = %{$_[0]}; 4961da177e4SLinus Torvalds my ($parameter, $section); 4971da177e4SLinus Torvalds my $count; 4981da177e4SLinus Torvalds print "<h2>Function</h2>\n"; 4991da177e4SLinus Torvalds 5001da177e4SLinus Torvalds print "<i>".$args{'functiontype'}."</i>\n"; 5011da177e4SLinus Torvalds print "<b>".$args{'function'}."</b>\n"; 5021da177e4SLinus Torvalds print "("; 5031da177e4SLinus Torvalds $count = 0; 5041da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 5051da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 5061da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 5071da177e4SLinus Torvalds # pointer-to-function 5081da177e4SLinus Torvalds print "<i>$1</i><b>$parameter</b>) <i>($2)</i>"; 5091da177e4SLinus Torvalds } else { 5101da177e4SLinus Torvalds print "<i>".$type."</i> <b>".$parameter."</b>"; 5111da177e4SLinus Torvalds } 5121da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 5131da177e4SLinus Torvalds $count++; 5141da177e4SLinus Torvalds print ",\n"; 5151da177e4SLinus Torvalds } 5161da177e4SLinus Torvalds } 5171da177e4SLinus Torvalds print ")\n"; 5181da177e4SLinus Torvalds 5191da177e4SLinus Torvalds print "<h3>Arguments</h3>\n"; 5201da177e4SLinus Torvalds print "<dl>\n"; 5211da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 5221da177e4SLinus Torvalds my $parameter_name = $parameter; 5231da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 5241da177e4SLinus Torvalds 5251da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 5261da177e4SLinus Torvalds print "<dt><b>".$parameter."</b>\n"; 5271da177e4SLinus Torvalds print "<dd>"; 5281da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 5291da177e4SLinus Torvalds } 5301da177e4SLinus Torvalds print "</dl>\n"; 5311da177e4SLinus Torvalds output_section_html(@_); 5321da177e4SLinus Torvalds print "<hr>\n"; 5331da177e4SLinus Torvalds} 5341da177e4SLinus Torvalds 5351da177e4SLinus Torvalds# output intro in html 5361da177e4SLinus Torvaldssub output_intro_html(%) { 5371da177e4SLinus Torvalds my %args = %{$_[0]}; 5381da177e4SLinus Torvalds my ($parameter, $section); 5391da177e4SLinus Torvalds my $count; 5401da177e4SLinus Torvalds 5411da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 5421da177e4SLinus Torvalds print "<h3>$section</h3>\n"; 5431da177e4SLinus Torvalds print "<ul>\n"; 5441da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 5451da177e4SLinus Torvalds print "</ul>\n"; 5461da177e4SLinus Torvalds } 5471da177e4SLinus Torvalds print "<hr>\n"; 5481da177e4SLinus Torvalds} 5491da177e4SLinus Torvalds 5501da177e4SLinus Torvaldssub output_section_xml(%) { 5511da177e4SLinus Torvalds my %args = %{$_[0]}; 5521da177e4SLinus Torvalds my $section; 5531da177e4SLinus Torvalds # print out each section 5541da177e4SLinus Torvalds $lineprefix=" "; 5551da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 556*c73894c1SRich Walker print "<refsect1>\n"; 557*c73894c1SRich Walker print "<title>$section</title>\n"; 5581da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 559*c73894c1SRich Walker print "<informalexample><programlisting>\n"; 560*c73894c1SRich Walker } else { 561*c73894c1SRich Walker print "<para>\n"; 5621da177e4SLinus Torvalds } 5631da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 5641da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 565*c73894c1SRich Walker print "</programlisting></informalexample>\n"; 566*c73894c1SRich Walker } else { 567*c73894c1SRich Walker print "</para>\n"; 5681da177e4SLinus Torvalds } 569*c73894c1SRich Walker print "</refsect1>\n"; 5701da177e4SLinus Torvalds } 5711da177e4SLinus Torvalds} 5721da177e4SLinus Torvalds 5731da177e4SLinus Torvalds# output function in XML DocBook 5741da177e4SLinus Torvaldssub output_function_xml(%) { 5751da177e4SLinus Torvalds my %args = %{$_[0]}; 5761da177e4SLinus Torvalds my ($parameter, $section); 5771da177e4SLinus Torvalds my $count; 5781da177e4SLinus Torvalds my $id; 5791da177e4SLinus Torvalds 5801da177e4SLinus Torvalds $id = "API-".$args{'function'}; 5811da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 5821da177e4SLinus Torvalds 5831da177e4SLinus Torvalds print "<refentry>\n"; 5841da177e4SLinus Torvalds print "<refmeta>\n"; 5851da177e4SLinus Torvalds print "<refentrytitle><phrase id=\"$id\">".$args{'function'}."</phrase></refentrytitle>\n"; 5861da177e4SLinus Torvalds print "</refmeta>\n"; 5871da177e4SLinus Torvalds print "<refnamediv>\n"; 5881da177e4SLinus Torvalds print " <refname>".$args{'function'}."</refname>\n"; 5891da177e4SLinus Torvalds print " <refpurpose>\n"; 5901da177e4SLinus Torvalds print " "; 5911da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 5921da177e4SLinus Torvalds print " </refpurpose>\n"; 5931da177e4SLinus Torvalds print "</refnamediv>\n"; 5941da177e4SLinus Torvalds 5951da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 5961da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 5971da177e4SLinus Torvalds print " <funcsynopsis><funcprototype>\n"; 5981da177e4SLinus Torvalds print " <funcdef>".$args{'functiontype'}." "; 5991da177e4SLinus Torvalds print "<function>".$args{'function'}." </function></funcdef>\n"; 6001da177e4SLinus Torvalds 6011da177e4SLinus Torvalds $count = 0; 6021da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 6031da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6041da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 6051da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 6061da177e4SLinus Torvalds # pointer-to-function 6071da177e4SLinus Torvalds print " <paramdef>$1<parameter>$parameter</parameter>)\n"; 6081da177e4SLinus Torvalds print " <funcparams>$2</funcparams></paramdef>\n"; 6091da177e4SLinus Torvalds } else { 6101da177e4SLinus Torvalds print " <paramdef>".$type; 6111da177e4SLinus Torvalds print " <parameter>$parameter</parameter></paramdef>\n"; 6121da177e4SLinus Torvalds } 6131da177e4SLinus Torvalds } 6141da177e4SLinus Torvalds } else { 6156013d544SMartin Waitz print " <void/>\n"; 6161da177e4SLinus Torvalds } 6171da177e4SLinus Torvalds print " </funcprototype></funcsynopsis>\n"; 6181da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 6191da177e4SLinus Torvalds 6201da177e4SLinus Torvalds # print parameters 6211da177e4SLinus Torvalds print "<refsect1>\n <title>Arguments</title>\n"; 6221da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 6231da177e4SLinus Torvalds print " <variablelist>\n"; 6241da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6251da177e4SLinus Torvalds my $parameter_name = $parameter; 6261da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 6271da177e4SLinus Torvalds 6281da177e4SLinus Torvalds print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n"; 6291da177e4SLinus Torvalds print " <listitem>\n <para>\n"; 6301da177e4SLinus Torvalds $lineprefix=" "; 6311da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 6321da177e4SLinus Torvalds print " </para>\n </listitem>\n </varlistentry>\n"; 6331da177e4SLinus Torvalds } 6341da177e4SLinus Torvalds print " </variablelist>\n"; 6351da177e4SLinus Torvalds } else { 6361da177e4SLinus Torvalds print " <para>\n None\n </para>\n"; 6371da177e4SLinus Torvalds } 6381da177e4SLinus Torvalds print "</refsect1>\n"; 6391da177e4SLinus Torvalds 6401da177e4SLinus Torvalds output_section_xml(@_); 6411da177e4SLinus Torvalds print "</refentry>\n\n"; 6421da177e4SLinus Torvalds} 6431da177e4SLinus Torvalds 6441da177e4SLinus Torvalds# output struct in XML DocBook 6451da177e4SLinus Torvaldssub output_struct_xml(%) { 6461da177e4SLinus Torvalds my %args = %{$_[0]}; 6471da177e4SLinus Torvalds my ($parameter, $section); 6481da177e4SLinus Torvalds my $id; 6491da177e4SLinus Torvalds 6501da177e4SLinus Torvalds $id = "API-struct-".$args{'struct'}; 6511da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 6521da177e4SLinus Torvalds 6531da177e4SLinus Torvalds print "<refentry>\n"; 6541da177e4SLinus Torvalds print "<refmeta>\n"; 6551da177e4SLinus Torvalds print "<refentrytitle><phrase id=\"$id\">".$args{'type'}." ".$args{'struct'}."</phrase></refentrytitle>\n"; 6561da177e4SLinus Torvalds print "</refmeta>\n"; 6571da177e4SLinus Torvalds print "<refnamediv>\n"; 6581da177e4SLinus Torvalds print " <refname>".$args{'type'}." ".$args{'struct'}."</refname>\n"; 6591da177e4SLinus Torvalds print " <refpurpose>\n"; 6601da177e4SLinus Torvalds print " "; 6611da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 6621da177e4SLinus Torvalds print " </refpurpose>\n"; 6631da177e4SLinus Torvalds print "</refnamediv>\n"; 6641da177e4SLinus Torvalds 6651da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 6661da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 6671da177e4SLinus Torvalds print " <programlisting>\n"; 6681da177e4SLinus Torvalds print $args{'type'}." ".$args{'struct'}." {\n"; 6691da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6701da177e4SLinus Torvalds if ($parameter =~ /^#/) { 6711da177e4SLinus Torvalds print "$parameter\n"; 6721da177e4SLinus Torvalds next; 6731da177e4SLinus Torvalds } 6741da177e4SLinus Torvalds 6751da177e4SLinus Torvalds my $parameter_name = $parameter; 6761da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 6771da177e4SLinus Torvalds 6781da177e4SLinus Torvalds defined($args{'parameterdescs'}{$parameter_name}) || next; 6791da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 6801da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 6811da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 6821da177e4SLinus Torvalds # pointer-to-function 6831da177e4SLinus Torvalds print " $1 $parameter) ($2);\n"; 6841da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 6851da177e4SLinus Torvalds print " $1 $parameter$2;\n"; 6861da177e4SLinus Torvalds } else { 6871da177e4SLinus Torvalds print " ".$type." ".$parameter.";\n"; 6881da177e4SLinus Torvalds } 6891da177e4SLinus Torvalds } 6901da177e4SLinus Torvalds print "};"; 6911da177e4SLinus Torvalds print " </programlisting>\n"; 6921da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 6931da177e4SLinus Torvalds 6941da177e4SLinus Torvalds print " <refsect1>\n"; 6951da177e4SLinus Torvalds print " <title>Members</title>\n"; 6961da177e4SLinus Torvalds 6971da177e4SLinus Torvalds print " <variablelist>\n"; 6981da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6991da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 7001da177e4SLinus Torvalds 7011da177e4SLinus Torvalds my $parameter_name = $parameter; 7021da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 7031da177e4SLinus Torvalds 7041da177e4SLinus Torvalds defined($args{'parameterdescs'}{$parameter_name}) || next; 7051da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 7061da177e4SLinus Torvalds print " <varlistentry>"; 7071da177e4SLinus Torvalds print " <term>$parameter</term>\n"; 7081da177e4SLinus Torvalds print " <listitem><para>\n"; 7091da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 7101da177e4SLinus Torvalds print " </para></listitem>\n"; 7111da177e4SLinus Torvalds print " </varlistentry>\n"; 7121da177e4SLinus Torvalds } 7131da177e4SLinus Torvalds print " </variablelist>\n"; 7141da177e4SLinus Torvalds print " </refsect1>\n"; 7151da177e4SLinus Torvalds 7161da177e4SLinus Torvalds output_section_xml(@_); 7171da177e4SLinus Torvalds 7181da177e4SLinus Torvalds print "</refentry>\n\n"; 7191da177e4SLinus Torvalds} 7201da177e4SLinus Torvalds 7211da177e4SLinus Torvalds# output enum in XML DocBook 7221da177e4SLinus Torvaldssub output_enum_xml(%) { 7231da177e4SLinus Torvalds my %args = %{$_[0]}; 7241da177e4SLinus Torvalds my ($parameter, $section); 7251da177e4SLinus Torvalds my $count; 7261da177e4SLinus Torvalds my $id; 7271da177e4SLinus Torvalds 7281da177e4SLinus Torvalds $id = "API-enum-".$args{'enum'}; 7291da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 7301da177e4SLinus Torvalds 7311da177e4SLinus Torvalds print "<refentry>\n"; 7321da177e4SLinus Torvalds print "<refmeta>\n"; 7331da177e4SLinus Torvalds print "<refentrytitle><phrase id=\"$id\">enum ".$args{'enum'}."</phrase></refentrytitle>\n"; 7341da177e4SLinus Torvalds print "</refmeta>\n"; 7351da177e4SLinus Torvalds print "<refnamediv>\n"; 7361da177e4SLinus Torvalds print " <refname>enum ".$args{'enum'}."</refname>\n"; 7371da177e4SLinus Torvalds print " <refpurpose>\n"; 7381da177e4SLinus Torvalds print " "; 7391da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 7401da177e4SLinus Torvalds print " </refpurpose>\n"; 7411da177e4SLinus Torvalds print "</refnamediv>\n"; 7421da177e4SLinus Torvalds 7431da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 7441da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 7451da177e4SLinus Torvalds print " <programlisting>\n"; 7461da177e4SLinus Torvalds print "enum ".$args{'enum'}." {\n"; 7471da177e4SLinus Torvalds $count = 0; 7481da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7491da177e4SLinus Torvalds print " $parameter"; 7501da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 7511da177e4SLinus Torvalds $count++; 7521da177e4SLinus Torvalds print ","; 7531da177e4SLinus Torvalds } 7541da177e4SLinus Torvalds print "\n"; 7551da177e4SLinus Torvalds } 7561da177e4SLinus Torvalds print "};"; 7571da177e4SLinus Torvalds print " </programlisting>\n"; 7581da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 7591da177e4SLinus Torvalds 7601da177e4SLinus Torvalds print "<refsect1>\n"; 7611da177e4SLinus Torvalds print " <title>Constants</title>\n"; 7621da177e4SLinus Torvalds print " <variablelist>\n"; 7631da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7641da177e4SLinus Torvalds my $parameter_name = $parameter; 7651da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 7661da177e4SLinus Torvalds 7671da177e4SLinus Torvalds print " <varlistentry>"; 7681da177e4SLinus Torvalds print " <term>$parameter</term>\n"; 7691da177e4SLinus Torvalds print " <listitem><para>\n"; 7701da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 7711da177e4SLinus Torvalds print " </para></listitem>\n"; 7721da177e4SLinus Torvalds print " </varlistentry>\n"; 7731da177e4SLinus Torvalds } 7741da177e4SLinus Torvalds print " </variablelist>\n"; 7751da177e4SLinus Torvalds print "</refsect1>\n"; 7761da177e4SLinus Torvalds 7771da177e4SLinus Torvalds output_section_xml(@_); 7781da177e4SLinus Torvalds 7791da177e4SLinus Torvalds print "</refentry>\n\n"; 7801da177e4SLinus Torvalds} 7811da177e4SLinus Torvalds 7821da177e4SLinus Torvalds# output typedef in XML DocBook 7831da177e4SLinus Torvaldssub output_typedef_xml(%) { 7841da177e4SLinus Torvalds my %args = %{$_[0]}; 7851da177e4SLinus Torvalds my ($parameter, $section); 7861da177e4SLinus Torvalds my $id; 7871da177e4SLinus Torvalds 7881da177e4SLinus Torvalds $id = "API-typedef-".$args{'typedef'}; 7891da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 7901da177e4SLinus Torvalds 7911da177e4SLinus Torvalds print "<refentry>\n"; 7921da177e4SLinus Torvalds print "<refmeta>\n"; 7931da177e4SLinus Torvalds print "<refentrytitle><phrase id=\"$id\">typedef ".$args{'typedef'}."</phrase></refentrytitle>\n"; 7941da177e4SLinus Torvalds print "</refmeta>\n"; 7951da177e4SLinus Torvalds print "<refnamediv>\n"; 7961da177e4SLinus Torvalds print " <refname>typedef ".$args{'typedef'}."</refname>\n"; 7971da177e4SLinus Torvalds print " <refpurpose>\n"; 7981da177e4SLinus Torvalds print " "; 7991da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 8001da177e4SLinus Torvalds print " </refpurpose>\n"; 8011da177e4SLinus Torvalds print "</refnamediv>\n"; 8021da177e4SLinus Torvalds 8031da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 8041da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 8051da177e4SLinus Torvalds print " <synopsis>typedef ".$args{'typedef'}.";</synopsis>\n"; 8061da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 8071da177e4SLinus Torvalds 8081da177e4SLinus Torvalds output_section_xml(@_); 8091da177e4SLinus Torvalds 8101da177e4SLinus Torvalds print "</refentry>\n\n"; 8111da177e4SLinus Torvalds} 8121da177e4SLinus Torvalds 8131da177e4SLinus Torvalds# output in XML DocBook 8141da177e4SLinus Torvaldssub output_intro_xml(%) { 8151da177e4SLinus Torvalds my %args = %{$_[0]}; 8161da177e4SLinus Torvalds my ($parameter, $section); 8171da177e4SLinus Torvalds my $count; 8181da177e4SLinus Torvalds 8191da177e4SLinus Torvalds my $id = $args{'module'}; 8201da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 8211da177e4SLinus Torvalds 8221da177e4SLinus Torvalds # print out each section 8231da177e4SLinus Torvalds $lineprefix=" "; 8241da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 8251da177e4SLinus Torvalds print "<refsect1>\n <title>$section</title>\n <para>\n"; 8261da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 8271da177e4SLinus Torvalds print "<example><para>\n"; 8281da177e4SLinus Torvalds } 8291da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 8301da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 8311da177e4SLinus Torvalds print "</para></example>\n"; 8321da177e4SLinus Torvalds } 8331da177e4SLinus Torvalds print " </para>\n</refsect1>\n"; 8341da177e4SLinus Torvalds } 8351da177e4SLinus Torvalds 8361da177e4SLinus Torvalds print "\n\n"; 8371da177e4SLinus Torvalds} 8381da177e4SLinus Torvalds 8391da177e4SLinus Torvalds# output in XML DocBook 8401da177e4SLinus Torvaldssub output_function_gnome { 8411da177e4SLinus Torvalds my %args = %{$_[0]}; 8421da177e4SLinus Torvalds my ($parameter, $section); 8431da177e4SLinus Torvalds my $count; 8441da177e4SLinus Torvalds my $id; 8451da177e4SLinus Torvalds 8461da177e4SLinus Torvalds $id = $args{'module'}."-".$args{'function'}; 8471da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 8481da177e4SLinus Torvalds 8491da177e4SLinus Torvalds print "<sect2>\n"; 8501da177e4SLinus Torvalds print " <title id=\"$id\">".$args{'function'}."</title>\n"; 8511da177e4SLinus Torvalds 8521da177e4SLinus Torvalds print " <funcsynopsis>\n"; 8531da177e4SLinus Torvalds print " <funcdef>".$args{'functiontype'}." "; 8541da177e4SLinus Torvalds print "<function>".$args{'function'}." "; 8551da177e4SLinus Torvalds print "</function></funcdef>\n"; 8561da177e4SLinus Torvalds 8571da177e4SLinus Torvalds $count = 0; 8581da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 8591da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 8601da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 8611da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 8621da177e4SLinus Torvalds # pointer-to-function 8631da177e4SLinus Torvalds print " <paramdef>$1 <parameter>$parameter</parameter>)\n"; 8641da177e4SLinus Torvalds print " <funcparams>$2</funcparams></paramdef>\n"; 8651da177e4SLinus Torvalds } else { 8661da177e4SLinus Torvalds print " <paramdef>".$type; 8671da177e4SLinus Torvalds print " <parameter>$parameter</parameter></paramdef>\n"; 8681da177e4SLinus Torvalds } 8691da177e4SLinus Torvalds } 8701da177e4SLinus Torvalds } else { 8711da177e4SLinus Torvalds print " <void>\n"; 8721da177e4SLinus Torvalds } 8731da177e4SLinus Torvalds print " </funcsynopsis>\n"; 8741da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 8751da177e4SLinus Torvalds print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n"; 8761da177e4SLinus Torvalds print "<tgroup cols=\"2\">\n"; 8771da177e4SLinus Torvalds print "<colspec colwidth=\"2*\">\n"; 8781da177e4SLinus Torvalds print "<colspec colwidth=\"8*\">\n"; 8791da177e4SLinus Torvalds print "<tbody>\n"; 8801da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 8811da177e4SLinus Torvalds my $parameter_name = $parameter; 8821da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 8831da177e4SLinus Torvalds 8841da177e4SLinus Torvalds print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n"; 8851da177e4SLinus Torvalds print " <entry>\n"; 8861da177e4SLinus Torvalds $lineprefix=" "; 8871da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 8881da177e4SLinus Torvalds print " </entry></row>\n"; 8891da177e4SLinus Torvalds } 8901da177e4SLinus Torvalds print " </tbody></tgroup></informaltable>\n"; 8911da177e4SLinus Torvalds } else { 8921da177e4SLinus Torvalds print " <para>\n None\n </para>\n"; 8931da177e4SLinus Torvalds } 8941da177e4SLinus Torvalds 8951da177e4SLinus Torvalds # print out each section 8961da177e4SLinus Torvalds $lineprefix=" "; 8971da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 8981da177e4SLinus Torvalds print "<simplesect>\n <title>$section</title>\n"; 8991da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 9001da177e4SLinus Torvalds print "<example><programlisting>\n"; 9011da177e4SLinus Torvalds } else { 9021da177e4SLinus Torvalds } 9031da177e4SLinus Torvalds print "<para>\n"; 9041da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 9051da177e4SLinus Torvalds print "</para>\n"; 9061da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 9071da177e4SLinus Torvalds print "</programlisting></example>\n"; 9081da177e4SLinus Torvalds } else { 9091da177e4SLinus Torvalds } 9101da177e4SLinus Torvalds print " </simplesect>\n"; 9111da177e4SLinus Torvalds } 9121da177e4SLinus Torvalds 9131da177e4SLinus Torvalds print "</sect2>\n\n"; 9141da177e4SLinus Torvalds} 9151da177e4SLinus Torvalds 9161da177e4SLinus Torvalds## 9171da177e4SLinus Torvalds# output function in man 9181da177e4SLinus Torvaldssub output_function_man(%) { 9191da177e4SLinus Torvalds my %args = %{$_[0]}; 9201da177e4SLinus Torvalds my ($parameter, $section); 9211da177e4SLinus Torvalds my $count; 9221da177e4SLinus Torvalds 9231da177e4SLinus Torvalds print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; 9241da177e4SLinus Torvalds 9251da177e4SLinus Torvalds print ".SH NAME\n"; 9261da177e4SLinus Torvalds print $args{'function'}." \\- ".$args{'purpose'}."\n"; 9271da177e4SLinus Torvalds 9281da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 9291da177e4SLinus Torvalds print ".B \"".$args{'functiontype'}."\" ".$args{'function'}."\n"; 9301da177e4SLinus Torvalds $count = 0; 9311da177e4SLinus Torvalds my $parenth = "("; 9321da177e4SLinus Torvalds my $post = ","; 9331da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 9341da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 9351da177e4SLinus Torvalds $post = ");"; 9361da177e4SLinus Torvalds } 9371da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 9381da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 9391da177e4SLinus Torvalds # pointer-to-function 9401da177e4SLinus Torvalds print ".BI \"".$parenth.$1."\" ".$parameter." \") (".$2.")".$post."\"\n"; 9411da177e4SLinus Torvalds } else { 9421da177e4SLinus Torvalds $type =~ s/([^\*])$/$1 /; 9431da177e4SLinus Torvalds print ".BI \"".$parenth.$type."\" ".$parameter." \"".$post."\"\n"; 9441da177e4SLinus Torvalds } 9451da177e4SLinus Torvalds $count++; 9461da177e4SLinus Torvalds $parenth = ""; 9471da177e4SLinus Torvalds } 9481da177e4SLinus Torvalds 9491da177e4SLinus Torvalds print ".SH ARGUMENTS\n"; 9501da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 9511da177e4SLinus Torvalds my $parameter_name = $parameter; 9521da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 9531da177e4SLinus Torvalds 9541da177e4SLinus Torvalds print ".IP \"".$parameter."\" 12\n"; 9551da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 9561da177e4SLinus Torvalds } 9571da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 9581da177e4SLinus Torvalds print ".SH \"", uc $section, "\"\n"; 9591da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 9601da177e4SLinus Torvalds } 9611da177e4SLinus Torvalds} 9621da177e4SLinus Torvalds 9631da177e4SLinus Torvalds## 9641da177e4SLinus Torvalds# output enum in man 9651da177e4SLinus Torvaldssub output_enum_man(%) { 9661da177e4SLinus Torvalds my %args = %{$_[0]}; 9671da177e4SLinus Torvalds my ($parameter, $section); 9681da177e4SLinus Torvalds my $count; 9691da177e4SLinus Torvalds 9701da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n"; 9711da177e4SLinus Torvalds 9721da177e4SLinus Torvalds print ".SH NAME\n"; 9731da177e4SLinus Torvalds print "enum ".$args{'enum'}." \\- ".$args{'purpose'}."\n"; 9741da177e4SLinus Torvalds 9751da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 9761da177e4SLinus Torvalds print "enum ".$args{'enum'}." {\n"; 9771da177e4SLinus Torvalds $count = 0; 9781da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 9791da177e4SLinus Torvalds print ".br\n.BI \" $parameter\"\n"; 9801da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 9811da177e4SLinus Torvalds print "\n};\n"; 9821da177e4SLinus Torvalds last; 9831da177e4SLinus Torvalds } 9841da177e4SLinus Torvalds else { 9851da177e4SLinus Torvalds print ", \n.br\n"; 9861da177e4SLinus Torvalds } 9871da177e4SLinus Torvalds $count++; 9881da177e4SLinus Torvalds } 9891da177e4SLinus Torvalds 9901da177e4SLinus Torvalds print ".SH Constants\n"; 9911da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 9921da177e4SLinus Torvalds my $parameter_name = $parameter; 9931da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 9941da177e4SLinus Torvalds 9951da177e4SLinus Torvalds print ".IP \"".$parameter."\" 12\n"; 9961da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 9971da177e4SLinus Torvalds } 9981da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 9991da177e4SLinus Torvalds print ".SH \"$section\"\n"; 10001da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 10011da177e4SLinus Torvalds } 10021da177e4SLinus Torvalds} 10031da177e4SLinus Torvalds 10041da177e4SLinus Torvalds## 10051da177e4SLinus Torvalds# output struct in man 10061da177e4SLinus Torvaldssub output_struct_man(%) { 10071da177e4SLinus Torvalds my %args = %{$_[0]}; 10081da177e4SLinus Torvalds my ($parameter, $section); 10091da177e4SLinus Torvalds 10101da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"".$args{'type'}." ".$args{'struct'}."\" \"$man_date\" \"API Manual\" LINUX\n"; 10111da177e4SLinus Torvalds 10121da177e4SLinus Torvalds print ".SH NAME\n"; 10131da177e4SLinus Torvalds print $args{'type'}." ".$args{'struct'}." \\- ".$args{'purpose'}."\n"; 10141da177e4SLinus Torvalds 10151da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 10161da177e4SLinus Torvalds print $args{'type'}." ".$args{'struct'}." {\n.br\n"; 10171da177e4SLinus Torvalds 10181da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 10191da177e4SLinus Torvalds if ($parameter =~ /^#/) { 10201da177e4SLinus Torvalds print ".BI \"$parameter\"\n.br\n"; 10211da177e4SLinus Torvalds next; 10221da177e4SLinus Torvalds } 10231da177e4SLinus Torvalds my $parameter_name = $parameter; 10241da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 10251da177e4SLinus Torvalds 10261da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 10271da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 10281da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 10291da177e4SLinus Torvalds # pointer-to-function 10301da177e4SLinus Torvalds print ".BI \" ".$1."\" ".$parameter." \") (".$2.")"."\"\n;\n"; 10311da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 10321da177e4SLinus Torvalds print ".BI \" ".$1."\" ".$parameter.$2." \""."\"\n;\n"; 10331da177e4SLinus Torvalds } else { 10341da177e4SLinus Torvalds $type =~ s/([^\*])$/$1 /; 10351da177e4SLinus Torvalds print ".BI \" ".$type."\" ".$parameter." \""."\"\n;\n"; 10361da177e4SLinus Torvalds } 10371da177e4SLinus Torvalds print "\n.br\n"; 10381da177e4SLinus Torvalds } 10391da177e4SLinus Torvalds print "};\n.br\n"; 10401da177e4SLinus Torvalds 10411da177e4SLinus Torvalds print ".SH Arguments\n"; 10421da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 10431da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 10441da177e4SLinus Torvalds 10451da177e4SLinus Torvalds my $parameter_name = $parameter; 10461da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 10471da177e4SLinus Torvalds 10481da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 10491da177e4SLinus Torvalds print ".IP \"".$parameter."\" 12\n"; 10501da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 10511da177e4SLinus Torvalds } 10521da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 10531da177e4SLinus Torvalds print ".SH \"$section\"\n"; 10541da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 10551da177e4SLinus Torvalds } 10561da177e4SLinus Torvalds} 10571da177e4SLinus Torvalds 10581da177e4SLinus Torvalds## 10591da177e4SLinus Torvalds# output typedef in man 10601da177e4SLinus Torvaldssub output_typedef_man(%) { 10611da177e4SLinus Torvalds my %args = %{$_[0]}; 10621da177e4SLinus Torvalds my ($parameter, $section); 10631da177e4SLinus Torvalds 10641da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n"; 10651da177e4SLinus Torvalds 10661da177e4SLinus Torvalds print ".SH NAME\n"; 10671da177e4SLinus Torvalds print "typedef ".$args{'typedef'}." \\- ".$args{'purpose'}."\n"; 10681da177e4SLinus Torvalds 10691da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 10701da177e4SLinus Torvalds print ".SH \"$section\"\n"; 10711da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 10721da177e4SLinus Torvalds } 10731da177e4SLinus Torvalds} 10741da177e4SLinus Torvalds 10751da177e4SLinus Torvaldssub output_intro_man(%) { 10761da177e4SLinus Torvalds my %args = %{$_[0]}; 10771da177e4SLinus Torvalds my ($parameter, $section); 10781da177e4SLinus Torvalds my $count; 10791da177e4SLinus Torvalds 10801da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; 10811da177e4SLinus Torvalds 10821da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 10831da177e4SLinus Torvalds print ".SH \"$section\"\n"; 10841da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 10851da177e4SLinus Torvalds } 10861da177e4SLinus Torvalds} 10871da177e4SLinus Torvalds 10881da177e4SLinus Torvalds## 10891da177e4SLinus Torvalds# output in text 10901da177e4SLinus Torvaldssub output_function_text(%) { 10911da177e4SLinus Torvalds my %args = %{$_[0]}; 10921da177e4SLinus Torvalds my ($parameter, $section); 10931da177e4SLinus Torvalds 10941da177e4SLinus Torvalds print "Function:\n\n"; 10951da177e4SLinus Torvalds my $start=$args{'functiontype'}." ".$args{'function'}." ("; 10961da177e4SLinus Torvalds print $start; 10971da177e4SLinus Torvalds my $count = 0; 10981da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 10991da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 11001da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 11011da177e4SLinus Torvalds # pointer-to-function 11021da177e4SLinus Torvalds print $1.$parameter.") (".$2; 11031da177e4SLinus Torvalds } else { 11041da177e4SLinus Torvalds print $type." ".$parameter; 11051da177e4SLinus Torvalds } 11061da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 11071da177e4SLinus Torvalds $count++; 11081da177e4SLinus Torvalds print ",\n"; 11091da177e4SLinus Torvalds print " " x length($start); 11101da177e4SLinus Torvalds } else { 11111da177e4SLinus Torvalds print ");\n\n"; 11121da177e4SLinus Torvalds } 11131da177e4SLinus Torvalds } 11141da177e4SLinus Torvalds 11151da177e4SLinus Torvalds print "Arguments:\n\n"; 11161da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 11171da177e4SLinus Torvalds my $parameter_name = $parameter; 11181da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 11191da177e4SLinus Torvalds 11201da177e4SLinus Torvalds print $parameter."\n\t".$args{'parameterdescs'}{$parameter_name}."\n"; 11211da177e4SLinus Torvalds } 11221da177e4SLinus Torvalds output_section_text(@_); 11231da177e4SLinus Torvalds} 11241da177e4SLinus Torvalds 11251da177e4SLinus Torvalds#output sections in text 11261da177e4SLinus Torvaldssub output_section_text(%) { 11271da177e4SLinus Torvalds my %args = %{$_[0]}; 11281da177e4SLinus Torvalds my $section; 11291da177e4SLinus Torvalds 11301da177e4SLinus Torvalds print "\n"; 11311da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 11321da177e4SLinus Torvalds print "$section:\n\n"; 11331da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 11341da177e4SLinus Torvalds } 11351da177e4SLinus Torvalds print "\n\n"; 11361da177e4SLinus Torvalds} 11371da177e4SLinus Torvalds 11381da177e4SLinus Torvalds# output enum in text 11391da177e4SLinus Torvaldssub output_enum_text(%) { 11401da177e4SLinus Torvalds my %args = %{$_[0]}; 11411da177e4SLinus Torvalds my ($parameter); 11421da177e4SLinus Torvalds my $count; 11431da177e4SLinus Torvalds print "Enum:\n\n"; 11441da177e4SLinus Torvalds 11451da177e4SLinus Torvalds print "enum ".$args{'enum'}." {\n"; 11461da177e4SLinus Torvalds $count = 0; 11471da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 11481da177e4SLinus Torvalds print "\t$parameter"; 11491da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 11501da177e4SLinus Torvalds $count++; 11511da177e4SLinus Torvalds print ","; 11521da177e4SLinus Torvalds } 11531da177e4SLinus Torvalds print "\n"; 11541da177e4SLinus Torvalds } 11551da177e4SLinus Torvalds print "};\n\n"; 11561da177e4SLinus Torvalds 11571da177e4SLinus Torvalds print "Constants:\n\n"; 11581da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 11591da177e4SLinus Torvalds print "$parameter\n\t"; 11601da177e4SLinus Torvalds print $args{'parameterdescs'}{$parameter}."\n"; 11611da177e4SLinus Torvalds } 11621da177e4SLinus Torvalds 11631da177e4SLinus Torvalds output_section_text(@_); 11641da177e4SLinus Torvalds} 11651da177e4SLinus Torvalds 11661da177e4SLinus Torvalds# output typedef in text 11671da177e4SLinus Torvaldssub output_typedef_text(%) { 11681da177e4SLinus Torvalds my %args = %{$_[0]}; 11691da177e4SLinus Torvalds my ($parameter); 11701da177e4SLinus Torvalds my $count; 11711da177e4SLinus Torvalds print "Typedef:\n\n"; 11721da177e4SLinus Torvalds 11731da177e4SLinus Torvalds print "typedef ".$args{'typedef'}."\n"; 11741da177e4SLinus Torvalds output_section_text(@_); 11751da177e4SLinus Torvalds} 11761da177e4SLinus Torvalds 11771da177e4SLinus Torvalds# output struct as text 11781da177e4SLinus Torvaldssub output_struct_text(%) { 11791da177e4SLinus Torvalds my %args = %{$_[0]}; 11801da177e4SLinus Torvalds my ($parameter); 11811da177e4SLinus Torvalds 11821da177e4SLinus Torvalds print $args{'type'}." ".$args{'struct'}.":\n\n"; 11831da177e4SLinus Torvalds print $args{'type'}." ".$args{'struct'}." {\n"; 11841da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 11851da177e4SLinus Torvalds if ($parameter =~ /^#/) { 11861da177e4SLinus Torvalds print "$parameter\n"; 11871da177e4SLinus Torvalds next; 11881da177e4SLinus Torvalds } 11891da177e4SLinus Torvalds 11901da177e4SLinus Torvalds my $parameter_name = $parameter; 11911da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 11921da177e4SLinus Torvalds 11931da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 11941da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 11951da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 11961da177e4SLinus Torvalds # pointer-to-function 11971da177e4SLinus Torvalds print "\t$1 $parameter) ($2);\n"; 11981da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 11991da177e4SLinus Torvalds print "\t$1 $parameter$2;\n"; 12001da177e4SLinus Torvalds } else { 12011da177e4SLinus Torvalds print "\t".$type." ".$parameter.";\n"; 12021da177e4SLinus Torvalds } 12031da177e4SLinus Torvalds } 12041da177e4SLinus Torvalds print "};\n\n"; 12051da177e4SLinus Torvalds 12061da177e4SLinus Torvalds print "Members:\n\n"; 12071da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 12081da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 12091da177e4SLinus Torvalds 12101da177e4SLinus Torvalds my $parameter_name = $parameter; 12111da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 12121da177e4SLinus Torvalds 12131da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 12141da177e4SLinus Torvalds print "$parameter\n\t"; 12151da177e4SLinus Torvalds print $args{'parameterdescs'}{$parameter_name}."\n"; 12161da177e4SLinus Torvalds } 12171da177e4SLinus Torvalds print "\n"; 12181da177e4SLinus Torvalds output_section_text(@_); 12191da177e4SLinus Torvalds} 12201da177e4SLinus Torvalds 12211da177e4SLinus Torvaldssub output_intro_text(%) { 12221da177e4SLinus Torvalds my %args = %{$_[0]}; 12231da177e4SLinus Torvalds my ($parameter, $section); 12241da177e4SLinus Torvalds 12251da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 12261da177e4SLinus Torvalds print " $section:\n"; 12271da177e4SLinus Torvalds print " -> "; 12281da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 12291da177e4SLinus Torvalds } 12301da177e4SLinus Torvalds} 12311da177e4SLinus Torvalds 12321da177e4SLinus Torvalds## 12331da177e4SLinus Torvalds# generic output function for typedefs 12341da177e4SLinus Torvaldssub output_declaration { 12351da177e4SLinus Torvalds no strict 'refs'; 12361da177e4SLinus Torvalds my $name = shift; 12371da177e4SLinus Torvalds my $functype = shift; 12381da177e4SLinus Torvalds my $func = "output_${functype}_$output_mode"; 12391da177e4SLinus Torvalds if (($function_only==0) || 12401da177e4SLinus Torvalds ( $function_only == 1 && defined($function_table{$name})) || 12411da177e4SLinus Torvalds ( $function_only == 2 && !defined($function_table{$name}))) 12421da177e4SLinus Torvalds { 12431da177e4SLinus Torvalds &$func(@_); 12441da177e4SLinus Torvalds $section_counter++; 12451da177e4SLinus Torvalds } 12461da177e4SLinus Torvalds} 12471da177e4SLinus Torvalds 12481da177e4SLinus Torvalds## 12491da177e4SLinus Torvalds# generic output function - calls the right one based 12501da177e4SLinus Torvalds# on current output mode. 12511da177e4SLinus Torvaldssub output_intro { 12521da177e4SLinus Torvalds no strict 'refs'; 12531da177e4SLinus Torvalds my $func = "output_intro_".$output_mode; 12541da177e4SLinus Torvalds &$func(@_); 12551da177e4SLinus Torvalds $section_counter++; 12561da177e4SLinus Torvalds} 12571da177e4SLinus Torvalds 12581da177e4SLinus Torvalds## 12591da177e4SLinus Torvalds# takes a declaration (struct, union, enum, typedef) and 12601da177e4SLinus Torvalds# invokes the right handler. NOT called for functions. 12611da177e4SLinus Torvaldssub dump_declaration($$) { 12621da177e4SLinus Torvalds no strict 'refs'; 12631da177e4SLinus Torvalds my ($prototype, $file) = @_; 12641da177e4SLinus Torvalds my $func = "dump_".$decl_type; 12651da177e4SLinus Torvalds &$func(@_); 12661da177e4SLinus Torvalds} 12671da177e4SLinus Torvalds 12681da177e4SLinus Torvaldssub dump_union($$) { 12691da177e4SLinus Torvalds dump_struct(@_); 12701da177e4SLinus Torvalds} 12711da177e4SLinus Torvalds 12721da177e4SLinus Torvaldssub dump_struct($$) { 12731da177e4SLinus Torvalds my $x = shift; 12741da177e4SLinus Torvalds my $file = shift; 12751da177e4SLinus Torvalds 12761da177e4SLinus Torvalds if ($x =~/(struct|union)\s+(\w+)\s*{(.*)}/) { 12771da177e4SLinus Torvalds $declaration_name = $2; 12781da177e4SLinus Torvalds my $members = $3; 12791da177e4SLinus Torvalds 12801da177e4SLinus Torvalds # ignore embedded structs or unions 12811da177e4SLinus Torvalds $members =~ s/{.*?}//g; 12821da177e4SLinus Torvalds 12831da177e4SLinus Torvalds create_parameterlist($members, ';', $file); 12841da177e4SLinus Torvalds 12851da177e4SLinus Torvalds output_declaration($declaration_name, 12861da177e4SLinus Torvalds 'struct', 12871da177e4SLinus Torvalds {'struct' => $declaration_name, 12881da177e4SLinus Torvalds 'module' => $modulename, 12891da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 12901da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 12911da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 12921da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 12931da177e4SLinus Torvalds 'sections' => \%sections, 12941da177e4SLinus Torvalds 'purpose' => $declaration_purpose, 12951da177e4SLinus Torvalds 'type' => $decl_type 12961da177e4SLinus Torvalds }); 12971da177e4SLinus Torvalds } 12981da177e4SLinus Torvalds else { 12991da177e4SLinus Torvalds print STDERR "Error(${file}:$.): Cannot parse struct or union!\n"; 13001da177e4SLinus Torvalds ++$errors; 13011da177e4SLinus Torvalds } 13021da177e4SLinus Torvalds} 13031da177e4SLinus Torvalds 13041da177e4SLinus Torvaldssub dump_enum($$) { 13051da177e4SLinus Torvalds my $x = shift; 13061da177e4SLinus Torvalds my $file = shift; 13071da177e4SLinus Torvalds 13081da177e4SLinus Torvalds if ($x =~ /enum\s+(\w+)\s*{(.*)}/) { 13091da177e4SLinus Torvalds $declaration_name = $1; 13101da177e4SLinus Torvalds my $members = $2; 13111da177e4SLinus Torvalds 13121da177e4SLinus Torvalds foreach my $arg (split ',', $members) { 13131da177e4SLinus Torvalds $arg =~ s/^\s*(\w+).*/$1/; 13141da177e4SLinus Torvalds push @parameterlist, $arg; 13151da177e4SLinus Torvalds if (!$parameterdescs{$arg}) { 13161da177e4SLinus Torvalds $parameterdescs{$arg} = $undescribed; 13171da177e4SLinus Torvalds print STDERR "Warning(${file}:$.): Enum value '$arg' ". 13181da177e4SLinus Torvalds "not described in enum '$declaration_name'\n"; 13191da177e4SLinus Torvalds } 13201da177e4SLinus Torvalds 13211da177e4SLinus Torvalds } 13221da177e4SLinus Torvalds 13231da177e4SLinus Torvalds output_declaration($declaration_name, 13241da177e4SLinus Torvalds 'enum', 13251da177e4SLinus Torvalds {'enum' => $declaration_name, 13261da177e4SLinus Torvalds 'module' => $modulename, 13271da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 13281da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 13291da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 13301da177e4SLinus Torvalds 'sections' => \%sections, 13311da177e4SLinus Torvalds 'purpose' => $declaration_purpose 13321da177e4SLinus Torvalds }); 13331da177e4SLinus Torvalds } 13341da177e4SLinus Torvalds else { 13351da177e4SLinus Torvalds print STDERR "Error(${file}:$.): Cannot parse enum!\n"; 13361da177e4SLinus Torvalds ++$errors; 13371da177e4SLinus Torvalds } 13381da177e4SLinus Torvalds} 13391da177e4SLinus Torvalds 13401da177e4SLinus Torvaldssub dump_typedef($$) { 13411da177e4SLinus Torvalds my $x = shift; 13421da177e4SLinus Torvalds my $file = shift; 13431da177e4SLinus Torvalds 13441da177e4SLinus Torvalds while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { 13451da177e4SLinus Torvalds $x =~ s/\(*.\)\s*;$/;/; 13461da177e4SLinus Torvalds $x =~ s/\[*.\]\s*;$/;/; 13471da177e4SLinus Torvalds } 13481da177e4SLinus Torvalds 13491da177e4SLinus Torvalds if ($x =~ /typedef.*\s+(\w+)\s*;/) { 13501da177e4SLinus Torvalds $declaration_name = $1; 13511da177e4SLinus Torvalds 13521da177e4SLinus Torvalds output_declaration($declaration_name, 13531da177e4SLinus Torvalds 'typedef', 13541da177e4SLinus Torvalds {'typedef' => $declaration_name, 13551da177e4SLinus Torvalds 'module' => $modulename, 13561da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 13571da177e4SLinus Torvalds 'sections' => \%sections, 13581da177e4SLinus Torvalds 'purpose' => $declaration_purpose 13591da177e4SLinus Torvalds }); 13601da177e4SLinus Torvalds } 13611da177e4SLinus Torvalds else { 13621da177e4SLinus Torvalds print STDERR "Error(${file}:$.): Cannot parse typedef!\n"; 13631da177e4SLinus Torvalds ++$errors; 13641da177e4SLinus Torvalds } 13651da177e4SLinus Torvalds} 13661da177e4SLinus Torvalds 13671da177e4SLinus Torvaldssub create_parameterlist($$$) { 13681da177e4SLinus Torvalds my $args = shift; 13691da177e4SLinus Torvalds my $splitter = shift; 13701da177e4SLinus Torvalds my $file = shift; 13711da177e4SLinus Torvalds my $type; 13721da177e4SLinus Torvalds my $param; 13731da177e4SLinus Torvalds 13741da177e4SLinus Torvalds while ($args =~ /(\([^\),]+),/) { 13751da177e4SLinus Torvalds $args =~ s/(\([^\),]+),/$1#/g; 13761da177e4SLinus Torvalds } 13771da177e4SLinus Torvalds 13781da177e4SLinus Torvalds foreach my $arg (split($splitter, $args)) { 13791da177e4SLinus Torvalds # strip comments 13801da177e4SLinus Torvalds $arg =~ s/\/\*.*\*\///; 13811da177e4SLinus Torvalds # strip leading/trailing spaces 13821da177e4SLinus Torvalds $arg =~ s/^\s*//; 13831da177e4SLinus Torvalds $arg =~ s/\s*$//; 13841da177e4SLinus Torvalds $arg =~ s/\s+/ /; 13851da177e4SLinus Torvalds 13861da177e4SLinus Torvalds if ($arg =~ /^#/) { 13871da177e4SLinus Torvalds # Treat preprocessor directive as a typeless variable just to fill 13881da177e4SLinus Torvalds # corresponding data structures "correctly". Catch it later in 13891da177e4SLinus Torvalds # output_* subs. 13901da177e4SLinus Torvalds push_parameter($arg, "", $file); 13911da177e4SLinus Torvalds } elsif ($arg =~ m/\(/) { 13921da177e4SLinus Torvalds # pointer-to-function 13931da177e4SLinus Torvalds $arg =~ tr/#/,/; 13941da177e4SLinus Torvalds $arg =~ m/[^\(]+\(\*([^\)]+)\)/; 13951da177e4SLinus Torvalds $param = $1; 13961da177e4SLinus Torvalds $type = $arg; 13971da177e4SLinus Torvalds $type =~ s/([^\(]+\(\*)$param/$1/; 13981da177e4SLinus Torvalds push_parameter($param, $type, $file); 13991da177e4SLinus Torvalds } else { 14001da177e4SLinus Torvalds $arg =~ s/\s*:\s*/:/g; 14011da177e4SLinus Torvalds $arg =~ s/\s*\[/\[/g; 14021da177e4SLinus Torvalds 14031da177e4SLinus Torvalds my @args = split('\s*,\s*', $arg); 14041da177e4SLinus Torvalds if ($args[0] =~ m/\*/) { 14051da177e4SLinus Torvalds $args[0] =~ s/(\*+)\s*/ $1/; 14061da177e4SLinus Torvalds } 14071da177e4SLinus Torvalds my @first_arg = split('\s+', shift @args); 14081da177e4SLinus Torvalds unshift(@args, pop @first_arg); 14091da177e4SLinus Torvalds $type = join " ", @first_arg; 14101da177e4SLinus Torvalds 14111da177e4SLinus Torvalds foreach $param (@args) { 14121da177e4SLinus Torvalds if ($param =~ m/^(\*+)\s*(.*)/) { 14131da177e4SLinus Torvalds push_parameter($2, "$type $1", $file); 14141da177e4SLinus Torvalds } 14151da177e4SLinus Torvalds elsif ($param =~ m/(.*?):(\d+)/) { 14161da177e4SLinus Torvalds push_parameter($1, "$type:$2", $file) 14171da177e4SLinus Torvalds } 14181da177e4SLinus Torvalds else { 14191da177e4SLinus Torvalds push_parameter($param, $type, $file); 14201da177e4SLinus Torvalds } 14211da177e4SLinus Torvalds } 14221da177e4SLinus Torvalds } 14231da177e4SLinus Torvalds } 14241da177e4SLinus Torvalds} 14251da177e4SLinus Torvalds 14261da177e4SLinus Torvaldssub push_parameter($$$) { 14271da177e4SLinus Torvalds my $param = shift; 14281da177e4SLinus Torvalds my $type = shift; 14291da177e4SLinus Torvalds my $file = shift; 14301da177e4SLinus Torvalds 14311da177e4SLinus Torvalds my $param_name = $param; 14321da177e4SLinus Torvalds $param_name =~ s/\[.*//; 14331da177e4SLinus Torvalds 14341da177e4SLinus Torvalds if ($type eq "" && $param eq "...") 14351da177e4SLinus Torvalds { 14361da177e4SLinus Torvalds $type=""; 14371da177e4SLinus Torvalds $param="..."; 14381da177e4SLinus Torvalds $parameterdescs{"..."} = "variable arguments"; 14391da177e4SLinus Torvalds } 14401da177e4SLinus Torvalds elsif ($type eq "" && ($param eq "" or $param eq "void")) 14411da177e4SLinus Torvalds { 14421da177e4SLinus Torvalds $type=""; 14431da177e4SLinus Torvalds $param="void"; 14441da177e4SLinus Torvalds $parameterdescs{void} = "no arguments"; 14451da177e4SLinus Torvalds } 14461da177e4SLinus Torvalds if (defined $type && $type && !defined $parameterdescs{$param_name}) { 14471da177e4SLinus Torvalds $parameterdescs{$param_name} = $undescribed; 14481da177e4SLinus Torvalds 14491da177e4SLinus Torvalds if (($type eq 'function') || ($type eq 'enum')) { 14501da177e4SLinus Torvalds print STDERR "Warning(${file}:$.): Function parameter ". 14511da177e4SLinus Torvalds "or member '$param' not " . 14521da177e4SLinus Torvalds "described in '$declaration_name'\n"; 14531da177e4SLinus Torvalds } 14541da177e4SLinus Torvalds print STDERR "Warning(${file}:$.):". 14551da177e4SLinus Torvalds " No description found for parameter '$param'\n"; 14561da177e4SLinus Torvalds ++$warnings; 14571da177e4SLinus Torvalds } 14581da177e4SLinus Torvalds 14591da177e4SLinus Torvalds push @parameterlist, $param; 14601da177e4SLinus Torvalds $parametertypes{$param} = $type; 14611da177e4SLinus Torvalds} 14621da177e4SLinus Torvalds 14631da177e4SLinus Torvalds## 14641da177e4SLinus Torvalds# takes a function prototype and the name of the current file being 14651da177e4SLinus Torvalds# processed and spits out all the details stored in the global 14661da177e4SLinus Torvalds# arrays/hashes. 14671da177e4SLinus Torvaldssub dump_function($$) { 14681da177e4SLinus Torvalds my $prototype = shift; 14691da177e4SLinus Torvalds my $file = shift; 14701da177e4SLinus Torvalds 14711da177e4SLinus Torvalds $prototype =~ s/^static +//; 14721da177e4SLinus Torvalds $prototype =~ s/^extern +//; 14734dc3b16bSPavel Pisa $prototype =~ s/^fastcall +//; 14744dc3b16bSPavel Pisa $prototype =~ s/^asmlinkage +//; 14751da177e4SLinus Torvalds $prototype =~ s/^inline +//; 14761da177e4SLinus Torvalds $prototype =~ s/^__inline__ +//; 14771da177e4SLinus Torvalds $prototype =~ s/^#define +//; #ak added 14781da177e4SLinus Torvalds $prototype =~ s/__attribute__ \(\([a-z,]*\)\)//; 14791da177e4SLinus Torvalds 14801da177e4SLinus Torvalds # Yes, this truly is vile. We are looking for: 14811da177e4SLinus Torvalds # 1. Return type (may be nothing if we're looking at a macro) 14821da177e4SLinus Torvalds # 2. Function name 14831da177e4SLinus Torvalds # 3. Function parameters. 14841da177e4SLinus Torvalds # 14851da177e4SLinus Torvalds # All the while we have to watch out for function pointer parameters 14861da177e4SLinus Torvalds # (which IIRC is what the two sections are for), C types (these 14871da177e4SLinus Torvalds # regexps don't even start to express all the possibilities), and 14881da177e4SLinus Torvalds # so on. 14891da177e4SLinus Torvalds # 14901da177e4SLinus Torvalds # If you mess with these regexps, it's a good idea to check that 14911da177e4SLinus Torvalds # the following functions' documentation still comes out right: 14921da177e4SLinus Torvalds # - parport_register_device (function pointer parameters) 14931da177e4SLinus Torvalds # - atomic_set (macro) 14941da177e4SLinus Torvalds # - pci_match_device (long return type) 14951da177e4SLinus Torvalds 14961da177e4SLinus Torvalds if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 14971da177e4SLinus Torvalds $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 14981da177e4SLinus Torvalds $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 14991da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 15001da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 15011da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 15021da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 15031da177e4SLinus Torvalds $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 15041da177e4SLinus Torvalds $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 15051da177e4SLinus Torvalds $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 15061da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 15071da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 15081da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 15091da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) { 15101da177e4SLinus Torvalds $return_type = $1; 15111da177e4SLinus Torvalds $declaration_name = $2; 15121da177e4SLinus Torvalds my $args = $3; 15131da177e4SLinus Torvalds 15141da177e4SLinus Torvalds create_parameterlist($args, ',', $file); 15151da177e4SLinus Torvalds } else { 15161da177e4SLinus Torvalds print STDERR "Error(${file}:$.): cannot understand prototype: '$prototype'\n"; 15171da177e4SLinus Torvalds ++$errors; 15181da177e4SLinus Torvalds return; 15191da177e4SLinus Torvalds } 15201da177e4SLinus Torvalds 15211da177e4SLinus Torvalds output_declaration($declaration_name, 15221da177e4SLinus Torvalds 'function', 15231da177e4SLinus Torvalds {'function' => $declaration_name, 15241da177e4SLinus Torvalds 'module' => $modulename, 15251da177e4SLinus Torvalds 'functiontype' => $return_type, 15261da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 15271da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 15281da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 15291da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 15301da177e4SLinus Torvalds 'sections' => \%sections, 15311da177e4SLinus Torvalds 'purpose' => $declaration_purpose 15321da177e4SLinus Torvalds }); 15331da177e4SLinus Torvalds} 15341da177e4SLinus Torvalds 15351da177e4SLinus Torvaldssub process_file($); 15361da177e4SLinus Torvalds 15371da177e4SLinus Torvalds# Read the file that maps relative names to absolute names for 15381da177e4SLinus Torvalds# separate source and object directories and for shadow trees. 15391da177e4SLinus Torvaldsif (open(SOURCE_MAP, "<.tmp_filelist.txt")) { 15401da177e4SLinus Torvalds my ($relname, $absname); 15411da177e4SLinus Torvalds while(<SOURCE_MAP>) { 15421da177e4SLinus Torvalds chop(); 15431da177e4SLinus Torvalds ($relname, $absname) = (split())[0..1]; 15441da177e4SLinus Torvalds $relname =~ s:^/+::; 15451da177e4SLinus Torvalds $source_map{$relname} = $absname; 15461da177e4SLinus Torvalds } 15471da177e4SLinus Torvalds close(SOURCE_MAP); 15481da177e4SLinus Torvalds} 15491da177e4SLinus Torvalds 15501da177e4SLinus Torvaldsif ($filelist) { 15511da177e4SLinus Torvalds open(FLIST,"<$filelist") or die "Can't open file list $filelist"; 15521da177e4SLinus Torvalds while(<FLIST>) { 15531da177e4SLinus Torvalds chop; 15541da177e4SLinus Torvalds process_file($_); 15551da177e4SLinus Torvalds } 15561da177e4SLinus Torvalds} 15571da177e4SLinus Torvalds 15581da177e4SLinus Torvaldsforeach (@ARGV) { 15591da177e4SLinus Torvalds chomp; 15601da177e4SLinus Torvalds process_file($_); 15611da177e4SLinus Torvalds} 15621da177e4SLinus Torvaldsif ($verbose && $errors) { 15631da177e4SLinus Torvalds print STDERR "$errors errors\n"; 15641da177e4SLinus Torvalds} 15651da177e4SLinus Torvaldsif ($verbose && $warnings) { 15661da177e4SLinus Torvalds print STDERR "$warnings warnings\n"; 15671da177e4SLinus Torvalds} 15681da177e4SLinus Torvalds 15691da177e4SLinus Torvaldsexit($errors); 15701da177e4SLinus Torvalds 15711da177e4SLinus Torvaldssub reset_state { 15721da177e4SLinus Torvalds $function = ""; 15731da177e4SLinus Torvalds %constants = (); 15741da177e4SLinus Torvalds %parameterdescs = (); 15751da177e4SLinus Torvalds %parametertypes = (); 15761da177e4SLinus Torvalds @parameterlist = (); 15771da177e4SLinus Torvalds %sections = (); 15781da177e4SLinus Torvalds @sectionlist = (); 15791da177e4SLinus Torvalds $prototype = ""; 15801da177e4SLinus Torvalds 15811da177e4SLinus Torvalds $state = 0; 15821da177e4SLinus Torvalds} 15831da177e4SLinus Torvalds 15841da177e4SLinus Torvaldssub process_state3_function($$) { 15851da177e4SLinus Torvalds my $x = shift; 15861da177e4SLinus Torvalds my $file = shift; 15871da177e4SLinus Torvalds 15881da177e4SLinus Torvalds if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#define/)) { 15891da177e4SLinus Torvalds # do nothing 15901da177e4SLinus Torvalds } 15911da177e4SLinus Torvalds elsif ($x =~ /([^\{]*)/) { 15921da177e4SLinus Torvalds $prototype .= $1; 15931da177e4SLinus Torvalds } 15941da177e4SLinus Torvalds if (($x =~ /\{/) || ($x =~ /\#define/) || ($x =~ /;/)) { 15951da177e4SLinus Torvalds $prototype =~ s@/\*.*?\*/@@gos; # strip comments. 15961da177e4SLinus Torvalds $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 15971da177e4SLinus Torvalds $prototype =~ s@^\s+@@gos; # strip leading spaces 15981da177e4SLinus Torvalds dump_function($prototype,$file); 15991da177e4SLinus Torvalds reset_state(); 16001da177e4SLinus Torvalds } 16011da177e4SLinus Torvalds} 16021da177e4SLinus Torvalds 16031da177e4SLinus Torvaldssub process_state3_type($$) { 16041da177e4SLinus Torvalds my $x = shift; 16051da177e4SLinus Torvalds my $file = shift; 16061da177e4SLinus Torvalds 16071da177e4SLinus Torvalds $x =~ s@/\*.*?\*/@@gos; # strip comments. 16081da177e4SLinus Torvalds $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 16091da177e4SLinus Torvalds $x =~ s@^\s+@@gos; # strip leading spaces 16101da177e4SLinus Torvalds $x =~ s@\s+$@@gos; # strip trailing spaces 16111da177e4SLinus Torvalds if ($x =~ /^#/) { 16121da177e4SLinus Torvalds # To distinguish preprocessor directive from regular declaration later. 16131da177e4SLinus Torvalds $x .= ";"; 16141da177e4SLinus Torvalds } 16151da177e4SLinus Torvalds 16161da177e4SLinus Torvalds while (1) { 16171da177e4SLinus Torvalds if ( $x =~ /([^{};]*)([{};])(.*)/ ) { 16181da177e4SLinus Torvalds $prototype .= $1 . $2; 16191da177e4SLinus Torvalds ($2 eq '{') && $brcount++; 16201da177e4SLinus Torvalds ($2 eq '}') && $brcount--; 16211da177e4SLinus Torvalds if (($2 eq ';') && ($brcount == 0)) { 16221da177e4SLinus Torvalds dump_declaration($prototype,$file); 16231da177e4SLinus Torvalds reset_state(); 16241da177e4SLinus Torvalds last; 16251da177e4SLinus Torvalds } 16261da177e4SLinus Torvalds $x = $3; 16271da177e4SLinus Torvalds } else { 16281da177e4SLinus Torvalds $prototype .= $x; 16291da177e4SLinus Torvalds last; 16301da177e4SLinus Torvalds } 16311da177e4SLinus Torvalds } 16321da177e4SLinus Torvalds} 16331da177e4SLinus Torvalds 16341da177e4SLinus Torvalds# replace <, >, and & 16351da177e4SLinus Torvaldssub xml_escape($) { 16361da177e4SLinus Torvalds my $text = shift; 16371da177e4SLinus Torvalds $text =~ s/\&/\\\\\\amp;/g; 16381da177e4SLinus Torvalds $text =~ s/\</\\\\\\lt;/g; 16391da177e4SLinus Torvalds $text =~ s/\>/\\\\\\gt;/g; 16401da177e4SLinus Torvalds return $text; 16411da177e4SLinus Torvalds} 16421da177e4SLinus Torvalds 16431da177e4SLinus Torvaldssub process_file($) { 16441da177e4SLinus Torvalds my ($file) = "$ENV{'SRCTREE'}@_"; 16451da177e4SLinus Torvalds my $identifier; 16461da177e4SLinus Torvalds my $func; 16471da177e4SLinus Torvalds my $initial_section_counter = $section_counter; 16481da177e4SLinus Torvalds 16491da177e4SLinus Torvalds if (defined($source_map{$file})) { 16501da177e4SLinus Torvalds $file = $source_map{$file}; 16511da177e4SLinus Torvalds } 16521da177e4SLinus Torvalds 16531da177e4SLinus Torvalds if (!open(IN,"<$file")) { 16541da177e4SLinus Torvalds print STDERR "Error: Cannot open file $file\n"; 16551da177e4SLinus Torvalds ++$errors; 16561da177e4SLinus Torvalds return; 16571da177e4SLinus Torvalds } 16581da177e4SLinus Torvalds 16591da177e4SLinus Torvalds $section_counter = 0; 16601da177e4SLinus Torvalds while (<IN>) { 16611da177e4SLinus Torvalds if ($state == 0) { 16621da177e4SLinus Torvalds if (/$doc_start/o) { 16631da177e4SLinus Torvalds $state = 1; # next line is always the function name 16641da177e4SLinus Torvalds } 16651da177e4SLinus Torvalds } elsif ($state == 1) { # this line is the function name (always) 16661da177e4SLinus Torvalds if (/$doc_block/o) { 16671da177e4SLinus Torvalds $state = 4; 16681da177e4SLinus Torvalds $contents = ""; 16691da177e4SLinus Torvalds if ( $1 eq "" ) { 16701da177e4SLinus Torvalds $section = $section_intro; 16711da177e4SLinus Torvalds } else { 16721da177e4SLinus Torvalds $section = $1; 16731da177e4SLinus Torvalds } 16741da177e4SLinus Torvalds } 16751da177e4SLinus Torvalds elsif (/$doc_decl/o) { 16761da177e4SLinus Torvalds $identifier = $1; 16771da177e4SLinus Torvalds if (/\s*([\w\s]+?)\s*-/) { 16781da177e4SLinus Torvalds $identifier = $1; 16791da177e4SLinus Torvalds } 16801da177e4SLinus Torvalds 16811da177e4SLinus Torvalds $state = 2; 16821da177e4SLinus Torvalds if (/-(.*)/) { 16831da177e4SLinus Torvalds $declaration_purpose = xml_escape($1); 16841da177e4SLinus Torvalds } else { 16851da177e4SLinus Torvalds $declaration_purpose = ""; 16861da177e4SLinus Torvalds } 16871da177e4SLinus Torvalds if ($identifier =~ m/^struct/) { 16881da177e4SLinus Torvalds $decl_type = 'struct'; 16891da177e4SLinus Torvalds } elsif ($identifier =~ m/^union/) { 16901da177e4SLinus Torvalds $decl_type = 'union'; 16911da177e4SLinus Torvalds } elsif ($identifier =~ m/^enum/) { 16921da177e4SLinus Torvalds $decl_type = 'enum'; 16931da177e4SLinus Torvalds } elsif ($identifier =~ m/^typedef/) { 16941da177e4SLinus Torvalds $decl_type = 'typedef'; 16951da177e4SLinus Torvalds } else { 16961da177e4SLinus Torvalds $decl_type = 'function'; 16971da177e4SLinus Torvalds } 16981da177e4SLinus Torvalds 16991da177e4SLinus Torvalds if ($verbose) { 17001da177e4SLinus Torvalds print STDERR "Info(${file}:$.): Scanning doc for $identifier\n"; 17011da177e4SLinus Torvalds } 17021da177e4SLinus Torvalds } else { 17031da177e4SLinus Torvalds print STDERR "Warning(${file}:$.): Cannot understand $_ on line $.", 17041da177e4SLinus Torvalds " - I thought it was a doc line\n"; 17051da177e4SLinus Torvalds ++$warnings; 17061da177e4SLinus Torvalds $state = 0; 17071da177e4SLinus Torvalds } 17081da177e4SLinus Torvalds } elsif ($state == 2) { # look for head: lines, and include content 17091da177e4SLinus Torvalds if (/$doc_sect/o) { 17101da177e4SLinus Torvalds $newsection = $1; 17111da177e4SLinus Torvalds $newcontents = $2; 17121da177e4SLinus Torvalds 17131da177e4SLinus Torvalds if ($contents ne "") { 17141da177e4SLinus Torvalds dump_section($section, xml_escape($contents)); 17151da177e4SLinus Torvalds $section = $section_default; 17161da177e4SLinus Torvalds } 17171da177e4SLinus Torvalds 17181da177e4SLinus Torvalds $contents = $newcontents; 17191da177e4SLinus Torvalds if ($contents ne "") { 17201da177e4SLinus Torvalds $contents .= "\n"; 17211da177e4SLinus Torvalds } 17221da177e4SLinus Torvalds $section = $newsection; 17231da177e4SLinus Torvalds } elsif (/$doc_end/) { 17241da177e4SLinus Torvalds 17251da177e4SLinus Torvalds if ($contents ne "") { 17261da177e4SLinus Torvalds dump_section($section, xml_escape($contents)); 17271da177e4SLinus Torvalds $section = $section_default; 17281da177e4SLinus Torvalds $contents = ""; 17291da177e4SLinus Torvalds } 17301da177e4SLinus Torvalds 17311da177e4SLinus Torvalds $prototype = ""; 17321da177e4SLinus Torvalds $state = 3; 17331da177e4SLinus Torvalds $brcount = 0; 17341da177e4SLinus Torvalds# print STDERR "end of doc comment, looking for prototype\n"; 17351da177e4SLinus Torvalds } elsif (/$doc_content/) { 17361da177e4SLinus Torvalds # miguel-style comment kludge, look for blank lines after 17371da177e4SLinus Torvalds # @parameter line to signify start of description 17381da177e4SLinus Torvalds if ($1 eq "" && 17391da177e4SLinus Torvalds ($section =~ m/^@/ || $section eq $section_context)) { 17401da177e4SLinus Torvalds dump_section($section, xml_escape($contents)); 17411da177e4SLinus Torvalds $section = $section_default; 17421da177e4SLinus Torvalds $contents = ""; 17431da177e4SLinus Torvalds } else { 17441da177e4SLinus Torvalds $contents .= $1."\n"; 17451da177e4SLinus Torvalds } 17461da177e4SLinus Torvalds } else { 17471da177e4SLinus Torvalds # i dont know - bad line? ignore. 17481da177e4SLinus Torvalds print STDERR "Warning(${file}:$.): bad line: $_"; 17491da177e4SLinus Torvalds ++$warnings; 17501da177e4SLinus Torvalds } 17511da177e4SLinus Torvalds } elsif ($state == 3) { # scanning for function { (end of prototype) 17521da177e4SLinus Torvalds if ($decl_type eq 'function') { 17531da177e4SLinus Torvalds process_state3_function($_, $file); 17541da177e4SLinus Torvalds } else { 17551da177e4SLinus Torvalds process_state3_type($_, $file); 17561da177e4SLinus Torvalds } 17571da177e4SLinus Torvalds } elsif ($state == 4) { 17581da177e4SLinus Torvalds # Documentation block 17591da177e4SLinus Torvalds if (/$doc_block/) { 17601da177e4SLinus Torvalds dump_section($section, $contents); 17611da177e4SLinus Torvalds output_intro({'sectionlist' => \@sectionlist, 17621da177e4SLinus Torvalds 'sections' => \%sections }); 17631da177e4SLinus Torvalds $contents = ""; 17641da177e4SLinus Torvalds $function = ""; 17651da177e4SLinus Torvalds %constants = (); 17661da177e4SLinus Torvalds %parameterdescs = (); 17671da177e4SLinus Torvalds %parametertypes = (); 17681da177e4SLinus Torvalds @parameterlist = (); 17691da177e4SLinus Torvalds %sections = (); 17701da177e4SLinus Torvalds @sectionlist = (); 17711da177e4SLinus Torvalds $prototype = ""; 17721da177e4SLinus Torvalds if ( $1 eq "" ) { 17731da177e4SLinus Torvalds $section = $section_intro; 17741da177e4SLinus Torvalds } else { 17751da177e4SLinus Torvalds $section = $1; 17761da177e4SLinus Torvalds } 17771da177e4SLinus Torvalds } 17781da177e4SLinus Torvalds elsif (/$doc_end/) 17791da177e4SLinus Torvalds { 17801da177e4SLinus Torvalds dump_section($section, $contents); 17811da177e4SLinus Torvalds output_intro({'sectionlist' => \@sectionlist, 17821da177e4SLinus Torvalds 'sections' => \%sections }); 17831da177e4SLinus Torvalds $contents = ""; 17841da177e4SLinus Torvalds $function = ""; 17851da177e4SLinus Torvalds %constants = (); 17861da177e4SLinus Torvalds %parameterdescs = (); 17871da177e4SLinus Torvalds %parametertypes = (); 17881da177e4SLinus Torvalds @parameterlist = (); 17891da177e4SLinus Torvalds %sections = (); 17901da177e4SLinus Torvalds @sectionlist = (); 17911da177e4SLinus Torvalds $prototype = ""; 17921da177e4SLinus Torvalds $state = 0; 17931da177e4SLinus Torvalds } 17941da177e4SLinus Torvalds elsif (/$doc_content/) 17951da177e4SLinus Torvalds { 17961da177e4SLinus Torvalds if ( $1 eq "" ) 17971da177e4SLinus Torvalds { 17981da177e4SLinus Torvalds $contents .= $blankline; 17991da177e4SLinus Torvalds } 18001da177e4SLinus Torvalds else 18011da177e4SLinus Torvalds { 18021da177e4SLinus Torvalds $contents .= $1 . "\n"; 18031da177e4SLinus Torvalds } 18041da177e4SLinus Torvalds } 18051da177e4SLinus Torvalds } 18061da177e4SLinus Torvalds } 18071da177e4SLinus Torvalds if ($initial_section_counter == $section_counter) { 18081da177e4SLinus Torvalds print STDERR "Warning(${file}): no structured comments found\n"; 18091da177e4SLinus Torvalds if ($output_mode eq "xml") { 18101da177e4SLinus Torvalds # The template wants at least one RefEntry here; make one. 18111da177e4SLinus Torvalds print "<refentry>\n"; 18121da177e4SLinus Torvalds print " <refnamediv>\n"; 18131da177e4SLinus Torvalds print " <refname>\n"; 18141da177e4SLinus Torvalds print " ${file}\n"; 18151da177e4SLinus Torvalds print " </refname>\n"; 18161da177e4SLinus Torvalds print " <refpurpose>\n"; 18171da177e4SLinus Torvalds print " Document generation inconsistency\n"; 18181da177e4SLinus Torvalds print " </refpurpose>\n"; 18191da177e4SLinus Torvalds print " </refnamediv>\n"; 18201da177e4SLinus Torvalds print " <refsect1>\n"; 18211da177e4SLinus Torvalds print " <title>\n"; 18221da177e4SLinus Torvalds print " Oops\n"; 18231da177e4SLinus Torvalds print " </title>\n"; 18241da177e4SLinus Torvalds print " <warning>\n"; 18251da177e4SLinus Torvalds print " <para>\n"; 18261da177e4SLinus Torvalds print " The template for this document tried to insert\n"; 18271da177e4SLinus Torvalds print " the structured comment from the file\n"; 18281da177e4SLinus Torvalds print " <filename>${file}</filename> at this point,\n"; 18291da177e4SLinus Torvalds print " but none was found.\n"; 18301da177e4SLinus Torvalds print " This dummy section is inserted to allow\n"; 18311da177e4SLinus Torvalds print " generation to continue.\n"; 18321da177e4SLinus Torvalds print " </para>\n"; 18331da177e4SLinus Torvalds print " </warning>\n"; 18341da177e4SLinus Torvalds print " </refsect1>\n"; 18351da177e4SLinus Torvalds print "</refentry>\n"; 18361da177e4SLinus Torvalds } 18371da177e4SLinus Torvalds } 18381da177e4SLinus Torvalds} 1839