wikiheaders.pl 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632
  1. #!/usr/bin/perl -w
  2. use warnings;
  3. use strict;
  4. use Text::Wrap;
  5. use File::Copy;
  6. $Text::Wrap::huge = 'overflow';
  7. my $projectfullname = 'Simple Directmedia Layer';
  8. my $projectshortname = 'SDL';
  9. my $wikisubdir = '';
  10. my $incsubdir = 'include';
  11. my $readmesubdir = undef;
  12. my $apiprefixregex = undef;
  13. my $versionfname = 'include/SDL_version.h';
  14. my $versionmajorregex = '\A\#define\s+SDL_MAJOR_VERSION\s+(\d+)\Z';
  15. my $versionminorregex = '\A\#define\s+SDL_MINOR_VERSION\s+(\d+)\Z';
  16. my $versionpatchregex = '\A\#define\s+SDL_PATCHLEVEL\s+(\d+)\Z';
  17. my $mainincludefname = 'SDL.h';
  18. my $selectheaderregex = '\ASDL.*?\.h\Z';
  19. my $projecturl = 'https://libsdl.org/';
  20. my $wikiurl = 'https://wiki.libsdl.org';
  21. my $bugreporturl = 'https://github.com/libsdl-org/sdlwiki/issues/new';
  22. my $srcpath = undef;
  23. my $wikipath = undef;
  24. my $wikireadmesubdir = 'README';
  25. my $warn_about_missing = 0;
  26. my $copy_direction = 0;
  27. my $optionsfname = undef;
  28. my $wikipreamble = undef;
  29. my $changeformat = undef;
  30. foreach (@ARGV) {
  31. $warn_about_missing = 1, next if $_ eq '--warn-about-missing';
  32. $copy_direction = 1, next if $_ eq '--copy-to-headers';
  33. $copy_direction = 1, next if $_ eq '--copy-to-header';
  34. $copy_direction = -1, next if $_ eq '--copy-to-wiki';
  35. $copy_direction = -2, next if $_ eq '--copy-to-manpages';
  36. if (/\A--options=(.*)\Z/) {
  37. $optionsfname = $1;
  38. next;
  39. } elsif (/\A--changeformat=(.*)\Z/) {
  40. $changeformat = $1;
  41. next;
  42. }
  43. $srcpath = $_, next if not defined $srcpath;
  44. $wikipath = $_, next if not defined $wikipath;
  45. }
  46. my $default_optionsfname = '.wikiheaders-options';
  47. $default_optionsfname = "$srcpath/$default_optionsfname" if defined $srcpath;
  48. if ((not defined $optionsfname) && (-f $default_optionsfname)) {
  49. $optionsfname = $default_optionsfname;
  50. }
  51. if (defined $optionsfname) {
  52. open OPTIONS, '<', $optionsfname or die("Failed to open options file '$optionsfname': $!\n");
  53. while (<OPTIONS>) {
  54. chomp;
  55. if (/\A(.*?)\=(.*)\Z/) {
  56. my $key = $1;
  57. my $val = $2;
  58. $key =~ s/\A\s+//;
  59. $key =~ s/\s+\Z//;
  60. $val =~ s/\A\s+//;
  61. $val =~ s/\s+\Z//;
  62. $warn_about_missing = int($val), next if $key eq 'warn_about_missing';
  63. $srcpath = $val, next if $key eq 'srcpath';
  64. $wikipath = $val, next if $key eq 'wikipath';
  65. $apiprefixregex = $val, next if $key eq 'apiprefixregex';
  66. $projectfullname = $val, next if $key eq 'projectfullname';
  67. $projectshortname = $val, next if $key eq 'projectshortname';
  68. $wikisubdir = $val, next if $key eq 'wikisubdir';
  69. $incsubdir = $val, next if $key eq 'incsubdir';
  70. $readmesubdir = $val, next if $key eq 'readmesubdir';
  71. $versionmajorregex = $val, next if $key eq 'versionmajorregex';
  72. $versionminorregex = $val, next if $key eq 'versionminorregex';
  73. $versionpatchregex = $val, next if $key eq 'versionpatchregex';
  74. $versionfname = $val, next if $key eq 'versionfname';
  75. $mainincludefname = $val, next if $key eq 'mainincludefname';
  76. $selectheaderregex = $val, next if $key eq 'selectheaderregex';
  77. $projecturl = $val, next if $key eq 'projecturl';
  78. $wikiurl = $val, next if $key eq 'wikiurl';
  79. $bugreporturl = $val, next if $key eq 'bugreporturl';
  80. $wikipreamble = $val, next if $key eq 'wikipreamble';
  81. }
  82. }
  83. close(OPTIONS);
  84. }
  85. my $wordwrap_mode = 'mediawiki';
  86. sub wordwrap_atom { # don't call this directly.
  87. my $str = shift;
  88. my $retval = '';
  89. # wordwrap but leave links intact, even if they overflow.
  90. if ($wordwrap_mode eq 'mediawiki') {
  91. while ($str =~ s/(.*?)\s*(\[https?\:\/\/.*?\s+.*?\])\s*//ms) {
  92. $retval .= fill('', '', $1); # wrap it.
  93. $retval .= "\n$2\n"; # don't wrap it.
  94. }
  95. } elsif ($wordwrap_mode eq 'md') {
  96. while ($str =~ s/(.*?)\s*(\[.*?\]\(https?\:\/\/.*?\))\s*//ms) {
  97. $retval .= fill('', '', $1); # wrap it.
  98. $retval .= "\n$2\n"; # don't wrap it.
  99. }
  100. }
  101. return $retval . fill('', '', $str);
  102. }
  103. sub wordwrap_with_bullet_indent { # don't call this directly.
  104. my $bullet = shift;
  105. my $str = shift;
  106. my $retval = '';
  107. #print("WORDWRAP BULLET ('$bullet'):\n\n$str\n\n");
  108. # You _can't_ (at least with Pandoc) have a bullet item with a newline in
  109. # MediaWiki, so _remove_ wrapping!
  110. if ($wordwrap_mode eq 'mediawiki') {
  111. $retval = "$bullet$str";
  112. $retval =~ s/\n/ /gms;
  113. $retval =~ s/\s+$//gms;
  114. #print("WORDWRAP BULLET DONE:\n\n$retval\n\n");
  115. return "$retval\n";
  116. }
  117. my $bulletlen = length($bullet);
  118. # wrap it and then indent each line to be under the bullet.
  119. $Text::Wrap::columns -= $bulletlen;
  120. my @wrappedlines = split /\n/, wordwrap_atom($str);
  121. $Text::Wrap::columns += $bulletlen;
  122. my $prefix = $bullet;
  123. my $usual_prefix = ' ' x $bulletlen;
  124. foreach (@wrappedlines) {
  125. s/\s*\Z//;
  126. $retval .= "$prefix$_\n";
  127. $prefix = $usual_prefix;
  128. }
  129. return $retval;
  130. }
  131. sub wordwrap_one_paragraph { # don't call this directly.
  132. my $retval = '';
  133. my $p = shift;
  134. #print "\n\n\nPARAGRAPH: [$p]\n\n\n";
  135. if ($p =~ s/\A([\*\-] )//) { # bullet list, starts with "* " or "- ".
  136. my $bullet = $1;
  137. my $item = '';
  138. my @items = split /\n/, $p;
  139. foreach (@items) {
  140. if (s/\A([\*\-] )//) {
  141. $retval .= wordwrap_with_bullet_indent($bullet, $item);
  142. $item = '';
  143. }
  144. s/\A\s*//;
  145. $item .= "$_\n"; # accumulate lines until we hit the end or another bullet.
  146. }
  147. if ($item ne '') {
  148. $retval .= wordwrap_with_bullet_indent($bullet, $item);
  149. }
  150. } else {
  151. $retval = wordwrap_atom($p) . "\n";
  152. }
  153. return $retval;
  154. }
  155. sub wordwrap_paragraphs { # don't call this directly.
  156. my $str = shift;
  157. my $retval = '';
  158. my @paragraphs = split /\n\n/, $str;
  159. foreach (@paragraphs) {
  160. next if $_ eq '';
  161. $retval .= wordwrap_one_paragraph($_);
  162. $retval .= "\n";
  163. }
  164. return $retval;
  165. }
  166. my $wordwrap_default_columns = 76;
  167. sub wordwrap {
  168. my $str = shift;
  169. my $columns = shift;
  170. $columns = $wordwrap_default_columns if not defined $columns;
  171. $columns += $wordwrap_default_columns if $columns < 0;
  172. $Text::Wrap::columns = $columns;
  173. my $retval = '';
  174. #print("\n\nWORDWRAP:\n\n$str\n\n\n");
  175. $str =~ s/\A\n+//ms;
  176. while ($str =~ s/(.*?)(\`\`\`.*?\`\`\`|\<syntaxhighlight.*?\<\/syntaxhighlight\>)//ms) {
  177. #print("\n\nWORDWRAP BLOCK:\n\n$1\n\n ===\n\n$2\n\n\n");
  178. $retval .= wordwrap_paragraphs($1); # wrap it.
  179. $retval .= "$2\n\n"; # don't wrap it.
  180. }
  181. $retval .= wordwrap_paragraphs($str); # wrap what's left.
  182. $retval =~ s/\n+\Z//ms;
  183. #print("\n\nWORDWRAP DONE:\n\n$retval\n\n\n");
  184. return $retval;
  185. }
  186. # This assumes you're moving from Markdown (in the Doxygen data) to Wiki, which
  187. # is why the 'md' section is so sparse.
  188. sub wikify_chunk {
  189. my $wikitype = shift;
  190. my $str = shift;
  191. my $codelang = shift;
  192. my $code = shift;
  193. #print("\n\nWIKIFY CHUNK:\n\n$str\n\n\n");
  194. if ($wikitype eq 'mediawiki') {
  195. # convert `code` things first, so they aren't mistaken for other markdown items.
  196. my $codedstr = '';
  197. while ($str =~ s/\A(.*?)\`(.*?)\`//ms) {
  198. my $codeblock = $2;
  199. $codedstr .= wikify_chunk($wikitype, $1, undef, undef);
  200. if (defined $apiprefixregex) {
  201. # Convert obvious API things to wikilinks, even inside `code` blocks.
  202. $codeblock =~ s/\b($apiprefixregex[a-zA-Z0-9_]+)/[[$1]]/gms;
  203. }
  204. $codedstr .= "<code>$codeblock</code>";
  205. }
  206. # Convert obvious API things to wikilinks.
  207. if (defined $apiprefixregex) {
  208. $str =~ s/\b($apiprefixregex[a-zA-Z0-9_]+)/[[$1]]/gms;
  209. }
  210. # Make some Markdown things into MediaWiki...
  211. # links
  212. $str =~ s/\[(.*?)\]\((https?\:\/\/.*?)\)/\[$2 $1\]/g;
  213. # bold+italic
  214. $str =~ s/\*\*\*(.*?)\*\*\*/'''''$1'''''/gms;
  215. # bold
  216. $str =~ s/\*\*(.*?)\*\*/'''$1'''/gms;
  217. # italic
  218. $str =~ s/\*(.*?)\*/''$1''/gms;
  219. # bullets
  220. $str =~ s/^\- /* /gm;
  221. $str = $codedstr . $str;
  222. if (defined $code) {
  223. $str .= "<syntaxhighlight lang='$codelang'>$code<\/syntaxhighlight>";
  224. }
  225. } elsif ($wikitype eq 'md') {
  226. # convert `code` things first, so they aren't mistaken for other markdown items.
  227. my $codedstr = '';
  228. while ($str =~ s/\A(.*?)(\`.*?\`)//ms) {
  229. my $codeblock = $2;
  230. $codedstr .= wikify_chunk($wikitype, $1, undef, undef);
  231. if (defined $apiprefixregex) {
  232. # Convert obvious API things to wikilinks, even inside `code` blocks,
  233. # BUT ONLY IF the entire code block is the API thing,
  234. # So something like "just call `SDL_Whatever`" will become
  235. # "just call [`SDL_Whatever`](SDL_Whatever)", but
  236. # "just call `SDL_Whatever(7)`" will not. It's just the safest
  237. # way to do this without resorting to wrapping things in html <code> tags.
  238. $codeblock =~ s/\A\`($apiprefixregex[a-zA-Z0-9_]+)\`\Z/[`$1`]($1)/gms;
  239. }
  240. $codedstr .= $codeblock;
  241. }
  242. # Convert obvious API things to wikilinks.
  243. if (defined $apiprefixregex) {
  244. $str =~ s/\b($apiprefixregex[a-zA-Z0-9_]+)/[$1]($1)/gms;
  245. }
  246. $str = $codedstr . $str;
  247. if (defined $code) {
  248. $str .= "```$codelang$code```";
  249. }
  250. }
  251. #print("\n\nWIKIFY CHUNK DONE:\n\n$str\n\n\n");
  252. return $str;
  253. }
  254. sub wikify {
  255. my $wikitype = shift;
  256. my $str = shift;
  257. my $retval = '';
  258. #print("WIKIFY WHOLE:\n\n$str\n\n\n");
  259. while ($str =~ s/\A(.*?)\`\`\`(c\+\+|c)(.*?)\`\`\`//ms) {
  260. $retval .= wikify_chunk($wikitype, $1, $2, $3);
  261. }
  262. $retval .= wikify_chunk($wikitype, $str, undef, undef);
  263. #print("WIKIFY WHOLE DONE:\n\n$retval\n\n\n");
  264. return $retval;
  265. }
  266. my $dewikify_mode = 'md';
  267. my $dewikify_manpage_code_indent = 1;
  268. sub dewikify_chunk {
  269. my $wikitype = shift;
  270. my $str = shift;
  271. my $codelang = shift;
  272. my $code = shift;
  273. #print("\n\nDEWIKIFY CHUNK:\n\n$str\n\n\n");
  274. if ($dewikify_mode eq 'md') {
  275. if ($wikitype eq 'mediawiki') {
  276. # Doxygen supports Markdown (and it just simply looks better than MediaWiki
  277. # when looking at the raw headers), so do some conversions here as necessary.
  278. # Dump obvious wikilinks.
  279. if (defined $apiprefixregex) {
  280. $str =~ s/\[\[($apiprefixregex[a-zA-Z0-9_]+)\]\]/$1/gms;
  281. }
  282. # links
  283. $str =~ s/\[(https?\:\/\/.*?)\s+(.*?)\]/\[$2\]\($1\)/g;
  284. # <code></code> is also popular. :/
  285. $str =~ s/\<code>(.*?)<\/code>/`$1`/gms;
  286. # bold+italic
  287. $str =~ s/'''''(.*?)'''''/***$1***/gms;
  288. # bold
  289. $str =~ s/'''(.*?)'''/**$1**/gms;
  290. # italic
  291. $str =~ s/''(.*?)''/*$1*/gms;
  292. # bullets
  293. $str =~ s/^\* /- /gm;
  294. } elsif ($wikitype eq 'md') {
  295. # Dump obvious wikilinks. The rest can just passthrough.
  296. if (defined $apiprefixregex) {
  297. $str =~ s/\[(\`?$apiprefixregex[a-zA-Z0-9_]+\`?)\]\($apiprefixregex[a-zA-Z0-9_]+\)/$1/gms;
  298. }
  299. }
  300. if (defined $code) {
  301. $str .= "```$codelang$code```";
  302. }
  303. } elsif ($dewikify_mode eq 'manpage') {
  304. $str =~ s/\./\\[char46]/gms; # make sure these can't become control codes.
  305. if ($wikitype eq 'mediawiki') {
  306. # Dump obvious wikilinks.
  307. if (defined $apiprefixregex) {
  308. $str =~ s/\s*\[\[($apiprefixregex[a-zA-Z0-9_]+)\]\]\s*/\n.BR $1\n/gms;
  309. }
  310. # links
  311. $str =~ s/\[(https?\:\/\/.*?)\s+(.*?)\]/\n.URL "$1" "$2"\n/g;
  312. # <code></code> is also popular. :/
  313. $str =~ s/\s*\<code>(.*?)<\/code>\s*/\n.BR $1\n/gms;
  314. # bold+italic
  315. $str =~ s/\s*'''''(.*?)'''''\s*/\n.BI $1\n/gms;
  316. # bold
  317. $str =~ s/\s*'''(.*?)'''\s*/\n.B $1\n/gms;
  318. # italic
  319. $str =~ s/\s*''(.*?)''\s*/\n.I $1\n/gms;
  320. # bullets
  321. $str =~ s/^\* /\n\\\(bu /gm;
  322. } elsif ($wikitype eq 'md') {
  323. # Dump obvious wikilinks.
  324. if (defined $apiprefixregex) {
  325. $str =~ s/\[(\`?$apiprefixregex[a-zA-Z0-9_]+\`?)\]\($apiprefixregex[a-zA-Z0-9_]+\)/\n.BR $1\n/gms;
  326. }
  327. # links
  328. $str =~ s/\[(.*?)]\((https?\:\/\/.*?)\)/\n.URL "$2" "$1"\n/g;
  329. # <code></code> is also popular. :/
  330. $str =~ s/\s*\`(.*?)\`\s*/\n.BR $1\n/gms;
  331. # bold+italic
  332. $str =~ s/\s*\*\*\*(.*?)\*\*\*\s*/\n.BI $1\n/gms;
  333. # bold
  334. $str =~ s/\s*\*\*(.*?)\*\*\s*/\n.B $1\n/gms;
  335. # italic
  336. $str =~ s/\s*\*(.*?)\*\s*/\n.I $1\n/gms;
  337. # bullets
  338. $str =~ s/^\- /\n\\\(bu /gm;
  339. } else {
  340. die("Unexpected wikitype when converting to manpages\n"); # !!! FIXME: need to handle Markdown wiki pages.
  341. }
  342. if (defined $code) {
  343. $code =~ s/\A\n+//gms;
  344. $code =~ s/\n+\Z//gms;
  345. if ($dewikify_manpage_code_indent) {
  346. $str .= "\n.IP\n"
  347. } else {
  348. $str .= "\n.PP\n"
  349. }
  350. $str .= ".EX\n$code\n.EE\n.PP\n";
  351. }
  352. } else {
  353. die("Unexpected dewikify_mode\n");
  354. }
  355. #print("\n\nDEWIKIFY CHUNK DONE:\n\n$str\n\n\n");
  356. return $str;
  357. }
  358. sub dewikify {
  359. my $wikitype = shift;
  360. my $str = shift;
  361. return '' if not defined $str;
  362. #print("DEWIKIFY WHOLE:\n\n$str\n\n\n");
  363. $str =~ s/\A[\s\n]*\= .*? \=\s*?\n+//ms;
  364. $str =~ s/\A[\s\n]*\=\= .*? \=\=\s*?\n+//ms;
  365. my $retval = '';
  366. while ($str =~ s/\A(.*?)<syntaxhighlight lang='?(.*?)'?>(.*?)<\/syntaxhighlight\>//ms) {
  367. $retval .= dewikify_chunk($wikitype, $1, $2, $3);
  368. }
  369. $retval .= dewikify_chunk($wikitype, $str, undef, undef);
  370. #print("DEWIKIFY WHOLE DONE:\n\n$retval\n\n\n");
  371. return $retval;
  372. }
  373. sub usage {
  374. die("USAGE: $0 <source code git clone path> <wiki git clone path> [--copy-to-headers|--copy-to-wiki|--copy-to-manpages] [--warn-about-missing]\n\n");
  375. }
  376. usage() if not defined $srcpath;
  377. usage() if not defined $wikipath;
  378. #usage() if $copy_direction == 0;
  379. my @standard_wiki_sections = (
  380. 'Draft',
  381. '[Brief]',
  382. 'Deprecated',
  383. 'Syntax',
  384. 'Function Parameters',
  385. 'Return Value',
  386. 'Remarks',
  387. 'Thread Safety',
  388. 'Version',
  389. 'Code Examples',
  390. 'Related Functions'
  391. );
  392. # Sections that only ever exist in the wiki and shouldn't be deleted when
  393. # not found in the headers.
  394. my %only_wiki_sections = ( # The ones don't mean anything, I just need to check for key existence.
  395. 'Draft', 1,
  396. 'Code Examples', 1
  397. );
  398. my %headers = (); # $headers{"SDL_audio.h"} -> reference to an array of all lines of text in SDL_audio.h.
  399. my %headerfuncs = (); # $headerfuncs{"SDL_OpenAudio"} -> string of header documentation for SDL_OpenAudio, with comment '*' bits stripped from the start. Newlines embedded!
  400. my %headerdecls = ();
  401. my %headerfuncslocation = (); # $headerfuncslocation{"SDL_OpenAudio"} -> name of header holding SDL_OpenAudio define ("SDL_audio.h" in this case).
  402. my %headerfuncschunk = (); # $headerfuncschunk{"SDL_OpenAudio"} -> offset in array in %headers that should be replaced for this function.
  403. my %headerfuncshasdoxygen = (); # $headerfuncschunk{"SDL_OpenAudio"} -> 1 if there was no existing doxygen for this function.
  404. my $incpath = "$srcpath";
  405. $incpath .= "/$incsubdir" if $incsubdir ne '';
  406. my $wikireadmepath = "$wikipath/$wikireadmesubdir";
  407. my $readmepath = undef;
  408. if (defined $readmesubdir) {
  409. $readmepath = "$srcpath/$readmesubdir";
  410. }
  411. opendir(DH, $incpath) or die("Can't opendir '$incpath': $!\n");
  412. while (readdir(DH)) {
  413. my $dent = $_;
  414. next if not $dent =~ /$selectheaderregex/; # just selected headers.
  415. open(FH, '<', "$incpath/$dent") or die("Can't open '$incpath/$dent': $!\n");
  416. my @contents = ();
  417. while (<FH>) {
  418. chomp;
  419. my $decl;
  420. my @templines;
  421. my $str;
  422. my $has_doxygen = 1;
  423. if (/\A\s*extern\s+(SDL_DEPRECATED\s+|)DECLSPEC/) { # a function declaration without a doxygen comment?
  424. @templines = ();
  425. $decl = $_;
  426. $str = '';
  427. $has_doxygen = 0;
  428. } elsif (not /\A\/\*\*\s*\Z/) { # not doxygen comment start?
  429. push @contents, $_;
  430. next;
  431. } else { # Start of a doxygen comment, parse it out.
  432. @templines = ( $_ );
  433. while (<FH>) {
  434. chomp;
  435. push @templines, $_;
  436. last if /\A\s*\*\/\Z/;
  437. if (s/\A\s*\*\s*\`\`\`/```/) { # this is a hack, but a lot of other code relies on the whitespace being trimmed, but we can't trim it in code blocks...
  438. $str .= "$_\n";
  439. while (<FH>) {
  440. chomp;
  441. push @templines, $_;
  442. s/\A\s*\*\s?//;
  443. if (s/\A\s*\`\`\`/```/) {
  444. $str .= "$_\n";
  445. last;
  446. } else {
  447. $str .= "$_\n";
  448. }
  449. }
  450. } else {
  451. s/\A\s*\*\s*//;
  452. $str .= "$_\n";
  453. }
  454. }
  455. $decl = <FH>;
  456. $decl = '' if not defined $decl;
  457. chomp($decl);
  458. if (not $decl =~ /\A\s*extern\s+(SDL_DEPRECATED\s+|)DECLSPEC/) {
  459. #print "Found doxygen but no function sig:\n$str\n\n";
  460. foreach (@templines) {
  461. push @contents, $_;
  462. }
  463. push @contents, $decl;
  464. next;
  465. }
  466. }
  467. my @decllines = ( $decl );
  468. if (not $decl =~ /\)\s*;/) {
  469. while (<FH>) {
  470. chomp;
  471. push @decllines, $_;
  472. s/\A\s+//;
  473. s/\s+\Z//;
  474. $decl .= " $_";
  475. last if /\)\s*;/;
  476. }
  477. }
  478. $decl =~ s/\s+\);\Z/);/;
  479. $decl =~ s/\s+\Z//;
  480. #print("DECL: [$decl]\n");
  481. my $fn = '';
  482. if ($decl =~ /\A\s*extern\s+(SDL_DEPRECATED\s+|)DECLSPEC\s+(const\s+|)(unsigned\s+|)(.*?)\s*(\*?)\s*SDLCALL\s+(.*?)\s*\((.*?)\);/) {
  483. $fn = $6;
  484. #$decl =~ s/\A\s*extern\s+DECLSPEC\s+(.*?)\s+SDLCALL/$1/;
  485. } else {
  486. #print "Found doxygen but no function sig:\n$str\n\n";
  487. foreach (@templines) {
  488. push @contents, $_;
  489. }
  490. foreach (@decllines) {
  491. push @contents, $_;
  492. }
  493. next;
  494. }
  495. $decl = ''; # build this with the line breaks, since it looks better for syntax highlighting.
  496. foreach (@decllines) {
  497. if ($decl eq '') {
  498. $decl = $_;
  499. $decl =~ s/\Aextern\s+(SDL_DEPRECATED\s+|)DECLSPEC\s+(.*?)\s+(\*?)SDLCALL\s+/$2$3 /;
  500. } else {
  501. my $trimmed = $_;
  502. # !!! FIXME: trim space for SDL_DEPRECATED if it was used, too.
  503. $trimmed =~ s/\A\s{24}//; # 24 for shrinking to match the removed "extern DECLSPEC SDLCALL "
  504. $decl .= $trimmed;
  505. }
  506. $decl .= "\n";
  507. }
  508. #print("$fn:\n$str\n\n");
  509. # There might be multiple declarations of a function due to #ifdefs,
  510. # and only one of them will have documentation. If we hit an
  511. # undocumented one before, delete the placeholder line we left for
  512. # it so it doesn't accumulate a new blank line on each run.
  513. my $skipfn = 0;
  514. if (defined $headerfuncshasdoxygen{$fn}) {
  515. if ($headerfuncshasdoxygen{$fn} == 0) { # An undocumented declaration already exists, nuke its placeholder line.
  516. delete $contents[$headerfuncschunk{$fn}]; # delete DOES NOT RENUMBER existing elements!
  517. } else { # documented function already existed?
  518. $skipfn = 1; # don't add this copy to the list of functions.
  519. if ($has_doxygen) {
  520. print STDERR "WARNING: Function '$fn' appears to be documented in multiple locations. Only keeping the first one we saw!\n";
  521. }
  522. push @contents, join("\n", @decllines); # just put the existing declation in as-is.
  523. }
  524. }
  525. if (!$skipfn) {
  526. $headerfuncs{$fn} = $str;
  527. $headerdecls{$fn} = $decl;
  528. $headerfuncslocation{$fn} = $dent;
  529. $headerfuncschunk{$fn} = scalar(@contents);
  530. $headerfuncshasdoxygen{$fn} = $has_doxygen;
  531. push @contents, join("\n", @templines);
  532. push @contents, join("\n", @decllines);
  533. }
  534. }
  535. close(FH);
  536. $headers{$dent} = \@contents;
  537. }
  538. closedir(DH);
  539. # !!! FIXME: we need to parse enums and typedefs and structs and defines and and and and and...
  540. # !!! FIXME: (but functions are good enough for now.)
  541. my %wikitypes = (); # contains string of wiki page extension, like $wikitypes{"SDL_OpenAudio"} == 'mediawiki'
  542. my %wikifuncs = (); # contains references to hash of strings, each string being the full contents of a section of a wiki page, like $wikifuncs{"SDL_OpenAudio"}{"Remarks"}.
  543. my %wikisectionorder = (); # contains references to array, each array item being a key to a wikipage section in the correct order, like $wikisectionorder{"SDL_OpenAudio"}[2] == 'Remarks'
  544. opendir(DH, $wikipath) or die("Can't opendir '$wikipath': $!\n");
  545. while (readdir(DH)) {
  546. my $dent = $_;
  547. my $type = '';
  548. if ($dent =~ /\.(md|mediawiki)\Z/) {
  549. $type = $1;
  550. } else {
  551. next; # only dealing with wiki pages.
  552. }
  553. my $fn = $dent;
  554. $fn =~ s/\..*\Z//;
  555. # Ignore FrontPage.
  556. next if $fn eq 'FrontPage';
  557. # Ignore "Category*" pages.
  558. next if ($fn =~ /\ACategory/);
  559. open(FH, '<', "$wikipath/$dent") or die("Can't open '$wikipath/$dent': $!\n");
  560. my $current_section = '[start]';
  561. my @section_order = ( $current_section );
  562. my %sections = ();
  563. $sections{$current_section} = '';
  564. my $firstline = 1;
  565. while (<FH>) {
  566. chomp;
  567. my $orig = $_;
  568. s/\A\s*//;
  569. s/\s*\Z//;
  570. if ($type eq 'mediawiki') {
  571. if (defined($wikipreamble) && $firstline && /\A\=\=\=\=\=\= (.*?) \=\=\=\=\=\=\Z/ && ($1 eq $wikipreamble)) {
  572. $firstline = 0; # skip this.
  573. next;
  574. } elsif (/\A\= (.*?) \=\Z/) {
  575. $firstline = 0;
  576. $current_section = ($1 eq $fn) ? '[Brief]' : $1;
  577. die("Doubly-defined section '$current_section' in '$dent'!\n") if defined $sections{$current_section};
  578. push @section_order, $current_section;
  579. $sections{$current_section} = '';
  580. } elsif (/\A\=\= (.*?) \=\=\Z/) {
  581. $firstline = 0;
  582. $current_section = ($1 eq $fn) ? '[Brief]' : $1;
  583. die("Doubly-defined section '$current_section' in '$dent'!\n") if defined $sections{$current_section};
  584. push @section_order, $current_section;
  585. $sections{$current_section} = '';
  586. next;
  587. } elsif (/\A\-\-\-\-\Z/) {
  588. $firstline = 0;
  589. $current_section = '[footer]';
  590. die("Doubly-defined section '$current_section' in '$dent'!\n") if defined $sections{$current_section};
  591. push @section_order, $current_section;
  592. $sections{$current_section} = '';
  593. next;
  594. }
  595. } elsif ($type eq 'md') {
  596. if (defined($wikipreamble) && $firstline && /\A\#\#\#\#\#\# (.*?)\Z/ && ($1 eq $wikipreamble)) {
  597. $firstline = 0; # skip this.
  598. next;
  599. } elsif (/\A\#+ (.*?)\Z/) {
  600. $firstline = 0;
  601. $current_section = ($1 eq $fn) ? '[Brief]' : $1;
  602. die("Doubly-defined section '$current_section' in '$dent'!\n") if defined $sections{$current_section};
  603. push @section_order, $current_section;
  604. $sections{$current_section} = '';
  605. next;
  606. } elsif (/\A\-\-\-\-\Z/) {
  607. $firstline = 0;
  608. $current_section = '[footer]';
  609. die("Doubly-defined section '$current_section' in '$dent'!\n") if defined $sections{$current_section};
  610. push @section_order, $current_section;
  611. $sections{$current_section} = '';
  612. next;
  613. }
  614. } else {
  615. die("Unexpected wiki file type. Fixme!\n");
  616. }
  617. if ($firstline) {
  618. $firstline = ($_ ne '');
  619. }
  620. if (!$firstline) {
  621. $sections{$current_section} .= "$orig\n";
  622. }
  623. }
  624. close(FH);
  625. foreach (keys %sections) {
  626. $sections{$_} =~ s/\A\n+//;
  627. $sections{$_} =~ s/\n+\Z//;
  628. $sections{$_} .= "\n";
  629. }
  630. if (0) {
  631. foreach (@section_order) {
  632. print("$fn SECTION '$_':\n");
  633. print($sections{$_});
  634. print("\n\n");
  635. }
  636. }
  637. $wikitypes{$fn} = $type;
  638. $wikifuncs{$fn} = \%sections;
  639. $wikisectionorder{$fn} = \@section_order;
  640. }
  641. closedir(DH);
  642. if ($warn_about_missing) {
  643. foreach (keys %wikifuncs) {
  644. my $fn = $_;
  645. if (not defined $headerfuncs{$fn}) {
  646. print("WARNING: $fn defined in the wiki but not the headers!\n");
  647. }
  648. }
  649. foreach (keys %headerfuncs) {
  650. my $fn = $_;
  651. if (not defined $wikifuncs{$fn}) {
  652. print("WARNING: $fn defined in the headers but not the wiki!\n");
  653. }
  654. }
  655. }
  656. if ($copy_direction == 1) { # --copy-to-headers
  657. my %changed_headers = ();
  658. $dewikify_mode = 'md';
  659. $wordwrap_mode = 'md'; # the headers use Markdown format.
  660. foreach (keys %headerfuncs) {
  661. my $fn = $_;
  662. next if not defined $wikifuncs{$fn}; # don't have a page for that function, skip it.
  663. my $wikitype = $wikitypes{$fn};
  664. my $sectionsref = $wikifuncs{$fn};
  665. my $remarks = %$sectionsref{'Remarks'};
  666. my $params = %$sectionsref{'Function Parameters'};
  667. my $returns = %$sectionsref{'Return Value'};
  668. my $threadsafety = %$sectionsref{'Thread Safety'};
  669. my $version = %$sectionsref{'Version'};
  670. my $related = %$sectionsref{'Related Functions'};
  671. my $deprecated = %$sectionsref{'Deprecated'};
  672. my $brief = %$sectionsref{'[Brief]'};
  673. my $addblank = 0;
  674. my $str = '';
  675. $headerfuncshasdoxygen{$fn} = 1; # Added/changed doxygen for this header.
  676. $brief = dewikify($wikitype, $brief);
  677. $brief =~ s/\A(.*?\.) /$1\n/; # \brief should only be one sentence, delimited by a period+space. Split if necessary.
  678. my @briefsplit = split /\n/, $brief;
  679. $brief = shift @briefsplit;
  680. if (defined $remarks) {
  681. $remarks = join("\n", @briefsplit) . dewikify($wikitype, $remarks);
  682. }
  683. if (defined $brief) {
  684. $str .= "\n" if $addblank; $addblank = 1;
  685. $str .= wordwrap($brief) . "\n";
  686. }
  687. if (defined $remarks) {
  688. $str .= "\n" if $addblank; $addblank = 1;
  689. $str .= wordwrap($remarks) . "\n";
  690. }
  691. if (defined $deprecated) {
  692. # !!! FIXME: lots of code duplication in all of these.
  693. $str .= "\n" if $addblank; $addblank = 1;
  694. my $v = dewikify($wikitype, $deprecated);
  695. my $whitespacelen = length("\\deprecated") + 1;
  696. my $whitespace = ' ' x $whitespacelen;
  697. $v = wordwrap($v, -$whitespacelen);
  698. my @desclines = split /\n/, $v;
  699. my $firstline = shift @desclines;
  700. $str .= "\\deprecated $firstline\n";
  701. foreach (@desclines) {
  702. $str .= "${whitespace}$_\n";
  703. }
  704. }
  705. if (defined $params) {
  706. $str .= "\n" if $addblank; $addblank = (defined $returns) ? 0 : 1;
  707. my @lines = split /\n/, dewikify($wikitype, $params);
  708. if ($wikitype eq 'mediawiki') {
  709. die("Unexpected data parsing MediaWiki table") if (shift @lines ne '{|'); # Dump the '{|' start
  710. while (scalar(@lines) >= 3) {
  711. my $name = shift @lines;
  712. my $desc = shift @lines;
  713. my $terminator = shift @lines; # the '|-' or '|}' line.
  714. last if ($terminator ne '|-') and ($terminator ne '|}'); # we seem to have run out of table.
  715. $name =~ s/\A\|\s*//;
  716. $name =~ s/\A\*\*(.*?)\*\*/$1/;
  717. $name =~ s/\A\'\'\'(.*?)\'\'\'/$1/;
  718. $desc =~ s/\A\|\s*//;
  719. #print STDERR "FN: $fn NAME: $name DESC: $desc TERM: $terminator\n";
  720. my $whitespacelen = length($name) + 8;
  721. my $whitespace = ' ' x $whitespacelen;
  722. $desc = wordwrap($desc, -$whitespacelen);
  723. my @desclines = split /\n/, $desc;
  724. my $firstline = shift @desclines;
  725. $str .= "\\param $name $firstline\n";
  726. foreach (@desclines) {
  727. $str .= "${whitespace}$_\n";
  728. }
  729. }
  730. } elsif ($wikitype eq 'md') {
  731. my $l;
  732. $l = shift @lines;
  733. die("Unexpected data parsing Markdown table") if (not $l =~ /\A\s*\|\s*\|\s*\|\s*\Z/);
  734. $l = shift @lines;
  735. die("Unexpected data parsing Markdown table") if (not $l =~ /\A\s*\|\s*\-*\s*\|\s*\-*\s*\|\s*\Z/);
  736. while (scalar(@lines) >= 1) {
  737. $l = shift @lines;
  738. if ($l =~ /\A\s*\|\s*(.*?)\s*\|\s*(.*?)\s*\|\s*\Z/) {
  739. my $name = $1;
  740. my $desc = $2;
  741. $name =~ s/\A\*\*(.*?)\*\*/$1/;
  742. $name =~ s/\A\'\'\'(.*?)\'\'\'/$1/;
  743. #print STDERR "FN: $fn NAME: $name DESC: $desc\n";
  744. my $whitespacelen = length($name) + 8;
  745. my $whitespace = ' ' x $whitespacelen;
  746. $desc = wordwrap($desc, -$whitespacelen);
  747. my @desclines = split /\n/, $desc;
  748. my $firstline = shift @desclines;
  749. $str .= "\\param $name $firstline\n";
  750. foreach (@desclines) {
  751. $str .= "${whitespace}$_\n";
  752. }
  753. } else {
  754. last; # we seem to have run out of table.
  755. }
  756. }
  757. } else {
  758. die("write me");
  759. }
  760. }
  761. if (defined $returns) {
  762. $str .= "\n" if $addblank; $addblank = 1;
  763. my $r = dewikify($wikitype, $returns);
  764. my $retstr = "\\returns";
  765. if ($r =~ s/\AReturn(s?) //) {
  766. $retstr = "\\return$1";
  767. }
  768. my $whitespacelen = length($retstr) + 1;
  769. my $whitespace = ' ' x $whitespacelen;
  770. $r = wordwrap($r, -$whitespacelen);
  771. my @desclines = split /\n/, $r;
  772. my $firstline = shift @desclines;
  773. $str .= "$retstr $firstline\n";
  774. foreach (@desclines) {
  775. $str .= "${whitespace}$_\n";
  776. }
  777. }
  778. if (defined $threadsafety) {
  779. # !!! FIXME: lots of code duplication in all of these.
  780. $str .= "\n" if $addblank; $addblank = 1;
  781. my $v = dewikify($wikitype, $threadsafety);
  782. my $whitespacelen = length("\\threadsafety") + 1;
  783. my $whitespace = ' ' x $whitespacelen;
  784. $v = wordwrap($v, -$whitespacelen);
  785. my @desclines = split /\n/, $v;
  786. my $firstline = shift @desclines;
  787. $str .= "\\threadsafety $firstline\n";
  788. foreach (@desclines) {
  789. $str .= "${whitespace}$_\n";
  790. }
  791. }
  792. if (defined $version) {
  793. # !!! FIXME: lots of code duplication in all of these.
  794. $str .= "\n" if $addblank; $addblank = 1;
  795. my $v = dewikify($wikitype, $version);
  796. my $whitespacelen = length("\\since") + 1;
  797. my $whitespace = ' ' x $whitespacelen;
  798. $v = wordwrap($v, -$whitespacelen);
  799. my @desclines = split /\n/, $v;
  800. my $firstline = shift @desclines;
  801. $str .= "\\since $firstline\n";
  802. foreach (@desclines) {
  803. $str .= "${whitespace}$_\n";
  804. }
  805. }
  806. if (defined $related) {
  807. # !!! FIXME: lots of code duplication in all of these.
  808. $str .= "\n" if $addblank; $addblank = 1;
  809. my $v = dewikify($wikitype, $related);
  810. my @desclines = split /\n/, $v;
  811. foreach (@desclines) {
  812. s/\A(\:|\* )//;
  813. s/\(\)\Z//; # Convert "SDL_Func()" to "SDL_Func"
  814. s/\[\[(.*?)\]\]/$1/; # in case some wikilinks remain.
  815. s/\[(.*?)\]\(.*?\)/$1/; # in case some wikilinks remain.
  816. s/\A\/*//;
  817. $str .= "\\sa $_\n";
  818. }
  819. }
  820. my $header = $headerfuncslocation{$fn};
  821. my $contentsref = $headers{$header};
  822. my $chunk = $headerfuncschunk{$fn};
  823. my @lines = split /\n/, $str;
  824. my $addnewline = (($chunk > 0) && ($$contentsref[$chunk-1] ne '')) ? "\n" : '';
  825. my $output = "$addnewline/**\n";
  826. foreach (@lines) {
  827. chomp;
  828. s/\s*\Z//;
  829. if ($_ eq '') {
  830. $output .= " *\n";
  831. } else {
  832. $output .= " * $_\n";
  833. }
  834. }
  835. $output .= " */";
  836. #print("$fn:\n$output\n\n");
  837. $$contentsref[$chunk] = $output;
  838. #$$contentsref[$chunk+1] = $headerdecls{$fn};
  839. $changed_headers{$header} = 1;
  840. }
  841. foreach (keys %changed_headers) {
  842. my $header = $_;
  843. # this is kinda inefficient, but oh well.
  844. my @removelines = ();
  845. foreach (keys %headerfuncslocation) {
  846. my $fn = $_;
  847. next if $headerfuncshasdoxygen{$fn};
  848. next if $headerfuncslocation{$fn} ne $header;
  849. # the index of the blank line we put before the function declaration in case we needed to replace it with new content from the wiki.
  850. push @removelines, $headerfuncschunk{$fn};
  851. }
  852. my $contentsref = $headers{$header};
  853. foreach (@removelines) {
  854. delete $$contentsref[$_]; # delete DOES NOT RENUMBER existing elements!
  855. }
  856. my $path = "$incpath/$header.tmp";
  857. open(FH, '>', $path) or die("Can't open '$path': $!\n");
  858. foreach (@$contentsref) {
  859. print FH "$_\n" if defined $_;
  860. }
  861. close(FH);
  862. rename($path, "$incpath/$header") or die("Can't rename '$path' to '$incpath/$header': $!\n");
  863. }
  864. if (defined $readmepath) {
  865. if ( -d $wikireadmepath ) {
  866. mkdir($readmepath); # just in case
  867. opendir(DH, $wikireadmepath) or die("Can't opendir '$wikireadmepath': $!\n");
  868. while (readdir(DH)) {
  869. my $dent = $_;
  870. if ($dent =~ /\A(.*?)\.md\Z/) { # we only bridge Markdown files here.
  871. copy("$wikireadmepath/$dent", "$readmepath/README-$dent") or die("failed to copy '$wikireadmepath/$dent' to '$readmepath/README-$dent': $!\n");
  872. }
  873. }
  874. closedir(DH);
  875. }
  876. }
  877. } elsif ($copy_direction == -1) { # --copy-to-wiki
  878. if (defined $changeformat) {
  879. $dewikify_mode = $changeformat;
  880. $wordwrap_mode = $changeformat;
  881. }
  882. foreach (keys %headerfuncs) {
  883. my $fn = $_;
  884. next if not $headerfuncshasdoxygen{$fn};
  885. my $origwikitype = defined $wikitypes{$fn} ? $wikitypes{$fn} : 'md'; # default to MarkDown for new stuff.
  886. my $wikitype = (defined $changeformat) ? $changeformat : $origwikitype;
  887. die("Unexpected wikitype '$wikitype'\n") if (($wikitype ne 'mediawiki') and ($wikitype ne 'md') and ($wikitype ne 'manpage'));
  888. #print("$fn\n"); next;
  889. $wordwrap_mode = $wikitype;
  890. my $raw = $headerfuncs{$fn}; # raw doxygen text with comment characters stripped from start/end and start of each line.
  891. next if not defined $raw;
  892. $raw =~ s/\A\s*\\brief\s+//; # Technically we don't need \brief (please turn on JAVADOC_AUTOBRIEF if you use Doxygen), so just in case one is present, strip it.
  893. my @doxygenlines = split /\n/, $raw;
  894. my $brief = '';
  895. while (@doxygenlines) {
  896. last if $doxygenlines[0] =~ /\A\\/; # some sort of doxygen command, assume we're past the general remarks.
  897. last if $doxygenlines[0] =~ /\A\s*\Z/; # blank line? End of paragraph, done.
  898. my $l = shift @doxygenlines;
  899. chomp($l);
  900. $l =~ s/\A\s*//;
  901. $l =~ s/\s*\Z//;
  902. $brief .= "$l ";
  903. }
  904. $brief =~ s/\A(.*?\.) /$1\n\n/; # \brief should only be one sentence, delimited by a period+space. Split if necessary.
  905. my @briefsplit = split /\n/, $brief;
  906. $brief = wikify($wikitype, shift @briefsplit) . "\n";
  907. @doxygenlines = (@briefsplit, @doxygenlines);
  908. my $remarks = '';
  909. # !!! FIXME: wordwrap and wikify might handle this, now.
  910. while (@doxygenlines) {
  911. last if $doxygenlines[0] =~ /\A\\/; # some sort of doxygen command, assume we're past the general remarks.
  912. my $l = shift @doxygenlines;
  913. if ($l =~ /\A\`\`\`/) { # syntax highlighting, don't reformat.
  914. $remarks .= "$l\n";
  915. while ((@doxygenlines) && (not $l =~ /\`\`\`\Z/)) {
  916. $l = shift @doxygenlines;
  917. $remarks .= "$l\n";
  918. }
  919. } else {
  920. $l =~ s/\A\s*//;
  921. $l =~ s/\s*\Z//;
  922. $remarks .= "$l\n";
  923. }
  924. }
  925. #print("REMARKS:\n\n $remarks\n\n");
  926. $remarks = wordwrap(wikify($wikitype, $remarks));
  927. $remarks =~ s/\A\s*//;
  928. $remarks =~ s/\s*\Z//;
  929. my $decl = $headerdecls{$fn};
  930. #$decl =~ s/\*\s+SDLCALL/ *SDLCALL/; # Try to make "void * Function" become "void *Function"
  931. #$decl =~ s/\A\s*extern\s+(SDL_DEPRECATED\s+|)DECLSPEC\s+(.*?)\s+(\*?)SDLCALL/$2$3/;
  932. my $syntax = '';
  933. if ($wikitype eq 'mediawiki') {
  934. $syntax = "<syntaxhighlight lang='c'>\n$decl</syntaxhighlight>\n";
  935. } elsif ($wikitype eq 'md') {
  936. $syntax = "```c\n$decl\n```\n";
  937. } else { die("Expected wikitype '$wikitype'\n"); }
  938. my %sections = ();
  939. $sections{'[Brief]'} = $brief; # include this section even if blank so we get a title line.
  940. $sections{'Remarks'} = "$remarks\n" if $remarks ne '';
  941. $sections{'Syntax'} = $syntax;
  942. my @params = (); # have to parse these and build up the wiki tables after, since Markdown needs to know the length of the largest string. :/
  943. while (@doxygenlines) {
  944. my $l = shift @doxygenlines;
  945. if ($l =~ /\A\\param\s+(.*?)\s+(.*)\Z/) {
  946. my $arg = $1;
  947. my $desc = $2;
  948. while (@doxygenlines) {
  949. my $subline = $doxygenlines[0];
  950. $subline =~ s/\A\s*//;
  951. last if $subline =~ /\A\\/; # some sort of doxygen command, assume we're past this thing.
  952. shift @doxygenlines; # dump this line from the array; we're using it.
  953. if ($subline eq '') { # empty line, make sure it keeps the newline char.
  954. $desc .= "\n";
  955. } else {
  956. $desc .= " $subline";
  957. }
  958. }
  959. $desc =~ s/[\s\n]+\Z//ms;
  960. # We need to know the length of the longest string to make Markdown tables, so we just store these off until everything is parsed.
  961. push @params, $arg;
  962. push @params, $desc;
  963. } elsif ($l =~ /\A\\r(eturns?)\s+(.*)\Z/) {
  964. my $retstr = "R$1"; # "Return" or "Returns"
  965. my $desc = $2;
  966. while (@doxygenlines) {
  967. my $subline = $doxygenlines[0];
  968. $subline =~ s/\A\s*//;
  969. last if $subline =~ /\A\\/; # some sort of doxygen command, assume we're past this thing.
  970. shift @doxygenlines; # dump this line from the array; we're using it.
  971. if ($subline eq '') { # empty line, make sure it keeps the newline char.
  972. $desc .= "\n";
  973. } else {
  974. $desc .= " $subline";
  975. }
  976. }
  977. $desc =~ s/[\s\n]+\Z//ms;
  978. $sections{'Return Value'} = wordwrap("$retstr " . wikify($wikitype, $desc)) . "\n";
  979. } elsif ($l =~ /\A\\deprecated\s+(.*)\Z/) {
  980. my $desc = $1;
  981. while (@doxygenlines) {
  982. my $subline = $doxygenlines[0];
  983. $subline =~ s/\A\s*//;
  984. last if $subline =~ /\A\\/; # some sort of doxygen command, assume we're past this thing.
  985. shift @doxygenlines; # dump this line from the array; we're using it.
  986. if ($subline eq '') { # empty line, make sure it keeps the newline char.
  987. $desc .= "\n";
  988. } else {
  989. $desc .= " $subline";
  990. }
  991. }
  992. $desc =~ s/[\s\n]+\Z//ms;
  993. $sections{'Deprecated'} = wordwrap(wikify($wikitype, $desc)) . "\n";
  994. } elsif ($l =~ /\A\\since\s+(.*)\Z/) {
  995. my $desc = $1;
  996. while (@doxygenlines) {
  997. my $subline = $doxygenlines[0];
  998. $subline =~ s/\A\s*//;
  999. last if $subline =~ /\A\\/; # some sort of doxygen command, assume we're past this thing.
  1000. shift @doxygenlines; # dump this line from the array; we're using it.
  1001. if ($subline eq '') { # empty line, make sure it keeps the newline char.
  1002. $desc .= "\n";
  1003. } else {
  1004. $desc .= " $subline";
  1005. }
  1006. }
  1007. $desc =~ s/[\s\n]+\Z//ms;
  1008. $sections{'Version'} = wordwrap(wikify($wikitype, $desc)) . "\n";
  1009. } elsif ($l =~ /\A\\threadsafety\s+(.*)\Z/) {
  1010. my $desc = $1;
  1011. while (@doxygenlines) {
  1012. my $subline = $doxygenlines[0];
  1013. $subline =~ s/\A\s*//;
  1014. last if $subline =~ /\A\\/; # some sort of doxygen command, assume we're past this thing.
  1015. shift @doxygenlines; # dump this line from the array; we're using it.
  1016. if ($subline eq '') { # empty line, make sure it keeps the newline char.
  1017. $desc .= "\n";
  1018. } else {
  1019. $desc .= " $subline";
  1020. }
  1021. }
  1022. $desc =~ s/[\s\n]+\Z//ms;
  1023. $sections{'Thread Safety'} = wordwrap(wikify($wikitype, $desc)) . "\n";
  1024. } elsif ($l =~ /\A\\sa\s+(.*)\Z/) {
  1025. my $sa = $1;
  1026. $sa =~ s/\(\)\Z//; # Convert "SDL_Func()" to "SDL_Func"
  1027. $sections{'Related Functions'} = '' if not defined $sections{'Related Functions'};
  1028. if ($wikitype eq 'mediawiki') {
  1029. $sections{'Related Functions'} .= ":[[$sa]]\n";
  1030. } elsif ($wikitype eq 'md') {
  1031. $sections{'Related Functions'} .= "* [$sa]($sa)\n";
  1032. } else { die("Expected wikitype '$wikitype'\n"); }
  1033. }
  1034. }
  1035. # Make sure this ends with a double-newline.
  1036. $sections{'Related Functions'} .= "\n" if defined $sections{'Related Functions'};
  1037. # We can build the wiki table now that we have all the data.
  1038. if (scalar(@params) > 0) {
  1039. my $str = '';
  1040. if ($wikitype eq 'mediawiki') {
  1041. while (scalar(@params) > 0) {
  1042. my $arg = shift @params;
  1043. my $desc = wikify($wikitype, shift @params);
  1044. $str .= ($str eq '') ? "{|\n" : "|-\n";
  1045. $str .= "|'''$arg'''\n";
  1046. $str .= "|$desc\n";
  1047. }
  1048. $str .= "|}\n";
  1049. } elsif ($wikitype eq 'md') {
  1050. my $longest_arg = 0;
  1051. my $longest_desc = 0;
  1052. my $which = 0;
  1053. foreach (@params) {
  1054. if ($which == 0) {
  1055. my $len = length($_) + 4;
  1056. $longest_arg = $len if ($len > $longest_arg);
  1057. $which = 1;
  1058. } else {
  1059. my $len = length(wikify($wikitype, $_));
  1060. $longest_desc = $len if ($len > $longest_desc);
  1061. $which = 0;
  1062. }
  1063. }
  1064. # Markdown tables are sort of obnoxious.
  1065. $str .= '| ' . (' ' x ($longest_arg+4)) . ' | ' . (' ' x $longest_desc) . " |\n";
  1066. $str .= '| ' . ('-' x ($longest_arg+4)) . ' | ' . ('-' x $longest_desc) . " |\n";
  1067. while (@params) {
  1068. my $arg = shift @params;
  1069. my $desc = wikify($wikitype, shift @params);
  1070. $str .= "| **$arg** " . (' ' x ($longest_arg - length($arg))) . "| $desc" . (' ' x ($longest_desc - length($desc))) . " |\n";
  1071. }
  1072. } else {
  1073. die("Unexpected wikitype!\n"); # should have checked this elsewhere.
  1074. }
  1075. $sections{'Function Parameters'} = $str;
  1076. }
  1077. my $path = "$wikipath/$_.${wikitype}.tmp";
  1078. open(FH, '>', $path) or die("Can't open '$path': $!\n");
  1079. my $sectionsref = $wikifuncs{$fn};
  1080. foreach (@standard_wiki_sections) {
  1081. # drop sections we either replaced or removed from the original wiki's contents.
  1082. if (not defined $only_wiki_sections{$_}) {
  1083. delete($$sectionsref{$_});
  1084. }
  1085. }
  1086. my $wikisectionorderref = $wikisectionorder{$fn};
  1087. # Make sure there's a footer in the wiki that puts this function in CategoryAPI...
  1088. if (not $$sectionsref{'[footer]'}) {
  1089. $$sectionsref{'[footer]'} = '';
  1090. push @$wikisectionorderref, '[footer]';
  1091. }
  1092. # If changing format, convert things that otherwise are passed through unmolested.
  1093. if (defined $changeformat) {
  1094. if (($dewikify_mode eq 'md') and ($origwikitype eq 'mediawiki')) {
  1095. $$sectionsref{'[footer]'} =~ s/\[\[(Category[a-zA-Z0-9_]+)\]\]/[$1]($1)/g;
  1096. } elsif (($dewikify_mode eq 'mediawiki') and ($origwikitype eq 'md')) {
  1097. $$sectionsref{'[footer]'} =~ s/\[(Category[a-zA-Z0-9_]+)\]\(.*?\)/[[$1]]/g;
  1098. }
  1099. foreach (keys %only_wiki_sections) {
  1100. my $sect = $_;
  1101. if (defined $$sectionsref{$sect}) {
  1102. $$sectionsref{$sect} = wikify($wikitype, dewikify($origwikitype, $$sectionsref{$sect}));
  1103. }
  1104. }
  1105. }
  1106. # !!! FIXME: This won't be CategoryAPI if we eventually handle things other than functions.
  1107. my $footer = $$sectionsref{'[footer]'};
  1108. if ($wikitype eq 'mediawiki') {
  1109. $footer =~ s/\[\[CategoryAPI\]\],?\s*//g;
  1110. $footer = '[[CategoryAPI]]' . (($footer eq '') ? "\n" : ", $footer");
  1111. } elsif ($wikitype eq 'md') {
  1112. $footer =~ s/\[CategoryAPI\]\(CategoryAPI\),?\s*//g;
  1113. $footer = '[CategoryAPI](CategoryAPI)' . (($footer eq '') ? '' : ', ') . $footer;
  1114. } else { die("Unexpected wikitype '$wikitype'\n"); }
  1115. $$sectionsref{'[footer]'} = $footer;
  1116. if (defined $wikipreamble) {
  1117. my $wikified_preamble = wikify($wikitype, $wikipreamble);
  1118. if ($wikitype eq 'mediawiki') {
  1119. print FH "====== $wikified_preamble ======\n";
  1120. } elsif ($wikitype eq 'md') {
  1121. print FH "###### $wikified_preamble\n";
  1122. } else { die("Unexpected wikitype '$wikitype'\n"); }
  1123. }
  1124. my $prevsectstr = '';
  1125. my @ordered_sections = (@standard_wiki_sections, defined $wikisectionorderref ? @$wikisectionorderref : ()); # this copies the arrays into one.
  1126. foreach (@ordered_sections) {
  1127. my $sect = $_;
  1128. next if $sect eq '[start]';
  1129. next if (not defined $sections{$sect} and not defined $$sectionsref{$sect});
  1130. my $section = defined $sections{$sect} ? $sections{$sect} : $$sectionsref{$sect};
  1131. if ($sect eq '[footer]') {
  1132. # Make sure previous section ends with two newlines.
  1133. if (substr($prevsectstr, -1) ne "\n") {
  1134. print FH "\n\n";
  1135. } elsif (substr($prevsectstr, -2) ne "\n\n") {
  1136. print FH "\n";
  1137. }
  1138. print FH "----\n"; # It's the same in Markdown and MediaWiki.
  1139. } elsif ($sect eq '[Brief]') {
  1140. if ($wikitype eq 'mediawiki') {
  1141. print FH "= $fn =\n\n";
  1142. } elsif ($wikitype eq 'md') {
  1143. print FH "# $fn\n\n";
  1144. } else { die("Unexpected wikitype '$wikitype'\n"); }
  1145. } else {
  1146. if ($wikitype eq 'mediawiki') {
  1147. print FH "\n== $sect ==\n\n";
  1148. } elsif ($wikitype eq 'md') {
  1149. print FH "\n## $sect\n\n";
  1150. } else { die("Unexpected wikitype '$wikitype'\n"); }
  1151. }
  1152. my $sectstr = defined $sections{$sect} ? $sections{$sect} : $$sectionsref{$sect};
  1153. print FH $sectstr;
  1154. $prevsectstr = $sectstr;
  1155. # make sure these don't show up twice.
  1156. delete($sections{$sect});
  1157. delete($$sectionsref{$sect});
  1158. }
  1159. print FH "\n\n";
  1160. close(FH);
  1161. if (defined $changeformat and ($origwikitype ne $wikitype)) {
  1162. system("cd '$wikipath' ; git mv '$_.${origwikitype}' '$_.${wikitype}'");
  1163. unlink("$wikipath/$_.${origwikitype}");
  1164. }
  1165. rename($path, "$wikipath/$_.${wikitype}") or die("Can't rename '$path' to '$wikipath/$_.${wikitype}': $!\n");
  1166. }
  1167. if (defined $readmepath) {
  1168. if ( -d $readmepath ) {
  1169. mkdir($wikireadmepath); # just in case
  1170. opendir(DH, $readmepath) or die("Can't opendir '$readmepath': $!\n");
  1171. while (readdir(DH)) {
  1172. my $dent = $_;
  1173. if ($dent =~ /\AREADME\-(.*?\.md)\Z/) { # we only bridge Markdown files here.
  1174. my $wikifname = $1;
  1175. copy("$readmepath/$dent", "$wikireadmepath/$wikifname") or die("failed to copy '$readmepath/$dent' to '$wikireadmepath/$wikifname': $!\n");
  1176. }
  1177. }
  1178. closedir(DH);
  1179. open(FH, '>', "$wikireadmepath/FrontPage.md") or die("Can't open '$wikireadmepath/FrontPage.md': $!\n");
  1180. print FH "# All READMEs available here\n\n";
  1181. opendir(DH, $wikireadmepath) or die("Can't opendir '$wikireadmepath': $!\n");
  1182. while (readdir(DH)) {
  1183. my $dent = $_;
  1184. if ($dent =~ /\A(.*?)\.(mediawiki|md)\Z/) {
  1185. my $wikiname = $1;
  1186. print FH "- [$wikiname]($wikiname)\n";
  1187. }
  1188. }
  1189. closedir(DH);
  1190. close(FH);
  1191. }
  1192. }
  1193. } elsif ($copy_direction == -2) { # --copy-to-manpages
  1194. # This only takes from the wiki data, since it has sections we omit from the headers, like code examples.
  1195. my $manpath = "$srcpath/man";
  1196. mkdir($manpath);
  1197. $manpath .= "/man3";
  1198. mkdir($manpath);
  1199. $dewikify_mode = 'manpage';
  1200. $wordwrap_mode = 'manpage';
  1201. my $introtxt = '';
  1202. if (0) {
  1203. open(FH, '<', "$srcpath/LICENSE.txt") or die("Can't open '$srcpath/LICENSE.txt': $!\n");
  1204. while (<FH>) {
  1205. chomp;
  1206. $introtxt .= ".\\\" $_\n";
  1207. }
  1208. close(FH);
  1209. }
  1210. my $gitrev = `cd "$srcpath" ; git rev-list HEAD~..`;
  1211. chomp($gitrev);
  1212. # !!! FIXME
  1213. open(FH, '<', "$srcpath/$versionfname") or die("Can't open '$srcpath/$versionfname': $!\n");
  1214. my $majorver = 0;
  1215. my $minorver = 0;
  1216. my $patchver = 0;
  1217. while (<FH>) {
  1218. chomp;
  1219. if (/$versionmajorregex/) {
  1220. $majorver = int($1);
  1221. } elsif (/$versionminorregex/) {
  1222. $minorver = int($1);
  1223. } elsif (/$versionpatchregex/) {
  1224. $patchver = int($1);
  1225. }
  1226. }
  1227. close(FH);
  1228. my $fullversion = "$majorver.$minorver.$patchver";
  1229. foreach (keys %headerfuncs) {
  1230. my $fn = $_;
  1231. next if not defined $wikifuncs{$fn}; # don't have a page for that function, skip it.
  1232. my $wikitype = $wikitypes{$fn};
  1233. my $sectionsref = $wikifuncs{$fn};
  1234. my $remarks = %$sectionsref{'Remarks'};
  1235. my $params = %$sectionsref{'Function Parameters'};
  1236. my $returns = %$sectionsref{'Return Value'};
  1237. my $version = %$sectionsref{'Version'};
  1238. my $threadsafety = %$sectionsref{'Thread Safety'};
  1239. my $related = %$sectionsref{'Related Functions'};
  1240. my $examples = %$sectionsref{'Code Examples'};
  1241. my $deprecated = %$sectionsref{'Deprecated'};
  1242. my $brief = %$sectionsref{'[Brief]'};
  1243. my $decl = $headerdecls{$fn};
  1244. my $str = '';
  1245. $brief = "$brief";
  1246. $brief =~ s/\A[\s\n]*\= .*? \=\s*?\n+//ms;
  1247. $brief =~ s/\A[\s\n]*\=\= .*? \=\=\s*?\n+//ms;
  1248. $brief =~ s/\A(.*?\.) /$1\n/; # \brief should only be one sentence, delimited by a period+space. Split if necessary.
  1249. my @briefsplit = split /\n/, $brief;
  1250. $brief = shift @briefsplit;
  1251. $brief = dewikify($wikitype, $brief);
  1252. if (defined $remarks) {
  1253. $remarks = dewikify($wikitype, join("\n", @briefsplit) . $remarks);
  1254. }
  1255. $str .= $introtxt;
  1256. $str .= ".\\\" This manpage content is licensed under Creative Commons\n";
  1257. $str .= ".\\\" Attribution 4.0 International (CC BY 4.0)\n";
  1258. $str .= ".\\\" https://creativecommons.org/licenses/by/4.0/\n";
  1259. $str .= ".\\\" This manpage was generated from ${projectshortname}'s wiki page for $fn:\n";
  1260. $str .= ".\\\" $wikiurl/$fn\n";
  1261. $str .= ".\\\" Generated with SDL/build-scripts/wikiheaders.pl\n";
  1262. $str .= ".\\\" revision $gitrev\n" if $gitrev ne '';
  1263. $str .= ".\\\" Please report issues in this manpage's content at:\n";
  1264. $str .= ".\\\" $bugreporturl\n";
  1265. $str .= ".\\\" Please report issues in the generation of this manpage from the wiki at:\n";
  1266. $str .= ".\\\" https://github.com/libsdl-org/SDL/issues/new?title=Misgenerated%20manpage%20for%20$fn\n";
  1267. $str .= ".\\\" $projectshortname can be found at $projecturl\n";
  1268. # Define a .URL macro. The "www.tmac" thing decides if we're using GNU roff (which has a .URL macro already), and if so, overrides the macro we just created.
  1269. # This wizadry is from https://web.archive.org/web/20060102165607/http://people.debian.org/~branden/talks/wtfm/wtfm.pdf
  1270. $str .= ".de URL\n";
  1271. $str .= '\\$2 \(laURL: \\$1 \(ra\\$3' . "\n";
  1272. $str .= "..\n";
  1273. $str .= '.if \n[.g] .mso www.tmac' . "\n";
  1274. $str .= ".TH $fn 3 \"$projectshortname $fullversion\" \"$projectfullname\" \"$projectshortname$majorver FUNCTIONS\"\n";
  1275. $str .= ".SH NAME\n";
  1276. $str .= "$fn";
  1277. $str .= " \\- $brief" if (defined $brief);
  1278. $str .= "\n";
  1279. $str .= ".SH SYNOPSIS\n";
  1280. $str .= ".nf\n";
  1281. $str .= ".B #include \\(dq$mainincludefname\\(dq\n";
  1282. $str .= ".PP\n";
  1283. my @decllines = split /\n/, $decl;
  1284. foreach (@decllines) {
  1285. $str .= ".BI \"$_\n";
  1286. }
  1287. $str .= ".fi\n";
  1288. if (defined $remarks) {
  1289. $str .= ".SH DESCRIPTION\n";
  1290. $str .= $remarks . "\n";
  1291. }
  1292. if (defined $deprecated) {
  1293. $str .= ".SH DEPRECATED\n";
  1294. $str .= dewikify($wikitype, $deprecated) . "\n";
  1295. }
  1296. if (defined $params) {
  1297. $str .= ".SH FUNCTION PARAMETERS\n";
  1298. my @lines = split /\n/, $params;
  1299. if ($wikitype eq 'mediawiki') {
  1300. die("Unexpected data parsing MediaWiki table") if (shift @lines ne '{|'); # Dump the '{|' start
  1301. while (scalar(@lines) >= 3) {
  1302. my $name = shift @lines;
  1303. my $desc = shift @lines;
  1304. my $terminator = shift @lines; # the '|-' or '|}' line.
  1305. last if ($terminator ne '|-') and ($terminator ne '|}'); # we seem to have run out of table.
  1306. $name =~ s/\A\|\s*//;
  1307. $name =~ s/\A\*\*(.*?)\*\*/$1/;
  1308. $name =~ s/\A\'\'\'(.*?)\'\'\'/$1/;
  1309. $desc =~ s/\A\|\s*//;
  1310. $desc = dewikify($wikitype, $desc);
  1311. #print STDERR "FN: $fn NAME: $name DESC: $desc TERM: $terminator\n";
  1312. $str .= ".TP\n";
  1313. $str .= ".I $name\n";
  1314. $str .= "$desc\n";
  1315. }
  1316. } elsif ($wikitype eq 'md') {
  1317. my $l;
  1318. $l = shift @lines;
  1319. die("Unexpected data parsing Markdown table") if (not $l =~ /\A\s*\|\s*\|\s*\|\s*\Z/);
  1320. $l = shift @lines;
  1321. die("Unexpected data parsing Markdown table") if (not $l =~ /\A\s*\|\s*\-*\s*\|\s*\-*\s*\|\s*\Z/);
  1322. while (scalar(@lines) >= 1) {
  1323. $l = shift @lines;
  1324. if ($l =~ /\A\s*\|\s*(.*?)\s*\|\s*(.*?)\s*\|\s*\Z/) {
  1325. my $name = $1;
  1326. my $desc = $2;
  1327. $name =~ s/\A\*\*(.*?)\*\*/$1/;
  1328. $name =~ s/\A\'\'\'(.*?)\'\'\'/$1/;
  1329. $desc = dewikify($wikitype, $desc);
  1330. $str .= ".TP\n";
  1331. $str .= ".I $name\n";
  1332. $str .= "$desc\n";
  1333. } else {
  1334. last; # we seem to have run out of table.
  1335. }
  1336. }
  1337. } else {
  1338. die("write me");
  1339. }
  1340. }
  1341. if (defined $returns) {
  1342. $str .= ".SH RETURN VALUE\n";
  1343. $str .= dewikify($wikitype, $returns) . "\n";
  1344. }
  1345. if (defined $examples) {
  1346. $str .= ".SH CODE EXAMPLES\n";
  1347. $dewikify_manpage_code_indent = 0;
  1348. $str .= dewikify($wikitype, $examples) . "\n";
  1349. $dewikify_manpage_code_indent = 1;
  1350. }
  1351. if (defined $threadsafety) {
  1352. $str .= ".SH THREAD SAFETY\n";
  1353. $str .= dewikify($wikitype, $threadsafety) . "\n";
  1354. }
  1355. if (defined $version) {
  1356. $str .= ".SH AVAILABILITY\n";
  1357. $str .= dewikify($wikitype, $version) . "\n";
  1358. }
  1359. if (defined $related) {
  1360. $str .= ".SH SEE ALSO\n";
  1361. # !!! FIXME: lots of code duplication in all of these.
  1362. my $v = dewikify($wikitype, $related);
  1363. my @desclines = split /\n/, $v;
  1364. my $nextstr = '';
  1365. foreach (@desclines) {
  1366. s/\A(\:|\* )//;
  1367. s/\(\)\Z//; # Convert "SDL_Func()" to "SDL_Func"
  1368. s/\[\[(.*?)\]\]/$1/; # in case some wikilinks remain.
  1369. s/\[(.*?)\]\(.*?\)/$1/; # in case some wikilinks remain.
  1370. s/\A\*\s*\Z//;
  1371. s/\A\/*//;
  1372. s/\A\.BR\s+//; # dewikify added this, but we want to handle it.
  1373. s/\A\.I\s+//; # dewikify added this, but we want to handle it.
  1374. s/\A\s+//;
  1375. s/\s+\Z//;
  1376. next if $_ eq '';
  1377. $str .= "$nextstr.BR $_ (3)";
  1378. $nextstr = ",\n";
  1379. }
  1380. $str .= "\n";
  1381. }
  1382. if (0) {
  1383. $str .= ".SH COPYRIGHT\n";
  1384. $str .= "This manpage is licensed under\n";
  1385. $str .= ".UR https://creativecommons.org/licenses/by/4.0/\n";
  1386. $str .= "Creative Commons Attribution 4.0 International (CC BY 4.0)\n";
  1387. $str .= ".UE\n";
  1388. $str .= ".PP\n";
  1389. $str .= "This manpage was generated from\n";
  1390. $str .= ".UR $wikiurl/$fn\n";
  1391. $str .= "${projectshortname}'s wiki\n";
  1392. $str .= ".UE\n";
  1393. $str .= "using SDL/build-scripts/wikiheaders.pl";
  1394. $str .= " revision $gitrev" if $gitrev ne '';
  1395. $str .= ".\n";
  1396. $str .= "Please report issues in this manpage at\n";
  1397. $str .= ".UR $bugreporturl\n";
  1398. $str .= "our bugtracker!\n";
  1399. $str .= ".UE\n";
  1400. }
  1401. my $path = "$manpath/$_.3.tmp";
  1402. open(FH, '>', $path) or die("Can't open '$path': $!\n");
  1403. print FH $str;
  1404. close(FH);
  1405. rename($path, "$manpath/$_.3") or die("Can't rename '$path' to '$manpath/$_.3': $!\n");
  1406. }
  1407. }
  1408. # end of wikiheaders.pl ...