-
Notifications
You must be signed in to change notification settings - Fork 27
/
ifdef
executable file
·89 lines (73 loc) · 1.33 KB
/
ifdef
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/perl -i
# Delete this line and above if you don't trust this script 8-)
#!/usr/bin/perl -i.bak
#
# Small script to configure code based on comments
use Getopt::Std;
getopts('nyt:');
$no = $opt_n;
$yes = $opt_y;
my $found;
$USAGE = <<EOF;
usage: $0 -(y|n) [-t STRING] filespec
EOF
if($opt_n and $opt_y) {
die "$USAGE\nCan't both set and unset at same time!\n";
}
if(!$opt_n and !$opt_y) {
die "$USAGE\nNeed to specify either -y or -n.\n";
}
$string = $opt_t || 'DEBUG';
unless($opt_t) {
require 5.003_93;
}
if(! @ARGV) {
my @args;
@args = glob 'bin/*';
push (@args, glob 'lib/Vend/*.pm');
push (@args, glob 'lib/Vend/Table/*.pm');
@ARGV = grep $_ !~ /\.bak$/, @args;
}
if($no) {
while(<>) {
(print, next) unless /^# (NO)?$string$/o;
$found = 1;
print;
if($1) {
while(<>) {
(print, last) if /^#\s*END NO$string$/o;
s/^#//;
print;
}
}
else {
while(<>) {
(print, last) if /^# END $string$/o;
s/^/#/;
print;
}
}
}
}
else {
while(<>) {
(print, next) unless /^# (NO)?$string$/o;
$found = 1;
print;
if($1) {
while(<>) {
(print, last) if /^# END NO$string$/o;
s/^/#/;
print;
}
}
else {
while(<>) {
(print, last) if /^# END $string$/o;
s/^#//;
print;
}
}
}
}
warn "Warning: no '$string' includes found.\n" unless defined $found;