3 # USAGE: specparser.pl file.spec
10 # except for lines prefixed with: ERROR:
13 # 2 - cannot open spec file
26 print "ERROR: $spec: $_[0]\n";
31 print "ERROR: $spec: $_[0]\n";
44 # expand macros in string
47 my $v = trim_spaces(shift);
50 while ($v =~ /\%\{([^\{]+)\}/) {
52 if (defined $macro{$1}) {
55 error("undefined macro $1");
58 $v =~ s/\%\{([^\{]+)\}/$value/;
60 return $v if (length $v > 1000 or $cnt-- <= 0)
63 while ($v =~ s/\%\(\s*echo\s+([^\|]+?)\s*\|\s*tr\s*(-d|)\s+([^\)]+?)\s*\)/\@\@tr-me\@\@/) {
64 my ($what, $d_opt, $how) = ($1, $2, $3);
65 my ($from, $to) = ($how, "");
66 ($from, $to) = ($1, $2)
67 if $how =~ /^([^\s]+)\s+([^\s]+)$/;
68 if ($d_opt and $to ne "") {
69 error("tr -d with second string)");
70 } elsif (($from . $to) =~ /^[a-zA-Z0-9\+_\-\.]+$/) {
72 eval "\$what =~ tr/$from//d;";
74 eval "\$what =~ tr/$from/$to/;";
77 error("illegal characters in tr string(s) '$from' '$to'");
79 $v =~ s/\@\@tr-me\@\@/$what/;
81 return $v if (length $v > 1000 or $cnt-- <= 0)
84 error("unexpanded macros in $v")
85 if ($v =~ /\%[^0-9]/);
94 $macro{$n} = trim_spaces($v);
97 # sets hash of macros defined with %define or %global
98 # also define %{name}, %{version} and %{source_N}
101 open(F, "< $_[0]") or die;
104 if (/^\s*\%(define|global)\s+([^\s]+)\s+([^\s].*)$/) {
106 } elsif (/^Version\s*:\s*(.*)/i) {
107 define("version", $1);
108 } elsif (/^Name\s*:\s*(.*)/i) {
110 } elsif (/^Source(\d+)\s*:\s*(.*)/i) {
111 define("source_$1", expand($2));
112 } elsif (/^Patch(\d+)\s*:\s*(.*)/i) {
113 define("patch_$1", expand($2));
121 open(F, "< $_[0]") or die;
124 if (/^\s*#\s*source(\d+)-md5\s*:\s*([a-f0-9]{32})/i) {
127 if (defined $macro{"source_$1"}) {
128 my $s = $macro{"source_$1"};
129 if ($s =~ /^([a-z0-9A-Z:\=\?\@\+\~\.\-\/_]|\%[0-9])+$/) {
130 if ($s =~ /^(ftp|http):\/\//) {
132 error("source $no ($s) is directory");
134 if ($s =~ /:\/\/distfiles\.pld-linux\.org\/src/) {
136 print "$md5 no-url-copy://$s\n";
143 print "$md5 no-url://$s\n";
146 error("source $no url $s is ill-formatted");
149 error("source $no not defined");
157 parse_defines($spec);