[comp.windows.x] Question re: scrolling AsciiText widgets.

leei@lightning.McRCIM.McGill.EDU (Lee Iverson) (05/24/91)

Below you'll find the first pass at a package which I've found quite
useful for managing error output from X applications.   If the
stderrNotifier() is called from an application (and the notifier
application is built and installed), then any messages written to
stderr by the application will popup in a window controlled by the
notifier process!  This is clean, simple and immensely useful, however
I'm waiting on a full release for one simple reason... I can't seem to
figure out how to get the Text widget to automatically scrollto the
just added text.

Ideally, this would likely involve a piece of code inserted just after
the XtPopup() in this fragment of main():

	    if ( len != prev_len ) {
		XtVaSetValues( text, XtNstring, str, XtNlength, len, NULL );
		if ( !initialized ) {
		    CenterWidgetUnderPointer(shell);
		    initialized = True;
		}
		if ( !popped_up ) XtPopup(shell,XtGrabNone);
		popped_up = True;
		/* Position scrollbars to display new text... How? */
		XBell(display,50);
	    } else {
	    ...

If anyone has any clues, I'd appreciate all the help I can get on this
one.  It should be simple, but the Athena Xaw docs give me no real
clues.

--
Lee Iverson			McGill Research Centre for Intelligent Machines
leei@mcrcim.mcgill.edu		Computer Vision and Robotics Lab
				McGill University, Montreal

----------
#! /bin/sh
#
# Shar: Shell Archiver
#
# This archive created Fri May 24 10:19:41 1991
# Run this through sh to create:
#	Imakefile
#	Makefile
#	Notifier.ad
#	Notifier.ad.h
#	notifier.c
#	notifier.h
#	stderr_notifier.c
echo x - Imakefile \(1932 characters\)
sed 's/^X//' > Imakefile << \EOF
X#
X#  Copyright 1991 McGill University
X#
X#  Permission to use, copy, modify, and distribute this software and its
X#  documentation for any purpose without fee is hereby granted without fee,
X#  provided that the above copyright notice appear in all copies and that
X#  both that copyright notice and this permission notice appear in
X#  supporting documentation, and that the name of McGill not be used in
X#  advertising or publicity pertaining to distribution of the software
X#  without specific, written prior permission.  McGill makes no
X#  representations about the suitability of this software for any purpose.
X#  It is provided "as is" without express or implied warranty.
X#
X#  MCGILL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
X#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
X#  BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
X#  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
X#  OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
X#  CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
X#
X#  Author:
X#    Lee Iverson <leei@mcrcim.mcgill.edu>,
X#    McGill Research Centre for Intelligent Machines (McRCIM)
X#
X#  $Id: Imakefile,v 0.7.1.7 1991/05/24 12:39:37 leei Exp $
X#
X
XDEBUG = UDEBUG
XAR = ar rv
X
X# Include these lines if you are using GCC.
X# Remember this needs an ANSI compiler!
XCC = gcc -pipe
XCDEBUGFLAGS = $(DBG) $(OPT) $(DEFS)
XOPT = -O -fstrength-reduce -fdelayed-branch
XDBG =
XDEFS = -$(DEBUG) $(BITMAPS)
XBITMAPS = -DBITMAPDIR=\"$(INCDIR)/bitmaps\" -DPIXMAPDIR=\"$(INCDIR)/pixmaps\"
X
XINCLUDES = -I.
XLOCAL_LIBRARIES = XawClientLibs
XDEPLIBS = XawClientDepLibs
X
XPROGRAMS = notifier
X
XSRCS = notifier.c
XOBJS = notifier.o
X
XComplexProgramTarget(notifier)
X
XInstallAppDefaults(Notifier)
X
XNotifier.ad.h: Notifier.ad
X	ad2c Notifier.ad > Notifier.ad.h
X
XWorld:
X	make Makefile
X	make depend
X	make all
X
EOF
if test 1932 -ne "`wc -c Imakefile`"
then
echo shar: error transmitting Imakefile \(should have been 1932 characters\)
fi
echo x - Makefile \(10430 characters\)
sed 's/^X//' > Makefile << \EOF
X# Makefile generated by imake - do not edit!
X# $XConsortium: imake.c,v 1.51 89/12/12 12:37:30 jim Exp $
X
X###########################################################################
X# Makefile generated from "Imake.tmpl" and </tmp/IIf.a02037>
X# $XConsortium: Imake.tmpl,v 1.77 89/12/18 17:01:37 jim Exp $
X#
X# Platform-specific parameters may be set in the appropriate .cf
X# configuration files.  Site-wide parameters may be set in the file
X# site.def.  Full rebuilds are recommended if any parameters are changed.
X#
X# If your C preprocessor doesn't define any unique symbols, you'll need
X# to set BOOTSTRAPCFLAGS when rebuilding imake (usually when doing
X# "make Makefile", "make Makefiles", or "make World").
X#
X# If you absolutely can't get imake to work, you'll need to set the
X# variables at the top of each Makefile as well as the dependencies at the
X# bottom (makedepend will do this automatically).
X#
X
X###########################################################################
X# platform-specific configuration parameters - edit ultrix.cf to change
X
X# platform:  $XConsortium: ultrix.cf,v 1.20 89/12/22 15:56:14 rws Exp $
X# operating system:             Ultrix 4.0
X
X###########################################################################
X# site-specific configuration parameters - edit site.def to change
X
X# site:  $XConsortium: site.def,v 1.21 89/12/06 11:46:50 jim Exp $
X
X            SHELL = 	/bin/sh
X
X              TOP = .
X      CURRENT_DIR = .
X
X               AR = ar cq
X  BOOTSTRAPCFLAGS =
X               CC = gcc -fpcc-struct-return -fwritable-strings
X
X         COMPRESS = compress
X              CPP = /lib/cpp $(STD_CPP_DEFINES)
X    PREPROCESSCMD = gcc -fpcc-struct-return -fwritable-strings -E $(STD_CPP_DEFINES)
X          INSTALL = install
X               LD = ld
X             LINT = lint
X      LINTLIBFLAG = -C
X         LINTOPTS = -axz
X               LN = ln -s
X             MAKE = 	/bin/make
X               MV = mv
X               CP = cp
X           RANLIB = ranlib
X  RANLIBINSTFLAGS = -t
X               RM = rm -f
X     STD_INCLUDES = -I$(INCROOT)
X  STD_CPP_DEFINES =
X      STD_DEFINES =
X EXTRA_LOAD_FLAGS = -L$(USRLIBDIR)
X  EXTRA_LIBRARIES =
X             TAGS = ctags
X
X    PROTO_DEFINES =
X
X     INSTPGMFLAGS =
X
X     INSTBINFLAGS = -m 0755
X     INSTUIDFLAGS = -m 4755
X     INSTLIBFLAGS = -m 0664
X     INSTINCFLAGS = -m 0444
X     INSTMANFLAGS = -m 0444
X     INSTDATFLAGS = -m 0444
X    INSTKMEMFLAGS = -m 4755
X
X          DESTDIR =
X
X     TOP_INCLUDES = -I$(INCROOT)
X
X      CDEBUGFLAGS = -O -fstrength-reduce -finline-functions -fcombine-regs -fdelayed-branch
X        CCOPTIONS = -pipe
X      COMPATFLAGS =
X
X      ALLINCLUDES = $(STD_INCLUDES) $(TOP_INCLUDES) $(INCLUDES) $(EXTRA_INCLUDES)
X       ALLDEFINES = $(ALLINCLUDES) $(STD_DEFINES) $(PROTO_DEFINES) $(DEFINES) $(COMPATFLAGS)
X           CFLAGS = $(CDEBUGFLAGS) $(CCOPTIONS) $(ALLDEFINES)
X        LINTFLAGS = $(LINTOPTS) -DLINT $(ALLDEFINES)
X           LDLIBS = $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
X        LDOPTIONS = $(CDEBUGFLAGS) $(CCOPTIONS)
X   LDCOMBINEFLAGS = -X -r
X
X        MACROFILE = ultrix.cf
X           RM_CMD = $(RM) *.CKP *.ln *.BAK *.bak *.o core errs ,* *~ *.a .emacs_* tags TAGS make.log MakeOut
X
X    IMAKE_DEFINES =
X
X         IRULESRC = $(CONFIGDIR)
X        IMAKE_CMD = $(IMAKE) -DUseInstalled -I$(IRULESRC) $(IMAKE_DEFINES)
X
X     ICONFIGFILES = $(IRULESRC)/Imake.tmpl $(IRULESRC)/Imake.rules \
X			$(IRULESRC)/Project.tmpl $(IRULESRC)/site.def \
X			$(IRULESRC)/$(MACROFILE) $(EXTRA_ICONFIGFILES)
X
X###########################################################################
X# X Window System Build Parameters
X# $XConsortium: Project.tmpl,v 1.63 89/12/18 16:46:44 jim Exp $
X
X###########################################################################
X# X Window System make variables; this need to be coordinated with rules
X# $XConsortium: Project.tmpl,v 1.63 89/12/18 16:46:44 jim Exp $
X
X          PATHSEP = /
X        USRLIBDIR = /usr/lib
X           BINDIR = /local/bin
X          INCROOT = /local/include
X     BUILDINCROOT = $(TOP)
X      BUILDINCDIR = $(BUILDINCROOT)/X11
X      BUILDINCTOP = ..
X           INCDIR = $(INCROOT)/X11
X           ADMDIR = $(DESTDIR)/usr/adm
X           LIBDIR = /usr/lib/X11
X        CONFIGDIR = $(LIBDIR)/config
X       LINTLIBDIR = $(USRLIBDIR)/lint
X
X          FONTDIR = $(LIBDIR)/fonts
X         XINITDIR = $(LIBDIR)/xinit
X           XDMDIR = $(LIBDIR)/xdm
X           AWMDIR = $(LIBDIR)/awm
X           TWMDIR = $(LIBDIR)/twm
X           GWMDIR = $(LIBDIR)/gwm
X          MANPATH = $(DESTDIR)/local/man
X    MANSOURCEPATH = $(MANPATH)/man
X           MANDIR = $(MANSOURCEPATH)1
X        LIBMANDIR = $(MANSOURCEPATH)3
X      XAPPLOADDIR = $(LIBDIR)/app-defaults
X
X       FONTCFLAGS = -t
X
X     INSTAPPFLAGS = $(INSTDATFLAGS)
X
X            IMAKE = imake
X           DEPEND = makedepend
X              RGB = rgb
X            FONTC = bdftosnf
X        MKFONTDIR = mkfontdir
X        MKDIRHIER = 	/bin/sh $(BINDIR)/mkdirhier.sh
X
X        CONFIGSRC = $(TOP)/config
X        CLIENTSRC = $(TOP)/clients
X          DEMOSRC = $(TOP)/demos
X           LIBSRC = $(TOP)/lib
X          FONTSRC = $(TOP)/fonts
X       INCLUDESRC = $(TOP)/X11
X        SERVERSRC = $(TOP)/server
X          UTILSRC = $(TOP)/util
X        SCRIPTSRC = $(UTILSRC)/scripts
X       EXAMPLESRC = $(TOP)/examples
X       CONTRIBSRC = $(TOP)/../contrib
X           DOCSRC = $(TOP)/doc
X           RGBSRC = $(TOP)/rgb
X        DEPENDSRC = $(UTILSRC)/makedepend
X         IMAKESRC = $(CONFIGSRC)
X         XAUTHSRC = $(LIBSRC)/Xau
X          XLIBSRC = $(LIBSRC)/X
X           XMUSRC = $(LIBSRC)/Xmu
X       TOOLKITSRC = $(LIBSRC)/Xt
X       AWIDGETSRC = $(LIBSRC)/Xaw
X       OLDXLIBSRC = $(LIBSRC)/oldX
X      XDMCPLIBSRC = $(LIBSRC)/Xdmcp
X      BDFTOSNFSRC = $(FONTSRC)/bdftosnf
X     MKFONTDIRSRC = $(FONTSRC)/mkfontdir
X     EXTENSIONSRC = $(TOP)/extensions
X
X  DEPEXTENSIONLIB =  $(USRLIBDIR)/libXext.a
X     EXTENSIONLIB = 			  -lXext
X
X          DEPXLIB = $(DEPEXTENSIONLIB)  $(USRLIBDIR)/libX11.a
X             XLIB = $(EXTENSIONLIB) 			  -lX11
X
X      DEPXAUTHLIB =  $(USRLIBDIR)/libXau.a
X         XAUTHLIB = 			  -lXau
X
X        DEPXMULIB =  $(USRLIBDIR)/libXmu.a
X           XMULIB = 			  -lXmu
X
X       DEPOLDXLIB =  $(USRLIBDIR)/liboldX.a
X          OLDXLIB = 			  -loldX
X
X      DEPXTOOLLIB =  $(USRLIBDIR)/libXt.a
X         XTOOLLIB = 			  -lXt
X
X        DEPXAWLIB =  $(USRLIBDIR)/libXaw.a
X           XAWLIB = 			  -lXaw
X
X LINTEXTENSIONLIB =  $(USRLIBDIR)/llib-lXext.ln
X         LINTXLIB =  $(USRLIBDIR)/llib-lX11.ln
X          LINTXMU =  $(USRLIBDIR)/llib-lXmu.ln
X        LINTXTOOL =  $(USRLIBDIR)/llib-lXt.ln
X          LINTXAW =  $(USRLIBDIR)/llib-lXaw.ln
X
X          DEPLIBS = $(LOCAL_LIBRARIES)
X
X         DEPLIBS1 = $(DEPLIBS)
X         DEPLIBS2 = $(DEPLIBS)
X         DEPLIBS3 = $(DEPLIBS)
X
X###########################################################################
X# Imake rules for building libraries, programs, scripts, and data files
X# rules:  $XConsortium: Imake.rules,v 1.67 89/12/18 17:14:15 jim Exp $
X
X###########################################################################
X# start of Imakefile
X
X#
X#  Copyright 1991 McGill University
X#
X#  Permission to use, copy, modify, and distribute this software and its
X#  documentation for any purpose without fee is hereby granted without fee,
X#  provided that the above copyright notice appear in all copies and that
X#  both that copyright notice and this permission notice appear in
X#  supporting documentation, and that the name of McGill not be used in
X#  advertising or publicity pertaining to distribution of the software
X#  without specific, written prior permission.  McGill makes no
X#  representations about the suitability of this software for any purpose.
X#  It is provided "as is" without express or implied warranty.
X#
X#  MCGILL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
X#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN 0 EVENT SHALL M.I.T.
X#  BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
X#  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
X#  OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
X#  CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
X#
X#  Author:
X#    Lee Iverson <leei@mcrcim.mcgill.edu>,
X#    McGill Research Centre for Intelligent Machines (McRCIM)
X#
X#  $Id: Imakefile,v 0.7.1.7 1991/05/24 12:39:37 leei Exp $
X#
X
XDEBUG = UDEBUG
XAR = ar rv
X
X# Include these lines if you are using GCC.
X# Remember this needs an ANSI compiler!
XCC = gcc -pipe
XCDEBUGFLAGS = $(DBG) $(OPT) $(DEFS)
XOPT = -O -fstrength-reduce -fdelayed-branch
XDBG =
XDEFS = -$(DEBUG) $(BITMAPS)
XBITMAPS = -DBITMAPDIR=\"$(INCDIR)/bitmaps\" -DPIXMAPDIR=\"$(INCDIR)/pixmaps\"
X
XINCLUDES = -I.
XLOCAL_LIBRARIES = $(XAWLIB) $(XMULIB) $(XTOOLLIB) $(XLIB)
XDEPLIBS = $(DEPXAWLIB) $(DEPXMULIB) $(DEPXTOOLLIB) $(DEPXLIB)
X
XPROGRAMS = notifier
X
XSRCS = notifier.c
XOBJS = notifier.o
X
X        PROGRAM = notifier
X
Xall:: notifier
X
Xnotifier: $(OBJS) $(DEPLIBS)
X	 $(RM) $@
X	$(CC) -o $@ $(OBJS) $(LDOPTIONS) $(LOCAL_LIBRARIES) $(LDLIBS) $(EXTRA_LOAD_FLAGS)
X
Xinstall:: notifier
X	$(INSTALL) -c $(INSTPGMFLAGS)   notifier $(BINDIR)
X
Xinstall.man:: notifier.man
X	$(INSTALL) -c $(INSTMANFLAGS) notifier.man $(MANDIR)/notifier.1
X
Xdepend::
X	$(DEPEND) -s "# DO NOT DELETE" -- $(ALLDEFINES) -- $(SRCS)
X
Xlint:
X	$(LINT) $(LINTFLAGS) $(SRCS) $(LINTLIBS)
Xlint1:
X	$(LINT) $(LINTFLAGS) $(FILE) $(LINTLIBS)
X
Xclean::
X	$(RM) $(PROGRAM)
X
Xinstall:: Notifier.ad
X	$(INSTALL) -c $(INSTAPPFLAGS) Notifier.ad $(XAPPLOADDIR)/Notifier
X
XNotifier.ad.h: Notifier.ad
X	ad2c Notifier.ad > Notifier.ad.h
X
XWorld:
X	make Makefile
X	make depend
X	make all
X
X###########################################################################
X# common rules for all Makefiles - do not edit
X
Xemptyrule::
X
Xclean::
X	$(RM_CMD) \#*
X
XMakefile::
X	-@if [ -f Makefile ]; then \
X		echo "	$(RM) Makefile.bak; $(MV) Makefile Makefile.bak"; \
X		$(RM) Makefile.bak; $(MV) Makefile Makefile.bak; \
X	else exit 0; fi
X	$(IMAKE_CMD) -DTOPDIR=$(TOP) -DCURDIR=$(CURRENT_DIR)
X
Xtags::
X	$(TAGS) -w *.[ch]
X	$(TAGS) -xw *.[ch] > TAGS
X
X###########################################################################
X# empty rules for directories that do not have SUBDIRS - do not edit
X
Xinstall::
X	@echo "install in $(CURRENT_DIR) done"
X
Xinstall.man::
X	@echo "install.man in $(CURRENT_DIR) done"
X
XMakefiles::
X
Xincludes::
X
X###########################################################################
X# dependencies generated by makedepend
X
EOF
if test 10430 -ne "`wc -c Makefile`"
then
echo shar: error transmitting Makefile \(should have been 10430 characters\)
fi
echo x - Notifier.ad \(923 characters\)
sed 's/^X//' > Notifier.ad << \EOF
XNotifier*BorderWidth: 0
XNotifier*Command.ShapeStyle: Oval
XNotifier*Command.BorderWidth: 3
X
XNotifier*shell.allowShellResize: True
X
XNotifier*form.title.borderWidth: 0
XNotifier*form.title.top: ChainTop
XNotifier*form.title.bottom: ChainTop
XNotifier*form.title.left: ChainLeft
XNotifier*form.title.right: ChainRight
X
XNotifier*form.text.height: 100
XNotifier*form.text.width: 300
XNotifier*form.text.scrollVertical: Always
XNotifier*form.text.scrollHorizontal: WhenNeeded
XNotifier*form.text.editType: read
XNotifier*form.text.fromVert: title
XNotifier*form.text.top: ChainTop
XNotifier*form.text.bottom: ChainBottom
XNotifier*form.text.left: ChainLeft
XNotifier*form.text.right: ChainRight
X
XNotifier*form.hideButton.label: Hide
XNotifier*form.hideButton.fromVert: text
XNotifier*form.hideButton.top: ChainBottom
XNotifier*form.hideButton.bottom: ChainBottom
XNotifier*form.hideButton.left: ChainLeft
XNotifier*form.hideButton.right: ChainLeft
EOF
if test 923 -ne "`wc -c Notifier.ad`"
then
echo shar: error transmitting Notifier.ad \(should have been 923 characters\)
fi
echo x - Notifier.ad.h \(861 characters\)
sed 's/^X//' > Notifier.ad.h << \EOF
X"*BorderWidth: 0",
X"*MenuButton.BorderWidth: 1",
X"*MenuButton.ShapeStyle: Rectangle",
X"*Command.ShapeStyle: Oval",
X"*Command.BorderWidth: 3",
X"*shell.allowShellResize: True",
X"*form.title.borderWidth: 0",
X"*form.title.top: ChainTop",
X"*form.title.bottom: ChainTop",
X"*form.title.left: ChainLeft",
X"*form.title.right: ChainRight",
X"*form.text.height: 100",
X"*form.text.width: 300",
X"*form.text.scrollVertical: Always",
X"*form.text.scrollHorizontal: WhenNeeded",
X"*form.text.editType: read",
X"*form.text.fromVert: title",
X"*form.text.top: ChainTop",
X"*form.text.bottom: ChainBottom",
X"*form.text.left: ChainLeft",
X"*form.text.right: ChainRight",
X"*form.hideButton.label: Hide",
X"*form.hideButton.fromVert: text",
X"*form.hideButton.top: ChainBottom",
X"*form.hideButton.bottom: ChainBottom",
X"*form.hideButton.left: ChainLeft",
X"*form.hideButton.right: ChainLeft",
EOF
if test 861 -ne "`wc -c Notifier.ad.h`"
then
echo shar: error transmitting Notifier.ad.h \(should have been 861 characters\)
fi
echo x - notifier.c \(5486 characters\)
sed 's/^X//' > notifier.c << \EOF
X/******************************************************************************
X
X   Copyright 1991 McGill University
X
X   Permission to use, copy, modify, and distribute this software and its
X   documentation for any purpose without fee is hereby granted without fee,
X   provided that the above copyright notice appear in all copies and that
X   both that copyright notice and this permission notice appear in
X   supporting documentation, and that the name of McGill not be used in
X   advertising or publicity pertaining to distribution of the software
X   without specific, written prior permission.  McGill makes no
X   representations about the suitability of this software for any purpose.
X   It is provided "as is" without express or implied warranty.
X
X   MCGILL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
X   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
X   BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
X   WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
X   OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
X   CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
X
X   Author:
X     Lee Iverson <leei@mcrcim.mcgill.edu>,
X     McGill Research Centre for Intelligent Machines (McRCIM)
X
X******************************************************************************/
X
Xstatic char RCSid[] = "$Id: notifier.c,v 0.7.1.1 1991/05/24 12:28:20 leei Exp $";
X
X#include <stdio.h>
X#include <stdlib.h>
X#include <errno.h>
X#include <fcntl.h>
X
X#include <sys/types.h>
X
X#include <X11/Intrinsic.h>
X#include <X11/StringDefs.h>
X
X#include <X11/Shell.h>
X
X#include <X11/Xaw/Form.h>
X#include <X11/Xaw/AsciiText.h>
X#include <X11/Xaw/Command.h>
X
X/*
X *	Widget and non-widget resources if the application defaults
X *	file can't be found.
X *	[ Generated automatically from Notifier.ad. ]
X */
Xstatic String fallbackResources[] = {
X#include "Notifier.ad.h"
X	NULL
X};
X
XBoolean stdin_open = True;
XBoolean popped_up = False;
X
Xstatic void
XHide( Widget w, XtPointer client_data, XtPointer call_data )
X{
X    if ( stdin_open ) {
X	XtPopdown((Widget)client_data);
X	XSync(XtDisplay(w),False);
X	popped_up = False;
X    } else {
X	exit(0);
X    }
X}
X
Xvoid CenterWidgetUnderPointer();
XBoolean WaitForXOrStdin();
X
Xmain(argc,argv)
XCardinal argc;
XString *argv;
X{
X    XtAppContext app_context;
X    Widget toplevel, shell, text, hide;
X    Display *display;
X    int len = 0;
X    char *str = 0;
X    int flags;
X    Boolean initialized = False;
X
X    /* Make sure that input on stdin is non-blocking. */
X    toplevel = XtVaAppInitialize( &app_context, "Notifier",
X				  NULL, 0,
X				  &argc, argv,
X				  fallbackResources,
X				  NULL );
X    shell = XtVaCreatePopupShell( "shell", transientShellWidgetClass, toplevel,
X				 NULL );
X
X    {
X	Widget form, title;
X
X	form = 
X	  XtVaCreateManagedWidget("form", formWidgetClass, shell, 
X				  NULL);
X
X	title =
X	  XtVaCreateManagedWidget( "title", labelWidgetClass, form,
X				  XtNlabel, argv[0],
X				  NULL );
X	text =
X	  XtVaCreateManagedWidget( "text", asciiTextWidgetClass, form,
X				  XtNtype, XawAsciiString,
X				  /* XtNuseStringInPlace, True, /**/
X				  NULL);
X
X	hide = 
X	  XtVaCreateManagedWidget( "hideButton", commandWidgetClass, form,
X				  NULL);
X
X	XtAddCallback( hide, XtNcallback, Hide, shell);
X    }
X
X    XtRealizeWidget(shell);
X    display = XtDisplay(shell);
X
X    /* Make sure stdin is set up for non-blocking input. */
X    flags = fcntl( 0, F_GETFL, 0 );
X    fcntl( 0, F_SETFL, flags | FNDELAY );
X
X    while ( True ) {
X	XEvent event;
X
X	if ( WaitForXOrStdin(display,stdin_open) ) {
X	    int prev_len = len, n; 
X	    char buf[BUFSIZ];
X
X	    /* Copy data from stdin to Text widget. */
X	    while ( (n = read(0,buf,BUFSIZ)) > 0 ) {
X		char *newstr = malloc(len+n+1);
X		if ( str ) {
X		    bcopy(str,newstr,len);
X		    free(str);
X		}
X		bcopy(buf,newstr+len,n);
X		newstr[len+n] = '\0';
X		str = newstr; len += n;
X	    }
X
X	    if ( len != prev_len ) {
X		XtVaSetValues( text, XtNstring, str, XtNlength, len, NULL );
X		if ( !initialized ) {
X		    CenterWidgetUnderPointer(shell);
X		    initialized = True;
X		}
X		if ( !popped_up ) XtPopup(shell,XtGrabNone);
X		popped_up = True;
X		XBell(display,50);
X	    } else {
X		if ( !popped_up ) exit(0);
X		XtVaSetValues( hide, XtNlabel, "Quit", NULL );
X		stdin_open = False;
X	    }
X	}
X
X	while ( XtAppPending(app_context) ) {
X	    XtAppNextEvent(app_context,&event);
X	    XtDispatchEvent(&event);
X	}
X    }
X}
X
X/* Centre the widget over the pointer. */
Xvoid
XCenterWidgetUnderPointer(w)
XWidget w;
X{
X    Dimension width, height;
X    Window r, c;
X    int rx, ry, cx, cy;
X    Position x, y;
X    unsigned int m;
X    
X    XtVaGetValues(w, XtNwidth, &width, XtNheight, &height, NULL); 
X    XQueryPointer(XtDisplay(w), XtWindow(w), &r,&c, &rx,&ry,&cx,&cy, &m);
X    x = rx-width/2;  if ( x < 0 ) x = 0;
X    y = ry-height/2; if ( y < 0 ) y = 0;
X    XtVaSetValues(w, XtNx, x, XtNy, y, NULL);
X}
X
X/* 
X * Blocks for input to either stdin or X connection. 
X * Returns True if stdin is available.
X */
XBoolean
XWaitForXOrStdin(dpy, use_stdin)
X  Display *dpy;
X  Boolean use_stdin;
X{
X    fd_set r_mask;
X    int result;
X
X    FD_ZERO(&r_mask);
X    do {
X        if ( use_stdin ) FD_SET(0, &r_mask); 	/* stdin */
X        FD_SET(dpy->fd, &r_mask);		/* display to X */
X        result = select(dpy->fd + 1, &r_mask, NULL, NULL, NULL);
X        if (result == -1 && errno != EINTR) _XIOError(dpy);
X    } while (result <= 0);
X    return FD_ISSET(0,&r_mask);
X}
EOF
if test 5486 -ne "`wc -c notifier.c`"
then
echo shar: error transmitting notifier.c \(should have been 5486 characters\)
fi
echo x - notifier.h \(1594 characters\)
sed 's/^X//' > notifier.h << \EOF
X/******************************************************************************
X
X   Copyright 1991 McGill University
X
X   Permission to use, copy, modify, and distribute this software and its
X   documentation for any purpose without fee is hereby granted without fee,
X   provided that the above copyright notice appear in all copies and that
X   both that copyright notice and this permission notice appear in
X   supporting documentation, and that the name of McGill not be used in
X   advertising or publicity pertaining to distribution of the software
X   without specific, written prior permission.  McGill makes no
X   representations about the suitability of this software for any purpose.
X   It is provided "as is" without express or implied warranty.
X
X   MCGILL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
X   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
X   BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
X   WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
X   OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
X   CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
X
X   Author:
X     Lee Iverson <leei@mcrcim.mcgill.edu>,
X     McGill Research Centre for Intelligent Machines (McRCIM)
X
X   $Id: notifier.h,v 0.7.1.1 1991/05/24 12:28:20 leei Exp $
X
X******************************************************************************/
X
X#ifndef _notifier_h_
X#define _notifier_h_
X
X#include <sys/wait.h>
X
Xpid_t stderrNotifier( char *name );
X
X#endif /* _notifier_h_ */
EOF
if test 1594 -ne "`wc -c notifier.h`"
then
echo shar: error transmitting notifier.h \(should have been 1594 characters\)
fi
echo x - stderr_notifier.c \(2183 characters\)
sed 's/^X//' > stderr_notifier.c << \EOF
X/******************************************************************************
X
X   Copyright 1991 McGill University
X
X   Permission to use, copy, modify, and distribute this software and its
X   documentation for any purpose without fee is hereby granted without fee,
X   provided that the above copyright notice appear in all copies and that
X   both that copyright notice and this permission notice appear in
X   supporting documentation, and that the name of McGill not be used in
X   advertising or publicity pertaining to distribution of the software
X   without specific, written prior permission.  McGill makes no
X   representations about the suitability of this software for any purpose.
X   It is provided "as is" without express or implied warranty.
X
X   MCGILL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
X   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
X   BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
X   WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
X   OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
X   CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
X
X   Author:
X     Lee Iverson <leei@mcrcim.mcgill.edu>,
X     McGill Research Centre for Intelligent Machines (McRCIM)
X
X******************************************************************************/
X
Xstatic char RCSid[] = "$Id: stderr_notifier.c,v 0.7.1.1 1991/05/24 12:28:20 leei Exp $";
X
X#include <stdio.h>
X#include <notifier.h>
X
Xpid_t
XstderrNotifier( char *name )
X{
X    pid_t pid;
X    int to_notifier[2];
X
X    if ( pipe(to_notifier) ) {
X	fprintf( stderr, "Failed to create pipe for notifier.\n" );
X	return;
X    }
X
X    if ( !(pid = vfork()) ) {
X	/* Exec notifier process and ... */
X	dup2( to_notifier[0], 0 ); /* Pipe -> stdin of notifier. */
X	close(to_notifier[0]); close(to_notifier[1]);
X	execlp( "notifier", name, 0 );
X	exit(1);
X    } else {
X	if ( waitpid( pid, WNOHANG ) != pid ) {
X	    /* Attach input end of pipe to stderr. */
X	    dup2( to_notifier[1], 2 ); /* Pipe <- stderr of process. */
X	    close(to_notifier[0]); close(to_notifier[1]);
X	}
X    }
X
X    return pid;
X}
EOF
if test 2183 -ne "`wc -c stderr_notifier.c`"
then
echo shar: error transmitting stderr_notifier.c \(should have been 2183 characters\)
fi
exit 0
# end of shell archive
-- 

Lee Iverson			McGill Research Centre for Intelligent Machines
leei@mcrcim.mcgill.edu		Computer Vision and Robotics Lab
				McGill University, Montreal