#!/bin/sh
dir=/tmp/xlogin$XSESSION
trap "echo -n Press Return or Enter to continue... ; read foo" 0 1 2 15

# If the command is of the form shell -c command, laugh heartily.
if [ $# -ge 2 ]; then
	if [ x$1 = x-c ]; then
		echo "No shell commands are allowed in xlogin lucy."
		exit 1
	fi
fi

if [ ! -r $dir/question.ez ]; then
	echo "First choose the option 'ask/edit a question' in the menu"
	echo "labeled 'lucy.'  When you quit editing, then send your question."
	exit 0
fi

# Otherwise run interactively, exit.
if [ 0`wc -w $dir/question.ez | awk ' { print $1 } ' ` -lt 04 ]; then
	echo 'First you need to save your question in ez.'
	echo 'Choose the "Save" option in the ez menu "ez".'
else
	cd $dir
	if grep -s begindata question.ez; then
		ez2ascii question.ez question.ascii
	else
		helpez2ascii < question.ez | ez2ascii > question.ascii
	fi
	lucy ask question.ascii
fi

# helpez2ascii does the same as the following awk script, but
# handles long lines.
# awk ' { if (NF == 0) { printf "%s\n", $0 } else { printf "%s\n\n", $0 } } '
