#!/bin/sh
#
# errno - display ENAME corresponding to number/all ENAMEs if no number specified

# License: LGPLv2
cols=$(tput cols)

[ "$#" -eq 1 ] && re="$1([^0-9]|$)"
echo "#include <errno.h>" \
  | cpp -dD -CC \
  | grep -E "^#define E[^ ]+ ${re}" \
  | sed ':s;s#/\*\([^ ]*\) #/*\1_#;t s;' \
  | column -t | tr _ ' ' | cut -c1-"${cols}"
