[comp.sys.next] Frustrated with the Workspace manager?

gregc@cgl.ucsf.edu (Greg Couch) (07/12/89)

Ever been frustrated by the inability to autostart several Terminal windows
in *different* screen locations?  If so, please check out the following "fix"
and let me know if you come up with any spiffy window positioning programs.

	- Greg Couch
	gregc@cgl.ucsf.edu
------
Pseudo.shar
------
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create:
#	Makefile
#	Pseudo.c
#	window-position.c
#	Pseudo.1
#	window-position.1
#	Pseudo.iconheader
# This archive created: Tue Jul 11 16:51:42 1989
export PATH; PATH=/bin:/usr/bin:$PATH
echo shar: "extracting 'Makefile'" '(1577 characters)'
if test -f 'Makefile'
then
	echo shar: "will not over-write existing file 'Makefile'"
else
sed 's/^	X//' << \SHAR_EOF > 'Makefile'
	X#
	X#	$Id: Makefile,v 1.3 89/07/11 16:51:33 gregc Exp $
	X#
	X#	See the manual pages for a description of what these programs
	X#	do.  To install, do a "make install" and then as root do a
	X#	"make installman".  You may want to change the APPDEST and
	X#	BINDEST macros first though.
	X#
	XSHELL		= /bin/sh
	X
	XAPPDEST		= /LocalApps
	XBINDEST		= /usr/local/bin
	X
	XCFLAGS		= -O -Wall -pendantic
	X
	XPROGRAM1	= Pseudo
	XAPPICON1	=
	XDOCICON1	=
	XAPPICONFLAGS1	= -segcreate __ICON __header ${PROGRAM1}.iconheader \
	X		-segcreate __ICON __tiff ${PROGRAM1}.iconlist
	XSRCS1		= Pseudo.c
	XOBJS1		= Pseudo.o
	XLIBS1		= -lNeXT_s -lsys_s
	X
	XPROGRAM2	= window-position
	XSRCS2		= window-position.c
	XOBJS2		= window-position.o
	XLIBS2		= -lsys_s
	X
	Xall: ${PROGRAM1} ${PROGRAM2}
	X
	Xinstall: ${PROGRAM1} ${PROGRAM2}
	X	install -s ${PROGRAM1} ${APPDEST}/${PROGRAM1}
	X	install -s ${PROGRAM2} ${BINDEST}/${PROGRAM2}
	X
	Xinstallman:
	X	@echo "You probably need to be root to install the manual pages"
	X	ln ${PROGRAM1}.1 ${PROGRAM1}.l ; \
	X		installman ${PROGRAM1}.l ; \
	X	rm ${PROGRAM1}.l
	X	ln ${PROGRAM2}.1 ${PROGRAM2}.l ; \
	X		installman ${PROGRAM2}.l ; \
	X	rm ${PROGRAM2}.l
	X
	X${PROGRAM1}: ${OBJS1} ${PROGRAM1}.iconheader ${PROGRAM1}.iconlist
	X	${CC} ${CFLAGS} -o ${PROGRAM1} ${OBJS1} ${LIBS1} ${APPICONFLAGS1}
	X
	X${PROGRAM1}.iconlist: ${APPICON1} ${DOCICON1}
	X	cat ${APPICON1} ${DOCICON1} /dev/null > ${PROGRAM1}.iconlist
	X
	X${PROGRAM2}: ${OBJS2}
	X	${CC} ${CFLAGS} -o ${PROGRAM2} ${OBJS2} ${LIBS2}
	X
	Xclean:
	X	rm -f ${OBJS1} ${PROGRAM1} ${PROGRAM1}.iconlist ${OBJS2} ${PROGRAM2} \
	X		${PROGRAM1}.shar
	X
	Xshar:
	X	shar -a Makefile *.c *.1 *.iconheader > ${PROGRAM1}.shar
SHAR_EOF
if test 1577 -ne "`wc -c < 'Makefile'`"
then
	echo shar: "error transmitting 'Makefile'" '(should have been 1577 characters)'
fi
fi
echo shar: "extracting 'Pseudo.c'" '(3506 characters)'
if test -f 'Pseudo.c'
then
	echo shar: "will not over-write existing file 'Pseudo.c'"
else
sed 's/^	X//' << \SHAR_EOF > 'Pseudo.c'
	X/*
	X *	$Id: Pseudo.c,v 1.3 89/07/11 16:50:45 gregc Exp $
	X *
	X *	Copyright 1989 by the Regents of the University of California and
	X *	the UCSF Computer Graphics Laboratory.  All rights reserved.
	X *	Freely redistributable.
	X *
	X *	Pseudo:	 by Greg Couch, gregc@cgl.ucsf.edu, July 1989.
	X *
	X *		One of the main design defects of the Workspace manager
	X *	and NeXT defaults database is that you can't specify command line
	X *	arguments to applications invoked via the dock.  This is especially
	X *	important if you wish to startup more than one terminal emulator
	X *	without them appearing in the same place, same font, same ....
	X *
	X *		This program pretends to be an application, so it will
	X *	get the -MachLaunch arguments to communicate back to the Workspace
	X *	manager with.  All of its arguments are passed through to the
	X *	real application being run.  To find out which application to run
	X *	and the set of arguments to use, it checks the name that it was
	X *	invoked with and uses that as the application name for finding
	X *	variables in the defaults database.
	X */
	X
	X# include	<appkit/defaults.h>
	X# include	<stdlib.h>
	X# include	<string.h>
	X# include	<syslog.h>
	X# include	<sys/param.h>
	X
	Xextern	int	execvp(char *, char **);
	Xstatic	char	*strend(char *, char *, char *);
	X
	X# define	DEFAULT_SHELL	"/bin/sh"
	X# define	CMDBUF_END	(&cmdbuf[sizeof cmdbuf])
	X
	Xstatic	char	cmdbuf[NCARGS];
	Xstatic	char	*shell[]	= { DEFAULT_SHELL, "-c", cmdbuf, NULL };
	X
	Xvoid
	Xmain(argc, argv)
	X	int	argc;
	X	char	*argv[];
	X{
	X	register char	*cmdend;
	X	register int	i;
	X	register char	*invoked_as;
	X		/* defaults */
	X	register char	*Application;
	X	register char	*Args;
	X	register char	*Shell;
	X
	X	if (argc <= 0)
	X		exit(1);
	X
	X	/* find out which application we're pretending to be */
	X	if ((invoked_as = strrchr(argv[0], '/')) != NULL)
	X		invoked_as += 1;
	X	else
	X		invoked_as = argv[0];
	X
	X	openlog(invoked_as, LOG_PID, LOG_USER);
	X
	X	Application = NXGetDefaultValue(invoked_as, "Application");
	X	if (Application == NULL) {
	X		syslog(LOG_ERR, "missing Application default");
	X		exit(2);
	X	}
	X
	X	Shell = NXGetDefaultValue(invoked_as, "Shell");
	X	if (Shell == NULL)
	X		Shell = getenv("SHELL");
	X	if (Shell != NULL)
	X		shell[0] = Shell;
	X
	X	/*
	X	 * build command string
	X	 */
	X
	X	cmdend = cmdbuf;
	X	cmdend = strend(cmdend, "exec ", CMDBUF_END);
	X
	X	/* start with application */
	X	cmdend = strend(cmdend, Application, CMDBUF_END);
	X	cmdend = strend(cmdend, " ", CMDBUF_END);
	X
	X	/* pass through command line arguments */
	X	for (i = 1; i < argc; i += 1) {
	X		register char	*s,  *t;
	X
	X		cmdend = strend(cmdend, "\"", CMDBUF_END);
	X		for (s = argv[i]; (t = strchr(s, '"')) != NULL; s = t + 1) {
	X			*t = '\0';
	X			cmdend = strend(cmdend, s, CMDBUF_END);
	X			*t = '"';
	X		}
	X		cmdend = strend(cmdend, s, CMDBUF_END);
	X		cmdend = strend(cmdend, "\" ", CMDBUF_END);
	X	}
	X
	X	/* add on specific arguments */
	X	Args = NXGetDefaultValue(invoked_as, "Args");
	X	if (Args != NULL)
	X		cmdend = strend(cmdend, Args, CMDBUF_END);
	X
	X	if (cmdend == NULL) {
	X		syslog(LOG_ERR, "argument list too long");
	X		exit(3);
	X	}
	X
	X	(void) execvp(shell[0], shell);
	X	syslog(LOG_ERR, "exec failed (%s): %m", shell[0]);
	X	syslog(LOG_ERR, "PATH = %s", getenv("PATH"));
	X	exit(errno);
	X}
	X
	X/*
	X *	strend:
	X *
	X *		append src string to dest string and return the end of the
	X *	dest string without going beyond the last position in the dest string.
	X */
	X
	Xstatic	char	*
	Xstrend(dest, src, last)
	X	char	*dest, *src, *last;
	X{
	X	if (dest == NULL)
	X		return NULL;
	X
	X	while (dest < last && *src)
	X		*dest++ = *src++;
	X
	X	if (*src)
	X		return NULL;
	X	*dest = '\0';
	X	return dest;
	X}
SHAR_EOF
if test 3506 -ne "`wc -c < 'Pseudo.c'`"
then
	echo shar: "error transmitting 'Pseudo.c'" '(should have been 3506 characters)'
fi
fi
echo shar: "extracting 'window-position.c'" '(1783 characters)'
if test -f 'window-position.c'
then
	echo shar: "will not over-write existing file 'window-position.c'"
else
sed 's/^	X//' << \SHAR_EOF > 'window-position.c'
	X/*
	X *	$Id: window-position.c,v 1.3 89/07/11 16:50:47 gregc Exp $
	X *
	X *	Copyright 1989 by the Regents of the University of California and
	X *	the UCSF Computer Graphics Laboratory.  All rights reserved.
	X *	Freely redistributable.
	X *
	X *	window-position:  by Greg Couch, gregc@cgl.ucsf.edu, July 1989.
	X *
	X *		Generate random window postions.
	X */
	X
	X# include	<stdio.h>
	X# include	<stdlib.h>
	X# include	<string.h>
	X# include	<nextdev/video.h>
	X
	Xextern	int	getpid(void);
	Xextern	int	getopt(int, char **, char *), optind;
	Xextern	char	*optarg;
	X
	Xvoid
	Xmain(argc, argv)
	X	int	argc;
	X	char	*argv[];
	X{
	X	int	c;
	X	int	along_line;
	X	int	h, v;
	X	double	t;
	X	int	lowerH, upperH, lowerV, upperV;
	X	char	*invoked_as;
	X
	X	if (argc <= 0) {
	X		invoked_as = "???";
	X		goto usage;
	X	}
	X
	X	if ((invoked_as = strrchr(argv[0], '/')) != NULL)
	X		invoked_as += 1;
	X	else
	X		invoked_as = argv[0];
	X
	X	along_line = 0;
	X	while ((c = getopt(argc, argv, "l")) != EOF) switch (c) {
	X
	X	case 'l':
	X		along_line = 1;
	X		break;
	X
	X	default:
	X		goto usage;
	X	}
	X
	X	if (optind + 4 != argc) {
	Xusage:
	X		(void) fprintf(stderr,
	X				"usage: %s [-l] lowerH upperH lowerV upperV\n",
	X				invoked_as);
	X		exit(1);
	X	}
	X
	X	lowerH = atoi(argv[optind + 0]);
	X	upperH = atoi(argv[optind + 1]);
	X	lowerV = atoi(argv[optind + 2]);
	X	upperV = atoi(argv[optind + 3]);
	X
	X	if (lowerH < 0 || lowerH > VIDEO_W
	X	|| upperH < 0 || upperH > VIDEO_W
	X	|| lowerV < 0 || lowerV > VIDEO_H
	X	|| upperV < 0 || upperV > VIDEO_H) {
	X		(void) fprintf(stderr,
	X			"%s: bounds must be between (0, 0) and (%d, %d)\n",
	X			invoked_as, VIDEO_W, VIDEO_H);
	X		exit(1);
	X	}
	X
	X	srand(getpid());
	X	t = rand() / (double) RAND_MAX;
	X	h = lowerH + t * (upperH - lowerH) + .5;
	X	if (!along_line)
	X		t = rand() / (double) RAND_MAX;
	X	v = lowerV + t * (upperV - lowerV) + .5;
	X	printf("-WinLocH %d -WinLocV %d\n", h, v);
	X	exit(0);
	X}
SHAR_EOF
if test 1783 -ne "`wc -c < 'window-position.c'`"
then
	echo shar: "error transmitting 'window-position.c'" '(should have been 1783 characters)'
fi
fi
echo shar: "extracting 'Pseudo.1'" '(2375 characters)'
if test -f 'Pseudo.1'
then
	echo shar: "will not over-write existing file 'Pseudo.1'"
else
sed 's/^	X//' << \SHAR_EOF > 'Pseudo.1'
	X.\"	$Id: Pseudo.1,v 1.2 89/07/11 16:50:43 gregc Exp $
	X.\"	Copyright 1989 by the Regents of the University of California and
	X.\"	the UCSF Computer Graphics Laboratory.  All rights reserved.
	X.\"	Freely redistributable.
	X.TH PSEUDO 1 "10 July 1989" "LOCAL"
	X.SH NAME
	XPseudo \- a fake application to customize instances of applications
	X.SH SYNOPSIS
	Xln -s /LocalApps/Pseudo ~/Apps/NewName
	X.sp
	XNewName
	X.RI [ "Arguments to pass to Application" ]
	X.SH DESCRIPTION
	XOne of the main design features of the NeXTStep Workspace manager
	Xand NeXT defaults database is that you can't specify command line
	Xarguments to applications invoked via the dock or the directory
	Xbrowser.
	XThis is especially important if you wish to autostart
	Xmore than one terminal emulator
	Xwithout them appearing in the same place, same font, same ....
	X.PP
	XThe
	X.I Pseudo
	Xapplication
	Xadds command line arguments to other applications by adding another
	Xlayer to their invocation.
	XAny command line arguments it receives are passed unaltered to the
	Xreal application.
	X.PP
	XTo find out which application to run
	Xand the set of arguments to use, it checks the name that it was
	Xinvoked with and uses that as the application name for finding
	Xvariables in the defaults database.
	XThe variables are used to construct the following command line
	Xto invoke the real application:
	X.sp
	X	\f2Shell\fP -c "exec \f2Application\fP command-line-args \f2Args\fP"
	X.SH "DEFAULTS VARIABLES"
	XThe
	X.I Application
	Xvariable is the name of the application to invoke.
	X.PP
	XThe
	X.I Args
	Xvariable is an argument string for the application.
	X.PP
	XThe
	X.I Shell
	Xvariable is the shell to pass the command to (the default is your SHELL
	Xenvironment variable \(em or the Workspace's).
	X.SH EXAMPLE #1
	X.nf
	X% ln -s /LocalApps/Pseudo ~/Apps/myterm
	X% dwrite myterm Application /NextApps/Terminal
	X% dwrite myterm Args "-Lines 40 -FontSize 14 -WinLocH 0 -WinLocV 152"
	X% rehash # if using csh
	X% myterm
	X.SH EXAMPLE #2
	X.nf
	X% ln -s /LocalApps/Pseudo ~/Apps/myterm
	X% dwrite Application /NextApps/Terminal
	X% dwrite myterm Args "-Lines 40 -FontSize 14 `window-position -l 0 369 152 0`"
	X% rehash # if using csh
	X% myterm & ; myterm &
	X.fi
	X.SH FILES
	X.IP "/bin/sh" 3i
	XDefault shell
	X.SH "SEE ALSO"
	Xwindow-position(local),
	Xdwrite(1),
	Xsyslogd(1)
	X.SH AUTHOR
	XGreg Couch, gregc@cgl.ucsf.edu
	X.SH DIAGNOSTICS
	XErrors are logged via syslog(3) with the
	X.I user
	Xfacility.
	X.SH BUGS
	XNeeds a spiffy icon.
SHAR_EOF
if test 2375 -ne "`wc -c < 'Pseudo.1'`"
then
	echo shar: "error transmitting 'Pseudo.1'" '(should have been 2375 characters)'
fi
fi
echo shar: "extracting 'window-position.1'" '(873 characters)'
if test -f 'window-position.1'
then
	echo shar: "will not over-write existing file 'window-position.1'"
else
sed 's/^	X//' << \SHAR_EOF > 'window-position.1'
	X.\"	$Id: window-position.1,v 1.3 89/07/11 16:50:44 gregc Exp $
	X.\"	Copyright 1989 by the Regents of the University of California and
	X.\"	the UCSF Computer Graphics Laboratory.  All rights reserved.
	X.\"	Freely redistributable.
	X.TH WINDOW-POSITION 1 "10 July 1989" "LOCAL"
	X.SH NAME
	Xwindow-position \- generate a random window position
	X.SH SYNOPSIS
	Xwindow-position
	X.RI [ \-l ]
	XlowerH upperH lowerV upperV
	X.SH DESCRIPTION
	X.I window-position
	Xgenerates a random window postion acceptable as command line input to
	Xthe
	X.IR Terminal (1)
	Xapplication.
	X.PP
	XThe horizontal position is between
	X.I lowerH
	Xand
	X.I upperH
	Xinclusive.
	X.PP
	XThe vertical position is between
	X.I upperH
	Xand
	X.I upperH
	Xinclusive.
	X.PP
	XIf the
	X.B \-l
	Xoption is given,
	Xthe output is along the line (lowerH, lowerV) to (upperH, upperV).
	X.SH "SEE ALSO"
	XTerminal(1),
	XPseudo(local)
	X.SH AUTHOR
	XGreg Couch, gregc@cgl.ucsf.edu
SHAR_EOF
if test 873 -ne "`wc -c < 'window-position.1'`"
then
	echo shar: "error transmitting 'window-position.1'" '(should have been 873 characters)'
fi
fi
echo shar: "extracting 'Pseudo.iconheader'" '(18 characters)'
if test -f 'Pseudo.iconheader'
then
	echo shar: "will not over-write existing file 'Pseudo.iconheader'"
else
sed 's/^	X//' << \SHAR_EOF > 'Pseudo.iconheader'
	XF	Pseudo	Pseudo	0
SHAR_EOF
if test 18 -ne "`wc -c < 'Pseudo.iconheader'`"
then
	echo shar: "error transmitting 'Pseudo.iconheader'" '(should have been 18 characters)'
fi
fi
exit 0
#	End of shell archive