line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# bibliography package for Perl |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# Error routines |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# Dana Jacobsen (dana@acm.org) |
7
|
|
|
|
|
|
|
# 12 January 1995 (last modified on 17 November 1995) |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# ignore (0) don't even record them |
11
|
|
|
|
|
|
|
# delay (1) record them for later |
12
|
|
|
|
|
|
|
# print (2) print immediately (implies report for warns or errors) |
13
|
|
|
|
|
|
|
# exit (3) print and exit (implies report for warns or errors) |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
# totals returns totals with no other action. |
16
|
|
|
|
|
|
|
# report prints all accumulated warns/errors, and clears their strings. |
17
|
|
|
|
|
|
|
# clear clears all our strings and totals |
18
|
|
|
|
|
|
|
# |
19
|
|
|
|
|
|
|
# All the commands return a list containing 4 elements: |
20
|
|
|
|
|
|
|
# num_warns the number of warnings since the last clear |
21
|
|
|
|
|
|
|
# num_errors the number of errors since the last clear |
22
|
|
|
|
|
|
|
# str_warns the accumulated warning string we have. |
23
|
|
|
|
|
|
|
# str_errors the accumulated error string we have. |
24
|
|
|
|
|
|
|
# |
25
|
|
|
|
|
|
|
# (actually, the strings are cleared upon calling report or clear, and the one |
26
|
|
|
|
|
|
|
# in question is cleared with a print or exit, so we would no longer actually |
27
|
|
|
|
|
|
|
# have the strings any more) |
28
|
|
|
|
|
|
|
# |
29
|
|
|
|
|
|
|
# If $glb_error_saveline is set, then the delay strings also include the |
30
|
|
|
|
|
|
|
# location information. This is useful if you have delay on for more than |
31
|
|
|
|
|
|
|
# one record. |
32
|
|
|
|
|
|
|
# |
33
|
|
|
|
|
|
|
# The values returned are the values previous to the effect of this command. |
34
|
|
|
|
|
|
|
# In other words, although a call to bib'errors('clear') will clear out all |
35
|
|
|
|
|
|
|
# our totals and strings, it will return to you the old totals and strings. |
36
|
|
|
|
|
|
|
# So you could call clear, but check the return values for any special |
37
|
|
|
|
|
|
|
# situations. Note that the strings are cleared upon clear, report, or |
38
|
|
|
|
|
|
|
# print/exit, but the strings are returned to you. Unless you did a clear, |
39
|
|
|
|
|
|
|
# you probably don't need to worry about it. |
40
|
|
|
|
|
|
|
# |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Example: |
43
|
|
|
|
|
|
|
# |
44
|
|
|
|
|
|
|
# &bib'errors('print', 'exit'); |
45
|
|
|
|
|
|
|
# ...do a bunch of normal processing... |
46
|
|
|
|
|
|
|
# ...getting ready for interesting stuff... |
47
|
|
|
|
|
|
|
# &bib'errors('delay', 'exit'); |
48
|
|
|
|
|
|
|
# foreach (@records) { |
49
|
|
|
|
|
|
|
# ...do a bunch of stuff on each record, accumulating all our warnings... |
50
|
|
|
|
|
|
|
# # print out all the warnings for this record with our new citekey |
51
|
|
|
|
|
|
|
# &bib'errors('report',undef," ($citekey)"); |
52
|
|
|
|
|
|
|
# } |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub errors { |
55
|
4
|
|
|
4
|
|
13
|
local($wlev, $elev, $header) = @_; |
56
|
4
|
|
|
|
|
13
|
local(@ret); |
57
|
|
|
|
|
|
|
|
58
|
4
|
50
|
|
|
|
12
|
&panic("errors called with no arguments") unless defined $wlev; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# check sanity of arguments given |
61
|
4
|
50
|
|
|
|
33
|
if ($wlev !~ /^(ignore|delay|print|exit|report|totals|clear)$/) { |
62
|
0
|
|
|
|
|
0
|
return &bib'error("Unknown first argument to errors routine"); |
63
|
|
|
|
|
|
|
} |
64
|
4
|
100
|
|
|
|
12
|
if (defined $elev) { |
65
|
2
|
50
|
|
|
|
13
|
if ($elev !~ /^(ignore|delay|print|exit)$/) { |
66
|
0
|
|
|
|
|
0
|
return &bib'error("Unknown second argument to errors routine"); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} else { |
69
|
2
|
|
|
|
|
5
|
$elev = ''; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
4
|
|
|
|
|
11
|
@ret = ($glb_num_warns, $glb_num_errors, $glb_str_warns, $glb_str_errors); |
73
|
|
|
|
|
|
|
|
74
|
4
|
50
|
|
|
|
13
|
return @ret if $wlev eq 'totals'; |
75
|
|
|
|
|
|
|
|
76
|
4
|
100
|
|
|
|
19
|
if ($wlev eq 'clear') { |
77
|
2
|
|
|
|
|
4
|
$glb_num_errors = 0; |
78
|
2
|
|
|
|
|
4
|
$glb_num_warns = 0; |
79
|
2
|
|
|
|
|
4
|
$glb_str_errors = undef; |
80
|
2
|
|
|
|
|
3
|
$glb_str_warns = undef; |
81
|
2
|
|
|
|
|
8
|
return @ret; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
2
|
50
|
|
|
|
8
|
$glb_warn_level = 0 if ($wlev eq 'ignore'); |
85
|
2
|
50
|
|
|
|
8
|
$glb_warn_level = 1 if ($wlev eq 'delay'); |
86
|
2
|
50
|
|
|
|
8
|
$glb_warn_level = 2 if ($wlev eq 'print'); |
87
|
2
|
50
|
|
|
|
7
|
$glb_warn_level = 3 if ($wlev eq 'exit'); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# Setting the error level to ignore is a Bad Thing. I suppose there may |
90
|
|
|
|
|
|
|
# be cases (debugging, etc.) where we just may want it. We can't really |
91
|
|
|
|
|
|
|
# warn them, since they just told us to shut up... |
92
|
|
|
|
|
|
|
|
93
|
2
|
50
|
|
|
|
8
|
$glb_error_level = 0 if ($elev eq 'ignore'); |
94
|
2
|
50
|
|
|
|
7
|
$glb_error_level = 1 if ($elev eq 'delay'); |
95
|
2
|
50
|
|
|
|
6
|
$glb_error_level = 2 if ($elev eq 'print'); |
96
|
2
|
50
|
|
|
|
9
|
$glb_error_level = 3 if ($elev eq 'exit'); |
97
|
|
|
|
|
|
|
|
98
|
2
|
50
|
33
|
|
|
20
|
if ( ($wlev =~ /^(report|print|exit)$/) && (defined $glb_str_warns) ) { |
99
|
0
|
0
|
|
|
|
0
|
$header = '' unless defined $header; |
100
|
0
|
|
|
|
|
0
|
foreach $warn ( split(/\n/, $glb_str_warns) ) { |
101
|
0
|
|
|
|
|
0
|
print STDERR "bp warning$header: $warn\n"; |
102
|
|
|
|
|
|
|
} |
103
|
0
|
|
|
|
|
0
|
$glb_str_warns = undef; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
2
|
50
|
33
|
|
|
20
|
if ( ($elev =~ /^(report|print|exit)$/) && (defined $glb_str_errors) ) { |
107
|
0
|
0
|
|
|
|
0
|
$header = '' unless defined $header; |
108
|
0
|
|
|
|
|
0
|
foreach $error ( split(/\n/, $glb_str_errors) ) { |
109
|
0
|
|
|
|
|
0
|
print STDERR "bp error$header: $error\n"; |
110
|
|
|
|
|
|
|
} |
111
|
0
|
|
|
|
|
0
|
$glb_str_errors = undef; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
2
|
|
|
|
|
8
|
@ret; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# |
118
|
|
|
|
|
|
|
# This must return undef, so programs can use 'return &goterror("ack!")' |
119
|
|
|
|
|
|
|
# |
120
|
|
|
|
|
|
|
sub goterror { |
121
|
0
|
|
|
0
|
|
|
local($error, $linenum) = @_; |
122
|
|
|
|
|
|
|
|
123
|
0
|
0
|
|
|
|
|
&panic("Error, but no error message") unless defined $error; |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
$glb_num_errors++; |
126
|
0
|
0
|
|
|
|
|
return undef if $glb_error_level == 0; |
127
|
|
|
|
|
|
|
|
128
|
0
|
0
|
|
|
|
|
if (defined $linenum) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# $linenum = $linenum; |
130
|
|
|
|
|
|
|
} elsif (defined $glb_vloc) { |
131
|
0
|
|
|
|
|
|
$linenum = $glb_vloc; |
132
|
|
|
|
|
|
|
} elsif (defined $glb_Ifilename) { |
133
|
0
|
|
|
|
|
|
$linenum = sprintf("record %4d", $glb_filelocmap{$glb_Ifilename}); |
134
|
|
|
|
|
|
|
} else { |
135
|
0
|
|
|
|
|
|
$linenum = 'main'; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
0
|
0
|
|
|
|
|
die "bp error ($linenum): $error\n" if $glb_error_level == 3; |
139
|
0
|
0
|
|
|
|
|
print STDERR "bp error ($linenum): $error\n" if $glb_error_level == 2; |
140
|
0
|
0
|
|
|
|
|
if ($glb_error_level == 1) { |
141
|
0
|
0
|
|
|
|
|
$glb_str_errors .= "($linenum): " if $glb_error_saveline; |
142
|
0
|
|
|
|
|
|
$glb_str_errors .= "$error\n" |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
|
undef; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub gotwarn { |
149
|
0
|
|
|
0
|
|
|
local($warn, $linenum) = @_; |
150
|
|
|
|
|
|
|
|
151
|
0
|
0
|
|
|
|
|
&panic("Warning, but no warning message") unless defined $warn; |
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
$glb_num_warns++; |
154
|
0
|
0
|
|
|
|
|
return undef if $glb_warn_level == 0; |
155
|
|
|
|
|
|
|
|
156
|
0
|
0
|
|
|
|
|
if (defined $linenum) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
157
|
|
|
|
|
|
|
# $linenum = $linenum; |
158
|
|
|
|
|
|
|
} elsif (defined $glb_vloc) { |
159
|
0
|
|
|
|
|
|
$linenum = $glb_vloc; |
160
|
|
|
|
|
|
|
} elsif (defined $glb_Ifilename) { |
161
|
0
|
|
|
|
|
|
$linenum = sprintf("record %4d", $glb_filelocmap{$glb_Ifilename}); |
162
|
|
|
|
|
|
|
} else { |
163
|
0
|
|
|
|
|
|
$linenum = 'main'; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
0
|
0
|
|
|
|
|
die "bp warning ($linenum): $warn\n" if $glb_warn_level == 3; |
167
|
0
|
0
|
|
|
|
|
print STDERR "bp warning ($linenum): $warn\n" if $glb_warn_level == 2; |
168
|
0
|
0
|
|
|
|
|
if ($glb_warn_level == 1) { |
169
|
0
|
0
|
|
|
|
|
$glb_str_warns .= "($linenum): " if $glb_error_saveline; |
170
|
0
|
|
|
|
|
|
$glb_str_warns .= "$warn\n"; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
0
|
|
|
|
|
|
undef; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
1; |