DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T x

⟦ad6cb852a⟧ TextFile

    Length: 6206 (0x183e)
    Types: TextFile
    Names: »xalert.c«

Derivation

└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0
    └─⟦dc59850a2⟧ »EurOpenD22/pp5.0/pp-5.tar.Z« 
        └─⟦e5a54fb17⟧ 
            └─⟦this⟧ »pp-5.0/Uip/rcvalert/xalert.c« 

TextFile

/* xalert.c: X based alert program */

# ifndef lint
static char Rcsid[] = "@(#)$Header: /cs/research/pp/hubris/pp-beta/Uip/rcvalert/RCS/xalert.c,v 5.0 90/09/20 16:34:02 pp Exp Locker: pp $";
# endif

/*
 * $Header: /cs/research/pp/hubris/pp-beta/Uip/rcvalert/RCS/xalert.c,v 5.0 90/09/20 16:34:02 pp Exp Locker: pp $
 *
 * $Log:	xalert.c,v $
 * Revision 5.0  90/09/20  16:34:02  pp
 * rcsforce : 5.0 public release
 * 
 */



#include <stdio.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>
#include <X11/Xaw/Command.h>	
#include <X11/Xaw/Box.h>
#include <X11/Xaw/Label.h>
#include <X11/Xaw/Cardinals.h>	
#include <X11/Xaw/Form.h>
#include <X11/Xaw/Text.h>
#include <X11/Xaw/AsciiText.h>

#include <pwd.h>


#define	BASIC_WIDTH 400

static struct _app_resources {
	char	*filename;
	char	*user;
	int	port;
} app_resource;

static int	defaultPort = 0;
char	homedir[BUFSIZ];

#define offset(x)	XtOffset (struct _app_resources *, x)
static XtResource resources[] = {
{"fileName",	"FileName",	XtRString,	sizeof (String),
	 offset(filename),	XtRString, 	(caddr_t) ".alert" },
{"userName",	"UserName",	XtRString,	sizeof (String),
	 offset(user),		XtRString,	(caddr_t) NULL },
{"port",	"Port",		XtRInt,		sizeof (int),
	 offset(port),		XtRInt,		(caddr_t) &defaultPort },
};

static XrmOptionDescRec table[] = {
{"-filename",	"fileName",	XrmoptionSepArg,	(caddr_t) NULL},
{"-user",	"userName",	XrmoptionSepArg,	(caddr_t) NULL},
{"-port",	"port",		XrmoptionSepArg,	(caddr_t) NULL},
};

XtAppContext context;
Display *dpy;
Screen 	*scrn;
Widget 	toplevel, box, qb, topform, txt, db, rst;
char	username[128];
int	replysock;
char	twfilename[BUFSIZ];

void	Delete ();
void	Quit ();
void	Reset ();
void	TextIn ();
int	EQuit ();
int	EQuit2 ();

main (argc, argv)
int	argc;
char	*argv[];
{
	int sd;
	struct passwd *pwd;
	char	*cp, *getenv ();

	if ((pwd = getpwuid (getuid ())) == NULL) {
		fprintf (stderr, "Unknown user");
	}
	else {
		(void) strcpy (username, pwd -> pw_name);
		if ((cp = getenv ("HOME")) && *cp)
			(void) strcpy (homedir, cp);
		else
			(void) strcpy (homedir, pwd -> pw_dir);
	}

	XtToolkitInitialize();
	context = XtCreateApplicationContext();
	dpy = XtOpenDisplay(context, (String)NULL, "xalert", "XAlert",
			    table, XtNumber(table), &argc, argv);
	if (dpy == (Display *)0) {
		fprintf (stderr, "Unable to open display\n");
		exit(-1);
	}
	scrn = DefaultScreenOfDisplay(dpy);

	toplevel = XtAppCreateShell("xalert", "XAlert", 
				    applicationShellWidgetClass, dpy, NULL,0);

	XtGetApplicationResources (toplevel, (caddr_t)&app_resource, resources,
				   XtNumber(resources), NULL, 0);

	if (app_resource.user == NULL)
		app_resource.user = username;
	topform = XtVaCreateManagedWidget(NULL,
			       formWidgetClass,
			       toplevel,
			       XtNdefaultDistance, 0,
			       XtNborderWidth,	0,
			       XtNtop,	XtChainTop,
			       NULL);
	box = XtVaCreateManagedWidget ("box",
			    boxWidgetClass,
			    topform,
			    XtNwidth,	BASIC_WIDTH,
			    XtNtop,	XtChainTop,
			    XtNbottom,	XtChainTop,
			    XtNleft,	XtChainLeft,
			    XtNright,	XtChainLeft,
			    NULL);

        qb = XtVaCreateManagedWidget ("Quit",
			   commandWidgetClass,
			   box,
			   NULL);
	XtAddCallback(qb, XtNcallback, Quit, NULL);

	db = XtVaCreateManagedWidget ("Clear",
			   commandWidgetClass,
			   box,
			   NULL);
	XtAddCallback (db, XtNcallback, Delete, NULL);

	rst = XtVaCreateManagedWidget ("Reset",
				       commandWidgetClass,
				       box,
				       NULL);
	XtAddCallback (rst, XtNcallback, Reset, NULL);

	crt_txt (BASIC_WIDTH, 120);
	sd = udp_start (app_resource.port, app_resource.filename, homedir);

	XSetErrorHandler (EQuit);
	XSetIOErrorHandler (EQuit2);

	(void) XtAppAddInput (context, sd, XtInputReadMask, TextIn, NULL);
	

	XtRealizeWidget(toplevel);

	XtAppMainLoop (context);
}

/* ARGSUSED */
void	TextIn (cdata, fdp, iid)
caddr_t	cdata;
int	*fdp;
XtInputId *iid;
{
	char	buffer[BUFSIZ];
	int	n;

	if (*fdp == 0) {
		if ((n = read (*fdp, buffer, sizeof buffer)) <= 0)
			Quit (toplevel, (caddr_t)0, (caddr_t)0);
		buffer[n] = 0;
		AddText (buffer, n);
	}
	else {
		if (getdata (*fdp, buffer, &n, app_resource.user))
			AddText (buffer, n);
	}
}

/* ARGSUSED */
int	EQuit (disp, error)
Display *disp;
XErrorEvent *error;
{
	Quit (toplevel, (caddr_t)0, (caddr_t)0);
}

/* ARGSUSED */
int	EQuit2 (disp)
Display *disp;
{
	Quit (toplevel, (caddr_t)0, (caddr_t)0);
}

/* ARGSUSED */
void Quit(widget, closure, callData)
Widget widget;
caddr_t closure;
caddr_t callData;
{
	XtDestroyWidget(toplevel);
	if (twfilename[0])
		(void) unlink (twfilename);
	udp_cleanup ();

	exit(0);
}

AddText (s, n)
char	*s;
int	n;
{
	XawTextPosition      last;
	XawTextBlock text;

	XawTextSetInsertionPoint (txt, (XawTextPosition)9999999);
	last = XawTextGetInsertionPoint (txt);

	text.ptr = s;
	text.firstPos = 0;
	text.length = n;
	text.format = FMT8BIT;

	if (XawTextReplace (txt, last, last, &text) != XawEditDone)
		XBell (XtDisplay (txt), 0);
	else {
		XawTextPosition newend;

		XawTextSetInsertionPoint(txt, last + text.length);
		newend = XawTextGetInsertionPoint(txt);
		if (text.ptr[text.length-1] != '\n') {
			text.ptr = "\n";
			text.length = 1;
			XawTextReplace(txt, newend, newend, &text);
			XawTextSetInsertionPoint(txt, newend += 1);
		}
	}

	XBell (XtDisplay (toplevel), 50);
}

/* ARGSUSED */
void Reset (widget, closure, callData)
Widget widget;
caddr_t closure;
caddr_t callData;
{
	makeredirfile (app_resource.filename, homedir);
}

/* ARGSUSED */
void Delete (widget, closure, callData) 
Widget widget;
caddr_t closure;
caddr_t callData;
{
	XtVaSetValues (txt, XtNstring, "", NULL);
}


crt_txt (wid, height)
Dimension wid, height;
{
	txt = XtVaCreateManagedWidget(NULL,
				      asciiTextWidgetClass,
				      topform,
				      XtNtype,	XawAsciiString,
				      XtNscrollVertical,
				      		XawtextScrollWhenNeeded,
				      XtNheight,	height,
				      XtNwidth,	wid,
				      XtNeditType,	XawtextAppend,
				      XtNfromHoriz,	NULL,
				      XtNfromVert,	box,
				      XtNtop,	XtChainTop,
				      XtNbottom,	XtChainBottom,
				      XtNright,	XtChainRight,
				      XtNleft,	XtChainLeft,
				      NULL);

}