blob: 37ac85793212ea900b3aa60df801c6755a6d42ca (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
#!/bin/bash
# made by Wiimm, 2012-10-06
plusmode=0
testmode=
kclmode=0
#------------------------------------------------------------------------------
function trim()
{
echo "$1" | sed -r 's/[[:blank:]]+/ /; s/^ //; s/ $//'
}
#------------------------------------------------------------------------------
function add_destname()
{
local dest="$1"
local plus="$2"
local add="$3"
if [[ ! $dest =~ $add ]]
then
if ((plus))
then
#--- add '+'
local s1="${dest%%(*}"
local s2="${dest#*(}"
if [[ $s1 != $s2 ]]
then
s2="($s2"
else
s1="${dest%%\[*}"
s2="${dest#*\[}"
if [[ $s1 != $s2 ]]
then
s2="[$s2"
else
s2=""
fi
fi
s1=$( trim "$s1" )
s2=$( trim "$s2" )
dest="$s1+ $s2"
fi
#--- add '[+$add]'
local s1="${dest%%]*}"
local s2="${dest#*]}"
if [[ $s1 != $s2 ]]
then
dest="$s1,+$add]$s2"
else
dest="$dest [+$add]"
fi
fi
echo "$dest"
}
#------------------------------------------------------------------------------
while (($#))
do
src="$1"
shift
if [[ $src = + ]]
then
plusmode=1
continue
fi
if [[ $src = ++ ]]
then
plusmode=1
kclmode=1
continue
fi
if [[ $src = -t || $src == --test ]]
then
testmode=--test
continue
fi
if [[ $src = -k || $src == --kcl ]]
then
kclmode=1
continue
fi
if [[ ! -f $src ]]
then
printf "%s: Not found: %s\n" "${0##*/}" "$src" >&2
continue
fi
#--- extract ext
ext="${src##*.}"
if [[ $ext = $src ]]
then
dest="$src"
ext=""
else
dest="${src%.*}"
ext=".$ext"
fi
d=${dest%_d}
if [[ "$d" != "$dest" ]]
then
dest="$d"
ext="_d${ext}"
fi
dest="$(add_destname "$dest" 1 minimap)"
#--- trim dest
dest="$( trim "$dest" )$ext"
if ((plusmode))
then
idx="${dest:0:2}"
idx="${idx/[^0-9]/}"
let idx=10#0$idx
if (( idx % 10 < 4 ))
then
let idx=idx+1
else
let idx=idx+7
fi
dest="$idx ${dest:3}"
#echo "idx=$idx"
fi
temp="$dest.temp"
echo "DEST=|$dest|"
#--- create temp, fix minimap, rename track
ln -f "$src" "$temp"
wszst -q minimap -r --auto "$temp" $testmode
if ! diff -q "$src" "$temp" >/dev/null
then
((plusmode)) || rm -f "$src"
mv "$temp" "$dest"
if ((kclmode))
then
kcldest="$(add_destname "$dest" 0 kcl)"
echo "KCLDEST=|$kcldest|"
cp -p "$dest" "$kcldest"
wszst norm "$kcldest" --kcl new,drop
if diff -q "$dest" "$kcldest" >/dev/null
then
rm "$kcldest"
else
rm "$dest"
fi
fi
fi
rm -f "$temp"
done
|