#!/usr/bin/env tclsh set prog modpkg set pbfields {pkgname pkgver pkgrel pkgdesc pkgbase epoch url license install changelog source noextract md5sums sha1sums sha256sums sha384sums sha512sums groups arch backup depends makedepends checkdepends optdepends conflicts provides replaces options} set pbfuncs {build check package} set dotfuncs {pre_install post_install pre_upgrade post_upgrade pre_remove post_remove} proc scanfields {inchan} { global pkgdata seek $inchan 0 set fld {} while {[gets $inchan line] >= 0} { if {$fld eq {}} { # Skip extra (>1) empty lines. if {$line ne {}} { lassign [list $line] fld vals } } elseif {$line eq {}} { set pkgdata($fld) $vals lassign {} fld vals } else { lappend vals $line } } if {$fld != {}} { set pkgdata($fld) $vals } } proc printfields {outchan} { global pkgdata foreach {fld vals} [array get pkgdata] { puts $outchan [join [concat $fld $vals] "\n"] puts "" } } if {$argc != 1} { puts stderr "usage: $prog \[path to modifier script\] < PKGDATA > PKGDATA.new" exit 2 } set mod [lindex $argv 0] if {! [file exists $mod]} { puts stderr "$prog: error: mod file does not exist" exit 1 } set modch [open $mod] scanfields stdin set modi [interp create] foreach {name vals} [array get pkgdata] { if {$name in $pbfields} { $modi eval [list set $name $vals] } } $modi eval [list set pbfuncs $pbfuncs] $modi eval [list set dotfuncs $dotfuncs] $modi eval { proc trimbash {code} { set code [string trim $code] set lines [split $code "\n"] set code {} for {set i 0} {$i < [llength $lines]} {incr i} { set ln " [string trim [lindex $lines $i]]" set code "$code$ln\n" } return $code } proc initfunc {file func} { if {! [file exists PKGTREE/$file/$func]} { exec putpkgtree $file $func beg << "${func}()\n(\n" exec putpkgtree $file $func end << ")\n" } } proc initdotfunc {func} { if {! [file exists PKGTREE/$pkgname.install]} { lappend source "$pkgname.install" } initfunc $pkgname.install $func } proc fput {name code section} { global dotfuncs pbfuncs if {$name in $dotfuncs} { initdotfunc $name set file $pkgname.install } elseif {$name in $pbfuncs} { initfunc PKGBUILD $name set file PKGBUILD } else { puts stderr "$prog: error: $name is not a known func" exit 2 } set code [trimbash $code] exec putpkgtree $file $name $section << $code } proc fappend {name code} { fput $name $code body } proc fprepend {name code} { fput $name $code beg } proc move {srcname destname args} { upvar #0 $srcname src $destname dest foreach pat $args { set idx [lsearch -glob $src "$pat*"] if {$idx == -1} { error "$pat was not found in $srcname" } lappend $dest [lindex $src $idx] set src [lreplace $src $idx $idx] } } } $modi eval [read $modch] foreach name $pbfields { if {[$modi eval info exists $name]} { set pkgdata($name) [$modi eval set $name] } } printfields stdout