New argument parsing.
authorfredrik <fredrik@959494ce-11ee-0310-bf91-de5d638817bd>
Sun, 10 Jun 2007 02:24:43 +0000 (02:24 +0000)
committerfredrik <fredrik@959494ce-11ee-0310-bf91-de5d638817bd>
Sun, 10 Jun 2007 02:24:43 +0000 (02:24 +0000)
git-svn-id: svn+ssh://svn.dolda2000.com/srv/svn/repos/src/utils@1069 959494ce-11ee-0310-bf91-de5d638817bd

planime

diff --git a/planime b/planime
index 5b09f0f..731a467 100755 (executable)
--- 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="$(<nextep)"
+    if ! isnum "$ep"; then
+       echo "planime: nextep is non-numeric" >&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