--- ray/src/gen/genworm.c 1993/11/18 09:33:07 2.3 +++ ray/src/gen/genworm.c 2019/12/07 02:21:42 2.11 @@ -1,9 +1,6 @@ #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: genworm.c,v 2.11 2019/12/07 02:21:42 greg Exp $"; #endif - -/* Copyright (c) 1989 Regents of the University of California */ - /* * genworm.c - program to generate worms (strings with varying thickness). * @@ -14,8 +11,15 @@ static char SCCSid[] = "$SunId$ LBL"; * 9/24/87 */ +#include #include #include +#include + +#include "calcomp.h" +#include "rtio.h" +#include "resolu.h" +#include "rterror.h" #include "fvect.h" #define XNAME "X`SYS`" /* x function name */ @@ -28,19 +32,22 @@ static char SCCSid[] = "$SunId$ LBL"; #define max(a,b) ((a) > (b) ? (a) : (b)) -double funvalue(), l_hermite(), l_bezier(), l_bspline(), argument(); +/* XXX redundant, move to library */ +double l_hermite(char *), l_bezier(char *), l_bspline(char *); +int main(argc, argv) int argc; char *argv[]; { - extern long eclock; char stmp[256]; - double t, f, lastr, r; + double t, f, lastr = 0, r; FVECT lastp, p; int i, nseg; + esupport |= E_VARIABLE|E_FUNCTION|E_RCONST; + esupport &= ~(E_OUTCHAN|E_INCHAN); varset("PI", ':', PI); funset("hermite", 5, ':', l_hermite); funset("bezier", 5, ':', l_bezier); @@ -52,9 +59,15 @@ char *argv[]; for (i = 8; i < argc; i++) if (!strcmp(argv[i], "-e")) scompile(argv[++i], NULL, 0); - else if (!strcmp(argv[i], "-f")) - fcompile(argv[++i]); - else + else if (!strcmp(argv[i], "-f")) { + char *fpath = getpath(argv[++i], getrlibpath(), 0); + if (fpath == NULL) { + fprintf(stderr, "%s: cannot find file '%s'\n", + argv[0], argv[i]); + quit(1); + } + fcompile(fpath); + } else goto userror; sprintf(stmp, "%s(t)=%s;", XNAME, argv[3]); @@ -65,11 +78,12 @@ char *argv[]; scompile(stmp, NULL, 0); sprintf(stmp, "%s(t)=%s;", RNAME, argv[6]); scompile(stmp, NULL, 0); - nseg = atoi(argv[7]); + nseg = eval(argv[7]) + .5; if (nseg <= 0) goto userror; - printhead(argc, argv); + fputs("# ", stdout); + printargs(argc, argv, stdout); eclock = 0; for (i = 0; i <= nseg; i++) { @@ -78,7 +92,7 @@ char *argv[]; p[1] = funvalue(YNAME, 1, &t); p[2] = funvalue(ZNAME, 1, &t); r = funvalue(RNAME, 1, &t); - if (i) + if (i) { if (lastr <= r+FTINY && lastr >= r-FTINY) { printf("\n%s cylinder %s.c%d\n", argv[1], argv[2], i); @@ -105,58 +119,25 @@ char *argv[]; f = f <= 0.0 ? 0.0 : sqrt(f); printf("%18.12g %18.12g\n", f*lastr, f*r); } + } printf("\n%s sphere %s.s%d\n", argv[1], argv[2], i); printf("0\n0\n4 %18.12g %18.12g %18.12g %18.12g\n", p[0], p[1], p[2], r); VCOPY(lastp, p); lastr = r; } - quit(0); + return 0; userror: fprintf(stderr, "Usage: %s material name x(t) y(t) z(t) r(t) nseg [-e expr] [-f file]\n", argv[0]); - quit(1); + return 1; } -eputs(msg) -char *msg; -{ - fputs(msg, stderr); -} - - -wputs(msg) -char *msg; -{ - eputs(msg); -} - - -quit(code) -int code; -{ - exit(code); -} - - -printhead(ac, av) /* print command header */ -register int ac; -register char **av; -{ - putchar('#'); - while (ac--) { - putchar(' '); - fputs(*av++, stdout); - } - putchar('\n'); -} - - double -l_hermite() +l_hermite(char *nm) { double t; @@ -169,7 +150,7 @@ l_hermite() double -l_bezier() +l_bezier(char *nm) { double t; @@ -182,7 +163,7 @@ l_bezier() double -l_bspline() +l_bspline(char *nm) { double t;