3 # USAGE: specparser.pl file.spec
10 # except for lines prefixed with: ERROR:
13 # 2 - cannot open spec file
20 $base_spec =~ s|.*/||;
28 print "ERROR: $base_spec: $_[0]\n";
33 print "ERROR: $base_spec: $_[0]\n";
46 # expand macros in string
49 my $v = trim_spaces(shift);
52 while ($v =~ /\%\{([^\{]+)\}/) {
54 if (defined $macro{$1}) {
57 error("undefined macro $1");
60 $v =~ s/\%\{([^\{]+)\}/$value/;
62 return $v if (length $v > 1000 or $cnt-- <= 0)
65 while ($v =~ s/\%\(\s*echo\s+([^\|]+?)\s*\|\s*tr\s*(-d|)\s+([^\)]+?)\s*\)/\@\@tr-me\@\@/) {
66 my ($what, $d_opt, $how) = ($1, $2, $3);
67 my ($from, $to) = ($how, "");
68 ($from, $to) = ($1, $2)
69 if $how =~ /^([^\s]+)\s+([^\s]+)$/;
70 if ($d_opt and $to ne "") {
71 error("tr -d with second string)");
72 } elsif (($from . $to) =~ /^[a-zA-Z0-9\+_\-\.]+$/) {
74 eval "\$what =~ tr/$from//d;";
76 eval "\$what =~ tr/$from/$to/;";
79 error("illegal characters in tr string(s) '$from' '$to'");
81 $v =~ s/\@\@tr-me\@\@/$what/;
83 return $v if (length $v > 1000 or $cnt-- <= 0)
86 error("unexpanded macros in $v")
87 if ($v =~ /\%[^0-9]/);
96 $macro{$n} = trim_spaces($v);
99 # sets hash of macros defined with %define or %global
100 # also define %{name}, %{version} and %{source_N}
103 open(F, "< $_[0]") or die;
106 if (/^\s*\%(define|global)\s+([^\s]+)\s+([^\s].*)$/) {
108 } elsif (/^Version\s*:\s*(.*)/i) {
109 define("version", $1);
110 } elsif (/^Name\s*:\s*(.*)/i) {
112 } elsif (/^Source(\d+)\s*:\s*(.*)/i) {
113 define("source_$1", expand($2));
114 } elsif (/^Patch(\d+)\s*:\s*(.*)/i) {
115 define("patch_$1", expand($2));
116 } elsif (/^NoSource\s*:\s*(\d+)\s*$/i) {
117 define("no_source_$1", "1");
125 open(F, "< $_[0]") or die;
128 if (/^\s*#\s*source(\d+)-md5\s*:\s*([a-f0-9]{32})/i) {
131 if (defined $macro{"no_source_$no"}) {
132 error("both NoSource: $no and md5 given");
133 } elsif (defined $macro{"source_$no"}) {
134 my $s = $macro{"source_$no"};
135 if ($s =~ /^([a-z0-9A-Z:\=\?\@\+\~\.\-\/_]|\%[0-9])+$/) {
136 if ($s =~ /^(ftp|http):\/\//) {
138 error("source $no ($s) is directory");
140 if ($s =~ /:\/\/distfiles\.pld-linux\.org\/src/) {
142 print "$md5 no-url-copy://$s\n";
149 print "$md5 no-url://$s\n";
152 error("source $no url $s is ill-formatted");
155 error("source $no not defined");
163 parse_defines($spec);