#!/usr/bin/perl -w use strict; my %func; my $prop; open(H, ">try_perlapi.h") || die; open(C, ">try_perlapi.c") || die; my $note = "/* DO NOT EDIT!!!\n * Autogenerated by $0\n */\n\n"; print H $note; print C $note; my $ENABLE_JMPENV = $^O ne "MSWin32"; print C < #include #include #include "try_perlapi.h" #include "perlmodule.h" #include "lang_lock.h" #include "thrd_ctx.h" EOT print C < oldscope) { PERL_CONTEXT *cx; PMOP *newpm; I32 optype; SV **newsp; I32 gimme; POPBLOCK(cx,newpm); POPEVAL(cx); pop_return(); PL_curpm = newpm; } FREETMPS; LEAVE; } EOT while () { if (/^(\w.*?)(\w+)\(([^)]*)\)\s*$/) { gen_func() if %func; %func = (); undef($prop); @func{qw/type name args/} = ($1, $2, $3); # some trimming for (@func{qw/type args/}) { s/^\s+//; s/\s+$//; } } elsif (s/\s+(\w+)\s*:\s*//) { $prop = lc($1); $func{$prop} = $_; if ($prop eq "code" && !/^\s*$/) { chomp($func{code}); $func{code} = "RETVAL = $func{code};"; } } elsif ($prop) { $func{$prop} .= $_; } elsif (%func) { warn; } else { print; } } gen_func() if %func; exit; #----------- sub gen_func { print H "$func{type}\ttry_$func{name}($func{args});\n"; my $fail = $func{fail}; $fail = -1 unless defined $fail; $fail =~ s/\s+$//; my $code = $func{code} || die; $code =~ s/\s+$//s; # fix code indentation my $indent = 9999; my @code = split(/^/, $code); for (@code) { 1 while s/\t/' ' x (8 - length($`) % 8)/e; # expand tabs /^(\s*)/ || die; my $i = length($1); $indent = $i if $i < $indent; } if ($indent < 8) { for (@code) { $_ = (" " x (8 - $indent)) . $_; } } $code = join("", @code); if ($ENABLE_JMPENV) { print C <