#!/bin/sh - # # Oliver Fromme # # BSD-style copyright and standard disclaimer applies. # # Save this script as ``errno'' and make a link or symlink # to ``signal''. If called as ``signal'', it will print # all signal names and numbers with comments. If called as # ``errno'', it will print all error names and numbers with # comments. # # If either a name or a number is specified, that name or # number is looked up and displayed. # # Portability: Tested on FreeBSD and Solaris, probably works on # other platforms, too (depends on the structure # and contents of C header files). # case "$0" in *sig*) ACTION=signal HEADER=/usr/include/sys/signal.h FILTER='1,/typedef/s/#define[ ]\(SIG[A-Z]\)/\1/p' # Note: There's a space and a tab inside the brackets! ;; *err*) ACTION=error HEADER=/usr/include/sys/errno.h FILTER='1,/pseudo-error/s/#define[ ]\(E[A-Z]\)/\1/p' # Note: There's a space and a tab inside the brackets! ;; *) echo "${0}: Don't know what to do." >&2 exit 1; ;; esac if [ $# -gt 1 ] || expr "x$1" : "x-" >/dev/null; then echo "Usage: `basename $0` [$ACTION name or number]" >&2 exit 1; fi if [ $# -eq 1 ]; then if expr "$1" : '[0-9][0-9]*$' >/dev/null; then # Search signal/error number. sed -n "$FILTER" < "$HEADER" \ | awk ' BEGIN{ found = 0; } ($2 == '$1'){ found = 1; print; } END{ if (!found) print "'$ACTION' number '$1' not found"; } ' elif expr "$1" : '[A-Za-z][A-Za-z]*$' >/dev/null; then # Search signal/error name. NAME=`echo $1 | tr '[a-z]' '[A-Z]'` sed -n "$FILTER" < "$HEADER" \ | awk ' BEGIN{ found = 0; } /'$NAME'/{ found = 1; print; } END{ if (!found) print "'$ACTION' name '$NAME' not found"; } ' else echo "`basename $0`: syntax error" >&2 exit 1 fi elif [ -t 1 ]; then if [ "x$PAGER" = "x" ];then PAGER=more fi sed -n "$FILTER" < "$HEADER" | $PAGER else sed -n "$FILTER" < "$HEADER" fi