kernel-doc 84 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015
  1. #!/usr/bin/perl -w
  2. use strict;
  3. ## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ##
  4. ## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ##
  5. ## Copyright (C) 2001 Simon Huggins ##
  6. ## Copyright (C) 2005-2012 Randy Dunlap ##
  7. ## Copyright (C) 2012 Dan Luedtke ##
  8. ## ##
  9. ## #define enhancements by Armin Kuster <akuster@mvista.com> ##
  10. ## Copyright (c) 2000 MontaVista Software, Inc. ##
  11. ## ##
  12. ## This software falls under the GNU General Public License. ##
  13. ## Please read the COPYING file for more information ##
  14. # 18/01/2001 - Cleanups
  15. # Functions prototyped as foo(void) same as foo()
  16. # Stop eval'ing where we don't need to.
  17. # -- huggie@earth.li
  18. # 27/06/2001 - Allowed whitespace after initial "/**" and
  19. # allowed comments before function declarations.
  20. # -- Christian Kreibich <ck@whoop.org>
  21. # Still to do:
  22. # - add perldoc documentation
  23. # - Look more closely at some of the scarier bits :)
  24. # 26/05/2001 - Support for separate source and object trees.
  25. # Return error code.
  26. # Keith Owens <kaos@ocs.com.au>
  27. # 23/09/2001 - Added support for typedefs, structs, enums and unions
  28. # Support for Context section; can be terminated using empty line
  29. # Small fixes (like spaces vs. \s in regex)
  30. # -- Tim Jansen <tim@tjansen.de>
  31. # 25/07/2012 - Added support for HTML5
  32. # -- Dan Luedtke <mail@danrl.de>
  33. sub usage {
  34. my $message = <<"EOF";
  35. Usage: $0 [OPTION ...] FILE ...
  36. Read C language source or header FILEs, extract embedded documentation comments,
  37. and print formatted documentation to standard output.
  38. The documentation comments are identified by "/**" opening comment mark. See
  39. Documentation/kernel-doc-nano-HOWTO.txt for the documentation comment syntax.
  40. Output format selection (mutually exclusive):
  41. -docbook Output DocBook format.
  42. -html Output HTML format.
  43. -html5 Output HTML5 format.
  44. -list Output symbol list format. This is for use by docproc.
  45. -man Output troff manual page format. This is the default.
  46. -rst Output reStructuredText format.
  47. -text Output plain text format.
  48. Output selection (mutually exclusive):
  49. -export Only output documentation for symbols that have been
  50. exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL()
  51. in the same FILE.
  52. -internal Only output documentation for symbols that have NOT been
  53. exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL()
  54. in the same FILE.
  55. -function NAME Only output documentation for the given function(s)
  56. or DOC: section title(s). All other functions and DOC:
  57. sections are ignored. May be specified multiple times.
  58. -nofunction NAME Do NOT output documentation for the given function(s);
  59. only output documentation for the other functions and
  60. DOC: sections. May be specified multiple times.
  61. Output selection modifiers:
  62. -no-doc-sections Do not output DOC: sections.
  63. Other parameters:
  64. -v Verbose output, more warnings and other information.
  65. -h Print this help.
  66. EOF
  67. print $message;
  68. exit 1;
  69. }
  70. #
  71. # format of comments.
  72. # In the following table, (...)? signifies optional structure.
  73. # (...)* signifies 0 or more structure elements
  74. # /**
  75. # * function_name(:)? (- short description)?
  76. # (* @parameterx: (description of parameter x)?)*
  77. # (* a blank line)?
  78. # * (Description:)? (Description of function)?
  79. # * (section header: (section description)? )*
  80. # (*)?*/
  81. #
  82. # So .. the trivial example would be:
  83. #
  84. # /**
  85. # * my_function
  86. # */
  87. #
  88. # If the Description: header tag is omitted, then there must be a blank line
  89. # after the last parameter specification.
  90. # e.g.
  91. # /**
  92. # * my_function - does my stuff
  93. # * @my_arg: its mine damnit
  94. # *
  95. # * Does my stuff explained.
  96. # */
  97. #
  98. # or, could also use:
  99. # /**
  100. # * my_function - does my stuff
  101. # * @my_arg: its mine damnit
  102. # * Description: Does my stuff explained.
  103. # */
  104. # etc.
  105. #
  106. # Besides functions you can also write documentation for structs, unions,
  107. # enums and typedefs. Instead of the function name you must write the name
  108. # of the declaration; the struct/union/enum/typedef must always precede
  109. # the name. Nesting of declarations is not supported.
  110. # Use the argument mechanism to document members or constants.
  111. # e.g.
  112. # /**
  113. # * struct my_struct - short description
  114. # * @a: first member
  115. # * @b: second member
  116. # *
  117. # * Longer description
  118. # */
  119. # struct my_struct {
  120. # int a;
  121. # int b;
  122. # /* private: */
  123. # int c;
  124. # };
  125. #
  126. # All descriptions can be multiline, except the short function description.
  127. #
  128. # For really longs structs, you can also describe arguments inside the
  129. # body of the struct.
  130. # eg.
  131. # /**
  132. # * struct my_struct - short description
  133. # * @a: first member
  134. # * @b: second member
  135. # *
  136. # * Longer description
  137. # */
  138. # struct my_struct {
  139. # int a;
  140. # int b;
  141. # /**
  142. # * @c: This is longer description of C
  143. # *
  144. # * You can use paragraphs to describe arguments
  145. # * using this method.
  146. # */
  147. # int c;
  148. # };
  149. #
  150. # This should be use only for struct/enum members.
  151. #
  152. # You can also add additional sections. When documenting kernel functions you
  153. # should document the "Context:" of the function, e.g. whether the functions
  154. # can be called form interrupts. Unlike other sections you can end it with an
  155. # empty line.
  156. # A non-void function should have a "Return:" section describing the return
  157. # value(s).
  158. # Example-sections should contain the string EXAMPLE so that they are marked
  159. # appropriately in DocBook.
  160. #
  161. # Example:
  162. # /**
  163. # * user_function - function that can only be called in user context
  164. # * @a: some argument
  165. # * Context: !in_interrupt()
  166. # *
  167. # * Some description
  168. # * Example:
  169. # * user_function(22);
  170. # */
  171. # ...
  172. #
  173. #
  174. # All descriptive text is further processed, scanning for the following special
  175. # patterns, which are highlighted appropriately.
  176. #
  177. # 'funcname()' - function
  178. # '$ENVVAR' - environmental variable
  179. # '&struct_name' - name of a structure (up to two words including 'struct')
  180. # '@parameter' - name of a parameter
  181. # '%CONST' - name of a constant.
  182. ## init lots of data
  183. my $errors = 0;
  184. my $warnings = 0;
  185. my $anon_struct_union = 0;
  186. # match expressions used to find embedded type information
  187. my $type_constant = '\%([-_\w]+)';
  188. my $type_func = '(\w+)\(\)';
  189. my $type_param = '\@(\w+)';
  190. my $type_struct = '\&((struct\s*)*[_\w]+)';
  191. my $type_struct_xml = '\\&amp;((struct\s*)*[_\w]+)';
  192. my $type_env = '(\$\w+)';
  193. my $type_enum_full = '\&(enum)\s*([_\w]+)';
  194. my $type_struct_full = '\&(struct)\s*([_\w]+)';
  195. # Output conversion substitutions.
  196. # One for each output format
  197. # these work fairly well
  198. my @highlights_html = (
  199. [$type_constant, "<i>\$1</i>"],
  200. [$type_func, "<b>\$1</b>"],
  201. [$type_struct_xml, "<i>\$1</i>"],
  202. [$type_env, "<b><i>\$1</i></b>"],
  203. [$type_param, "<tt><b>\$1</b></tt>"]
  204. );
  205. my $local_lt = "\\\\\\\\lt:";
  206. my $local_gt = "\\\\\\\\gt:";
  207. my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>"
  208. # html version 5
  209. my @highlights_html5 = (
  210. [$type_constant, "<span class=\"const\">\$1</span>"],
  211. [$type_func, "<span class=\"func\">\$1</span>"],
  212. [$type_struct_xml, "<span class=\"struct\">\$1</span>"],
  213. [$type_env, "<span class=\"env\">\$1</span>"],
  214. [$type_param, "<span class=\"param\">\$1</span>]"]
  215. );
  216. my $blankline_html5 = $local_lt . "br /" . $local_gt;
  217. # XML, docbook format
  218. my @highlights_xml = (
  219. ["([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>"],
  220. [$type_constant, "<constant>\$1</constant>"],
  221. [$type_struct_xml, "<structname>\$1</structname>"],
  222. [$type_param, "<parameter>\$1</parameter>"],
  223. [$type_func, "<function>\$1</function>"],
  224. [$type_env, "<envar>\$1</envar>"]
  225. );
  226. my $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n";
  227. # gnome, docbook format
  228. my @highlights_gnome = (
  229. [$type_constant, "<replaceable class=\"option\">\$1</replaceable>"],
  230. [$type_func, "<function>\$1</function>"],
  231. [$type_struct, "<structname>\$1</structname>"],
  232. [$type_env, "<envar>\$1</envar>"],
  233. [$type_param, "<parameter>\$1</parameter>" ]
  234. );
  235. my $blankline_gnome = "</para><para>\n";
  236. # these are pretty rough
  237. my @highlights_man = (
  238. [$type_constant, "\$1"],
  239. [$type_func, "\\\\fB\$1\\\\fP"],
  240. [$type_struct, "\\\\fI\$1\\\\fP"],
  241. [$type_param, "\\\\fI\$1\\\\fP"]
  242. );
  243. my $blankline_man = "";
  244. # text-mode
  245. my @highlights_text = (
  246. [$type_constant, "\$1"],
  247. [$type_func, "\$1"],
  248. [$type_struct, "\$1"],
  249. [$type_param, "\$1"]
  250. );
  251. my $blankline_text = "";
  252. # rst-mode
  253. my @highlights_rst = (
  254. [$type_constant, "``\$1``"],
  255. [$type_func, "\\:c\\:func\\:`\$1`"],
  256. [$type_struct_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
  257. [$type_enum_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
  258. [$type_struct, "\\:c\\:type\\:`struct \$1 <\$1>`"],
  259. [$type_param, "**\$1**"]
  260. );
  261. my $blankline_rst = "\n";
  262. # list mode
  263. my @highlights_list = (
  264. [$type_constant, "\$1"],
  265. [$type_func, "\$1"],
  266. [$type_struct, "\$1"],
  267. [$type_param, "\$1"]
  268. );
  269. my $blankline_list = "";
  270. # read arguments
  271. if ($#ARGV == -1) {
  272. usage();
  273. }
  274. my $kernelversion;
  275. my $dohighlight = "";
  276. my $verbose = 0;
  277. my $output_mode = "man";
  278. my $output_preformatted = 0;
  279. my $no_doc_sections = 0;
  280. my @highlights = @highlights_man;
  281. my $blankline = $blankline_man;
  282. my $modulename = "Kernel API";
  283. use constant {
  284. OUTPUT_ALL => 0, # output all symbols and doc sections
  285. OUTPUT_INCLUDE => 1, # output only specified symbols
  286. OUTPUT_EXCLUDE => 2, # output everything except specified symbols
  287. OUTPUT_EXPORTED => 3, # output exported symbols
  288. OUTPUT_INTERNAL => 4, # output non-exported symbols
  289. };
  290. my $output_selection = OUTPUT_ALL;
  291. my $show_not_found = 0;
  292. my @build_time;
  293. if (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) &&
  294. (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') {
  295. @build_time = gmtime($seconds);
  296. } else {
  297. @build_time = localtime;
  298. }
  299. my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
  300. 'July', 'August', 'September', 'October',
  301. 'November', 'December')[$build_time[4]] .
  302. " " . ($build_time[5]+1900);
  303. # Essentially these are globals.
  304. # They probably want to be tidied up, made more localised or something.
  305. # CAVEAT EMPTOR! Some of the others I localised may not want to be, which
  306. # could cause "use of undefined value" or other bugs.
  307. my ($function, %function_table, %parametertypes, $declaration_purpose);
  308. my ($type, $declaration_name, $return_type);
  309. my ($newsection, $newcontents, $prototype, $brcount, %source_map);
  310. if (defined($ENV{'KBUILD_VERBOSE'})) {
  311. $verbose = "$ENV{'KBUILD_VERBOSE'}";
  312. }
  313. # Generated docbook code is inserted in a template at a point where
  314. # docbook v3.1 requires a non-zero sequence of RefEntry's; see:
  315. # http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
  316. # We keep track of number of generated entries and generate a dummy
  317. # if needs be to ensure the expanded template can be postprocessed
  318. # into html.
  319. my $section_counter = 0;
  320. my $lineprefix="";
  321. # Parser states
  322. use constant {
  323. STATE_NORMAL => 0, # normal code
  324. STATE_NAME => 1, # looking for function name
  325. STATE_FIELD => 2, # scanning field start
  326. STATE_PROTO => 3, # scanning prototype
  327. STATE_DOCBLOCK => 4, # documentation block
  328. STATE_INLINE => 5, # gathering documentation outside main block
  329. };
  330. my $state;
  331. my $in_doc_sect;
  332. # Inline documentation state
  333. use constant {
  334. STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE)
  335. STATE_INLINE_NAME => 1, # looking for member name (@foo:)
  336. STATE_INLINE_TEXT => 2, # looking for member documentation
  337. STATE_INLINE_END => 3, # done
  338. STATE_INLINE_ERROR => 4, # error - Comment without header was found.
  339. # Spit a warning as it's not
  340. # proper kernel-doc and ignore the rest.
  341. };
  342. my $inline_doc_state;
  343. #declaration types: can be
  344. # 'function', 'struct', 'union', 'enum', 'typedef'
  345. my $decl_type;
  346. my $doc_special = "\@\%\$\&";
  347. my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
  348. my $doc_end = '\*/';
  349. my $doc_com = '\s*\*\s*';
  350. my $doc_com_body = '\s*\* ?';
  351. my $doc_decl = $doc_com . '(\w+)';
  352. my $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)';
  353. my $doc_content = $doc_com_body . '(.*)';
  354. my $doc_block = $doc_com . 'DOC:\s*(.*)?';
  355. my $doc_inline_start = '^\s*/\*\*\s*$';
  356. my $doc_inline_sect = '\s*\*\s*(@[\w\s]+):(.*)';
  357. my $doc_inline_end = '^\s*\*/\s*$';
  358. my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;';
  359. my %constants;
  360. my %parameterdescs;
  361. my @parameterlist;
  362. my %sections;
  363. my @sectionlist;
  364. my $sectcheck;
  365. my $struct_actual;
  366. my $contents = "";
  367. my $section_default = "Description"; # default section
  368. my $section_intro = "Introduction";
  369. my $section = $section_default;
  370. my $section_context = "Context";
  371. my $section_return = "Return";
  372. my $undescribed = "-- undescribed --";
  373. reset_state();
  374. while ($ARGV[0] =~ m/^-(.*)/) {
  375. my $cmd = shift @ARGV;
  376. if ($cmd eq "-html") {
  377. $output_mode = "html";
  378. @highlights = @highlights_html;
  379. $blankline = $blankline_html;
  380. } elsif ($cmd eq "-html5") {
  381. $output_mode = "html5";
  382. @highlights = @highlights_html5;
  383. $blankline = $blankline_html5;
  384. } elsif ($cmd eq "-man") {
  385. $output_mode = "man";
  386. @highlights = @highlights_man;
  387. $blankline = $blankline_man;
  388. } elsif ($cmd eq "-text") {
  389. $output_mode = "text";
  390. @highlights = @highlights_text;
  391. $blankline = $blankline_text;
  392. } elsif ($cmd eq "-rst") {
  393. $output_mode = "rst";
  394. @highlights = @highlights_rst;
  395. $blankline = $blankline_rst;
  396. } elsif ($cmd eq "-docbook") {
  397. $output_mode = "xml";
  398. @highlights = @highlights_xml;
  399. $blankline = $blankline_xml;
  400. } elsif ($cmd eq "-list") {
  401. $output_mode = "list";
  402. @highlights = @highlights_list;
  403. $blankline = $blankline_list;
  404. } elsif ($cmd eq "-gnome") {
  405. $output_mode = "gnome";
  406. @highlights = @highlights_gnome;
  407. $blankline = $blankline_gnome;
  408. } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
  409. $modulename = shift @ARGV;
  410. } elsif ($cmd eq "-function") { # to only output specific functions
  411. $output_selection = OUTPUT_INCLUDE;
  412. $function = shift @ARGV;
  413. $function_table{$function} = 1;
  414. } elsif ($cmd eq "-nofunction") { # output all except specific functions
  415. $output_selection = OUTPUT_EXCLUDE;
  416. $function = shift @ARGV;
  417. $function_table{$function} = 1;
  418. } elsif ($cmd eq "-export") { # only exported symbols
  419. $output_selection = OUTPUT_EXPORTED;
  420. %function_table = ()
  421. } elsif ($cmd eq "-internal") { # only non-exported symbols
  422. $output_selection = OUTPUT_INTERNAL;
  423. %function_table = ()
  424. } elsif ($cmd eq "-v") {
  425. $verbose = 1;
  426. } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
  427. usage();
  428. } elsif ($cmd eq '-no-doc-sections') {
  429. $no_doc_sections = 1;
  430. } elsif ($cmd eq '-show-not-found') {
  431. $show_not_found = 1;
  432. }
  433. }
  434. # continue execution near EOF;
  435. # get kernel version from env
  436. sub get_kernel_version() {
  437. my $version = 'unknown kernel version';
  438. if (defined($ENV{'KERNELVERSION'})) {
  439. $version = $ENV{'KERNELVERSION'};
  440. }
  441. return $version;
  442. }
  443. ##
  444. # dumps section contents to arrays/hashes intended for that purpose.
  445. #
  446. sub dump_section {
  447. my $file = shift;
  448. my $name = shift;
  449. my $contents = join "\n", @_;
  450. if ($name =~ m/$type_constant/) {
  451. $name = $1;
  452. # print STDERR "constant section '$1' = '$contents'\n";
  453. $constants{$name} = $contents;
  454. } elsif ($name =~ m/$type_param/) {
  455. # print STDERR "parameter def '$1' = '$contents'\n";
  456. $name = $1;
  457. $parameterdescs{$name} = $contents;
  458. $sectcheck = $sectcheck . $name . " ";
  459. } elsif ($name eq "@\.\.\.") {
  460. # print STDERR "parameter def '...' = '$contents'\n";
  461. $name = "...";
  462. $parameterdescs{$name} = $contents;
  463. $sectcheck = $sectcheck . $name . " ";
  464. } else {
  465. # print STDERR "other section '$name' = '$contents'\n";
  466. if (defined($sections{$name}) && ($sections{$name} ne "")) {
  467. print STDERR "${file}:$.: error: duplicate section name '$name'\n";
  468. ++$errors;
  469. }
  470. $sections{$name} = $contents;
  471. push @sectionlist, $name;
  472. }
  473. }
  474. ##
  475. # dump DOC: section after checking that it should go out
  476. #
  477. sub dump_doc_section {
  478. my $file = shift;
  479. my $name = shift;
  480. my $contents = join "\n", @_;
  481. if ($no_doc_sections) {
  482. return;
  483. }
  484. if (($output_selection == OUTPUT_ALL) ||
  485. ($output_selection == OUTPUT_INCLUDE &&
  486. defined($function_table{$name})) ||
  487. ($output_selection == OUTPUT_EXCLUDE &&
  488. !defined($function_table{$name})))
  489. {
  490. dump_section($file, $name, $contents);
  491. output_blockhead({'sectionlist' => \@sectionlist,
  492. 'sections' => \%sections,
  493. 'module' => $modulename,
  494. 'content-only' => ($output_selection != OUTPUT_ALL), });
  495. }
  496. }
  497. ##
  498. # output function
  499. #
  500. # parameterdescs, a hash.
  501. # function => "function name"
  502. # parameterlist => @list of parameters
  503. # parameterdescs => %parameter descriptions
  504. # sectionlist => @list of sections
  505. # sections => %section descriptions
  506. #
  507. sub output_highlight {
  508. my $contents = join "\n",@_;
  509. my $line;
  510. # DEBUG
  511. # if (!defined $contents) {
  512. # use Carp;
  513. # confess "output_highlight got called with no args?\n";
  514. # }
  515. if ($output_mode eq "html" || $output_mode eq "html5" ||
  516. $output_mode eq "xml") {
  517. $contents = local_unescape($contents);
  518. # convert data read & converted thru xml_escape() into &xyz; format:
  519. $contents =~ s/\\\\\\/\&/g;
  520. }
  521. # print STDERR "contents b4:$contents\n";
  522. eval $dohighlight;
  523. die $@ if $@;
  524. # print STDERR "contents af:$contents\n";
  525. # strip whitespaces when generating html5
  526. if ($output_mode eq "html5") {
  527. $contents =~ s/^\s+//;
  528. $contents =~ s/\s+$//;
  529. }
  530. foreach $line (split "\n", $contents) {
  531. if (! $output_preformatted) {
  532. $line =~ s/^\s*//;
  533. }
  534. if ($line eq ""){
  535. if (! $output_preformatted) {
  536. print $lineprefix, local_unescape($blankline);
  537. }
  538. } else {
  539. $line =~ s/\\\\\\/\&/g;
  540. if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
  541. print "\\&$line";
  542. } else {
  543. print $lineprefix, $line;
  544. }
  545. }
  546. print "\n";
  547. }
  548. }
  549. # output sections in html
  550. sub output_section_html(%) {
  551. my %args = %{$_[0]};
  552. my $section;
  553. foreach $section (@{$args{'sectionlist'}}) {
  554. print "<h3>$section</h3>\n";
  555. print "<blockquote>\n";
  556. output_highlight($args{'sections'}{$section});
  557. print "</blockquote>\n";
  558. }
  559. }
  560. # output enum in html
  561. sub output_enum_html(%) {
  562. my %args = %{$_[0]};
  563. my ($parameter);
  564. my $count;
  565. print "<h2>enum " . $args{'enum'} . "</h2>\n";
  566. print "<b>enum " . $args{'enum'} . "</b> {<br>\n";
  567. $count = 0;
  568. foreach $parameter (@{$args{'parameterlist'}}) {
  569. print " <b>" . $parameter . "</b>";
  570. if ($count != $#{$args{'parameterlist'}}) {
  571. $count++;
  572. print ",\n";
  573. }
  574. print "<br>";
  575. }
  576. print "};<br>\n";
  577. print "<h3>Constants</h3>\n";
  578. print "<dl>\n";
  579. foreach $parameter (@{$args{'parameterlist'}}) {
  580. print "<dt><b>" . $parameter . "</b>\n";
  581. print "<dd>";
  582. output_highlight($args{'parameterdescs'}{$parameter});
  583. }
  584. print "</dl>\n";
  585. output_section_html(@_);
  586. print "<hr>\n";
  587. }
  588. # output typedef in html
  589. sub output_typedef_html(%) {
  590. my %args = %{$_[0]};
  591. my ($parameter);
  592. my $count;
  593. print "<h2>typedef " . $args{'typedef'} . "</h2>\n";
  594. print "<b>typedef " . $args{'typedef'} . "</b>\n";
  595. output_section_html(@_);
  596. print "<hr>\n";
  597. }
  598. # output struct in html
  599. sub output_struct_html(%) {
  600. my %args = %{$_[0]};
  601. my ($parameter);
  602. print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n";
  603. print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n";
  604. foreach $parameter (@{$args{'parameterlist'}}) {
  605. if ($parameter =~ /^#/) {
  606. print "$parameter<br>\n";
  607. next;
  608. }
  609. my $parameter_name = $parameter;
  610. $parameter_name =~ s/\[.*//;
  611. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  612. $type = $args{'parametertypes'}{$parameter};
  613. if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
  614. # pointer-to-function
  615. print "&nbsp; &nbsp; <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
  616. } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
  617. # bitfield
  618. print "&nbsp; &nbsp; <i>$1</i> <b>$parameter</b>$2;<br>\n";
  619. } else {
  620. print "&nbsp; &nbsp; <i>$type</i> <b>$parameter</b>;<br>\n";
  621. }
  622. }
  623. print "};<br>\n";
  624. print "<h3>Members</h3>\n";
  625. print "<dl>\n";
  626. foreach $parameter (@{$args{'parameterlist'}}) {
  627. ($parameter =~ /^#/) && next;
  628. my $parameter_name = $parameter;
  629. $parameter_name =~ s/\[.*//;
  630. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  631. print "<dt><b>" . $parameter . "</b>\n";
  632. print "<dd>";
  633. output_highlight($args{'parameterdescs'}{$parameter_name});
  634. }
  635. print "</dl>\n";
  636. output_section_html(@_);
  637. print "<hr>\n";
  638. }
  639. # output function in html
  640. sub output_function_html(%) {
  641. my %args = %{$_[0]};
  642. my ($parameter, $section);
  643. my $count;
  644. print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n";
  645. print "<i>" . $args{'functiontype'} . "</i>\n";
  646. print "<b>" . $args{'function'} . "</b>\n";
  647. print "(";
  648. $count = 0;
  649. foreach $parameter (@{$args{'parameterlist'}}) {
  650. $type = $args{'parametertypes'}{$parameter};
  651. if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
  652. # pointer-to-function
  653. print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
  654. } else {
  655. print "<i>" . $type . "</i> <b>" . $parameter . "</b>";
  656. }
  657. if ($count != $#{$args{'parameterlist'}}) {
  658. $count++;
  659. print ",\n";
  660. }
  661. }
  662. print ")\n";
  663. print "<h3>Arguments</h3>\n";
  664. print "<dl>\n";
  665. foreach $parameter (@{$args{'parameterlist'}}) {
  666. my $parameter_name = $parameter;
  667. $parameter_name =~ s/\[.*//;
  668. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  669. print "<dt><b>" . $parameter . "</b>\n";
  670. print "<dd>";
  671. output_highlight($args{'parameterdescs'}{$parameter_name});
  672. }
  673. print "</dl>\n";
  674. output_section_html(@_);
  675. print "<hr>\n";
  676. }
  677. # output DOC: block header in html
  678. sub output_blockhead_html(%) {
  679. my %args = %{$_[0]};
  680. my ($parameter, $section);
  681. my $count;
  682. foreach $section (@{$args{'sectionlist'}}) {
  683. print "<h3>$section</h3>\n";
  684. print "<ul>\n";
  685. output_highlight($args{'sections'}{$section});
  686. print "</ul>\n";
  687. }
  688. print "<hr>\n";
  689. }
  690. # output sections in html5
  691. sub output_section_html5(%) {
  692. my %args = %{$_[0]};
  693. my $section;
  694. foreach $section (@{$args{'sectionlist'}}) {
  695. print "<section>\n";
  696. print "<h1>$section</h1>\n";
  697. print "<p>\n";
  698. output_highlight($args{'sections'}{$section});
  699. print "</p>\n";
  700. print "</section>\n";
  701. }
  702. }
  703. # output enum in html5
  704. sub output_enum_html5(%) {
  705. my %args = %{$_[0]};
  706. my ($parameter);
  707. my $count;
  708. my $html5id;
  709. $html5id = $args{'enum'};
  710. $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
  711. print "<article class=\"enum\" id=\"enum:". $html5id . "\">";
  712. print "<h1>enum " . $args{'enum'} . "</h1>\n";
  713. print "<ol class=\"code\">\n";
  714. print "<li>";
  715. print "<span class=\"keyword\">enum</span> ";
  716. print "<span class=\"identifier\">" . $args{'enum'} . "</span> {";
  717. print "</li>\n";
  718. $count = 0;
  719. foreach $parameter (@{$args{'parameterlist'}}) {
  720. print "<li class=\"indent\">";
  721. print "<span class=\"param\">" . $parameter . "</span>";
  722. if ($count != $#{$args{'parameterlist'}}) {
  723. $count++;
  724. print ",";
  725. }
  726. print "</li>\n";
  727. }
  728. print "<li>};</li>\n";
  729. print "</ol>\n";
  730. print "<section>\n";
  731. print "<h1>Constants</h1>\n";
  732. print "<dl>\n";
  733. foreach $parameter (@{$args{'parameterlist'}}) {
  734. print "<dt>" . $parameter . "</dt>\n";
  735. print "<dd>";
  736. output_highlight($args{'parameterdescs'}{$parameter});
  737. print "</dd>\n";
  738. }
  739. print "</dl>\n";
  740. print "</section>\n";
  741. output_section_html5(@_);
  742. print "</article>\n";
  743. }
  744. # output typedef in html5
  745. sub output_typedef_html5(%) {
  746. my %args = %{$_[0]};
  747. my ($parameter);
  748. my $count;
  749. my $html5id;
  750. $html5id = $args{'typedef'};
  751. $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
  752. print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n";
  753. print "<h1>typedef " . $args{'typedef'} . "</h1>\n";
  754. print "<ol class=\"code\">\n";
  755. print "<li>";
  756. print "<span class=\"keyword\">typedef</span> ";
  757. print "<span class=\"identifier\">" . $args{'typedef'} . "</span>";
  758. print "</li>\n";
  759. print "</ol>\n";
  760. output_section_html5(@_);
  761. print "</article>\n";
  762. }
  763. # output struct in html5
  764. sub output_struct_html5(%) {
  765. my %args = %{$_[0]};
  766. my ($parameter);
  767. my $html5id;
  768. $html5id = $args{'struct'};
  769. $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
  770. print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n";
  771. print "<hgroup>\n";
  772. print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>";
  773. print "<h2>". $args{'purpose'} . "</h2>\n";
  774. print "</hgroup>\n";
  775. print "<ol class=\"code\">\n";
  776. print "<li>";
  777. print "<span class=\"type\">" . $args{'type'} . "</span> ";
  778. print "<span class=\"identifier\">" . $args{'struct'} . "</span> {";
  779. print "</li>\n";
  780. foreach $parameter (@{$args{'parameterlist'}}) {
  781. print "<li class=\"indent\">";
  782. if ($parameter =~ /^#/) {
  783. print "<span class=\"param\">" . $parameter ."</span>\n";
  784. print "</li>\n";
  785. next;
  786. }
  787. my $parameter_name = $parameter;
  788. $parameter_name =~ s/\[.*//;
  789. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  790. $type = $args{'parametertypes'}{$parameter};
  791. if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
  792. # pointer-to-function
  793. print "<span class=\"type\">$1</span> ";
  794. print "<span class=\"param\">$parameter</span>";
  795. print "<span class=\"type\">)</span> ";
  796. print "(<span class=\"args\">$2</span>);";
  797. } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
  798. # bitfield
  799. print "<span class=\"type\">$1</span> ";
  800. print "<span class=\"param\">$parameter</span>";
  801. print "<span class=\"bits\">$2</span>;";
  802. } else {
  803. print "<span class=\"type\">$type</span> ";
  804. print "<span class=\"param\">$parameter</span>;";
  805. }
  806. print "</li>\n";
  807. }
  808. print "<li>};</li>\n";
  809. print "</ol>\n";
  810. print "<section>\n";
  811. print "<h1>Members</h1>\n";
  812. print "<dl>\n";
  813. foreach $parameter (@{$args{'parameterlist'}}) {
  814. ($parameter =~ /^#/) && next;
  815. my $parameter_name = $parameter;
  816. $parameter_name =~ s/\[.*//;
  817. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  818. print "<dt>" . $parameter . "</dt>\n";
  819. print "<dd>";
  820. output_highlight($args{'parameterdescs'}{$parameter_name});
  821. print "</dd>\n";
  822. }
  823. print "</dl>\n";
  824. print "</section>\n";
  825. output_section_html5(@_);
  826. print "</article>\n";
  827. }
  828. # output function in html5
  829. sub output_function_html5(%) {
  830. my %args = %{$_[0]};
  831. my ($parameter, $section);
  832. my $count;
  833. my $html5id;
  834. $html5id = $args{'function'};
  835. $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
  836. print "<article class=\"function\" id=\"func:". $html5id . "\">\n";
  837. print "<hgroup>\n";
  838. print "<h1>" . $args{'function'} . "</h1>";
  839. print "<h2>" . $args{'purpose'} . "</h2>\n";
  840. print "</hgroup>\n";
  841. print "<ol class=\"code\">\n";
  842. print "<li>";
  843. print "<span class=\"type\">" . $args{'functiontype'} . "</span> ";
  844. print "<span class=\"identifier\">" . $args{'function'} . "</span> (";
  845. print "</li>";
  846. $count = 0;
  847. foreach $parameter (@{$args{'parameterlist'}}) {
  848. print "<li class=\"indent\">";
  849. $type = $args{'parametertypes'}{$parameter};
  850. if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
  851. # pointer-to-function
  852. print "<span class=\"type\">$1</span> ";
  853. print "<span class=\"param\">$parameter</span>";
  854. print "<span class=\"type\">)</span> ";
  855. print "(<span class=\"args\">$2</span>)";
  856. } else {
  857. print "<span class=\"type\">$type</span> ";
  858. print "<span class=\"param\">$parameter</span>";
  859. }
  860. if ($count != $#{$args{'parameterlist'}}) {
  861. $count++;
  862. print ",";
  863. }
  864. print "</li>\n";
  865. }
  866. print "<li>)</li>\n";
  867. print "</ol>\n";
  868. print "<section>\n";
  869. print "<h1>Arguments</h1>\n";
  870. print "<p>\n";
  871. print "<dl>\n";
  872. foreach $parameter (@{$args{'parameterlist'}}) {
  873. my $parameter_name = $parameter;
  874. $parameter_name =~ s/\[.*//;
  875. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  876. print "<dt>" . $parameter . "</dt>\n";
  877. print "<dd>";
  878. output_highlight($args{'parameterdescs'}{$parameter_name});
  879. print "</dd>\n";
  880. }
  881. print "</dl>\n";
  882. print "</section>\n";
  883. output_section_html5(@_);
  884. print "</article>\n";
  885. }
  886. # output DOC: block header in html5
  887. sub output_blockhead_html5(%) {
  888. my %args = %{$_[0]};
  889. my ($parameter, $section);
  890. my $count;
  891. my $html5id;
  892. foreach $section (@{$args{'sectionlist'}}) {
  893. $html5id = $section;
  894. $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
  895. print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n";
  896. print "<h1>$section</h1>\n";
  897. print "<p>\n";
  898. output_highlight($args{'sections'}{$section});
  899. print "</p>\n";
  900. }
  901. print "</article>\n";
  902. }
  903. sub output_section_xml(%) {
  904. my %args = %{$_[0]};
  905. my $section;
  906. # print out each section
  907. $lineprefix=" ";
  908. foreach $section (@{$args{'sectionlist'}}) {
  909. print "<refsect1>\n";
  910. print "<title>$section</title>\n";
  911. if ($section =~ m/EXAMPLE/i) {
  912. print "<informalexample><programlisting>\n";
  913. $output_preformatted = 1;
  914. } else {
  915. print "<para>\n";
  916. }
  917. output_highlight($args{'sections'}{$section});
  918. $output_preformatted = 0;
  919. if ($section =~ m/EXAMPLE/i) {
  920. print "</programlisting></informalexample>\n";
  921. } else {
  922. print "</para>\n";
  923. }
  924. print "</refsect1>\n";
  925. }
  926. }
  927. # output function in XML DocBook
  928. sub output_function_xml(%) {
  929. my %args = %{$_[0]};
  930. my ($parameter, $section);
  931. my $count;
  932. my $id;
  933. $id = "API-" . $args{'function'};
  934. $id =~ s/[^A-Za-z0-9]/-/g;
  935. print "<refentry id=\"$id\">\n";
  936. print "<refentryinfo>\n";
  937. print " <title>LINUX</title>\n";
  938. print " <productname>Kernel Hackers Manual</productname>\n";
  939. print " <date>$man_date</date>\n";
  940. print "</refentryinfo>\n";
  941. print "<refmeta>\n";
  942. print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n";
  943. print " <manvolnum>9</manvolnum>\n";
  944. print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
  945. print "</refmeta>\n";
  946. print "<refnamediv>\n";
  947. print " <refname>" . $args{'function'} . "</refname>\n";
  948. print " <refpurpose>\n";
  949. print " ";
  950. output_highlight ($args{'purpose'});
  951. print " </refpurpose>\n";
  952. print "</refnamediv>\n";
  953. print "<refsynopsisdiv>\n";
  954. print " <title>Synopsis</title>\n";
  955. print " <funcsynopsis><funcprototype>\n";
  956. print " <funcdef>" . $args{'functiontype'} . " ";
  957. print "<function>" . $args{'function'} . " </function></funcdef>\n";
  958. $count = 0;
  959. if ($#{$args{'parameterlist'}} >= 0) {
  960. foreach $parameter (@{$args{'parameterlist'}}) {
  961. $type = $args{'parametertypes'}{$parameter};
  962. if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
  963. # pointer-to-function
  964. print " <paramdef>$1<parameter>$parameter</parameter>)\n";
  965. print " <funcparams>$2</funcparams></paramdef>\n";
  966. } else {
  967. print " <paramdef>" . $type;
  968. print " <parameter>$parameter</parameter></paramdef>\n";
  969. }
  970. }
  971. } else {
  972. print " <void/>\n";
  973. }
  974. print " </funcprototype></funcsynopsis>\n";
  975. print "</refsynopsisdiv>\n";
  976. # print parameters
  977. print "<refsect1>\n <title>Arguments</title>\n";
  978. if ($#{$args{'parameterlist'}} >= 0) {
  979. print " <variablelist>\n";
  980. foreach $parameter (@{$args{'parameterlist'}}) {
  981. my $parameter_name = $parameter;
  982. $parameter_name =~ s/\[.*//;
  983. print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
  984. print " <listitem>\n <para>\n";
  985. $lineprefix=" ";
  986. output_highlight($args{'parameterdescs'}{$parameter_name});
  987. print " </para>\n </listitem>\n </varlistentry>\n";
  988. }
  989. print " </variablelist>\n";
  990. } else {
  991. print " <para>\n None\n </para>\n";
  992. }
  993. print "</refsect1>\n";
  994. output_section_xml(@_);
  995. print "</refentry>\n\n";
  996. }
  997. # output struct in XML DocBook
  998. sub output_struct_xml(%) {
  999. my %args = %{$_[0]};
  1000. my ($parameter, $section);
  1001. my $id;
  1002. $id = "API-struct-" . $args{'struct'};
  1003. $id =~ s/[^A-Za-z0-9]/-/g;
  1004. print "<refentry id=\"$id\">\n";
  1005. print "<refentryinfo>\n";
  1006. print " <title>LINUX</title>\n";
  1007. print " <productname>Kernel Hackers Manual</productname>\n";
  1008. print " <date>$man_date</date>\n";
  1009. print "</refentryinfo>\n";
  1010. print "<refmeta>\n";
  1011. print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n";
  1012. print " <manvolnum>9</manvolnum>\n";
  1013. print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
  1014. print "</refmeta>\n";
  1015. print "<refnamediv>\n";
  1016. print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n";
  1017. print " <refpurpose>\n";
  1018. print " ";
  1019. output_highlight ($args{'purpose'});
  1020. print " </refpurpose>\n";
  1021. print "</refnamediv>\n";
  1022. print "<refsynopsisdiv>\n";
  1023. print " <title>Synopsis</title>\n";
  1024. print " <programlisting>\n";
  1025. print $args{'type'} . " " . $args{'struct'} . " {\n";
  1026. foreach $parameter (@{$args{'parameterlist'}}) {
  1027. if ($parameter =~ /^#/) {
  1028. my $prm = $parameter;
  1029. # convert data read & converted thru xml_escape() into &xyz; format:
  1030. # This allows us to have #define macros interspersed in a struct.
  1031. $prm =~ s/\\\\\\/\&/g;
  1032. print "$prm\n";
  1033. next;
  1034. }
  1035. my $parameter_name = $parameter;
  1036. $parameter_name =~ s/\[.*//;
  1037. defined($args{'parameterdescs'}{$parameter_name}) || next;
  1038. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  1039. $type = $args{'parametertypes'}{$parameter};
  1040. if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
  1041. # pointer-to-function
  1042. print " $1 $parameter) ($2);\n";
  1043. } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
  1044. # bitfield
  1045. print " $1 $parameter$2;\n";
  1046. } else {
  1047. print " " . $type . " " . $parameter . ";\n";
  1048. }
  1049. }
  1050. print "};";
  1051. print " </programlisting>\n";
  1052. print "</refsynopsisdiv>\n";
  1053. print " <refsect1>\n";
  1054. print " <title>Members</title>\n";
  1055. if ($#{$args{'parameterlist'}} >= 0) {
  1056. print " <variablelist>\n";
  1057. foreach $parameter (@{$args{'parameterlist'}}) {
  1058. ($parameter =~ /^#/) && next;
  1059. my $parameter_name = $parameter;
  1060. $parameter_name =~ s/\[.*//;
  1061. defined($args{'parameterdescs'}{$parameter_name}) || next;
  1062. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  1063. print " <varlistentry>";
  1064. print " <term>$parameter</term>\n";
  1065. print " <listitem><para>\n";
  1066. output_highlight($args{'parameterdescs'}{$parameter_name});
  1067. print " </para></listitem>\n";
  1068. print " </varlistentry>\n";
  1069. }
  1070. print " </variablelist>\n";
  1071. } else {
  1072. print " <para>\n None\n </para>\n";
  1073. }
  1074. print " </refsect1>\n";
  1075. output_section_xml(@_);
  1076. print "</refentry>\n\n";
  1077. }
  1078. # output enum in XML DocBook
  1079. sub output_enum_xml(%) {
  1080. my %args = %{$_[0]};
  1081. my ($parameter, $section);
  1082. my $count;
  1083. my $id;
  1084. $id = "API-enum-" . $args{'enum'};
  1085. $id =~ s/[^A-Za-z0-9]/-/g;
  1086. print "<refentry id=\"$id\">\n";
  1087. print "<refentryinfo>\n";
  1088. print " <title>LINUX</title>\n";
  1089. print " <productname>Kernel Hackers Manual</productname>\n";
  1090. print " <date>$man_date</date>\n";
  1091. print "</refentryinfo>\n";
  1092. print "<refmeta>\n";
  1093. print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n";
  1094. print " <manvolnum>9</manvolnum>\n";
  1095. print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
  1096. print "</refmeta>\n";
  1097. print "<refnamediv>\n";
  1098. print " <refname>enum " . $args{'enum'} . "</refname>\n";
  1099. print " <refpurpose>\n";
  1100. print " ";
  1101. output_highlight ($args{'purpose'});
  1102. print " </refpurpose>\n";
  1103. print "</refnamediv>\n";
  1104. print "<refsynopsisdiv>\n";
  1105. print " <title>Synopsis</title>\n";
  1106. print " <programlisting>\n";
  1107. print "enum " . $args{'enum'} . " {\n";
  1108. $count = 0;
  1109. foreach $parameter (@{$args{'parameterlist'}}) {
  1110. print " $parameter";
  1111. if ($count != $#{$args{'parameterlist'}}) {
  1112. $count++;
  1113. print ",";
  1114. }
  1115. print "\n";
  1116. }
  1117. print "};";
  1118. print " </programlisting>\n";
  1119. print "</refsynopsisdiv>\n";
  1120. print "<refsect1>\n";
  1121. print " <title>Constants</title>\n";
  1122. print " <variablelist>\n";
  1123. foreach $parameter (@{$args{'parameterlist'}}) {
  1124. my $parameter_name = $parameter;
  1125. $parameter_name =~ s/\[.*//;
  1126. print " <varlistentry>";
  1127. print " <term>$parameter</term>\n";
  1128. print " <listitem><para>\n";
  1129. output_highlight($args{'parameterdescs'}{$parameter_name});
  1130. print " </para></listitem>\n";
  1131. print " </varlistentry>\n";
  1132. }
  1133. print " </variablelist>\n";
  1134. print "</refsect1>\n";
  1135. output_section_xml(@_);
  1136. print "</refentry>\n\n";
  1137. }
  1138. # output typedef in XML DocBook
  1139. sub output_typedef_xml(%) {
  1140. my %args = %{$_[0]};
  1141. my ($parameter, $section);
  1142. my $id;
  1143. $id = "API-typedef-" . $args{'typedef'};
  1144. $id =~ s/[^A-Za-z0-9]/-/g;
  1145. print "<refentry id=\"$id\">\n";
  1146. print "<refentryinfo>\n";
  1147. print " <title>LINUX</title>\n";
  1148. print " <productname>Kernel Hackers Manual</productname>\n";
  1149. print " <date>$man_date</date>\n";
  1150. print "</refentryinfo>\n";
  1151. print "<refmeta>\n";
  1152. print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n";
  1153. print " <manvolnum>9</manvolnum>\n";
  1154. print "</refmeta>\n";
  1155. print "<refnamediv>\n";
  1156. print " <refname>typedef " . $args{'typedef'} . "</refname>\n";
  1157. print " <refpurpose>\n";
  1158. print " ";
  1159. output_highlight ($args{'purpose'});
  1160. print " </refpurpose>\n";
  1161. print "</refnamediv>\n";
  1162. print "<refsynopsisdiv>\n";
  1163. print " <title>Synopsis</title>\n";
  1164. print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n";
  1165. print "</refsynopsisdiv>\n";
  1166. output_section_xml(@_);
  1167. print "</refentry>\n\n";
  1168. }
  1169. # output in XML DocBook
  1170. sub output_blockhead_xml(%) {
  1171. my %args = %{$_[0]};
  1172. my ($parameter, $section);
  1173. my $count;
  1174. my $id = $args{'module'};
  1175. $id =~ s/[^A-Za-z0-9]/-/g;
  1176. # print out each section
  1177. $lineprefix=" ";
  1178. foreach $section (@{$args{'sectionlist'}}) {
  1179. if (!$args{'content-only'}) {
  1180. print "<refsect1>\n <title>$section</title>\n";
  1181. }
  1182. if ($section =~ m/EXAMPLE/i) {
  1183. print "<example><para>\n";
  1184. $output_preformatted = 1;
  1185. } else {
  1186. print "<para>\n";
  1187. }
  1188. output_highlight($args{'sections'}{$section});
  1189. $output_preformatted = 0;
  1190. if ($section =~ m/EXAMPLE/i) {
  1191. print "</para></example>\n";
  1192. } else {
  1193. print "</para>";
  1194. }
  1195. if (!$args{'content-only'}) {
  1196. print "\n</refsect1>\n";
  1197. }
  1198. }
  1199. print "\n\n";
  1200. }
  1201. # output in XML DocBook
  1202. sub output_function_gnome {
  1203. my %args = %{$_[0]};
  1204. my ($parameter, $section);
  1205. my $count;
  1206. my $id;
  1207. $id = $args{'module'} . "-" . $args{'function'};
  1208. $id =~ s/[^A-Za-z0-9]/-/g;
  1209. print "<sect2>\n";
  1210. print " <title id=\"$id\">" . $args{'function'} . "</title>\n";
  1211. print " <funcsynopsis>\n";
  1212. print " <funcdef>" . $args{'functiontype'} . " ";
  1213. print "<function>" . $args{'function'} . " ";
  1214. print "</function></funcdef>\n";
  1215. $count = 0;
  1216. if ($#{$args{'parameterlist'}} >= 0) {
  1217. foreach $parameter (@{$args{'parameterlist'}}) {
  1218. $type = $args{'parametertypes'}{$parameter};
  1219. if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
  1220. # pointer-to-function
  1221. print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
  1222. print " <funcparams>$2</funcparams></paramdef>\n";
  1223. } else {
  1224. print " <paramdef>" . $type;
  1225. print " <parameter>$parameter</parameter></paramdef>\n";
  1226. }
  1227. }
  1228. } else {
  1229. print " <void>\n";
  1230. }
  1231. print " </funcsynopsis>\n";
  1232. if ($#{$args{'parameterlist'}} >= 0) {
  1233. print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
  1234. print "<tgroup cols=\"2\">\n";
  1235. print "<colspec colwidth=\"2*\">\n";
  1236. print "<colspec colwidth=\"8*\">\n";
  1237. print "<tbody>\n";
  1238. foreach $parameter (@{$args{'parameterlist'}}) {
  1239. my $parameter_name = $parameter;
  1240. $parameter_name =~ s/\[.*//;
  1241. print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
  1242. print " <entry>\n";
  1243. $lineprefix=" ";
  1244. output_highlight($args{'parameterdescs'}{$parameter_name});
  1245. print " </entry></row>\n";
  1246. }
  1247. print " </tbody></tgroup></informaltable>\n";
  1248. } else {
  1249. print " <para>\n None\n </para>\n";
  1250. }
  1251. # print out each section
  1252. $lineprefix=" ";
  1253. foreach $section (@{$args{'sectionlist'}}) {
  1254. print "<simplesect>\n <title>$section</title>\n";
  1255. if ($section =~ m/EXAMPLE/i) {
  1256. print "<example><programlisting>\n";
  1257. $output_preformatted = 1;
  1258. } else {
  1259. }
  1260. print "<para>\n";
  1261. output_highlight($args{'sections'}{$section});
  1262. $output_preformatted = 0;
  1263. print "</para>\n";
  1264. if ($section =~ m/EXAMPLE/i) {
  1265. print "</programlisting></example>\n";
  1266. } else {
  1267. }
  1268. print " </simplesect>\n";
  1269. }
  1270. print "</sect2>\n\n";
  1271. }
  1272. ##
  1273. # output function in man
  1274. sub output_function_man(%) {
  1275. my %args = %{$_[0]};
  1276. my ($parameter, $section);
  1277. my $count;
  1278. print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
  1279. print ".SH NAME\n";
  1280. print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
  1281. print ".SH SYNOPSIS\n";
  1282. if ($args{'functiontype'} ne "") {
  1283. print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
  1284. } else {
  1285. print ".B \"" . $args{'function'} . "\n";
  1286. }
  1287. $count = 0;
  1288. my $parenth = "(";
  1289. my $post = ",";
  1290. foreach my $parameter (@{$args{'parameterlist'}}) {
  1291. if ($count == $#{$args{'parameterlist'}}) {
  1292. $post = ");";
  1293. }
  1294. $type = $args{'parametertypes'}{$parameter};
  1295. if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
  1296. # pointer-to-function
  1297. print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
  1298. } else {
  1299. $type =~ s/([^\*])$/$1 /;
  1300. print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
  1301. }
  1302. $count++;
  1303. $parenth = "";
  1304. }
  1305. print ".SH ARGUMENTS\n";
  1306. foreach $parameter (@{$args{'parameterlist'}}) {
  1307. my $parameter_name = $parameter;
  1308. $parameter_name =~ s/\[.*//;
  1309. print ".IP \"" . $parameter . "\" 12\n";
  1310. output_highlight($args{'parameterdescs'}{$parameter_name});
  1311. }
  1312. foreach $section (@{$args{'sectionlist'}}) {
  1313. print ".SH \"", uc $section, "\"\n";
  1314. output_highlight($args{'sections'}{$section});
  1315. }
  1316. }
  1317. ##
  1318. # output enum in man
  1319. sub output_enum_man(%) {
  1320. my %args = %{$_[0]};
  1321. my ($parameter, $section);
  1322. my $count;
  1323. print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
  1324. print ".SH NAME\n";
  1325. print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
  1326. print ".SH SYNOPSIS\n";
  1327. print "enum " . $args{'enum'} . " {\n";
  1328. $count = 0;
  1329. foreach my $parameter (@{$args{'parameterlist'}}) {
  1330. print ".br\n.BI \" $parameter\"\n";
  1331. if ($count == $#{$args{'parameterlist'}}) {
  1332. print "\n};\n";
  1333. last;
  1334. }
  1335. else {
  1336. print ", \n.br\n";
  1337. }
  1338. $count++;
  1339. }
  1340. print ".SH Constants\n";
  1341. foreach $parameter (@{$args{'parameterlist'}}) {
  1342. my $parameter_name = $parameter;
  1343. $parameter_name =~ s/\[.*//;
  1344. print ".IP \"" . $parameter . "\" 12\n";
  1345. output_highlight($args{'parameterdescs'}{$parameter_name});
  1346. }
  1347. foreach $section (@{$args{'sectionlist'}}) {
  1348. print ".SH \"$section\"\n";
  1349. output_highlight($args{'sections'}{$section});
  1350. }
  1351. }
  1352. ##
  1353. # output struct in man
  1354. sub output_struct_man(%) {
  1355. my %args = %{$_[0]};
  1356. my ($parameter, $section);
  1357. print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
  1358. print ".SH NAME\n";
  1359. print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
  1360. print ".SH SYNOPSIS\n";
  1361. print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
  1362. foreach my $parameter (@{$args{'parameterlist'}}) {
  1363. if ($parameter =~ /^#/) {
  1364. print ".BI \"$parameter\"\n.br\n";
  1365. next;
  1366. }
  1367. my $parameter_name = $parameter;
  1368. $parameter_name =~ s/\[.*//;
  1369. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  1370. $type = $args{'parametertypes'}{$parameter};
  1371. if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
  1372. # pointer-to-function
  1373. print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n";
  1374. } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
  1375. # bitfield
  1376. print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n";
  1377. } else {
  1378. $type =~ s/([^\*])$/$1 /;
  1379. print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n";
  1380. }
  1381. print "\n.br\n";
  1382. }
  1383. print "};\n.br\n";
  1384. print ".SH Members\n";
  1385. foreach $parameter (@{$args{'parameterlist'}}) {
  1386. ($parameter =~ /^#/) && next;
  1387. my $parameter_name = $parameter;
  1388. $parameter_name =~ s/\[.*//;
  1389. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  1390. print ".IP \"" . $parameter . "\" 12\n";
  1391. output_highlight($args{'parameterdescs'}{$parameter_name});
  1392. }
  1393. foreach $section (@{$args{'sectionlist'}}) {
  1394. print ".SH \"$section\"\n";
  1395. output_highlight($args{'sections'}{$section});
  1396. }
  1397. }
  1398. ##
  1399. # output typedef in man
  1400. sub output_typedef_man(%) {
  1401. my %args = %{$_[0]};
  1402. my ($parameter, $section);
  1403. print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
  1404. print ".SH NAME\n";
  1405. print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
  1406. foreach $section (@{$args{'sectionlist'}}) {
  1407. print ".SH \"$section\"\n";
  1408. output_highlight($args{'sections'}{$section});
  1409. }
  1410. }
  1411. sub output_blockhead_man(%) {
  1412. my %args = %{$_[0]};
  1413. my ($parameter, $section);
  1414. my $count;
  1415. print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
  1416. foreach $section (@{$args{'sectionlist'}}) {
  1417. print ".SH \"$section\"\n";
  1418. output_highlight($args{'sections'}{$section});
  1419. }
  1420. }
  1421. ##
  1422. # output in text
  1423. sub output_function_text(%) {
  1424. my %args = %{$_[0]};
  1425. my ($parameter, $section);
  1426. my $start;
  1427. print "Name:\n\n";
  1428. print $args{'function'} . " - " . $args{'purpose'} . "\n";
  1429. print "\nSynopsis:\n\n";
  1430. if ($args{'functiontype'} ne "") {
  1431. $start = $args{'functiontype'} . " " . $args{'function'} . " (";
  1432. } else {
  1433. $start = $args{'function'} . " (";
  1434. }
  1435. print $start;
  1436. my $count = 0;
  1437. foreach my $parameter (@{$args{'parameterlist'}}) {
  1438. $type = $args{'parametertypes'}{$parameter};
  1439. if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
  1440. # pointer-to-function
  1441. print $1 . $parameter . ") (" . $2;
  1442. } else {
  1443. print $type . " " . $parameter;
  1444. }
  1445. if ($count != $#{$args{'parameterlist'}}) {
  1446. $count++;
  1447. print ",\n";
  1448. print " " x length($start);
  1449. } else {
  1450. print ");\n\n";
  1451. }
  1452. }
  1453. print "Arguments:\n\n";
  1454. foreach $parameter (@{$args{'parameterlist'}}) {
  1455. my $parameter_name = $parameter;
  1456. $parameter_name =~ s/\[.*//;
  1457. print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n";
  1458. }
  1459. output_section_text(@_);
  1460. }
  1461. #output sections in text
  1462. sub output_section_text(%) {
  1463. my %args = %{$_[0]};
  1464. my $section;
  1465. print "\n";
  1466. foreach $section (@{$args{'sectionlist'}}) {
  1467. print "$section:\n\n";
  1468. output_highlight($args{'sections'}{$section});
  1469. }
  1470. print "\n\n";
  1471. }
  1472. # output enum in text
  1473. sub output_enum_text(%) {
  1474. my %args = %{$_[0]};
  1475. my ($parameter);
  1476. my $count;
  1477. print "Enum:\n\n";
  1478. print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n";
  1479. print "enum " . $args{'enum'} . " {\n";
  1480. $count = 0;
  1481. foreach $parameter (@{$args{'parameterlist'}}) {
  1482. print "\t$parameter";
  1483. if ($count != $#{$args{'parameterlist'}}) {
  1484. $count++;
  1485. print ",";
  1486. }
  1487. print "\n";
  1488. }
  1489. print "};\n\n";
  1490. print "Constants:\n\n";
  1491. foreach $parameter (@{$args{'parameterlist'}}) {
  1492. print "$parameter\n\t";
  1493. print $args{'parameterdescs'}{$parameter} . "\n";
  1494. }
  1495. output_section_text(@_);
  1496. }
  1497. # output typedef in text
  1498. sub output_typedef_text(%) {
  1499. my %args = %{$_[0]};
  1500. my ($parameter);
  1501. my $count;
  1502. print "Typedef:\n\n";
  1503. print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n";
  1504. output_section_text(@_);
  1505. }
  1506. # output struct as text
  1507. sub output_struct_text(%) {
  1508. my %args = %{$_[0]};
  1509. my ($parameter);
  1510. print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n";
  1511. print $args{'type'} . " " . $args{'struct'} . " {\n";
  1512. foreach $parameter (@{$args{'parameterlist'}}) {
  1513. if ($parameter =~ /^#/) {
  1514. print "$parameter\n";
  1515. next;
  1516. }
  1517. my $parameter_name = $parameter;
  1518. $parameter_name =~ s/\[.*//;
  1519. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  1520. $type = $args{'parametertypes'}{$parameter};
  1521. if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
  1522. # pointer-to-function
  1523. print "\t$1 $parameter) ($2);\n";
  1524. } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
  1525. # bitfield
  1526. print "\t$1 $parameter$2;\n";
  1527. } else {
  1528. print "\t" . $type . " " . $parameter . ";\n";
  1529. }
  1530. }
  1531. print "};\n\n";
  1532. print "Members:\n\n";
  1533. foreach $parameter (@{$args{'parameterlist'}}) {
  1534. ($parameter =~ /^#/) && next;
  1535. my $parameter_name = $parameter;
  1536. $parameter_name =~ s/\[.*//;
  1537. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  1538. print "$parameter\n\t";
  1539. print $args{'parameterdescs'}{$parameter_name} . "\n";
  1540. }
  1541. print "\n";
  1542. output_section_text(@_);
  1543. }
  1544. sub output_blockhead_text(%) {
  1545. my %args = %{$_[0]};
  1546. my ($parameter, $section);
  1547. foreach $section (@{$args{'sectionlist'}}) {
  1548. print " $section:\n";
  1549. print " -> ";
  1550. output_highlight($args{'sections'}{$section});
  1551. }
  1552. }
  1553. ##
  1554. # output in restructured text
  1555. #
  1556. #
  1557. # This could use some work; it's used to output the DOC: sections, and
  1558. # starts by putting out the name of the doc section itself, but that tends
  1559. # to duplicate a header already in the template file.
  1560. #
  1561. sub output_blockhead_rst(%) {
  1562. my %args = %{$_[0]};
  1563. my ($parameter, $section);
  1564. foreach $section (@{$args{'sectionlist'}}) {
  1565. print "**$section**\n\n";
  1566. output_highlight_rst($args{'sections'}{$section});
  1567. print "\n";
  1568. }
  1569. }
  1570. sub output_highlight_rst {
  1571. my $contents = join "\n",@_;
  1572. my $line;
  1573. # undo the evil effects of xml_escape() earlier
  1574. $contents = xml_unescape($contents);
  1575. eval $dohighlight;
  1576. die $@ if $@;
  1577. foreach $line (split "\n", $contents) {
  1578. if ($line eq "") {
  1579. print $lineprefix, $blankline;
  1580. } else {
  1581. $line =~ s/\\\\\\/\&/g;
  1582. print $lineprefix, $line;
  1583. }
  1584. print "\n";
  1585. }
  1586. }
  1587. sub output_function_rst(%) {
  1588. my %args = %{$_[0]};
  1589. my ($parameter, $section);
  1590. my $start;
  1591. print ".. c:function:: ";
  1592. if ($args{'functiontype'} ne "") {
  1593. $start = $args{'functiontype'} . " " . $args{'function'} . " (";
  1594. } else {
  1595. $start = $args{'function'} . " (";
  1596. }
  1597. print $start;
  1598. my $count = 0;
  1599. foreach my $parameter (@{$args{'parameterlist'}}) {
  1600. if ($count ne 0) {
  1601. print ", ";
  1602. }
  1603. $count++;
  1604. $type = $args{'parametertypes'}{$parameter};
  1605. if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
  1606. # pointer-to-function
  1607. print $1 . $parameter . ") (" . $2;
  1608. } else {
  1609. print $type . " " . $parameter;
  1610. }
  1611. }
  1612. print ")\n\n " . $args{'purpose'} . "\n\n";
  1613. print ":Parameters:\n\n";
  1614. foreach $parameter (@{$args{'parameterlist'}}) {
  1615. my $parameter_name = $parameter;
  1616. #$parameter_name =~ s/\[.*//;
  1617. $type = $args{'parametertypes'}{$parameter};
  1618. if ($type ne "") {
  1619. print " ``$type $parameter``\n";
  1620. } else {
  1621. print " ``$parameter``\n";
  1622. }
  1623. if (defined($args{'parameterdescs'}{$parameter_name}) &&
  1624. $args{'parameterdescs'}{$parameter_name} ne $undescribed) {
  1625. my $oldprefix = $lineprefix;
  1626. $lineprefix = " ";
  1627. output_highlight_rst($args{'parameterdescs'}{$parameter_name});
  1628. $lineprefix = $oldprefix;
  1629. } else {
  1630. print "\n _undescribed_\n";
  1631. }
  1632. print "\n";
  1633. }
  1634. output_section_rst(@_);
  1635. }
  1636. sub output_section_rst(%) {
  1637. my %args = %{$_[0]};
  1638. my $section;
  1639. my $oldprefix = $lineprefix;
  1640. $lineprefix = " ";
  1641. foreach $section (@{$args{'sectionlist'}}) {
  1642. print ":$section:\n\n";
  1643. output_highlight_rst($args{'sections'}{$section});
  1644. print "\n";
  1645. }
  1646. print "\n";
  1647. $lineprefix = $oldprefix;
  1648. }
  1649. sub output_enum_rst(%) {
  1650. my %args = %{$_[0]};
  1651. my ($parameter);
  1652. my $count;
  1653. my $name = "enum " . $args{'enum'};
  1654. print "\n\n.. c:type:: " . $name . "\n\n";
  1655. print " " . $args{'purpose'} . "\n\n";
  1656. print "..\n\n:Constants:\n\n";
  1657. my $oldprefix = $lineprefix;
  1658. $lineprefix = " ";
  1659. foreach $parameter (@{$args{'parameterlist'}}) {
  1660. print " `$parameter`\n";
  1661. if ($args{'parameterdescs'}{$parameter} ne $undescribed) {
  1662. output_highlight_rst($args{'parameterdescs'}{$parameter});
  1663. } else {
  1664. print " undescribed\n";
  1665. }
  1666. print "\n";
  1667. }
  1668. $lineprefix = $oldprefix;
  1669. output_section_rst(@_);
  1670. }
  1671. sub output_typedef_rst(%) {
  1672. my %args = %{$_[0]};
  1673. my ($parameter);
  1674. my $count;
  1675. my $name = "typedef " . $args{'typedef'};
  1676. ### FIXME: should the name below contain "typedef" or not?
  1677. print "\n\n.. c:type:: " . $name . "\n\n";
  1678. print " " . $args{'purpose'} . "\n\n";
  1679. output_section_rst(@_);
  1680. }
  1681. sub output_struct_rst(%) {
  1682. my %args = %{$_[0]};
  1683. my ($parameter);
  1684. my $name = $args{'type'} . " " . $args{'struct'};
  1685. print "\n\n.. c:type:: " . $name . "\n\n";
  1686. print " " . $args{'purpose'} . "\n\n";
  1687. print ":Definition:\n\n";
  1688. print " ::\n\n";
  1689. print " " . $args{'type'} . " " . $args{'struct'} . " {\n";
  1690. foreach $parameter (@{$args{'parameterlist'}}) {
  1691. if ($parameter =~ /^#/) {
  1692. print " " . "$parameter\n";
  1693. next;
  1694. }
  1695. my $parameter_name = $parameter;
  1696. $parameter_name =~ s/\[.*//;
  1697. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  1698. $type = $args{'parametertypes'}{$parameter};
  1699. if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
  1700. # pointer-to-function
  1701. print " $1 $parameter) ($2);\n";
  1702. } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
  1703. # bitfield
  1704. print " $1 $parameter$2;\n";
  1705. } else {
  1706. print " " . $type . " " . $parameter . ";\n";
  1707. }
  1708. }
  1709. print " };\n\n";
  1710. print ":Members:\n\n";
  1711. foreach $parameter (@{$args{'parameterlist'}}) {
  1712. ($parameter =~ /^#/) && next;
  1713. my $parameter_name = $parameter;
  1714. $parameter_name =~ s/\[.*//;
  1715. ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
  1716. $type = $args{'parametertypes'}{$parameter};
  1717. print " `$type $parameter`" . "\n";
  1718. my $oldprefix = $lineprefix;
  1719. $lineprefix = " ";
  1720. output_highlight_rst($args{'parameterdescs'}{$parameter_name});
  1721. $lineprefix = $oldprefix;
  1722. print "\n";
  1723. }
  1724. print "\n";
  1725. output_section_rst(@_);
  1726. }
  1727. ## list mode output functions
  1728. sub output_function_list(%) {
  1729. my %args = %{$_[0]};
  1730. print $args{'function'} . "\n";
  1731. }
  1732. # output enum in list
  1733. sub output_enum_list(%) {
  1734. my %args = %{$_[0]};
  1735. print $args{'enum'} . "\n";
  1736. }
  1737. # output typedef in list
  1738. sub output_typedef_list(%) {
  1739. my %args = %{$_[0]};
  1740. print $args{'typedef'} . "\n";
  1741. }
  1742. # output struct as list
  1743. sub output_struct_list(%) {
  1744. my %args = %{$_[0]};
  1745. print $args{'struct'} . "\n";
  1746. }
  1747. sub output_blockhead_list(%) {
  1748. my %args = %{$_[0]};
  1749. my ($parameter, $section);
  1750. foreach $section (@{$args{'sectionlist'}}) {
  1751. print "DOC: $section\n";
  1752. }
  1753. }
  1754. ##
  1755. # generic output function for all types (function, struct/union, typedef, enum);
  1756. # calls the generated, variable output_ function name based on
  1757. # functype and output_mode
  1758. sub output_declaration {
  1759. no strict 'refs';
  1760. my $name = shift;
  1761. my $functype = shift;
  1762. my $func = "output_${functype}_$output_mode";
  1763. if (($output_selection == OUTPUT_ALL) ||
  1764. (($output_selection == OUTPUT_INCLUDE ||
  1765. $output_selection == OUTPUT_EXPORTED) &&
  1766. defined($function_table{$name})) ||
  1767. (($output_selection == OUTPUT_EXCLUDE ||
  1768. $output_selection == OUTPUT_INTERNAL) &&
  1769. !($functype eq "function" && defined($function_table{$name}))))
  1770. {
  1771. &$func(@_);
  1772. $section_counter++;
  1773. }
  1774. }
  1775. ##
  1776. # generic output function - calls the right one based on current output mode.
  1777. sub output_blockhead {
  1778. no strict 'refs';
  1779. my $func = "output_blockhead_" . $output_mode;
  1780. &$func(@_);
  1781. $section_counter++;
  1782. }
  1783. ##
  1784. # takes a declaration (struct, union, enum, typedef) and
  1785. # invokes the right handler. NOT called for functions.
  1786. sub dump_declaration($$) {
  1787. no strict 'refs';
  1788. my ($prototype, $file) = @_;
  1789. my $func = "dump_" . $decl_type;
  1790. &$func(@_);
  1791. }
  1792. sub dump_union($$) {
  1793. dump_struct(@_);
  1794. }
  1795. sub dump_struct($$) {
  1796. my $x = shift;
  1797. my $file = shift;
  1798. my $nested;
  1799. if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
  1800. #my $decl_type = $1;
  1801. $declaration_name = $2;
  1802. my $members = $3;
  1803. # ignore embedded structs or unions
  1804. $members =~ s/({.*})//g;
  1805. $nested = $1;
  1806. # ignore members marked private:
  1807. $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi;
  1808. $members =~ s/\/\*\s*private:.*//gosi;
  1809. # strip comments:
  1810. $members =~ s/\/\*.*?\*\///gos;
  1811. $nested =~ s/\/\*.*?\*\///gos;
  1812. # strip kmemcheck_bitfield_{begin,end}.*;
  1813. $members =~ s/kmemcheck_bitfield_.*?;//gos;
  1814. # strip attributes
  1815. $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
  1816. $members =~ s/__aligned\s*\([^;]*\)//gos;
  1817. $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos;
  1818. # replace DECLARE_BITMAP
  1819. $members =~ s/DECLARE_BITMAP\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos;
  1820. create_parameterlist($members, ';', $file);
  1821. check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
  1822. output_declaration($declaration_name,
  1823. 'struct',
  1824. {'struct' => $declaration_name,
  1825. 'module' => $modulename,
  1826. 'parameterlist' => \@parameterlist,
  1827. 'parameterdescs' => \%parameterdescs,
  1828. 'parametertypes' => \%parametertypes,
  1829. 'sectionlist' => \@sectionlist,
  1830. 'sections' => \%sections,
  1831. 'purpose' => $declaration_purpose,
  1832. 'type' => $decl_type
  1833. });
  1834. }
  1835. else {
  1836. print STDERR "${file}:$.: error: Cannot parse struct or union!\n";
  1837. ++$errors;
  1838. }
  1839. }
  1840. sub dump_enum($$) {
  1841. my $x = shift;
  1842. my $file = shift;
  1843. $x =~ s@/\*.*?\*/@@gos; # strip comments.
  1844. # strip #define macros inside enums
  1845. $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos;
  1846. if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
  1847. $declaration_name = $1;
  1848. my $members = $2;
  1849. foreach my $arg (split ',', $members) {
  1850. $arg =~ s/^\s*(\w+).*/$1/;
  1851. push @parameterlist, $arg;
  1852. if (!$parameterdescs{$arg}) {
  1853. $parameterdescs{$arg} = $undescribed;
  1854. print STDERR "${file}:$.: warning: Enum value '$arg' ".
  1855. "not described in enum '$declaration_name'\n";
  1856. }
  1857. }
  1858. output_declaration($declaration_name,
  1859. 'enum',
  1860. {'enum' => $declaration_name,
  1861. 'module' => $modulename,
  1862. 'parameterlist' => \@parameterlist,
  1863. 'parameterdescs' => \%parameterdescs,
  1864. 'sectionlist' => \@sectionlist,
  1865. 'sections' => \%sections,
  1866. 'purpose' => $declaration_purpose
  1867. });
  1868. }
  1869. else {
  1870. print STDERR "${file}:$.: error: Cannot parse enum!\n";
  1871. ++$errors;
  1872. }
  1873. }
  1874. sub dump_typedef($$) {
  1875. my $x = shift;
  1876. my $file = shift;
  1877. $x =~ s@/\*.*?\*/@@gos; # strip comments.
  1878. # Parse function prototypes
  1879. if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/) {
  1880. # Function typedefs
  1881. $return_type = $1;
  1882. $declaration_name = $2;
  1883. my $args = $3;
  1884. create_parameterlist($args, ',', $file);
  1885. output_declaration($declaration_name,
  1886. 'function',
  1887. {'function' => $declaration_name,
  1888. 'module' => $modulename,
  1889. 'functiontype' => $return_type,
  1890. 'parameterlist' => \@parameterlist,
  1891. 'parameterdescs' => \%parameterdescs,
  1892. 'parametertypes' => \%parametertypes,
  1893. 'sectionlist' => \@sectionlist,
  1894. 'sections' => \%sections,
  1895. 'purpose' => $declaration_purpose
  1896. });
  1897. return;
  1898. }
  1899. while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
  1900. $x =~ s/\(*.\)\s*;$/;/;
  1901. $x =~ s/\[*.\]\s*;$/;/;
  1902. }
  1903. if ($x =~ /typedef.*\s+(\w+)\s*;/) {
  1904. $declaration_name = $1;
  1905. output_declaration($declaration_name,
  1906. 'typedef',
  1907. {'typedef' => $declaration_name,
  1908. 'module' => $modulename,
  1909. 'sectionlist' => \@sectionlist,
  1910. 'sections' => \%sections,
  1911. 'purpose' => $declaration_purpose
  1912. });
  1913. }
  1914. else {
  1915. print STDERR "${file}:$.: error: Cannot parse typedef!\n";
  1916. ++$errors;
  1917. }
  1918. }
  1919. sub save_struct_actual($) {
  1920. my $actual = shift;
  1921. # strip all spaces from the actual param so that it looks like one string item
  1922. $actual =~ s/\s*//g;
  1923. $struct_actual = $struct_actual . $actual . " ";
  1924. }
  1925. sub create_parameterlist($$$) {
  1926. my $args = shift;
  1927. my $splitter = shift;
  1928. my $file = shift;
  1929. my $type;
  1930. my $param;
  1931. # temporarily replace commas inside function pointer definition
  1932. while ($args =~ /(\([^\),]+),/) {
  1933. $args =~ s/(\([^\),]+),/$1#/g;
  1934. }
  1935. foreach my $arg (split($splitter, $args)) {
  1936. # strip comments
  1937. $arg =~ s/\/\*.*\*\///;
  1938. # strip leading/trailing spaces
  1939. $arg =~ s/^\s*//;
  1940. $arg =~ s/\s*$//;
  1941. $arg =~ s/\s+/ /;
  1942. if ($arg =~ /^#/) {
  1943. # Treat preprocessor directive as a typeless variable just to fill
  1944. # corresponding data structures "correctly". Catch it later in
  1945. # output_* subs.
  1946. push_parameter($arg, "", $file);
  1947. } elsif ($arg =~ m/\(.+\)\s*\(/) {
  1948. # pointer-to-function
  1949. $arg =~ tr/#/,/;
  1950. $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
  1951. $param = $1;
  1952. $type = $arg;
  1953. $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
  1954. save_struct_actual($param);
  1955. push_parameter($param, $type, $file);
  1956. } elsif ($arg) {
  1957. $arg =~ s/\s*:\s*/:/g;
  1958. $arg =~ s/\s*\[/\[/g;
  1959. my @args = split('\s*,\s*', $arg);
  1960. if ($args[0] =~ m/\*/) {
  1961. $args[0] =~ s/(\*+)\s*/ $1/;
  1962. }
  1963. my @first_arg;
  1964. if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
  1965. shift @args;
  1966. push(@first_arg, split('\s+', $1));
  1967. push(@first_arg, $2);
  1968. } else {
  1969. @first_arg = split('\s+', shift @args);
  1970. }
  1971. unshift(@args, pop @first_arg);
  1972. $type = join " ", @first_arg;
  1973. foreach $param (@args) {
  1974. if ($param =~ m/^(\*+)\s*(.*)/) {
  1975. save_struct_actual($2);
  1976. push_parameter($2, "$type $1", $file);
  1977. }
  1978. elsif ($param =~ m/(.*?):(\d+)/) {
  1979. if ($type ne "") { # skip unnamed bit-fields
  1980. save_struct_actual($1);
  1981. push_parameter($1, "$type:$2", $file)
  1982. }
  1983. }
  1984. else {
  1985. save_struct_actual($param);
  1986. push_parameter($param, $type, $file);
  1987. }
  1988. }
  1989. }
  1990. }
  1991. }
  1992. sub push_parameter($$$) {
  1993. my $param = shift;
  1994. my $type = shift;
  1995. my $file = shift;
  1996. if (($anon_struct_union == 1) && ($type eq "") &&
  1997. ($param eq "}")) {
  1998. return; # ignore the ending }; from anon. struct/union
  1999. }
  2000. $anon_struct_union = 0;
  2001. my $param_name = $param;
  2002. $param_name =~ s/\[.*//;
  2003. if ($type eq "" && $param =~ /\.\.\.$/)
  2004. {
  2005. if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
  2006. $parameterdescs{$param} = "variable arguments";
  2007. }
  2008. }
  2009. elsif ($type eq "" && ($param eq "" or $param eq "void"))
  2010. {
  2011. $param="void";
  2012. $parameterdescs{void} = "no arguments";
  2013. }
  2014. elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
  2015. # handle unnamed (anonymous) union or struct:
  2016. {
  2017. $type = $param;
  2018. $param = "{unnamed_" . $param . "}";
  2019. $parameterdescs{$param} = "anonymous\n";
  2020. $anon_struct_union = 1;
  2021. }
  2022. # warn if parameter has no description
  2023. # (but ignore ones starting with # as these are not parameters
  2024. # but inline preprocessor statements);
  2025. # also ignore unnamed structs/unions;
  2026. if (!$anon_struct_union) {
  2027. if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
  2028. $parameterdescs{$param_name} = $undescribed;
  2029. if (($type eq 'function') || ($type eq 'enum')) {
  2030. print STDERR "${file}:$.: warning: Function parameter ".
  2031. "or member '$param' not " .
  2032. "described in '$declaration_name'\n";
  2033. }
  2034. print STDERR "${file}:$.: warning:" .
  2035. " No description found for parameter '$param'\n";
  2036. ++$warnings;
  2037. }
  2038. }
  2039. $param = xml_escape($param);
  2040. # strip spaces from $param so that it is one continuous string
  2041. # on @parameterlist;
  2042. # this fixes a problem where check_sections() cannot find
  2043. # a parameter like "addr[6 + 2]" because it actually appears
  2044. # as "addr[6", "+", "2]" on the parameter list;
  2045. # but it's better to maintain the param string unchanged for output,
  2046. # so just weaken the string compare in check_sections() to ignore
  2047. # "[blah" in a parameter string;
  2048. ###$param =~ s/\s*//g;
  2049. push @parameterlist, $param;
  2050. $parametertypes{$param} = $type;
  2051. }
  2052. sub check_sections($$$$$$) {
  2053. my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
  2054. my @sects = split ' ', $sectcheck;
  2055. my @prms = split ' ', $prmscheck;
  2056. my $err;
  2057. my ($px, $sx);
  2058. my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
  2059. foreach $sx (0 .. $#sects) {
  2060. $err = 1;
  2061. foreach $px (0 .. $#prms) {
  2062. $prm_clean = $prms[$px];
  2063. $prm_clean =~ s/\[.*\]//;
  2064. $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
  2065. # ignore array size in a parameter string;
  2066. # however, the original param string may contain
  2067. # spaces, e.g.: addr[6 + 2]
  2068. # and this appears in @prms as "addr[6" since the
  2069. # parameter list is split at spaces;
  2070. # hence just ignore "[..." for the sections check;
  2071. $prm_clean =~ s/\[.*//;
  2072. ##$prm_clean =~ s/^\**//;
  2073. if ($prm_clean eq $sects[$sx]) {
  2074. $err = 0;
  2075. last;
  2076. }
  2077. }
  2078. if ($err) {
  2079. if ($decl_type eq "function") {
  2080. print STDERR "${file}:$.: warning: " .
  2081. "Excess function parameter " .
  2082. "'$sects[$sx]' " .
  2083. "description in '$decl_name'\n";
  2084. ++$warnings;
  2085. } else {
  2086. if ($nested !~ m/\Q$sects[$sx]\E/) {
  2087. print STDERR "${file}:$.: warning: " .
  2088. "Excess struct/union/enum/typedef member " .
  2089. "'$sects[$sx]' " .
  2090. "description in '$decl_name'\n";
  2091. ++$warnings;
  2092. }
  2093. }
  2094. }
  2095. }
  2096. }
  2097. ##
  2098. # Checks the section describing the return value of a function.
  2099. sub check_return_section {
  2100. my $file = shift;
  2101. my $declaration_name = shift;
  2102. my $return_type = shift;
  2103. # Ignore an empty return type (It's a macro)
  2104. # Ignore functions with a "void" return type. (But don't ignore "void *")
  2105. if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) {
  2106. return;
  2107. }
  2108. if (!defined($sections{$section_return}) ||
  2109. $sections{$section_return} eq "") {
  2110. print STDERR "${file}:$.: warning: " .
  2111. "No description found for return value of " .
  2112. "'$declaration_name'\n";
  2113. ++$warnings;
  2114. }
  2115. }
  2116. ##
  2117. # takes a function prototype and the name of the current file being
  2118. # processed and spits out all the details stored in the global
  2119. # arrays/hashes.
  2120. sub dump_function($$) {
  2121. my $prototype = shift;
  2122. my $file = shift;
  2123. my $noret = 0;
  2124. $prototype =~ s/^static +//;
  2125. $prototype =~ s/^extern +//;
  2126. $prototype =~ s/^asmlinkage +//;
  2127. $prototype =~ s/^inline +//;
  2128. $prototype =~ s/^__inline__ +//;
  2129. $prototype =~ s/^__inline +//;
  2130. $prototype =~ s/^__always_inline +//;
  2131. $prototype =~ s/^noinline +//;
  2132. $prototype =~ s/__init +//;
  2133. $prototype =~ s/__init_or_module +//;
  2134. $prototype =~ s/__meminit +//;
  2135. $prototype =~ s/__must_check +//;
  2136. $prototype =~ s/__weak +//;
  2137. my $define = $prototype =~ s/^#\s*define\s+//; #ak added
  2138. $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
  2139. # Yes, this truly is vile. We are looking for:
  2140. # 1. Return type (may be nothing if we're looking at a macro)
  2141. # 2. Function name
  2142. # 3. Function parameters.
  2143. #
  2144. # All the while we have to watch out for function pointer parameters
  2145. # (which IIRC is what the two sections are for), C types (these
  2146. # regexps don't even start to express all the possibilities), and
  2147. # so on.
  2148. #
  2149. # If you mess with these regexps, it's a good idea to check that
  2150. # the following functions' documentation still comes out right:
  2151. # - parport_register_device (function pointer parameters)
  2152. # - atomic_set (macro)
  2153. # - pci_match_device, __copy_to_user (long return type)
  2154. if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) {
  2155. # This is an object-like macro, it has no return type and no parameter
  2156. # list.
  2157. # Function-like macros are not allowed to have spaces between
  2158. # declaration_name and opening parenthesis (notice the \s+).
  2159. $return_type = $1;
  2160. $declaration_name = $2;
  2161. $noret = 1;
  2162. } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  2163. $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  2164. $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  2165. $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  2166. $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  2167. $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  2168. $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
  2169. $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  2170. $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  2171. $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  2172. $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  2173. $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  2174. $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  2175. $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  2176. $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  2177. $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
  2178. $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
  2179. $return_type = $1;
  2180. $declaration_name = $2;
  2181. my $args = $3;
  2182. create_parameterlist($args, ',', $file);
  2183. } else {
  2184. print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n";
  2185. return;
  2186. }
  2187. my $prms = join " ", @parameterlist;
  2188. check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
  2189. # This check emits a lot of warnings at the moment, because many
  2190. # functions don't have a 'Return' doc section. So until the number
  2191. # of warnings goes sufficiently down, the check is only performed in
  2192. # verbose mode.
  2193. # TODO: always perform the check.
  2194. if ($verbose && !$noret) {
  2195. check_return_section($file, $declaration_name, $return_type);
  2196. }
  2197. output_declaration($declaration_name,
  2198. 'function',
  2199. {'function' => $declaration_name,
  2200. 'module' => $modulename,
  2201. 'functiontype' => $return_type,
  2202. 'parameterlist' => \@parameterlist,
  2203. 'parameterdescs' => \%parameterdescs,
  2204. 'parametertypes' => \%parametertypes,
  2205. 'sectionlist' => \@sectionlist,
  2206. 'sections' => \%sections,
  2207. 'purpose' => $declaration_purpose
  2208. });
  2209. }
  2210. sub reset_state {
  2211. $function = "";
  2212. %constants = ();
  2213. %parameterdescs = ();
  2214. %parametertypes = ();
  2215. @parameterlist = ();
  2216. %sections = ();
  2217. @sectionlist = ();
  2218. $sectcheck = "";
  2219. $struct_actual = "";
  2220. $prototype = "";
  2221. $state = STATE_NORMAL;
  2222. $inline_doc_state = STATE_INLINE_NA;
  2223. }
  2224. sub tracepoint_munge($) {
  2225. my $file = shift;
  2226. my $tracepointname = 0;
  2227. my $tracepointargs = 0;
  2228. if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
  2229. $tracepointname = $1;
  2230. }
  2231. if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
  2232. $tracepointname = $1;
  2233. }
  2234. if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
  2235. $tracepointname = $2;
  2236. }
  2237. $tracepointname =~ s/^\s+//; #strip leading whitespace
  2238. if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
  2239. $tracepointargs = $1;
  2240. }
  2241. if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
  2242. print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n".
  2243. "$prototype\n";
  2244. } else {
  2245. $prototype = "static inline void trace_$tracepointname($tracepointargs)";
  2246. }
  2247. }
  2248. sub syscall_munge() {
  2249. my $void = 0;
  2250. $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
  2251. ## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
  2252. if ($prototype =~ m/SYSCALL_DEFINE0/) {
  2253. $void = 1;
  2254. ## $prototype = "long sys_$1(void)";
  2255. }
  2256. $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
  2257. if ($prototype =~ m/long (sys_.*?),/) {
  2258. $prototype =~ s/,/\(/;
  2259. } elsif ($void) {
  2260. $prototype =~ s/\)/\(void\)/;
  2261. }
  2262. # now delete all of the odd-number commas in $prototype
  2263. # so that arg types & arg names don't have a comma between them
  2264. my $count = 0;
  2265. my $len = length($prototype);
  2266. if ($void) {
  2267. $len = 0; # skip the for-loop
  2268. }
  2269. for (my $ix = 0; $ix < $len; $ix++) {
  2270. if (substr($prototype, $ix, 1) eq ',') {
  2271. $count++;
  2272. if ($count % 2 == 1) {
  2273. substr($prototype, $ix, 1) = ' ';
  2274. }
  2275. }
  2276. }
  2277. }
  2278. sub process_state3_function($$) {
  2279. my $x = shift;
  2280. my $file = shift;
  2281. $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
  2282. if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
  2283. # do nothing
  2284. }
  2285. elsif ($x =~ /([^\{]*)/) {
  2286. $prototype .= $1;
  2287. }
  2288. if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
  2289. $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
  2290. $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
  2291. $prototype =~ s@^\s+@@gos; # strip leading spaces
  2292. if ($prototype =~ /SYSCALL_DEFINE/) {
  2293. syscall_munge();
  2294. }
  2295. if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
  2296. $prototype =~ /DEFINE_SINGLE_EVENT/)
  2297. {
  2298. tracepoint_munge($file);
  2299. }
  2300. dump_function($prototype, $file);
  2301. reset_state();
  2302. }
  2303. }
  2304. sub process_state3_type($$) {
  2305. my $x = shift;
  2306. my $file = shift;
  2307. $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
  2308. $x =~ s@^\s+@@gos; # strip leading spaces
  2309. $x =~ s@\s+$@@gos; # strip trailing spaces
  2310. $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
  2311. if ($x =~ /^#/) {
  2312. # To distinguish preprocessor directive from regular declaration later.
  2313. $x .= ";";
  2314. }
  2315. while (1) {
  2316. if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
  2317. $prototype .= $1 . $2;
  2318. ($2 eq '{') && $brcount++;
  2319. ($2 eq '}') && $brcount--;
  2320. if (($2 eq ';') && ($brcount == 0)) {
  2321. dump_declaration($prototype, $file);
  2322. reset_state();
  2323. last;
  2324. }
  2325. $x = $3;
  2326. } else {
  2327. $prototype .= $x;
  2328. last;
  2329. }
  2330. }
  2331. }
  2332. # xml_escape: replace <, >, and & in the text stream;
  2333. #
  2334. # however, formatting controls that are generated internally/locally in the
  2335. # kernel-doc script are not escaped here; instead, they begin life like
  2336. # $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
  2337. # are converted to their mnemonic-expected output, without the 4 * '\' & ':',
  2338. # just before actual output; (this is done by local_unescape())
  2339. sub xml_escape($) {
  2340. my $text = shift;
  2341. if (($output_mode eq "text") || ($output_mode eq "man")) {
  2342. return $text;
  2343. }
  2344. $text =~ s/\&/\\\\\\amp;/g;
  2345. $text =~ s/\</\\\\\\lt;/g;
  2346. $text =~ s/\>/\\\\\\gt;/g;
  2347. return $text;
  2348. }
  2349. # xml_unescape: reverse the effects of xml_escape
  2350. sub xml_unescape($) {
  2351. my $text = shift;
  2352. if (($output_mode eq "text") || ($output_mode eq "man")) {
  2353. return $text;
  2354. }
  2355. $text =~ s/\\\\\\amp;/\&/g;
  2356. $text =~ s/\\\\\\lt;/</g;
  2357. $text =~ s/\\\\\\gt;/>/g;
  2358. return $text;
  2359. }
  2360. # convert local escape strings to html
  2361. # local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
  2362. sub local_unescape($) {
  2363. my $text = shift;
  2364. if (($output_mode eq "text") || ($output_mode eq "man")) {
  2365. return $text;
  2366. }
  2367. $text =~ s/\\\\\\\\lt:/</g;
  2368. $text =~ s/\\\\\\\\gt:/>/g;
  2369. return $text;
  2370. }
  2371. sub process_file($) {
  2372. my $file;
  2373. my $identifier;
  2374. my $func;
  2375. my $descr;
  2376. my $in_purpose = 0;
  2377. my $initial_section_counter = $section_counter;
  2378. my ($orig_file) = @_;
  2379. if (defined($ENV{'SRCTREE'})) {
  2380. $file = "$ENV{'SRCTREE'}" . "/" . $orig_file;
  2381. }
  2382. else {
  2383. $file = $orig_file;
  2384. }
  2385. if (defined($source_map{$file})) {
  2386. $file = $source_map{$file};
  2387. }
  2388. if (!open(IN,"<$file")) {
  2389. print STDERR "Error: Cannot open file $file\n";
  2390. ++$errors;
  2391. return;
  2392. }
  2393. # two passes for -export and -internal
  2394. if ($output_selection == OUTPUT_EXPORTED ||
  2395. $output_selection == OUTPUT_INTERNAL) {
  2396. while (<IN>) {
  2397. if (/$export_symbol/o) {
  2398. $function_table{$2} = 1;
  2399. }
  2400. }
  2401. seek(IN, 0, 0);
  2402. }
  2403. $. = 1;
  2404. $section_counter = 0;
  2405. while (<IN>) {
  2406. while (s/\\\s*$//) {
  2407. $_ .= <IN>;
  2408. }
  2409. if ($state == STATE_NORMAL) {
  2410. if (/$doc_start/o) {
  2411. $state = STATE_NAME; # next line is always the function name
  2412. $in_doc_sect = 0;
  2413. }
  2414. } elsif ($state == STATE_NAME) {# this line is the function name (always)
  2415. if (/$doc_block/o) {
  2416. $state = STATE_DOCBLOCK;
  2417. $contents = "";
  2418. if ( $1 eq "" ) {
  2419. $section = $section_intro;
  2420. } else {
  2421. $section = $1;
  2422. }
  2423. }
  2424. elsif (/$doc_decl/o) {
  2425. $identifier = $1;
  2426. if (/\s*([\w\s]+?)\s*-/) {
  2427. $identifier = $1;
  2428. }
  2429. $state = STATE_FIELD;
  2430. if (/-(.*)/) {
  2431. # strip leading/trailing/multiple spaces
  2432. $descr= $1;
  2433. $descr =~ s/^\s*//;
  2434. $descr =~ s/\s*$//;
  2435. $descr =~ s/\s+/ /g;
  2436. $declaration_purpose = xml_escape($descr);
  2437. $in_purpose = 1;
  2438. } else {
  2439. $declaration_purpose = "";
  2440. }
  2441. if (($declaration_purpose eq "") && $verbose) {
  2442. print STDERR "${file}:$.: warning: missing initial short description on line:\n";
  2443. print STDERR $_;
  2444. ++$warnings;
  2445. }
  2446. if ($identifier =~ m/^struct/) {
  2447. $decl_type = 'struct';
  2448. } elsif ($identifier =~ m/^union/) {
  2449. $decl_type = 'union';
  2450. } elsif ($identifier =~ m/^enum/) {
  2451. $decl_type = 'enum';
  2452. } elsif ($identifier =~ m/^typedef/) {
  2453. $decl_type = 'typedef';
  2454. } else {
  2455. $decl_type = 'function';
  2456. }
  2457. if ($verbose) {
  2458. print STDERR "${file}:$.: info: Scanning doc for $identifier\n";
  2459. }
  2460. } else {
  2461. print STDERR "${file}:$.: warning: Cannot understand $_ on line $.",
  2462. " - I thought it was a doc line\n";
  2463. ++$warnings;
  2464. $state = STATE_NORMAL;
  2465. }
  2466. } elsif ($state == STATE_FIELD) { # look for head: lines, and include content
  2467. if (/$doc_sect/o) {
  2468. $newsection = $1;
  2469. $newcontents = $2;
  2470. if (($contents ne "") && ($contents ne "\n")) {
  2471. if (!$in_doc_sect && $verbose) {
  2472. print STDERR "${file}:$.: warning: contents before sections\n";
  2473. ++$warnings;
  2474. }
  2475. dump_section($file, $section, xml_escape($contents));
  2476. $section = $section_default;
  2477. }
  2478. $in_doc_sect = 1;
  2479. $in_purpose = 0;
  2480. $contents = $newcontents;
  2481. if ($contents ne "") {
  2482. while ((substr($contents, 0, 1) eq " ") ||
  2483. substr($contents, 0, 1) eq "\t") {
  2484. $contents = substr($contents, 1);
  2485. }
  2486. $contents .= "\n";
  2487. }
  2488. $section = $newsection;
  2489. } elsif (/$doc_end/) {
  2490. if (($contents ne "") && ($contents ne "\n")) {
  2491. dump_section($file, $section, xml_escape($contents));
  2492. $section = $section_default;
  2493. $contents = "";
  2494. }
  2495. # look for doc_com + <text> + doc_end:
  2496. if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
  2497. print STDERR "${file}:$.: warning: suspicious ending line: $_";
  2498. ++$warnings;
  2499. }
  2500. $prototype = "";
  2501. $state = STATE_PROTO;
  2502. $brcount = 0;
  2503. # print STDERR "end of doc comment, looking for prototype\n";
  2504. } elsif (/$doc_content/) {
  2505. # miguel-style comment kludge, look for blank lines after
  2506. # @parameter line to signify start of description
  2507. if ($1 eq "") {
  2508. if ($section =~ m/^@/ || $section eq $section_context) {
  2509. dump_section($file, $section, xml_escape($contents));
  2510. $section = $section_default;
  2511. $contents = "";
  2512. } else {
  2513. $contents .= "\n";
  2514. }
  2515. $in_purpose = 0;
  2516. } elsif ($in_purpose == 1) {
  2517. # Continued declaration purpose
  2518. chomp($declaration_purpose);
  2519. $declaration_purpose .= " " . xml_escape($1);
  2520. $declaration_purpose =~ s/\s+/ /g;
  2521. } else {
  2522. $contents .= $1 . "\n";
  2523. }
  2524. } else {
  2525. # i dont know - bad line? ignore.
  2526. print STDERR "${file}:$.: warning: bad line: $_";
  2527. ++$warnings;
  2528. }
  2529. } elsif ($state == STATE_INLINE) { # scanning for inline parameters
  2530. # First line (state 1) needs to be a @parameter
  2531. if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) {
  2532. $section = $1;
  2533. $contents = $2;
  2534. if ($contents ne "") {
  2535. while ((substr($contents, 0, 1) eq " ") ||
  2536. substr($contents, 0, 1) eq "\t") {
  2537. $contents = substr($contents, 1);
  2538. }
  2539. $contents .= "\n";
  2540. }
  2541. $inline_doc_state = STATE_INLINE_TEXT;
  2542. # Documentation block end */
  2543. } elsif (/$doc_inline_end/) {
  2544. if (($contents ne "") && ($contents ne "\n")) {
  2545. dump_section($file, $section, xml_escape($contents));
  2546. $section = $section_default;
  2547. $contents = "";
  2548. }
  2549. $state = STATE_PROTO;
  2550. $inline_doc_state = STATE_INLINE_NA;
  2551. # Regular text
  2552. } elsif (/$doc_content/) {
  2553. if ($inline_doc_state == STATE_INLINE_TEXT) {
  2554. $contents .= $1 . "\n";
  2555. } elsif ($inline_doc_state == STATE_INLINE_NAME) {
  2556. $inline_doc_state = STATE_INLINE_ERROR;
  2557. print STDERR "Warning(${file}:$.): ";
  2558. print STDERR "Incorrect use of kernel-doc format: $_";
  2559. ++$warnings;
  2560. }
  2561. }
  2562. } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype)
  2563. if (/$doc_inline_start/) {
  2564. $state = STATE_INLINE;
  2565. $inline_doc_state = STATE_INLINE_NAME;
  2566. } elsif ($decl_type eq 'function') {
  2567. process_state3_function($_, $file);
  2568. } else {
  2569. process_state3_type($_, $file);
  2570. }
  2571. } elsif ($state == STATE_DOCBLOCK) {
  2572. # Documentation block
  2573. if (/$doc_block/) {
  2574. dump_doc_section($file, $section, xml_escape($contents));
  2575. $contents = "";
  2576. $function = "";
  2577. %constants = ();
  2578. %parameterdescs = ();
  2579. %parametertypes = ();
  2580. @parameterlist = ();
  2581. %sections = ();
  2582. @sectionlist = ();
  2583. $prototype = "";
  2584. if ( $1 eq "" ) {
  2585. $section = $section_intro;
  2586. } else {
  2587. $section = $1;
  2588. }
  2589. }
  2590. elsif (/$doc_end/)
  2591. {
  2592. dump_doc_section($file, $section, xml_escape($contents));
  2593. $contents = "";
  2594. $function = "";
  2595. %constants = ();
  2596. %parameterdescs = ();
  2597. %parametertypes = ();
  2598. @parameterlist = ();
  2599. %sections = ();
  2600. @sectionlist = ();
  2601. $prototype = "";
  2602. $state = STATE_NORMAL;
  2603. }
  2604. elsif (/$doc_content/)
  2605. {
  2606. if ( $1 eq "" )
  2607. {
  2608. $contents .= $blankline;
  2609. }
  2610. else
  2611. {
  2612. $contents .= $1 . "\n";
  2613. }
  2614. }
  2615. }
  2616. }
  2617. if ($initial_section_counter == $section_counter) {
  2618. print STDERR "${file}:1: warning: no structured comments found\n";
  2619. if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) {
  2620. print STDERR " Was looking for '$_'.\n" for keys %function_table;
  2621. }
  2622. if ($output_mode eq "xml") {
  2623. # The template wants at least one RefEntry here; make one.
  2624. print "<refentry>\n";
  2625. print " <refnamediv>\n";
  2626. print " <refname>\n";
  2627. print " ${orig_file}\n";
  2628. print " </refname>\n";
  2629. print " <refpurpose>\n";
  2630. print " Document generation inconsistency\n";
  2631. print " </refpurpose>\n";
  2632. print " </refnamediv>\n";
  2633. print " <refsect1>\n";
  2634. print " <title>\n";
  2635. print " Oops\n";
  2636. print " </title>\n";
  2637. print " <warning>\n";
  2638. print " <para>\n";
  2639. print " The template for this document tried to insert\n";
  2640. print " the structured comment from the file\n";
  2641. print " <filename>${orig_file}</filename> at this point,\n";
  2642. print " but none was found.\n";
  2643. print " This dummy section is inserted to allow\n";
  2644. print " generation to continue.\n";
  2645. print " </para>\n";
  2646. print " </warning>\n";
  2647. print " </refsect1>\n";
  2648. print "</refentry>\n";
  2649. }
  2650. }
  2651. }
  2652. $kernelversion = get_kernel_version();
  2653. # generate a sequence of code that will splice in highlighting information
  2654. # using the s// operator.
  2655. for (my $k = 0; $k < @highlights; $k++) {
  2656. my $pattern = $highlights[$k][0];
  2657. my $result = $highlights[$k][1];
  2658. # print STDERR "scanning pattern:$pattern, highlight:($result)\n";
  2659. $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n";
  2660. }
  2661. # Read the file that maps relative names to absolute names for
  2662. # separate source and object directories and for shadow trees.
  2663. if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
  2664. my ($relname, $absname);
  2665. while(<SOURCE_MAP>) {
  2666. chop();
  2667. ($relname, $absname) = (split())[0..1];
  2668. $relname =~ s:^/+::;
  2669. $source_map{$relname} = $absname;
  2670. }
  2671. close(SOURCE_MAP);
  2672. }
  2673. foreach (@ARGV) {
  2674. chomp;
  2675. process_file($_);
  2676. }
  2677. if ($verbose && $errors) {
  2678. print STDERR "$errors errors\n";
  2679. }
  2680. if ($verbose && $warnings) {
  2681. print STDERR "$warnings warnings\n";
  2682. }
  2683. exit($errors);