3 # USAGE: specparser.pl file.spec
14 # 2 - cannot open spec file
19 # expand macros in string
25 while ($cnt-- > 0 && $v =~ /\%\{([^\{]+)\}/) {
27 if (defined $macro{$1}) {
30 $value = "\@undef:$1\@";
32 $v =~ s/\%\{([^\{]+)\}/$value/;
33 last if (length $v > 1000);
42 $macro{$n} = expand($v);
45 # sets hash of macros defined with %define or %global
46 # also define %{name}, %{version} and %{source_N}
49 open(F, "< $_[0]") or die;
52 if (/^\s*\%(define|global)\s+([^\s]+)\s+([^\s].*)$/) {
54 } elsif (/^Version\s*:\s*(.*)/i) {
55 define("version", $1);
56 } elsif (/^Name\s*:\s*(.*)/i) {
58 } elsif (/^Source(\d+)\s*:\s*(.*)/i) {
59 define("source_$1", $2);
67 open(F, "< $_[0]") or die;
70 if (/^\s*#\s*source(\d+)-md5\s*:\s*([a-f0-9]{32})/i) {
71 if (defined $macro{"source_$1"}) {
72 my $s = $macro{"source_$1"};
74 if ($s =~ / / || $s =~ /^\%\{/ || $s =~ /\@undef/) {
75 print STDERR "$_[0]: source url $s is ill-formatted\n";
80 print STDERR "$_[0]: source $1 not defined\n";