466
|
1 #!/usr/bin/perl
|
|
2
|
607
|
3
|
|
4 # /************************************************************************
|
|
5 # ** Copyright (C) 2006 Shinji Kono
|
|
6 # ** 連絡先: 琉球大学情報工学科 河野 真治
|
|
7 # ** (E-Mail Address: kono@ie.u-ryukyu.ac.jp)
|
|
8 # **
|
|
9 # ** このソースのいかなる複写,改変,修正も許諾します。ただし、
|
|
10 # ** その際には、誰が貢献したを示すこの部分を残すこと。
|
|
11 # ** 再配布や雑誌の付録などの問い合わせも必要ありません。
|
|
12 # ** 営利利用も上記に反しない範囲で許可します。
|
|
13 # ** バイナリの配布の際にはversion messageを保存することを条件とします。
|
|
14 # ** このプログラムについては特に何の保証もしない、悪しからず。
|
|
15 # **
|
|
16 # ** Everyone is permitted to do anything on this program
|
|
17 # ** including copying, modifying, improving,
|
|
18 # ** as long as you don't try to pretend that you wrote it.
|
|
19 # ** i.e., the above copyright notice has to appear in all copies.
|
|
20 # ** Binary distribution requires original version messages.
|
|
21 # ** You don't have to ask before copying, redistribution or publishing.
|
|
22 # ** THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE.
|
|
23 # ***********************************************************************/
|
|
24
|
466
|
25 $in="conv_func.tbl";
|
|
26 $out="conv/conv.h";
|
|
27 $def="conv/convdef.h";
|
|
28 $nul="conv/null.c";
|
|
29
|
|
30 open(IN,"<$in") or die("can't open $in");
|
|
31 open(OUT,">$out") or die("can't open $out");
|
|
32 print OUT "/* Do not edit this file. This is automatically generated. */\n";
|
|
33 print OUT "/* Edit $in */\n";
|
|
34 open(DEF,">$def") or die("can't open $def");
|
|
35 print DEF "/* Do not edit this file. This is automatically generated. */\n";
|
|
36 print DEF "/* Edit $in */\n";
|
|
37 open(NUL,">$nul") or die("can't open $nul");
|
|
38 print NUL "/* Do not edit this file. This is automatically generated. */\n";
|
|
39 print NUL "/* Edit $in */\n";
|
|
40
|
|
41 print OUT "typedef struct converter {\n";
|
|
42
|
|
43 print NUL "#include <stdio.h>\n";
|
|
44 print NUL "#include \"mc.h\"\n";
|
|
45 print NUL "#include \"mc-parse.h\"\n";
|
|
46
|
|
47 print NUL "#include \"conv/conv.h\"\n";
|
|
48 print NUL "#include \"conv/convdef.h\"\n";
|
|
49 print NUL "#include \"conv/null.h\"\n";
|
|
50
|
|
51
|
|
52 while(<IN>) {
|
|
53 if (/([^\s]*)\s+([_a-zA-Z0-9]*)\((.*)\)/) {
|
|
54 $type=$1; $name=$2; $arg=$3;
|
|
55 # print OUT "$type=$name=$arg\n";
|
|
56 $return = ($type && $type ne "void")? "return ($type)0;" : "";
|
|
57 print OUT " $type (*$name)($arg);\n";
|
|
58 print NUL "static $type\n$name($arg)\n{ $return}\n\n";
|
|
59 print DEF "static $_";
|
|
60 }
|
|
61 }
|
|
62
|
|
63 print OUT "} Converter;\n";
|
|
64
|
599
|
65 foreach $def ('conv/c.h','conv/c2cbc.h','conv/cbc2c.h','conv/null.h' ) {
|
466
|
66 $def =~ m-conv/(.*)\.h-; $m = $1;
|
|
67 open(DEF,">$def") or die("can't open $def");
|
|
68 print DEF "/* Do not edit this file. This is automatically generated. */\n";
|
|
69
|
|
70 print OUT "extern Converter ${m}_converter;\n";
|
|
71 print DEF "\nextern Converter $1_converter;\n";
|
|
72 print DEF "\n\n\nConverter $1_converter = {\n";
|
|
73 open(IN,"<$in") or die("can't open $in");
|
|
74 while(<IN>) {
|
|
75 if (/([^\s]*)\s+([_a-zA-Z0-9]*)\((.*)\)/) {
|
|
76 $type=$1; $name=$2; $arg=$3;
|
|
77 print DEF " \&$name,\n";
|
|
78 }
|
|
79 }
|
|
80 print DEF "};\n";
|
|
81 }
|
|
82
|