--- ray/src/gen/xform.c 2005/12/28 18:35:42 2.39 +++ ray/src/gen/xform.c 2018/12/02 16:30:30 2.51 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: xform.c,v 2.39 2005/12/28 18:35:42 greg Exp $"; +static const char RCSid[] = "$Id: xform.c,v 2.51 2018/12/02 16:30:30 greg Exp $"; #endif /* * xform.c - program to transform object files. @@ -13,7 +13,6 @@ static const char RCSid[] = "$Id: xform.c,v 2.39 2005/ #include "platform.h" #include "paths.h" -#include "rtprocess.h" /* win_popen() */ #include "rtio.h" #include "rtmath.h" #include "object.h" @@ -98,7 +97,7 @@ main( /* get transform options and transform file */ if (idprefix == NULL) idprefix = argv[a]; else { - register char *newp; + char *newp; newp = (char *)malloc(strlen(idprefix)+ strlen(argv[a])+2); if (newp == NULL) @@ -106,7 +105,7 @@ main( /* get transform options and transform file */ sprintf(newp, "%s.%s", idprefix, argv[a]); if (mal_prefix++) - free((void *)idprefix); + free(idprefix); idprefix = newp; } continue; @@ -134,7 +133,7 @@ main( /* get transform options and transform file */ a += xf(&tot, argc-a, argv+a); - if ( (reverse = tot.sca < 0.0) ) + if ( (reverse = (tot.sca < 0.0)) ) tot.sca = -tot.sca; if (invert) reverse = !reverse; @@ -167,7 +166,7 @@ main( /* get transform options and transform file */ } if (mal_prefix) - free((void *)idprefix); + free(idprefix); return(0); } @@ -182,9 +181,9 @@ doargf( /* take argument list from file */ int inquote; char *newav[256], **avp; char argbuf[2048]; - char newid[128]; + char *newid, newidbuf[128]; char *oldid; - register char *cp; + char *cp; FILE *argfp; int n, i, k, newac, err; @@ -210,19 +209,21 @@ doargf( /* take argument list from file */ } n = 0; /* count number of lines in file */ while (fgetline(argbuf,sizeof(argbuf),argfp) != NULL) - n += argbuf[0] && argbuf[0] != '#'; + n += (argbuf[0] != '\0') & (argbuf[0] != '#'); if (!n) { fprintf(stderr, "%s: empty argument file \"%s\"\n", av[0], av[fi+1]); exit(1); } - nrept *= n; rewind(argfp); } + nrept *= n; err = 0; k = 0; /* read each arg list and call main */ while (fgetline(argbuf,sizeof(argbuf),argfp) != NULL) { - if (!argbuf[0] || argbuf[0] == '#') + if (!argbuf[0] | (argbuf[0] == '#')) { + printf("%s\n", argbuf); continue; + } avp = newav+2; avp[0] = av[0]; for (i = 1; i < fi; i++) @@ -258,10 +259,16 @@ doargf( /* take argument list from file */ for (i = fi+2; i < ac; i++) avp[newac++] = av[i]; avp[newac] = NULL; + newid = newidbuf; oldid = NULL; for (i = 2; i < newac; i++) if (!strcmp(avp[i-1], "-n")) { oldid = avp[i]; + if (strlen(oldid)+32 > sizeof(newidbuf)) { + newid = (char *)malloc(strlen(oldid)+32); + if (newid == NULL) + exit(2); + } avp[i] = newid; break; } @@ -277,6 +284,8 @@ doargf( /* take argument list from file */ else sprintf(newid, "%s.%d", oldid, k); err |= main(newac, avp); + if (newid != newidbuf) + free(newid); k++; } fclose(argfp); @@ -335,11 +344,11 @@ doarray( /* make array */ void xform( /* transform stream by tot.xfm */ char *name, - register FILE *fin + FILE *fin ) { int nobjs = 0; - register int c; + int c; while ((c = getc(fin)) != EOF) { if (isspace(c)) /* blank */ @@ -448,7 +457,7 @@ o_default( /* pass on arguments unchanged */ FILE *fin ) { - register int i; + int i; FUNARGS fa; if (readfargs(&fa, fin) != 1) @@ -484,7 +493,7 @@ addxform( /* add xf arguments to strings */ FILE *fin ) { - register int i; + int i; int resetarr = 0; FUNARGS fa; @@ -545,7 +554,7 @@ m_glow( /* transform arguments for proximity light * if (readfargs(&fa, fin) != 1) return(-1); - if (fa.nsargs != 0 || fa.nfargs != 4) + if ((fa.nsargs != 0) | (fa.nfargs != 4)) return(-1); printf("0\n0\n4"); printf(" %18.12g %18.12g %18.12g", @@ -566,7 +575,7 @@ m_spot( /* transform arguments for spotlight */ if (readfargs(&fa, fin) != 1) return(-1); - if (fa.nsargs != 0 || fa.nfargs != 7) + if ((fa.nsargs != 0) | ( fa.nfargs != 7)) return(-1); printf("0\n0\n7"); printf(" %18.12g %18.12g %18.12g %18.12g\n", @@ -597,7 +606,7 @@ m_mist( /* transform arguments for mist */ else for (i = 0; i < fa.nsargs; i++) { char sname[256], *sp; - register char *cp1, *cp2 = sname; + char *cp1, *cp2 = sname; /* add idprefix */ for (sp = fa.sarg[i]; *sp; sp = cp1) { for (cp1 = idprefix; *cp1; ) @@ -767,7 +776,7 @@ o_face( /* transform face arguments */ ) { FVECT p; - register int i; + int i; FUNARGS fa; if (readfargs(&fa, fin) != 1) @@ -881,7 +890,7 @@ o_ring( /* transform ring arguments */ void initotypes(void) /* initialize ofun[] array */ { - register int i; + int i; if (ofun[OBJ_SOURCE].funp == o_source) return; /* done already */ @@ -921,6 +930,7 @@ initotypes(void) /* initialize ofun[] array */ tinvers[OBJ_CYLINDER] = OBJ_TUBE; tinvers[OBJ_TUBE] = OBJ_CYLINDER; tinvers[OBJ_INSTANCE] = OBJ_INSTANCE; /* oh, well */ + tinvers[OBJ_MESH] = OBJ_MESH; /* ditto */ } @@ -958,11 +968,11 @@ openmain( /* open input, changing directory for file static char origdir[PATH_MAX]; static char curfn[PATH_MAX]; static int diffdir; - register char *fpath; + char *fpath; if (iname == NULL) { /* standard input */ if (mainfp == NULL) { - register int c; + int c; strcpy(mainfn, "standard input"); if (nrept <= 1) { mainfp = stdin; @@ -1006,7 +1016,7 @@ openmain( /* open input, changing directory for file /* record path name */ strcpy(mainfn, fpath); if (expand) { /* change to local directory */ - register char *cp = fpath + strlen(fpath); /* get dir. */ + char *cp = fpath + strlen(fpath); /* get dir. */ while (cp > fpath) { cp--; if (ISDIRSEP(*cp)) {