Tweak the bash parsing for package submission.

Better detection of the build function.
Better detection of variables.
Support for variables with underscores.

Signed-off-by: Loui Chang <louipc.ist@gmail.com>
This commit is contained in:
Loui Chang 2009-04-01 11:55:59 -04:00
parent ab1300d23a
commit 74a75661d9

View file

@ -120,10 +120,15 @@ if ($_COOKIE["AURSID"]):
$line = preg_replace('/\${(\w+)#(\w*)}?/', '$1$2', $line); $line = preg_replace('/\${(\w+)#(\w*)}?/', '$1$2', $line);
# Remove comments # Remove comments
$line = preg_replace('/#.*/', '', $line); $line = preg_replace('/\s*#.*/', '', $line);
$lparts = explode("=", $line, 2); $lparts = Array();
if (count($lparts) == 2) { # Match variable assignment only.
if (preg_match('/^\s*[_\w]+=[^=].*/', $line, $matches)) {
$lparts = explode("=", $matches[0], 2);
}
if (!empty($lparts)) {
# this is a variable/value pair, strip out # this is a variable/value pair, strip out
# array parens and any quoting, except in pkgdesc # array parens and any quoting, except in pkgdesc
# for pkgdesc, only remove start/end pairs of " or ' # for pkgdesc, only remove start/end pairs of " or '
@ -143,10 +148,10 @@ if ($_COOKIE["AURSID"]):
$pkgbuild[$lparts[0]] = str_replace(array("(",")","\"","'"), "", $pkgbuild[$lparts[0]] = str_replace(array("(",")","\"","'"), "",
$lparts[1]); $lparts[1]);
} }
} else { }
# either a comment, blank line, continued line, or build function else {
# # Non variable assignment line. (comment, blank, command, etc)
if (substr($lparts[0], 0, 5) == "build") { if (preg_match('/\s*build\s*\(\)/', $line)) {
$seen_build_function = 1; $seen_build_function = 1;
} }
} }
@ -203,10 +208,12 @@ if ($_COOKIE["AURSID"]):
} }
} }
} }
##simple variable replacement
$pattern_var = '/\$({?)([\w]+)(}?)/'; # Simple variable replacement
$pattern_var = '/\$({?)([_\w]+)(}?)/';
while (preg_match($pattern_var,$v,$regs)) { while (preg_match($pattern_var,$v,$regs)) {
$pieces = explode(" ",$pkgbuild["$regs[2]"],2); $pieces = explode(" ",$pkgbuild["$regs[2]"],2);
$pattern = '/\$'.$regs[1].$regs[2].$regs[3].'/'; $pattern = '/\$'.$regs[1].$regs[2].$regs[3].'/';
if ($regs[2] != $k) { if ($regs[2] != $k) {
$replacement = $pieces[0]; $replacement = $pieces[0];
@ -221,7 +228,7 @@ if ($_COOKIE["AURSID"]):
# Now we've parsed the pkgbuild, let's move it to where it belongs # Now we've parsed the pkgbuild, let's move it to where it belongs
if (!$error) { if (!$error) {
$pkg_name = str_replace("'", "", $pkgbuild['pkgname']); $pkg_name = str_replace("'", "", $new_pkgbuild['pkgname']);
$pkg_name = escapeshellarg($pkg_name); $pkg_name = escapeshellarg($pkg_name);
$pkg_name = str_replace("'", "", $pkg_name); $pkg_name = str_replace("'", "", $pkg_name);