line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Getopt::Tiny; |
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
1408
|
use vars qw($VERSION); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
204
|
|
5
|
|
|
|
|
|
|
$VERSION = 1.02; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
8
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
9
|
|
|
|
|
|
|
@EXPORT = qw(getopt); |
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
90
|
|
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
10
|
use vars qw($usageHandle); |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
1328
|
|
14
|
|
|
|
|
|
|
$usageHandle = 'STDERR'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub getopt |
17
|
|
|
|
|
|
|
{ |
18
|
5
|
|
|
5
|
0
|
4718
|
my ($avref, $flagref, $switchref, $remainder) = @_; |
19
|
5
|
50
|
|
|
|
38
|
unless (defined($avref)) { |
20
|
0
|
|
|
|
|
0
|
$avref = \@::ARGV; |
21
|
0
|
|
|
|
|
0
|
$flagref = \%::flags; |
22
|
0
|
|
|
|
|
0
|
$switchref = \%::switches; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
5
|
|
|
|
|
21
|
while (@$avref) { |
26
|
21
|
|
|
|
|
51
|
$_ = shift @$avref; |
27
|
21
|
100
|
|
|
|
103
|
unless (/^-(no)?(.+)$/) { |
28
|
3
|
50
|
|
|
|
16
|
if ($remainder) { |
29
|
0
|
|
|
|
|
0
|
unshift(@$avref, $_); |
30
|
0
|
|
|
|
|
0
|
return; |
31
|
|
|
|
|
|
|
} |
32
|
3
|
|
|
|
|
21
|
callusage($_, $flagref, $switchref, $remainder); |
33
|
3
|
|
|
|
|
11
|
return; |
34
|
|
|
|
|
|
|
} |
35
|
18
|
50
|
|
|
|
40
|
if (@$avref) { |
36
|
18
|
100
|
|
|
|
50
|
if (exists $flagref->{$2}) { |
37
|
14
|
100
|
|
|
|
56
|
if (ref $flagref->{$2} eq 'ARRAY') { |
|
|
100
|
|
|
|
|
|
38
|
8
|
|
|
|
|
14
|
my $f = $2; |
39
|
8
|
|
|
|
|
12
|
for (;;) { |
40
|
12
|
|
|
|
|
12
|
push(@{$flagref->{$f}}, shift @$avref); |
|
12
|
|
|
|
|
24
|
|
41
|
12
|
100
|
100
|
|
|
90
|
last unless @$avref && $avref->[0] =~ /^[^-]/; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} elsif (ref $flagref->{$2} eq 'HASH') { |
44
|
4
|
|
|
|
|
6
|
my $f = $2; |
45
|
4
|
|
|
|
|
8
|
for (;;) { |
46
|
6
|
|
|
|
|
8
|
my $v = shift @$avref; |
47
|
6
|
50
|
|
|
|
32
|
if ($v =~ /^(.*)=(.*)/) { |
48
|
6
|
|
|
|
|
24
|
$flagref->{$f}->{$1} = $2; |
49
|
|
|
|
|
|
|
} else { |
50
|
0
|
|
|
|
|
0
|
callusage("$_ $v", $flagref, $switchref, $remainder); |
51
|
|
|
|
|
|
|
} |
52
|
6
|
100
|
66
|
|
|
44
|
last unless @$avref && $avref->[0] =~ /^[^-].*=/; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} else { |
55
|
2
|
|
|
|
|
4
|
${$flagref->{$2}} = shift @$avref; |
|
2
|
|
|
|
|
6
|
|
56
|
|
|
|
|
|
|
} |
57
|
14
|
|
|
|
|
36
|
next; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
4
|
50
|
|
|
|
20
|
if (exists $switchref->{$2}) { |
61
|
|
|
|
|
|
|
# if (ref $switchref->{$2} eq 'HASH') { |
62
|
|
|
|
|
|
|
# if (@$avref) { |
63
|
|
|
|
|
|
|
# $switchref->{$2}->{shift @$avref} = ! $1; |
64
|
|
|
|
|
|
|
# } else { |
65
|
|
|
|
|
|
|
# callusage($_, $flagref, $switchref, $remainder); |
66
|
|
|
|
|
|
|
# } |
67
|
|
|
|
|
|
|
# } else { |
68
|
4
|
|
|
|
|
38
|
${$switchref->{$2}} = ! $1; |
|
4
|
|
|
|
|
16
|
|
69
|
|
|
|
|
|
|
# } |
70
|
4
|
|
|
|
|
10
|
next; |
71
|
|
|
|
|
|
|
} |
72
|
0
|
|
|
|
|
0
|
callusage($_, $flagref, $switchref, $remainder); |
73
|
0
|
|
|
|
|
0
|
return; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub callusage |
78
|
|
|
|
|
|
|
{ |
79
|
3
|
|
|
3
|
0
|
15
|
my ($arg, $flagref, $switchref, $remainder) = @_; |
80
|
3
|
|
|
|
|
148
|
my ($package, $filename) = (caller(1))[0,1]; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
{ |
83
|
2
|
|
|
2
|
|
12
|
no strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
1218
|
|
|
3
|
|
|
|
|
6
|
|
84
|
3
|
100
|
|
|
|
6
|
if (defined &{"${package}::usage"}) { |
|
3
|
|
|
|
|
40
|
|
85
|
2
|
|
|
|
|
2
|
&{"${package}::usage"}($arg); |
|
2
|
|
|
|
|
14
|
|
86
|
2
|
|
|
|
|
10
|
return; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
1
|
|
50
|
|
|
81
|
my $o = select($usageHandle || 'STDERR'); |
91
|
|
|
|
|
|
|
|
92
|
1
|
|
|
|
|
49
|
print "$0: unknown option '$arg'\n"; |
93
|
|
|
|
|
|
|
|
94
|
1
|
50
|
|
|
|
254
|
$remainder = 'args' if $remainder > 0; |
95
|
1
|
|
|
|
|
70
|
print "Usage: $0 [flags] [switches] $remainder\n"; |
96
|
|
|
|
|
|
|
|
97
|
1
|
|
|
|
|
11
|
usage($filename, $flagref, $switchref); |
98
|
|
|
|
|
|
|
|
99
|
1
|
|
|
|
|
5
|
select($o); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub usage |
103
|
|
|
|
|
|
|
{ |
104
|
1
|
|
|
1
|
0
|
3
|
my ($filename, $flagref, $switchref) = @_; |
105
|
1
|
50
|
|
|
|
4
|
unless (defined $filename) { |
106
|
0
|
|
|
|
|
0
|
$filename = (caller[0])[1]; |
107
|
0
|
|
|
|
|
0
|
$flagref = \%::flags; |
108
|
0
|
|
|
|
|
0
|
$switchref = \%::switches; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
1
|
|
|
|
|
2
|
my %comment; |
112
|
1
|
50
|
|
|
|
85
|
open(USAGESOURCEFILE, "<$filename") or die "open $filename: $!"; |
113
|
1
|
|
|
|
|
41
|
while () { |
114
|
21
|
100
|
|
|
|
114
|
last if /^# begin usage info/; |
115
|
|
|
|
|
|
|
} |
116
|
1
|
|
|
|
|
15
|
while () { |
117
|
19
|
100
|
|
|
|
123
|
if (/^\s*["'](\S+?)["']\s*=\>.*?\#\s*(\S.*)/) { |
118
|
14
|
|
|
|
|
201
|
$comment{$1} = $2; |
119
|
|
|
|
|
|
|
} |
120
|
19
|
100
|
|
|
|
100
|
last if /^# end usage info/; |
121
|
|
|
|
|
|
|
} |
122
|
1
|
50
|
|
|
|
77
|
if (%$flagref) { |
123
|
1
|
|
|
|
|
34
|
for my $f (sort keys %$flagref) { |
124
|
11
|
100
|
|
|
|
45
|
if (ref $flagref->{$f} eq 'ARRAY') { |
|
|
100
|
|
|
|
|
|
125
|
2
|
|
50
|
|
|
20
|
printf "\t-%-25s %s\n", "$f value ...", $comment{$f}||''; |
126
|
|
|
|
|
|
|
} elsif (ref $flagref->{$f} eq 'HASH') { |
127
|
1
|
|
50
|
|
|
7
|
printf "\t-%-25s %s\n", "$f key=value ...", $comment{$f}||''; |
128
|
|
|
|
|
|
|
} else { |
129
|
8
|
|
50
|
|
|
47
|
printf "\t-%-25s %s\n", "$f value", $comment{$f}||''; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
} |
133
|
1
|
50
|
|
|
|
5
|
if (%$switchref) { |
134
|
1
|
|
|
|
|
14
|
for my $f (sort keys %$switchref) { |
135
|
|
|
|
|
|
|
# if (ref $switchref->{$f} eq 'HASH') { |
136
|
|
|
|
|
|
|
# printf "\t-%-25s %s\n", "[no]$f key", $comment{$f}||''; |
137
|
|
|
|
|
|
|
# } else { |
138
|
3
|
|
50
|
|
|
24
|
printf "\t-[no]%-21s %s\n", $f, $comment{$f}||''; |
139
|
|
|
|
|
|
|
# } |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
1; |