11 sub DEFAULT_ON () { 1 }
12 sub DEFAULT_OFF () { 2 }
17 'io' => { 'pipe' => DEFAULT_OFF,
18 'unopened' => DEFAULT_OFF,
19 'closed' => DEFAULT_OFF,
20 'newline' => DEFAULT_OFF,
21 'exec' => DEFAULT_OFF,
23 'syntax' => { 'ambiguous' => DEFAULT_OFF,
24 'semicolon' => DEFAULT_OFF,
25 'precedence' => DEFAULT_OFF,
26 'bareword' => DEFAULT_OFF,
27 'reserved' => DEFAULT_OFF,
28 'digit' => DEFAULT_OFF,
29 'parenthesis' => DEFAULT_OFF,
30 'deprecated' => DEFAULT_OFF,
31 'printf' => DEFAULT_OFF,
32 'prototype' => DEFAULT_OFF,
35 'severe' => { 'inplace' => DEFAULT_ON,
36 'internal' => DEFAULT_ON,
37 'debugging' => DEFAULT_ON,
38 'malloc' => DEFAULT_ON,
40 'void' => DEFAULT_OFF,
41 'recursion' => DEFAULT_OFF,
42 'redefine' => DEFAULT_OFF,
43 'numeric' => DEFAULT_OFF,
44 'uninitialized' => DEFAULT_OFF,
45 'once' => DEFAULT_OFF,
46 'misc' => DEFAULT_OFF,
47 'regexp' => DEFAULT_OFF,
48 'glob' => DEFAULT_OFF,
50 'untie' => DEFAULT_OFF,
51 'substr' => DEFAULT_OFF,
52 'taint' => DEFAULT_OFF,
53 'signal' => DEFAULT_OFF,
54 'closure' => DEFAULT_OFF,
55 'overflow' => DEFAULT_OFF,
56 'portable' => DEFAULT_OFF,
57 'utf8' => DEFAULT_OFF,
58 'exiting' => DEFAULT_OFF,
59 'pack' => DEFAULT_OFF,
60 'unpack' => DEFAULT_OFF,
61 #'default' => DEFAULT_ON,
66 ###########################################################################
69 $t .= "\t" x ($l - (length($t) + 1) / 8);
73 ###########################################################################
85 foreach $k (sort keys %$tre) {
87 die "duplicate key $k\n" if defined $list{$k} ;
88 $Value{$index} = uc $k ;
89 push @{ $list{$k} }, $index ++ ;
91 { push (@{ $list{$k} }, walk ($v)) }
92 push @list, @{ $list{$k} } ;
98 ###########################################################################
107 for ($i = 1 ; $i < @a; ++ $i) {
109 if $a[$i] == $a[$i - 1] + 1 && $a[$i] + 1 == $a[$i + 1] ;
112 my $out = join(",",@out);
114 $out =~ s/,(\.\.,)+/../g ;
118 ###########################################################################
126 my $max = (sort {$a <=> $b} map { length $_ } keys %$tre)[-1] ;
128 $prefix .= " " x $indent ;
129 foreach $k (sort keys %$tre) {
131 print $prefix . "|\n" ;
132 print $prefix . "+- $k" ;
135 print " " . "-" x ($max - length $k ) . "+\n" ;
136 printTree ($v, $prefix . "|" , $max + $indent - 1)
144 ###########################################################################
148 my ($f, $max, @a) = @_ ;
149 my $mask = "\x00" x $max ;
153 vec($mask, $_, 1) = 1 ;
156 foreach (unpack("C*", $mask)) {
158 $string .= '\x' . sprintf("%2.2x", $_)
161 $string .= '\\' . sprintf("%o", $_)
170 return mkHexOct("x", $max, @a);
176 return mkHexOct("o", $max, @a);
179 ###########################################################################
181 if (@ARGV && $ARGV[0] eq "tree")
184 printTree($tree, " ", 4) ;
189 unlink "lib/warnings.pm";
190 open(WARN, ">warnings.h") || die "Can't create warnings.h: $!\n";
191 open(PM, ">lib/warnings.pm") || die "Can't create lib/warnings.pm: $!\n";
194 /* !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
195 This file is built by warnings.pl
196 Any changes made here will be lost!
200 #define Off(x) ((x) / 8)
201 #define Bit(x) (1 << ((x) % 8))
202 #define IsSet(a, x) ((a)[Off(x)] & Bit(x))
205 #define G_WARN_OFF 0 /* $^W == 0 */
206 #define G_WARN_ON 1 /* -w flag and $^W != 0 */
207 #define G_WARN_ALL_ON 2 /* -W flag */
208 #define G_WARN_ALL_OFF 4 /* -X flag */
209 #define G_WARN_ONCE 8 /* set if 'once' ever enabled */
210 #define G_WARN_ALL_MASK (G_WARN_ALL_ON|G_WARN_ALL_OFF)
212 #define pWARN_STD Nullsv
213 #define pWARN_ALL (Nullsv+1) /* use warnings 'all' */
214 #define pWARN_NONE (Nullsv+2) /* no warnings 'all' */
216 #define specialWARN(x) ((x) == pWARN_STD || (x) == pWARN_ALL || \
223 #@{ $list{"all"} } = walk ($tree) ;
228 my $warn_size = int($index / 8) + ($index % 8 != 0) ;
231 foreach $k (sort { $a <=> $b } keys %Value) {
232 print WARN tab(5, "#define WARN_$Value{$k}"), "$k\n" ;
236 print WARN tab(5, '#define WARNsize'), "$warn_size\n" ;
237 #print WARN tab(5, '#define WARN_ALLstring'), '"', ('\377' x $warn_size) , "\"\n" ;
238 print WARN tab(5, '#define WARN_ALLstring'), '"', ('\125' x $warn_size) , "\"\n" ;
239 print WARN tab(5, '#define WARN_NONEstring'), '"', ('\0' x $warn_size) , "\"\n" ;
240 my $WARN_TAINTstring = mkOct($warn_size, map $_ * 2, @{ $list{'taint'} });
242 print WARN tab(5, '#define WARN_TAINTstring'), qq["$WARN_TAINTstring"\n] ;
246 #define isLEXWARN_on (PL_curcop->cop_warnings != pWARN_STD)
247 #define isLEXWARN_off (PL_curcop->cop_warnings == pWARN_STD)
248 #define isWARN_ONCE (PL_dowarn & (G_WARN_ON|G_WARN_ONCE))
249 #define isWARN_on(c,x) (IsSet(SvPVX(c), 2*(x)))
250 #define isWARNf_on(c,x) (IsSet(SvPVX(c), 2*(x)+1))
253 ( ! specialWARN(PL_curcop->cop_warnings) && \
254 ( isWARNf_on(PL_curcop->cop_warnings, WARN_ALL) || \
255 isWARNf_on(PL_curcop->cop_warnings, x)))
258 ( (isLEXWARN_on && PL_curcop->cop_warnings != pWARN_NONE && \
259 (PL_curcop->cop_warnings == pWARN_ALL || \
260 isWARN_on(PL_curcop->cop_warnings, x) ) ) \
261 || (isLEXWARN_off && PL_dowarn & G_WARN_ON) )
263 #define ckWARN2(x,y) \
264 ( (isLEXWARN_on && PL_curcop->cop_warnings != pWARN_NONE && \
265 (PL_curcop->cop_warnings == pWARN_ALL || \
266 isWARN_on(PL_curcop->cop_warnings, x) || \
267 isWARN_on(PL_curcop->cop_warnings, y) ) ) \
268 || (isLEXWARN_off && PL_dowarn & G_WARN_ON) )
270 #define ckWARN_d(x) \
271 (isLEXWARN_off || PL_curcop->cop_warnings == pWARN_ALL || \
272 (PL_curcop->cop_warnings != pWARN_NONE && \
273 isWARN_on(PL_curcop->cop_warnings, x) ) )
275 #define ckWARN2_d(x,y) \
276 (isLEXWARN_off || PL_curcop->cop_warnings == pWARN_ALL || \
277 (PL_curcop->cop_warnings != pWARN_NONE && \
278 (isWARN_on(PL_curcop->cop_warnings, x) || \
279 isWARN_on(PL_curcop->cop_warnings, y) ) ) )
281 /* end of file warnings.h */
288 last if /^KEYWORDS$/ ;
292 #$list{'all'} = [ $offset .. 8 * ($warn_size/2) - 1 ] ;
294 #my %Keys = map {lc $Value{$_}, $_} keys %Value ;
296 print PM "%Offsets = (\n" ;
297 foreach my $k (sort { $a <=> $b } keys %Value) {
298 my $v = lc $Value{$k} ;
300 print PM tab(4, " '$v'"), "=> $k,\n" ;
305 print PM "%Bits = (\n" ;
306 foreach $k (sort keys %list) {
309 my @list = sort { $a <=> $b } @$v ;
311 print PM tab(4, " '$k'"), '=> "',
312 # mkHex($warn_size, @list),
313 mkHex($warn_size, map $_ * 2 , @list),
314 '", # [', mkRange(@list), "]\n" ;
319 print PM "%DeadBits = (\n" ;
320 foreach $k (sort keys %list) {
323 my @list = sort { $a <=> $b } @$v ;
325 print PM tab(4, " '$k'"), '=> "',
326 # mkHex($warn_size, @list),
327 mkHex($warn_size, map $_ * 2 + 1 , @list),
328 '", # [', mkRange(@list), "]\n" ;
332 print PM '$NONE = "', ('\0' x $warn_size) , "\";\n" ;
333 print PM '$LAST_BIT = ' . "$index ;\n" ;
334 print PM '$BYTES = ' . "$warn_size ;\n" ;
343 # This file was created by warnings.pl
344 # Any changes made here will be lost.
349 our $VERSION = '1.00';
353 warnings - Perl pragma to control optional warnings
363 use warnings::register;
364 if (warnings::enabled()) {
365 warnings::warn("some warning");
368 if (warnings::enabled("void")) {
369 warnings::warn("void", "some warning");
372 if (warnings::enabled($object)) {
373 warnings::warn($object, "some warning");
376 warnif("some warning");
377 warnif("void", "some warning");
378 warnif($object, "some warning");
382 If no import list is supplied, all possible warnings are either enabled
385 A number of functions are provided to assist module authors.
389 =item use warnings::register
391 Creates a new warnings category with the same name as the package where
392 the call to the pragma is used.
394 =item warnings::enabled()
396 Use the warnings category with the same name as the current package.
398 Return TRUE if that warnings category is enabled in the calling module.
399 Otherwise returns FALSE.
401 =item warnings::enabled($category)
403 Return TRUE if the warnings category, C<$category>, is enabled in the
405 Otherwise returns FALSE.
407 =item warnings::enabled($object)
409 Use the name of the class for the object reference, C<$object>, as the
412 Return TRUE if that warnings category is enabled in the first scope
413 where the object is used.
414 Otherwise returns FALSE.
416 =item warnings::warn($message)
418 Print C<$message> to STDERR.
420 Use the warnings category with the same name as the current package.
422 If that warnings category has been set to "FATAL" in the calling module
423 then die. Otherwise return.
425 =item warnings::warn($category, $message)
427 Print C<$message> to STDERR.
429 If the warnings category, C<$category>, has been set to "FATAL" in the
430 calling module then die. Otherwise return.
432 =item warnings::warn($object, $message)
434 Print C<$message> to STDERR.
436 Use the name of the class for the object reference, C<$object>, as the
439 If that warnings category has been set to "FATAL" in the scope where C<$object>
440 is first used then die. Otherwise return.
443 =item warnings::warnif($message)
447 if (warnings::enabled())
448 { warnings::warn($message) }
450 =item warnings::warnif($category, $message)
454 if (warnings::enabled($category))
455 { warnings::warn($category, $message) }
457 =item warnings::warnif($object, $message)
461 if (warnings::enabled($object))
462 { warnings::warn($object, $message) }
466 See L<perlmodlib/Pragmatic Modules> and L<perllexwarn>.
474 $All = "" ; vec($All, $Offsets{'all'}, 2) = 3 ;
480 foreach my $word (@_) {
481 if ($word eq 'FATAL') {
484 elsif ($catmask = $Bits{$word}) {
486 $mask |= $DeadBits{$word} if $fatal ;
489 { croak("unknown warnings category '$word'")}
497 my $mask = ${^WARNING_BITS} ;
498 if (vec($mask, $Offsets{'all'}, 1)) {
499 $mask |= $Bits{'all'} ;
500 $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
502 ${^WARNING_BITS} = $mask | bits(@_ ? @_ : 'all') ;
507 my $mask = ${^WARNING_BITS} ;
508 if (vec($mask, $Offsets{'all'}, 1)) {
509 $mask |= $Bits{'all'} ;
510 $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
512 ${^WARNING_BITS} = $mask & ~ (bits('FATAL' => (@_ ? @_ : 'all')) | $All) ;
522 # check the category supplied.
525 croak ("not an object")
526 if $category !~ /^([^=]+)=/ ;+
530 $offset = $Offsets{$category};
531 croak("unknown warnings category '$category'")
532 unless defined $offset;
535 $category = (caller(1))[0] ;
536 $offset = $Offsets{$category};
537 croak("package '$category' not registered for warnings")
538 unless defined $offset ;
541 my $this_pkg = (caller(1))[0] ;
546 while (do { { package DB; $pkg = (caller($i++))[0] } } ) {
547 last unless @DB::args && $DB::args[0] =~ /^$category=/ ;
552 for ($i = 2 ; $pkg = (caller($i))[0] ; ++ $i) {
553 last if $pkg ne $this_pkg ;
556 if !$pkg || $pkg eq $this_pkg ;
559 my $callers_bitmask = (caller($i))[9] ;
560 return ($callers_bitmask, $offset, $i) ;
565 croak("Usage: warnings::enabled([category])")
566 unless @_ == 1 || @_ == 0 ;
568 my ($callers_bitmask, $offset, $i) = __chk(@_) ;
570 return 0 unless defined $callers_bitmask ;
571 return vec($callers_bitmask, $offset, 1) ||
572 vec($callers_bitmask, $Offsets{'all'}, 1) ;
578 croak("Usage: warnings::warn([category,] 'message')")
579 unless @_ == 2 || @_ == 1 ;
582 my ($callers_bitmask, $offset, $i) = __chk(@_) ;
583 local $Carp::CarpLevel = $i ;
585 if vec($callers_bitmask, $offset+1, 1) ||
586 vec($callers_bitmask, $Offsets{'all'}+1, 1) ;
592 croak("Usage: warnings::warnif([category,] 'message')")
593 unless @_ == 2 || @_ == 1 ;
596 my ($callers_bitmask, $offset, $i) = __chk(@_) ;
597 local $Carp::CarpLevel = $i ;
600 unless defined $callers_bitmask &&
601 (vec($callers_bitmask, $offset, 1) ||
602 vec($callers_bitmask, $Offsets{'all'}, 1)) ;
605 if vec($callers_bitmask, $offset+1, 1) ||
606 vec($callers_bitmask, $Offsets{'all'}+1, 1) ;