summaryrefslogtreecommitdiffstats
path: root/bin/pbfields
diff options
context:
space:
mode:
authorJustin Davis <jrcd83@gmail.com>2012-02-05 18:16:43 +0100
committerJustin Davis <jrcd83@gmail.com>2012-02-05 18:16:43 +0100
commitba97a989c2228e4840a0c58173b0d8f541911c69 (patch)
tree5e0fd4bae7c1270f3237f5415fef645baaf60c3d /bin/pbfields
parent30669532cbd4439ed731778c08c8636491f8fc6e (diff)
downloadgenpkg-ba97a989c2228e4840a0c58173b0d8f541911c69.tar.gz
genpkg-ba97a989c2228e4840a0c58173b0d8f541911c69.tar.xz
Start of big rewrite of pkg tweaking.
The current setup is only really good for modifying PKGBUILD fields. The modification of PKGBUILD funcs is hackish. Instead, the tweaks will be written in a scripting language (like Io) where both PKGBUILD fields and function code can be easily modified. Fields should be able to be modified just like arrays, but with easier package matching going on. PKGBUILD bash functions are simply arrays of lines, but they are not as sophisticated. Instead they can only be appended to. Package files are represented as trees. Each file (PKGBUILD pkg.install) is a child of the top-level node of the tree. Each child of the file node is a section of the file (intro, body, end). Each section can also have its own intro, body, and end node. In this way each bash function is a node with its own intro, body, and end node. Prepending to a function appends to its intro node. Appending to a function appends to its end child node. The body cannot be modified.
Diffstat (limited to 'bin/pbfields')
-rwxr-xr-xbin/pbfields99
1 files changed, 99 insertions, 0 deletions
diff --git a/bin/pbfields b/bin/pbfields
new file mode 100755
index 0000000..5e7844c
--- /dev/null
+++ b/bin/pbfields
@@ -0,0 +1,99 @@
+#!/usr/bin/awk -f
+
+BEGIN {
+ fieldstr = "pkgname pkgver pkgrel pkgdesc epoch" \
+ " *arch *license *options" \
+ " install changelog" \
+ " *depends *makedepends *checkdepends *optdepends" \
+ " *conflicts *provides" \
+ " url *source *noextract *md5sums *sha512sums"
+ max = split(fieldstr, fields)
+ for(i=1; i<=max; i++) {
+ if(sub(/^[*]/, "", fields[i])) arrfield[fields[i]] = 1;
+ else strfield[fields[i]] = 1;
+ }
+
+ COLS = 78; FS = "\n"; RS = ""
+}
+
+NF < 2 { next }
+
+$1 == "packager" { packager = $2 }
+
+$1 == "maintainer" { maintainer = $2 }
+
+$1 ~ /depends$|conflicts|provides|source/ { quotevals() }
+
+$1 == "pkgdesc" {
+ gsub(/[$"`]/, "\\\\&", $2)
+ $2 = sprintf("\"%s\"", $2)
+}
+
+$1 == "pkgverfmt" { pkgverfmt = $2 }
+
+strfield[$1] { output[$1] = $2 }
+
+arrfield[$1] {
+ output[$1] = wraparray(length($1) + 2)
+}
+
+END {
+ if(pkgverfmt){
+ output["pkgver"] = sprintf(pkgverfmt, output["pkgver"])
+ }
+
+ if(!maintainer && !packager) { packager = "Anonymous" }
+ if(maintainer) print "# Maintainer: " maintainer
+ else if(packager) print "# Packager: " packager
+ print ""
+
+ OFS = "="; ORS = "\n";
+ for(i=1; i<=max; i++){
+ name = fields[i]
+ if(name in output){
+ print name, output[name]
+ }
+ }
+}
+
+function wraparray (indent)
+{
+ if(NF == 1) return "()" # this shouldn't happen but just in case.
+
+ line = ""
+ delete lines
+ linecount = 0
+
+ i = 2
+ while(i <= NF) {
+ linelen = length(line)
+
+ if((indent + linelen + 1 + length($i) > COLS) && linelen > 0) {
+ lines[++linecount] = line
+ line = ""
+ } else {
+ if(linelen == 0) line = $(i++)
+ else line = line " " $(i++)
+ }
+ }
+
+ if(length(line) > 0) lines[++linecount] = line
+
+ indtxt = sprintf("%" indent "s", "")
+ txt = "(" lines[1]
+ for(i=2; i<=linecount; i++) txt = txt "\n" indtxt lines[i]
+ txt = txt ")"
+
+ return txt
+}
+
+function quotevals ()
+{
+ for(i=2; i<=NF; i++) $i = bashquote($i)
+}
+
+function bashquote (val)
+{
+ if(val ~ /[$]/) return sprintf("\"%s\"", val)
+ return sprintf("'%s'", val)
+}