ly/: Create one .ly file for every .ily instrument file
[sunny256-utils.git] / filt
blob9c51527e3de565333cf1062627f33cd99d731231
1 #!/usr/bin/env bash
3 #=======================================================================
4 # filt
5 # File ID: aad4fde6-02e6-11de-acfb-000475e441b9
6 # Kjører ei fil ($2 osv) gjennom et filter som spesifiseres som $1.
7 # License: GNU General Public License version 2 or later.
8 #=======================================================================
10 use_lock=1
11 test "$1" = "-u" && { use_lock=0; shift; }
12 cmd=$1
13 retval=0
14 shift
15 for ff in "$@"; do
16 if [ -f "$ff" ]; then
17 # cp -p $ff $ff.filt-bck
18 if test "$use_lock" = "1"; then
19 lock_wait=0
20 until mkdir "$ff.lock"; do
21 echo filt: $ff: Waiting for lock... >&2
22 lock_wait=1
23 sleep 1
24 done
25 test "$lock_wait" = "1" && { echo filt: $ff: Obtained lock >&2; }
27 cat "$ff" | $cmd >"$ff.filt.tmp"
28 retval=$[$retval | $?];
29 chmod --reference "$ff" "$ff.filt.tmp"
30 mv "$ff.filt.tmp" "$ff"
31 if test "$use_lock" = "1"; then
32 rmdir "$ff.lock" || { echo filt: $ff.lock: Lockdir unexpectedly disappeared >&2; }
34 else
35 echo filt: $ff: Not a regular file >&2
36 retval=$[$retval | 1];
38 done
39 exit $retval