winapi_parser.pm 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. #
  2. # Copyright 1999, 2000, 2001 Patrik Stridvall
  3. #
  4. # This library is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU Lesser General Public
  6. # License as published by the Free Software Foundation; either
  7. # version 2.1 of the License, or (at your option) any later version.
  8. #
  9. # This library is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. # Lesser General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Lesser General Public
  15. # License along with this library; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  17. #
  18. package winapi_parser;
  19. use strict;
  20. use output qw($output);
  21. use options qw($options);
  22. # Defined a couple common regexp tidbits
  23. my $CALL_CONVENTION="__cdecl|__stdcall|" .
  24. "__RPC_API|__RPC_STUB|__RPC_USER|RPC_ENTRY|" .
  25. "RPC_VAR_ENTRY|STDMETHODCALLTYPE|NET_API_FUNCTION|" .
  26. "CALLBACK|CDECL|NTAPI|PASCAL|APIENTRY|" .
  27. "SEC_ENTRY|VFWAPI|VFWAPIV|WINGDIPAPI|WMIAPI|WINAPI|WINAPIV|";
  28. sub parse_c_file($$) {
  29. my $file = shift;
  30. my $callbacks = shift;
  31. my $empty_callback = sub { };
  32. my $c_comment_found_callback = $$callbacks{c_comment_found} || $empty_callback;
  33. my $cplusplus_comment_found_callback = $$callbacks{cplusplus_comment_found} || $empty_callback;
  34. my $function_create_callback = $$callbacks{function_create} || $empty_callback;
  35. my $function_found_callback = $$callbacks{function_found} || $empty_callback;
  36. my $type_create_callback = $$callbacks{type_create} || $empty_callback;
  37. my $type_found_callback = $$callbacks{type_found} || $empty_callback;
  38. my $preprocessor_found_callback = $$callbacks{preprocessor_found} || $empty_callback;
  39. # global
  40. my $debug_channels = [];
  41. my $in_function = 0;
  42. my $function_begin;
  43. my $function_end;
  44. {
  45. my $documentation_line;
  46. my $documentation;
  47. my $function_line;
  48. my $linkage;
  49. my $return_type;
  50. my $calling_convention;
  51. my $internal_name = "";
  52. my $argument_types;
  53. my $argument_names;
  54. my $argument_documentations;
  55. my $statements_line;
  56. my $statements;
  57. $function_begin = sub {
  58. $documentation_line = shift;
  59. $documentation = shift;
  60. $function_line = shift;
  61. $linkage = shift;
  62. $return_type= shift;
  63. $calling_convention = shift;
  64. $internal_name = shift;
  65. $argument_types = shift;
  66. $argument_names = shift;
  67. $argument_documentations = shift;
  68. if(defined($argument_names) && defined($argument_types) &&
  69. $#$argument_names == -1)
  70. {
  71. foreach my $n (0..$#$argument_types) {
  72. push @$argument_names, "";
  73. }
  74. }
  75. if(defined($argument_documentations) &&
  76. $#$argument_documentations == -1)
  77. {
  78. foreach my $n (0..$#$argument_documentations) {
  79. push @$argument_documentations, "";
  80. }
  81. }
  82. $in_function = 1;
  83. };
  84. $function_end = sub {
  85. $statements_line = shift;
  86. $statements = shift;
  87. my $function = &$function_create_callback();
  88. if(!defined($documentation_line)) {
  89. $documentation_line = 0;
  90. }
  91. $function->file($file);
  92. $function->debug_channels([@$debug_channels]);
  93. $function->documentation_line($documentation_line);
  94. $function->documentation($documentation);
  95. $function->function_line($function_line);
  96. $function->linkage($linkage);
  97. $function->return_type($return_type);
  98. $function->calling_convention($calling_convention);
  99. $function->internal_name($internal_name);
  100. if(defined($argument_types)) {
  101. $function->argument_types([@$argument_types]);
  102. }
  103. if(defined($argument_names)) {
  104. $function->argument_names([@$argument_names]);
  105. }
  106. if(defined($argument_documentations)) {
  107. $function->argument_documentations([@$argument_documentations]);
  108. }
  109. $function->statements_line($statements_line);
  110. $function->statements($statements);
  111. &$function_found_callback($function);
  112. $in_function = 0;
  113. };
  114. }
  115. my $in_type = 0;
  116. my $type_begin;
  117. my $type_end;
  118. {
  119. my $type;
  120. $type_begin = sub {
  121. $type = shift;
  122. $in_type = 1;
  123. };
  124. $type_end = sub {
  125. my $names = shift;
  126. foreach my $name (@$names) {
  127. if($type =~ /^(?:enum|interface|struct|union)/) {
  128. # $output->write("typedef $type {\n");
  129. # $output->write("} $name;\n");
  130. } else {
  131. # $output->write("typedef $type $name;\n");
  132. }
  133. }
  134. $in_type = 0;
  135. };
  136. }
  137. my %regs_entrypoints;
  138. my @comment_lines = ();
  139. my @comments = ();
  140. my $statements_line;
  141. my $statements;
  142. my $level = 0;
  143. my $extern_c = 0;
  144. my $again = 0;
  145. my $lookahead = 0;
  146. my $lookahead_count = 0;
  147. print STDERR "Processing file '$file' ... " if $options->verbose;
  148. open(IN, "< $file") || die "<internal>: $file: $!\n";
  149. local $_ = "";
  150. readmore: while($again || defined(my $line = <IN>)) {
  151. $_ = "" if !defined($_);
  152. if(!$again) {
  153. chomp $line;
  154. if($lookahead) {
  155. $lookahead = 0;
  156. $_ .= "\n" . $line;
  157. $lookahead_count++;
  158. } else {
  159. $_ = $line;
  160. $lookahead_count = 0;
  161. }
  162. $output->write(" $level($lookahead_count): $line\n") if $options->debug >= 2;
  163. $output->write("*** $_\n") if $options->debug >= 3;
  164. } else {
  165. $lookahead_count = 0;
  166. $again = 0;
  167. }
  168. # CVS merge conflicts in file?
  169. if(/^(<<<<<<<|=======|>>>>>>>)/) {
  170. $output->write("$file: merge conflicts in file\n");
  171. last;
  172. }
  173. my $prefix="";
  174. while ($_ ne "")
  175. {
  176. if (s/^([^\"\/]+|\"(?:[^\\\"]*|\\.)*\")//)
  177. {
  178. $prefix.=$1;
  179. }
  180. elsif (/^\/\*/)
  181. {
  182. # remove C comments
  183. if(s/^(\/\*.*?\*\/)//s) {
  184. my @lines = split(/\n/, $1);
  185. push @comment_lines, $.;
  186. push @comments, $1;
  187. &$c_comment_found_callback($. - $#lines, $., $1);
  188. if($#lines <= 0) {
  189. $_ = "$prefix $_";
  190. } else {
  191. $_ = $prefix . ("\n" x $#lines) . $_;
  192. }
  193. $again = 1;
  194. } else {
  195. $_ = "$prefix$_";
  196. $lookahead = 1;
  197. }
  198. next readmore;
  199. }
  200. elsif (s/^(\/\/.*)$//)
  201. {
  202. # remove C++ comments
  203. &$cplusplus_comment_found_callback($., $1);
  204. $again = 1;
  205. }
  206. elsif (s/^(.)//)
  207. {
  208. $prefix.=$1;
  209. }
  210. }
  211. $_=$prefix;
  212. # remove preprocessor directives
  213. if(s/^\s*\#/\#/s) {
  214. if(/^(\#.*?)\\$/s) {
  215. $_ = "$1\n";
  216. $lookahead = 1;
  217. next;
  218. } elsif(s/^\#\s*(\w+)((?:\s+(.*?))?\s*)$//s) {
  219. my @lines = split(/\n/, $2);
  220. if($#lines > 0) {
  221. $_ = "\n" x $#lines;
  222. }
  223. if(defined($3)) {
  224. &$preprocessor_found_callback($1, $3);
  225. } else {
  226. &$preprocessor_found_callback($1, "");
  227. }
  228. $again = 1;
  229. next;
  230. }
  231. }
  232. # Remove extern "C"
  233. if(s/^\s*extern\s+"C"\s+\{//m) {
  234. $extern_c = 1;
  235. $again = 1;
  236. next;
  237. }
  238. my $documentation_line;
  239. my $documentation;
  240. my @argument_documentations = ();
  241. {
  242. my $n = $#comments;
  243. while($n >= 0 && ($comments[$n] !~ /^\/\*\*/ ||
  244. $comments[$n] =~ /^\/\*\*+\/$/))
  245. {
  246. $n--;
  247. }
  248. if(defined($comments[$n]) && $n >= 0) {
  249. my @lines = split(/\n/, $comments[$n]);
  250. $documentation_line = $comment_lines[$n] - scalar(@lines) + 1;
  251. $documentation = $comments[$n];
  252. for(my $m=$n+1; $m <= $#comments; $m++) {
  253. if($comments[$m] =~ /^\/\*\*+\/$/ ||
  254. $comments[$m] =~ /^\/\*\s*(?:\!)?defined/) # FIXME: Kludge
  255. {
  256. @argument_documentations = ();
  257. next;
  258. }
  259. push @argument_documentations, $comments[$m];
  260. }
  261. } else {
  262. $documentation = "";
  263. }
  264. }
  265. if($level > 0)
  266. {
  267. my $line = "";
  268. while(/^[^\{\}]/) {
  269. s/^([^\{\}\'\"]*)//s;
  270. $line .= $1;
  271. if(s/^\'//) {
  272. $line .= "\'";
  273. while(/^./ && !s/^\'//) {
  274. s/^([^\'\\]*)//s;
  275. $line .= $1;
  276. if(s/^\\//) {
  277. $line .= "\\";
  278. if(s/^(.)//s) {
  279. $line .= $1;
  280. if($1 eq "0") {
  281. s/^(\d{0,3})//s;
  282. $line .= $1;
  283. }
  284. }
  285. }
  286. }
  287. $line .= "\'";
  288. } elsif(s/^\"//) {
  289. $line .= "\"";
  290. while(/^./ && !s/^\"//) {
  291. s/^([^\"\\]*)//s;
  292. $line .= $1;
  293. if(s/^\\//) {
  294. $line .= "\\";
  295. if(s/^(.)//s) {
  296. $line .= $1;
  297. if($1 eq "0") {
  298. s/^(\d{0,3})//s;
  299. $line .= $1;
  300. }
  301. }
  302. }
  303. }
  304. $line .= "\"";
  305. }
  306. }
  307. if(s/^\{//) {
  308. $_ = $'; $again = 1;
  309. $line .= "{";
  310. print "+1: \{$_\n" if $options->debug >= 2;
  311. $level++;
  312. $statements .= $line;
  313. } elsif(s/^\}//) {
  314. $_ = $'; $again = 1;
  315. $line .= "}" if $level > 1;
  316. print "-1: \}$_\n" if $options->debug >= 2;
  317. $level--;
  318. if($level == -1 && $extern_c) {
  319. $extern_c = 0;
  320. $level = 0;
  321. }
  322. $statements .= $line;
  323. } else {
  324. $statements .= "$line\n";
  325. }
  326. if($level == 0) {
  327. if($in_function) {
  328. &$function_end($statements_line, $statements);
  329. $statements = undef;
  330. } elsif($in_type) {
  331. if(/^\s*((?:(?:FAR\s*)?\*\s*(?:RESTRICTED_POINTER\s+)?)?
  332. (?:volatile\s+)?
  333. (?:\w+|WS\(\w+\))\s*
  334. (?:\s*,\s*(?:(?:FAR\s*)?\*+\s*(?:RESTRICTED_POINTER\s+)?)?(?:volatile\s+)?(?:\w+|WS\(\w+\)))*\s*);/sx) {
  335. my @parts = split(/\s*,\s*/, $1);
  336. &$type_end([@parts]);
  337. } elsif(/;/s) {
  338. die "$file: $.: syntax error: '$_'\n";
  339. } else {
  340. $lookahead = 1;
  341. }
  342. }
  343. }
  344. next;
  345. } elsif(/(extern\s+|static\s+)?((interface\s+|struct\s+|union\s+|enum\s+|signed\s+|unsigned\s+)?\w+((\s*\*)+\s*|\s+))
  346. (($CALL_CONVENTION)\s+)?
  347. (?:DECLSPEC_HOTPATCH\s+)?
  348. (\w+(\(\w+\))?)\s*\((.*?)\)\s*(\{|\;)/sx)
  349. {
  350. my @lines = split(/\n/, $&);
  351. my $function_line = $. - scalar(@lines) + 1;
  352. $_ = $'; $again = 1;
  353. if($11 eq "{") {
  354. $level++;
  355. }
  356. my $linkage = $1;
  357. my $return_type = $2;
  358. my $calling_convention = $7;
  359. my $name = $8;
  360. my $arguments = $10;
  361. if(!defined($linkage)) {
  362. $linkage = "";
  363. }
  364. if(!defined($calling_convention)) {
  365. $calling_convention = "";
  366. }
  367. $linkage =~ s/\s*$//;
  368. $return_type =~ s/\s*$//;
  369. $return_type =~ s/\s*\*\s*/*/g;
  370. $return_type =~ s/(\*+)/ $1/g;
  371. if($regs_entrypoints{$name}) {
  372. $name = $regs_entrypoints{$name};
  373. }
  374. $arguments =~ y/\t\n/ /;
  375. $arguments =~ s/^\s*(.*?)\s*$/$1/;
  376. if($arguments eq "") { $arguments = "..." }
  377. my @argument_types;
  378. my @argument_names;
  379. my @arguments;
  380. my $n = 0;
  381. while ($arguments =~ s/^((?:[^,\(\)]*|(?:\([^\)]*\))?)+)(?:,|$)// && $1) {
  382. my $argument = $1;
  383. push @arguments, $argument;
  384. my $argument_type = "";
  385. my $argument_name = "";
  386. $argument =~ s/^\s*(.*?)\s*$/$1/;
  387. # print " " . ($n + 1) . ": '$argument'\n";
  388. $argument =~ s/^(?:IN OUT|IN|OUT)?\s+//;
  389. $argument =~ s/^(?:const|CONST|GDIPCONST|volatile)?\s+//;
  390. if($argument =~ /^\.\.\.$/) {
  391. $argument_type = "...";
  392. $argument_name = "...";
  393. } elsif($argument =~ /^
  394. ((?:interface\s+|struct\s+|union\s+|enum\s+|register\s+|(?:signed\s+|unsigned\s+)?
  395. (?:short\s+(?=int)|long\s+(?=int))?)?(?:\w+|ElfW\(\w+\)|WS\(\w+\)))\s*
  396. ((?:__RPC_FAR|const|CONST|GDIPCONST|volatile)?\s*(?:\*\s*(?:__RPC_FAR|const|CONST|volatile)?\s*?)*)\s*
  397. (\w*)\s*(\[\])?(?:\s+OPTIONAL)?$/x)
  398. {
  399. $argument_type = $1;
  400. if ($2) {
  401. $argument_type .= " $2";
  402. }
  403. if ($4) {
  404. $argument_type .= "$4";
  405. }
  406. $argument_name = $3;
  407. } elsif ($argument =~ /^
  408. ((?:interface\s+|struct\s+|union\s+|enum\s+|register\s+|(?:signed\s+|unsigned\s+)?
  409. (?:short\s+(?=int)|long\s+(?=int))?)?\w+)\s*
  410. ((?:const|volatile)?\s*(?:\*\s*(?:const|volatile)?\s*?)*)\s*
  411. (?:(?:$CALL_CONVENTION)\s+)?
  412. \(\s*(?:$CALL_CONVENTION)?\s*\*\s*((?:\w+)?)\s*\)\s*
  413. \(\s*(.*?)\s*\)$/x)
  414. {
  415. my $return_type = $1;
  416. if($2) {
  417. $return_type .= " $2";
  418. }
  419. $argument_name = $3;
  420. my $arguments = $4;
  421. $return_type =~ s/\s+/ /g;
  422. $arguments =~ s/\s*,\s*/,/g;
  423. $argument_type = "$return_type (*)($arguments)";
  424. } elsif ($argument =~ /^
  425. ((?:interface\s+|struct\s+|union\s+|enum\s+|register\s+|(?:signed\s+|unsigned\s+)
  426. (?:short\s+(?=int)|long\s+(?=int))?)?\w+)\s*
  427. ((?:const|volatile)?\s*(?:\*\s*(?:const|volatile)?\s*?)*)\s*
  428. (\w+)\s*\[\s*(.*?)\s*\](?:\[\s*(.*?)\s*\])?$/x)
  429. {
  430. my $return_type = $1;
  431. if($2) {
  432. $return_type .= " $2";
  433. }
  434. $argument_name = $3;
  435. $argument_type = "$return_type\[$4\]";
  436. if (defined($5)) {
  437. $argument_type .= "\[$5\]";
  438. }
  439. # die "$file: $.: syntax error: '$argument_type':'$argument_name'\n";
  440. } else {
  441. die "$file: $.: syntax error: '$argument'\n";
  442. }
  443. $argument_type =~ s/\s*(?:const|volatile)\s*/ /g; # Remove const/volatile
  444. $argument_type =~ s/([^\*\(\s])\*/$1 \*/g; # Assure whitespace between non-* and *
  445. $argument_type =~ s/,([^\s])/, $1/g; # Assure whitespace after ,
  446. $argument_type =~ s/\*\s+\*/\*\*/g; # Remove whitespace between * and *
  447. $argument_type =~ s/([\(\[])\s+/$1/g; # Remove whitespace after ( and [
  448. $argument_type =~ s/\s+([\)\]])/$1/g; # Remove whitespace before ] and )
  449. $argument_type =~ s/\s+/ /; # Remove multiple whitespace
  450. $argument_type =~ s/^\s*(.*?)\s*$/$1/; # Remove leading and trailing whitespace
  451. $argument_name =~ s/^\s*(.*?)\s*$/$1/; # Remove leading and trailing whitespace
  452. $argument_types[$n] = $argument_type;
  453. $argument_names[$n] = $argument_name;
  454. # print " " . ($n + 1) . ": '" . $argument_types[$n] . "', '" . $argument_names[$n] . "'\n";
  455. $n++;
  456. }
  457. if($#argument_types == 0 && $argument_types[0] =~ /^void$/i) {
  458. $#argument_types = -1;
  459. $#argument_names = -1;
  460. }
  461. if($options->debug) {
  462. print "$file: $return_type $calling_convention $name(" . join(",", @arguments) . ")\n";
  463. }
  464. &$function_begin($documentation_line, $documentation,
  465. $function_line, $linkage, $return_type, $calling_convention, $name,
  466. \@argument_types,\@argument_names,\@argument_documentations);
  467. if($level == 0) {
  468. &$function_end(undef, undef);
  469. }
  470. $statements_line = $.;
  471. $statements = "";
  472. } elsif(/__ASM_GLOBAL_FUNC\(\s*(.*?)\s*,/s) {
  473. my @lines = split(/\n/, $&);
  474. my $function_line = $. - scalar(@lines) + 1;
  475. $_ = $'; $again = 1;
  476. &$function_begin($documentation_line, $documentation,
  477. $function_line, "", "void", "__asm", $1);
  478. &$function_end($., "");
  479. } elsif(/DEFINE_THISCALL_WRAPPER\((\S*)\)/s) {
  480. my @lines = split(/\n/, $&);
  481. my $function_line = $. - scalar(@lines) + 1;
  482. $_ = $'; $again = 1;
  483. &$function_begin($documentation_line, $documentation,
  484. $function_line, "", "void", "", "__thiscall_" . $1, \());
  485. &$function_end($function_line, "");
  486. } elsif(/DEFINE_REGS_ENTRYPOINT_\d+\(\s*(\S*)\s*,\s*([^\s,\)]*).*?\)/s) {
  487. $_ = $'; $again = 1;
  488. $regs_entrypoints{$2} = $1;
  489. } elsif(/DEFAULT_DEBUG_CHANNEL\s*\((\S+)\)/s) {
  490. $_ = $'; $again = 1;
  491. unshift @$debug_channels, $1;
  492. } elsif(/(DEFAULT|DECLARE)_DEBUG_CHANNEL\s*\((\S+)\)/s) {
  493. $_ = $'; $again = 1;
  494. push @$debug_channels, $1;
  495. } elsif(/typedef\s+(enum|interface|struct|union)(?:\s+(\w+))?\s*\{/s) {
  496. $_ = $'; $again = 1;
  497. $level++;
  498. my $type = $1;
  499. if(defined($2)) {
  500. $type .= " $2";
  501. }
  502. &$type_begin($type);
  503. } elsif(/typedef\s+
  504. ((?:const\s+|CONST\s+|enum\s+|interface\s+|long\s+|signed\s+|short\s+|struct\s+|union\s+|unsigned\s+|volatile\s+)*?)
  505. (\w+)
  506. (?:\s+const|\s+volatile)?
  507. ((?:\s*(?:(?:FAR|__RPC_FAR|TW_HUGE)?\s*)?\*+\s*|\s+)(?:volatile\s+|DECLSPEC_ALIGN\(\d+\)\s+)?\w+\s*(?:\[[^\]]*\])*
  508. (?:\s*,\s*(?:\s*(?:(?:FAR|__RPC_FAR|TW_HUGE)?\s*)?\*+\s*|\s+)\w+\s*(?:\[[^\]]*\])?)*)
  509. \s*;/sx)
  510. {
  511. $_ = $'; $again = 1;
  512. my $type = "$1 $2";
  513. my @names;
  514. my @parts = split(/\s*,\s*/, $2);
  515. foreach my $part (@parts) {
  516. if($part =~ /(?:\s*((?:(?:FAR|__RPC_FAR|TW_HUGE)?\s*)?\*+)\s*|\s+)(\w+)\s*(\[[^\]]*\])?/) {
  517. my $name = $2;
  518. if(defined($1)) {
  519. $name = "$1$2";
  520. }
  521. if(defined($3)) {
  522. $name .= $3;
  523. }
  524. push @names, $name;
  525. }
  526. }
  527. &$type_begin($type);
  528. &$type_end([@names]);
  529. } elsif(/typedef\s+
  530. (?:(?:const\s+|enum\s+|interface\s+|long\s+|signed\s+|short\s+|struct\s+|union\s+|unsigned\s+|volatile\s+)*?)
  531. (\w+(?:\s*\*+\s*)?)\s*
  532. (?:(\w+)\s*)?
  533. \((?:(\w+)\s*)?\s*(?:\*\s*(\w+)|_ATL_CATMAPFUNC)\s*\)\s*
  534. (?:\(([^\)]*)\)|\[([^\]]*)\])\s*;/sx)
  535. {
  536. $_ = $'; $again = 1;
  537. my $type;
  538. if(defined($2) || defined($3)) {
  539. my $cc = $2 || $3;
  540. if(defined($5)) {
  541. $type = "$1 ($cc *)($5)";
  542. } else {
  543. $type = "$1 ($cc *)[$6]";
  544. }
  545. } else {
  546. if(defined($5)) {
  547. $type = "$1 (*)($5)";
  548. } else {
  549. $type = "$1 (*)[$6]";
  550. }
  551. }
  552. my $name = $4;
  553. &$type_begin($type);
  554. &$type_end([$name]);
  555. } elsif(/typedef[^\{;]*;/s) {
  556. $_ = $'; $again = 1;
  557. $output->write("$file: $.: can't parse: '$&'\n");
  558. } elsif(/typedef[^\{]*\{[^\}]*\}[^;];/s) {
  559. $_ = $'; $again = 1;
  560. $output->write("$file: $.: can't parse: '$&'\n");
  561. } elsif(/\'[^\']*\'/s) {
  562. $_ = $'; $again = 1;
  563. } elsif(/\"(?:[^\\\"]*|\\.)*\"/s) {
  564. $_ = $'; $again = 1;
  565. } elsif(/;/s) {
  566. $_ = $'; $again = 1;
  567. } elsif(/extern\s+"C"\s+{/s) {
  568. $_ = $'; $again = 1;
  569. } elsif(/\{/s) {
  570. $_ = $'; $again = 1;
  571. print "+1: $_\n" if $options->debug >= 2;
  572. $level++;
  573. } else {
  574. $lookahead = 1;
  575. }
  576. }
  577. close(IN);
  578. print STDERR "done\n" if $options->verbose;
  579. $output->write("$file: not at toplevel at end of file\n") unless $level == 0;
  580. }
  581. 1;