forked from shidel/fd-nls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckup.sh
executable file
·350 lines (302 loc) · 8.94 KB
/
checkup.sh
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
#!/bin/bash
SPECIAL=';packages;pgme;fdi;'
EXCLUDE=';txt;docinfo;htm;html;'
LANGUAGES=''
APPLANGS=''
APPS=0
LANGS=0
TRANS=0
PLATFORM="$(uname)"
KEYFILE_ERR="translation file"
function script_header () {
echo "When listing languages for a specific program, the language maybe followed"
echo "by a special character. Those characters mean the translation file failed"
echo "a specific test."
echo
echo " ? unable to locate default English version"
echo " ! caution, English version is newer than translation"
echo " * problem, either missing or extras keys"
echo
}
function script_summary () {
script_header
echo "Also note, this utility does not scan the following directories:"
echo
x="${SPECIAL:1:$(( ${#SPECIAL} - 2))}"
x="${x//;/, }"
echo " ${x}"
echo
x="${EXCLUDE:0:$(( ${#EXCLUDE} - 1))}"
x="${x//;/, }"
x="${x:2}"
echo "and does not compare '${x}' file types or subdirectories."
}
function script_help () {
echo "usage: ${0##*/} [program]"
echo
script_summary
}
function get_stamp () {
local ret=0
stat -f %m "${1}" 2>/dev/null || ret=$?
if [[ $ret -ne 0 ]] ; then
echo 0
return 1
fi
return 0
}
function load_nls () {
# echo load "${2}"
unset ${1}
local line flag hold t
if [[ -f "${2}" ]] ; then
hold=$( while [[ ! $flag ]] ; do
read -r line || flag=done
line="${line//[$'\t\r\n']}"
line="${line#${line%%[![:space:]]*}}"
line="${line%${line##*[![:space:]]}}"
t="${line}"
line="${line%%:*}"
line="${line%%=*}"
[[ "${line}" == "" ]] && continue
[[ "${t}" == "${line}" ]] && continue
line="${line%${line##*[![:space:]]}}"
[[ "${line// }" != "${line}" ]] && continue
[[ "${line:0:1}" == "#" ]] && continue
[[ "${line:0:1}" == ";" ]] && continue
echo "${line};"
done< "${2}" | sort -u )
else
hold="${2}"
fi
hold="${hold//[$'\t\r\n']}"
if [[ "${hold}" != "" ]] ; then
read -r ${1} <<<";${hold}"
elif [[ "${2}" != "${EN}" ]] ; then
EN_DATA="${EN}"
fi
}
function compare_nls () {
local t x d n
local p="${1%/*}"
p="${p##*/}"
EN_CMP=''
if [[ ${EN_STAMP} -eq 0 ]] ; then
EN_CMP='?'
elif [[ "${p}" == "nls" ]] ; then
[[ "${EN_DATA}" == "" ]] && load_nls EN_DATA "${EN}"
unset NLS_DATA
load_nls NLS_DATA "${1}"
if [[ "${EN_DATA}" == "${EN}" ]] ; then
UC=yes
elif [[ "${NLS_DATA}" != "${EN_DATA}" ]] ; then
EN_CMP="*"
[[ ${NO_REP} ]] && return 0
t="${EN_DATA}"
d=
while [[ ${#t} -ne 0 ]] ; do
x="${t%%;*}"
t="${t:$(( ${#x} + 1 ))}"
n="${NLS_DATA//;${x};/;}"
if [[ "${n}" == "${NLS_DATA}" ]] ; then
d="${d};${x}"
else
NLS_DATA="${n}"
fi
done
d="${d//;;/;}"
d="${d:1}"
if [[ "${d}" != '' ]] ; then
[[ ! ${KEY_BR} ]] && echo
KEY_BR=yes
echo "${KEYFILE_ERR} '${1}' is missing key(s): '${d//;/, }'"
fi
d="${NLS_DATA//;;/;}"
[[ ${#d} -gt 1 ]] && d="${d:1:$(( ${#d} - 2 ))}" || d=''
if [[ "${d}" != '' ]] ; then
[[ ! ${KEY_BR} ]] && echo
KEY_BR=yes
echo "${KEYFILE_ERR} '${1}' has extra key(s): '${d//;/, }'"
fi
# else
# echo "${1}"
# echo "${EN_DATA}"
# echo "${NLS_DATA}"
# echo
fi
else
UC=yes
fi
if [[ "${EN_CMP}" == "" ]] ; then
t=$(get_stamp "${1}")
[[ ${t} -lt ${EN_STAMP} ]] && EN_CMP='!'
fi
return 0
}
function lang_of_nls () {
local t=$(echo "${1}" | tr "[:upper:]" "[:lower:]")
t="${t##*/}"
t="${t#*.}"
t="${t%.*}"
[[ "${EXCLUDE//;${t};}" != "${EXCLUDE}" ]] && return 0
echo "${t}"
}
function calc_add_language () {
local i="${1}"
local x="${i//\*}"
x="${x//!}"
x="${x//\?}"
[[ "${x}" == "" ]] && return 0
[[ "${LANGUAGES}" = '' ]] && LANGUAGES=";"
[[ "${APPLANGS}" = '' ]] && APPLANGS=";"
if [[ "${LANGUAGES//;${x};}" == "${LANGUAGES}" ]] ; then
LANGUAGES="${LANGUAGES}${x};"
(( LANGS++ ))
fi
if [[ "${APPLANGS//;${i};}" == "${APPLANGS}" ]] && \
[[ "${APPLANGS//;${i}\*;}" == "${APPLANGS}" ]] && \
[[ "${APPLANGS//;${i}\?;}" == "${APPLANGS}" ]] && \
[[ "${APPLANGS//;${i}!;}" == "${APPLANGS}" ]] \
; then
APPLANGS="${APPLANGS}${i};"
fi
}
function calc_dir_languages () {
[[ ! -d "${1}" ]] && return 1
local i utf l
unset EN
unset EN_STAMP
unset EN_DATA
for i in "${1}"/* ; do
[[ ! -e "${i}" ]] && continue
if [[ "${EN}" == "" ]] ; then
EN="${1}/${1%%/*}.en"
if [[ ! -e "${EN}" ]] ; then
l=$(ls -a1d "${1}"/*.en 2>/dev/null | wc -l )
[[ ${l} -eq 1 ]] && EN=$(ls -a1d "${1}"/*.en)
fi
# echo "English version $EN"
EN_STAMP=$(get_stamp "${EN}")
# echo "Timestamp $EN_STAMP"
[[ ! -e "${EN}" ]] && UC=fail
fi
utf=$(ls -1d "${i}"* 2>/dev/null | grep -i "${i}\.utf-8" )
[[ "${utf}" != "" ]] && continue
l=$(lang_of_nls "${i}")
[[ "${l}" == "" ]] && continue
if [[ "${l}" == 'en' ]] ; then
calc_add_language "${l}"
else
compare_nls "$i"
calc_add_language "${l}${EN_CMP}"
fi
(( TRANS++ ))
done
return 0
}
function calc_src_languages () {
[[ ! -d "${1}" ]] && return 1
US=yes
local i utf l
for i in "${1}"/* ; do
[[ ! -e "${i}" ]] && continue
utf=$(ls -1d "${i}"* 2>/dev/null | grep -i "${i}\.utf-8" )
[[ "${utf}" != "" ]] && continue
case "${1%%/*}" in
ctmouse)
i="${i//.MSG}"
i="${i//CTM-/CTM.}"
:;
;;
mkeyb)
return 1
;;
*)
calc_dir_languages ${1%%/*}/source
return $?
esac
l=$(lang_of_nls "${i}")
[[ "${l}" == "" ]] && continue
calc_add_language "${l}?"
(( TRANS++ ))
done
return 0
}
function calc_languages () {
APPLANGS=''
local prog
unset UC
unset KEY_BR
calc_dir_languages ${1}/nls && prog=y
calc_dir_languages ${1}/doc && prog=y
calc_dir_languages ${1}/help && prog=y
calc_src_languages ${1}/source && prog=y
if [[ "${prog}" == "y" ]] ; then
(( APPS++ ))
APPLANGS="${APPLANGS:1:$(( ${#APPLANGS} - 2))}"
APPLANGS="${APPLANGS//;/, }"
/bin/echo -n "${1}: ${APPLANGS}"
[[ ${UC} ]] && /bin/echo -n " (compare manually)"
echo
sleep 1
fi
return 0
}
function each_app () {
local app
for app in * ; do
[[ ! -d "${app}" ]] && continue
[[ "${SPECIAL//;${app};}" != "${SPECIAL}" ]] && continue
${1} ${app}
done
}
function scan_summary () {
echo
echo "${APPS} total programs, ${LANGS} total languages, ${TRANS} total translations"
LANGUAGES=$(for i in ${LANGUAGES//;/ } ; do echo "${i}, "; done | sort | tr -d "[:cntrl:]")
[[ "${LANGUAGES}" != "" ]] && LANGUAGES="${LANGUAGES:0:$(( ${#LANGUAGES} - 2))}" || LANGUAGES="(none)"
echo "Languages: ${LANGUAGES}"
}
function create_report () {
local out="report.txt"
echo "Generating '${out}'"
echo "Report date: $(date)" | tee "${out}"
echo | tee -a "${out}"
script_summary | tee -a "${out}"
echo | tee -a "${out}"
echo "Translation file overview:" | tee -a "${out}"
echo | tee -a "${out}"
${0} -n -s | tee -a "${out}"
echo | tee -a "${out}"
echo "(index comparison is filtered through grep, so output may not be displayed until complete)"
echo "Translation file index key comparison:" | tee -a "${out}"
echo | tee -a "${out}"
each_app calc_languages | grep "^${KEYFILE_ERR}" | tee -a "${out}"
}
function main () {
local opt i
local once=yes
while [[ "${1}" != "" ]] || [[ $once ]]; do
opt="${1}"
shift
if [[ "${opt}" == "-h" ]] || [[ "${opt}" == "--help" ]] ; then
script_help
return 0
elif [[ "${opt}" == "-n" ]] ; then
NO_REP=yes # don't show key comparisons
elif [[ "${opt}" == "-s" ]] || [[ "${opt}" == "" ]] ; then
# summary
[[ $once ]] && script_header;
each_app calc_languages
scan_summary
elif [[ "${opt}" == "-r" ]] ; then
create_report
else
# summary
[[ $once ]] && script_header;
calc_languages "${opt}"
fi
unset once
done
}
main ${@}