mtree-to-plist.awk revision 280215
1#!/usr/bin/awk 2/^[^#]/ { 3 gsub(/^\./,"", $1) 4 uname = gname = mode = flags = tags = type = "" 5 for (i=2; i<=NF; i++) { 6 if ($i ~ /^uname=/) { 7 uname=$i 8 gsub(/uname=/, "", uname) 9 } else if ($i ~ /^gname=/) { 10 gname=$i 11 gsub(/gname=/, "", gname) 12 } else if ($i ~ /^mode=/) { 13 mode=$i 14 gsub(/mode=/,"", mode) 15 } else if ($i ~ /^flags=/) { 16 flags=$i 17 gsub(/flags=/, "", flags) 18 } else if ($i ~ /^tags=/) { 19 tags=$i 20 gsub(/tags=/, "", tags) 21 } else if ($i ~ /^type=dir/) { 22 type="dir" 23 } 24 } 25 if (length(tags) == 0) 26 next 27 if (tags ~ /package=/) { 28 ext = pkgname = pkgend = "" 29 split(tags, a, ","); 30 for (i in a) { 31 if (a[i] ~ /^package=/) { 32 pkgname=a[i] 33 gsub(/package=/, "", pkgname) 34 } else if (a[i] == "config") { 35 type="config" 36 } else if (a[i] == "development" || a[i] == "profile") { 37 pkgend=a[i] 38 } else { 39 if (ext != "") 40 ext=ext"-"a[i] 41 else 42 ext=a[i] 43 } 44 } 45 if (ext != "") { 46 if (pkgname == "runtime") { 47 pkgname=ext 48 } else { 49 pkgname=pkgname"-"ext 50 } 51 } 52 if (pkgend != "") { 53 if (pkgname == "runtime") { 54 pkgname=pkgend 55 } else { 56 pkgname=pkgname"-"pkgend 57 } 58 } 59 } else { 60 print "No packages specified in line: $0" > 2 61 next 62 } 63 output=pkgname".plist" 64 65 print "@"type"("uname","gname","mode","flags") " $1 > output 66} 67