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

📄 xwho.c

📁 ftam等标准协议服务器和客户端的源代码。
💻 C
📖 第 1 页 / 共 2 页
字号:
		break;	    case ReparentNotify:		if (debug)		    (void) fprintf (stderr, "ReparentNotify\n");		break;	    default: 		if (debug)		    (void) fprintf (stderr, "Event %d\n", xe -> type);		break;	}    }}/*  */static init_X (){    char    def[BUFSIZ];    myframe.bdrwidth = bwidth;    myframe.height = largest_h + 100;    if (myframe.height + bwidth * 2 > DisplayHeight (DISP, SCRN))	myframe.height = DisplayHeight (DISP, SCRN) - bwidth * 2;    myframe.width = largest_w + 100;    if (myframe.width + bwidth * 2 > DisplayWidth (DISP, SCRN))	myframe.width = DisplayWidth (DISP, SCRN) - bwidth * 2;    myframe.x = DisplayWidth (DISP, SCRN) - (myframe.width + bwidth * 2);    myframe.y = 0;    (void) sprintf (def, "=%dx%d+%d+%d", myframe.width, myframe.height,		    myframe.x, myframe.y);    if (debug)	(void) fprintf (stderr, "def: %s, myframe: =%dx%d+%d+%d/%d\n", def,		 myframe.width, myframe.height, myframe.x, myframe.y,		 myframe.bdrwidth);    hints.width = largest_w + 100;    hints.height = largest_h + 100;    hints.x = hints.y = 0;    hints.flags = PSize | PPosition;    xswattrs.border_pixel = bdrpix;    xswattrs.background_pixel = backpix;    xswattrs_mask = CWBackPixel | CWBorderPixel;    mywindow = XCreateWindow (DISP, RootWindow (DISP, SCRN),			      myframe.x, myframe.y,			      myframe.width, myframe.height,			      myframe.bdrwidth,			      0, InputOutput, (Visual *) CopyFromParent,			      xswattrs_mask, &xswattrs);    XSetStandardProperties (DISP, mywindow, myname, "X Who", None,			    (char **) 0, 0, &hints);    XSelectInput (DISP, mywindow, ExposureMask | StructureNotifyMask);    XMapWindow (DISP, mywindow);    mapped = 0;}/*  */static	layout_X (){    int     h;    register struct face   *fp;    register struct host   *hp;    XCharStruct mychar;    h = largest_w = 0;    for (hp = hosts; hp; hp = hp -> h_next) {	int     hh,	        hw;	hh = hw = 0;	if (hp -> h_window == NULL || hp -> h_frame.y != h) {	    int	    direction_return,		    font_ascent_return,		    font_descent_return;	    hp -> h_frame.bdrwidth = 2;	    XTextExtents (myfont, hp -> h_string, strlen (hp -> h_string),			  &direction_return, &font_ascent_return,			  &font_descent_return, &mychar);	    hp -> h_ascent = mychar.ascent;	    hp -> h_frame.height = mychar.ascent + mychar.descent;	    hp -> h_frame.border = backpix;	    hp -> h_frame.background = backpix;	    hp -> h_frame.x = 0;	    hp -> h_frame.y = h;	    hp -> h_update = 1;	}	else	    hp -> h_update = 0;	h += hp -> h_frame.height + 2 * hp -> h_frame.bdrwidth;	for (fp = hp -> h_faces; fp; fp = fp -> f_next)	    if (fp -> f_imap && fp -> f_imap -> height > hh)		hh = fp -> f_imap -> height;	for (fp = hp -> h_faces; fp; fp = fp -> f_next)	    if (fp -> f_imap) {		if (fp -> f_window == NULL			|| fp -> f_frame.height != hh			|| fp -> f_frame.width != fp -> f_imap -> width			|| fp -> f_frame.x != hw			|| fp -> f_frame.y != h) {		    fp -> f_frame.bdrwidth = bwidth;		    fp -> f_frame.height = hh;		    fp -> f_frame.width = fp -> f_imap -> width;		    fp -> f_frame.border = backpix;		    fp -> f_frame.background = backpix;		    fp -> f_frame.x = hw;		    fp -> f_frame.y = h;		    fp -> f_update = 1;		}		else		    fp -> f_update = 0;		hw += fp -> f_imap -> width + bwidth * 2;	    }	    else		fp -> f_update = 0;	if (hw > largest_w)	    largest_w = hw;	if (hp -> h_frame.width > largest_w)	    largest_w = hp -> h_frame.width;	if (hw > 0)	    h += hh + 2;	else {	    h -= hp -> h_frame.height + 2 * hp -> h_frame.bdrwidth;	    hp -> h_update = 0;	    if (hp -> h_window) {		XFreeGC (DISP, hp -> h_gc);		XDestroyWindow (DISP, hp -> h_window);		hp -> h_window = NULL;	    }	}    }    largest_h = h;}/*  */static	display_top (){    if (debug)	(void) fprintf (stderr, "top window\n");}static	display_host (hp)register struct host *hp;{    if (debug)	(void) fprintf (stderr, "%s:\n", hp -> h_name);    XDrawImageString (DISP, hp -> h_window, hp -> h_gc, 0, hp -> h_ascent,		 hp -> h_string, strlen (hp -> h_string));}/*  */static	display_face (fp)register struct face *fp;{    int     sx,            sy,            dx,            dy;    unsigned int    h,		    w;    register struct type_IMAGE_Image *im = fp -> f_imap;    register OpaqueFrame *xm = &fp -> f_frame;    XImage *image;        sx = max (im -> width - (int) xm -> width, 0) / 2;    sy = max (im -> height - (int) xm -> height, 0) / 2;    dx = max ((int) xm -> width - im -> width, 0) / 2;    dy = max ((int) xm -> height - im -> height, 0) / 2;    w = min (xm -> width, im -> width);    h = min (xm -> height, im -> height);    if (debug) {	(void) fprintf (stderr, "im: %dx%d frame:%dx%d\n",		 im -> width, im -> height, xm -> width, xm -> height);	(void) fprintf (stderr, "sx=%d sy=%d dx=%d dy=%d w=%d h=%d\n",		sx, sy, dx, dy, w, h);    }    image = XCreateImage (DISP, DefaultVisual (DISP, SCRN), 1, XYBitmap, 0,			  im -> data -> qb_forw -> qb_data,			  (unsigned int) im -> width,			  (unsigned int) im -> height, 8, 0);    if (image == NULL)	adios (NULLCP, "XCreateImage failed");    image -> byte_order = image -> bitmap_bit_order = LSBFirst;    XClearWindow (DISP, fp -> f_window);    XPutImage (DISP, fp -> f_window, forepix, image, sx, sy, dx, dy, w, h);    XDestroyImage (image);}/*  */static int facecmp (f1, f2)struct face **f1,	    **f2;{    return strcmp ((*f1) -> f_name, (*f2) -> f_name);}static int hostcmp (h1, h2)struct host **h1,	    **h2;{    return strcmp ((*h1) -> h_name, (*h2) -> h_name);}static	read_X (){    int	    fd,	    n;    long    now;    register struct dirent *dp;    register struct face *fp,			**fpp;    register struct host *hp,			**hpp;    struct whod wds;    register struct whod *wd = &wds;    register struct whoent *we;    static DIR *dd = NULL;    (void) time (&now);    for (hp = hosts; hp; hp = hp -> h_next) {	hp -> h_up = 0;	for (fp = hp -> h_faces; fp; fp = fp -> f_next)	    fp -> f_active = 0;    }	    if (dd == NULL) {	if (chdir ("/usr/spool/rwho") == NOTOK)	    adios ("/usr/spool/rwho", "unable to change directory to");	if ((dd = opendir (".")) == NULL)	    adios ("/usr/spool/rwho", "unable to read");    }    else	rewinddir (dd);    while (dp = readdir (dd)) {	if (dp -> d_ino == 0 || strncmp (dp -> d_name, "whod.", 5) != 0)	    continue;	if ((fd = open (dp -> d_name, O_RDONLY)) == NOTOK)	    continue;	n = read (fd, (char *) wd, sizeof *wd);	(void) close (fd);	if ((n -= sizeof *wd - sizeof wd -> wd_we) < 0)	    continue;	if (now - wd -> wd_recvtime > 5 * 60 || n < sizeof *we)	    continue;	for (hp = hosts; hp; hp = hp -> h_next)	    if (strncmp (hp -> h_name, wd -> wd_hostname,			sizeof wd -> wd_hostname) == 0)		break;	if (hp == NULL) {	    if ((hp = (struct host *) calloc (1, sizeof *hp)) == NULL)		adios (NULLCP, "out of memory");	    hp -> h_next = hosts;	    hosts = hp;	    (void) strncpy (hp -> h_name, wd -> wd_hostname,		    sizeof wd -> wd_hostname);	    (void) sprintf (hp -> h_string, "%s:", hp -> h_name);	    hp -> h_frame.width = XTextWidth (myfont, hp -> h_string,					      strlen (hp -> h_string));	}	hp -> h_up = 1;	for (we = wd -> wd_we, n = n / sizeof *we; n > 0; we++, n--) {	    if (we -> we_idle > 60 * 60)		continue;	    for (fp = hp -> h_faces; fp; fp = fp -> f_next)		if (strncmp (fp -> f_name, we -> we_utmp.out_name,			    sizeof we -> we_utmp.out_name) == 0)		    break;	    if (fp == NULL) {		if ((fp = (struct face *) calloc (1, sizeof *fp)) == NULL)		    adios (NULLCP, "out of memory");		fp -> f_next = hp -> h_faces;		hp -> h_faces = fp;		(void) strncpy (fp -> f_name, we -> we_utmp.out_name,			sizeof we -> we_utmp.out_name);		if (display_this_host (hp -> h_name)		        && (fp -> f_imap = fetch_image (fp -> f_name, NULLCP))				    == NULL) {		    if (recording)			LLOG (pgm_log, LLOG_NOTICE,			      ("no image for \"%s\" \"%s\"",			       hp -> h_name, fp -> f_name));		}	    }	    fp -> f_active = 1;	}    }    for (hpp = &hosts; hp = *hpp;) {	for (fpp = &hp -> h_faces; fp = *fpp;) {	    if (!hp -> h_up || !fp -> f_active) {		*fpp = fp -> f_next;		if (fp -> f_window)		    XDestroyWindow (DISP, fp -> f_window);		free ((char *) fp);		continue;	    }	    fpp = &fp -> f_next;	}	if (!hp -> h_up || hp -> h_faces == NULL) {	    *hpp = hp -> h_next;	    if (hp -> h_window) {		XFreeGC (DISP, hp -> h_gc);		XDestroyWindow (DISP, hp -> h_window);	    }	    free ((char *) hp);	}	else	    hpp = &hp -> h_next;    }    {	register int    i;	register struct host **hq;	i = 0;	for (hp = hosts; hp; hp = hp -> h_next) {	    register int j;	    register struct face **fq;	    i++, j = 0;	    for (fp = hp -> h_faces; fp; fp = fp -> f_next)		j++;	    if (j > 1) {		register struct face **faces;		if ((faces = (struct face **)		     		calloc ((unsigned) j, sizeof *faces)) == NULL)		    continue;		for (fp = hp -> h_faces, fq = faces;			*fq = fp;			fp = fp -> f_next, fq++)		    continue;		qsort ((char *) faces, j, sizeof *faces, (IFP)facecmp);		for (fq = faces, fpp = &hp -> h_faces;		        *fpp = *fq;		        fq++, fpp = &(*fpp) -> f_next)		    continue;		free ((char *) faces);	    }	}	if (i > 1) {	    register struct host **hostz;	    if ((hostz = (struct host **)			    calloc ((unsigned) i, sizeof *hostz)) == NULL)		goto out;	    for (hp = hosts, hq = hostz; *hq = hp; hp = hp -> h_next, hq++)		continue;	    qsort ((char *) hostz, i, sizeof *hostz, (IFP)hostcmp);	    for (hq = hostz, hpp = &hosts;		    *hpp = *hq;		    hq++, hpp = &(*hpp) -> h_next)		continue;	    free ((char *) hostz);	}    }out: ;}/*  */static int  display_this_host (n)register char *n;{    register char **ap;    if (host_list == host_end)	return 1;    for (ap = host_list; ap < host_end; ap++)	if (strcmp (*ap, n) == 0)	    return (!dont_list);    return dont_list;}

⌨️ 快捷键说明

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