v01i064: torch: dialog utilities, Part03/04

Mike Wexler mikew at wyse.wyse.com
Thu Oct 13 04:41:37 AEST 1988


Submitted-by:  gary at torch.UUCP (Gary Henderson)
Posting-number: Volume 1, Issue 64
Archive-name: torch/part03

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 3 (of 4)."
# Contents:  gs.1 gs.c main.c misc.c textmode.c yorn.1
# Wrapped by mikew at wyse on Wed Oct 12 11:38:41 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'gs.1' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'gs.1'\"
else
echo shar: Extracting \"'gs.1'\" \(6048 characters\)
sed "s/^X//" >'gs.1' <<'END_OF_FILE'
X.TH GS 1 "3 October 1988" "X Version 11"
X.SH NAME
Xgs \- get a text string from a dialogue box
X.SH SYNOPSIS
X.B gs
X[
X.B \-z
X] [ 
X.B \-r width height
X] [
X.B \-t timeout
X] [
X.B \-n title
X] [
X.B \-standard X Toolkit options \.\.\.
X] [
X.B text to be displayed
X]
X.SH DESCRIPTION
X.I Gs
Xis a utility designed for use in shell scripts for obtaining short text
Xresponses from users.
X.PP
X.I Gs
Xopens a window containing a box to display the text passed on the command
Xline.  If the
X.B \-r
Xoption is present, another box is created into which the user may enter a
Xreply (the maximum number characters that may be entered is given by
X\fIwidth\fPx\fIheight\fP fields from the
X.B \-r
Xoption).  The reply box allows simple character editing (such as cursor
Xmovement, character insertion and deletion).  The window can be closed and any
Xtext typed by the user sent to standard output by clicking the `Finished'
Xbutton with the mouse.  The window is also closed and any text sent if a
Xtimeout has been specified (see the
X.B \-t
Xoption) and this has been exceeded.
X.PP
X.I Gs
Xcan take the following options:
X.TP 8
X.B \-z
XNo Zoom.  \fIGs\fP will attempt to bypass the window manager and appear
Ximmediately, rather than going through the window manager's placement and
Xsizing scheme.
X.PP
X.TP 8
X.B \-r \fIwidth\fP \fIheight\fP
XA reply box of \fIwidth\fP characters wide and \fIheight\fP characters high
Xwill be created (if the window manager or screen size allows).  The maximum
Xnumber of characters the user may enter is always \fIwidth\fPx\fIheight\fP
Xcharacters.  The text in the reply box may be scrolled if the box cannot be
Xmade large enough or lots of short lines have been entered.
X.TP 8
X.B \-n \fItitle\fP \fRor\fP \-title \fItitle\fP
XSpecifies the title for the \fIgs\fP window.  The default, if this option is
Xnot supplied, is `Get string'.
X.TP 8
X.B \-t \fInumber\fP
XSpecifies a timeout value (in seconds) in which the user must enter a reply.
XIf the time limit is exceeded, any text already typed will be sent to \fgs\fP'
Xstandard output and \fIgs\fP will exit.
X.PP
X\fIGs\fP additionally recognizes the following standard X Toolkit command
Xline arguments:
X.TP 8
X.B \-bg \fIcolour\fP \fRor\fP \-background \fIcolour\fP
XThis option specifies the colour to use for the background of the window and
Xwidgets.  The default is `white.'
X.TP 8
X.B \-bd \fIcolour\fP \fRor\fP \-bordercolor \fIcolour\fP
XThis option specifies the colour to use for the border of the main window.
XThe default is `black.'
X.TP 8
X.B \-bw \fInumber\fP \fRor\fP \-borderwidth \fInumber\fP
XThis option specifies the width in pixels of the border surrounding the main
Xwindow. 
X.TP 8
X.B \-fg \fIcolour\fP \fRor\fP \-foreground \fIcolour\fP
XThis option specifies the colour to use for the text.  The default
Xis `black'.
X.TP 8
X.B \-fn \fIfont\fP
XThis option specifies the font to be used for displaying the text warning
Xmessage.  The default is `serif10'.
X.TP 8
X.B \-name \fIname\fP
XThis option specifies the application name under which resources are to be
Xobtained, rather than the default executable file name, `gs'.
X.TP 8
X.B \-geometry \fIgeometry\fP
XThis option specifies the preferred size and position of the gs window; see
X\fIX(1)\fP; 
X.TP 8
X.B \-display \fIdisplay\fP
XThis option specifies the X server to contact; see \fIX(1)\fP.
X.TP 8
X.B \-xrm \fIresourcestring\fP
XThis option specifies a resource string to be used.  This is especially
Xuseful for setting resources that do not have separate command line options.
X.SH "X DEFAULTS"
X\fIGs\fP is implemented using the Athena widgets.  Each widget can
Xindividually or in groups have various visual and operational aspects changed
Xvia a `.Xdefaults' file on the client machine or the `RESOURCE_MANAGER'
Xproperty on the server.  All widgets have a common set of resources
X(background, backgroundPixmap, etc.) and resources unique to each type of
Xwidget; a `command button' widget, for example, also has a cursor resource.
XFor a full list see the document \fIX Toolkit Widgets - C Language X
XInterface\fP. 
X.PP
XThe path names and types of all widgets used by \fIgs\fP are as follows:
X.TP 8
X.B "\fIXXX\fP.gsbox"
XThe widget that is a child of root.  All the other widgets used by the gs
Xbox are children or grand children of this widget. 
X.TP 8
X.B "\fIXXX\fP.gsbox.contents"
XA form widget that manages the layout of the gs box.  Normally completely
Xcovers the `gsbox' widget.
X.TP 8
X.B "\fIXXX\fP.gsbox.contents.message"
XA widget to display and format the text message.
X.TP 8
X.B "\fIXXX\fP.gsbox.contents.Finished"
XA command button widget that when clicked causes \fIgs\fP to write any text
Xentered by the user to standard output and exit.
X.TP 8
X.B "\fIXXX\fP.gsbox.contents.reply"
XA text widget where the user can type a reply.
X.PP
XAdditionally, the following item is also fetched from the resource database:
X.TP 8
X.B "backgroundPixmap.foreground"
XOne of two colours (the other is the widget's background colour) required when
Xconverting a bitmap file into a pixmap for use as the widget's background
Xpixmap. 
X.SH RETURN CODES
X.IP
X0 \- Termination via the tick box or the timeout value being exceeded.
X.IP
X2 \- Termination due to some internal error.
X.SH ENVIRONMENT
X.TP 8
XDISPLAY - the default host and display number of the X server.
X.TP 8
XXENVIRONMENT - the name of the Xdefaults file to use (normally
X$HOME/.Xdefaults). 
X.SH EXAMPLES
X.IP
Xgs -r 40 1 Please enter the name of a file to edit
X.PP
XWill open an gs box with the title
X.I Get string
Xand containing a box displaying the text
X.I Please enter the name of a file to edit
Xand another box where the user may type upto 40 characters.
X.SH FILES
X$HOME/.Xdefaults
X/usr/lib/X11/app-defaults/Xopentop
X.SH SEE ALSO
Xalert(1), yorn(1)
X.SH BUGS
X.PP
XIf the font is too large or the message too long, the text will be clipped and
Xthe window will have to be scrolled before the whole message may be read.
X.PP
XThe title may not be displayed if the window manager does not provide title
Xbars around windows or the \fB\-z\fP option is used.
X.SH AUTHOR
XGary Henderson & Mark E. Howells, Torch Computers Ltd.
END_OF_FILE
if test 6048 -ne `wc -c <'gs.1'`; then
    echo shar: \"'gs.1'\" unpacked with wrong size!
fi
# end of 'gs.1'
fi
if test -f 'gs.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'gs.c'\"
else
echo shar: Extracting \"'gs.c'\" \(7594 characters\)
sed "s/^X//" >'gs.c' <<'END_OF_FILE'
X/*
XCopyright 1988 Torch Computers Ltd.
X
XPermission to use, copy, modify, and otherwise generally do what you like
Xwith this software is hereby granted provided that the above copyright notice
Xappears in all copies.
X
XTorch disclaims all warranties implied or expressed with regard to this
Xsoftware.  In no event shall Torch be liable for any damages arising from
Xthis use of software.
X*/
X
X/********************************************************
X*							*
X*  Title   Yorn, Gs and Alert				*
X*							*
X*  File	   : gs.c					*
X*  Author  : Gary Henderson				*
X*  Date	   : 29th Sep 1988				*
X*  Purpose : The gs box widgets code.	    	    	*
X*							*
X*********************************************************/
X
X/*------Include files-----------------------------------*/
X
X#include <stdio.h>
X#include <X11/Xlib.h>
X#include <X11/Xos.h>
X#include <X11/Xutil.h>
X#include <X11/StringDefs.h>
X#include <X11/Intrinsic.h>
X#include <X11/Form.h>
X#include <X11/Core.h>
X#include <X11/Shell.h>
X#include <X11/Command.h>
X#include <X11/AsciiText.h>
X
X/*------Forward delarations-----------------------------*/
X
Xextern long time ();
X
X/*------Constants and macros----------------------------*/
X
X#define ALONX 	    	((root_width / 5 + rand () % 48))
X#define ALONY 	    	((root_height / 5 + rand () % 48))
X#define MESSAGE_WIDTH	40
X#define EXTRA 6
X
X/*------Exported variables/functions--------------------*/
X
XWidget 	gswidget;
Xvoid 	Finished ();
X
X/*------Imported variables/functions--------------------*/
X
Xextern Widget 	    a_widget;
Xextern XFontStruct  *sysfont;
Xextern unsigned int root_width, root_height;
Xextern Display 	    *display;
Xextern Window 	    root_window;
Xextern int  	    screen_number;
Xextern Screen 	    *screen;
Xextern Boolean 	    zoom;
Xextern int  	    lines, cols;
Xextern char 	    *font_name;
X
X/*------Static variables--------------------------------*/
X
Xstatic Widget 	button;
Xstatic Widget 	textwidget;
Xstatic Widget 	messagewidget;
Xstatic char 	*data;
Xstatic int  	length;
X
X/*
X							*****************
X							*		*
X							*    INITGS	*
X							*		*
X							*****************
X-------------------------------------------------------------------------
X| Initialise the widgets for the gs box.    	    	    	    	|
X-------------------------------------------------------------------------
X*/
Xvoid InitGS (string, geometry)
Xchar * string;
Xchar * geometry;
X{
X    Arg args[20];
X    Widget formwidget;
X    int message_width, message_height;
X    int char_width = (sysfont->max_bounds.width + 
X    	    	      sysfont->min_bounds.width) / 2;
X    int char_height = (sysfont->ascent + sysfont->descent);
X    int mx_offset, tx_offset;
X    
X    static XtCallbackRec ackbacks[] = {
X    	{Finished, NULL},
X    	{NULL, NULL},
X    };
X
X#ifdef BSD
X    (void) srand ((int) time ((long *) 0));
X#endif BSD
X
X#if defined(UNISOFTV) || defined(SYSV)
X    (void) srand ((unsigned int) time ((long *) 0));
X#endif /* UNISOFTV || SYSV */
X
X    /* Its a popup */
X
X    XtSetArg (args[0], XtNx, ALONX);
X    XtSetArg (args[1], XtNy, ALONY);
X    XtSetArg (args[2], XtNgeometry, geometry);
X    
X    gswidget = XtCreatePopupShell ("gsbox", 
X    	    	    	    	    zoom ? topLevelShellWidgetClass :
X				    	   overrideShellWidgetClass, 
X				    a_widget,
X				    args,
X				    geometry ? 3 : 2);
X				    
X    formwidget= XtCreateManagedWidget ("contents",
X    	    	    	    	      formWidgetClass,
X				      gswidget,
X				      (ArgList) 0,
X				      0);
X
X    XtSetArg (args[0], XtNhorizDistance, 4);
X    XtSetArg (args[1], XtNvertDistance, 4);
X    XtSetArg (args[2], XtNresizable, False);
X    XtSetArg (args[3], XtNcallback, ackbacks);
X    XtSetArg (args[4], XtNfont, sysfont);
X    XtSetArg (args[5], XtNbottom, XtChainTop);
X    XtSetArg (args[6], XtNtop, XtChainTop);
X    XtSetArg (args[7], XtNleft, XtChainLeft);
X    XtSetArg (args[8], XtNright, XtChainLeft);
X    
X    button = XtCreateManagedWidget("Finished",
X    	    	    	    	    commandWidgetClass,
X				    formwidget,
X				    args,
X				    9);
X
X    message_height = char_height + EXTRA;
X
X    if (strlen (string) < MESSAGE_WIDTH)
X    	message_width = strlen (string) * char_width + EXTRA;
X    else
X    {
X    	message_width = MESSAGE_WIDTH * char_width + EXTRA;
X	message_height = char_height * (1 + strlen (string) / 
X	    	    	    	       MESSAGE_WIDTH) + EXTRA;
X    }
X
X    if (cols * lines != 0)
X    {
X    	if (cols * char_width + EXTRA > message_width)
X	{
X    	    mx_offset = ((cols * char_width + EXTRA) - message_width) / 2 + 4;
X	    tx_offset = 4;
X	}
X	else
X	{
X    	    mx_offset = 4;
X    	    tx_offset = (message_width - (cols * char_width + EXTRA)) / 2 + 4;
X	}
X    }
X    else
X    	mx_offset = 4;
X
X    XtSetArg (args[0], XtNhorizDistance, mx_offset);
X    XtSetArg (args[1], XtNvertDistance, 4);
X    XtSetArg (args[2], XtNresizable, True);
X    XtSetArg (args[3], XtNeditType, XttextRead);
X    XtSetArg (args[4], XtNstring, string);
X    XtSetArg (args[5], XtNlength, strlen (string));
X    XtSetArg (args[6], XtNtextOptions, scrollOnOverflow | wordBreak);
X    XtSetArg (args[7], XtNbottom, XtRubber);
X    XtSetArg (args[8], XtNtop, XtChainTop);
X    XtSetArg (args[9], XtNleft, XtChainLeft);
X    XtSetArg (args[10], XtNright, XtChainRight);
X    XtSetArg (args[11], XtNfromVert, button);
X    XtSetArg (args[12], XtNwidth, message_width);
X    XtSetArg (args[13], XtNheight, message_height);
X    XtSetArg (args[14], XtNfont, sysfont);
X    
X    messagewidget = XtCreateManagedWidget ("message", asciiStringWidgetClass, 
X    	    	    	    	    	formwidget, args, 15);
X    if (lines * cols != 0)
X    {
X    	data = XtMalloc ((length = lines * cols) + 2);
X
X    	*data = '\0';
X	
X	XtSetArg (args[0], XtNhorizDistance, tx_offset);
X    	XtSetArg (args[1], XtNvertDistance, 4);
X    	XtSetArg (args[2], XtNresizable, False);
X    	XtSetArg (args[3], XtNeditType, XttextEdit);
X    	XtSetArg (args[4], XtNstring, data);
X    	XtSetArg (args[5], XtNlength, length);
X    	XtSetArg (args[6], XtNtextOptions, scrollOnOverflow | wordBreak | editable);
X    	XtSetArg (args[7], XtNbottom, XtChainBottom);
X    	XtSetArg (args[8], XtNtop, XtRubber);
X    	XtSetArg (args[9], XtNleft, XtChainLeft);
X    	XtSetArg (args[10], XtNright, XtChainRight);
X    	XtSetArg (args[11], XtNfromVert, messagewidget);
X    	XtSetArg (args[12], XtNwidth, cols * char_width + EXTRA);
X    	XtSetArg (args[13], XtNheight, lines * char_height + EXTRA);
X    	XtSetArg (args[14], XtNfont, sysfont);
X    
X    	textwidget = XtCreateManagedWidget ("reply", asciiStringWidgetClass, 
X    	    	    	    	    	    	    formwidget, args, 15);
X    }
X    else
X    	length = 0, data = 0;
X	
X    XtRealizeWidget (gswidget);
X}
X
X/*
X							*****************
X							*		*
X							*   FINISHED	*
X							*		*
X							*****************
X-------------------------------------------------------------------------
X| The 'Finished' button has been selected by the user.  Read the text	|
X| widget's current text, print it on stdout and then exit.    	    	|
X-------------------------------------------------------------------------
X*/
X/*ARGSUSED*/
Xvoid Finished (widget, client_data, call_data)
XWidget widget;
Xcaddr_t client_data,call_data;
X{
X    char * p;
X    
X    XtPopdown (gswidget);
X
X    if (length == 0)
X    	exit (0);
X	
X    /* Remove trailing spaces and make sure the string is terminated by
X       a new line character */
X       
X    p = data + strlen (data);
X
X    if (strlen (data) != 0)
X    	p--;
X	
X    if (*p != '\n')
X    {
X    	while (p > data && *p == ' ')
X	    p--;
X
X	if (*p == ' ')
X	    *p++ = '\n';
X    	else
X	    if (*p != '\n')
X	    {
X		*++p = '\n';
X		p++;
X	    }
X	
X	*p = '\0';
X    }
X    	
X    printf ("%s", data);
X    exit (0);
X}
END_OF_FILE
if test 7594 -ne `wc -c <'gs.c'`; then
    echo shar: \"'gs.c'\" unpacked with wrong size!
fi
# end of 'gs.c'
fi
if test -f 'main.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'main.c'\"
else
echo shar: Extracting \"'main.c'\" \(13399 characters\)
sed "s/^X//" >'main.c' <<'END_OF_FILE'
X/*
XCopyright 1988 Torch Computers Ltd.
X
XPermission to use, copy, modify, and otherwise generally do what you like
Xwith this software is hereby granted provided that the above copyright notice
Xappears in all copies.
X
XTorch disclaims all warranties implied or expressed with regard to this
Xsoftware.  In no event shall Torch be liable for any damages arising from
Xthis use of software.
X*/
X
X/********************************************************
X*							*
X*  Title   Yorn, Gs and Alert				*
X*							*
X*  File	   : main.c					*
X*  Author  : Gary Henderson				*
X*  Date	   : 26th Sep 1988. 	    	    	    	*
X*  Purpose : Decide what we are called (hence what  	*
X*   	     progame to act like), initialise the   	*
X*   	     toolkit, setup some global variables and	*
X*   	     call the right code.   	    	    	*
X*							*
X*********************************************************/
X
X/*------Include files-----------------------------------*/
X
X#include <stdio.h>
X#include <X11/Xlib.h>
X#include <X11/Xos.h>
X#include <X11/Xutil.h>
X#include <X11/StringDefs.h>
X#include <X11/Intrinsic.h>
X#include <X11/TopLevel.h>
X#include <X11/Shell.h>
X#include <X11/Core.h>
X#include <X11/Label.h>
X#include <X11/cursorfont.h>
X
X#include "classname.h"
X
X/*------Forward delarations-----------------------------*/
X
Xstatic void InitFontAndResources ();
X
X/*------Constants and macros----------------------------*/
X
X#define EXTRABIT    50	/* Extra amount added to new long string */
X
X/*------Exported variables/functions--------------------*/
X
XDisplay     *display;
XWindow 	    root_window;
XScreen 	    *screen;
Xint 	    screen_number;
XXFontStruct *sysfont;
XWidget 	    a_widget;
XCursor 	    arrow_cursor;
Xunsigned int root_width, 
X    	     root_height;
XBoolean     zoom = True;      	    /* Flag to use override redirect
X    	    	    	    	       (False, use override ) */
Xint 	    cols = 0, 
X    	    lines = 0,
X 	    timeout = 0;
Xchar 	    *title;
Xint 	    is_gs;
Xchar	    *alertsym_name, 	    /* Various names of bitmap files */
X    	    *yornsym_name,  	    /* if not null, use these in preference */
X	    *ticksym_name,  	    /* to the built-in ones. */
X    	    *crosssym_name,
X	    *oksym_name;
X
Xchar 	    *progname;
X	    
Xvoid	    ReadWidgetColours ();
Xvoid 	    Usage ();
X
X/*------Imported variables/functions--------------------*/
X
Xextern Widget 	alertwidget;
Xextern Widget 	gswidget;
Xextern void 	Finished (), AddTimeout (), AddNewConverter ();
Xextern void 	Yorn (), Alert (), InitAlert (), InitGS ();
X
X/*------Static variables--------------------------------*/
X
Xstatic XrmOptionDescRec gscommand_options[] =
X{
X    {"-z", "*zoom", XrmoptionNoArg, (caddr_t) "False"},
X    {"-r", "*columns", XrmoptionSepArg, (caddr_t) NULL},
X    {"-n", "*gstitle", XrmoptionSepArg, (caddr_t) NULL},
X    {"-t", "*gstimeout", XrmoptionSepArg, (caddr_t) NULL},
X};
X
Xstatic XrmOptionDescRec alertcommand_options[] =
X{
X    {"-z", "*zoom", XrmoptionNoArg, (caddr_t) "False"},
X};
X
X/*
X							*****************
X							*		*
X							*     MAIN	*
X							*		*
X							*****************
X-------------------------------------------------------------------------
X| Try to open the connection to the X server.  If OK initialise the 	|
X| toolkit, otherwise drop into text only mode.  If toolkit initialised, |
X| setup some global variables, load up some resources and decide from	|
X| our name what utility to act like.	    	    	    	    	|
X-------------------------------------------------------------------------
X*/
Xint main (argc, argv)
Xint argc;
Xchar *argv[];
X{
X    Arg arglist [10];
X    unsigned int dummy;
X    Window dummy_window;
X    char * message;
X    char * geometry;
X    int i, len, start_arg;
X    int alert_comm_size = XtNumber (alertcommand_options);
X    int gs_comm_size = XtNumber (gscommand_options);
X    char * disp = NULL;
X    
X    /* Note our base name */
X    
X    if ((progname = rindex (argv[0], '/')) == 0)
X    	progname = argv[0];
X    else
X    	progname++;
X	
X    is_gs = strcmp (progname, "gs") == 0;
X
X    /* See if the -display flag has been passed on the command line */
X    
X    for (i = 1;	i < argc; i++)
X    	if (strcmp (argv[i], "-display") == 0)
X	{
X	    disp = argv[i + 1];
X	    break;
X	}
X
X    /* Make sure server is up and running */
X    
X    if ((display = XOpenDisplay (disp)) == NULL)
X    {
X    	/* Cannot open display, go into text mode */
X    	
X	TextMode (argc, argv);
X    }
X
X    XCloseDisplay (display);
X    
X    AddNewConverter ();
X    
X    /* Initialise the toolkit */
X
X    if ((a_widget = XtInitialize ("temp", CLASSNAME, 
X    	    	    is_gs ? gscommand_options : alertcommand_options,
X 		    is_gs ? gs_comm_size : alert_comm_size,
X		    &argc, argv)) == NULL)
X    {
X    	(void) fprintf (stderr, "%s: Failed to initialise X toolkit\n", progname);
X	TextMode (argc, argv);
X    }
X    
X    display = XtDisplay (a_widget);
X    root_window = DefaultRootWindow (display);
X    screen_number = DefaultScreen (display);
X    screen = DefaultScreenOfDisplay (display);
X
X    /* Find out size of root window */
X    
X    if (!XGetGeometry (display, 
X    	    	       root_window,
X		       &dummy_window, 
X		       &dummy, 
X		       &dummy, 
X		       &root_width, 
X		       &root_height,
X		       &dummy, 
X		       &dummy))
X    {
X    	/* If couldn't obtain size of root window, use the macros instead */
X	
X	root_width = WidthOfScreen (screen);
X	root_height = HeightOfScreen (screen);
X    }
X
X    /* Read what font to use and some other resource values */
X
X    InitFontAndResources ();
X
X    /* Check the number of command line options are OK */
X    
X    if ((!is_gs && argc < 3) || 
X    	(is_gs && ((cols != 0 && argc < 3) || 
X	(cols == 0 && argc < 2))))
X    	Usage ();
X
X    /* If the toplevel widget has been given a geometry string pass it on
X       to the other toplevel widgets */
X       
X    XtSetArg (arglist[0], XtNgeometry, &geometry);
X    XtGetValues (a_widget, arglist, 1);
X
X    /* We are called 'gs', so start acting like it */
X    
X    if (is_gs)
X    {
X    	/* If the -r flag has been given then the first arg in the argv list
X       	   must be the number of lines */
X       
X    	if (cols == 0)
X    	    start_arg = 0;
X    	else
X    	{
X    	    start_arg = 1;
X
X	    if (sscanf (argv[1], "%d", &lines) != 1)
X	    	Usage ();
X    	}
X    
X    	/* Message may have been given as lots of seperate arguments.
X       	   Copy them into one long string */
X
X    	len = strlen (argv[start_arg + 1]) + 1;
X    	message = XtMalloc (len);
X    
X    	(void) strcpy (message, argv[start_arg + 1]);
X
X    	for (i = start_arg + 2; i < argc; i++)
X    	{
X    	    if (strlen (argv[i]) + strlen (message) + 2 > len)
X	    	/* Need more space for the string */
X    	    	message = XtRealloc (message, 
X		    	    	     len = len + strlen (argv[i]) + 2);
X	    
X	    (void) strcat (message, " ");
X    	    (void) strcat (message, argv[i]);
X    	}
X
X	/* Initialise the gs widgets */
X	
X    	InitGS (message, geometry);
X    
X    	XtSetArg (arglist[0], XtNtitle, title);
X    	XtSetValues (gswidget, arglist, 1);
X
X    	/* Add an event handler to set a timer going on the first
X	   MapNotify event if a timeout has been specified for gs */
X	
X	if (timeout)
X    	    XtAddEventHandler (gswidget, 
X	    	    	       StructureNotifyMask, 
X			       False, 
X			       AddTimeout, 
X    	    	    	       (caddr_t) NULL);
X			       
X    	XtPopup (gswidget, XtGrabExclusive);
X	XDefineCursor (display, XtWindow (gswidget), arrow_cursor);
X    }
X    else
X    {
X    	/* Initialise the widgets for the yorn and alert boxes */
X	
X	InitAlert (geometry);
X    
X    	XtSetArg (arglist[0], XtNtitle, argv[1]);
X    	XtSetValues (alertwidget, arglist, 1);
X
X    	/* Message may have been given as lots of seperate arguments.
X       	   Copy them into one long string */
X
X    	len = strlen (argv[2]) + EXTRABIT + 1;
X    	message = XtMalloc (len);
X    
X    	(void) strcpy (message, argv[2]);
X
X    	for (i = 3; i < argc; i++)
X    	{
X    	    if (strlen (argv[i]) + strlen (message) + 2 > len)
X	    	/* Need more space for the string */
X    	    	message = XtRealloc (message, 
X		    	    	     len = len + strlen (argv[i]) +
X	    	    	    	    	   EXTRABIT + 2);
X	    (void) strcat (message, " ");
X    	    (void) strcat (message, argv[i]);
X    	}
X    
X    	/* If we are called 'alert' act like alert otherwise act like yorn */
X	
X	if (strcmp (progname, "alert") == 0)
X    	    Alert (message);
X    	else
X    	    Yorn (message);
X    }
X    
X    /* Wait for events to arrive and act on them */
X    
X    XtMainLoop ();
X}
X
X/*
X							*****************
X							*		*
X							*  ADDTIMEOUT	*
X							*		*
X							*****************
X-------------------------------------------------------------------------
X| Set a timer going on the first MapNotify event to be received from the|
X| server.   	    	    	    	    	    	    	    	|
X-------------------------------------------------------------------------
X*/
X/*ARGSUSED*/
Xvoid AddTimeout (widget, client_data, event)
XWidget widget;
Xcaddr_t client_data;
XXMapEvent * event;
X{
X    static int set = False;
X    
X    if (!set && event->type == MapNotify)
X    {
X    	set = True;
X	
X	/* Add a dummy timeout value to stop a core dump with an early
X	   X11R2 toolkit issue */
X	   
X	XtAddTimeOut ((unsigned long) 0xffffffff, Finished, (caddr_t) NULL);
X    	XtAddTimeOut ((unsigned long) (timeout * 1000), Finished, 
X	    	    	    	    	    	    	    (caddr_t) NULL);
X    }
X}
X
X/*
X							*****************
X							*		*
X							*INITFONTANDRESOURCES*
X							*		*
X							*****************
X-------------------------------------------------------------------------
X| Looks up default font to use from toolkit database, loads it  and 	|
X| fills in a pointer to the font's structure.  	    	    	    	|
X| and look up the icon height						|
X-------------------------------------------------------------------------
X*/
Xstatic void InitFontAndResources ()
X{
X    static char * sfont;
X    static Boolean truezoom = True;
X    static int zero = 0;
X    static Cursor left_ptr;
X    
X    static XtResource resources[] = {
X    	{XtNfont, XtCFont, XtRString, (Cardinal) sizeof (char *),
X	 (Cardinal) &sfont, XtRString, (caddr_t) NULL},
X    	
X    	{XtNcursor, XtCCursor, XtRCursor, sizeof (Cursor),
X	 (Cardinal) &arrow_cursor, XtRCursor, (caddr_t) &left_ptr},
X    	
X	{"zoom", "Zoom", XtRBoolean, (Cardinal) sizeof (Boolean),
X	 (Cardinal) &zoom, XtRBoolean, (caddr_t) &truezoom},
X	
X	{"columns", "Columns", XtRInt, (Cardinal) sizeof (int),
X	 (Cardinal) &cols, XtRInt, (caddr_t) &zero},
X
X	{"gstimeout", "Timeout", XtRInt, (Cardinal) sizeof (int),
X	 (Cardinal) &timeout, XtRInt, (caddr_t) 0},
X
X	{"gstitle", "Title", XtRString, (Cardinal) sizeof (char *),
X	 (Cardinal) &title, XtRString, (caddr_t) "Get String"},
X
X	{"alertsym", "Alertsym", XtRString, (Cardinal) sizeof (char *),
X	 (Cardinal) &alertsym_name, XtRString, (caddr_t) 0},
X
X	{"yornsym", "Yornsym", XtRString, (Cardinal) sizeof (char *),
X	 (Cardinal) &yornsym_name, XtRString, (caddr_t) 0},
X	
X	{"ticksym", "Ticksym", XtRString, (Cardinal) sizeof (char *),
X	 (Cardinal) &ticksym_name, XtRString, (caddr_t) 0},
X
X	{"crosssym", "Crosssym", XtRString, (Cardinal) sizeof (char *),
X	 (Cardinal) &crosssym_name, XtRString, (caddr_t) 0},
X
X	{"oksym", "Oksym", XtRString, (Cardinal) sizeof (char *),
X	 (Cardinal) &oksym_name, XtRString, (caddr_t) 0},
X    };
X    
X    sysfont = (XFontStruct *) NULL;
X    left_ptr = XtGetCursor (display, XC_left_ptr);
X    
X    XtGetApplicationResources (a_widget, (caddr_t) 0, resources, 
X    	    	    	    	    	    	XtNumber (resources), NULL, 0);
X
X    /* If no resource (-font or -fn) specified use default font (serif10) */
X    
X    if (sfont == NULL)
X    	sysfont = XLoadQueryFont (display, "serif10");
X    else
X    	sysfont = XLoadQueryFont (display, sfont);
X    
X    /* If one of the fonts don't exist, use fixed.  If that isn't there
X       we've had it */
X       
X    if (sysfont == NULL)
X	sysfont = XLoadQueryFont (display, "fixed");
X    
X    if (sysfont == NULL)
X    {
X	(void) fprintf (stderr, "%s: Suitable font cannot be found - giving up.",
X	    	    	    progname);
X    	exit (2);
X    }
X}
X
X/*
X							*****************
X							*		*
X							*READWIDGETCOLOURS*
X							*		*
X							*****************
X-------------------------------------------------------------------------
X| Read a widget's background and foreground (if it has one) colours.	|
X-------------------------------------------------------------------------
X*/
X
Xvoid ReadWidgetColours (widget, fore, back)
XWidget widget;
XPixel *fore, *back;
X{
X    Arg args[2];
X    
X    /* Set up some defaults just in case we can't read any values */
X    
X    *fore = BlackPixel (display, screen_number);
X    *back = WhitePixel (display, screen_number);
X    
X    XtSetArg (args[0], XtNforeground, fore);
X    XtSetArg (args[1], XtNbackground, back);
X
X    XtGetValues (widget, args, 2);
X}
X
X/*
X							*****************
X							*		*
X							*     USAGE	*
X							*		*
X							*****************
X-------------------------------------------------------------------------
X| Too few command line arguments supplied, print out a usage string and |
X| exit.	    	    	    	    	    	    	    	    	|
X-------------------------------------------------------------------------
X*/
Xvoid Usage ()
X{
X    if (is_gs)
X    	(void) fprintf (stderr, "%s: Usage: %s [-z] [-r cols lines] [-n title] [-t seconds] message\n", 
X	    	    	    progname, progname);
X    else
X    	(void) fprintf (stderr, "%s: Usage: %s [-z] title message\n", progname, progname);
X	
X    exit (2);
X}
END_OF_FILE
if test 13399 -ne `wc -c <'main.c'`; then
    echo shar: \"'main.c'\" unpacked with wrong size!
fi
# end of 'main.c'
fi
if test -f 'misc.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'misc.c'\"
else
echo shar: Extracting \"'misc.c'\" \(5047 characters\)
sed "s/^X//" >'misc.c' <<'END_OF_FILE'
X/*
XCopyright 1988 Torch Computers Ltd.
X
XPermission to use, copy, modify, and otherwise generally do what you like
Xwith this software is hereby granted provided that the above copyright notice
Xappears in all copies.
X
XTorch disclaims all warranties implied or expressed with regard to this
Xsoftware.  In no event shall Torch be liable for any damages arising from
Xthis use of software.
X*/
X
X/********************************************************
X*							*
X*  Title   Yorn, Gs and Alert.	    	    	    	*
X*							*
X*  File	   : misc.c					*
X*  Author  : Gary Henderson 	    	    	    	*
X*  Date	   : 23rd Aug 1988				*
X*  Purpose : String to pixmap converter so user can 	*
X*   	     specify background bitmaps for widgets. 	*
X*							*
X*********************************************************/
X
X/*------Include files-----------------------------------*/
X
X#include <stdio.h>
X#include <X11/Xlib.h>
X#include <X11/IntrinsicP.h>
X#include <X11/Convert.h>
X#include <X11/StringDefs.h>
X
X/*------Forward delarations-----------------------------*/
X
X/*------Constants and macros----------------------------*/
X
X/*------Exported variables/functions--------------------*/
X
Xvoid AddNewConverter ();
X
X/*------Imported variables/functions--------------------*/
X
X/*------Static variables--------------------------------*/
X
X/*
X							*****************
X							*		*
X							*CVTSTRINGTOPIXMAP*
X							*		*
X							*****************
X-------------------------------------------------------------------------
X| Convert the given string (taken to be the path name of a bitmap file)	|
X| into a pixmap.  This is so the user can specify background pixmaps	|
X| for widgets from a .Xdefaults file.	    	    	    	    	|
X-------------------------------------------------------------------------
X*/
Xstatic void CvtStringToPixmap (args, num_args, fromVal, toVal)
XXrmValuePtr args;
XCardinal * num_args;
XXrmValuePtr fromVal;
XXrmValuePtr toVal;
X{
X    static Pixmap pixmap;
X    static Pixel fore_pixel;
X    static XtResource pixmap_resources[] = {
X    	{XtNforeground, XtCForeground, XtRPixel, sizeof (Pixel),
X 	(Cardinal) &fore_pixel, XtRString, "Black"},
X    };
X    
X    unsigned int width, height;
X    int result;
X    Pixmap temp;
X    XGCValues gcvalues;
X    GC gc;
X    Screen * screen;
X    Cardinal depth;
X    Pixel back_pixel;
X    Widget widget;
X    
X    if (*num_args != 4)
X    	return;
X
X    widget = (Widget) args[0].addr;
X    screen = *((Screen **) args[1].addr);
X    
X    /* So much for doing things properly; if you try to get the widget's
X       depth with the following code: 
X    	    depth = *((Cardinal *) args[2].addr);
X
X       you always read zero !  So for the time been, assume the widget has
X       the same depth as the root window */
X
X    depth = PlanesOfScreen (screen);
X    back_pixel = *((Pixel *) args[3].addr);
X
X    result = XReadBitmapFile (DisplayOfScreen (screen),
X    	    	    	      RootWindowOfScreen (screen),
X			      (char *) fromVal->addr,
X	    	    	      &width, 
X			      &height, 
X			      &temp, 
X			      (int *) 0,
X			      (int *) 0);
X
X    if (result != BitmapSuccess)
X        return;
X    else
X    {
X	pixmap = XCreatePixmap (DisplayOfScreen (screen),
X	    	    	        RootWindowOfScreen (screen),
X				width,
X				height, 
X				depth);
X	    
X	/* Need two colours when converting a bitmap into a pixmap.  The
X	   background pixel value is easy, but the foreground requires a bit
X	   more work to get hold of */
X	   
X	gcvalues.background = back_pixel;
X	
X	XtGetSubresources (widget, 
X	    	    	   (caddr_t) 0,
X			   XtNbackgroundPixmap,
X			   XtCPixmap,
X    	    	    	   pixmap_resources,
X			   XtNumber (pixmap_resources),
X			   (ArgList) 0,
X			   0);
X
X	gcvalues.foreground = fore_pixel;
X	
X	gc = XCreateGC (DisplayOfScreen (screen),
X	    	    	pixmap,
X			GCForeground | GCBackground,
X			&gcvalues);
X
X	XCopyPlane (DisplayOfScreen (screen),
X	    	    temp, 
X		    pixmap, 
X		    gc, 
X		    0, 
X		    0, 
X		    width, 
X		    height, 
X	    	    0, 
X		    0, 
X		    1l);
X	    
X	XFreePixmap (DisplayOfScreen (screen), temp);
X    	XFreeGC (DisplayOfScreen (screen), gc);
X    }
X
X    toVal->addr = (caddr_t) &pixmap;
X    toVal->size = sizeof (Pixmap);
X}
X
X/*
X							*****************
X							*		*
X							*ADDNEWCONVERTER*
X							*		*
X							*****************
X-------------------------------------------------------------------------
X| Install the string-to-pixmap converter into the toolkit's current list|
X| of converters.    	    	    	    	    	    	    	|
X-------------------------------------------------------------------------
X*/
Xvoid AddNewConverter ()
X{
X    static XtConvertArgRec pixmapConvertArgs[] = {
X    	{XtBaseOffset, (caddr_t) 0, sizeof (Widget)},
X	{XtBaseOffset, (caddr_t) XtOffset (Widget, core.screen), 
X	 sizeof (Screen *)},
X    	{XtBaseOffset, (caddr_t) XtOffset (Widget, core.depth), 
X	 sizeof (Cardinal)},
X	{XtBaseOffset, (caddr_t) XtOffset (Widget, core.background_pixel),
X	 sizeof (Pixel)},
X    };
X
X    XtAddConverter (XtRString, XtRPixmap, CvtStringToPixmap,
X    	    	    pixmapConvertArgs, XtNumber (pixmapConvertArgs));
X}
END_OF_FILE
if test 5047 -ne `wc -c <'misc.c'`; then
    echo shar: \"'misc.c'\" unpacked with wrong size!
fi
# end of 'misc.c'
fi
if test -f 'textmode.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'textmode.c'\"
else
echo shar: Extracting \"'textmode.c'\" \(9705 characters\)
sed "s/^X//" >'textmode.c' <<'END_OF_FILE'
X/*
XCopyright 1988 Torch Computers Ltd.
X
XPermission to use, copy, modify, and otherwise generally do what you like
Xwith this software is hereby granted provided that the above copyright notice
Xappears in all copies.
X
XTorch disclaims all warranties implied or expressed with regard to this
Xsoftware.  In no event shall Torch be liable for any damages arising from
Xthis use of software.
X*/
X
X/********************************************************
X*							*
X*  Title   Yorn, Gs and Alert				*
X*							*
X*  File	   : textmode.c					*
X*  Author  : Gary Henderson				*
X*  Date	   : 26th Sep 1988.				*
X*  Purpose : Terminal versions of above programs, in 	*
X*   	     connection to server cannot be opened. 	*
X*							*
X*********************************************************/
X
X/*------Include files-----------------------------------*/
X
X#include <stdio.h>
X#include <signal.h>
X#include <errno.h>
X
X#if defined(SYSV) || defined(UNISOFTV)
X#include <termio.h>
X#endif SYSV
X
X#ifdef BSD
X#include <sgtty.h>
X#include <setjmp.h>
X#endif BSD
X
X/*------Forward delarations-----------------------------*/
X
X/*------Constants and macros----------------------------*/
X
X/*------Exported variables/functions--------------------*/
X
X/*------Imported variables/functions--------------------*/
X
Xextern int is_gs;
Xextern int cols, lines;
Xextern char * progname;
Xextern int errno;
Xextern int timeout;
Xextern void Usage ();
X
X/*------Static variables--------------------------------*/
X
Xstatic int size_args, title_arg, seconds_arg;
X
Xstatic int set = -1;
X
X#ifdef SYSV
Xstatic int (*old_sig[SIGPWR + 1])();
Xstatic struct termio term_settings, term;
X#endif SYSV
X
X#ifdef UNISOFTV
Xstatic int (*old_sig[SIGIO + 1])();
Xstatic struct termio term_settings, term;
X#endif UNISOFTV
X
X#ifdef BSD
Xstatic int (*old_sig[SIGUSR2 + 1])();
Xstatic struct sgttyb term_settings, term;
Xstatic jmp_buf env;
X#endif BSD
X
Xstatic struct options {
X    char * name;
X    int args;
X    int * addr;
X} opts[] = {
X    {"-z", 0, 0},
X    {"-r", 2, &size_args},
X    {"-n", 1, &title_arg},
X    {"-t", 1, &seconds_arg},
X    {"-display", 1, 0},
X    {"-font", 1, 0},
X    {"-fn", 1, 0},
X    {"-fg", 1, 0},
X    {"-bg", 1, 0},
X};
X
Xstatic int AlarmCall ();
Xstatic int alarm_gone_off = 0;
Xstatic int ResetTerm ();
X
X/*
X							*****************
X							*		*
X							*   TEXTMODE	*
X							*		*
X							*****************
X-------------------------------------------------------------------------
X| Hmmm, the connection to the X server could not be made.  Just to be	|
X| nice, give the user a terminal version of the program he/she asked for|
X| (useful if the utility is in a Unix start up shell script and the 	|
X| the server failed to start up for some reason).   	    	    	|
X-------------------------------------------------------------------------
X*/
XTextMode (argc, argv)
Xint argc;
Xchar ** argv;
X{
X    register struct options * parse;
X    int max_arg = 1;
X    int i, j;
X    char c;
X
X    /* Parse options (the toolkit can't parse them without a connection to
X       the server */
X    
X    for (i = 1; i < argc; i++)
X    	for (j = 0, parse = opts; j < sizeof (opts) / sizeof (opts[0]); 
X	    	    	    	    	    	    	    	j++, parse++)
X	    if (strcmp (parse->name, argv[i]) == 0)
X	    {
X	    	if (i + parse->args >= argc)
X		    Usage ();
X
X		if (i + parse->args + 1 >= max_arg)
X		    max_arg = i + parse->args + 1;
X
X		if (parse->addr)
X		    *(parse->addr) = i + 1;
X
X		i += parse->args;
X
X		break;
X	    }
X
X    if ((is_gs && argc - max_arg < 1) || (!is_gs && argc - max_arg < 2))
X    	Usage ();
X
X    if (is_gs)
X    {
X	/* We are called 'gs', so act like gs.  Print out the title and 
X	   the message... */
X	if (title_arg)
X	    (void) fprintf (stderr, "\t%s\n", argv[title_arg]);
X
X	for (i = max_arg; i < argc; i++)
X	    (void) fprintf (stderr, "%s ", argv[i]);
X
X	(void) fprintf (stderr, "\n");
X
X	/* ...find out if a timeout is required... */
X	
X	if (!seconds_arg || sscanf (argv[seconds_arg], "%d", &timeout) != 1 ||
X	    timeout < 1)
X	    timeout = 0;
X	    
X	/* ...and the size of the reply from the user. */
X	
X	if (size_args)
X	{
X	    if (sscanf (argv[size_args], "%d", &cols) != 1 ||
X	    	sscanf (argv[size_args + 1], "%d", &lines) != 1)
X
X	    	cols = lines = 0;
X	}
X	else
X	    cols = lines = 0;
X
X	if (cols * lines <= 0)
X	{
X	    /* Negative or zero length reply required from user.  If there's
X	       a timeout wait for it to go off, otherwise... */
X	    if (timeout)
X	    {
X	    	(void) signal (SIGALRM, AlarmCall);
X	    	(void) alarm ((unsigned int) timeout);
X	    	
X		while (!alarm_gone_off)
X		    pause ();
X	    }
X	    else
X	    {
X	    	/* ...ask the user to press RETURN */
X		
X		(void) fprintf (stderr, "(Press RETURN to continue)");
X		(void) fflush (stderr);
X	    	
X		do
X	    	{
X	    	} while (((j = read (0, &c, 1)) == -1 && errno == EINTR) ||
X 	    	    	(j == 1 && c != '\n')); 
X	    }
X		
X	    exit (0);
X	}
X	
X	/* A positive length reply is required from the user, ask for one... */
X
X	i = 0;
X
X	(void) fprintf (stderr, "(Please type in your reply and press RETURN)\n\
X\nEnter> ");
X	(void) fflush (stderr);
X	
X	/* ...set a timer going if a timeout is required... */
X	
X	if (timeout)
X	{
X	    (void) signal (SIGALRM, AlarmCall);
X	    (void) alarm ((unsigned int) timeout);
X	}
X	
X#ifdef BSD
X    	if (setjmp (env) == 0)
X	{
X#endif BSD
X    	/* ...and read in the reply and send it to stdout. */
X	
X	do
X	{
X	    do
X	    {
X    	    } while (!alarm_gone_off && ((j = read (0, &c, 1)) == -1 && 
X	    	    	    	    	    	    	    errno == EINTR));
X	    if (j == 1 && i++ < cols * lines && c != '\n')
X	    	(void) putchar (c);
X
X	} while (j == 1 && c != '\n' && !alarm_gone_off);
X#ifdef BSD
X	}
X#endif BSD	
X
X	if (i)
X	    (void) printf ("\n");
X	    
X	exit (0);
X    }
X
X    /* Yorn or alert.  Print out the message... */
X    
X    (void) printf ("\t%s\n", argv[max_arg]);
X	
X    for (i = max_arg + 1; i < argc; i++)
X    	(void) printf ("%s ", argv[i]);
X
X    if (strcmp ("alert", progname) == 0)
X    {
X    	/* ...if we are alert, ask the user to press RETURN when he/she has
X	   read the message... */
X	   
X	(void) printf ("\07\n(Press RETURN to continue) ");
X    	
X	(void) fflush (stdout);
X	
X	do
X	{
X	} while (((j = read (0, &c, 1)) == -1 && errno == EINTR) ||
X 	    	    (j == 1 && c != '\n')); 
X
X	exit (0);
X    }
X    else
X    {
X    	/* ...otherwise must be yorn.  Trap most signals (so the terminal state
X	   can be reset before we get killed off)... */
X	   
X	(void) printf ("(y/n) ");
X
X	(void) fflush (stdout);
X	
X	for (i = SIGHUP; i < SIGALRM; i++)
X	    old_sig[i] = signal (i, ResetTerm);
X
X#ifdef SYSV
X    	for (i = SIGTERM; i <= SIGPWR; i++)
X	    old_sig[i] = signal (i, ResetTerm);
X#endif SYSV
X
X#ifdef UNISOFTV
X    	for (i = SIGTERM; i <= SIGIO; i++)
X	    old_sig[i] = signal (i, ResetTerm);
X#endif UNISOFTV
X
X	/* ...fiddle the terminal to give one key press at a time and convert
X	   upper-case to lower-case... */
X
X#if defined(SYSV) || defined(UNISOFTV)
X	if ((set = ioctl (0, TCGETA, &term_settings)) == 0)
X	{
X#ifdef UNISOFTV
X	    blt ((char *) &term, (char *) &term_settings, 
X	    	    	    	    	    	    sizeof (struct termio));
X#else
X	    (void) memcpy ((char *) &term, (char *) &term_settings, 
X	    	    	    	    	    	    sizeof (struct termio));
X#endif UNISOFTV
X
X	    term.c_lflag &= ~ICANON;
X	    term.c_iflag |= IUCLC;
X	    
X	    term.c_cc[4] = 1;
X	    term.c_cc[5] = 255;
X
X	    (void) ioctl (0, TCSETA, &term);
X	}
X#endif SYSV
X
X#ifdef BSD
X	for (i = SIGTERM; i <= SIGUSR2; i++)
X	    old_sig[i] = signal (i, ResetTerm);
X	    
X	if ((set = ioctl (0, TIOCGETP, &term_settings)) == 0)
X	{
X	    bcopy ((char *) &term_settings, (char *) &term, 
X	    	    	    	    	    	    sizeof (struct sgttyb));
X	    term.sg_flags |= CBREAK | LCASE;
X
X	    (void) ioctl (0, TIOCSETP, &term);
X	}
X#endif BSD
X
X	/* ...wait for a 'y' or and 'n' to be typed... */
X	do
X	{
X	} while (((j = read (0, &c, 1)) == -1 && errno == EINTR) ||
X	    	(j == 1 && c != 'y' && c != 'n'));
X
X	/* ...reset the terminal state... */
X	
X	if (set == 0)
X	{
X#if defined(SYSV) || defined(UNISOFTV)
X	    (void) ioctl (0, TCSETA, &term_settings);
X#endif SYSV
X
X#ifdef BSD
X	    (void) ioctl (0, TIOCSETN, &term_settings);
X#endif BSD
X	}
X
X	(void) printf ("\n");
X	
X	/* ...and return 0 or 1 to the calling program depending on which
X	   key was pressed (return 2 on some sort of error) */
X	   
X	if (c == 'y')
X	    exit (0);
X    	else
X	    if (c == 'n')
X	    	exit (1);
X	    else
X	    	exit (2);
X    }
X}
X
X/*
X							*****************
X							*		*
X							*   ALARMCALL	*
X							*		*
X							*****************
X-------------------------------------------------------------------------
X| SIGALRM signal handler.  Used to add a timeout facility to gs.    	|
X-------------------------------------------------------------------------
X*/
X
Xstatic int AlarmCall ()
X{
X    alarm_gone_off = 1;
X
X#ifdef BSD
X    if (env)
X    	longjmp (env, 1);
X#endif BSD    
X}
X
X/*
X							*****************
X							*		*
X							*  RESETTERM	*
X							*		*
X							*****************
X-------------------------------------------------------------------------
X| Handler for every other type of signal (that is catchable).  If the 	|
X| terminal state has been fiddled with, reset it then reset the signal	|
X| to its default state and send the signal again.   	    	    	|
X| Note: The code will work correctly for signals that don't kill the	|
X        process (may fix it one day, but it's only a minor problem).	|
X-------------------------------------------------------------------------
X*/
X
Xstatic int ResetTerm (sig)
Xint sig;
X{
X    if (set == 0)
X    {
X#if defined(SYSV) || defined(UNISOFTV)
X	(void) ioctl (0, TCSETA, &term_settings);
X#endif SYSV
X
X#ifdef BSD
X	(void) ioctl (0, TIOCSETP, &term_settings);
X#endif BSD
X    }
X
X    (void) signal (sig, old_sig[sig]);
X
X    (void) kill (getpid (), sig);
X}
END_OF_FILE
if test 9705 -ne `wc -c <'textmode.c'`; then
    echo shar: \"'textmode.c'\" unpacked with wrong size!
fi
# end of 'textmode.c'
fi
if test -f 'yorn.1' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'yorn.1'\"
else
echo shar: Extracting \"'yorn.1'\" \(5595 characters\)
sed "s/^X//" >'yorn.1' <<'END_OF_FILE'
X.TH YORN 1 "3 October 1988" "X Version 11"
X.SH NAME
Xyorn \- display a dialogue box
X.SH SYNOPSIS
X.B yorn
X[
X.B -z
X] 
X[
X.B -standard X Toolkit options \.\.\.
X] "\fBTITLE\fP"
X.B text to be displayed
X.SH DESCRIPTION
X.I Yorn
Xis a utility that asks the user a question that can be answered yes or no.  It
Xdisplays a question mark symbol, some justified text and two buttons labelled
Xwith a tick and a cross, representing yes or no respectively.  The question
Xcan be answered by clicking one of the boxes with the mouse.
X.PP
XIf the connection to the X server cannot be established, the title and text is
Xprinted on \fIyorn\fP's standard output and the user is requested to press
X\fIY\fP or \fIN\fP to answer the question.
X.PP
X.I Yorn
Xcan take the following option:
X.TP 8
X.B \-z
XNo Zoom.  The window will attempt to by pass the window manager and appear
Ximmediately, rather than going through the window manager's placement and
Xsizing scheme.
X.PP
X\fIyorn\fP additionally recognizes the following standard X Toolkit command
Xline arguments:
X.TP 8
X.B \-bg \fIcolour\fP \fRor\fP \-background \fIcolour\fP
XThis option specifies the colour to use for the background of the window and
Xwidgets.  The default is `white.'
X.TP 8
X.B \-bd \fIcolour\fP \fRor\fP \-bordercolor \fIcolour\fP
XThis option specifies the colour to use for the border of the main window.
XThe default is `black.'
X.TP 8
X.B \-bw \fInumber\fP \fRor\fP \-borderwidth \fInumber\fP
XThis option specifies the width in pixels of the border surrounding the main
Xwindow. 
X.TP 8
X.B \-fg \fIcolour\fP \fRor\fP \-foreground \fIcolour\fP
XThis option specifies the colour to use for all text and symbols.  The default
Xis `black'.
X.TP 8
X.B \-fn \fIfont\fP
XThis option specifies the font to be used for displaying the text warning
Xmessage.  The default is `serif10'.
X.TP 8
X.B \-name \fIname\fP
XThis option specifies the application name under which resources are to be
Xobtained, rather than the default executable file name, `yorn'.
X.TP 8
X.B \-geometry \fIgeometry\fP
XThis option specifies the preferred size and position yorn window; see
X\fIX(1)\fP; 
X.TP 8
X.B \-display \fIdisplay\fP
XThis option specifies the X server to contact; see \fIX(1)\fP.
X.TP 8
X.B \-xrm \fIresourcestring\fP
XThis option specifies a resource string to be used.  This is especially
Xuseful for setting resources that do not have separate command line options.
X.SH "X DEFAULTS"
X\fIYorn\fP is implemented using the Athena widgets.  Each widget can
Xindividually or in groups have various visual and operational aspects changed
Xvia a `.Xdefaults' file on the client machine or the `RESOURCE_MANAGER'
Xproperty on the server.  All widgets have a common set of resources
X(background, backgroundPixmap, etc.) and resources unique to each type of
Xwidget; a `command button' widget, for example, also has a cursor resource.
XFor a full list see the document \fIX Toolkit Widgets - C Language X Interface\fP.
X.PP
XThe path names and types of all widgets used by \fIyorn\fP are as follows:
X.TP 8
X.B "\fIXXX\fP.alert/yorn"
XThe widget that is a child of root.  All the other widgets used by the yorn
Xbox are children or grand children of this widget. 
X.TP 8
X.B "\fIXXX\fP.alert/yorn.contents"
XA form widget that manages the layout of the yorn box.  Normally completely
Xcovers the `alert/yorn' widget.
X.TP 8
X.B "\fIXXX\fP.alert/yorn.contents.symbol"
XA widget to display the `query' symbol.
X.TP 8
X.B "\fIXXX\fP.alert/yorn.contents.ok/yes button"
XA command button widget to obtain a `yes' answer from the user, normally
Xdisplaying a `tick' symbol.
X.TP 8
X.B "\fIXXX\fP.alert/yorn.contents.no button"
XA command button widget to obtain a `no' answer from the user, normally
Xdisplaying a `cross' symbol.
X.TP 8
X.B "\fIXXX\fP.alert/yorn.contents.message"
XA widget to display and format the text message.
XThe `\fIXXX\fP' may be replaced by either \fIyorn\fP's classname, `Xopentop',
Xor its application name, `yorn'.
X.PP
XAdditionally, the following items are also fetched from the resource database:
X.TP 8
X.B "yornsym"
XThe pathname of a bitmap file to use as an alternative to the
X`question-mark-in-a-triangle' symbol displayed in the `symbol' widget.
X.TP 8
X.B "ticksym"
XThe pathname of a bitmap file to use as an alternative to the `tick' symbol
Xdisplayed in the `ok/yes button' widget.
X.TP 8
X.B "crosssym"
XThe pathname of a bitmap file to use as an alternative to the `cross' symbol
Xdisplayed in the `no button' widget.
X.TP 8
X.B "backgroundPixmap.foreground"
XOne of two colours (the other is the widget's background colour) required when
Xconverting a bitmap file into a pixmap for use as the widget's background
Xpixmap. 
X.SH RETURN CODES
X.IP
X0 \- Termination via the tick box.
X.IP
X1 \- Termination via the cross box.
X.IP
X2 \- Termination due to some internal error.
X.SH ENVIRONMENT
X.TP 8
XDISPLAY - the default host and display number of the X server.
X.TP 8
XXENVIRONMENT - the name of the Xdefaults file to use (normally 
X$HOME/.Xdefaults).
X.SH EXAMPLES
X.IP
Xyorn "Yorn" "The file /etc/passwd exists.  Are you sure you want to delete it ?"
X.PP
XWill open an yorn box with the title
X.I Yorn
Xand containing the text
X.I The file /etc/passwd exists.  Are you sure you want to delete it ?
Xand waits for the user to click one of the buttons.
X.SH FILES
X$HOME/.Xdefaults
X/usr/lib/X11/app-defaults/Xopentop
X.SH SEE ALSO
Xalert(1), gs(1)
X.SH BUGS
X.PP
XIf the font is too large or the message too long, the text will be clipped.
X.PP
XThe title may not be displayed if the window manager does not provide title bars
Xaround windows or the \fB\-z\fP option is used.
X.SH AUTHOR
XGary Henderson & Mark E. Howells, Torch Computers Ltd.
END_OF_FILE
if test 5595 -ne `wc -c <'yorn.1'`; then
    echo shar: \"'yorn.1'\" unpacked with wrong size!
fi
# end of 'yorn.1'
fi
echo shar: End of archive 3 \(of 4\).
cp /dev/null ark3isdone
MISSING=""
for I in 1 2 3 4 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 4 archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0
-- 
Mike Wexler(wyse!mikew)    Phone: (408)433-1000 x1330
Moderator of comp.sources.x



More information about the Comp.sources.x mailing list