8 sub DEFAULT_ON () { 1 }
9 sub DEFAULT_OFF () { 2 }
12 'io' => { 'pipe' => DEFAULT_OFF,
13 'unopened' => DEFAULT_OFF,
14 'closed' => DEFAULT_OFF,
15 'newline' => DEFAULT_OFF,
16 'exec' => DEFAULT_OFF,
18 'syntax' => { 'ambiguous' => DEFAULT_OFF,
19 'semicolon' => DEFAULT_OFF,
20 'precedence' => DEFAULT_OFF,
21 'bareword' => DEFAULT_OFF,
22 'reserved' => DEFAULT_OFF,
23 'digit' => DEFAULT_OFF,
24 'parenthesis' => DEFAULT_OFF,
25 'deprecated' => DEFAULT_OFF,
26 'printf' => DEFAULT_OFF,
27 'prototype' => DEFAULT_OFF,
30 'severe' => { 'inplace' => DEFAULT_ON,
31 'internal' => DEFAULT_ON,
32 'debugging' => DEFAULT_ON,
33 'malloc' => DEFAULT_ON,
35 'void' => DEFAULT_OFF,
36 'recursion' => DEFAULT_OFF,
37 'redefine' => DEFAULT_OFF,
38 'numeric' => DEFAULT_OFF,
39 'uninitialized' => DEFAULT_OFF,
40 'once' => DEFAULT_OFF,
41 'misc' => DEFAULT_OFF,
42 'regexp' => DEFAULT_OFF,
43 'glob' => DEFAULT_OFF,
45 'chmod' => DEFAULT_OFF,
46 'umask' => DEFAULT_OFF,
47 'untie' => DEFAULT_OFF,
48 'substr' => DEFAULT_OFF,
49 'taint' => DEFAULT_OFF,
50 'signal' => DEFAULT_OFF,
51 'closure' => DEFAULT_OFF,
52 'overflow' => DEFAULT_OFF,
53 'portable' => DEFAULT_OFF,
54 'utf8' => DEFAULT_OFF,
55 'exiting' => DEFAULT_OFF,
56 'pack' => DEFAULT_OFF,
57 'unpack' => DEFAULT_OFF,
58 #'default' => DEFAULT_ON,
62 ###########################################################################
65 $t .= "\t" x ($l - (length($t) + 1) / 8);
69 ###########################################################################
81 foreach $k (sort keys %$tre) {
83 die "duplicate key $k\n" if defined $list{$k} ;
84 $Value{$index} = uc $k ;
85 push @{ $list{$k} }, $index ++ ;
87 { push (@{ $list{$k} }, walk ($v)) }
88 push @list, @{ $list{$k} } ;
94 ###########################################################################
103 for ($i = 1 ; $i < @a; ++ $i) {
105 if $a[$i] == $a[$i - 1] + 1 && $a[$i] + 1 == $a[$i + 1] ;
108 my $out = join(",",@out);
110 $out =~ s/,(\.\.,)+/../g ;
114 ###########################################################################
122 my $max = (sort {$a <=> $b} map { length $_ } keys %$tre)[-1] ;
124 $prefix .= " " x $indent ;
125 foreach $k (sort keys %$tre) {
127 print $prefix . "|\n" ;
128 print $prefix . "+- $k" ;
131 print " " . "-" x ($max - length $k ) . "+\n" ;
132 printTree ($v, $prefix . "|" , $max + $indent - 1)
140 ###########################################################################
145 my $mask = "\x00" x $max ;
149 vec($mask, $_, 1) = 1 ;
152 #$string = unpack("H$max", $mask) ;
153 #$string =~ s/(..)/\x$1/g;
154 foreach (unpack("C*", $mask)) {
155 $string .= '\x' . sprintf("%2.2x", $_) ;
160 ###########################################################################
162 if (@ARGV && $ARGV[0] eq "tree")
165 printTree($tree, " ", 4) ;
169 #unlink "warnings.h";
170 #unlink "lib/warnings.pm";
171 open(WARN, ">warnings.h") || die "Can't create warnings.h: $!\n";
172 open(PM, ">lib/warnings.pm") || die "Can't create lib/warnings.pm: $!\n";
175 /* !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
176 This file is built by warnings.pl
177 Any changes made here will be lost!
181 #define Off(x) ((x) / 8)
182 #define Bit(x) (1 << ((x) % 8))
183 #define IsSet(a, x) ((a)[Off(x)] & Bit(x))
186 #define G_WARN_OFF 0 /* $^W == 0 */
187 #define G_WARN_ON 1 /* -w flag and $^W != 0 */
188 #define G_WARN_ALL_ON 2 /* -W flag */
189 #define G_WARN_ALL_OFF 4 /* -X flag */
190 #define G_WARN_ONCE 8 /* set if 'once' ever enabled */
191 #define G_WARN_ALL_MASK (G_WARN_ALL_ON|G_WARN_ALL_OFF)
193 #define WARN_STD Nullsv
194 #define WARN_ALL (Nullsv+1) /* use warnings 'all' */
195 #define WARN_NONE (Nullsv+2) /* no warnings 'all' */
197 #define specialWARN(x) ((x) == WARN_STD || (x) == WARN_ALL || \
201 ( ! specialWARN(PL_curcop->cop_warnings) && \
202 IsSet(SvPVX(PL_curcop->cop_warnings), 2*x+1))
205 ( (PL_curcop->cop_warnings != WARN_STD && \
206 PL_curcop->cop_warnings != WARN_NONE && \
207 (PL_curcop->cop_warnings == WARN_ALL || \
208 IsSet(SvPVX(PL_curcop->cop_warnings), 2*x) ) ) \
209 || (PL_curcop->cop_warnings == WARN_STD && PL_dowarn & G_WARN_ON) )
211 #define ckWARN2(x,y) \
212 ( (PL_curcop->cop_warnings != WARN_STD && \
213 PL_curcop->cop_warnings != WARN_NONE && \
214 (PL_curcop->cop_warnings == WARN_ALL || \
215 IsSet(SvPVX(PL_curcop->cop_warnings), 2*x) || \
216 IsSet(SvPVX(PL_curcop->cop_warnings), 2*y) ) ) \
217 || (PL_curcop->cop_warnings == WARN_STD && PL_dowarn & G_WARN_ON) )
219 #define ckWARN_d(x) \
220 (PL_curcop->cop_warnings == WARN_STD || \
221 PL_curcop->cop_warnings == WARN_ALL || \
222 (PL_curcop->cop_warnings != WARN_NONE && \
223 IsSet(SvPVX(PL_curcop->cop_warnings), 2*x) ) )
225 #define ckWARN2_d(x,y) \
226 (PL_curcop->cop_warnings == WARN_STD || \
227 PL_curcop->cop_warnings == WARN_ALL || \
228 (PL_curcop->cop_warnings != WARN_NONE && \
229 (IsSet(SvPVX(PL_curcop->cop_warnings), 2*x) || \
230 IsSet(SvPVX(PL_curcop->cop_warnings), 2*y) ) ) )
233 #define isLEXWARN_on (PL_curcop->cop_warnings != WARN_STD)
234 #define isLEXWARN_off (PL_curcop->cop_warnings == WARN_STD)
235 #define isWARN_ONCE (PL_dowarn & (G_WARN_ON|G_WARN_ONCE))
236 #define isWARN_on(c,x) (IsSet(SvPVX(c), 2*(x)))
242 @{ $list{"all"} } = walk ($tree) ;
245 my $warn_size = int($index / 8) + ($index % 8 != 0) ;
248 foreach $k (sort { $a <=> $b } keys %Value) {
249 print WARN tab(5, "#define WARN_$Value{$k}"), "$k\n" ;
253 print WARN tab(5, '#define WARNsize'), "$warn_size\n" ;
254 #print WARN tab(5, '#define WARN_ALLstring'), '"', ('\377' x $warn_size) , "\"\n" ;
255 print WARN tab(5, '#define WARN_ALLstring'), '"', ('\125' x $warn_size) , "\"\n" ;
256 print WARN tab(5, '#define WARN_NONEstring'), '"', ('\0' x $warn_size) , "\"\n" ;
260 /* end of file warnings.h */
267 last if /^KEYWORDS$/ ;
271 $list{'all'} = [ 0 .. 8 * ($warn_size/2) - 1 ] ;
272 print PM "%Bits = (\n" ;
273 foreach $k (sort keys %list) {
276 my @list = sort { $a <=> $b } @$v ;
278 print PM tab(4, " '$k'"), '=> "',
279 # mkHex($warn_size, @list),
280 mkHex($warn_size, map $_ * 2 , @list),
281 '", # [', mkRange(@list), "]\n" ;
286 print PM "%DeadBits = (\n" ;
287 foreach $k (sort keys %list) {
290 my @list = sort { $a <=> $b } @$v ;
292 print PM tab(4, " '$k'"), '=> "',
293 # mkHex($warn_size, @list),
294 mkHex($warn_size, map $_ * 2 + 1 , @list),
295 '", # [', mkRange(@list), "]\n" ;
299 print PM '$NONE = "', ('\0' x $warn_size) , "\";\n" ;
308 # This file was created by warnings.pl
309 # Any changes made here will be lost.
316 warnings - Perl pragma to control optional warnings
326 if (warnings::enabled("void") {
327 warnings::warn("void", "some warning");
332 If no import list is supplied, all possible warnings are either enabled
335 Two functions are provided to assist module authors.
339 =item warnings::enabled($category)
341 Returns TRUE if the warnings category in C<$category> is enabled in the
342 calling module. Otherwise returns FALSE.
345 =item warnings::warn($category, $message)
347 If the calling module has I<not> set C<$category> to "FATAL", print
348 C<$message> to STDERR.
349 If the calling module has set C<$category> to "FATAL", print C<$message>
354 See L<perlmod/Pragmatic Modules> and L<perllexwarn>.
366 foreach my $word (@_) {
367 if ($word eq 'FATAL') {
371 if ($catmask = $Bits{$word}) {
373 $mask |= $DeadBits{$word} if $fatal ;
383 ${^WARNING_BITS} |= bits(@_ ? @_ : 'all') ;
388 ${^WARNING_BITS} &= ~ bits(@_ ? @_ : 'all') ;
393 # If no parameters, check for any lexical warnings enabled
394 # in the users scope.
395 my $callers_bitmask = (caller(1))[9] ;
396 return ($callers_bitmask ne $NONE) if @_ == 0 ;
398 # otherwise check for the category supplied.
399 my $category = shift ;
401 unless $Bits{$category} ;
402 return 0 unless defined $callers_bitmask ;
404 if ($callers_bitmask & $Bits{$category}) ne $NONE ;
411 croak "Usage: warnings::warn('category', 'message')"
413 my $category = shift ;
414 my $message = shift ;
415 local $Carp::CarpLevel = 1 ;
416 my $callers_bitmask = (caller(1))[9] ;
418 if defined $callers_bitmask &&
419 ($callers_bitmask & $DeadBits{$category}) ne $NONE ;