blob: f9b4902a13184b4e9c4f1402a59079e4ae6c179f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
@rem = '--*-Perl-*--
@echo off
perl -x -S %0 %*
goto endofperl
@rem ';
#!perl -w
#line 8
(my $head = <<'--end--') =~ s/^\t//gm;
@rem = '--*-Perl-*--
@echo off
perl -x -S %0 %*
goto endofperl
@rem ';
--end--
my $headlines = 2 + ($head =~ tr/\n/\n/);
my $tail = "__END__\n:endofperl\n";
@ARGV = ('-') unless @ARGV;
process(@ARGV);
sub process {
LOOP:
foreach ( @_ ) {
my $myhead = $head;
my $linedone = 0;
my $linenum = $headlines;
my $line;
open( FILE, $_ ) or die "Can't open $_: $!";
@file = <FILE>;
foreach $line ( @file ) {
$linenum++;
if ( $line =~ /^:endofperl/) {
warn "$_ has already been converted to a batch file!\n";
next LOOP;
}
if ( not $linedone and $line =~ /^#!.*perl/ ) {
$line .= "#line $linenum\n";
$linedone++;
}
}
close( FILE );
s/\.pl$//;
$_ .= '.bat' unless /\.bat$/ or /^-$/;
open( FILE, ">$_" ) or die "Can't open $_: $!";
$myhead =~ s/perl -x/perl/ unless $linedone;
print FILE $myhead;
print FILE "#line $headlines\n" unless $linedone;
print FILE @file, $tail;
close( FILE );
}
}
__END__
:endofperl
|