diff options
author | Justin Davis <jrcd83@gmail.com> | 2012-03-05 22:49:56 +0100 |
---|---|---|
committer | Justin Davis <jrcd83@gmail.com> | 2012-03-05 22:49:56 +0100 |
commit | 75bddd0e24674d76a2518dcbdced5a015b550775 (patch) | |
tree | c6cc9e33ced7447a0ad0ef08f66eb660120d1b2e | |
parent | bd9d357c9344f9c23919f5300ce780be2e2ddda0 (diff) | |
download | genpkg-75bddd0e24674d76a2518dcbdced5a015b550775.tar.gz genpkg-75bddd0e24674d76a2518dcbdced5a015b550775.tar.xz |
Replace old pkgtree scripts with new simpler ones.
-rw-r--r-- | bin/catpkgtree | 67 | ||||
-rwxr-xr-x | bin/emitpkgtree | 58 | ||||
-rwxr-xr-x | bin/getpkgtree | 22 | ||||
-rwxr-xr-x | bin/initpkgtree | 40 | ||||
-rwxr-xr-x | bin/putpkgtree | 26 |
5 files changed, 88 insertions, 125 deletions
diff --git a/bin/catpkgtree b/bin/catpkgtree deleted file mode 100644 index 846655c..0000000 --- a/bin/catpkgtree +++ /dev/null @@ -1,67 +0,0 @@ -#!/bin/sh - -PROG=catpkgtree - -findnode() -{ - for f in * - do - [ "$f" = '*' ] && break - [ -f "$f" ] || continue - case f in - [0-9][0-9]-*) - n=`echo "$f" | sed 's/^...//'` - if [ "$n" = "$1" ] - then - echo "$f" - return 0 - fi - esac - done - return 1 -} - -if [ $# -ne 1 ] -then - echo "usage: $PROG [tree path] < [text to append]" 1>&2 - exit 2 -fi - -if ! cd PKGTREE -then - echo "$PROG: PKGTREE dir must be present in current dir" 1>&2 - exit 100 -fi - -IFS=/ set -- "$1" -if [ $# -lt 2 ] -then - echo "$PROG: path to tree node must be separated by forward slashes" 1>&2 - exit 101 -fi - -if ! cd "$1" -then - echo "$PROG: $1 is not a valid package file" 1>&2 - exit 102 -fi -shift - -while [ $# -gt 1 ] -do - f=`findnode $1` - if [ $? -ne 0 ] || ! cd "$f" - then - echo "$PROG: $1 is not a valid node name" >1&2 - exit 102 - fi - shift -done - -f=`findnode $1` -if [ $? -ne 0 ] || [ ! -f "$f" ] -then - echo "$PROG: $f is not a valid final node" 1>&2 - exit 102 -fi -cat >> "$f" diff --git a/bin/emitpkgtree b/bin/emitpkgtree deleted file mode 100755 index ca12c59..0000000 --- a/bin/emitpkgtree +++ /dev/null @@ -1,58 +0,0 @@ -#!/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(); diff --git a/bin/getpkgtree b/bin/getpkgtree new file mode 100755 index 0000000..dd2517c --- /dev/null +++ b/bin/getpkgtree @@ -0,0 +1,22 @@ +#!/bin/sh + +prog=getpkgtree + +if [ "$#" -ne 2 ] +then + echo "usage: $prog [file] [section]" + exit 2 +fi + +if ! [ -d "$1" ] +then + echo "$prog: package file does not exist: $1" 1>&2 + exit 101 +fi +if ! [ -d "$1/$2" ] +then + echo "$prog: section does not exist: $2" 1>&2 + exit 102 +fi + +find "$1/$2" -maxdepth 1 -type f | sort | xargs cat diff --git a/bin/initpkgtree b/bin/initpkgtree new file mode 100755 index 0000000..77d8e47 --- /dev/null +++ b/bin/initpkgtree @@ -0,0 +1,40 @@ +#!/bin/sh +# Initializes files and their sections in a package tree directory structure. +# Assumes we are already inside of a package tree's root directory. + +prog=initpkgtree + +if [ $# -eq 0 ] +then + echo "usage: $prog [filename] [section 1] [section 2] [...]" 1>&2 + exit 2 +fi + +if [ -d "$1" ] +then + echo "$prog: a file named $1 already exists in the package tree" 1>&2 + exit 101 +fi + +dups=`for sect; do echo "$sect"; done | awk ' +{ dups[$1]++ } END { for(d in dups) if(dups[d] > 1) printf d " " }' +` +if [ "$dups" ] +then + echo "$prog: duplicate sections not permitted: $dups" 1>&2 + exit 102 +fi + +mkdir "$1" +cd "$1" +shift + +for sect +do + d="$sect" + mkdir "$d" + for f in beg body end + do + touch "$d/$f" + done +done diff --git a/bin/putpkgtree b/bin/putpkgtree new file mode 100755 index 0000000..f415108 --- /dev/null +++ b/bin/putpkgtree @@ -0,0 +1,26 @@ +#!/bin/sh + +prog=putpkgtree + +err() +{ + code="$1" + shift + echo $@ 1>&2 + exit "$code" +} + +if [ "$#" -ne 3 ] +then + echo "usage: $prog [file] [section] ['beg'/'body'/'end'] < [text to append]" 1>&2 + exit 2 +fi + +[ -d "$1" ] || err 101 "$prog: package file does not exist: $1" +cd "$1" + +[ -d "$2" ] || err 102 "$prog: section does not exist: $2" 1>&2 +cd "$2" + +[ -f "$3" ] || err 103 "$prog: subsection does not exist: $3" +cat >> "$3" |