OSDN Git Service

0392297dfb407e8c5a67825e8cc4c169ce4749f7
[hmh/hhml.git] / bin / MKWTABLE.pl
1 #! /usr/bin/perl
2
3 my @CMD;
4 my @FN;
5 my @FN2;
6 my @HDR;
7 my @SRCS;
8 #my $target = "wikitable.cc";
9 #my $targetTmp = "$target-$$";
10 my $Target;
11 my $TargetTmp;
12
13 while ($_ = shift) {
14     if (/^-/) {
15         if ($_ eq "-o") {
16             $Target = shift;
17             $TargetTmp = ".tmp-$Target";
18         } elsif (/^-[DI]/) {
19             push (@CPPFLAGS, $_);
20         }
21     } else {
22         if (-f $_) {
23             push (@SRCS, $_);
24         } else {
25             die "$_: not found\n";
26         }
27     }
28 }
29
30 foreach (@SRCS) {
31     &p ($_);
32 }
33
34 open (OUT, "> $TargetTmp");
35 print OUT "#include \"wikitable.h\"\n";
36 foreach (@HDR) {
37     print OUT "#include \"$_\"\n";
38 }
39 print OUT "//============================================================\n";
40 print OUT "static WikiCmdTableSupport::wikicmd_t  wikitable[] = {\n";
41 foreach (@CMD) {
42     if ($#$_ == 1) {
43         print OUT "    {CharConst (\"$_->[0]\"), NULL, 0, NULL, 0, $_->[1]},\n";
44     } elsif ($#$_ == 2) {
45         print OUT "    {CharConst (\"$_->[0]\"), NULL, 0, CharConst (\"$_->[1]\"), $_->[2]},\n";
46     } else {
47         print OUT "    {CharConst (\"$_->[0]\"), CharConst (\"$_->[1]\"), CharConst (\"$_->[2]\"), $_->[3]},\n";
48     }
49 }
50 print OUT "    {NULL, 0, NULL, 0, NULL},\n";
51 print OUT "};\n";
52 print OUT "WikiCmdTable  GWikiCmdTable (wikitable);\n";
53 print OUT "//============================================================\n";
54 print OUT "static WikiCmdTableSupport::wikifunc_t  wftable[] = {\n";
55 foreach (@FN) {
56     print OUT "    {CharConst (\"$_->[0]\"), $_->[2], (bool(*)())$_->[1]},\n";
57     die "error\n" if ($_->[2] eq '');
58 }
59 print OUT "    {NULL, 0, WikiCmdTableSupport::WikiArg1, NULL},\n";
60 print OUT "};\n";
61 #@#print OUT "static WikiCmdTableSupport::wikifunc_t  wftable2[] = {\n";
62 #@#foreach (@FN2) {
63 #@#    print OUT "    {CharConst (\"$_->[0]\"), $_->[2], (bool(*)())$_->[1]},\n";
64 #@#}
65 #@#print OUT "    {NULL, 0, WikiCmdTableSupport::WikiArg1, NULL},\n";
66 #@#print OUT "};\n";
67 print OUT "WikiFuncTable  GWikiFuncTable (wftable);\n";
68 #@#print OUT "WikiFuncTable  GWikiFuncTable2 (wftable2);\n";
69 print OUT "//============================================================\n";
70 close (OUT);
71
72 rename ($TargetTmp, $Target);
73
74 exit;
75
76 sub  p {
77     my ($file) = @_;
78     my ($hdr, @a, $ffn, $x, $c, $name);
79
80     $hdr = $file;
81     $hdr =~ s/\.cc$/.h/;
82     $ffn = 0;
83
84     open (IN, $file);
85     while (<IN>) {
86         chomp;
87         if (/^\/\/\#WIKICMD\s+/) {
88             @a = split (/\s+/, $');
89             push (@CMD, [@a]);
90             $ffn = 1;
91         } elsif (/^\/\/\#WIKILINE2?\s+/) {
92             @a = split (/\s+/, $');
93             push (@FN, [$a[0], $a[1]]);
94             $ffn = 1;
95 #@#     } elsif (/^\/\/\#WIKILINE2\s+/) {
96 #@#         @a = split (/\s+/, $');
97 #@#         push (@FN2, [$a[0], $a[1]]);
98 #@#         $ffn = 1;
99         } elsif (/^bool\s+(wl_[^ \t\(]+)/) {
100             $name = $1;
101             $c = 0;
102             $x = $_;
103             while ($x !~ /\)/) {
104                 chomp ($x .= <IN>);
105             }
106 #@#         if ($x =~ /\(\s*WikiMotorObjVec\*\s*\w+\s*,\s*MotorOutput\*/) {
107             if ($x =~ /\(\s*WikiMotorObjVec\*\s*\w+\s*,\s*WikiMotorObjVec&/) {
108                 &setFN (\@FN, $name, WikiCmdTableSupport::WikiArg1);
109 #@#             &setFN (\@FN2, $name, WikiCmdTableSupport::WikiArg1);
110 #@#         } elsif ($x =~ /\(\s*WikiMotorObjVecVec\*\s*\w+\s*,\s*MotorOutput\*/) {
111             } elsif ($x =~ /\(\s*WikiMotorObjVecVec\*\s*\w+\s*,\s*WikiMotorObjVec&/) {
112                 &setFN (\@FN, $name, WikiCmdTableSupport::WikiArgM);
113 #@#             &setFN (\@FN2, $name, WikiCmdTableSupport::WikiArgM);
114 #@#         } elsif ($x =~ /\(\s*WikiMotorObjVecVec\*\s+\w+\s*,\s*WikiMotorObjVec\*\s+\w+\s*,\s*MotorOutput\*/) {
115             } elsif ($x =~ /\(\s*WikiMotorObjVecVec\*\s+\w+\s*,\s*WikiMotorObjVec\*\s+\w+\s*,\s*WikiMotorObjVec&/) {
116                 &setFN (\@FN, $name, WikiCmdTableSupport::WikiArgM2);
117 #@#             &setFN (\@FN2, $name, WikiCmdTableSupport::WikiArgM2);
118             }
119         }
120     }
121     close (IN);
122
123     if (-f $hdr) {
124         if ($ffn) {
125             push (@HDR, $hdr);
126         }
127     }
128 }
129
130 sub  countComma {
131     my ($str) = @_;
132     my (@a) = split (/,/, $str, -1);
133     return ($#a);
134 }
135
136 sub  setFN {
137     my ($rfn, $name, $val) = @_;
138     foreach (@$rfn) {
139         if ($_->[1] eq $name) {
140             $_->[2] = $val;
141         }
142     }
143 }
144
145 sub  cmpFile {
146     my ($f1, $f2) = @_;
147     my ($rc);
148
149     $rc = system ('/usr/bin/cmp', '-s', $f1, $f2) >> 8;
150     return $rc;
151 }