diff options
author | Justin Davis <jrcd83@gmail.com> | 2012-02-05 18:16:43 +0100 |
---|---|---|
committer | Justin Davis <jrcd83@gmail.com> | 2012-02-05 18:16:43 +0100 |
commit | ba97a989c2228e4840a0c58173b0d8f541911c69 (patch) | |
tree | 5e0fd4bae7c1270f3237f5415fef645baaf60c3d /bin/emitpkgtree | |
parent | 30669532cbd4439ed731778c08c8636491f8fc6e (diff) | |
download | genpkg-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/emitpkgtree')
-rwxr-xr-x | bin/emitpkgtree | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/bin/emitpkgtree b/bin/emitpkgtree new file mode 100755 index 0000000..ca12c59 --- /dev/null +++ b/bin/emitpkgtree @@ -0,0 +1,58 @@ +#!/usr/bin/env perl + +use warnings; +use strict; + +my $PROG = 'flatlntree'; + +sub parsetree +{ + my($name) = @_; + my($txt, $ln, @tree) = (q{}, $., $name); + while(<STDIN>){ + if(/^BEGNODE (\S+)$/){ + push @tree, $txt if($txt); + push @tree, parsetree($1); + $txt = q{}; + }elsif(/^ENDNODE (\S+)$/){ + if($1 ne $name){ + print STDERR "$PROG: wrong ENDNODE:" + . qq{ '$1' at line $.} + . qq{ (in '$name' started at line $ln)\n}; + exit 101; + }else{ + last; + } + }else{ + $txt .= $_; + } + } + + push @tree, $txt if($txt); + return \@tree; +} + +sub flatten +{ + my($tree) = @_; + if(ref $tree){ + # skip name + return join q{}, map { flatten($tree->[$_]) } 1 .. $#$tree; + }else{ + return $tree; + } +} + +sub main +{ + my $top = parsetree('TOP'); + @$top = grep { ref } @$top; # only keep sub-nodes + for my $n (@$top){ + my $name = $n->[0]; + print ">>> $name\n"; + print flatten($n); + } + return 0; +} + +exit main(); |