X-Git-Url: http://git.pld-linux.org/?a=blobdiff_plain;f=rpm-php-requires;h=2a3fb601ac143e2bcc7fd30ca02f84dd91255cee;hb=765b7c4193af0b9737c02aa103d1ebb2b3ebda9c;hp=a8dad654d20c85071db9d00333888d73994c1799;hpb=ce0971dd598bc1766ef80086cbc6fe44d6ecda3d;p=packages%2Frpm.git diff --git a/rpm-php-requires b/rpm-php-requires index a8dad65..2a3fb60 100644 --- a/rpm-php-requires +++ b/rpm-php-requires @@ -1,19 +1,82 @@ -#!/bin/sh -if [ $# -lt 1 ]; then - echo "You have to specify input file" - exit 1 -fi - -for i in `echo $@`; do - i=`echo $i | grep "\.php"` - if [ -n "$i" ]; then - j=`cat $i | grep -i ^require_once | egrep -v "^ \*" | sed -e "s/['|\"]//" | sed -e "s/(/ /" | cut -f 2 -d " " | sed -e "s/\//_/g" | cut -f 1 -d "."` - if [ -n "$j" ]; then - for p in $j; do - echo "pear($p)" - done - j="" - fi - fi -done +#!/usr/bin/perl +##################################################################### +# # +# Check system dependences between php-pear modules # +# # +# Pawe³ Go³aszewski # +# Micha³ Moskal # +# ------------------------------------------------------------------# +# TODO: # +# - extension_loaded - dependencies. # +# - some clean-up... # +##################################################################### +$pear = "/usr/share/pear"; + +@files = (); +%req = (); + +foreach (@ARGV ? $ARGV : <> ) { + chomp; + $f = $_; + push @files, $f; + # skip non-php files + next unless ($f =~ /\.php$/); + open(F, "< $f") or die; + + if ($f =~ /$pear/) { + $file_dir = $f; + $file_dir =~ s|.*$pear/||; + $file_dir =~ s|/[^/]*$||; + } else { + $file_dir = undef; + } + + while () { + # skip comments + next if (/^\s*(#|\/\/|\*|\/\*)/); + + while (/(\W|^)(require|include)(_once)? + \s* \(? \s* ("([^"]*)"|'([^']*)') + \s* \)? \s* ;/xg) { + if ($5 ne "") { + $x = $5; + } elsif ($6 ne "") { + $x = $6; + } else { + next; + } + + next if ($x =~ m|^\./| or $x =~ /\$/); + next unless ($x =~ /\.php$/); + $req{$x} = 1; + } + + next unless (defined $file_dir); + + while (/(\W|^)(require|include)(_once)? + \s* \(? \s* dirname \s* \( \s* __FILE__ \s* \) \s* \. \s* + ("([^"]*)"|'([^']*)') + \s* \)? \s* ;/xg) { + if ($5 ne "") { + $x = $5; + } elsif ($6 ne "") { + $x = $6; + } else { + next; + } + + next if ($x =~ /\$/); + next unless ($x =~ /\.php$/); + + $x = "$file_dir/$x"; + $x =~ s|/+|/|g; + $req{$x} = 1; + } + } +} + +f: for $f (keys %req) { + for $g (@files) { next f if ($g =~ /\Q$f\E$/); } + print "pear($f)\n"; +}