make xsubpp skip embedded pod (from Matthias Neeracher
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / xsubpp
CommitLineData
2304df62 1#!./miniperl
75f92628 2
3=head1 NAME
4
5xsubpp - compiler to convert Perl XS code into C code
6
7=head1 SYNOPSIS
8
b26a54d0 9B<xsubpp> [B<-v>] [B<-C++>] [B<-except>] [B<-s pattern>] [B<-prototypes>] [B<-noversioncheck>] [B<-nolinenumbers>] [B<-nooptimize>] [B<-typemap typemap>] ... file.xs
75f92628 10
11=head1 DESCRIPTION
12
b26a54d0 13This compiler is typically run by the makefiles created by L<ExtUtils::MakeMaker>.
14
75f92628 15I<xsubpp> will compile XS code into C code by embedding the constructs
16necessary to let C functions manipulate Perl values and creates the glue
17necessary to let Perl access those functions. The compiler uses typemaps to
18determine how to map C function parameters and variables to Perl values.
19
20The compiler will search for typemap files called I<typemap>. It will use
21the following search path to find default typemaps, with the rightmost
22typemap taking precedence.
23
24 ../../../typemap:../../typemap:../typemap:typemap
25
26=head1 OPTIONS
27
b26a54d0 28Note that the C<XSOPT> MakeMaker option may be used to add these options to
29any makefiles generated by MakeMaker.
30
75f92628 31=over 5
32
33=item B<-C++>
34
35Adds ``extern "C"'' to the C code.
36
75f92628 37=item B<-except>
38
39Adds exception handling stubs to the C code.
40
41=item B<-typemap typemap>
42
43Indicates that a user-supplied typemap should take precedence over the
44default typemaps. This option may be used multiple times, with the last
45typemap having the highest precedence.
46
8e07c86e 47=item B<-v>
48
49Prints the I<xsubpp> version number to standard output, then exits.
50
8fc38fda 51=item B<-prototypes>
382b8d97 52
8fc38fda 53By default I<xsubpp> will not automatically generate prototype code for
54all xsubs. This flag will enable prototypes.
55
56=item B<-noversioncheck>
57
58Disables the run time test that determines if the object file (derived
59from the C<.xs> file) and the C<.pm> files have the same version
60number.
382b8d97 61
6f1abe2b 62=item B<-nolinenumbers>
63
64Prevents the inclusion of `#line' directives in the output.
65
b26a54d0 66=item B<-nooptimize>
67
68Disables certain optimizations. The only optimization that is currently
69affected is the use of I<target>s by the output C code (see L<perlguts>).
70This may significantly slow down the generated code, but this is the way
71B<xsubpp> of 5.005 and earlier operated.
72
11416672 73=item B<-noinout>
74
75Disable recognition of C<IN>, C<OUT_LIST> and C<INOUT_LIST> declarations.
76
77=item B<-noargtypes>
78
79Disable recognition of ANSI-like descriptions of function signature.
80
c5be433b 81=back
75f92628 82
83=head1 ENVIRONMENT
84
85No environment variables are used.
86
87=head1 AUTHOR
88
89Larry Wall
90
f06db76b 91=head1 MODIFICATION HISTORY
92
8e07c86e 93See the file F<changes.pod>.
e50aee73 94
75f92628 95=head1 SEE ALSO
96
55a00e51 97perl(1), perlxs(1), perlxstut(1)
75f92628 98
99=cut
93a17b20 100
382b8d97 101require 5.002;
774d564b 102use Cwd;
4230ab3f 103use vars '$cplusplus';
7ad6fb0b 104use vars '%v';
382b8d97 105
01f988be 106use Config;
107
aa689395 108sub Q ;
109
774d564b 110# Global Constants
774d564b 111
cfc02341 112$XSUBPP_version = "1.9507";
aa689395 113
114my ($Is_VMS, $SymSet);
115if ($^O eq 'VMS') {
116 $Is_VMS = 1;
117 # Establish set of global symbols with max length 28, since xsubpp
118 # will later add the 'XS_' prefix.
119 require ExtUtils::XSSymSet;
120 $SymSet = new ExtUtils::XSSymSet 28;
121}
8fc38fda 122
c07a80fd 123$FH = 'File0000' ;
8fc38fda 124
11416672 125$usage = "Usage: xsubpp [-v] [-C++] [-except] [-prototypes] [-noversioncheck] [-nolinenumbers] [-nooptimize] [-noinout] [-noargtypes] [-s pattern] [-typemap typemap]... file.xs\n";
f06db76b 126
382b8d97 127$proto_re = "[" . quotemeta('\$%&*@;') . "]" ;
01f988be 128# mjn
129$OBJ = 1 if $Config{'ccflags'} =~ /PERL_OBJECT/i;
93a17b20 130
8e07c86e 131$except = "";
8fc38fda 132$WantPrototypes = -1 ;
133$WantVersionChk = 1 ;
134$ProtoUsed = 0 ;
6f1abe2b 135$WantLineNumbers = 1 ;
b26a54d0 136$WantOptimize = 1 ;
11416672 137
138my $process_inout = 1;
139my $process_argtypes = 1;
140
8e07c86e 141SWITCH: while (@ARGV and $ARGV[0] =~ /^-./) {
93a17b20 142 $flag = shift @ARGV;
e50aee73 143 $flag =~ s/^-// ;
ff68c719 144 $spat = quotemeta shift, next SWITCH if $flag eq 's';
8990e307 145 $cplusplus = 1, next SWITCH if $flag eq 'C++';
382b8d97 146 $WantPrototypes = 0, next SWITCH if $flag eq 'noprototypes';
147 $WantPrototypes = 1, next SWITCH if $flag eq 'prototypes';
8fc38fda 148 $WantVersionChk = 0, next SWITCH if $flag eq 'noversioncheck';
149 $WantVersionChk = 1, next SWITCH if $flag eq 'versioncheck';
c5be433b 150 # XXX left this in for compat
b207eff1 151 $WantCAPI = 1, next SWITCH if $flag eq 'object_capi';
8e07c86e 152 $except = " TRY", next SWITCH if $flag eq 'except';
8990e307 153 push(@tm,shift), next SWITCH if $flag eq 'typemap';
6f1abe2b 154 $WantLineNumbers = 0, next SWITCH if $flag eq 'nolinenumbers';
155 $WantLineNumbers = 1, next SWITCH if $flag eq 'linenumbers';
b26a54d0 156 $WantOptimize = 0, next SWITCH if $flag eq 'nooptimize';
157 $WantOptimize = 1, next SWITCH if $flag eq 'optimize';
11416672 158 $process_inout = 0, next SWITCH if $flag eq 'noinout';
159 $process_inout = 1, next SWITCH if $flag eq 'inout';
160 $process_argtypes = 0, next SWITCH if $flag eq 'noargtypes';
161 $process_argtypes = 1, next SWITCH if $flag eq 'argtypes';
b26a54d0 162 (print "xsubpp version $XSUBPP_version\n"), exit
8e07c86e 163 if $flag eq 'v';
93a17b20 164 die $usage;
165}
8fc38fda 166if ($WantPrototypes == -1)
167 { $WantPrototypes = 0}
168else
169 { $ProtoUsed = 1 }
170
171
8990e307 172@ARGV == 1 or die $usage;
c2960299 173($dir, $filename) = $ARGV[0] =~ m#(.*)/(.*)#
57497940 174 or ($dir, $filename) = $ARGV[0] =~ m#(.*)\\(.*)#
c2960299 175 or ($dir, $filename) = $ARGV[0] =~ m#(.*[>\]])(.*)#
8990e307 176 or ($dir, $filename) = ('.', $ARGV[0]);
177chdir($dir);
774d564b 178$pwd = cwd();
8fc38fda 179
180++ $IncludedFiles{$ARGV[0]} ;
93a17b20 181
4230ab3f 182my(@XSStack) = ({type => 'none'}); # Stack of conditionals and INCLUDEs
183my($XSS_work_idx, $cpp_next_tmp) = (0, "XSubPPtmpAAAA");
aa689395 184
4230ab3f 185
f06db76b 186sub TrimWhitespace
187{
188 $_[0] =~ s/^\s+|\s+$//go ;
189}
190
191sub TidyType
192{
193 local ($_) = @_ ;
194
195 # rationalise any '*' by joining them into bunches and removing whitespace
196 s#\s*(\*+)\s*#$1#g;
e50aee73 197 s#(\*+)# $1 #g ;
f06db76b 198
199 # change multiple whitespace into a single space
200 s/\s+/ /g ;
201
202 # trim leading & trailing whitespace
203 TrimWhitespace($_) ;
204
205 $_ ;
206}
207
93a17b20 208$typemap = shift @ARGV;
8990e307 209foreach $typemap (@tm) {
210 die "Can't find $typemap in $pwd\n" unless -r $typemap;
93a17b20 211}
748a9306 212unshift @tm, qw(../../../../lib/ExtUtils/typemap ../../../lib/ExtUtils/typemap
213 ../../lib/ExtUtils/typemap ../../../typemap ../../typemap
214 ../typemap typemap);
8990e307 215foreach $typemap (@tm) {
f06db76b 216 next unless -e $typemap ;
217 # skip directories, binary files etc.
218 warn("Warning: ignoring non-text typemap file '$typemap'\n"), next
219 unless -T $typemap ;
220 open(TYPEMAP, $typemap)
221 or warn ("Warning: could not open typemap file '$typemap': $!\n"), next;
e50aee73 222 $mode = 'Typemap';
c2960299 223 $junk = "" ;
8990e307 224 $current = \$junk;
225 while (<TYPEMAP>) {
e50aee73 226 next if /^\s*#/;
e1f0c0aa 227 my $line_no = $. + 1;
8e07c86e 228 if (/^INPUT\s*$/) { $mode = 'Input'; $current = \$junk; next; }
229 if (/^OUTPUT\s*$/) { $mode = 'Output'; $current = \$junk; next; }
230 if (/^TYPEMAP\s*$/) { $mode = 'Typemap'; $current = \$junk; next; }
e50aee73 231 if ($mode eq 'Typemap') {
232 chomp;
f06db76b 233 my $line = $_ ;
234 TrimWhitespace($_) ;
235 # skip blank lines and comment lines
236 next if /^$/ or /^#/ ;
382b8d97 237 my($type,$kind, $proto) = /^\s*(.*?\S)\s+(\S+)\s*($proto_re*)\s*$/ or
238 warn("Warning: File '$typemap' Line $. '$line' TYPEMAP entry needs 2 or 3 columns\n"), next;
239 $type = TidyType($type) ;
240 $type_kind{$type} = $kind ;
241 # prototype defaults to '$'
93d3b392 242 $proto = "\$" unless $proto ;
382b8d97 243 warn("Warning: File '$typemap' Line $. '$line' Invalid prototype '$proto'\n")
244 unless ValidProtoString($proto) ;
245 $proto_letter{$type} = C_string($proto) ;
8e07c86e 246 }
247 elsif (/^\s/) {
248 $$current .= $_;
463ee0b2 249 }
e50aee73 250 elsif ($mode eq 'Input') {
8e07c86e 251 s/\s+$//;
252 $input_expr{$_} = '';
253 $current = \$input_expr{$_};
93a17b20 254 }
8990e307 255 else {
8e07c86e 256 s/\s+$//;
257 $output_expr{$_} = '';
258 $current = \$output_expr{$_};
93a17b20 259 }
8990e307 260 }
261 close(TYPEMAP);
262}
93a17b20 263
8990e307 264foreach $key (keys %input_expr) {
265 $input_expr{$key} =~ s/\n+$//;
266}
93a17b20 267
14455d6c 268$bal = qr[(?:(?>[^()]+)|\((??{ $bal })\))*]; # ()-balanced
b26a54d0 269$cast = qr[(?:\(\s*SV\s*\*\s*\)\s*)?]; # Optional (SV*) cast
14455d6c 270$size = qr[,\s* (??{ $bal }) ]x; # Third arg (to setpvn)
b26a54d0 271
272foreach $key (keys %output_expr) {
273 use re 'eval';
274
275 my ($t, $with_size, $arg, $sarg) =
276 ($output_expr{$key} =~
277 m[^ \s+ sv_set ( [iunp] ) v (n)? # Type, is_setpvn
278 \s* \( \s* $cast \$arg \s* ,
14455d6c 279 \s* ( (??{ $bal }) ) # Set from
280 ( (??{ $size }) )? # Possible sizeof set-from
b26a54d0 281 \) \s* ; \s* $
282 ]x);
283 $targetable{$key} = [$t, $with_size, $arg, $sarg] if $t;
284}
285
8e07c86e 286$END = "!End!\n\n"; # "impossible" keyword (multiple newline)
287
288# Match an XS keyword
382b8d97 289$BLOCK_re= '\s*(' . join('|', qw(
290 REQUIRE BOOT CASE PREINIT INPUT INIT CODE PPCODE OUTPUT
8fc38fda 291 CLEANUP ALIAS PROTOTYPES PROTOTYPE VERSIONCHECK INCLUDE
63385af5 292 SCOPE INTERFACE INTERFACE_MACRO C_ARGS POSTCALL
382b8d97 293 )) . "|$END)\\s*:";
8e07c86e 294
295# Input: ($_, @line) == unparsed input.
296# Output: ($_, @line) == (rest of line, following lines).
297# Return: the matched keyword if found, otherwise 0
298sub check_keyword {
299 $_ = shift(@line) while !/\S/ && @line;
300 s/^(\s*)($_[0])\s*:\s*(?:#.*)?/$1/s && $2;
301}
302
f8b8e0a4 303my ($C_group_rex, $C_arg);
304# Group in C (no support for comments or literals)
305$C_group_rex = qr/ [({\[]
14455d6c 306 (?: (?> [^()\[\]{}]+ ) | (??{ $C_group_rex }) )*
f8b8e0a4 307 [)}\]] /x ;
308# Chunk in C without comma at toplevel (no comments):
309$C_arg = qr/ (?: (?> [^()\[\]{},"']+ )
14455d6c 310 | (??{ $C_group_rex })
f8b8e0a4 311 | " (?: (?> [^\\"]+ )
312 | \\.
313 )* " # String literal
314 | ' (?: (?> [^\\']+ ) | \\. )* ' # Char literal
315 )* /xs;
8e07c86e 316
6f1abe2b 317if ($WantLineNumbers) {
318 {
319 package xsubpp::counter;
320 sub TIEHANDLE {
321 my ($class, $cfile) = @_;
322 my $buf = "";
323 $SECTION_END_MARKER = "#line --- \"$cfile\"";
324 $line_no = 1;
325 bless \$buf;
326 }
327
328 sub PRINT {
329 my $self = shift;
330 for (@_) {
331 $$self .= $_;
332 while ($$self =~ s/^([^\n]*\n)//) {
333 my $line = $1;
334 ++ $line_no;
335 $line =~ s|^\#line\s+---(?=\s)|#line $line_no|;
336 print STDOUT $line;
337 }
338 }
339 }
340
341 sub PRINTF {
342 my $self = shift;
343 my $fmt = shift;
344 $self->PRINT(sprintf($fmt, @_));
345 }
346
347 sub DESTROY {
348 # Not necessary if we're careful to end with a "\n"
349 my $self = shift;
350 print STDOUT $$self;
351 }
352 }
353
354 my $cfile = $filename;
355 $cfile =~ s/\.xs$/.c/i or $cfile .= ".c";
356 tie(*PSEUDO_STDOUT, 'xsubpp::counter', $cfile);
357 select PSEUDO_STDOUT;
358}
359
8e07c86e 360sub print_section {
6f1abe2b 361 # the "do" is required for right semantics
362 do { $_ = shift(@line) } while !/\S/ && @line;
363
364 print("#line ", $line_no[@line_no - @line -1], " \"$filename\"\n")
d3308daf 365 if $WantLineNumbers && !/^\s*#\s*line\b/ && !/^#if XSubPPtmp/;
8e07c86e 366 for (; defined($_) && !/^$BLOCK_re/o; $_ = shift(@line)) {
367 print "$_\n";
368 }
6f1abe2b 369 print "$xsubpp::counter::SECTION_END_MARKER\n" if $WantLineNumbers;
8e07c86e 370}
371
cfc02341 372sub merge_section {
373 my $in = '';
374
375 while (!/\S/ && @line) {
376 $_ = shift(@line);
377 }
378
379 for (; defined($_) && !/^$BLOCK_re/o; $_ = shift(@line)) {
380 $in .= "$_\n";
381 }
382 chomp $in;
383 return $in;
384}
385
8fc38fda 386sub process_keyword($)
387{
388 my($pattern) = @_ ;
389 my $kwd ;
390
391 &{"${kwd}_handler"}()
392 while $kwd = check_keyword($pattern) ;
393}
394
8e07c86e 395sub CASE_handler {
396 blurt ("Error: `CASE:' after unconditional `CASE:'")
397 if $condnum && $cond eq '';
398 $cond = $_;
399 TrimWhitespace($cond);
400 print " ", ($condnum++ ? " else" : ""), ($cond ? " if ($cond)\n" : "\n");
401 $_ = '' ;
402}
403
404sub INPUT_handler {
405 for (; !/^$BLOCK_re/o; $_ = shift(@line)) {
406 last if /^\s*NOT_IMPLEMENTED_YET/;
407 next unless /\S/; # skip blank lines
408
409 TrimWhitespace($_) ;
410 my $line = $_ ;
411
412 # remove trailing semicolon if no initialisation
7ad6fb0b 413 s/\s*;$//g unless /[=;+].*\S/ ;
8e07c86e 414
415 # check for optional initialisation code
416 my $var_init = '' ;
7ad6fb0b 417 $var_init = $1 if s/\s*([=;+].*)$//s ;
8e07c86e 418 $var_init =~ s/"/\\"/g;
419
420 s/\s+/ /g;
421 my ($var_type, $var_addr, $var_name) = /^(.*?[^& ]) *(\&?) *\b(\w+)$/s
422 or blurt("Error: invalid argument declaration '$line'"), next;
423
424 # Check for duplicate definitions
425 blurt ("Error: duplicate definition of argument '$var_name' ignored"), next
f8b8e0a4 426 if $arg_list{$var_name}++
427 or defined $arg_types{$var_name} and not $processing_arg_with_types;
8e07c86e 428
429 $thisdone |= $var_name eq "THIS";
430 $retvaldone |= $var_name eq "RETVAL";
431 $var_types{$var_name} = $var_type;
ddf6bed1 432 # XXXX This check is a safeguard against the unfinished conversion of
433 # generate_init(). When generate_init() is fixed,
434 # one can use 2-args map_type() unconditionally.
435 if ($var_type =~ / \( \s* \* \s* \) /x) {
436 # Function pointers are not yet supported with &output_init!
437 print "\t" . &map_type($var_type, $var_name);
438 $name_printed = 1;
439 } else {
440 print "\t" . &map_type($var_type);
441 $name_printed = 0;
442 }
8e07c86e 443 $var_num = $args_match{$var_name};
382b8d97 444
8fc38fda 445 $proto_arg[$var_num] = ProtoString($var_type)
446 if $var_num ;
8e07c86e 447 if ($var_addr) {
448 $var_addr{$var_name} = 1;
449 $func_args =~ s/\b($var_name)\b/&$1/;
450 }
f8b8e0a4 451 if ($var_init =~ /^[=;]\s*NO_INIT\s*;?\s*$/
63385af5 452 or $in_out{$var_name} and $in_out{$var_name} eq 'OUTLIST'
f8b8e0a4 453 and $var_init !~ /\S/) {
ddf6bed1 454 if ($name_printed) {
455 print ";\n";
456 } else {
9bea678f 457 print "\t$var_name;\n";
ddf6bed1 458 }
8e07c86e 459 } elsif ($var_init =~ /\S/) {
ddf6bed1 460 &output_init($var_type, $var_num, $var_name, $var_init, $name_printed);
8e07c86e 461 } elsif ($var_num) {
462 # generate initialization code
ddf6bed1 463 &generate_init($var_type, $var_num, $var_name, $name_printed);
8e07c86e 464 } else {
465 print ";\n";
466 }
467 }
468}
469
470sub OUTPUT_handler {
471 for (; !/^$BLOCK_re/o; $_ = shift(@line)) {
472 next unless /\S/;
ef50df4b 473 if (/^\s*SETMAGIC\s*:\s*(ENABLE|DISABLE)\s*/) {
474 $DoSetMagic = ($1 eq "ENABLE" ? 1 : 0);
475 next;
476 }
8e07c86e 477 my ($outarg, $outcode) = /^\s*(\S+)\s*(.*?)\s*$/s ;
478 blurt ("Error: duplicate OUTPUT argument '$outarg' ignored"), next
479 if $outargs{$outarg} ++ ;
480 if (!$gotRETVAL and $outarg eq 'RETVAL') {
481 # deal with RETVAL last
482 $RETVAL_code = $outcode ;
483 $gotRETVAL = 1 ;
484 next ;
485 }
486 blurt ("Error: OUTPUT $outarg not an argument"), next
487 unless defined($args_match{$outarg});
488 blurt("Error: No input definition for OUTPUT argument '$outarg' - ignored"), next
489 unless defined $var_types{$outarg} ;
f78230ad 490 $var_num = $args_match{$outarg};
8e07c86e 491 if ($outcode) {
492 print "\t$outcode\n";
f78230ad 493 print "\tSvSETMAGIC(ST(" , $var_num-1 , "));\n" if $DoSetMagic;
8e07c86e 494 } else {
ef50df4b 495 &generate_output($var_types{$outarg}, $var_num, $outarg, $DoSetMagic);
8e07c86e 496 }
497 }
498}
499
cfc02341 500sub C_ARGS_handler() {
501 my $in = merge_section();
502
503 TrimWhitespace($in);
504 $func_args = $in;
505}
506
507sub INTERFACE_MACRO_handler() {
508 my $in = merge_section();
509
510 TrimWhitespace($in);
511 if ($in =~ /\s/) { # two
512 ($interface_macro, $interface_macro_set) = split ' ', $in;
513 } else {
514 $interface_macro = $in;
515 $interface_macro_set = 'UNKNOWN_CVT'; # catch later
516 }
517 $interface = 1; # local
518 $Interfaces = 1; # global
519}
520
521sub INTERFACE_handler() {
522 my $in = merge_section();
523
524 TrimWhitespace($in);
525
526 foreach (split /[\s,]+/, $in) {
527 $Interfaces{$_} = $_;
528 }
529 print Q<<"EOF";
530# XSFUNCTION = $interface_macro($ret_type,cv,XSANY.any_dptr);
531EOF
532 $interface = 1; # local
533 $Interfaces = 1; # global
534}
535
8fc38fda 536sub CLEANUP_handler() { print_section() }
537sub PREINIT_handler() { print_section() }
63385af5 538sub POSTCALL_handler() { print_section() }
8fc38fda 539sub INIT_handler() { print_section() }
540
8e07c86e 541sub GetAliases
542{
543 my ($line) = @_ ;
544 my ($orig) = $line ;
545 my ($alias) ;
546 my ($value) ;
547
548 # Parse alias definitions
549 # format is
550 # alias = value alias = value ...
551
552 while ($line =~ s/^\s*([\w:]+)\s*=\s*(\w+)\s*//) {
553 $alias = $1 ;
554 $orig_alias = $alias ;
555 $value = $2 ;
556
557 # check for optional package definition in the alias
558 $alias = $Packprefix . $alias if $alias !~ /::/ ;
559
560 # check for duplicate alias name & duplicate value
561 Warn("Warning: Ignoring duplicate alias '$orig_alias'")
4230ab3f 562 if defined $XsubAliases{$alias} ;
8e07c86e 563
4230ab3f 564 Warn("Warning: Aliases '$orig_alias' and '$XsubAliasValues{$value}' have identical values")
565 if $XsubAliasValues{$value} ;
8e07c86e 566
4230ab3f 567 $XsubAliases = 1;
568 $XsubAliases{$alias} = $value ;
569 $XsubAliasValues{$value} = $orig_alias ;
8e07c86e 570 }
571
572 blurt("Error: Cannot parse ALIAS definitions from '$orig'")
573 if $line ;
574}
575
382b8d97 576sub ALIAS_handler ()
8e07c86e 577{
578 for (; !/^$BLOCK_re/o; $_ = shift(@line)) {
579 next unless /\S/;
580 TrimWhitespace($_) ;
581 GetAliases($_) if $_ ;
582 }
583}
584
382b8d97 585sub REQUIRE_handler ()
8e07c86e 586{
587 # the rest of the current line should contain a version number
588 my ($Ver) = $_ ;
589
590 TrimWhitespace($Ver) ;
591
592 death ("Error: REQUIRE expects a version number")
593 unless $Ver ;
594
595 # check that the version number is of the form n.n
596 death ("Error: REQUIRE: expected a number, got '$Ver'")
597 unless $Ver =~ /^\d+(\.\d*)?/ ;
598
599 death ("Error: xsubpp $Ver (or better) required--this is only $XSUBPP_version.")
600 unless $XSUBPP_version >= $Ver ;
601}
602
8fc38fda 603sub VERSIONCHECK_handler ()
604{
605 # the rest of the current line should contain either ENABLE or
606 # DISABLE
607
608 TrimWhitespace($_) ;
609
610 # check for ENABLE/DISABLE
611 death ("Error: VERSIONCHECK: ENABLE/DISABLE")
612 unless /^(ENABLE|DISABLE)/i ;
613
614 $WantVersionChk = 1 if $1 eq 'ENABLE' ;
615 $WantVersionChk = 0 if $1 eq 'DISABLE' ;
616
617}
618
382b8d97 619sub PROTOTYPE_handler ()
620{
7d41bd0a 621 my $specified ;
622
c07a80fd 623 death("Error: Only 1 PROTOTYPE definition allowed per xsub")
624 if $proto_in_this_xsub ++ ;
625
382b8d97 626 for (; !/^$BLOCK_re/o; $_ = shift(@line)) {
627 next unless /\S/;
7d41bd0a 628 $specified = 1 ;
382b8d97 629 TrimWhitespace($_) ;
630 if ($_ eq 'DISABLE') {
631 $ProtoThisXSUB = 0
632 }
633 elsif ($_ eq 'ENABLE') {
634 $ProtoThisXSUB = 1
635 }
636 else {
637 # remove any whitespace
638 s/\s+//g ;
639 death("Error: Invalid prototype '$_'")
640 unless ValidProtoString($_) ;
641 $ProtoThisXSUB = C_string($_) ;
642 }
643 }
c07a80fd 644
7d41bd0a 645 # If no prototype specified, then assume empty prototype ""
646 $ProtoThisXSUB = 2 unless $specified ;
647
8fc38fda 648 $ProtoUsed = 1 ;
c07a80fd 649
382b8d97 650}
651
db3b9414 652sub SCOPE_handler ()
653{
654 death("Error: Only 1 SCOPE declaration allowed per xsub")
655 if $scope_in_this_xsub ++ ;
656
657 for (; !/^$BLOCK_re/o; $_ = shift(@line)) {
658 next unless /\S/;
659 TrimWhitespace($_) ;
660 if ($_ =~ /^DISABLE/i) {
661 $ScopeThisXSUB = 0
662 }
663 elsif ($_ =~ /^ENABLE/i) {
664 $ScopeThisXSUB = 1
665 }
666 }
667
668}
669
382b8d97 670sub PROTOTYPES_handler ()
671{
672 # the rest of the current line should contain either ENABLE or
673 # DISABLE
674
675 TrimWhitespace($_) ;
676
677 # check for ENABLE/DISABLE
678 death ("Error: PROTOTYPES: ENABLE/DISABLE")
679 unless /^(ENABLE|DISABLE)/i ;
680
681 $WantPrototypes = 1 if $1 eq 'ENABLE' ;
682 $WantPrototypes = 0 if $1 eq 'DISABLE' ;
8fc38fda 683 $ProtoUsed = 1 ;
382b8d97 684
685}
686
8fc38fda 687sub INCLUDE_handler ()
688{
689 # the rest of the current line should contain a valid filename
690
691 TrimWhitespace($_) ;
692
8fc38fda 693 death("INCLUDE: filename missing")
694 unless $_ ;
695
696 death("INCLUDE: output pipe is illegal")
697 if /^\s*\|/ ;
698
699 # simple minded recursion detector
700 death("INCLUDE loop detected")
701 if $IncludedFiles{$_} ;
702
703 ++ $IncludedFiles{$_} unless /\|\s*$/ ;
704
705 # Save the current file context.
4230ab3f 706 push(@XSStack, {
707 type => 'file',
8fc38fda 708 LastLine => $lastline,
709 LastLineNo => $lastline_no,
710 Line => \@line,
711 LineNo => \@line_no,
712 Filename => $filename,
c07a80fd 713 Handle => $FH,
8fc38fda 714 }) ;
715
c07a80fd 716 ++ $FH ;
8fc38fda 717
718 # open the new file
c07a80fd 719 open ($FH, "$_") or death("Cannot open '$_': $!") ;
8fc38fda 720
721 print Q<<"EOF" ;
722#
723#/* INCLUDE: Including '$_' from '$filename' */
724#
725EOF
726
8fc38fda 727 $filename = $_ ;
728
c07a80fd 729 # Prime the pump by reading the first
730 # non-blank line
731
732 # skip leading blank lines
733 while (<$FH>) {
734 last unless /^\s*$/ ;
735 }
736
737 $lastline = $_ ;
8fc38fda 738 $lastline_no = $. ;
739
740}
741
742sub PopFile()
743{
4230ab3f 744 return 0 unless $XSStack[-1]{type} eq 'file' ;
745
746 my $data = pop @XSStack ;
8fc38fda 747 my $ThisFile = $filename ;
748 my $isPipe = ($filename =~ /\|\s*$/) ;
749
750 -- $IncludedFiles{$filename}
751 unless $isPipe ;
752
c07a80fd 753 close $FH ;
8fc38fda 754
c07a80fd 755 $FH = $data->{Handle} ;
8fc38fda 756 $filename = $data->{Filename} ;
757 $lastline = $data->{LastLine} ;
758 $lastline_no = $data->{LastLineNo} ;
759 @line = @{ $data->{Line} } ;
760 @line_no = @{ $data->{LineNo} } ;
4230ab3f 761
8fc38fda 762 if ($isPipe and $? ) {
763 -- $lastline_no ;
764 print STDERR "Error reading from pipe '$ThisFile': $! in $filename, line $lastline_no\n" ;
765 exit 1 ;
766 }
767
768 print Q<<"EOF" ;
769#
770#/* INCLUDE: Returning to '$filename' from '$ThisFile' */
771#
772EOF
773
774 return 1 ;
775}
776
382b8d97 777sub ValidProtoString ($)
778{
779 my($string) = @_ ;
780
781 if ( $string =~ /^$proto_re+$/ ) {
782 return $string ;
783 }
784
785 return 0 ;
786}
787
788sub C_string ($)
789{
790 my($string) = @_ ;
791
792 $string =~ s[\\][\\\\]g ;
793 $string ;
794}
795
796sub ProtoString ($)
797{
798 my ($type) = @_ ;
799
93d3b392 800 $proto_letter{$type} or "\$" ;
382b8d97 801}
802
8e07c86e 803sub check_cpp {
804 my @cpp = grep(/^\#\s*(?:if|e\w+)/, @line);
805 if (@cpp) {
806 my ($cpp, $cpplevel);
807 for $cpp (@cpp) {
808 if ($cpp =~ /^\#\s*if/) {
809 $cpplevel++;
810 } elsif (!$cpplevel) {
811 Warn("Warning: #else/elif/endif without #if in this function");
4230ab3f 812 print STDERR " (precede it with a blank line if the matching #if is outside the function)\n"
813 if $XSStack[-1]{type} eq 'if';
8e07c86e 814 return;
815 } elsif ($cpp =~ /^\#\s*endif/) {
816 $cpplevel--;
817 }
818 }
819 Warn("Warning: #if without #endif in this function") if $cpplevel;
820 }
821}
822
823
8990e307 824sub Q {
e50aee73 825 my($text) = @_;
4633a7c4 826 $text =~ s/^#//gm;
2304df62 827 $text =~ s/\[\[/{/g;
828 $text =~ s/\]\]/}/g;
8990e307 829 $text;
93a17b20 830}
831
c07a80fd 832open($FH, $filename) or die "cannot open $filename: $!\n";
c2960299 833
f06db76b 834# Identify the version of xsubpp used
f06db76b 835print <<EOM ;
e50aee73 836/*
837 * This file was generated automatically by xsubpp version $XSUBPP_version from the
93d3b392 838 * contents of $filename. Do not edit this file, edit $filename instead.
e50aee73 839 *
840 * ANY CHANGES MADE HERE WILL BE LOST!
f06db76b 841 *
842 */
e50aee73 843
f06db76b 844EOM
6f1abe2b 845
846
847print("#line 1 \"$filename\"\n")
848 if $WantLineNumbers;
f06db76b 849
e03d20b3 850firstmodule:
c07a80fd 851while (<$FH>) {
e03d20b3 852 if (/^=/) {
853 do {
854 next firstmodule if /^=cut\s*$/;
855 } while (<$FH>);
856 &Exit;
857 }
e50aee73 858 last if ($Module, $Package, $Prefix) =
859 /^MODULE\s*=\s*([\w:]+)(?:\s+PACKAGE\s*=\s*([\w:]+))?(?:\s+PREFIX\s*=\s*(\S+))?\s*$/;
01f988be 860
861 if ($OBJ) {
b85ee828 862 s/#if(?:def\s|\s+defined)\s*(\(__cplusplus\)|__cplusplus)/#if defined(__cplusplus) && !defined(PERL_OBJECT)/;
01f988be 863 }
a0d0e21e 864 print $_;
93a17b20 865}
e50aee73 866&Exit unless defined $_;
867
cfc02341 868print "$xsubpp::counter::SECTION_END_MARKER\n" if $WantLineNumbers;
869
8fc38fda 870$lastline = $_;
871$lastline_no = $.;
93a17b20 872
c07a80fd 873# Read next xsub into @line from ($lastline, <$FH>).
2304df62 874sub fetch_para {
875 # parse paragraph
4230ab3f 876 death ("Error: Unterminated `#if/#ifdef/#ifndef'")
877 if !defined $lastline && $XSStack[-1]{type} eq 'if';
2304df62 878 @line = ();
c2960299 879 @line_no = () ;
4230ab3f 880 return PopFile() if !defined $lastline;
e50aee73 881
882 if ($lastline =~
883 /^MODULE\s*=\s*([\w:]+)(?:\s+PACKAGE\s*=\s*([\w:]+))?(?:\s+PREFIX\s*=\s*(\S+))?\s*$/) {
884 $Module = $1;
8e07c86e 885 $Package = defined($2) ? $2 : ''; # keep -w happy
886 $Prefix = defined($3) ? $3 : ''; # keep -w happy
ff68c719 887 $Prefix = quotemeta $Prefix ;
e50aee73 888 ($Module_cname = $Module) =~ s/\W/_/g;
8e07c86e 889 ($Packid = $Package) =~ tr/:/_/;
e50aee73 890 $Packprefix = $Package;
8e07c86e 891 $Packprefix .= "::" if $Packprefix ne "";
2304df62 892 $lastline = "";
e50aee73 893 }
894
895 for(;;) {
e03d20b3 896 # Skip embedded PODs
897 while ($lastline =~ /^=/) {
898 while ($lastline = <$FH>) {
899 last if ($lastline =~ /^=cut\s*$/);
900 }
901 death ("Error: Unterminated pod") unless $lastline;
902 $lastline = <$FH>;
903 chomp $lastline;
904 $lastline =~ s/^\s+$//;
905 }
e50aee73 906 if ($lastline !~ /^\s*#/ ||
4230ab3f 907 # CPP directives:
908 # ANSI: if ifdef ifndef elif else endif define undef
909 # line error pragma
910 # gcc: warning include_next
911 # obj-c: import
912 # others: ident (gcc notes that some cpps have this one)
913 $lastline =~ /^#[ \t]*(?:(?:if|ifn?def|elif|else|endif|define|undef|pragma|error|warning|line\s+\d+|ident)\b|(?:include(?:_next)?|import)\s*["<].*[>"])/) {
e50aee73 914 last if $lastline =~ /^\S/ && @line && $line[-1] eq "";
915 push(@line, $lastline);
916 push(@line_no, $lastline_no) ;
93a17b20 917 }
e50aee73 918
919 # Read next line and continuation lines
c07a80fd 920 last unless defined($lastline = <$FH>);
e50aee73 921 $lastline_no = $.;
922 my $tmp_line;
923 $lastline .= $tmp_line
c07a80fd 924 while ($lastline =~ /\\$/ && defined($tmp_line = <$FH>));
f8b8e0a4 925
8e07c86e 926 chomp $lastline;
e50aee73 927 $lastline =~ s/^\s+$//;
2304df62 928 }
e50aee73 929 pop(@line), pop(@line_no) while @line && $line[-1] eq "";
e50aee73 930 1;
2304df62 931}
93a17b20 932
c2960299 933PARAGRAPH:
8e07c86e 934while (fetch_para()) {
e50aee73 935 # Print initial preprocessor statements and blank lines
4230ab3f 936 while (@line && $line[0] !~ /^[^\#]/) {
937 my $line = shift(@line);
938 print $line, "\n";
939 next unless $line =~ /^\#\s*((if)(?:n?def)?|elsif|else|endif)\b/;
940 my $statement = $+;
941 if ($statement eq 'if') {
942 $XSS_work_idx = @XSStack;
943 push(@XSStack, {type => 'if'});
944 } else {
945 death ("Error: `$statement' with no matching `if'")
946 if $XSStack[-1]{type} ne 'if';
947 if ($XSStack[-1]{varname}) {
948 push(@InitFileCode, "#endif\n");
949 push(@BootCode, "#endif");
950 }
951
952 my(@fns) = keys %{$XSStack[-1]{functions}};
953 if ($statement ne 'endif') {
954 # Hide the functions defined in other #if branches, and reset.
955 @{$XSStack[-1]{other_functions}}{@fns} = (1) x @fns;
956 @{$XSStack[-1]}{qw(varname functions)} = ('', {});
957 } else {
958 my($tmp) = pop(@XSStack);
959 0 while (--$XSS_work_idx
960 && $XSStack[$XSS_work_idx]{type} ne 'if');
961 # Keep all new defined functions
962 push(@fns, keys %{$tmp->{other_functions}});
963 @{$XSStack[$XSS_work_idx]{functions}}{@fns} = (1) x @fns;
964 }
965 }
966 }
e50aee73 967
968 next PARAGRAPH unless @line;
969
4230ab3f 970 if ($XSS_work_idx && !$XSStack[$XSS_work_idx]{varname}) {
971 # We are inside an #if, but have not yet #defined its xsubpp variable.
972 print "#define $cpp_next_tmp 1\n\n";
973 push(@InitFileCode, "#if $cpp_next_tmp\n");
974 push(@BootCode, "#if $cpp_next_tmp");
975 $XSStack[$XSS_work_idx]{varname} = $cpp_next_tmp++;
976 }
977
55497cff 978 death ("Code is not inside a function"
979 ." (maybe last function was ended by a blank line "
980 ." followed by a a statement on column one?)")
e50aee73 981 if $line[0] =~ /^\s/;
982
2304df62 983 # initialize info arrays
984 undef(%args_match);
985 undef(%var_types);
986 undef(%var_addr);
987 undef(%defaults);
988 undef($class);
989 undef($static);
990 undef($elipsis);
f06db76b 991 undef($wantRETVAL) ;
f8b8e0a4 992 undef($RETVAL_no_return) ;
f06db76b 993 undef(%arg_list) ;
382b8d97 994 undef(@proto_arg) ;
f8b8e0a4 995 undef(@arg_with_types) ;
996 undef($processing_arg_with_types) ;
997 undef(%arg_types) ;
998 undef(@in_out) ;
999 undef(%in_out) ;
c07a80fd 1000 undef($proto_in_this_xsub) ;
db3b9414 1001 undef($scope_in_this_xsub) ;
cfc02341 1002 undef($interface);
f8b8e0a4 1003 undef($prepush_done);
cfc02341 1004 $interface_macro = 'XSINTERFACE_FUNC' ;
1005 $interface_macro_set = 'XSINTERFACE_FUNC_SET' ;
382b8d97 1006 $ProtoThisXSUB = $WantPrototypes ;
db3b9414 1007 $ScopeThisXSUB = 0;
f8b8e0a4 1008 $xsreturn = 0;
2304df62 1009
8e07c86e 1010 $_ = shift(@line);
8fc38fda 1011 while ($kwd = check_keyword("REQUIRE|PROTOTYPES|VERSIONCHECK|INCLUDE")) {
1012 &{"${kwd}_handler"}() ;
8e07c86e 1013 next PARAGRAPH unless @line ;
1014 $_ = shift(@line);
1015 }
c2960299 1016
8e07c86e 1017 if (check_keyword("BOOT")) {
1018 &check_cpp;
6f1abe2b 1019 push (@BootCode, "#line $line_no[@line_no - @line] \"$filename\"")
1020 if $WantLineNumbers && $line[0] !~ /^\s*#\s*line\b/;
1021 push (@BootCode, @line, "") ;
c2960299 1022 next PARAGRAPH ;
a0d0e21e 1023 }
c2960299 1024
8e07c86e 1025
1026 # extract return type, function name and arguments
cfc02341 1027 ($ret_type) = TidyType($_);
f8b8e0a4 1028 $RETVAL_no_return = 1 if $ret_type =~ s/^NO_OUTPUT\s+//;
8e07c86e 1029
11416672 1030 # Allow one-line ANSI-like declaration
1031 unshift @line, $2
1032 if $process_argtypes
1033 and $ret_type =~ s/^(.*?\w.*?)\s*\b(\w+\s*\(.*)/$1/s;
1034
c2960299 1035 # a function definition needs at least 2 lines
1036 blurt ("Error: Function definition too short '$ret_type'"), next PARAGRAPH
1037 unless @line ;
1038
8e07c86e 1039 $static = 1 if $ret_type =~ s/^static\s+//;
1040
2304df62 1041 $func_header = shift(@line);
c2960299 1042 blurt ("Error: Cannot parse function definition from '$func_header'"), next PARAGRAPH
f8b8e0a4 1043 unless $func_header =~ /^(?:([\w:]*)::)?(\w+)\s*\(\s*(.*?)\s*\)\s*(const)?\s*(;\s*)?$/s;
c2960299 1044
8e07c86e 1045 ($class, $func_name, $orig_args) = ($1, $2, $3) ;
f480b56a 1046 $class = "$4 $class" if $4;
2304df62 1047 ($pname = $func_name) =~ s/^($Prefix)?/$Packprefix/;
ff68c719 1048 ($clean_func_name = $func_name) =~ s/^$Prefix//;
1049 $Full_func_name = "${Packid}_$clean_func_name";
ff0cee69 1050 if ($Is_VMS) { $Full_func_name = $SymSet->addsym($Full_func_name); }
c2960299 1051
1052 # Check for duplicate function definition
4230ab3f 1053 for $tmp (@XSStack) {
1054 next unless defined $tmp->{functions}{$Full_func_name};
ff68c719 1055 Warn("Warning: duplicate function definition '$clean_func_name' detected");
4230ab3f 1056 last;
8e07c86e 1057 }
4230ab3f 1058 $XSStack[$XSS_work_idx]{functions}{$Full_func_name} ++ ;
cfc02341 1059 %XsubAliases = %XsubAliasValues = %Interfaces = ();
ef50df4b 1060 $DoSetMagic = 1;
c2960299 1061
f8b8e0a4 1062 $orig_args =~ s/\\\s*/ /g; # process line continuations
1063
1064 my %out_vars;
1065 if ($process_argtypes and $orig_args =~ /\S/) {
1066 my $args = "$orig_args ,";
14455d6c 1067 if ($args =~ /^( (??{ $C_arg }) , )* $ /x) {
1068 @args = ($args =~ /\G ( (??{ $C_arg }) ) , /xg);
f8b8e0a4 1069 for ( @args ) {
1070 s/^\s+//;
1071 s/\s+$//;
1072 my $arg = $_;
1073 my $default;
1074 ($arg, $default) = / ( [^=]* ) ( (?: = .* )? ) /x;
1075 my ($pre, $name) = ($arg =~ /(.*?) \s* \b(\w+) \s* $ /x);
1076 next unless length $pre;
1077 my $out_type;
1078 my $inout_var;
63385af5 1079 if ($process_inout and s/^(IN|IN_OUTLIST|OUTLIST)\s+//) {
f8b8e0a4 1080 my $type = $1;
63385af5 1081 $out_type = $type if $type ne 'IN';
1082 $arg =~ s/^(IN|IN_OUTLIST|OUTLIST)\s+//;
f8b8e0a4 1083 }
1084 if (/\W/) { # Has a type
1085 push @arg_with_types, $arg;
1086 # warn "pushing '$arg'\n";
1087 $arg_types{$name} = $arg;
1088 $_ = "$name$default";
1089 }
63385af5 1090 $out_vars{$_} = 1 if $out_type eq 'OUTLIST';
f8b8e0a4 1091 push @in_out, $name if $out_type;
1092 $in_out{$name} = $out_type if $out_type;
1093 }
1094 } else {
1095 @args = split(/\s*,\s*/, $orig_args);
1096 Warn("Warning: cannot parse argument list '$orig_args', fallback to split");
1097 }
1098 } else {
1099 @args = split(/\s*,\s*/, $orig_args);
1100 for (@args) {
63385af5 1101 if ($process_inout and s/^(IN|IN_OUTLIST|OUTLIST)\s+//) {
f8b8e0a4 1102 my $out_type = $1;
63385af5 1103 next if $out_type eq 'IN';
1104 $out_vars{$_} = 1 if $out_type eq 'OUTLIST';
f8b8e0a4 1105 push @in_out, $name;
1106 $in_out{$_} = $out_type;
1107 }
1108 }
1109 }
a0d0e21e 1110 if (defined($class)) {
683d4eee 1111 my $arg0 = ((defined($static) or $func_name eq 'new')
1112 ? "CLASS" : "THIS");
8e07c86e 1113 unshift(@args, $arg0);
f8b8e0a4 1114 ($report_args = "$arg0, $report_args") =~ s/^\w+, $/$arg0/;
2304df62 1115 }
f8b8e0a4 1116 my $extra_args = 0;
1117 @args_num = ();
1118 $num_args = 0;
1119 my $report_args = '';
1120 foreach $i (0 .. $#args) {
2304df62 1121 if ($args[$i] =~ s/\.\.\.//) {
1122 $elipsis = 1;
f8b8e0a4 1123 if ($args[$i] eq '' && $i == $#args) {
1124 $report_args .= ", ...";
2304df62 1125 pop(@args);
1126 last;
1127 }
1128 }
f8b8e0a4 1129 if ($out_vars{$args[$i]}) {
1130 push @args_num, undef;
1131 } else {
1132 push @args_num, ++$num_args;
1133 $report_args .= ", $args[$i]";
1134 }
8e07c86e 1135 if ($args[$i] =~ /^([^=]*[^\s=])\s*=\s*(.*)/s) {
f8b8e0a4 1136 $extra_args++;
2304df62 1137 $args[$i] = $1;
1138 $defaults{$args[$i]} = $2;
1139 $defaults{$args[$i]} =~ s/"/\\"/g;
1140 }
93d3b392 1141 $proto_arg[$i+1] = "\$" ;
2304df62 1142 }
f8b8e0a4 1143 $min_args = $num_args - $extra_args;
1144 $report_args =~ s/"/\\"/g;
1145 $report_args =~ s/^,\s+//;
1146 my @func_args = @args;
1147 shift @func_args if defined($class);
1148
1149 for (@func_args) {
1150 s/^/&/ if $in_out{$_};
2304df62 1151 }
f8b8e0a4 1152 $func_args = join(", ", @func_args);
1153 @args_match{@args} = @args_num;
2304df62 1154
8e07c86e 1155 $PPCODE = grep(/^\s*PPCODE\s*:/, @line);
93d3b392 1156 $CODE = grep(/^\s*CODE\s*:/, @line);
6c5fb52b 1157 # Detect CODE: blocks which use ST(n)= or XST_m*(n,v)
1158 # to set explicit return values.
1159 $EXPLICIT_RETURN = ($CODE &&
1160 ("@line" =~ /(\bST\s*\([^;]*=) | (\bXST_m\w+\s*\()/x ));
8e07c86e 1161 $ALIAS = grep(/^\s*ALIAS\s*:/, @line);
cfc02341 1162 $INTERFACE = grep(/^\s*INTERFACE\s*:/, @line);
8e07c86e 1163
f8b8e0a4 1164 $xsreturn = 1 if $EXPLICIT_RETURN;
1165
2304df62 1166 # print function header
a0d0e21e 1167 print Q<<"EOF";
ff68c719 1168#XS(XS_${Full_func_name})
2304df62 1169#[[
a0d0e21e 1170# dXSARGS;
93a17b20 1171EOF
8e07c86e 1172 print Q<<"EOF" if $ALIAS ;
1173# dXSI32;
1174EOF
cfc02341 1175 print Q<<"EOF" if $INTERFACE ;
1176# dXSFUNCTION($ret_type);
1177EOF
2304df62 1178 if ($elipsis) {
8e07c86e 1179 $cond = ($min_args ? qq(items < $min_args) : 0);
2304df62 1180 }
1181 elsif ($min_args == $num_args) {
1182 $cond = qq(items != $min_args);
1183 }
1184 else {
1185 $cond = qq(items < $min_args || items > $num_args);
1186 }
8990e307 1187
2304df62 1188 print Q<<"EOF" if $except;
1189# char errbuf[1024];
1190# *errbuf = '\0';
1191EOF
1192
8e07c86e 1193 if ($ALIAS)
1194 { print Q<<"EOF" if $cond }
1195# if ($cond)
f8b8e0a4 1196# Perl_croak(aTHX_ "Usage: %s($report_args)", GvNAME(CvGV(cv)));
8e07c86e 1197EOF
1198 else
1199 { print Q<<"EOF" if $cond }
1200# if ($cond)
f8b8e0a4 1201# Perl_croak(aTHX_ "Usage: $pname($report_args)");
93a17b20 1202EOF
1203
a0d0e21e 1204 print Q<<"EOF" if $PPCODE;
1205# SP -= items;
1206EOF
1207
2304df62 1208 # Now do a block of some sort.
93a17b20 1209
2304df62 1210 $condnum = 0;
8e07c86e 1211 $cond = ''; # last CASE: condidional
1212 push(@line, "$END:");
1213 push(@line_no, $line_no[-1]);
1214 $_ = '';
1215 &check_cpp;
2304df62 1216 while (@line) {
8e07c86e 1217 &CASE_handler if check_keyword("CASE");
1218 print Q<<"EOF";
1219# $except [[
93a17b20 1220EOF
1221
1222 # do initialization of input variables
1223 $thisdone = 0;
1224 $retvaldone = 0;
463ee0b2 1225 $deferred = "";
c2960299 1226 %arg_list = () ;
1227 $gotRETVAL = 0;
f06db76b 1228
8fc38fda 1229 INPUT_handler() ;
cfc02341 1230 process_keyword("INPUT|PREINIT|INTERFACE_MACRO|C_ARGS|ALIAS|PROTOTYPE|SCOPE") ;
8fc38fda 1231
db3b9414 1232 print Q<<"EOF" if $ScopeThisXSUB;
1233# ENTER;
1234# [[
1235EOF
1236
a0d0e21e 1237 if (!$thisdone && defined($class)) {
683d4eee 1238 if (defined($static) or $func_name eq 'new') {
a0d0e21e 1239 print "\tchar *";
1240 $var_types{"CLASS"} = "char *";
1241 &generate_init("char *", 1, "CLASS");
1242 }
1243 else {
93a17b20 1244 print "\t$class *";
1245 $var_types{"THIS"} = "$class *";
1246 &generate_init("$class *", 1, "THIS");
a0d0e21e 1247 }
93a17b20 1248 }
1249
1250 # do code
1251 if (/^\s*NOT_IMPLEMENTED_YET/) {
cea2e8a9 1252 print "\n\tPerl_croak(aTHX_ \"$pname: not implemented yet\");\n";
4633a7c4 1253 $_ = '' ;
93a17b20 1254 } else {
1255 if ($ret_type ne "void") {
ddf6bed1 1256 print "\t" . &map_type($ret_type, 'RETVAL') . ";\n"
93a17b20 1257 if !$retvaldone;
1258 $args_match{"RETVAL"} = 0;
1259 $var_types{"RETVAL"} = $ret_type;
b26a54d0 1260 print "\tdXSTARG;\n"
1261 if $WantOptimize and $targetable{$type_kind{$ret_type}};
93a17b20 1262 }
db3b9414 1263
f8b8e0a4 1264 if (@arg_with_types) {
1265 unshift @line, @arg_with_types, $_;
1266 $_ = "";
1267 $processing_arg_with_types = 1;
1268 INPUT_handler() ;
1269 }
8e07c86e 1270 print $deferred;
db3b9414 1271
cfc02341 1272 process_keyword("INIT|ALIAS|PROTOTYPE|INTERFACE_MACRO|INTERFACE|C_ARGS") ;
8e07c86e 1273
1274 if (check_keyword("PPCODE")) {
8fc38fda 1275 print_section();
8e07c86e 1276 death ("PPCODE must be last thing") if @line;
db3b9414 1277 print "\tLEAVE;\n" if $ScopeThisXSUB;
a0d0e21e 1278 print "\tPUTBACK;\n\treturn;\n";
8e07c86e 1279 } elsif (check_keyword("CODE")) {
8fc38fda 1280 print_section() ;
1281 } elsif (defined($class) and $func_name eq "DESTROY") {
a0d0e21e 1282 print "\n\t";
8e07c86e 1283 print "delete THIS;\n";
93a17b20 1284 } else {
1285 print "\n\t";
1286 if ($ret_type ne "void") {
463ee0b2 1287 print "RETVAL = ";
e50aee73 1288 $wantRETVAL = 1;
93a17b20 1289 }
1290 if (defined($static)) {
683d4eee 1291 if ($func_name eq 'new') {
8fc38fda 1292 $func_name = "$class";
8e07c86e 1293 } else {
1294 print "${class}::";
a0d0e21e 1295 }
93a17b20 1296 } elsif (defined($class)) {
683d4eee 1297 if ($func_name eq 'new') {
8fc38fda 1298 $func_name .= " $class";
1299 } else {
93a17b20 1300 print "THIS->";
8fc38fda 1301 }
93a17b20 1302 }
e50aee73 1303 $func_name =~ s/^($spat)//
1304 if defined($spat);
cfc02341 1305 $func_name = 'XSFUNCTION' if $interface;
93a17b20 1306 print "$func_name($func_args);\n";
93a17b20 1307 }
1308 }
1309
1310 # do output variables
f8b8e0a4 1311 $gotRETVAL = 0; # 1 if RETVAL seen in OUTPUT section;
1312 undef $RETVAL_code ; # code to set RETVAL (from OUTPUT section);
1313 # $wantRETVAL set if 'RETVAL =' autogenerated
1314 ($wantRETVAL, $ret_type) = (0, 'void') if $RETVAL_no_return;
8e07c86e 1315 undef %outargs ;
63385af5 1316 process_keyword("POSTCALL|OUTPUT|ALIAS|PROTOTYPE");
f06db76b 1317
1318 # all OUTPUT done, so now push the return value on the stack
8e07c86e 1319 if ($gotRETVAL && $RETVAL_code) {
1320 print "\t$RETVAL_code\n";
1321 } elsif ($gotRETVAL || $wantRETVAL) {
b26a54d0 1322 my $t = $WantOptimize && $targetable{$type_kind{$ret_type}};
1323 my $var = 'RETVAL';
1324 my $type = $ret_type;
1325
1326 # 0: type, 1: with_size, 2: how, 3: how_size
1327 if ($t and not $t->[1] and $t->[0] eq 'p') {
1328 # PUSHp corresponds to setpvn. Treate setpv directly
1329 my $what = eval qq("$t->[2]");
1330 warn $@ if $@;
1331
1332 print "\tsv_setpv(TARG, $what); XSprePUSH; PUSHTARG;\n";
f8b8e0a4 1333 $prepush_done = 1;
b26a54d0 1334 }
1335 elsif ($t) {
1336 my $what = eval qq("$t->[2]");
1337 warn $@ if $@;
1338
1339 my $size = $t->[3];
1340 $size = '' unless defined $size;
1341 $size = eval qq("$size");
1342 warn $@ if $@;
1343 print "\tXSprePUSH; PUSH$t->[0]($what$size);\n";
f8b8e0a4 1344 $prepush_done = 1;
b26a54d0 1345 }
1346 else {
1347 # RETVAL almost never needs SvSETMAGIC()
1348 &generate_output($ret_type, 0, 'RETVAL', 0);
1349 }
8e07c86e 1350 }
f06db76b 1351
f8b8e0a4 1352 $xsreturn = 1 if $ret_type ne "void";
1353 my $num = $xsreturn;
1354 my $c = @in_out;
1355 print "\tXSprePUSH;" if $c and not $prepush_done;
1356 print "\tEXTEND(SP,$c);\n" if $c;
1357 $xsreturn += $c;
1358 generate_output($var_types{$_}, $num++, $_, 0, 1) for @in_out;
1359
93a17b20 1360 # do cleanup
8fc38fda 1361 process_keyword("CLEANUP|ALIAS|PROTOTYPE") ;
8e07c86e 1362
db3b9414 1363 print Q<<"EOF" if $ScopeThisXSUB;
1364# ]]
1365EOF
1366 print Q<<"EOF" if $ScopeThisXSUB and not $PPCODE;
1367# LEAVE;
1368EOF
1369
93a17b20 1370 # print function trailer
8e07c86e 1371 print Q<<EOF;
2304df62 1372# ]]
8e07c86e 1373EOF
1374 print Q<<EOF if $except;
8990e307 1375# BEGHANDLERS
1376# CATCHALL
1377# sprintf(errbuf, "%s: %s\\tpropagated", Xname, Xreason);
1378# ENDHANDLERS
93a17b20 1379EOF
8e07c86e 1380 if (check_keyword("CASE")) {
1381 blurt ("Error: No `CASE:' at top of function")
1382 unless $condnum;
1383 $_ = "CASE: $_"; # Restore CASE: label
1384 next;
8990e307 1385 }
8e07c86e 1386 last if $_ eq "$END:";
1387 death(/^$BLOCK_re/o ? "Misplaced `$1:'" : "Junk at end of function");
2304df62 1388 }
a0d0e21e 1389
2304df62 1390 print Q<<EOF if $except;
1391# if (errbuf[0])
cea2e8a9 1392# Perl_croak(aTHX_ errbuf);
2304df62 1393EOF
a0d0e21e 1394
f8b8e0a4 1395 if ($xsreturn) {
93d3b392 1396 print Q<<EOF unless $PPCODE;
f8b8e0a4 1397# XSRETURN($xsreturn);
a0d0e21e 1398EOF
93d3b392 1399 } else {
1400 print Q<<EOF unless $PPCODE;
1401# XSRETURN_EMPTY;
1402EOF
1403 }
a0d0e21e 1404
2304df62 1405 print Q<<EOF;
2304df62 1406#]]
8990e307 1407#
93a17b20 1408EOF
382b8d97 1409
4230ab3f 1410 my $newXS = "newXS" ;
1411 my $proto = "" ;
1412
382b8d97 1413 # Build the prototype string for the xsub
1414 if ($ProtoThisXSUB) {
4230ab3f 1415 $newXS = "newXSproto";
1416
6f1abe2b 1417 if ($ProtoThisXSUB eq 2) {
4230ab3f 1418 # User has specified empty prototype
1419 $proto = ', ""' ;
1420 }
6f1abe2b 1421 elsif ($ProtoThisXSUB ne 1) {
7d41bd0a 1422 # User has specified a prototype
4230ab3f 1423 $proto = ', "' . $ProtoThisXSUB . '"';
382b8d97 1424 }
1425 else {
1426 my $s = ';';
1427 if ($min_args < $num_args) {
1428 $s = '';
1429 $proto_arg[$min_args] .= ";" ;
1430 }
4230ab3f 1431 push @proto_arg, "$s\@"
382b8d97 1432 if $elipsis ;
1433
4230ab3f 1434 $proto = ', "' . join ("", @proto_arg) . '"';
382b8d97 1435 }
1436 }
1437
4230ab3f 1438 if (%XsubAliases) {
1439 $XsubAliases{$pname} = 0
1440 unless defined $XsubAliases{$pname} ;
1441 while ( ($name, $value) = each %XsubAliases) {
1442 push(@InitFileCode, Q<<"EOF");
1443# cv = newXS(\"$name\", XS_$Full_func_name, file);
1444# XSANY.any_i32 = $value ;
1445EOF
1446 push(@InitFileCode, Q<<"EOF") if $proto;
1447# sv_setpv((SV*)cv$proto) ;
1448EOF
1449 }
cfc02341 1450 }
1451 elsif ($interface) {
1452 while ( ($name, $value) = each %Interfaces) {
1453 $name = "$Package\::$name" unless $name =~ /::/;
1454 push(@InitFileCode, Q<<"EOF");
1455# cv = newXS(\"$name\", XS_$Full_func_name, file);
1456# $interface_macro_set(cv,$value) ;
1457EOF
1458 push(@InitFileCode, Q<<"EOF") if $proto;
1459# sv_setpv((SV*)cv$proto) ;
1460EOF
1461 }
4230ab3f 1462 }
1463 else {
1464 push(@InitFileCode,
1465 " ${newXS}(\"$pname\", XS_$Full_func_name, file$proto);\n");
1466 }
93a17b20 1467}
1468
1469# print initialization routine
7ee8c957 1470
e3b8966e 1471print Q<<"EOF";
e3b8966e 1472##ifdef __cplusplus
1473#extern "C"
1474##endif
7ee8c957 1475EOF
1476
8990e307 1477print Q<<"EOF";
a0d0e21e 1478#XS(boot_$Module_cname)
7ee8c957 1479EOF
1480
7ee8c957 1481print Q<<"EOF";
2304df62 1482#[[
a0d0e21e 1483# dXSARGS;
8990e307 1484# char* file = __FILE__;
1485#
93a17b20 1486EOF
1487
8fc38fda 1488print Q<<"EOF" if $WantVersionChk ;
1489# XS_VERSION_BOOTCHECK ;
1490#
1491EOF
1492
cfc02341 1493print Q<<"EOF" if defined $XsubAliases or defined $Interfaces ;
8e07c86e 1494# {
1495# CV * cv ;
1496#
1497EOF
1498
4230ab3f 1499print @InitFileCode;
a0d0e21e 1500
cfc02341 1501print Q<<"EOF" if defined $XsubAliases or defined $Interfaces ;
8e07c86e 1502# }
1503EOF
1504
a0d0e21e 1505if (@BootCode)
1506{
6f1abe2b 1507 print "\n /* Initialisation Section */\n\n" ;
1508 @line = @BootCode;
1509 print_section();
8e07c86e 1510 print "\n /* End of Initialisation Section */\n\n" ;
93a17b20 1511}
a0d0e21e 1512
e50aee73 1513print Q<<"EOF";;
3280af22 1514# XSRETURN_YES;
e50aee73 1515#]]
e3b8966e 1516#
1517EOF
1518
8fc38fda 1519warn("Please specify prototyping behavior for $filename (see perlxs manual)\n")
1520 unless $ProtoUsed ;
e50aee73 1521&Exit;
1522
93a17b20 1523sub output_init {
ddf6bed1 1524 local($type, $num, $var, $init, $name_printed) = @_;
a0d0e21e 1525 local($arg) = "ST(" . ($num - 1) . ")";
93a17b20 1526
7ad6fb0b 1527 if( $init =~ /^=/ ) {
ddf6bed1 1528 if ($name_printed) {
1529 eval qq/print " $init\\n"/;
1530 } else {
1531 eval qq/print "\\t$var $init\\n"/;
1532 }
7ad6fb0b 1533 warn $@ if $@;
1534 } else {
1535 if( $init =~ s/^\+// && $num ) {
ddf6bed1 1536 &generate_init($type, $num, $var, $name_printed);
1537 } elsif ($name_printed) {
1538 print ";\n";
1539 $init =~ s/^;//;
7ad6fb0b 1540 } else {
1541 eval qq/print "\\t$var;\\n"/;
1542 warn $@ if $@;
1543 $init =~ s/^;//;
1544 }
1545 $deferred .= eval qq/"\\n\\t$init\\n"/;
1546 warn $@ if $@;
1547 }
93a17b20 1548}
1549
c2960299 1550sub Warn
1551{
1552 # work out the line number
1553 my $line_no = $line_no[@line_no - @line -1] ;
1554
1555 print STDERR "@_ in $filename, line $line_no\n" ;
1556}
1557
1558sub blurt
1559{
1560 Warn @_ ;
1561 $errors ++
1562}
1563
1564sub death
1565{
1566 Warn @_ ;
1567 exit 1 ;
1568}
8990e307 1569
93a17b20 1570sub generate_init {
2304df62 1571 local($type, $num, $var) = @_;
a0d0e21e 1572 local($arg) = "ST(" . ($num - 1) . ")";
2304df62 1573 local($argoff) = $num - 1;
1574 local($ntype);
1575 local($tk);
93a17b20 1576
f06db76b 1577 $type = TidyType($type) ;
c2960299 1578 blurt("Error: '$type' not in typemap"), return
1579 unless defined($type_kind{$type});
1580
2304df62 1581 ($ntype = $type) =~ s/\s*\*/Ptr/g;
8e07c86e 1582 ($subtype = $ntype) =~ s/(?:Array)?(?:Ptr)?$//;
2304df62 1583 $tk = $type_kind{$type};
1584 $tk =~ s/OBJ$/REF/ if $func_name =~ /DESTROY$/;
8e07c86e 1585 $type =~ tr/:/_/;
615ca1f4 1586 blurt("Error: No INPUT definition for type '$type', typekind '$type_kind{$type}' found"), return
c2960299 1587 unless defined $input_expr{$tk} ;
2304df62 1588 $expr = $input_expr{$tk};
1589 if ($expr =~ /DO_ARRAY_ELEM/) {
c2960299 1590 blurt("Error: '$subtype' not in typemap"), return
1591 unless defined($type_kind{$subtype});
615ca1f4 1592 blurt("Error: No INPUT definition for type '$subtype', typekind '$type_kind{$subtype}' found"), return
c2960299 1593 unless defined $input_expr{$type_kind{$subtype}} ;
2304df62 1594 $subexpr = $input_expr{$type_kind{$subtype}};
1595 $subexpr =~ s/ntype/subtype/g;
1596 $subexpr =~ s/\$arg/ST(ix_$var)/g;
1597 $subexpr =~ s/\n\t/\n\t\t/g;
93d3b392 1598 $subexpr =~ s/is not of (.*\")/[arg %d] is not of $1, ix_$var + 1/g;
a0d0e21e 1599 $subexpr =~ s/\$var/${var}[ix_$var - $argoff]/;
2304df62 1600 $expr =~ s/DO_ARRAY_ELEM/$subexpr/;
1601 }
db3b9414 1602 if ($expr =~ m#/\*.*scope.*\*/#i) { # "scope" in C comments
1603 $ScopeThisXSUB = 1;
1604 }
2304df62 1605 if (defined($defaults{$var})) {
1606 $expr =~ s/(\t+)/$1 /g;
1607 $expr =~ s/ /\t/g;
ddf6bed1 1608 if ($name_printed) {
1609 print ";\n";
1610 } else {
1611 eval qq/print "\\t$var;\\n"/;
1612 warn $@ if $@;
1613 }
a104f515 1614 if ($defaults{$var} eq 'NO_INIT') {
4628e4f8 1615 $deferred .= eval qq/"\\n\\tif (items >= $num) {\\n$expr;\\n\\t}\\n"/;
1616 } else {
1617 $deferred .= eval qq/"\\n\\tif (items < $num)\\n\\t $var = $defaults{$var};\\n\\telse {\\n$expr;\\n\\t}\\n"/;
1618 }
7ad6fb0b 1619 warn $@ if $@;
db3b9414 1620 } elsif ($ScopeThisXSUB or $expr !~ /^\t\$var =/) {
ddf6bed1 1621 if ($name_printed) {
1622 print ";\n";
1623 } else {
1624 eval qq/print "\\t$var;\\n"/;
1625 warn $@ if $@;
1626 }
2304df62 1627 $deferred .= eval qq/"\\n$expr;\\n"/;
7ad6fb0b 1628 warn $@ if $@;
2304df62 1629 } else {
ddf6bed1 1630 die "panic: do not know how to handle this branch for function pointers"
1631 if $name_printed;
2304df62 1632 eval qq/print "$expr;\\n"/;
7ad6fb0b 1633 warn $@ if $@;
2304df62 1634 }
93a17b20 1635}
1636
1637sub generate_output {
f8b8e0a4 1638 local($type, $num, $var, $do_setmagic, $do_push) = @_;
a0d0e21e 1639 local($arg) = "ST(" . ($num - ($num != 0)) . ")";
2304df62 1640 local($argoff) = $num - 1;
1641 local($ntype);
93a17b20 1642
f06db76b 1643 $type = TidyType($type) ;
2304df62 1644 if ($type =~ /^array\(([^,]*),(.*)\)/) {
4bd3d083 1645 print "\tsv_setpvn($arg, (char *)$var, $2 * sizeof($1));\n";
ef50df4b 1646 print "\tSvSETMAGIC($arg);\n" if $do_setmagic;
2304df62 1647 } else {
f06db76b 1648 blurt("Error: '$type' not in typemap"), return
2304df62 1649 unless defined($type_kind{$type});
615ca1f4 1650 blurt("Error: No OUTPUT definition for type '$type', typekind '$type_kind{$type}' found"), return
c2960299 1651 unless defined $output_expr{$type_kind{$type}} ;
2304df62 1652 ($ntype = $type) =~ s/\s*\*/Ptr/g;
1653 $ntype =~ s/\(\)//g;
8e07c86e 1654 ($subtype = $ntype) =~ s/(?:Array)?(?:Ptr)?$//;
2304df62 1655 $expr = $output_expr{$type_kind{$type}};
1656 if ($expr =~ /DO_ARRAY_ELEM/) {
c2960299 1657 blurt("Error: '$subtype' not in typemap"), return
1658 unless defined($type_kind{$subtype});
615ca1f4 1659 blurt("Error: No OUTPUT definition for type '$subtype', typekind '$type_kind{$subtype}' found"), return
c2960299 1660 unless defined $output_expr{$type_kind{$subtype}} ;
2304df62 1661 $subexpr = $output_expr{$type_kind{$subtype}};
1662 $subexpr =~ s/ntype/subtype/g;
1663 $subexpr =~ s/\$arg/ST(ix_$var)/g;
1664 $subexpr =~ s/\$var/${var}[ix_$var]/g;
1665 $subexpr =~ s/\n\t/\n\t\t/g;
1666 $expr =~ s/DO_ARRAY_ELEM\n/$subexpr/;
a0d0e21e 1667 eval "print qq\a$expr\a";
7ad6fb0b 1668 warn $@ if $@;
ef50df4b 1669 print "\t\tSvSETMAGIC(ST(ix_$var));\n" if $do_setmagic;
2304df62 1670 }
a0d0e21e 1671 elsif ($var eq 'RETVAL') {
a2baab1c 1672 if ($expr =~ /^\t\$arg = new/) {
1673 # We expect that $arg has refcnt 1, so we need to
1674 # mortalize it.
a0d0e21e 1675 eval "print qq\a$expr\a";
7ad6fb0b 1676 warn $@ if $@;
f8b8e0a4 1677 print "\tsv_2mortal(ST($num));\n";
1678 print "\tSvSETMAGIC(ST($num));\n" if $do_setmagic;
93a17b20 1679 }
a2baab1c 1680 elsif ($expr =~ /^\s*\$arg\s*=/) {
1681 # We expect that $arg has refcnt >=1, so we need
d689ffdd 1682 # to mortalize it!
a2baab1c 1683 eval "print qq\a$expr\a";
7ad6fb0b 1684 warn $@ if $@;
d689ffdd 1685 print "\tsv_2mortal(ST(0));\n";
ef50df4b 1686 print "\tSvSETMAGIC(ST(0));\n" if $do_setmagic;
a2baab1c 1687 }
2304df62 1688 else {
a2baab1c 1689 # Just hope that the entry would safely write it
1690 # over an already mortalized value. By
1691 # coincidence, something like $arg = &sv_undef
1692 # works too.
8990e307 1693 print "\tST(0) = sv_newmortal();\n";
a0d0e21e 1694 eval "print qq\a$expr\a";
7ad6fb0b 1695 warn $@ if $@;
ef50df4b 1696 # new mortals don't have set magic
463ee0b2 1697 }
2304df62 1698 }
f8b8e0a4 1699 elsif ($do_push) {
1700 print "\tPUSHs(sv_newmortal());\n";
1701 $arg = "ST($num)";
1702 eval "print qq\a$expr\a";
1703 warn $@ if $@;
1704 print "\tSvSETMAGIC($arg);\n" if $do_setmagic;
1705 }
a0d0e21e 1706 elsif ($arg =~ /^ST\(\d+\)$/) {
1707 eval "print qq\a$expr\a";
7ad6fb0b 1708 warn $@ if $@;
ef50df4b 1709 print "\tSvSETMAGIC($arg);\n" if $do_setmagic;
a0d0e21e 1710 }
2304df62 1711 }
93a17b20 1712}
1713
1714sub map_type {
ddf6bed1 1715 my($type, $varname) = @_;
93a17b20 1716
8e07c86e 1717 $type =~ tr/:/_/;
1718 $type =~ s/^array\(([^,]*),(.*)\).*/$1 */s;
ddf6bed1 1719 if ($varname) {
1720 if ($varname && $type =~ / \( \s* \* (?= \s* \) ) /xg) {
1721 (substr $type, pos $type, 0) = " $varname ";
1722 } else {
1723 $type .= "\t$varname";
1724 }
1725 }
8e07c86e 1726 $type;
93a17b20 1727}
8990e307 1728
e50aee73 1729
1730sub Exit {
ff0cee69 1731# If this is VMS, the exit status has meaning to the shell, so we
1732# use a predictable value (SS$_Normal or SS$_Abort) rather than an
1733# arbitrary number.
1734# exit ($Is_VMS ? ($errors ? 44 : 1) : $errors) ;
1735 exit ($errors ? 1 : 0);
e50aee73 1736}