--- ray/src/rt/x11.c 1994/09/12 15:57:55 2.17 +++ ray/src/rt/x11.c 1994/12/12 16:47:29 2.23 @@ -13,6 +13,12 @@ static char SCCSid[] = "$SunId$ LBL"; #include #include #include +#include +#ifdef sparc +#include +#include +#include +#endif #include #include @@ -69,8 +75,14 @@ static GC ourgc = 0; /* our graphics context for dr static Colormap ourmap = 0; /* our color map */ -extern char *malloc(), *getcombuf(); +#define IC_X11 0 +#define IC_IOCTL 1 +#define IC_READ 2 +static int inpcheck; /* whence to check input */ + +extern char *malloc(); + static int x11_close(), x11_clear(), x11_paintr(), x11_errout(), x11_getcur(), x11_comout(), x11_comin(), x11_flush(); @@ -129,7 +141,7 @@ char *name, *id; } /* set gamma */ if ((gv = XGetDefault(ourdisplay, "radiance", "gamma")) != NULL - || (gv = getenv("GAMMA")) != NULL) + || (gv = getenv("DISPLAY_GAMMA")) != NULL) make_gmap(atof(gv)); else make_gmap(GAMMA); @@ -182,10 +194,12 @@ char *name, *id; cmdvec = x11_comout; if (wrnvec != NULL) wrnvec = x11_errout; + inpcheck = IC_X11; } else { x11_driver.comin = std_comin; x11_driver.comout = std_comout; cmdvec = std_comout; + inpcheck = IC_IOCTL; } return(&x11_driver); } @@ -282,19 +296,36 @@ int xmin, ymin, xmax, ymax; static x11_flush() /* flush output */ { + char buf[256]; int n; /* check for input */ XNoOp(ourdisplay); n = XPending(ourdisplay); /* from X server */ while (n-- > 0) getevent(); - if (x11_driver.comin == std_comin) { /* from stdin */ +#ifdef FNDELAY + if (inpcheck == IC_IOCTL) { /* from stdin */ +#ifdef FIONREAD if (ioctl(fileno(stdin), FIONREAD, &n) < 0) { - stderr_v("ioctl error on stdin\n"); - quit(1); +#else + if (1) { +#endif + if (fcntl(fileno(stdin), F_SETFL, FNDELAY) < 0) { + stderr_v("Cannot change input mode\n"); + quit(1); + } + inpcheck = IC_READ; + } else + x11_driver.inpready += n; + } + if (inpcheck == IC_READ) { + n = read(fileno(stdin), buf, sizeof(buf)-1); + if (n > 0) { + buf[n] = '\0'; + tocombuf(buf, &x11_driver); } - x11_driver.inpready += n; } +#endif } @@ -362,6 +393,7 @@ std_comout(outp) /* write out string to stdout */ char *outp; { fputs(outp, stdout); + fflush(stdout); } @@ -555,10 +587,13 @@ static fixwindow(eexp) /* repair damage to window */ register XExposeEvent *eexp; { + char buf[80]; + if (eexp->window == gwind) { - sprintf(getcombuf(&x11_driver), "repaint %d %d %d %d\n", + sprintf(buf, "repaint %d %d %d %d\n", eexp->x, gheight - eexp->y - eexp->height, eexp->x + eexp->width, gheight - eexp->y); + tocombuf(buf, &x11_driver); } else if (eexp->window == comline->w) { if (eexp->count == 0) xt_redraw(comline); @@ -578,5 +613,5 @@ register XConfigureEvent *ersz; x11_driver.xsiz = gwidth < MINWIDTH ? MINWIDTH : gwidth; x11_driver.ysiz = gheight < MINHEIGHT ? MINHEIGHT : gheight; - strcpy(getcombuf(&x11_driver), "new\n"); + tocombuf("new\n", &x11_driver); }