File: fix_substvars.pl

package info (click to toggle)
icu 63.2-2
  • links: PTS
  • area: main
  • in suites: bullseye, sid
  • size: 102,128 kB
  • sloc: cpp: 452,584; ansic: 109,494; makefile: 5,350; sh: 4,106; xml: 3,861; perl: 3,195; python: 376; sed: 36; lisp: 12
file content (52 lines) | stat: -rw-r--r-- 912 bytes parent folder | download | duplicates (11)
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
#
# Remove any whose names that match the given pattern from the
# shlibs:Depends entry in the given substvars.
#

BEGIN { $^W = 1; }
use strict;
my $whoami = ($0 =~ m,([^/\\]*)$,) ? $1 : $0;

die "usage: $whoami substvars-file pattern" unless @ARGV == 2;
my ($file, $pattern) = @ARGV;
if (! -f $file)
{
    exit 0;
}

open(F, "<$file") or die "$whoami: can't open $file: $!\n";
my @in = (<F>);
close(F);
my @out = ();

for (@in)
{
    if (m/(shlibs:Depends=)(.*)/)
    {
	my $prefix = $1;
	my $contents = $2;
	my @items = split(',\s*', $contents);
	my @new = ();
	foreach my $i (@items)
	{
	    $i =~ m/^(\S+)/ or die;
	    my $pkg = $1;
	    if ($pkg !~ m/^${pattern}$/)
	    {
		push(@new, $i);
	    }
	}
	push(@out, $prefix . join(', ', @new) . "\n");
    }
    else
    {
	push(@out, $_);
    }
}

open(F, ">$file") or die "$whoami: can't open $file.new: $!\n";
foreach (@out)
{
    print F $_;
}
close(F);