--- ray/src/rt/x11.c 1995/12/05 10:54:39 2.26
+++ ray/src/rt/x11.c 2003/02/22 02:07:29 2.29
@@ -1,19 +1,69 @@
-/* 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.29 2003/02/22 02:07:29 greg Exp $";
#endif
-
/*
* x11.c - driver for X-windows version 11
+ */
+
+/* ====================================================================
+ * The Radiance Software License, Version 1.0
*
- * Jan 1990
+ * Copyright (c) 1990 - 2002 The Regents of the University of California,
+ * through Lawrence Berkeley National Laboratory. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes Radiance software
+ * (http://radsite.lbl.gov/)
+ * developed by the Lawrence Berkeley National Laboratory
+ * (http://www.lbl.gov/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
+ * and "The Regents of the University of California" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact radiance@radsite.lbl.gov.
+ *
+ * 5. Products derived from this software may not be called "Radiance",
+ * nor may "Radiance" appear in their name, without prior written
+ * permission of Lawrence Berkeley National Laboratory.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of Lawrence Berkeley National Laboratory. For more
+ * information on Lawrence Berkeley National Laboratory, please see
+ * .
*/
-#include
-#include
+#include "standard.h"
#include
-#include
#ifdef sparc
#include
#include
@@ -84,20 +134,21 @@ static Colormap ourmap = 0; /* our color map */
static int inpcheck; /* whence to check input */
-extern char *malloc();
+static int x11_getcur();
-static int x11_close(), x11_clear(), x11_paintr(), x11_errout(),
- x11_getcur(), x11_comout(), x11_comin(), x11_flush();
+static void x11_close(), x11_clear(), x11_paintr(), x11_errout(),
+ x11_comout(), x11_comin(), x11_flush();
-static int std_comin(), std_comout();
+static void std_comin(), 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 int getpixels(), x11_getc();
+static void xnewcolr(), freepixels(), resizewindow(),
+ getevent(), getkey(), fixwindow();
static unsigned long true_pixel();
@@ -105,7 +156,6 @@ struct driver *
x11_init(name, id) /* initialize driver */
char *name, *id;
{
- extern char *getenv();
char *gv;
int nplanes;
XSetWindowAttributes ourwinattr;
@@ -114,7 +164,7 @@ 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 */
@@ -129,14 +179,14 @@ char *name, *id;
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 +204,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 +219,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 +248,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
+static void
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) {
@@ -235,7 +285,7 @@ x11_close() /* close our display */
}
-static
+static void
x11_clear(xres, yres) /* clear our display */
int xres, yres;
{
@@ -258,7 +308,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 */
@@ -268,7 +318,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,7 +331,7 @@ int xres, yres;
}
-static
+static void
x11_paintr(col, xmin, ymin, xmax, ymax) /* fill a rectangle */
COLOR col;
int xmin, ymin, xmax, ymax;
@@ -300,7 +350,7 @@ int xmin, ymin, xmax, ymax;
}
-static
+static void
x11_flush() /* flush output */
{
char buf[256];
@@ -318,7 +368,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,7 +386,7 @@ x11_flush() /* flush output */
}
-static
+static void
x11_comin(inp, prompt) /* read in a command line */
char *inp, *prompt;
{
@@ -352,11 +402,11 @@ char *inp, *prompt;
}
-static
+static void
x11_comout(outp) /* 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 +414,19 @@ char *outp;
}
-static
+static void
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);
}
-static
+static void
std_comin(inp, prompt) /* read in command line from stdin */
char *inp, *prompt;
{
- extern char *gets();
-
if (prompt != NULL) {
if (fromcombuf(inp, &x11_driver))
return;
@@ -388,7 +436,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,7 +452,7 @@ char *inp, *prompt;
}
-static
+static void
std_comout(outp) /* write out string to stdout */
char *outp;
{
@@ -442,7 +490,7 @@ int *xp, *yp;
}
-static
+static void
xnewcolr(ndx, r, g, b) /* enter a color into hardware table */
int ndx;
int r, g, b;
@@ -482,7 +530,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 +559,13 @@ loop:
}
-static
+static void
freepixels() /* 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))
@@ -553,7 +601,7 @@ x11_getc() /* get a command character */
}
-static
+static void
getevent() /* get next event */
{
XNextEvent(ourdisplay, levptr(XEvent));
@@ -569,7 +617,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;
@@ -586,7 +634,7 @@ getevent() /* get next event */
}
-static
+static void
getkey(ekey) /* get input key */
register XKeyPressedEvent *ekey;
{
@@ -599,7 +647,7 @@ register XKeyPressedEvent *ekey;
}
-static
+static void
fixwindow(eexp) /* repair damage to window */
register XExposeEvent *eexp;
{
@@ -617,7 +665,7 @@ register XExposeEvent *eexp;
}
-static
+static void
resizewindow(ersz) /* resize window */
register XConfigureEvent *ersz;
{