⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xwho.c

📁 ftam等标准协议服务器和客户端的源代码。
💻 C
📖 第 1 页 / 共 2 页
字号:
/* xwho.c - who for X windows */#ifndef	lintstatic char *rcsid = "$Header: /xtel/isode/isode/others/quipu/image/RCS/xwho.c,v 9.0 1992/06/16 12:43:24 isode Rel $";#endif/*  * $Header: /xtel/isode/isode/others/quipu/image/RCS/xwho.c,v 9.0 1992/06/16 12:43:24 isode Rel $ * * * $Log: xwho.c,v $ * Revision 9.0  1992/06/16  12:43:24  isode * Release 8.0 * *//* *				  NOTICE * *    Acquisition, use, and distribution of this module and related *    materials are subject to the restrictions of a license agreement. *    Consult the Preface in the User's Manual for the full terms of *    this agreement. * */#include <stdio.h>#include "imagesbr.h"#include <X11/Xlib.h>#include <X11/Xutil.h>#include "rwhod.h"#include <netdb.h>#include "general.h"#include "manifest.h"#include "sys.file.h"#include "usr.dirent.h"#define	NHOSTS	100/*    DATA */int	debug = 0;int	errsw = 0;static int  sleepsw = 60;static char  *host_list[NHOSTS + 1];	/* Hosts to (not) list */static char **host_end = host_list;static int    dont_list = 0;static char *myname = "xwho";static char *display = NULL;static char *geometry = NULL;/*  */typedef struct _frame {    short x, y;    unsigned int width, height;    unsigned int bdrwidth;    unsigned long border;    unsigned long background;}	OpaqueFrame;static Display *DISP;static int	SCRN;static int    mapped;static Window mywindow;static OpaqueFrame myframe;static char *fontname = "6x10";static XFontStruct *myfont;static int  bwidth;static XSizeHints hints;static XSetWindowAttributes xswattrs;static unsigned long xswattrs_mask;static unsigned long backpix, bdrpix;static GC  forepix, highpix;struct face {    char    f_name[8 + 1];    int	    f_active;    int	    f_update;    Window	f_window;    OpaqueFrame f_frame;    struct type_IMAGE_Image *f_imap;    struct face *f_next;};struct host {    char    h_name[32 + 1];    int	    h_up;    int	    h_update;    char    h_string[32 + 2];    Window  h_window;    GC	    h_gc;    int     h_ascent;    OpaqueFrame h_frame;    struct face *h_faces;    struct host *h_next;};static int largest_h, largest_w;static struct host *hosts;/*    MAIN *//* ARGSUSED */main (argc, argv, envp)int	argc;char  **argv,      **envp;{    int	    nfds;    fd_set  rfds;    arginit (argv);    if (errsw)	errsw = NOTOK;    update_X ();        FD_ZERO (&rfds);    nfds = ConnectionNumber (DISP) + 1;    FD_SET (ConnectionNumber (DISP), &rfds);    for (;;) {	fd_set	ifds;	ifds = rfds;	(void) xselect (nfds, &ifds, NULLFD, NULLFD, sleepsw);		update_X ();    }}/*    ARGINIT */arginit (vec)char  **vec;{    int	    n,	    nhosts;    register char  *ap,		   *cp,		   *lp;    register struct hostent *hp;    if (myname = rindex (*vec, '/'))	myname++;    if (myname == NULL || *myname == NULL)	myname = *vec;    isodetailor (myname, 1);    lp = NULL;    nhosts = 0;    for (vec++; ap = *vec; vec++)	if (*ap == '-')	    switch (*++ap) {		case 'd':		    debug++;		    break;		case 'e': 		    errsw++;		    break;		case 'l':		    if ((lp = *++vec) == NULL)			adios (NULLCP, "usage: %s -h local_dit", myname);		    break;		case 'r':		    recording++;		    break;		case 's':		    if ((ap = *++vec) == NULL			    || sscanf (ap, "%d", &sleepsw) != 1			    || sleepsw < 1)			adios (NULLCP, "usage: %s -s seconds", myname);		    break;		case 'n':		    dont_list++;		    break;		default: 		    adios (NULLCP, "unknown switch -%s", ap);	    }	else	    if (*ap == '=')		geometry = ap;	    else		if ((cp = rindex (ap, ':')) && sscanf (++cp, "%d", &n) == 1)		    display = ap;		else {		    if (nhosts++ >= NHOSTS)			adios (NULLCP, "too many hosts");		    if ((hp = gethostbyname (ap)) == NULL)			adios (NULLCP, "%s: unknown host", ap);		    if ((ap = malloc ((unsigned) (strlen (hp -> h_name) + 1)))			    == NULL)			adios (NULLCP, "out of memory");		    (void) strcpy (*host_end++ = ap, hp -> h_name);		}    init_aka (myname, 1, lp);    if (debug)	ll_dbinit (pgm_log, myname);    else	ll_hdinit (pgm_log, myname);    (void) ll_open (pgm_log);    if ((DISP = XOpenDisplay (display)) == NULL)	adios (NULLCP, "unable to open display \"%s\"",		XDisplayName (display));    SCRN = DefaultScreen (DISP);    forepix = XCreateGC (DISP, RootWindow (DISP, SCRN), 0L, (XGCValues *)NULL);    highpix = XCreateGC (DISP, RootWindow (DISP, SCRN), 0L, (XGCValues *)NULL);    XCopyGC (DISP, DefaultGC (DISP, SCRN), (1L<<(GCLastBit+1)) - 1, forepix);    XCopyGC (DISP, DefaultGC (DISP, SCRN), (1L<<(GCLastBit+1)) - 1, highpix);    if ((cp = XGetDefault (DISP, myname, "ReverseVideo"))	    && strcmp (cp, "on") == 0) {	XSetForeground(DISP, forepix, WhitePixel(DISP, SCRN));	XSetForeground(DISP, highpix, WhitePixel(DISP, SCRN));	backpix = BlackPixel(DISP, SCRN);	bdrpix  = WhitePixel(DISP, SCRN);	XSetFunction(DISP, forepix, GXcopyInverted);	XSetFunction(DISP, highpix, GXand);    }    else {	XSetForeground(DISP, forepix, BlackPixel(DISP, SCRN));	XSetForeground(DISP, highpix, BlackPixel(DISP, SCRN));	backpix = WhitePixel(DISP, SCRN);	bdrpix  = BlackPixel(DISP, SCRN);	XSetFunction(DISP, forepix, GXcopy);	XSetFunction(DISP, highpix, GXor);    }    XSetBackground (DISP, forepix, backpix);    XSetBackground (DISP, highpix, backpix);    if (cp = XGetDefault (DISP, myname, "BorderWidth"))	bwidth = atoi (cp);    else	bwidth = 2;    if (cp = XGetDefault (DISP, myname, "BodyFont"))	fontname = cp;    myfont = XLoadQueryFont (DISP, fontname);}/*    XWINDOWS */static	update_X (){    register struct host   *hp;    register struct face   *fp;    XGCValues gcvalues;    service_X ();    if (mywindow && !mapped)	return;    read_X ();    layout_X ();    if (mywindow == NULL)	init_X ();    for (hp = hosts; hp; hp = hp -> h_next) {	if (hp -> h_update && display_this_host (hp -> h_name)) {	    if (hp -> h_window) {		XFreeGC (DISP, hp -> h_gc);		XDestroyWindow (DISP, hp -> h_window);	    }	    if (debug)		(void) fprintf (stderr, "%s: %dx%d+%d+%d/%d\n",			hp -> h_name, hp -> h_frame.width,			hp -> h_frame.height, hp -> h_frame.x,			hp -> h_frame.y, hp -> h_frame.bdrwidth);	    hp -> h_window = XCreateSimpleWindow (DISP, mywindow,					hp -> h_frame.x,					hp -> h_frame.y,					hp -> h_frame.width,					hp -> h_frame.height,					hp -> h_frame.bdrwidth,					hp -> h_frame.border,					hp -> h_frame.background);	    XSelectInput (DISP, hp -> h_window, ExposureMask);	    XMapWindow (DISP, hp -> h_window);	    gcvalues.foreground = bdrpix;	    gcvalues.background = backpix;	    gcvalues.font = myfont -> fid;	    hp -> h_gc = XCreateGC (DISP, hp -> h_window,				    GCForeground | GCBackground | GCFont,				    &gcvalues);	}	for (fp = hp -> h_faces; fp; fp = fp -> f_next)	    if (fp -> f_update) {		if (fp -> f_window)		    XDestroyWindow (DISP, fp -> f_window);		if (debug)		    (void) fprintf (stderr, "%s: %dx%d+%d+%d/%d\n",			    fp -> f_name, fp -> f_frame.width,			    fp -> f_frame.height, fp -> f_frame.x,			    fp -> f_frame.y, fp -> f_frame.bdrwidth);		fp -> f_window = XCreateSimpleWindow(DISP, mywindow,					fp -> f_frame.x,					fp -> f_frame.y,					fp -> f_frame.width,					fp -> f_frame.height,					fp -> f_frame.bdrwidth,					fp -> f_frame.border,					fp -> f_frame.background);		XSelectInput (DISP, fp -> f_window, ExposureMask);		XMapWindow (DISP, fp -> f_window);	    }    }    service_X ();}/*  */static int  service_X (){    int	    wh,	    ww;    register Window w;    register struct face   *fp;    register struct host   *hp;    XEvent xevent;    register XEvent *xe = &xevent;    while (XPending (DISP)) {	XNextEvent (DISP, xe);	switch (xe -> type) {	    case Expose: 		if ((w = ((XExposeEvent *) xe) -> window) == mywindow) {		    display_top ();		    break;		}		for (hp = hosts; hp; hp = hp -> h_next) {		    if (!display_this_host (hp -> h_name))			continue;		    if (hp -> h_window == w) {			display_host (hp);			break;		    }		    for (fp = hp -> h_faces; fp; fp = fp -> f_next)			if (fp -> f_window == w)			    break;		    if (fp) {			display_face (fp);			break;		    }		}		break;	    case MapNotify:		if (debug)		    (void) fprintf (stderr, "MapNotify\n");		mapped = 1;		display_top ();		break;	    case ConfigureNotify:		if (debug)		    (void) fprintf (stderr, "ConfigureNotify %dx%d\n",			     ((XConfigureEvent *) xe) -> height,			     ((XConfigureEvent *) xe) -> width);		if (((XConfigureEvent *) xe) -> window == mywindow		    	&& (wh = ((XConfigureEvent *) xe) -> height) > 0		        && (ww = ((XConfigureEvent *) xe) -> width) > 0)		    myframe.height = wh, myframe.width = ww;		break;			    case UnmapNotify:		if (debug)		    (void) fprintf (stderr, "UnmapNotify\n");		mapped = 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -