From: fredrik Date: Sun, 10 Jun 2007 02:24:43 +0000 (+0000) Subject: New argument parsing. X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=529814da44d274cafe5cedf336102fd3649902e1;p=utils.git New argument parsing. git-svn-id: svn+ssh://svn.dolda2000.com/srv/svn/repos/src/utils@1069 959494ce-11ee-0310-bf91-de5d638817bd --- diff --git a/planime b/planime index 5b09f0f..731a467 100755 --- a/planime +++ b/planime @@ -40,6 +40,10 @@ while [ "${1:0:1}" = - ]; do a="$1" shift case "$a" in + -h) + echo "usage: planime [-ht] [-s PAR VAL] [NAME-QUAL] [EP|.] [TYPE-QUAL]" >&2 + exit 0 + ;; -t) cmdline=("${cmdline[@]}" -ao oss:/dev/dsp1) ;; @@ -52,17 +56,53 @@ while [ "${1:0:1}" = - ]; do esac done -if [ $# -lt 1 ]; then - echo "usage: planime [QUAL] EPNUM" >&2 - exit 1 -fi -if [ $# -eq 1 ]; then - ep="$1" - unset qual +base="$(basename "$(pwd)")" +nextep=n +file= +tqual= +if [ $# -eq 0 ]; then + nextep=y +elif [ $# -eq 1 ]; then + if [ -r "$1" ]; then + file="$1" + else + if findfile "$base - " "$1" >/dev/null; then + ep="$1" + else + nextep=y + base="$base $1" + fi + fi elif [ $# -eq 2 ]; then - qual="$1" + if findfile "$base - " "$1" "$2" >/dev/null; then + ep="$1" + tqual="$2" + else + base="$base $1" + ep="$2" + fi +else + base="$base $1" ep="$2" + tqual="$3" +fi +if [ "$ep" = . ]; then nextep=y; fi +if [ "$nextep" = y -a -r nextep ]; then + ep="$(&2 + exit 1 + fi fi +file="$(findfile "$base - " "$ep" "$qual")" + +if [ -z "$file" ]; then + echo "planime: no matching file found" >&2 + exit 1 +fi + +echo "$file" +exit 0 if [ ! -r "$ep" ]; then if [ -z "$qual" ]; then