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:   23-Jul-2003 15:34:17
  Branch: HEAD                             Handle: 2003072314341600

  Modified files:
    openpkg-re              speclint.pl

  Log:
    ok, and now make sure all subshells use correct error handling

  Summary:
    Revision    Changes     Path
    1.48        +58 -1      openpkg-re/speclint.pl
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: openpkg-re/speclint.pl
  ============================================================================
  $ cvs diff -u -r1.47 -r1.48 speclint.pl
  --- openpkg-re/speclint.pl    23 Jul 2003 07:07:01 -0000      1.47
  +++ openpkg-re/speclint.pl    23 Jul 2003 13:34:16 -0000      1.48
  @@ -830,7 +830,64 @@
           }
       }
   
  -    #   TODO: parenthesis style for sub-shells
  +    #   check for sub-shell parenthesis style
  +    #   (this is such complicated because the Bourne Shell has a
  +    #   construct "case <value> in <pattern> ) <script> ;; ... esac"
  +    #   where the closing parenthesis makes heavy problems for our
  +    #   check. So we first have to get rid of this. Unfortunately this
  +    #   is again not easy because there exists nested(!) case/esac
  +    #   constructs. Hence, we have to use a small recursive descent
  +    #   parser which replaces the ")" in case/esac constructs with
  +    #   "PCLOSE". A similar thing is done with string literals, although
  +    #   here the job is more trivial).
  +    if ($section !~ m/^\%files$/s) {
  +        $done = $outer_done; $this = ''; $todo = $outer_this;
  +        $todo =~ s/`[^`]*`/STRING/sg;
  +        $todo =~ s/'[^']*'/STRING/sg;
  +        $todo =~ s/"[^"]*"/STRING/sg;
  +        $todo = (&parse_sh("", $todo))[0];
  +        sub parse_sh {
  +            my ($done, $todo) = @_;
  +            while ($todo =~ m/^(.*?)(case|;;)/s) {
  +                if ($2 eq 'case') {
  +                    ($done, $todo) = &parse_case($done.$1, $2.$');
  +                }
  +                else {
  +                    ($done, $todo) = ($done.$1, $2.$');
  +                    return ($done, $todo);
  +                }
  +            }
  +            ($done, $todo) = ($done . $todo, "");
  +            return ($done, $todo);
  +        }
  +        sub parse_case {
  +            my ($done, $todo) = @_;
  +            $todo =~ m|^\s*case\s+\S+\s+in\b|s or return (undef, undef);
  +            ($done, $todo) = ($done . $&, $');
  +            while ($todo =~ m|^(\s*[^)\n]+)(\))|s) {
  +                ($done, $todo) = ($done . $1 . "PCLOSE", $');
  +                ($done, $todo) = &parse_sh($done, $todo) or return (undef, undef);
  +                $todo =~ m|^\s*;;|s or return (undef, undef);
  +                ($done, $todo) = ($done . $&, $');
  +            }
  +            $todo =~ m|^\s*esac|s or return (undef, undef);
  +            ($done, $todo) = ($done . $&, $');
  +            return ($done, $todo);
  +        }
  +        if ($todo eq '') {
  +            &lint_warning($file, $outer_done, $outer_this, 
  +                          "unable to correctly parse case/esac constructs in 
shell-script" .
  +                          " (sub-shell parenthesis check skipped)");
  +        }
  +        else {
  +            while ($todo =~ m/\)[ \t]*\n/s) {
  +                $done .= $`; $this = $&; $todo = $';
  +                &lint_warning($file, $done, $this, "problematic sub-shell construct 
without error handling " .
  +                              "(use \"...) || exit \$?\" to make sure it correctly 
exits on nested failure)");
  +                $done .= $this;
  +            }
  +        }
  +    }
   }
   
   ##  _________________________________________________________________
  @@ .
______________________________________________________________________
The OpenPKG Project                                    www.openpkg.org
CVS Repository Commit List                     [EMAIL PROTECTED]

Reply via email to