summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorJustin Davis <jrcd83@gmail.com>2011-09-09 23:32:59 +0200
committerJustin Davis <jrcd83@gmail.com>2011-09-09 23:32:59 +0200
commita904c6436bb93ce4c3fdeb583f40845db90de5be (patch)
tree7ce09e48f5bd4acf6cea46aaad8a97fd9da34e0e /bin
parente236a8163f1ade5956aa6d33642a4f3eba1f58f6 (diff)
downloadgenpkg-a904c6436bb93ce4c3fdeb583f40845db90de5be.tar.gz
genpkg-a904c6436bb93ce4c3fdeb583f40845db90de5be.tar.xz
Many changes to parser. Creates remval, remelem, findval funcs.
Adds the < and > stack operations. < pushes a value that matches its parameter to to the stack. > pops from the stack, storing in the given field. Fix error messages in die(), too.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/pbjparse.awk43
1 files changed, 30 insertions, 13 deletions
diff --git a/bin/pbjparse.awk b/bin/pbjparse.awk
index b5a5bc0..6da1d34 100755
--- a/bin/pbjparse.awk
+++ b/bin/pbjparse.awk
@@ -61,8 +61,17 @@ function parsepbj ( cmd) # cmd is a "local" var
else if ($1 == "-") {
if ($2 == "optdepends")
die("cannot delete an optdep once it is created.")
- if (! remval($2, $3))
- die("could not find " $3 " in " $2 "'s values")
+ remval($2, $3)
+ }
+ else if ($1 == "<") {
+ i = findval($2, $3)
+ stack[++stacklen] = pbvars[$2, i]
+ remelem($2, i)
+ }
+ else if ($1 == ">") {
+ if (stacklen < 1)
+ die("No values on the stack. Make sure you used '<' first.")
+ pushval($2, stack[stacklen--])
}
else if ($1 == "=") {
if ($2 == "optdepends") die("cannot use '=' with optdepends.")
@@ -84,7 +93,7 @@ function parsepbj ( cmd) # cmd is a "local" var
function die (msg)
{
- printf "%s: error: %s:%d %s\n", PROG, FILENAME, FNR, msg | "cat 1>&2"
+ printf "%s: error line %d: %s\n", PROG, FNR, msg | "cat 1>&2"
exit 1
}
@@ -106,21 +115,29 @@ function pushval (field, val)
pbvars[field, ++pbcount[field]] = val
}
-function remval (field, prefix, i, len)
+function remval (field, prefix)
{
- len = pbcount[field]
- if (len == 0) return 0
-
- for (i=1; i<=len; i++)
- if (pbvars[field, i] ~ "^" prefix) break
-
- if (i > len) return 0
+ remelem(field, findval(field, prefix))
+}
- for ( ; i < len; i++) pbvars[field, i] = pbvars[field, i+1]
+function remelem (field, i, len)
+{
+ # TODO: error check if "i" is in bounds?
+ len = pbcount[field]
+ for (len = pbcount[field]; i < len; i++)
+ pbvars[field, i] = pbvars[field, i+1]
delete pbvars[field, i]
pbcount[field]--
+}
+
+function findval (field, prefix, i, len)
+{
+ len = pbcount[field]
+ if (len == 0) die(field " is empty!")
- return 1
+ for (i=1; i<=len; i++) if (pbvars[field, i] ~ "^" prefix) break
+ if (i > len) die("could not find " prefix " in " field "'s values")
+ return i
}
function optdepname (msgbeg)