-
Notifications
You must be signed in to change notification settings - Fork 1
/
istext
executable file
·63 lines (58 loc) · 1.09 KB
/
istext
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
#!/usr/bin/env bash
#
# Synopsis:
# List UTF-8 text compliant files path in either argv or standard input.
# Usage:
# istext [-v] /etc/*
# find / -xdev -print0 | xargs -0 istext | xargs fgrep -l PATTERN
# Note:
# Need option "--reverse-match".
#
# Investigate why bash version of istext is 100 times slower then
# old c version. probably because only a fraction of the file
# is searched in old version.
#
# Consider an option "--frisk" that uses program jmscott/slice-file
# to extract just a portion of the file instead of the whole file
# (as legacy istext.c does).
#
REVERSE=no
_istext()
{
local F;
F="$1"
if [ ! -f "$F" ]; then
if [ ! -e "$F" ]; then
echo "file does not exist: $F" >&2
fi
return
fi
is-utf8wf <"$F"
STATUS=$?
case $STATUS in
0)
test $REVERSE = no && echo "$F"
;;
1|2)
test $REVERSE = yes && echo "$F"
;;
*)
echo "$PROG: ERROR: is-utf8wf failed: exit status=$STATUS" >&2
exit 2
;;
esac
return 0
}
if [ "$1" = -v ]; then
REVERSE=yes
shift
fi
if [ $# = 0 ]; then
while read -r F; do
_istext "$F"
done
else
for F in $@; do
_istext "$F"
done
fi