dnl CF_XTERM_MODE version: 7 updated: 2001/02/03 00:10:35
dnl -------------
dnl Check if xterm is installed setuid/setgid, assume we want to do the same on a
dnl new install
AC_DEFUN([CF_XTERM_MODE],[
AC_PATH_PROG(XTERM_PATH,xterm)
XTERM_MODE=755
XTERM_USR=
XTERM_GRP=
AC_MSG_CHECKING(for presumed installation-mode)
if test -f "$XTERM_PATH" ; then
	cf_option="-l -L"

	# Expect listing to have fields like this:
	#-r--r--r--   1 user      group       34293 Jul 18 16:29 pathname
	ls $cf_option $XTERM_PATH >conftest.out
	read cf_mode cf_links cf_usr cf_grp cf_size cf_date1 cf_date2 cf_date3 cf_rest <conftest.out
	echo "if \"$cf_rest\" is null, try the -g option" 1>&AC_FD_CC
	if test -z "$cf_rest" ; then
		cf_option="$cf_option -g"
		ls $cf_option $XTERM_PATH >conftest.out
		read cf_mode cf_links cf_usr cf_grp cf_size cf_date1 cf_date2 cf_date3 cf_rest <conftest.out
	fi

	# If we have a pathname, and the date fields look right, assume we've
	# captured the group as well.
	echo "if \"$cf_rest\" is null, we do not look for group" 1>&AC_FD_CC
	if test -n "$cf_rest" ; then
		cf_test=`echo "${cf_date2}${cf_date3}" | sed -e 's/[[0-9:]]//g'`
		echo "if we have date in proper columns ($cf_date1 $cf_date2 $cf_date3), \"$cf_test\" is null" 1>&AC_FD_CC
		if test -z "$cf_test" ; then
			XTERM_USR=$cf_usr;
			XTERM_GRP=$cf_grp;
		fi
	fi
	echo "derived user \"$XTERM_USR\", group \"$XTERM_GRP\" of previously-installed xterm" 1>&AC_FD_CC

	echo "see if mode \"$cf_mode\" has s-bit set" 1>&AC_FD_CC
	case ".$cf_mode" in #(vi
	.???s*) #(vi
		XTERM_MODE=4711
		XTERM_GRP=
		;;
	.??????s*)
		XTERM_MODE=2711
		XTERM_USR=
		;;
	esac
fi

if test -n "${XTERM_USR}${XTERM_GRP}" ; then
	cf_usr=`id | sed -e 's/^[[^(]]*(//' -e 's/).*$//'`
	cf_grp=`id | sed -e 's/^.* gid=[[^(]]*(//' -e 's/).*$//'`
	echo "configuring as user \"$cf_usr\", group \"$cf_grp\" of previously-installed xterm" 1>&AC_FD_CC
	test "$XTERM_USR" = "$cf_usr" && XTERM_USR=""
	test "$XTERM_USR" = "root"    && XTERM_USR=""
	test "$XTERM_GRP" = "$cf_grp" && XTERM_GRP=""
	test "$XTERM_GRP" = "root"    && XTERM_GRP=""
	test "$XTERM_GRP" = "wheel"   && XTERM_GRP=""
fi

AC_MSG_RESULT($XTERM_MODE $XTERM_USR $XTERM_GRP)

test -n "$XTERM_USR" && XTERM_USR="-o $XTERM_USR"
test -n "$XTERM_GRP" && XTERM_GRP="-g $XTERM_GRP"

AC_SUBST(XTERM_MODE)
AC_SUBST(XTERM_USR)
AC_SUBST(XTERM_GRP)
])dnl
