#!/bin/bash #-*- sh -*- It=`basename $0` Version="0.1" Copyright=2005 Author="Tim Menzies" What="replace cocomo symbols with the numerics" ## define defaults Defaults=" --numbers numbers.dat" ##### end config ########################################### #### standard stuff - rarely changes copyright() { When=2005 Me="Tim Menzies" copyleft $It $When $What } playpen() { # make a temp place for intermediary files root="/tmp/$USER/$It" subdir="$root/$$.$RANDOM" mkdir -p $subdir [ -d "$root/last" ] && unlink "$root/last" ln -sf "$subdir" "$root/last" printf $subdir } purge() { # zap that place with the intermediary files if [ -z "$Keep" ] then [ -n "$Sandbox" ] && rm -rf $Sandbox else ./blab "$Sandbox\n" fi } help() { (help1 $* ); } help1() { # print stuff from the help directory cd $SrcDir; cd ../man/txt1; man1 $It $* } manual() { (manual1) ; } manual1() { # print all the manual cd $SrcDir; cd ../man/cat1; less $It } eg() { (eg1 $1); } eg1() { # show or tun the examples local x=$1 local some=0 [ -z "$1" ] && x=0 cd $SrcDir; cd ../eg/$It; if [ "$x" = "0" ]; then for i in `ls [0-9]* | fgrep -v '.'` do some=1 echo -n "$i " head -1 $i done [ $some = 0 ] && ./blab "$It: no examples\n" else ./$1 fi } config() { # load the rc files for i in /etc/${It}rc $HOME/.${It}rc $HOME/etc/${It}rc; do [ -f $i ] && . $i done } ######################################################## #### non-standard stuff- usually changes a lot prep() { # any magic pre-processing? ./table2Awk Table="Table" $Numbers } worker() { # call the worker prep > $Sandbox/nums.awk gawk -f $Sandbox/nums.awk -f cocNums.awk $1 } run() { # catch all flags, send the rest to the worker while [ -n "$*" ]; do S=1 # set to two when skipping flags with arguments case $1 in [^-]*) worker $*; exit ;; --numbers) Numbers=$2;S=2;; -K) Keep=1;; --copyright) copyright; exit ;; --version) printf "$It $Version\nWritten by $Author\n\n"; printf "For copyright information, see '$It --copyright'.\n"; exit ;; -h|--help) help Synopsis Options; exit ;; --seed) Seed=$2; S=2 ;; --eg) eg $2; exit ;; --man) manual; exit;; -*) echo -n "Unknown option: [$1]. "; help Synopsis Options; exit 1;; esac; shift $S; done worker $* } trap "purge" 0 1 2 3 15 # always purge on exit SrcDir="`dirname $0`" # know your place Sandbox=`playpen` # get a temp directory config # read the "rc" files run $Defaults $* # process command line flags