Added findfile.
authorfredrik <fredrik@959494ce-11ee-0310-bf91-de5d638817bd>
Sun, 10 Jun 2007 00:20:26 +0000 (00:20 +0000)
committerfredrik <fredrik@959494ce-11ee-0310-bf91-de5d638817bd>
Sun, 10 Jun 2007 00:20:26 +0000 (00:20 +0000)
git-svn-id: svn+ssh://svn.dolda2000.com/srv/svn/repos/src/utils@1068 959494ce-11ee-0310-bf91-de5d638817bd

planime

diff --git a/planime b/planime
index edcba1f..5b09f0f 100755 (executable)
--- a/planime
+++ b/planime
@@ -1,5 +1,39 @@
 #!/bin/sh
 
+isnum() {
+    grep -xq '[0-9]\+' <<<"$1"
+}
+
+findfile() {
+    local file tail eq eqt m
+    for file in "$1"*; do
+       tail="${file#$1}"
+       eq="${tail%.*}"
+       m=n
+       if [ "${eq%% *}" -eq "$2" ] 2>/dev/null; then
+           if [[ "$eq" == *\ * ]]; then
+               eqt="${eq#* }"
+           else
+               eqt=
+           fi
+           m=y
+       elif [ "${eq:0:${#2}}" = "$2" ]; then
+           eqt="${eq:${#2}}"
+           if [ "${eqt:0:1}" = " " -o -z "$eqt" ]; then
+               eqt="${eqt# }"
+               m=y
+           fi
+       fi
+       if [ "$m" = y ]; then
+           if [ "$eqt" = "$3" -o "$eqt" = "($3)" ]; then
+               echo "$file"
+               return 0
+           fi
+       fi
+    done
+    return 1
+}
+
 cmdline=(mplayer -fs)
 
 while [ "${1:0:1}" = - ]; do