Commit 2568851e authored by Gergely Imreh's avatar Gergely Imreh Committed by Loui Chang
Browse files

FS#2649, FS#12645: subsititution of all variables and "eval"



All custom variables are handled during subsitution, as well as
bash "eval" statements.

Signed-off-by: default avatarLoui Chang <louipc.ist@gmail.com>
parent 24865f2a
......@@ -180,19 +180,34 @@ if ($_COOKIE["AURSID"]):
}
}
# Now, run through the pkgbuild array and do any $pkgname/$pkgver
# substituions.
#
# TODO: run through and do ALL substitutions, to cover custom vars
# Now, run through the pkgbuild array, and do "eval" and simple substituions.
if (!$error) {
$pkgname_var = $pkgbuild["pkgname"];
$pkgver_var = $pkgbuild["pkgver"];
$new_pkgbuild = array();
while (list($k, $v) = each($pkgbuild)) {
$v = str_replace('$pkgname', $pkgname_var, $v);
$v = str_replace('${pkgname}', $pkgname_var, $v);
$v = str_replace('$pkgver', $pkgver_var, $v);
$v = str_replace('${pkgver}', $pkgver_var, $v);
if (strpos($k,'eval ') !== false) {
$k = preg_replace('/^eval[\s]*/', "", $k);
##"eval" replacements
$pattern_eval = '/{\$({?)([\w]+)(}?)}/';
while (preg_match($pattern_eval,$v,$regs)) {
$pieces = explode(",",$pkgbuild["$regs[2]"]);
## nongreedy matching! - preserving the order of "eval"
$pattern = '/([\S]*?){\$'.$regs[1].$regs[2].$regs[3].'}([\S]*)/';
while (preg_match($pattern,$v,$regs_replace)) {
$replacement = "";
for ($i = 0; $i < sizeof($pieces); $i++) {
$replacement .= $regs_replace[1].$pieces[$i].$regs_replace[2]." ";
}
$v=preg_replace($pattern, $replacement, $v, 1);
}
}
}
##simple variable replacement
$pattern_var = '/\$({?)([\w]+)(}?)/';
while (preg_match($pattern_var,$v,$regs)) {
$pieces = explode(" ",$pkgbuild["$regs[2]"],2);
$pattern = '/\$'.$regs[1].$regs[2].$regs[3].'/';
$replacement = $pieces[0];
$v=preg_replace($pattern, $replacement, $v);
}
$new_pkgbuild[$k] = $v;
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment