blob: 614c3eb7e8d31dd6dcd8b538b8f9c39949f7779b (
plain)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
#!/usr/bin/perl -w
# $Id$
#require 5.008;
use strict;
use Getopt::Mixed qw(nextOption);
my @lines = ();
my ($REL) = q$Revision: 1.4 $=~m/(\d+(?:\.\d+)+)/;
my $prefix = undef;
my $verbose = undef;
my $reverse = undef;
my $flag_choice = undef;
my $line = '';
# help(): print help text and exit
sub help {
print "Usage: $0 [options]
-h, --help show this short help and exit
-p, --prefix=PREFIX prefix
-r, --reverse revert changes
-v, --verbose print superfluous info
-V, --version show version string and exit\n";
exit;
}
# version(): print version info and exit
sub version {
print "$0 r$REL, Jochen Striepe <ptxdist\@tolot.escape.de>\n";
exit;
}
# esc(): escapes a scalar reference for use in perl regexp
sub esc { ${$_[0]} =~ s/([\[\]\(\)\*\.\-\^\$\@])/\\$1/g; }
# get command line params:
$0 =~ s!^.*/!!;
Getopt::Mixed::init('h p=s r v V help>h prefix>p reverse>r verbose>v version>V');
while (my ($opt, $val, $pretty) = nextOption()) {
if ($opt eq 'h') { help(); }
elsif ($opt eq 'p') { $prefix = $val; }
elsif ($opt eq 'r') { $reverse = 1; }
elsif ($opt eq 'v') { $verbose = 1; }
elsif ($opt eq 'V') { version(); }
}
Getopt::Mixed::cleanup();
if (!defined $prefix) {
print STDERR "Fatal: prefix not specified\n\n"; help; die;
}
if (defined $reverse) { esc(\$prefix); }
@lines = <STDIN>;
while (@lines) {
$line = shift @lines;
chomp($line);
if (defined $reverse) {
if ($line =~ s/^(\s*config\s+)$prefix/$1/e) {
print STDERR "$prefix removed\n" if defined $verbose;
$flag_choice = undef;
}
elsif ($line =~ /^\s*depends\s+(on\s)?\s*/) {
while ($line =~ s/^(\s*depends\s+(on\s)?\s*(?:[0-9A-Z_]+\s+)*?)$prefix/$1/e) {
print STDERR "$prefix removed\n" if defined $verbose;
}
}
elsif ($line =~ s/^(\s*(?:default\s+\S+\s+)?if\s+)(.*)/$1/e) {
while ($line =~ s/^(\s*(?:default\s+\S\s+)?if\s(?:[0-9A-Z_]+\s+)*?)$prefix/$1/e) {
print STDERR "$prefix removed\n" if defined $verbose;
}
}
elsif (defined $flag_choice) {
if ($line =~ s/^(\s*default\s+)$prefix/$1/e) {
print STDERR "$prefix removed\n" if defined $verbose;
}
}
}
elsif ($line =~ s/^(\s*config\s+)([0-9A-Z_]+)/$1.$prefix.$2/e) {
print STDERR "$2 is now $prefix$2\n" if defined $verbose;
$flag_choice = undef;
}
elsif ($line =~ s/^(\s*select\s+)([0-9A-Z_]+)/$1.$prefix.$2/e) {
print STDERR "$2 is now $prefix$2\n" if defined $verbose;
$flag_choice = undef;
}
elsif ($line =~ s/^(\s*depends\s+(on\s)?\s*)(.*)/$1/e) {
my $foo = $3;
while ($foo =~ s/^([^0-9A-Z_]*)([0-9A-Z_]+)(.*)/$3/e) {
$line .= $1.$prefix.$2;
print STDERR "$2 is now $prefix$2\n" if defined $verbose;
}
$line .= $foo;
}
elsif ($line =~ s/^(\s*(?:default\s+\S+\s+)?if\s+)(.*)/$1/e) {
my $foo = $2;
while ($foo =~ s/^([^0-9A-Z_]*)([0-9A-Z_]+)(.*)/$3/e) {
$line .= $1.$prefix.$2;
print STDERR "$2 is now $prefix$2\n" if defined $verbose;
}
$line .= $foo;
}
elsif (defined $flag_choice) {
if ($line =~ s/^(\s*default\s+)([0-9A-Z_]+)/$1.$prefix.$2/e) {
print STDERR "$2 is now $prefix$2\n" if defined $verbose;
}
}
if ($line =~ /^choice/) {
$flag_choice = 1;
}
print STDOUT "$line\n";
}
# vim500:set shiftwidth=4
# vim500:set tabstop=4
# eof
|