Skip to content

Commit 3453801

Browse files
committed
Use perl instead of GNU grep
1 parent e5dc172 commit 3453801

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

scripts/exract-common-text.sh

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,29 @@
55
# - under src/ directory
66
# - ../scripts/extract-common-text.sh
77

8+
# check if grep support -P (PCRE)
9+
grep -q -P x <<<"x" 2>/dev/null && PCRE=1 || PCRE=0
810

911
function get_text {
10-
grep -hPo '(?<=^extern const char )TEXT_[\w_]+' "$@"
12+
if [[ ${PCRE} = 1 ]]; then
13+
grep -hPo '(?<=^extern const char )TEXT_[\w_]+' "$@"
14+
else
15+
perl -ne 'print "$&\n" if /(?<=^extern const char )TEXT_[\w_]+/' "$@"
16+
fi
1117
}
1218

1319
function list_files {
14-
for f in $(grep -lPow '(?<=^extern const char )'"$1" text_*.h); do
20+
local -a list=()
21+
if [[ ${PCRE} = 1 ]]; then
22+
list=($(grep -lPow '(?<=^extern const char )'"$1" text_*.h))
23+
else
24+
list=($(perl -ne 'if (/(?<=^extern const char )\Q'"$1"'\E\b/) {
25+
print "$ARGV\n";
26+
close ARGV;
27+
}' text_*.h))
28+
fi
29+
local f
30+
for f in "${list[@]}"; do
1531
printf "%-16s" $f
1632
done
1733
echo
@@ -30,6 +46,6 @@ for f in text_*.h; do
3046
done
3147

3248
for t in $(list_array "${texts[@]}" | uniq -d); do
33-
printf "%-7s" "${t/TEXT_/}"
49+
printf "%-12s" "${t/TEXT_/}"
3450
list_files "$t"
3551
done

scripts/make-index-array.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@
88
# - Mark start and end of table.
99
# - C-u M-x shell-command-on-region ../scripts/make-index-array.sh
1010

11-
grep -Po '(TEXT_[A-Za-z0-9]+)' |
11+
# check if grep support -P (PCRE)
12+
grep -q -P x <<<"x" 2>/dev/null && PCRE=1 || PCRE=0
13+
14+
if [[ ${PCRE} = 1 ]]; then
15+
grep -Po '(TEXT_[A-Za-z0-9]+)'
16+
else
17+
perl -ne 'print "$1\n" while /(TEXT_[A-Za-z0-9]+)/g'
18+
fi |
1219
sed 's/TEXT_null/@@@@_null/' |
1320
awk '{ printf(" %3d, // %s\n", i++, $1); }' |
1421
sort -k3 -s |

0 commit comments

Comments
 (0)