summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/pbfields72
1 files changed, 44 insertions, 28 deletions
diff --git a/bin/pbfields b/bin/pbfields
index 310a375..2b9b927 100755
--- a/bin/pbfields
+++ b/bin/pbfields
@@ -8,8 +8,8 @@ BEGIN {
" *conflicts *provides" \
" url *source *noextract *md5sums *sha512sums" \
" _dir"
- max = split(fieldstr, fields)
- for(i = 1; i <= max; i++){
+ fieldcnt = split(fieldstr, fields)
+ for(i = 1; i <= fieldcnt; i++){
f = fields[i]
if(sub(/^[*]/, "", f)){
arrfield[f] = 1
@@ -18,6 +18,7 @@ BEGIN {
}else{
strfield[f] = 1
}
+ fields[i] = f
}
COLS = 78; FS = "\n"; RS = ""
@@ -29,15 +30,19 @@ $1 == "packager" { packager = $2; next }
$1 == "maintainer" { maintainer = $2; next }
+# pkgdesc has the only value where parameters do not expand.
+$1 == "pkgdesc" { output[$1] = qnoexpand($2); next }
+
$1 == "customvars" {
for(i = 2; i <= NF; i++){
customvars[i - 1] = $i
}
customlen = NF - 1
+ next
}
{
- quotevals()
+ for(i = 2; i <= NF; i++) $i = qexpand($i)
if(($1 in strfield) || ($1 in cfield)){
output[$1] = $2
}else {
@@ -61,22 +66,23 @@ END {
OFS = "="; ORS = "\n";
- for(i=1; i<=max; i++){
- name = fields[i]
- if(!(name in output)){
- continue
- }
-
- if(name in cfield){
- print "_" name, output[name]
- }else{
- print name, output[name]
- }
+ for(i = 1; i <= fieldcnt; i++){
+ f = fields[i]
+ if(!(f in output)) continue
+ v = output[f]
+ if(f in cfield) f = "_" f
+ print f, v
}
for(i = 1; i <= customlen; i++){
- v = customvars[i]
- print "_" v, unk[v]
+ f = customvars[i]
+ if(f in unk){
+ print "_" f, unk[f]
+ }else{
+ printf("pbfields: error: customvar \"%s\" has no value\n", f) \
+ > "/dev/stderr"
+ exit 100
+ }
}
}
@@ -89,13 +95,13 @@ function wraparray (indent)
linecount = 0
i = 2
- while(i <= NF) {
+ while(i <= NF){
linelen = length(line)
- if((indent + linelen + 1 + length($i) > COLS) && linelen > 0) {
+ if((indent + linelen + 1 + length($i) > COLS) && linelen > 0){
lines[++linecount] = line
line = ""
- } else {
+ }else{
if(linelen == 0) line = $(i++)
else line = line " " $(i++)
}
@@ -111,19 +117,29 @@ function wraparray (indent)
return txt
}
-function quotevals ()
+# Quote field value so that parameters ARE expanded.
+# NEVER expand command substition (ie backtick or $(...))
+function qexpand (v)
{
- for(i=2; i<=NF; i++) $i = bashquote($i)
+ if(v ~ /[$']/){
+ gsub(/["`]/, "\\\\&", v)
+ return sprintf("\"%s\"", v)
+ }else if(v ~ /[ <>`"]/){
+ return sprintf("'%s'", v)
+ }else{
+ return v
+ }
}
-function bashquote (val)
+# Quote field value so that parameters ARE NOT expanded.
+function qnoexpand (v)
{
- if(val ~ /'/){
- gsub(/[$"`]/, "\\\\&", val)
- return sprintf("\"%s\"", val)
- }else if(val ~ /[ <>`$"]/){
- return sprintf("'%s'", val)
+ if(v ~ /'/){
+ gsub(/[$"`]/, "\\\\&", v)
+ return sprintf("\"%s\"", v)
+ }else if(v ~ /[ $"`<>]/){
+ return sprintf("'%s'", v)
}else{
- return val
+ return v
}
}