6 parse('builtins','DATA');
11 $x= new IO::File $_,'r' or die "$_: $!\n";
17 while (defined($_= $f->getline)) {
21 s/\t/ ' 'x(8-(length $`) % 8) /eg;
24 $this_indent= length $&;
25 while (@i && $this_indent < $i[0]) {
28 if ($this_indent && (!@i || $this_indent > $i[0])) {
29 unshift @i, $this_indent;
32 if (@i==0 && m/^Table\s+(\w+)$/) {
35 } elsif (@i==1 && m/^([a-z]\w*)$/ && defined $c_table) {
37 $tables{$c_table}{$c_entry}{A} = [ ];
38 } elsif (@i==2 && m/^(\w+)\s+\.\.\.$/ && defined $c_entry) {
39 $tables{$c_table}{$c_entry}{V}= $1;
40 } elsif (@i==2 && m/^(\??)([a-z]\w*)\s*(\S.*)/
41 && defined $c_entry) {
42 ($opt, $var, $type) = ($1,$2,$3);
43 if ($type =~ m/^\w+$/) {
45 } elsif ($type =~ m/^(\w+)\((.+)\)$/) {
49 push @{ $tables{$c_table}{$c_entry}{A} },
50 { N => $var, T => $type, A => $xtypeargs, O => ($opt eq '?') };
51 } elsif (@i==2 && m/^\=\>\s*(\S.*)$/ && defined $c_entry) {
52 $tables{$c_table}{$c_entry}{R}= $1;
53 } elsif (@i==0 && m/^Type\s+([^\:]+)\:\s+(\S.*)$/) {
54 ($typename,$ctype)= ($1,$2);
55 $ctype .= ' @' unless $ctype =~ m/\@/;
56 if ($typename =~ m/^\w+$/) {
58 } elsif ($typename =~ m/^(\w+)\((.+)\)$/) {
62 badsyntax($wh,$.,"bad type name/args");
64 $types{$typename}= { C => $ctype, X => $xtypeargs };
66 printf STDERR ">%d<\n",
67 scalar m/^Type\s+([^\:]+)\:\s+(\S.*)$/;
68 badsyntax($wh,$., sprintf
69 "bad directive (indent level %d)", scalar @i);
76 #print Dumper(\%tables),"\n";
77 #print Dumper(\%types),"\n";
79 foreach $c_table (sort keys %tables) {
80 $r_table= $tables{$c_table};
81 foreach $c_entry (keys %$r_table) {
82 $r_entry= $r_table->{$c_entry};
83 $pa_decl= "int fn_${c_table}_${c_entry}(";
85 foreach $arg (@{ $r_entry->{A} }) {
86 push @pa_al, make_decl($arg->{N}, $arg->{T}, $arg->{A});
88 if (exists $r_entry->{V}) {
90 push @pa_al, make_decl_c("${va}c", 'int @');
91 push @pa_al, make_decl_c("${va}v", 'Tcl_Obj *const *@');
93 if (exists $r_entry->{R}) {
95 push @pa_al, make_decl("*result", $t);
97 $pa_decl .= join ', ', @pa_al;
99 print $pa_decl or die $!;
103 sub make_decl ($$$) {
104 my ($n, $t, $ta) = @_;
107 $ta =~ m/\,/ or die "enum with bad args \`$ta'\n";
110 defined $types{$t} or die "unknown type $t\n";
113 return make_decl_c($n,$c);
116 sub make_decl_c ($$) {
118 $c =~ m/\@/ or die "$c for $n?";
122 sub badsyntax ($$$) {
123 die "$_[0]:$_[1]: $_[2]\n";
129 Type charfrom(const char*): int