standard_typemap_locations
trim_whitespace
tidy_type
+ C_string
);
our (@ISA, @EXPORT_OK, $VERSION);
sub process_file {
# Allow for $package->process_file(%hash) in the future
- my ($pkg, %args) = @_ % 2 ? @_ : (__PACKAGE__, @_);
+ my ($pkg, %options) = @_ % 2 ? @_ : (__PACKAGE__, @_);
- $ProtoUsed = exists $args{prototypes};
+ $ProtoUsed = exists $options{prototypes};
# Set defaults.
- %args = (
+ my %args = (
argtypes => 1,
csuffix => '.c',
except => 0,
prototypes => 0,
typemap => [],
versioncheck => 1,
- %args,
+ %options,
);
+ $args{except} = $args{except} ? ' TRY' : '';
# Global Constants
$hiertype = $args{hiertype};
$WantPrototypes = $args{prototypes};
$WantVersionChk = $args{versioncheck};
- my $except = $args{except} ? ' TRY' : '';
$WantLineNumbers = $args{linenumbers};
- my $WantOptimize = $args{optimize};
- my $process_inout = $args{inout};
- my $process_argtypes = $args{argtypes};
my @tm = ref $args{typemap} ? @{$args{typemap}} : ($args{typemap});
- for ($args{filename}) {
- die "Missing required parameter 'filename'" unless $_;
- $filepathname = $_;
- ($dir, $filename) = (dirname($_), basename($_));
+ for my $f ($args{filename}) {
+ die "Missing required parameter 'filename'" unless $f;
+ $filepathname = $f;
+ ($dir, $filename) = (dirname($f), basename($f));
$filepathname =~ s/\\/\\\\/g;
- $IncludedFiles{$_}++;
+ $IncludedFiles{$f}++;
}
# Open the input file
# Allow one-line ANSI-like declaration
unshift @line, $2
- if $process_argtypes
+ if $args{argtypes}
and $ret_type =~ s/^(.*?\w.*?)\s*\b(\w+\s*\(.*)/$1/s;
# a function definition needs at least 2 lines
my @args;
my %only_C_inlist; # Not in the signature of Perl function
- if ($process_argtypes and $orig_args =~ /\S/) {
+ if ($args{argtypes} and $orig_args =~ /\S/) {
my $args = "$orig_args ,";
if ($args =~ /^( (??{ $C_arg }) , )* $ /x) {
@args = ($args =~ /\G ( (??{ $C_arg }) ) , /xg);
next unless defined($pre) && length($pre);
my $out_type = '';
my $inout_var;
- if ($process_inout and s/^(IN|IN_OUTLIST|OUTLIST|OUT|IN_OUT)\b\s*//) {
+ if ($args{inout} and s/^(IN|IN_OUTLIST|OUTLIST|OUT|IN_OUT)\b\s*//) {
my $type = $1;
$out_type = $type if $type ne 'IN';
$arg =~ s/^(IN|IN_OUTLIST|OUTLIST|OUT|IN_OUT)\b\s*//;
else {
@args = split(/\s*,\s*/, $orig_args);
for (@args) {
- if ($process_inout and s/^(IN|IN_OUTLIST|OUTLIST|IN_OUT|OUT)\b\s*//) {
+ if ($args{inout} and s/^(IN|IN_OUTLIST|OUTLIST|IN_OUT|OUT)\b\s*//) {
my $out_type = $1;
next if $out_type eq 'IN';
$only_C_inlist{$_} = 1 if $out_type eq "OUTLIST";
$cond = qq(items < $min_args || items > $num_args);
}
- print Q(<<"EOF") if $except;
+ print Q(<<"EOF") if $args{except};
# char errbuf[1024];
# *errbuf = '\0';
EOF
while (@line) {
&CASE_handler if check_keyword("CASE");
print Q(<<"EOF");
-# $except [[
+# $args{except} [[
EOF
# do initialization of input variables
$args_match{"RETVAL"} = 0;
$var_types{"RETVAL"} = $ret_type;
print "\tdXSTARG;\n"
- if $WantOptimize and $targetable{$type_kind{$ret_type}};
+ if $args{optimize} and $targetable{$type_kind{$ret_type}};
}
if (@fake_INPUT or @fake_INPUT_pre) {
print "\t$RETVAL_code\n";
}
elsif ($gotRETVAL || $wantRETVAL) {
- my $t = $WantOptimize && $targetable{$type_kind{$ret_type}};
+ my $t = $args{optimize} && $targetable{$type_kind{$ret_type}};
my $var = 'RETVAL';
my $type = $ret_type;
print Q(<<"EOF");
# ]]
EOF
- print Q(<<"EOF") if $except;
+ print Q(<<"EOF") if $args{except};
# BEGHANDLERS
# CATCHALL
# sprintf(errbuf, "%s: %s\\tpropagated", Xname, Xreason);
death(/^$BLOCK_re/o ? "Misplaced `$1:'" : "Junk at end of function ($_)");
}
- print Q(<<"EOF") if $except;
+ print Q(<<"EOF") if $args{except};
# if (errbuf[0])
# Perl_croak(aTHX_ errbuf);
EOF
return 0;
}
-sub C_string ($) {
- my($string) = @_;
-
- $string =~ s[\\][\\\\]g;
- $string;
-}
-
sub ProtoString ($) {
my ($type) = @_;