annotate conv_func.pl @ 432:f8ebd7e1c644

*** empty log message ***
author kono
date Sun, 31 Oct 2004 12:20:30 +0900
parents da2e3f2d127d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
134
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
1 #!/usr/bin/perl
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
2
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
3 $in="conv_func.tbl";
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
4 $out="conv/conv.h";
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
5 $def="conv/convdef.h";
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
6 $nul="conv/null.c";
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
7
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
8 open(IN,"<$in") or die("can't open $in");
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
9 open(OUT,">$out") or die("can't open $out");
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
10 print OUT "/* Do not edit this file. This is automatically generated. */\n";
140
aac62d1e30a6 fix minor syntax error
kono
parents: 134
diff changeset
11 print OUT "/* Edit $in */\n";
134
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
12 open(DEF,">$def") or die("can't open $def");
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
13 print DEF "/* Do not edit this file. This is automatically generated. */\n";
140
aac62d1e30a6 fix minor syntax error
kono
parents: 134
diff changeset
14 print DEF "/* Edit $in */\n";
134
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
15 open(NUL,">$nul") or die("can't open $nul");
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
16 print NUL "/* Do not edit this file. This is automatically generated. */\n";
140
aac62d1e30a6 fix minor syntax error
kono
parents: 134
diff changeset
17 print NUL "/* Edit $in */\n";
134
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
18
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
19 print OUT "typedef struct converter {\n";
327
da2e3f2d127d macro/codegen reorganization
kono
parents: 140
diff changeset
20
da2e3f2d127d macro/codegen reorganization
kono
parents: 140
diff changeset
21 print NUL "#include <stdio.h>\n";
134
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
22 print NUL "#include \"mc.h\"\n";
327
da2e3f2d127d macro/codegen reorganization
kono
parents: 140
diff changeset
23 print NUL "#include \"mc-parse.h\"\n";
da2e3f2d127d macro/codegen reorganization
kono
parents: 140
diff changeset
24
da2e3f2d127d macro/codegen reorganization
kono
parents: 140
diff changeset
25 print NUL "#include \"conv/conv.h\"\n";
da2e3f2d127d macro/codegen reorganization
kono
parents: 140
diff changeset
26 print NUL "#include \"conv/convdef.h\"\n";
da2e3f2d127d macro/codegen reorganization
kono
parents: 140
diff changeset
27 print NUL "#include \"conv/null.h\"\n";
da2e3f2d127d macro/codegen reorganization
kono
parents: 140
diff changeset
28
134
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
29
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
30 while(<IN>) {
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
31 if (/([^\s]*)\s+([_a-zA-Z0-9]*)\((.*)\)/) {
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
32 $type=$1; $name=$2; $arg=$3;
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
33 # print OUT "$type=$name=$arg\n";
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
34 $return = ($type && $type ne "void")? "return ($type)0;" : "";
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
35 print OUT " $type (*$name)($arg);\n";
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
36 print NUL "static $type\n$name($arg)\n{ $return}\n\n";
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
37 print DEF "static $_";
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
38 }
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
39 }
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
40
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
41 print OUT "} Converter;\n";
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
42
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
43 foreach $def ('conv/c.h','conv/null.h' ) {
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
44 $def =~ m-conv/(.*)\.h-; $m = $1;
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
45 open(DEF,">$def") or die("can't open $def");
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
46 print DEF "/* Do not edit this file. This is automatically generated. */\n";
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
47
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
48 print OUT "extern Converter ${m}_converter;\n";
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
49 print DEF "\nextern Converter $1_converter;\n";
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
50 print DEF "\n\n\nConverter $1_converter = {\n";
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
51 open(IN,"<$in") or die("can't open $in");
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
52 while(<IN>) {
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
53 if (/([^\s]*)\s+([_a-zA-Z0-9]*)\((.*)\)/) {
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
54 $type=$1; $name=$2; $arg=$3;
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
55 print DEF " \&$name,\n";
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
56 }
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
57 }
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
58 print DEF "};\n";
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
59 }
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
60