#!/usr/bin/perl $in="conv_func.tbl"; $out="conv/conv.h"; $def="conv/convdef.h"; $nul="conv/null.c"; open(IN,"<$in") or die("can't open $in"); open(OUT,">$out") or die("can't open $out"); print OUT "/* Do not edit this file. This is automatically generated. */\n"; print OUT "/* Edit $in */\n"; open(DEF,">$def") or die("can't open $def"); print DEF "/* Do not edit this file. This is automatically generated. */\n"; print DEF "/* Edit $in */\n"; open(NUL,">$nul") or die("can't open $nul"); print NUL "/* Do not edit this file. This is automatically generated. */\n"; print NUL "/* Edit $in */\n"; print OUT "typedef struct converter {\n"; print NUL "#include \n"; print NUL "#include \"mc.h\"\n"; print NUL "#include \"mc-parse.h\"\n"; print NUL "#include \"conv/conv.h\"\n"; print NUL "#include \"conv/convdef.h\"\n"; print NUL "#include \"conv/null.h\"\n"; while() { if (/([^\s]*)\s+([_a-zA-Z0-9]*)\((.*)\)/) { $type=$1; $name=$2; $arg=$3; # print OUT "$type=$name=$arg\n"; $return = ($type && $type ne "void")? "return ($type)0;" : ""; print OUT " $type (*$name)($arg);\n"; print NUL "static $type\n$name($arg)\n{ $return}\n\n"; print DEF "static $_"; } } print OUT "} Converter;\n"; foreach $def ('conv/c.h','conv/null.h' ) { $def =~ m-conv/(.*)\.h-; $m = $1; open(DEF,">$def") or die("can't open $def"); print DEF "/* Do not edit this file. This is automatically generated. */\n"; print OUT "extern Converter ${m}_converter;\n"; print DEF "\nextern Converter $1_converter;\n"; print DEF "\n\n\nConverter $1_converter = {\n"; open(IN,"<$in") or die("can't open $in"); while() { if (/([^\s]*)\s+([_a-zA-Z0-9]*)\((.*)\)/) { $type=$1; $name=$2; $arg=$3; print DEF " \&$name,\n"; } } print DEF "};\n"; }