summaryrefslogtreecommitdiffstats
path: root/opensuse/core/tqt3/update_spec.pl
blob: 8c67241dc0553f0594283d671ca6c37be00a8cac (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
#! /usr/bin/perl

my $name = $ARGV[0];
$name =~ s,.*/,,;
$name =~ s,\.spec.*,,;

my %attributes = ();
open(FILE, $ARGV[1]) || die 'no attributes';
my $pack = undef;
my $text = undef;
while ( <FILE> ) {
	if (/^\+(.*)$/) { $pack = $1; $text = ''; next }
	if (/^-(.*)$/) {
	    if ($pack ne $1) {
		die "$pack and $1 do not match";
	    }
	    $text =~ s,^\s*,,;
	    $text =~ s,\s*$,,;
	    $attributes{$pack} = $text;
	    $text = undef;
	    $pack = undef;
	    next;
	}
	if (defined $text) {
	    $text .= $_;
	} elsif (/^(\S*)\s*(.*)$/) {
	    my $attr = $1;
	    my $string = $2;
	    $string =~ s,^\s*,,;
	    $string =~ s,\s*$,,;
	    $attributes{$attr} = $string;
	}
}
close(FILE);

open(FILE, $ARGV[0]);

sub description()
{
  if (/^%description\s*(.*)\s*/) {
        my $suffix = $1;
        my $pname = $name;

	if ($suffix =~ m/-n\s*(.*)/) {
		$pname = $1;
        } else {
	        $pname = "$name-$suffix" if ($suffix);
	}

        if (defined $attributes{"description.$pname"}) {
           print $_;
           my $descr = $attributes{"description.$pname"};
           print "$descr\n";
           $_ = '';
           do {
	       $_ = <FILE>;
           } while ( $_ !~ /^%/ && $_ !~ /^@/ );
           print "\n";
           description();
        }
  }

}

# current subpackage
my $pname = $name;

while ( <FILE> )
{
  if (/^Name:\s*(.*)/) {
	$name = $1;
	$pname = $1;
  }
  description();

  if (/^%package\s*(.*)/) {
      my $suffix = $1;
      if ($suffix =~ m/-n\s*(.*)/) {
	  $pname = $1;
      } else {
	  $pname = "$name-$1";
      }
  }

  if (/^(Summary:\s*)(.*)$/) {
      if (defined $attributes{"summary.$pname"}) {
	  print $1 . $attributes{"summary.$pname"} ."\n";
	  next;
      }
  }
  if (/^(License:\s*)(.*)$/) {
      if (defined $attributes{"license.$pname"}) {
	  print $1 . $attributes{"license.$pname"} ."\n";
	  next;
      }
  }
  if (/^(Group:\s*)(.*)$/) {
      if (defined $attributes{"group.$pname"}) {
	  print $1 . $attributes{"group.$pname"} ."\n";
	  next;
      }
  }
  print $_;
}

close(FILE);