line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Psh::Options; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
require Psh; |
4
|
|
|
|
|
|
|
require Psh::OS; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# externally stored options |
7
|
|
|
|
|
|
|
my %env_options= qw( cdpath 1 fignore 1 histsize 1 ignoreeof 1 |
8
|
|
|
|
|
|
|
ps1 1 ps2 1 path 1); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# internally stored options and their defaults |
11
|
|
|
|
|
|
|
my %options=( |
12
|
|
|
|
|
|
|
'array_exports' => { |
13
|
|
|
|
|
|
|
'path' => $Psh::OS::PATH_SEPARATOR, |
14
|
|
|
|
|
|
|
'classpath' => $Psh::OS::PATH_SEPARATOR, |
15
|
|
|
|
|
|
|
'ld_library_path' => $Psh::OS::PATH_SEPARATOR, |
16
|
|
|
|
|
|
|
'fignore' => $Psh::OS::PATH_SEPARATOR, |
17
|
|
|
|
|
|
|
'cdpath' => $Psh::OS::PATH_SEPARATOR, |
18
|
|
|
|
|
|
|
'ls_colors' => ':', |
19
|
|
|
|
|
|
|
}, |
20
|
|
|
|
|
|
|
'expansion' => 1, |
21
|
|
|
|
|
|
|
'globbing' => 1, |
22
|
|
|
|
|
|
|
'window_title' => '\w', |
23
|
|
|
|
|
|
|
'save_history' => 1, |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# setup defaults for ENV variables |
27
|
|
|
|
|
|
|
if (!exists $ENV{HISTSIZE}) { |
28
|
|
|
|
|
|
|
$ENV{HISTSIZE}=50; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub set_option { |
32
|
39
|
|
|
39
|
0
|
5943
|
my $option= lc(shift()); |
33
|
39
|
|
|
|
|
58
|
my @value= @_; |
34
|
39
|
50
|
|
|
|
90
|
return unless $option; |
35
|
39
|
50
|
|
|
|
78
|
return unless @value; |
36
|
39
|
|
|
|
|
39
|
my $val; |
37
|
39
|
100
|
|
|
|
105
|
if ($env_options{$option}) { |
38
|
6
|
50
|
33
|
|
|
38
|
if (@value>1 or (ref $value[0] and ref $value[0] eq 'ARRAY')) { |
|
|
|
33
|
|
|
|
|
39
|
6
|
50
|
|
|
|
14
|
if (ref $value[0]) { |
40
|
6
|
|
|
|
|
7
|
@value= @{$value[0]}; |
|
6
|
|
|
|
|
14
|
|
41
|
|
|
|
|
|
|
} |
42
|
6
|
50
|
33
|
|
|
31
|
if ($options{array_exports} and $options{array_exports}{$option}) { |
43
|
6
|
|
|
|
|
15
|
$val= join($options{array_exports}{$option},@value); |
44
|
|
|
|
|
|
|
} else { |
45
|
0
|
|
|
|
|
0
|
$val= $value[0]; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} else { |
48
|
0
|
|
|
|
|
0
|
$val= $value[0]; |
49
|
|
|
|
|
|
|
} |
50
|
6
|
|
|
|
|
41
|
$ENV{uc($option)}= $val; |
51
|
|
|
|
|
|
|
} else { |
52
|
33
|
50
|
|
|
|
55
|
if (@value>1) { |
53
|
0
|
|
|
|
|
0
|
$val= \@value; |
54
|
|
|
|
|
|
|
} else { |
55
|
33
|
|
|
|
|
43
|
$val= $value[0]; |
56
|
|
|
|
|
|
|
} |
57
|
33
|
|
|
|
|
126
|
$options{$option}= $val; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub get_option { |
62
|
166
|
|
|
166
|
0
|
283
|
my $option= lc(shift()); |
63
|
166
|
|
|
|
|
140
|
my $val; |
64
|
166
|
100
|
|
|
|
342
|
if ($env_options{$option}) { |
65
|
18
|
|
|
|
|
30
|
$val= $ENV{uc($option)}; |
66
|
18
|
50
|
33
|
|
|
81
|
if ($options{array_exports} and $options{array_exports}{$option}) { |
67
|
18
|
|
|
|
|
71
|
$val= [split($options{array_exports}{$option}, $val)]; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} else { |
70
|
148
|
|
|
|
|
211
|
$val=$options{$option}; |
71
|
|
|
|
|
|
|
} |
72
|
166
|
100
|
|
|
|
318
|
if (defined $val) { |
73
|
165
|
50
|
|
|
|
271
|
if (wantarray()) { |
74
|
0
|
0
|
0
|
|
|
0
|
if (ref $val and ref $val eq 'ARRAY') { |
|
|
0
|
0
|
|
|
|
|
75
|
0
|
|
|
|
|
0
|
return @{$val}; |
|
0
|
|
|
|
|
0
|
|
76
|
|
|
|
|
|
|
} elsif ( ref $val and ref $val eq 'HASH') { |
77
|
0
|
|
|
|
|
0
|
return %{$val}; |
|
0
|
|
|
|
|
0
|
|
78
|
|
|
|
|
|
|
} |
79
|
0
|
|
|
|
|
0
|
return $val; |
80
|
|
|
|
|
|
|
} else { |
81
|
165
|
|
|
|
|
415
|
return $val; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
1
|
|
|
|
|
3
|
return undef; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub get_printable_option { |
88
|
0
|
|
|
0
|
0
|
|
my $option= shift; |
89
|
0
|
|
|
|
|
|
my $noquote= shift; |
90
|
0
|
|
|
|
|
|
my $tmpval= get_option($option); |
91
|
0
|
|
|
|
|
|
my $val= ''; |
92
|
0
|
0
|
|
|
|
|
if (ref $tmpval) { |
93
|
0
|
0
|
|
|
|
|
if (ref $tmpval eq 'HASH') { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
$val='{'; |
95
|
0
|
|
|
|
|
|
while (my ($k,$v)= each %$tmpval) { |
96
|
0
|
0
|
|
|
|
|
next unless defined $k; |
97
|
0
|
0
|
|
|
|
|
if (defined $v) { |
98
|
0
|
|
|
|
|
|
$val.=" \'".$k."\' => \'".$v."\', "; |
99
|
|
|
|
|
|
|
} else { |
100
|
0
|
|
|
|
|
|
$val.=" \'".$k."\' => undef, "; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
} |
103
|
0
|
|
|
|
|
|
$val= substr($val,0,-2).' }'; |
104
|
|
|
|
|
|
|
} elsif (ref $tmpval eq 'ARRAY') { |
105
|
0
|
|
|
|
|
|
$val='['; |
106
|
0
|
|
|
|
|
|
foreach (@$tmpval) { |
107
|
0
|
0
|
|
|
|
|
if (defined $_) { |
108
|
0
|
|
|
|
|
|
$val.=" \'".$_."\', "; |
109
|
|
|
|
|
|
|
} else { |
110
|
0
|
|
|
|
|
|
$val.=" undef, "; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
0
|
|
|
|
|
|
$val= substr($val,0,-2).' ]'; |
114
|
|
|
|
|
|
|
} elsif (ref $tmpval eq 'CODE') { |
115
|
0
|
|
|
|
|
|
$val='CODE'; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} else { |
118
|
0
|
0
|
|
|
|
|
if (defined $tmpval) { |
119
|
0
|
0
|
|
|
|
|
if ($noquote) { |
120
|
0
|
|
|
|
|
|
$val= $tmpval; |
121
|
|
|
|
|
|
|
} else { |
122
|
0
|
|
|
|
|
|
$val= qq['$tmpval']; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
} else { |
125
|
0
|
|
|
|
|
|
$val= 'undef'; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
0
|
|
|
|
|
|
return $val; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub has_option { |
132
|
0
|
|
|
0
|
0
|
|
my $option= lc(shift()); |
133
|
0
|
0
|
0
|
|
|
|
return 1 if exists $options{$option} or ($env_options{$option} and |
|
|
|
0
|
|
|
|
|
134
|
|
|
|
|
|
|
exists $ENV{uc($option)}); |
135
|
0
|
|
|
|
|
|
return 0; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub del_option { |
139
|
0
|
|
|
0
|
0
|
|
my $option= lc(shift()); |
140
|
0
|
0
|
|
|
|
|
if ($env_options{$option}) { |
141
|
0
|
|
|
|
|
|
delete $ENV{uc($option)}; |
142
|
|
|
|
|
|
|
} else { |
143
|
0
|
|
|
|
|
|
delete $options{$option}; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub list_options { |
148
|
0
|
|
|
0
|
0
|
|
my @opts= keys %options; |
149
|
0
|
|
|
|
|
|
foreach (keys %env_options) { |
150
|
0
|
0
|
|
|
|
|
push @opts, lc($_) if exists $ENV{uc($_)}; |
151
|
|
|
|
|
|
|
} |
152
|
0
|
|
|
|
|
|
return @opts; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
1; |