annotate conv_func.pl @ 297:0f79c95df73a

switch index no compile error
author kono
date Sun, 06 Jun 2004 20:19:36 +0900
parents aac62d1e30a6
children da2e3f2d127d
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";
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
20 print NUL "#define EXTERN /**/\n";
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
21 print NUL "#include \"mc.h\"\n";
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
22 print NUL "#include \"conv/convdef.h\"\n\n";
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
23 print NUL "#include \"conv/null.h\"\n\n";
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
24
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
25 while(<IN>) {
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
26 if (/([^\s]*)\s+([_a-zA-Z0-9]*)\((.*)\)/) {
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
27 $type=$1; $name=$2; $arg=$3;
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
28 # print OUT "$type=$name=$arg\n";
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
29 $return = ($type && $type ne "void")? "return ($type)0;" : "";
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
30 print OUT " $type (*$name)($arg);\n";
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
31 print NUL "static $type\n$name($arg)\n{ $return}\n\n";
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
32 print DEF "static $_";
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
33 }
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
34 }
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
35
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
36 print OUT "} Converter;\n";
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
37
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
38 foreach $def ('conv/c.h','conv/null.h' ) {
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
39 $def =~ m-conv/(.*)\.h-; $m = $1;
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
40 open(DEF,">$def") or die("can't open $def");
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
41 print DEF "/* Do not edit this file. This is automatically generated. */\n";
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
42
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
43 print OUT "extern Converter ${m}_converter;\n";
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
44 print DEF "\nextern Converter $1_converter;\n";
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
45 print DEF "\n\n\nConverter $1_converter = {\n";
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
46 open(IN,"<$in") or die("can't open $in");
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
47 while(<IN>) {
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
48 if (/([^\s]*)\s+([_a-zA-Z0-9]*)\((.*)\)/) {
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
49 $type=$1; $name=$2; $arg=$3;
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
50 print DEF " \&$name,\n";
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
51 }
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
52 }
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
53 print DEF "};\n";
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
54 }
7a55819b0482 *** empty log message ***
kono
parents:
diff changeset
55