466
|
1 #!/usr/bin/perl
|
|
2
|
|
3 $in="conv_func.tbl";
|
|
4 $out="conv/conv.h";
|
|
5 $def="conv/convdef.h";
|
|
6 $nul="conv/null.c";
|
|
7
|
|
8 open(IN,"<$in") or die("can't open $in");
|
|
9 open(OUT,">$out") or die("can't open $out");
|
|
10 print OUT "/* Do not edit this file. This is automatically generated. */\n";
|
|
11 print OUT "/* Edit $in */\n";
|
|
12 open(DEF,">$def") or die("can't open $def");
|
|
13 print DEF "/* Do not edit this file. This is automatically generated. */\n";
|
|
14 print DEF "/* Edit $in */\n";
|
|
15 open(NUL,">$nul") or die("can't open $nul");
|
|
16 print NUL "/* Do not edit this file. This is automatically generated. */\n";
|
|
17 print NUL "/* Edit $in */\n";
|
|
18
|
|
19 print OUT "typedef struct converter {\n";
|
|
20
|
|
21 print NUL "#include <stdio.h>\n";
|
|
22 print NUL "#include \"mc.h\"\n";
|
|
23 print NUL "#include \"mc-parse.h\"\n";
|
|
24
|
|
25 print NUL "#include \"conv/conv.h\"\n";
|
|
26 print NUL "#include \"conv/convdef.h\"\n";
|
|
27 print NUL "#include \"conv/null.h\"\n";
|
|
28
|
|
29
|
|
30 while(<IN>) {
|
|
31 if (/([^\s]*)\s+([_a-zA-Z0-9]*)\((.*)\)/) {
|
|
32 $type=$1; $name=$2; $arg=$3;
|
|
33 # print OUT "$type=$name=$arg\n";
|
|
34 $return = ($type && $type ne "void")? "return ($type)0;" : "";
|
|
35 print OUT " $type (*$name)($arg);\n";
|
|
36 print NUL "static $type\n$name($arg)\n{ $return}\n\n";
|
|
37 print DEF "static $_";
|
|
38 }
|
|
39 }
|
|
40
|
|
41 print OUT "} Converter;\n";
|
|
42
|
|
43 foreach $def ('conv/c.h','conv/null.h' ) {
|
|
44 $def =~ m-conv/(.*)\.h-; $m = $1;
|
|
45 open(DEF,">$def") or die("can't open $def");
|
|
46 print DEF "/* Do not edit this file. This is automatically generated. */\n";
|
|
47
|
|
48 print OUT "extern Converter ${m}_converter;\n";
|
|
49 print DEF "\nextern Converter $1_converter;\n";
|
|
50 print DEF "\n\n\nConverter $1_converter = {\n";
|
|
51 open(IN,"<$in") or die("can't open $in");
|
|
52 while(<IN>) {
|
|
53 if (/([^\s]*)\s+([_a-zA-Z0-9]*)\((.*)\)/) {
|
|
54 $type=$1; $name=$2; $arg=$3;
|
|
55 print DEF " \&$name,\n";
|
|
56 }
|
|
57 }
|
|
58 print DEF "};\n";
|
|
59 }
|
|
60
|