--- ray/src/gen/xform.c 2003/11/16 09:23:46 2.35 +++ ray/src/gen/xform.c 2011/08/16 18:09:53 2.47 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: xform.c,v 2.35 2003/11/16 09:23:46 schorsch Exp $"; +static const char RCSid[] = "$Id: xform.c,v 2.47 2011/08/16 18:09:53 greg Exp $"; #endif /* * xform.c - program to transform object files. @@ -54,7 +54,7 @@ static void xfcomm(char *fname, FILE *fin); static void xfobject(char *fname, FILE *fin); static int addxform(FILE *fin); static int alias(FILE *fin); -static void initotypes(void); +void initotypes(void); /* XXX conflict with otypes.h */ static void openmain(char *iname); @@ -106,7 +106,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 +134,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 +167,7 @@ main( /* get transform options and transform file */ } if (mal_prefix) - free((void *)idprefix); + free(idprefix); return(0); } @@ -181,8 +181,8 @@ doargf( /* take argument list from file */ { int inquote; char *newav[256], **avp; - char argbuf[1024]; - char newid[128]; + char argbuf[2048]; + char *newid, newidbuf[128]; char *oldid; register char *cp; FILE *argfp; @@ -258,10 +258,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 +283,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); @@ -374,7 +382,7 @@ xfcomm( /* transform a command */ ) { FILE *pin; - char buf[512]; + char buf[2048]; int i; fgetline(buf, sizeof(buf), fin); @@ -416,17 +424,24 @@ xfobject( /* transform an object */ progname, fname, typ); exit(1); } - if (ismodifier(fn)) - printf("\n%s %s ", nam, typ); - else - printf("\n%s %s ", newmod != NULL ? newmod : nam, - invert ? ofun[tinvers[fn]].funame : typ); + putchar('\n'); + if (ismodifier(fn)) { + fputword(nam, stdout); + printf(" %s ", typ); + } else { + fputword(newmod != NULL ? newmod : nam, stdout); + printf(" %s ", invert ? ofun[tinvers[fn]].funame : typ); + } /* object name */ fgetword(nam, sizeof(nam), fin); if (idprefix == NULL || ismodifier(fn)) - printf("%s\n", nam); - else - printf("%s.%s\n", idprefix, nam); + fputword(nam, stdout); + else { + char nnam[MAXSTR]; + sprintf(nnam, "%s.%s", idprefix, nam); + fputword(nnam, stdout); + } + putchar('\n'); /* transform arguments */ if ((*ofun[fn].funp)(fin) < 0) { fprintf(stderr, "%s: (%s): bad %s \"%s\"\n", @@ -914,6 +929,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 */ }