--- ray/src/rt/x11.c 1995/09/29 20:20:37 2.25 +++ ray/src/rt/x11.c 2004/03/30 16:13:01 2.32 @@ -1,19 +1,14 @@ -/* Copyright (c) 1995 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: x11.c,v 2.32 2004/03/30 16:13:01 schorsch Exp $"; #endif - /* * x11.c - driver for X-windows version 11 - * - * Jan 1990 */ -#include -#include +#include "copyright.h" + +#include "standard.h" #include -#include #ifdef sparc #include #include @@ -27,6 +22,7 @@ static char SCCSid[] = "$SunId$ LBL"; #include #include +#include "platform.h" #include "color.h" #include "driver.h" #include "x11twind.h" @@ -84,28 +80,44 @@ static Colormap ourmap = 0; /* our color map */ static int inpcheck; /* whence to check input */ -extern char *malloc(); +static void x11_errout(char *msg); -static int x11_close(), x11_clear(), x11_paintr(), x11_errout(), - x11_getcur(), x11_comout(), x11_comin(), x11_flush(); +static dr_closef_t x11_close; +static dr_clearf_t x11_clear; +static dr_paintrf_t x11_paintr; +static dr_getcurf_t x11_getcur; +static dr_comoutf_t x11_comout; +static dr_cominf_t x11_comin; +static dr_flushf_t x11_flush; -static int std_comin(), std_comout(); +static dr_cominf_t std_comin; +static dr_comoutf_t std_comout; static struct driver x11_driver = { x11_close, x11_clear, x11_paintr, x11_getcur, NULL, NULL, x11_flush, 1.0 }; -static int getpixels(), xnewcolr(), freepixels(), resizewindow(), - getevent(), getkey(), fixwindow(), x11_getc(); -static unsigned long true_pixel(); +static dr_getchf_t x11_getc; +static void freepixels(void); +static int getpixels(void); +static dr_newcolrf_t xnewcolr; +static unsigned long true_pixel(COLOR col); +static void getevent(void); +static void getkey(XKeyPressedEvent *ekey); +static void fixwindow(XExposeEvent *eexp); +static void resizewindow(XConfigureEvent *ersz); -struct driver * -x11_init(name, id) /* initialize driver */ -char *name, *id; +extern dr_initf_t x11_init; /* XXX this should be in a seperate header file */ + + +extern struct driver * +x11_init( /* initialize driver */ + char *name, + char *id +) { - extern char *getenv(); char *gv; int nplanes; XSetWindowAttributes ourwinattr; @@ -114,29 +126,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); @@ -154,7 +166,7 @@ char *name, *id; else /* "x11d" */ { comheight = 0; #ifndef FNDELAY - stderr_v("warning: x11d driver not fully functional on this machine\n"); + eputs("warning: x11d driver not fully functional on this machine\n"); #endif } /* open window */ @@ -169,7 +181,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); @@ -198,26 +210,26 @@ 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); } -static -x11_close() /* close our display */ +static void +x11_close(void) /* 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) { @@ -235,9 +247,11 @@ x11_close() /* close our display */ } -static -x11_clear(xres, yres) /* clear our display */ -int xres, yres; +static void +x11_clear( /* clear our display */ + int xres, + int yres +) { /* check limits */ if (xres < MINWIDTH) @@ -256,11 +270,12 @@ int xres, yres; } XClearWindow(ourdisplay, gwind); /* reinitialize color table */ - if (ourvinfo.class == PseudoColor || ourvinfo.class == GrayScale) + 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 */ if (comline != NULL) xt_close(comline); @@ -268,7 +283,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); @@ -281,10 +296,14 @@ int xres, yres; } -static -x11_paintr(col, xmin, ymin, xmax, ymax) /* fill a rectangle */ -COLOR col; -int xmin, ymin, xmax, ymax; +static void +x11_paintr( /* fill a rectangle */ + COLOR col, + int xmin, + int ymin, + int xmax, + int ymax +) { unsigned long pixel; @@ -300,8 +319,8 @@ int xmin, ymin, xmax, ymax; } -static -x11_flush() /* flush output */ +static void +x11_flush(void) /* flush output */ { char buf[256]; int n; @@ -318,7 +337,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; @@ -336,9 +355,11 @@ x11_flush() /* flush output */ } -static -x11_comin(inp, prompt) /* read in a command line */ -char *inp, *prompt; +static void +x11_comin( /* read in a command line */ + char *inp, + char *prompt +) { if (prompt != NULL) { x11_flush(); /* make sure we get everything */ @@ -352,11 +373,12 @@ char *inp, *prompt; } -static -x11_comout(outp) /* output a string to command line */ -char *outp; +static void +x11_comout( /* output a string to command line */ + char *outp +) { - if (comline == NULL) + if (comline == NULL || outp == NULL || !outp[0]) return; xt_puts(outp, comline); if (outp[strlen(outp)-1] == '\n') @@ -364,21 +386,22 @@ char *outp; } -static -x11_errout(msg) /* output an error message */ -char *msg; +static void +x11_errout( /* output an error message */ + char *msg +) { - stderr_v(msg); /* send to stderr also! */ + eputs(msg); /* send to stderr also! */ x11_comout(msg); } -static -std_comin(inp, prompt) /* read in command line from stdin */ -char *inp, *prompt; +static void +std_comin( /* read in command line from stdin */ + char *inp, + char *prompt +) { - extern char *gets(); - if (prompt != NULL) { if (fromcombuf(inp, &x11_driver)) return; @@ -388,7 +411,7 @@ char *inp, *prompt; #ifdef FNDELAY if (inpcheck == IC_READ) { /* turn off FNDELAY */ if (fcntl(fileno(stdin), F_SETFL, 0) < 0) { - stderr_v("cannot change input mode\n"); + eputs("cannot change input mode\n"); quit(1); } inpcheck = IC_IOCTL; @@ -404,9 +427,10 @@ char *inp, *prompt; } -static -std_comout(outp) /* write out string to stdout */ -char *outp; +static void +std_comout( /* write out string to stdout */ + char *outp +) { fputs(outp, stdout); fflush(stdout); @@ -414,8 +438,10 @@ char *outp; static int -x11_getcur(xp, yp) /* get cursor position */ -int *xp, *yp; +x11_getcur( /* get cursor position */ + int *xp, + int *yp +) { while (XGrabPointer(ourdisplay, gwind, True, ButtonPressMask, GrabModeAsync, GrabModeAsync, None, pickcursor, @@ -442,10 +468,13 @@ int *xp, *yp; } -static -xnewcolr(ndx, r, g, b) /* enter a color into hardware table */ -int ndx; -int r, g, b; +static void +xnewcolr( /* enter a color into hardware table */ + int ndx, + int r, + int g, + int b +) { XColor xcolor; @@ -460,7 +489,7 @@ int r, g, b; static int -getpixels() /* get the color map */ +getpixels(void) /* get the color map */ { XColor thiscolor; register int i, j; @@ -482,7 +511,7 @@ loop: return(ncolors = 0); if (XAllocColorCells(ourdisplay,ourmap,0,NULL,0,pixval,ncolors)) break; - free((char *)pixval); + free((void *)pixval); pixval = NULL; } if (pixval == NULL) { @@ -511,13 +540,13 @@ loop: } -static -freepixels() /* free our pixels */ +static void +freepixels(void) /* free our pixels */ { if (ncolors == 0) return; XFreeColors(ourdisplay,ourmap,pixval,ncolors,0L); - free((char *)pixval); + free((void *)pixval); pixval = NULL; ncolors = 0; if (ourmap != DefaultColormap(ourdisplay,ourscreen)) @@ -527,8 +556,9 @@ freepixels() /* free our pixels */ static unsigned long -true_pixel(col) /* return true pixel value for color */ -COLOR col; +true_pixel( /* return true pixel value for color */ + COLOR col +) { unsigned long rval; BYTE rgb[3]; @@ -542,7 +572,7 @@ COLOR col; static int -x11_getc() /* get a command character */ +x11_getc(void) /* get a command character */ { while (c_last <= c_first) { c_first = c_last = 0; /* reset */ @@ -553,8 +583,8 @@ x11_getc() /* get a command character */ } -static -getevent() /* get next event */ +static void +getevent(void) /* get next event */ { XNextEvent(ourdisplay, levptr(XEvent)); switch (levptr(XEvent)->type) { @@ -567,11 +597,12 @@ getevent() /* get next event */ break; case MapNotify: if (ourvinfo.class == PseudoColor || - ourvinfo.class == GrayScale) + ourvinfo.class == GrayScale) { if (getpixels() == 0) - stderr_v("cannot allocate colors\n"); + eputs("cannot allocate colors\n"); else new_ctab(ncolors); + } mapped = 1; break; case Expose: @@ -586,9 +617,10 @@ getevent() /* get next event */ } -static -getkey(ekey) /* get input key */ -register XKeyPressedEvent *ekey; +static void +getkey( /* get input key */ + register XKeyPressedEvent *ekey +) { register int n; @@ -599,9 +631,10 @@ register XKeyPressedEvent *ekey; } -static -fixwindow(eexp) /* repair damage to window */ -register XExposeEvent *eexp; +static void +fixwindow( /* repair damage to window */ + register XExposeEvent *eexp +) { char buf[80]; @@ -617,9 +650,10 @@ register XExposeEvent *eexp; } -static -resizewindow(ersz) /* resize window */ -register XConfigureEvent *ersz; +static void +resizewindow( /* resize window */ + register XConfigureEvent *ersz +) { if (ersz->width == gwidth && ersz->height-comheight == gheight) return;