annotate tools/conv_func.pl @ 505:5d4112735c5c

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