OpenPKG CVS Repository http://cvs.openpkg.org/ ____________________________________________________________________________
Server: cvs.openpkg.org Name: Ralf S. Engelschall Root: /e/openpkg/cvs Email: [EMAIL PROTECTED] Module: openpkg-re Date: 24-Mar-2003 21:12:48 Branch: HEAD Handle: 2003032420124800 Modified files: openpkg-re speclint.pl Log: first cut for little pre-processor checks Summary: Revision Changes Path 1.6 +60 -0 openpkg-re/speclint.pl ____________________________________________________________________________ patch -p0 <<'@@ .' Index: openpkg-re/speclint.pl ============================================================================ $ cvs diff -u -r1.5 -r1.6 speclint.pl --- openpkg-re/speclint.pl 24 Mar 2003 19:32:13 -0000 1.5 +++ openpkg-re/speclint.pl 24 Mar 2003 20:12:48 -0000 1.6 @@ -102,6 +102,7 @@ license header section + preproc )); my @checks = (); if ($check eq 'all') { @@ -417,5 +418,64 @@ $regex =~ s|,| |sg; &lint_error($file, undef, undef, "invalid RPM section order (expected \"$regex\")"); } +} + +## _________________________________________________________________ +## +## CHECK "preproc": RPM macro pre-processor +## _________________________________________________________________ +## + +sub check_preproc { + my ($file, $spec) = @_; + + my $done = ''; my $this = ''; my $todo = $spec; + while ($todo =~ m/^(%(?:if|else|endif|define|undefine|option))(.*)$/m) { + $done .= $`; $this = $&; $todo = $'; + my ($cmd, $args) = ($1, $2); + if ($cmd eq '%if') { + # FIXME: either try to really parse the boolean expression + # FIXME: or at least try to guess its correct syntax + } + elsif ($cmd eq '%else' or $cmd eq '%endif') { + if (length($args) > 0) { + &lint_warning($file, $done, $this, "garbage after pre-processor directive " . + "\"$cmd\" (expected no arguments)"); + } + } + elsif ($cmd eq '%undefine') { + if ($args =~ m|^\s+(\S+)\s*$|) { + my $var = $1; + if ($var !~ m/^(V|with)_[a-z][a-zA-Z0-9_]*$/) { + &lint_warning($file, $done, $this, "unusually named macro: \"$var\" " . + "(expected \"(V|with)_[a-z][a-zA-Z0-9_]*\")"); + next; + } + } + else { + &lint_error($file, $done, $this, "invalid number of arguments to pre-processor " . + "directive \"$cmd\" (expected exactly 1 argument)"); + } + } + elsif ($cmd eq '%define' or $cmd eq '%option') { + if ($args =~ m|^\s+(\S+)\s+(.*)$|) { + my ($var, $val) = ($1, $2); + if ($var !~ m/^(V|with)_[a-z][a-zA-Z0-9_]*$/) { + &lint_warning($file, $done, $this, "unusually named macro: \"$var\" " . + "(expected \"(V|with)_[a-z][a-zA-Z0-9_]*\")"); + next; + } + if (length($val) == 0) { + &lint_error($file, $done, $this, "empty macro value"); + } + } + else { + &lint_error($file, $done, $this, "invalid number of arguments to pre-processor " . + "directive \"$cmd\" (expected exactly 2 arguments)"); + } + } + } + + # FIXME: check correct nesting, too. } @@ . ______________________________________________________________________ The OpenPKG Project www.openpkg.org CVS Repository Commit List [EMAIL PROTECTED]