Browse Source

Fixed case of /0+/ filename

Alois Mahdal 11 years ago
parent
commit
3514311b53
1 changed files with 10 additions and 7 deletions
  1. 10
    7
      bin/mkexec.pl

+ 10
- 7
bin/mkexec.pl View File

5
 use warnings;
5
 use warnings;
6
 
6
 
7
 sub usage; sub mkexec; sub guesstype; sub getcmd; sub launch_editor;
7
 sub usage; sub mkexec; sub guesstype; sub getcmd; sub launch_editor;
8
+sub nextarg { $ARGV[0] }
8
 
9
 
9
 my $DEFAULT_TYPE = 'pl';
10
 my $DEFAULT_TYPE = 'pl';
10
 my $DEFAULT_MODE = 0755;
11
 my $DEFAULT_MODE = 0755;
15
 ## INIT ## -------------------------------------------------------------------
16
 ## INIT ## -------------------------------------------------------------------
16
 ## '''' ##   ' ' '  '   '    '     '      '       '        '         '
17
 ## '''' ##   ' ' '  '   '    '     '      '       '        '         '
17
 
18
 
18
-my $force = $ARGV[0] == '-f' ? shift : $DEFAULT_FORCE;
19
-my $name = shift or usage;
20
-my $type = ($ARGV[0] ? shift : guesstype $name);
19
+defined nextarg() or usage;
20
+my $force   = (nextarg() eq '-f' ? shift : $DEFAULT_FORCE);
21
+my $name    = (defined nextarg() ? shift : usage);
22
+my $type    = (defined nextarg() ? shift : guesstype $name);
21
 
23
 
22
 my $bangs = {
24
 my $bangs = {
23
     pl   => `which perl`,
25
     pl   => `which perl`,
46
 ## ''' ##   # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
48
 ## ''' ##   # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
47
 
49
 
48
 if (exists $bangs->{$type}) {
50
 if (exists $bangs->{$type}) {
49
-    -e $name and not $force || mkexec $name, mkbody($type);
51
+    -e $name and not $force
52
+        or mkexec $name, mkbody($type);
50
     chmod $DEFAULT_MODE, $name;
53
     chmod $DEFAULT_MODE, $name;
51
     launch_editor $name;
54
     launch_editor $name;
52
 } else {
55
 } else {
78
 
81
 
79
 sub mkexec {
82
 sub mkexec {
80
     my ($name, $body) = @_;
83
     my ($name, $body) = @_;
81
-    open EXE, ">", $name    || die "cannot open $name for writing: $!\n";
82
-    -W EXE                  || die "file $name is not writable\n";
84
+    open EXE, ">", $name    or die "cannot open $name for writing: $!\n";
85
+    -W EXE                  or die "file $name is not writable\n";
83
     print EXE $body;
86
     print EXE $body;
84
-    close EXE               || die "cannot close $name: $!\n";
87
+    close EXE               or die "cannot close $name: $!\n";
85
 }
88
 }
86
 
89
 
87
 sub get_cmd {
90
 sub get_cmd {