line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# bibliography package for Perl |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# options and documentation |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# Dana Jacobsen (dana@acm.org) |
7
|
|
|
|
|
|
|
# 12 January 1995 (last modified on 18 January 1996) |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub stdargs { |
10
|
0
|
|
|
0
|
|
0
|
local(@oldargv) = @_; |
11
|
0
|
|
|
|
|
0
|
local(@args, @nargv); |
12
|
0
|
|
|
|
|
0
|
local($_, $opt, $ret); |
13
|
|
|
|
|
|
|
|
14
|
0
|
|
|
|
|
0
|
&debugs("processing std args", 8192); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# We do this in two steps. |
17
|
|
|
|
|
|
|
# 1) Look for options we want to parse right away. |
18
|
|
|
|
|
|
|
# 2) Check the rest. |
19
|
0
|
|
|
|
|
0
|
while (@oldargv) { |
20
|
0
|
|
|
|
|
0
|
$_ = shift @oldargv; |
21
|
0
|
0
|
|
|
|
0
|
/^--$/ && do { push(@nargv, @args, @oldargv); return @nargv; }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
22
|
0
|
0
|
|
|
|
0
|
/^-bibhelp$/ && do { die &doc('bibpkg'); }; |
|
0
|
|
|
|
|
0
|
|
23
|
0
|
0
|
|
|
|
0
|
/^-supported$/ && do { die &doc('supported'); }; |
|
0
|
|
|
|
|
0
|
|
24
|
0
|
0
|
|
|
|
0
|
/^-hush$/ && do { &errors('ignore'); next; }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
25
|
0
|
0
|
|
|
|
0
|
/^-(debugging=.*)/ && do { $ret = &parse_option($1); |
|
0
|
|
|
|
|
0
|
|
26
|
0
|
|
|
|
|
0
|
next; }; |
27
|
0
|
0
|
|
|
|
0
|
/^-(format=.*)/ && do { $ret = &parse_option($1); |
|
0
|
|
|
|
|
0
|
|
28
|
0
|
|
|
|
|
0
|
next; }; |
29
|
0
|
0
|
|
|
|
0
|
/^-(informat=.*)/ && do { $ret = &parse_option($1); |
|
0
|
|
|
|
|
0
|
|
30
|
0
|
|
|
|
|
0
|
next; }; |
31
|
0
|
0
|
|
|
|
0
|
/^-(outformat=.*)/ && do { $ret = &parse_option($1); |
|
0
|
|
|
|
|
0
|
|
32
|
0
|
|
|
|
|
0
|
next; }; |
33
|
0
|
|
|
|
|
0
|
push(@args, $_); |
34
|
|
|
|
|
|
|
} |
35
|
0
|
|
|
|
|
0
|
foreach $opt (@args) { |
36
|
0
|
0
|
|
|
|
0
|
if ($opt =~ /^-(.*)/) { |
37
|
0
|
|
|
|
|
0
|
$ret = &parse_option($1); |
38
|
0
|
0
|
|
|
|
0
|
next if defined $ret; |
39
|
|
|
|
|
|
|
# fall through if we didn't recognize it |
40
|
|
|
|
|
|
|
} |
41
|
0
|
|
|
|
|
0
|
push(@nargv, $opt); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
0
|
@nargv; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
###### |
49
|
|
|
|
|
|
|
# |
50
|
|
|
|
|
|
|
# XXXXX what about cset options? |
51
|
|
|
|
|
|
|
# |
52
|
|
|
|
|
|
|
# XXXXX we use the "$ret = &foo; next if defined $ret" construct because |
53
|
|
|
|
|
|
|
# perl4 can't handle "if defined &foo". |
54
|
|
|
|
|
|
|
sub options { |
55
|
0
|
|
|
0
|
|
0
|
local($gen, $conv, $in, $out) = @_; |
56
|
0
|
|
|
|
|
0
|
local($fmt, $cset); |
57
|
0
|
|
|
|
|
0
|
local($sopt, $ret); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# general |
60
|
0
|
0
|
|
|
|
0
|
if ($gen) { |
61
|
0
|
|
|
|
|
0
|
&debugs("general options: $gen", 2048); |
62
|
0
|
|
|
|
|
0
|
foreach $sopt (split(/\s+/, $gen)) { |
63
|
0
|
|
|
|
|
0
|
$ret = &parse_option($sopt); |
64
|
0
|
0
|
|
|
|
0
|
next if defined $ret; |
65
|
0
|
|
|
|
|
0
|
&gotwarn("Unknown general option: $sopt"); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# conversion |
70
|
0
|
0
|
|
|
|
0
|
if ($conv) { |
71
|
0
|
|
|
|
|
0
|
&debugs("conversion options: $conv", 2048); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# in format |
75
|
|
|
|
|
|
|
|
76
|
0
|
0
|
|
|
|
0
|
if ($in) { |
77
|
0
|
|
|
|
|
0
|
($fmt, $cset) = &parse_format($glb_Iformat); |
78
|
0
|
|
|
|
|
0
|
$func = $formats{$fmt, "options"}; |
79
|
0
|
|
|
|
|
0
|
&debugs("informat ($fmt) options: $in", 2048); |
80
|
0
|
|
|
|
|
0
|
foreach $sopt (split(/\s+/, $in)) { |
81
|
0
|
|
|
|
|
0
|
$ret = &$func($sopt); |
82
|
0
|
0
|
|
|
|
0
|
next if defined $ret; |
83
|
0
|
|
|
|
|
0
|
&gotwarn("Unknown $fmt option: $sopt"); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# out format |
88
|
|
|
|
|
|
|
|
89
|
0
|
0
|
|
|
|
0
|
if ($out) { |
90
|
0
|
|
|
|
|
0
|
($fmt, $cset) = &parse_format($glb_Oformat); |
91
|
0
|
|
|
|
|
0
|
$func = $formats{$fmt, "options"}; |
92
|
0
|
|
|
|
|
0
|
&debugs("outformat ($fmt) options: $out", 2048); |
93
|
0
|
|
|
|
|
0
|
foreach $sopt (split(/\s+/, $out)) { |
94
|
0
|
|
|
|
|
0
|
$ret = &$func($sopt); |
95
|
0
|
0
|
|
|
|
0
|
next if defined $ret; |
96
|
0
|
|
|
|
|
0
|
&gotwarn("Unknown $fmt option: $sopt"); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# done |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
0
|
1; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub parse_num_option { |
106
|
0
|
|
|
0
|
|
0
|
local($val) = @_; |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
0
|
&debugs("parsing numerical option $val", 64); |
109
|
|
|
|
|
|
|
|
110
|
0
|
0
|
|
|
|
0
|
return 1 if $val =~ /^(T|true|yes|on)$/i; |
111
|
0
|
0
|
|
|
|
0
|
return 0 if $val =~ /^(F|false|no|off)$/i; |
112
|
0
|
0
|
|
|
|
0
|
if ($val =~ /\D/) { |
113
|
0
|
|
|
|
|
0
|
&gotwarn("expected numeric or boolean value: $val"); |
114
|
|
|
|
|
|
|
} |
115
|
0
|
|
|
|
|
0
|
$val; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# |
119
|
|
|
|
|
|
|
# This routine is given an option string like "informat=refer" and does the |
120
|
|
|
|
|
|
|
# appropriate action. It will be called by bib'options and by bib'stdargs. |
121
|
|
|
|
|
|
|
# If it doesn't recognize the option it will return undef. |
122
|
|
|
|
|
|
|
# |
123
|
|
|
|
|
|
|
sub parse_option { |
124
|
0
|
|
|
0
|
|
0
|
local($opt) = @_; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# XXXXX probably don't want this to be panic. |
127
|
0
|
0
|
|
|
|
0
|
&panic("parse_option called with no arguments!") unless defined $opt; |
128
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
0
|
&debugs("parsing option '$opt'", 64); |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# all our options are =. |
132
|
0
|
0
|
|
|
|
0
|
return undef unless $opt =~ /=/; |
133
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
0
|
local($_, $val) = split(/\s*=\s*/, $opt, 2); |
135
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
0
|
&debugs("option split: $_ = $val", 8); |
137
|
|
|
|
|
|
|
|
138
|
0
|
0
|
|
|
|
0
|
/^noconverter$/ && do { undef $glb_cvtname if &parse_num_option($val); |
|
0
|
0
|
|
|
|
0
|
|
139
|
0
|
|
|
|
|
0
|
return 1; }; |
140
|
0
|
0
|
|
|
|
0
|
/^debugging$/ && do { $glb_debug = &parse_num_option($val); |
|
0
|
|
|
|
|
0
|
|
141
|
0
|
|
|
|
|
0
|
$glb_moddebug = $glb_debug; |
142
|
0
|
|
|
|
|
0
|
return $glb_debug; }; |
143
|
0
|
0
|
|
|
|
0
|
/^csconv$/ && do { $opt_CSConvert = &parse_num_option($val); |
|
0
|
|
|
|
|
0
|
|
144
|
0
|
|
|
|
|
0
|
return 1; }; |
145
|
0
|
0
|
|
|
|
0
|
/^csprot$/ && do { $opt_CSProtect = &parse_num_option($val); |
|
0
|
|
|
|
|
0
|
|
146
|
0
|
|
|
|
|
0
|
return 1; }; |
147
|
0
|
0
|
|
|
|
0
|
/^informat$/ && return &format($val, ''); |
148
|
0
|
0
|
|
|
|
0
|
/^outformat$/ && return &format('', $val); |
149
|
|
|
|
|
|
|
# XXXXX This is the wrong place for options. We very well might have not |
150
|
|
|
|
|
|
|
# picked our format yet! |
151
|
0
|
0
|
|
|
|
0
|
/^inopts$/ && return &options('', '', $val, ''); |
152
|
0
|
0
|
|
|
|
0
|
/^outopts$/ && return &options('', '', '', $val); |
153
|
0
|
0
|
|
|
|
0
|
/^format$/ && return &format( split(/,/, $val) ); |
154
|
|
|
|
|
|
|
|
155
|
0
|
0
|
|
|
|
0
|
/^error_savelines$/ && do { $glb_error_saveline = &parse_num_option($val); |
|
0
|
|
|
|
|
0
|
|
156
|
0
|
|
|
|
|
0
|
return 1; }; |
157
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
0
|
return undef; |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
###### |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub doc { |
165
|
3
|
|
|
3
|
|
8
|
local($what) = @_; |
166
|
3
|
|
|
|
|
8
|
local($retstr); |
167
|
|
|
|
|
|
|
|
168
|
3
|
50
|
|
|
|
11
|
$what = "bibpkg" unless defined($what); |
169
|
|
|
|
|
|
|
|
170
|
3
|
|
|
|
|
15
|
&debugs("documentation on $what", 2048); |
171
|
|
|
|
|
|
|
|
172
|
3
|
50
|
|
|
|
733
|
return $glb_version if $what eq 'version'; |
173
|
|
|
|
|
|
|
|
174
|
0
|
0
|
0
|
|
|
|
if ($what eq "bibpkg" || $what eq "bibpackage" || $what eq "bp") { |
|
|
|
0
|
|
|
|
|
175
|
0
|
|
|
|
|
|
$retstr = "See http://www.ecst.csuchico.edu/~jacobsd/bib/bp/index.html\n" . |
176
|
|
|
|
|
|
|
"for documentation on bp. Online help has not been added yet.\n"; |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
# XXXXX we should go through each format and check the support: |
180
|
|
|
|
|
|
|
# is it full, readconv only, or writeconv only. |
181
|
0
|
0
|
|
|
|
|
if ($what eq "supported") { |
182
|
0
|
|
|
|
|
|
$retstr = ""; |
183
|
0
|
|
|
|
|
|
local($fmts, $csets) = &find_bp_files(); |
184
|
0
|
|
|
|
|
|
$retstr .= "Formats supported:\n"; |
185
|
0
|
|
|
|
|
|
foreach ( split(/\s+/, $fmts) ) { |
186
|
0
|
|
|
|
|
|
$retstr .= " $_\n"; |
187
|
|
|
|
|
|
|
} |
188
|
0
|
|
|
|
|
|
$retstr .= "Character sets supported:\n"; |
189
|
0
|
|
|
|
|
|
foreach ( split(/\s+/, $csets) ) { |
190
|
0
|
|
|
|
|
|
$retstr .= " $_\n"; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
0
|
|
|
|
|
|
$retstr; |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
1; |