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

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