kernel-doc 93 KB

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