From: Not Zed Date: Thu, 19 May 2022 22:32:47 +0000 (+0930) Subject: tabify X-Git-Url: https://code.zedzone.au/cvs?a=commitdiff_plain;h=HEAD;p=nativez tabify --- diff --git a/src/notzed.nativez/jni/nativez-gen b/src/notzed.nativez/jni/nativez-gen index f359fdf..5a6a176 100755 --- a/src/notzed.nativez/jni/nativez-gen +++ b/src/notzed.nativez/jni/nativez-gen @@ -1,5 +1,7 @@ #!/usr/bin/perl +# -*- Mode:perl; perl-indent-level:4;tab-width:4; -*- + # usage [ options ]* def-file.def # -b basedir Base directory for any 'header' sections. It is added to the include path. @@ -18,21 +20,21 @@ $doLong = 0; $cprotoArgs = ""; while ($#ARGV > 0) { - my $cmd = shift; - if ($cmd eq "-b") { - $basedir = shift; - $cprotoArgs .= " -I '${basedir}'"; - } elsif ($cmd eq "--func-name") { - $func_name = shift; - } elsif ($cmd eq "--java-name") { - $java_name = shift; - } elsif ($cmd eq "-J") { - $doJ = 1; - } elsif ($cmd eq "--java-long") { - $doLong = 1; - } else { - $cprotoArgs .= " '$cmd'"; - } + my $cmd = shift; + if ($cmd eq "-b") { + $basedir = shift; + $cprotoArgs .= " -I '${basedir}'"; + } elsif ($cmd eq "--func-name") { + $func_name = shift; + } elsif ($cmd eq "--java-name") { + $java_name = shift; + } elsif ($cmd eq "-J") { + $doJ = 1; + } elsif ($cmd eq "--java-long") { + $doLong = 1; + } else { + $cprotoArgs .= " '$cmd'"; + } } $def = shift; @@ -47,54 +49,54 @@ $mode = ""; open (IN,"<$def") || die ("opening $def"); while () { - chop; - s/#.*$//; - if (m/^header (.*) (.*) \{/) { - $library = $1; - $header = $2; - push @headers, $header; - - print STDERR "cproto -q -x ${cprotoArgs} $basedir/$header\n"; - %proto = (); - open (PROTO, "cproto -q -x ${cprotoArgs} $basedir/$header|") || die("cproto failed"); - - while () { - chop; - $cproto = $_; - if (m/([a-zA-Z0-9_]*)\(/) { - $func = $1; - $proto{$func} = $cproto; - } - } - close PROTO; - - if ($library ne $last_library) { - push @functions, "#$library"; - $last_library = $library; - } - $mode = "proto"; - } elsif (m/^java (.*) (.*) \{/) { - $name = $1; - $class = $2; - $mode = "java"; - push @classes,"#$name:$class"; - } elsif (m/^}$/) { - $mode = ""; - } elsif ($mode eq "proto") { - if (m/\s*([a-zA-Z0-9_]+)/) { - my $func= $1; - my $cproto = $proto{$func}; - - die ("No function $func in $header") if !defined($cproto); - - push @functions, $cproto; + chop; + s/#.*$//; + if (m/^header (.*) (.*) \{/) { + $library = $1; + $header = $2; + push @headers, $header; + + print STDERR "cproto -q -x ${cprotoArgs} $basedir/$header\n"; + %proto = (); + open (PROTO, "cproto -q -x ${cprotoArgs} $basedir/$header|") || die("cproto failed"); + + while () { + chop; + $cproto = $_; + if (m/([a-zA-Z0-9_]*)\(/) { + $func = $1; + $proto{$func} = $cproto; + } + } + close PROTO; + + if ($library ne $last_library) { + push @functions, "#$library"; + $last_library = $library; + } + $mode = "proto"; + } elsif (m/^java (.*) (.*) \{/) { + $name = $1; + $class = $2; + $mode = "java"; + push @classes,"#$name:$class"; + } elsif (m/^}$/) { + $mode = ""; + } elsif ($mode eq "proto") { + if (m/\s*([a-zA-Z0-9_]+)/) { + my $func= $1; + my $cproto = $proto{$func}; + + die ("No function $func in $header") if !defined($cproto); + + push @functions, $cproto; + } + } elsif ($mode eq "java") { + # maps to strict "[static|],name,(arguments)" + if (m/(static)? *([\w<>]*) *, *([\[\w\$<>\(\)\/;]*)/) { + push @classes,"$1,$2,$3"; + } } - } elsif ($mode eq "java") { - # maps to strict "[static|],name,(arguments)" - if (m/(static)? *([\w<>]*) *, *([\[\w\$<>\(\)\/;]*)/) { - push @classes,"$1,$2,$3"; - } - } } close IN; @@ -102,96 +104,96 @@ print "/* This file was autogenerated by: */\n"; print "/* $args */\n"; if ($#headers >= 0) { - # Handle C prototype mappings - foreach $h (@headers) { - print "#include <$h>\n"; - } - - print "static struct functable {\n"; - foreach $func (@functions) { - if ($func =~ m/^\#(.+)/) { - print "\t/* lib$1 */\n"; - } else { - $dfunc = $func; - $dfunc =~ s/([a-zA-Z0-9_]*)(\(.*;)/(*\1)\2/; - print "\t$dfunc\n"; + # Handle C prototype mappings + foreach $h (@headers) { + print "#include <$h>\n"; } - } - print "} ${func_name};\n"; - print "static const char *${func_name}_names =\n"; - foreach $func (@functions) { - if ($func =~ m/^(\#.+)/) { - print "\t\"$func\\0\"\n"; - } else { - $func =~ m/([a-zA-Z0-9_]*)\(/; - print "\t\"$1\\0\"\n"; + + print "static struct functable {\n"; + foreach $func (@functions) { + if ($func =~ m/^\#(.+)/) { + print "\t/* lib$1 */\n"; + } else { + $dfunc = $func; + $dfunc =~ s/([a-zA-Z0-9_]*)(\(.*;)/(*\1)\2/; + print "\t$dfunc\n"; + } + } + print "} ${func_name};\n"; + print "static const char *${func_name}_names =\n"; + foreach $func (@functions) { + if ($func =~ m/^(\#.+)/) { + print "\t\"$func\\0\"\n"; + } else { + $func =~ m/([a-zA-Z0-9_]*)\(/; + print "\t\"$1\\0\"\n"; + } } - } - print "\t;\n"; + print "\t;\n"; } if ($#classes >= 0) { - # Handle java defines - $name = ""; - $class = ""; - print "static struct {\n"; - foreach $func (@classes) { - if ($func =~ m/^#(.+):(.+)/) { - $name = $1; - $class = $2; - print "\t// $class\n"; - print "\tjclass $name"."_classid;\n"; - printf "#define $name"."_classid ${java_name}.$name"."_classid\n" if $doJ; - } elsif ($func =~ m/(.*),(.+),\((.*)\).*/) { - my $method = $2; - my $args = $3; - - if ($doLong) { - while ($args =~ m/(.*)L([^;]*);(.*)/) { - my $a = $1; - my $b = $2; - my $c = $3; - - $b =~ s,/,_,g; - $args = $a."_".$b."_".$c; - } - } else { - $args =~ s/L[^;]*;/l/g; - $args =~ tr/A-Z/a-z/; - } - $args =~ s/\[/_/g; - - $method =~ s//new/; - - print "\tjmethodID $name"."_$method"."_$args;\n"; - print "#define $name"."_$method"."_$args ${java_name}.$name"."_$method"."_$args\n" if $doJ; - } elsif ($func =~ m/(.*),(.+),(.+)/) { - my $field = $2; - my $type = $3; - - print "\tjfieldID $name"."_$field;\n"; - print "#define $name"."_$field ${java_name}.$name"."_$field\n" if $doJ; - } else { - die("can't parse java signature $func"); + # Handle java defines + $name = ""; + $class = ""; + print "static struct {\n"; + foreach $func (@classes) { + if ($func =~ m/^#(.+):(.+)/) { + $name = $1; + $class = $2; + print "\t// $class\n"; + print "\tjclass $name"."_classid;\n"; + printf "#define $name"."_classid ${java_name}.$name"."_classid\n" if $doJ; + } elsif ($func =~ m/(.*),(.+),\((.*)\).*/) { + my $method = $2; + my $args = $3; + + if ($doLong) { + while ($args =~ m/(.*)L([^;]*);(.*)/) { + my $a = $1; + my $b = $2; + my $c = $3; + + $b =~ s,/,_,g; + $args = $a."_".$b."_".$c; + } + } else { + $args =~ s/L[^;]*;/l/g; + $args =~ tr/A-Z/a-z/; + } + $args =~ s/\[/_/g; + + $method =~ s//new/; + + print "\tjmethodID $name"."_$method"."_$args;\n"; + print "#define $name"."_$method"."_$args ${java_name}.$name"."_$method"."_$args\n" if $doJ; + } elsif ($func =~ m/(.*),(.+),(.+)/) { + my $field = $2; + my $type = $3; + + print "\tjfieldID $name"."_$field;\n"; + print "#define $name"."_$field ${java_name}.$name"."_$field\n" if $doJ; + } else { + die("can't parse java signature $func"); + } } - } - print "} ${java_name};\n"; - print "static const char *${java_name}_names =\n"; - foreach $func (@classes) { - if ($func =~ m/^#(.+):(.+)/) { - $name = $1; - $class = $2; - - print "\t\"#$class\\0\"\n"; - } elsif ($func =~ m/static,(.*),(.*\(.*\).*)/) { - print "\t\":$1\\0$2\\0\"\n"; - } elsif ($func =~ m/,(.*),(.*\(.*\).*)/) { - print "\t\".$1\\0$2\\0\"\n"; - } elsif ($func =~ m/static,(.*),(.*)/) { - print "\t\";$1\\0$2\\0\"\n"; - } elsif ($func =~ m/,(.*),(.*)/) { - print "\t\",$1\\0$2\\0\"\n"; + print "} ${java_name};\n"; + print "static const char *${java_name}_names =\n"; + foreach $func (@classes) { + if ($func =~ m/^#(.+):(.+)/) { + $name = $1; + $class = $2; + + print "\t\"#$class\\0\"\n"; + } elsif ($func =~ m/static,(.*),(.*\(.*\).*)/) { + print "\t\":$1\\0$2\\0\"\n"; + } elsif ($func =~ m/,(.*),(.*\(.*\).*)/) { + print "\t\".$1\\0$2\\0\"\n"; + } elsif ($func =~ m/static,(.*),(.*)/) { + print "\t\";$1\\0$2\\0\"\n"; + } elsif ($func =~ m/,(.*),(.*)/) { + print "\t\",$1\\0$2\\0\"\n"; + } } - } - print "\t;\n"; + print "\t;\n"; }