--- ray/src/rt/x11.c 1994/12/12 11:22:20 2.22 +++ ray/src/rt/x11.c 1997/11/11 20:03:02 2.27 @@ -1,4 +1,4 @@ -/* Copyright (c) 1992 Regents of the University of California */ +/* Copyright (c) 1995 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -10,10 +10,16 @@ static char SCCSid[] = "$SunId$ LBL"; * Jan 1990 */ -#include -#include +#include "standard.h" #include -#include +#ifdef sparc +#include +#include +#include +#endif +#if !defined(FNDELAY) && defined(O_NONBLOCK) +#define FNDELAY O_NONBLOCK +#endif #include #include @@ -106,29 +112,29 @@ char *name, *id; /* open display server */ ourdisplay = XOpenDisplay(NULL); if (ourdisplay == NULL) { - stderr_v("cannot open X-windows; DISPLAY variable set?\n"); + eputs("cannot open X-windows; DISPLAY variable set?\n"); return(NULL); } /* find a usable visual */ nplanes = DisplayPlanes(ourdisplay, ourscreen); if (XMatchVisualInfo(ourdisplay,ourscreen, - 24,TrueColor,&ourvinfo) || + nplanes>12?nplanes:24,TrueColor,&ourvinfo) || XMatchVisualInfo(ourdisplay,ourscreen, - 24,DirectColor,&ourvinfo)) { + nplanes>12?nplanes:24,DirectColor,&ourvinfo)) { ourblack = 0; ourwhite = ourvinfo.red_mask | ourvinfo.green_mask | ourvinfo.blue_mask ; } else { if (nplanes < 4) { - stderr_v("not enough colors\n"); + eputs("not enough colors\n"); return(NULL); } if (!XMatchVisualInfo(ourdisplay,ourscreen, nplanes,PseudoColor,&ourvinfo) && !XMatchVisualInfo(ourdisplay,ourscreen, nplanes,GrayScale,&ourvinfo)) { - stderr_v("unsupported visual type\n"); + eputs("unsupported visual type\n"); return(NULL); } ourblack = BlackPixel(ourdisplay,ourscreen); @@ -143,8 +149,12 @@ char *name, *id; /* X11 command line or no? */ if (!strcmp(name, "x11")) comheight = COMHEIGHT; - else /* "x11d" */ + else /* "x11d" */ { comheight = 0; +#ifndef FNDELAY + eputs("warning: x11d driver not fully functional on this machine\n"); +#endif + } /* open window */ ourwinattr.background_pixel = ourblack; ourwinattr.border_pixel = ourblack; @@ -157,7 +167,7 @@ char *name, *id; BORWIDTH, ourvinfo.depth, InputOutput, ourvinfo.visual, CWBackPixel|CWBorderPixel|CWColormap, &ourwinattr); if (gwind == 0) { - stderr_v("cannot create window\n"); + eputs("cannot create window\n"); return(NULL); } XStoreName(ourdisplay, gwind, id); @@ -186,14 +196,14 @@ char *name, *id; if (comheight) { x11_driver.comin = x11_comin; x11_driver.comout = x11_comout; - cmdvec = x11_comout; - if (wrnvec != NULL) - wrnvec = x11_errout; + erract[COMMAND].pf = x11_comout; + if (erract[WARNING].pf != NULL) + erract[WARNING].pf = x11_errout; inpcheck = IC_X11; } else { x11_driver.comin = std_comin; x11_driver.comout = std_comout; - cmdvec = std_comout; + erract[COMMAND].pf = std_comout; inpcheck = IC_IOCTL; } return(&x11_driver); @@ -203,9 +213,9 @@ char *name, *id; static x11_close() /* close our display */ { - cmdvec = NULL; /* reset error vectors */ - if (wrnvec != NULL) - wrnvec = stderr_v; + erract[COMMAND].pf = NULL; /* reset error vectors */ + if (erract[WARNING].pf != NULL) + erract[WARNING].pf = wputs; if (ourdisplay == NULL) return; if (comline != NULL) { @@ -246,7 +256,7 @@ int xres, yres; /* reinitialize color table */ if (ourvinfo.class == PseudoColor || ourvinfo.class == GrayScale) if (getpixels() == 0) - stderr_v("cannot allocate colors\n"); + eputs("cannot allocate colors\n"); else new_ctab(ncolors); /* get new command line */ @@ -256,7 +266,7 @@ int xres, yres; comline = xt_open(ourdisplay, gwind, 0, gheight, gwidth, comheight, 0, ourblack, ourwhite, COMFN); if (comline == NULL) { - stderr_v("Cannot open command line window\n"); + eputs("cannot open command line window\n"); quit(1); } XSelectInput(ourdisplay, comline->w, ExposureMask); @@ -306,7 +316,7 @@ x11_flush() /* flush output */ if (1) { #endif if (fcntl(fileno(stdin), F_SETFL, FNDELAY) < 0) { - stderr_v("Cannot change input mode\n"); + eputs("cannot change input mode\n"); quit(1); } inpcheck = IC_READ; @@ -356,7 +366,7 @@ static x11_errout(msg) /* output an error message */ char *msg; { - stderr_v(msg); /* send to stderr also! */ + eputs(msg); /* send to stderr also! */ x11_comout(msg); } @@ -371,8 +381,17 @@ char *inp, *prompt; if (fromcombuf(inp, &x11_driver)) return; if (!x11_driver.inpready) - fputs(prompt, stdout); + std_comout(prompt); } +#ifdef FNDELAY + if (inpcheck == IC_READ) { /* turn off FNDELAY */ + if (fcntl(fileno(stdin), F_SETFL, 0) < 0) { + eputs("cannot change input mode\n"); + quit(1); + } + inpcheck = IC_IOCTL; + } +#endif if (gets(inp) == NULL) { strcpy(inp, "quit"); return; @@ -548,7 +567,7 @@ getevent() /* get next event */ if (ourvinfo.class == PseudoColor || ourvinfo.class == GrayScale) if (getpixels() == 0) - stderr_v("Cannot allocate colors\n"); + eputs("cannot allocate colors\n"); else new_ctab(ncolors); mapped = 1;