Just because I felt like wasting time, I tried to improve some of 'errno' tool there, which I find quite useful.
The result is generally faster, with less forks, relying on matching of sed and awk or shell rather than a grep. The only thing non-standard is the use of 'I' in sed 's' for case insensitivity. I checked that that is supported by busybox's sed as well as gnu's.
if $(which gcc >/dev/null); then
# Header finding trick from Kees Cook <email address hidden> headers=$(echo "#include <asm/errno.h>" | gcc -E - | awk -F\" '$2 ~ /\.h/ { print $2}' | sort -u)
else headers="/usr/include/asm-generic/errno*.h"
fi
for code in "${@}"; do
if [ "$code" -le 0 -o "$code" -ge 0 ] 2>/dev/null; then
# Input is a number, search for a particular matching code
sed -n "s,^#define\s\+\([^\s]\+\s\+${code}\s.*\),\1,p" ${headers}
else
# Input is not a number, search for any matching strings
sed -n "s,^#define\s\+\(.*${code}.*\),\1,Ip" ${headers}
fi
done
Just because I felt like wasting time, I tried to improve some of 'errno' tool there, which I find quite useful.
The result is generally faster, with less forks, relying on matching of sed and awk or shell rather than a grep. The only thing non-standard is the use of 'I' in sed 's' for case insensitivity. I checked that that is supported by busybox's sed as well as gnu's.
if $(which gcc >/dev/null); then
headers= $(echo "#include <asm/errno.h>" | gcc -E - | awk -F\" '$2 ~ /\.h/ { print $2}' | sort -u)
headers= "/usr/include/ asm-generic/ errno*. h"
# Header finding trick from Kees Cook <email address hidden>
else
fi
for code in "${@}"; do s\+\([^ \s]\+\s\ +${code} \s.*\), \1,p" ${headers} s\+\(.* ${code} .*\),\1, Ip" ${headers}
if [ "$code" -le 0 -o "$code" -ge 0 ] 2>/dev/null; then
# Input is a number, search for a particular matching code
sed -n "s,^#define\
else
# Input is not a number, search for any matching strings
sed -n "s,^#define\
fi
done