#!/bin/bash

# this structured collection of characters is Beer-licensed

DATAPATH="/your/data/path/"
CMAVOLIST="/usr/share/lojban/cmavo.txt"

case "$1" in
	-h)
			cat <<EOF
-s -> find all cmavo of a given selma'o
-ss -> find all cmavo of a given selma'o including suffixes
-f -> do a freetext search in the cmavo-list
-i -> show CLL-info about a given selma'o
none -> give info about the given cmavo
EOF
	;;

	-s)
		egrep -i "^.{11}$2 " $CMAVOLIST

	;;

	-ss)
		egrep -i "^.{11}$2" $CMAVOLIST

	;;

	-f)
		grep $2 $CMAVOLIST
		exit 0
	;;

	-i)
		SELMAHO=$(echo -n "$2" | tr a-z A-Z | tr H h)
		cat $DATAPATH$SELMAHO
		exit 0
	;;

	*)
		REQUEST=$(echo -n $1 | sed -e "s/h/'/g")

		if echo "$REQUEST" | grep -v "\." > /dev/null
		then
			REQUEST=" $REQUEST"
		fi

		SELMAHO=$(grep "^$REQUEST " $CMAVOLIST | head -n 1 | sed -e 's/^.\{11\}\([A-Za-z]*\).*$/\1/')

		echo -e "\033[4mFrom the cmavo list:\033[0m"
		grep "^$REQUEST " $CMAVOLIST

		echo

		echo -e "\033[4mThe entry for the selma'o \033[1;4m$SELMAHO\033[0;4m in the catalogue:\033[0m"
		cat "$DATAPATH$SELMAHO"

		exit 0
	;;
esac
