kernel-doc 83 KB

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