--- ray/src/px/xshowtrace.c 1992/12/11 18:28:43 2.5 +++ ray/src/px/xshowtrace.c 2005/04/19 18:44:22 2.11 @@ -1,19 +1,17 @@ -/* Copyright (c) 1991 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: xshowtrace.c,v 2.11 2005/04/19 18:44:22 greg Exp $"; #endif - /* * Display an image and watch the rays get traced. * * 9/21/90 Greg Ward */ +#include + #include "standard.h" +#include "paths.h" #include "view.h" -#include "resolu.h" -#include #define MAXDEPTH 32 /* ridiculous ray tree depth */ @@ -23,7 +21,7 @@ static char SCCSid[] = "$SunId$ LBL"; #define sscanvec(s,v) (sscanf(s,"%lf %lf %lf",v,v+1,v+2)==3) #endif -char rtcom[] = "rtrace -h- -otp -fa -x 1"; +char rtcom[64] = "rtrace -h- -otp -fa -x 1"; char xicom[] = "ximage -c 256"; VIEW ourview = STDVIEW; /* view for picture */ @@ -47,18 +45,29 @@ struct node { /* ray tree node */ int slow = 0; /* slow trace? */ +void mainloop(void); +static void freetree(struct node *tp); +static void tracerays(struct node *tp); +static int strtoipt(int ipt[2], char *str); +static void setvec(int ipt[2]); +static void vector(int ip1[2], int ip2[2]); -main(argc, argv) /* takes both the octree and the image */ -int argc; -char *argv[]; + +int +main( /* takes both the octree and the image */ + int argc, + char *argv[] +) { int i; - char combuf[256]; + char combuf[PATH_MAX]; progname = argv[0]; for (i = 1; i < argc-2; i++) if (!strcmp(argv[i], "-s")) slow++; + else if (!strcmp(argv[i], "-T")) + strcat(rtcom, " -oTp"); else break; if (i > argc-2) { @@ -82,7 +91,7 @@ char *argv[]; exit(1); } /* build input command */ - sprintf(combuf, "%s %s | %s", xicom, picture, rtcom); + sprintf(combuf, "%s \"%s\" | %s", xicom, picture, rtcom); for ( ; i < argc-1; i++) { strcat(combuf, " "); strcat(combuf, argv[i]); @@ -98,7 +107,8 @@ char *argv[]; } -mainloop() /* get and process input */ +void +mainloop(void) /* get and process input */ { static struct node *sis[MAXDEPTH]; register struct node *newp; @@ -137,19 +147,25 @@ mainloop() /* get and process input */ } -freetree(tp) /* free a trace tree */ -struct node *tp; +static void +freetree( /* free a trace tree */ + struct node *tp +) { - register struct node *kid; + register struct node *kid, *k2; - for (kid = tp->daughter; kid != NULL; kid = kid->sister) + for (kid = tp->daughter; kid != NULL; kid = k2) { + k2 = kid->sister; freetree(kid); - free((char *)tp); + } + free((void *)tp); } -tracerays(tp) /* trace a ray tree */ -struct node *tp; +static void +tracerays( /* trace a ray tree */ + struct node *tp +) { register struct node *kid; @@ -160,9 +176,11 @@ struct node *tp; } -strtoipt(ipt, str) /* convert string x y z to image point */ -int ipt[2]; -char *str; +static int +strtoipt( /* convert string x y z to image point */ + int ipt[2], + char *str +) { FVECT im_pt, pt; @@ -186,8 +204,10 @@ Window gwind = 0; int xoff, yoff; -setvec(ipt) /* set up vector drawing for pick */ -int ipt[2]; +static void +setvec( /* set up vector drawing for pick */ + int ipt[2] +) { extern Window xfindwind(); XWindowAttributes wa; @@ -197,10 +217,15 @@ int ipt[2]; Window rw, cw; unsigned int pm; /* compute pointer location */ - if (gwind == 0 && - (gwind = xfindwind(theDisplay, rwind, picture, 4)) == 0) { - fprintf(stderr, "%s: cannot find display window!\n", progname); - exit(1); + if (gwind == 0) { + register char *wn; + for (wn = picture; *wn; wn++); + while (wn > picture && wn[-1] != '/') wn--; + if ((gwind = xfindwind(theDisplay, rwind, wn, 4)) == 0) { + fprintf(stderr, "%s: cannot find display window!\n", + progname); + exit(1); + } } XQueryPointer(theDisplay, gwind, &rw, &cw, &rx, &ry, &wx, &wy, &pm); xoff = wx - ipt[0]; @@ -221,8 +246,11 @@ int ipt[2]; } -vector(ip1, ip2) /* draw a vector */ -int ip1[2], ip2[2]; +static void +vector( /* draw a vector */ + int ip1[2], + int ip2[2] +) { if (ip2[0] == -1 && ip2[1] == -1) return; /* null vector */