3 # USAGE: specparser.pl file.spec
10 # except for lines prefixed with: ERROR:
13 # 2 - cannot open spec file
18 # expand macros in string
27 while ($cnt-- > 0 && $v =~ /\%\{([^\{]+)\}/) {
29 if (defined $macro{$1}) {
32 $value = "\@undef:$1\@";
34 $v =~ s/\%\{([^\{]+)\}/$value/;
35 last if (length $v > 1000);
44 $macro{$n} = expand($v);
47 # sets hash of macros defined with %define or %global
48 # also define %{name}, %{version} and %{source_N}
51 open(F, "< $_[0]") or die;
54 if (/^\s*\%(define|global)\s+([^\s]+)\s+([^\s].*)$/) {
56 } elsif (/^Version\s*:\s*(.*)/i) {
57 define("version", $1);
58 } elsif (/^Name\s*:\s*(.*)/i) {
60 } elsif (/^Source(\d+)\s*:\s*(.*)/i) {
61 define("source_$1", $2);
69 open(F, "< $_[0]") or die;
72 if (/^\s*#\s*source(\d+)-md5\s*:\s*([a-f0-9]{32})/i) {
75 if (defined $macro{"source_$1"}) {
76 my $s = $macro{"source_$1"};
77 if ($s =~ /^([a-z0-9A-Z:\+\~\.\-\/_]|\%[0-9])+$/) {
78 if ($s =~ /^(ftp|http):\/\//) {
80 print "ERROR: $_[0]: source $no ($s) is directory\n";
85 print "ERROR: $_[0]: source $no ($s) isn't http/ftp url\n";
88 print "ERROR: $_[0]: source $no url $s is ill-formatted\n";
91 print "ERROR: $_[0]: source $no not defined\n";
100 parse_defines($spec);