Commit fab15ba7 authored by Michael Shigorin's avatar Michael Shigorin

bin/archdep-filter: factored out

This code started breeding within pkg.in/*/Makefile, and it was lacking both E2K (as a generic alias, not just "e2k or e2kv4") _and_ the ability to negate selection, as in "everywhere but not on any e2k"). Let's fix all of that at once, and parallelize sed execution as well; my tests with 1000-line file containing "a b c d@!E2K e@e2k f g@!X86 h i@IA32" lines show roughly 3x higher CPU load and lower execution time (~0.3 sec vs ~0.9 sec on 801-PC). And turn that code snippet into a proper filter with inline edit capability (I've dropped the exit trap as failing to mv signals a disaster anyway).
parent df88da98
#!/bin/sh
# filter stdin or file for words related to
# the specified target architecture
#
# args: -a arch [-i file]
if [ "$1" = "-a" -a -n "$2" ]; then
a="$2"
shift 2
else
cat
exit
fi
if [ "$1" = "-i" -a -w "$2" ]; then
f="$2"
t="`mktemp`"
fi
# map meta-arches for prefiltering
# NB: biarch gets special expansion later
case "$a" in
i586)
A="(IA32|X86)";;
x86_64)
A="X86";;
e2k*)
A="E2K";;
*)
A=;;
esac
# NB: pipe runs in parallel => faster than -e -e
cat ${f:+"$f"} |
sed -rn "s/\<([^@ ]*)\>|\<([^@ ]*)@$A\>/\1\2/pg" |
sed -rn "s/\<([^@ ]*)\>|\<[^@ ]*@\!$A\> */\1/pg" |
sed -r "s/\<([^@ ]*)@IA32\>/\1@i586 i586-\1@x86_64/g" |
sed -rn "s/\<([^@ ]*)\>|\<([^@ ]*)@$a\>/\1\2/pg" |
sed -rn "s/\<([^@ ]*)\>|\<[^@ ]*@\!$a\> */\1/pg" |
sed -r "s/\<([^@ ]*)@\![^@ ]+\>/\1/g" |
sed -r "s/\<([^@ ]*)@[^@ ]+\> *//g" |
sed -r "s/^ +//;s/ +$//" |
if [ -n "$f" ]; then
cat > "$t" && mv "$t" "$f"
else
cat
fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment