Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!rutgers!ames!sdcsvax!ucbvax!unl::spa!psi From: psi@unl::spa (Salvador Pinto Abreu) Newsgroups: comp.windows.x Subject: xrload (part 3 of 6) Message-ID: <8708131205.AA05152@decwrl.dec.com> Date: Thu, 13-Aug-87 14:56:00 EDT Article-I.D.: decwrl.8708131205.AA05152 Posted: Thu Aug 13 14:56:00 1987 Date-Received: Sat, 15-Aug-87 08:44:44 EDT Sender: daemon@ucbvax.BERKELEY.EDU Distribution: world Organization: The ARPA Internet Lines: 230 #! /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 event-loop.c <<'END_OF_event-loop.c' X/**************************************************************************/ X/* */ X/* Main Event Loop */ X/* */ X/**************************************************************************/ X X#include "xrload.h" X Xvoid doit () X{ X for (;;) { X if (mapped) { X register int nsys = get_stats (stats); X show_stats (stats, nsys); X } X handle_X_events (); X } X} X Xhandle_X_events () X{ X struct timeval timeout; X int maxfds, fdmask, readfds, nfound; X XEvent event; X X if (dflag) printf ("in handle_X_event()\n"); X timeout.tv_sec = delay; X timeout.tv_usec = 0; X maxfds = dpyno() + 1; X fdmask = 1 << dpyno(); X X do { X if (XPending()) { X XNextEvent (&event); X switch (event.type) { X X case ExposeWindow: X mapped = TRUE; X show_stats (stats, nSystems); X break; X X case UnmapWindow: X mapped = FALSE; X break; X X default: X fprintf (stderr, "xrload: unexpected X event (%d)\n", X event.type); X exit(1); X } X } X X readfds = fdmask; X if ((nfound = select (maxfds, &readfds, NULL, NULL, &timeout)) < 0) { X perror ("select"); X exit (1); X } X if (dflag) printf ("select(...) -> %d\n", nfound); X } while (nfound); X} END_OF_event-loop.c if test 1223 -ne `wc -c globals.c <<'END_OF_globals.c' X/**************************************************************************/ X/* */ X/* Global Variables */ X/* */ X/**************************************************************************/ X X#include "xrload.h" X X#include "back.bitmap" X#include "down.bitmap" X X#define gray1_width 16 /* from gray1.bitmap */ X#define gray1_height 16 Xstatic short gray1_bits[] = { X 0x5555, 0xaaaa, 0x5555, 0xaaaa, X 0x5555, 0xaaaa, 0x5555, 0xaaaa, X 0x5555, 0xaaaa, 0x5555, 0xaaaa, X 0x5555, 0xaaaa, 0x5555, 0xaaaa}; X XPixmap GrayPixmap; XPixmap whitePixmap, blackPixmap; Xint whitePixel, blackPixel; X XBitmap_data gray1 = { gray1_width, gray1_height, 0, 0, gray1_bits }; XBitmap_data back = { back_width, back_height, X back_x_hot, back_y_hot, back_bits }; XBitmap_data down = { down_width, down_height, X down_x_hot, down_y_hot, down_bits }; X XFontInfo *theFont; XOpaqueFrame frame; XWindow mainWindow; XWindowInfo mainLoc; X Xchar *geometry=""; Xchar defGeometry[16]; X Xint minWidth, minHeight; XBitmap bitmap; X Xint mapped = TRUE; Xint nSystems = 0; Xint ncols = 0; Xint dflag = FALSE; Xint delay = DEFAULT_DELAY; Xint border_width = DEFAULT_BWIDTH; Xint same_scale = FALSE; Xchar *font_name = DEFAULT_FONT; Xint reverse = FALSE; Xint all_hosts = FALSE; Xint X_hosts = FALSE; Xchar *host_names[MAXSYS]; Xint ww, dd=DEFAULT_SPACING, hh, rr; X Xsys_stat stats[MAXSYS]; END_OF_globals.c if test 1386 -ne `wc -c hostname.c <<'END_OF_hostname.c' X/**************************************************************************/ X/* */ X/* Stuff to deal with host names */ X/* */ X/**************************************************************************/ X X#include "xrload.h" X X/* stolen from xhost.c */ X X/* X * get_hostname - Given an internet address, return a name (CHARON.MIT.EDU) X * or a string representing the address (18.58.0.13) if the name cannot X * be found. X */ X Xjmp_buf env; X Xchar *get_hostname (address) X struct in_addr address; X{ X struct hostent *hp = NULL; X int nameserver_lost(); X char *inet_ntoa(); X X/* X * gethostbyaddr can take a LONG time if the host does not exist. X * Assume that if it does not respond in NAMESERVER_TIMEOUT seconds X * that something is wrong and do not make the user wait. X * gethostbyaddr will continue after a signal, so we have to X * jump out of it. X */ X signal(SIGALRM, nameserver_lost); X alarm(8); X if (setjmp(env) == 0) { X hp = gethostbyaddr (&address, sizeof(struct in_addr), AF_INET); X } X alarm(0); X if (hp) X return (hp->h_name); X else return (inet_ntoa(address)); X} X Xnameserver_lost() X{ X longjmp(env, -1); X} END_OF_hostname.c if test 1186 -ne `wc -c