[BACK]Return to wtf CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / games / wtf

File: [cvs.NetBSD.org] / src / games / wtf / wtf (download)

Revision 1.25, Thu Aug 16 13:31:04 2018 UTC (2 years, 1 month ago) by maya
Branch: MAIN
CVS Tags: phil-wifi-20200421, phil-wifi-20200411, phil-wifi-20200406, phil-wifi-20191119, phil-wifi-20190609, pgoyette-compat-20190127, pgoyette-compat-20190118, pgoyette-compat-1226, pgoyette-compat-1126, pgoyette-compat-1020, pgoyette-compat-0930, pgoyette-compat-0906, netbsd-9-base, netbsd-9-0-RELEASE, netbsd-9-0-RC2, netbsd-9-0-RC1, netbsd-9, is-mlppp-base, is-mlppp, HEAD
Changes since 1.24: +8 -1 lines

Try freebsd's pkg-info as well

From John Hein, via Nikolai Lifanov. PR misc/52684

#!/bin/sh
#
#	$NetBSD: wtf,v 1.25 2018/08/16 13:31:04 maya Exp $
#
# Public domain
#

PROGNAME="$(basename "$0")"
offensive=false

usage() {
	echo "usage: $PROGNAME [-o] [-f dbfile] [is] term ..."
	exit 1
}

while getopts f:o f
do
	case "$f" in
	o)	offensive=true
		;;
	f)
		acronyms="$OPTARG $acronyms"
		;;
	*)
		usage
		;;
	esac
done

shift "$(expr "$OPTIND" - 1)"

if [ "$1" = "is" ]; then
	if [ $# -gt 1 ] ; then
		shift
	fi
fi

if [ -z "$1" ]; then
	usage
fi

if [ -z "$acronyms" ]; then
	if [ -z "$ACRONYMDB" ]; then
		for f in /usr/share/misc/acronyms*; do
			case $f in
			*-o)
				if $offensive; then
					acronyms="$acronyms $f"
				fi
				;;
			*)
				acronyms="$acronyms $f"
				;;
			esac
		done
	else
		acronyms="$ACRONYMDB"
	fi
fi

if [ -z "$acronyms" ]; then
	echo "$PROGNAME: acronym database not found!" >&2
	exit 1
fi


for f in $acronyms; do
	if [ ! -f "$f" ]; then
		echo "$PROGNAME: cannot open acronym database file \`$f'" >&2
		exit 1
	fi
done

rv=0
for i; do
	# Search acronym list first
  target="$(echo "$i" | tr '[:lower:]' '[:upper:]')"
	ans="$(fgrep -h "$target" $acronyms 2>/dev/null \
	     | sed -ne "\|^$target[[:space:]]|s|^$target[[:space:]]*||p")"
	if [ -n "$ans" ] ; then
		echo "$target: $ans"
		continue
	fi

	# Try whatis(1) next
	ans="$(whatis "$i" 2>/dev/null)"
	if [ $? -eq 0 ]; then
		echo "$ans" | sort -u
		continue
	fi

	# Try pkg_info(1) next
	ans="$(pkg_info -qc "$i" 2> /dev/null)"
	if [ $? -eq 0 ]; then
		echo "$i: $ans"
		continue
	fi

	# Try pkg-info(1) next
	ans="$(pkg info -qI "$i" 2> /dev/null)"
	if [ $? -eq 0 ]; then
		echo "$i: $ans"
		continue
	fi

	# If called from pkgsrc package directory,
	# try querying pkgsrc's help facility next
	if [ -f ../../mk/bsd.pkg.mk ]; then
		ans="$(make help topic="$i")"
		if [ "$ans" != "No help found for $i." ]; then
			echo "$i: $ans"
			continue
		fi
	fi

	# Give up!
	echo "$PROGNAME: I don't know what \`$i' means!" 1>&2
	rv=1
done
exit $rv