#!/bin/sh
################################################################################
#
# File:         xmu
# RCS:          $Header: $
# Description:  talk to the XmuServer... [ WINTERP-based menu server ]
# Author:       Richard Hess, Consilium.
# Created:      Sat Oct  5 23:53:37 1991
# Modified:     Sat Oct  5 23:58:20 1991 (Niels Mayer) mayer@hplnpm
# Language:     sh
# Package:      N/A
# Status:       X11r5 contrib tape release
#
# WINTERP Copyright 1989, 1990, 1991 Hewlett-Packard Company (by Niels Mayer).
# XLISP version 2.1, Copyright (c) 1989, by David Betz.
#
# Permission to use, copy, modify, distribute, and sell this software and its
# documentation for any purpose is hereby granted without fee, provided that
# the above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear in supporting
# documentation, and that the name of Hewlett-Packard and David Betz not be
# used in advertising or publicity pertaining to distribution of the software
# without specific, written prior permission.  Hewlett-Packard and David Betz
# make no representations about the suitability of this software for any
# purpose. It is provided "as is" without express or implied warranty.
################################################################################

# 
# +---------------------------------------------------------------------------
#  WHO:    Richard Hess                    CORP:   Consilium
#  TITLE:  Staff Engineer                  VOICE:  [415] 691-6342
#      [ X-SWAT Team:  Special Projects ]  USNAIL: 640 Clyde Court
#  UUCP:   ...!uunet!cimshop!rhess                 Mountain View, CA 94043
# +---------------------------------------------------------------------------

unset WINTERP_UNIX_SOCKET_FILEPATH

PROG=`basename $0`
SERVER=/tmp/.xmu_server
export SERVER

if [ -w $SERVER ]
then
  HELP="$PROG  -color [ STRING ] | -keys | -nuke | -num | -xtra [ # ] | KEY | LISP"
else
  echo ":NoServer"
  HELP="$PROG  -init"
fi
case $# in
  0)  [ -w $SERVER ] && echo ":XmuServer" ;;
  1)  case $* in
	-color) [ -w $SERVER ] && wl -f $SERVER '*xmu_color*' ;;
	-help)	echo "$HELP" ;;
	-gc)	[ -w $SERVER ] && wl -f $SERVER '(gc)' ;;
	-init)	if [ -w $SERVER ]
		then
		  echo "WARNING -- Xmu Menu Server currently active..."
		else
		  CLASS="-class Xmu"
		  XGEO="-geometry 80x10+0+2"
		  XRM_OPTS="*VT100.Translations:#override<KeyDown>:ignore()"
		  XTERM_OPTS="-name XmuServer -title XmuServer -sb -sl 300 -ut"
		  xterm -iconic $XGEO $XTERM_OPTS -xrm "$XRM_OPTS" -e winterp $CLASS &
		  echo "-- Starting Xmu Menu Server..." 
		fi ;;
	-keys)  [ -w $SERVER ]  && wl -f $SERVER \
		 '(progn (format T "~%")
			 (dolist (elt *xmu_assoc*)
		               (let ((key  (car elt))
			             (note (caddr elt)))
				     (format T "~A  ~S~%" key note)
				     )))' ;;
	-nuke)  [ -w $SERVER ] && wl -f $SERVER ;;
	-num)   [ -w $SERVER ] && wl -f $SERVER '(length *xmu_assoc*)' ;;
	-xtra)  [ -w $SERVER ] && wl -f $SERVER '*xmu_xtra*' ;;
	-*)	echo "$HELP" ;;
	[0-9]*) xmenu.pl xpos=20 ypos=20 key=$1 ;;
        *)	[ -w $SERVER ] && wl -f $SERVER $* ;;
      esac ;;
  2)  case $1 in
	-color) [ -w $SERVER ] && wl -f $SERVER "(setq *xmu_color* \"$2\")" ;;
	-xtra)  [ -w $SERVER ] && wl -f $SERVER "(setq *xmu_xtra* $2)" ;;
	*)	echo "$HELP" ;;
      esac ;;
  *)  echo "$HELP" ;;
esac 
# -----------------------------------------------------------------------<eof>
