view conv_func.pl @ 451:656ec59cd79f

ia32 fix
author kono
date Sun, 28 Nov 2004 04:16:27 +0900
parents da2e3f2d127d
children
line wrap: on
line source

#!/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 <stdio.h>\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(<IN>) {
    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(<IN>) {
	if (/([^\s]*)\s+([_a-zA-Z0-9]*)\((.*)\)/) {
	    $type=$1; $name=$2; $arg=$3;
	    print DEF "    \&$name,\n";
	}
    }
    print DEF "};\n";
}