--- ray/src/ot/readobj2.c 1991/11/12 17:01:03 2.1 +++ ray/src/ot/readobj2.c 2003/10/27 10:29:29 2.8 @@ -1,34 +1,29 @@ -/* Copyright (c) 1991 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: readobj2.c,v 2.8 2003/10/27 10:29:29 schorsch Exp $"; #endif - /* * readobj2.c - routines for reading in object descriptions. */ -#include "standard.h" +#include +#include +#include "platform.h" +#include "rtprocess.h" +#include "rtmath.h" +#include "rtio.h" +#include "rterror.h" #include "object.h" - #include "otypes.h" -#include -extern char *fgetword(); +static void getobject2(char *name, FILE *fp, int (*f)()); -OBJREC *objblock[MAXOBJBLK]; /* our objects */ -OBJECT nobjects = 0; /* # of objects */ -int newobject() {return(0);} - - -readobj(input, callback) /* read in an object file or stream */ +readobj2(input, callback) /* read in an object file or stream */ char *input; int (*callback)(); { - FILE *popen(); - char *fgets(), *fgetline(); + char *fgetline(); FILE *infp; char buf[512]; register int c; @@ -53,10 +48,10 @@ int (*callback)(); } else if (c == '!') { /* command */ ungetc(c, infp); fgetline(buf, sizeof(buf), infp); - readobj(buf, callback); + readobj2(buf, callback); } else { /* object */ ungetc(c, infp); - getobject(input, infp, callback); + getobject2(input, infp, callback); } } if (input[0] == '!') @@ -66,10 +61,12 @@ int (*callback)(); } -getobject(name, fp, f) /* read the next object */ -char *name; -FILE *fp; -int (*f)(); +static void +getobject2( /* read the next object */ +char *name, +FILE *fp, +int (*f)() +) { char sbuf[MAXSTR]; OBJREC thisobj; @@ -78,9 +75,7 @@ int (*f)(); thisobj.omod = OVOID; /* get type */ fgetword(sbuf, MAXSTR, fp); - if (!strcmp(sbuf, ALIASID)) - thisobj.otype = -1; - else if ((thisobj.otype = otype(sbuf)) < 0) { + if ((thisobj.otype = otype(sbuf)) < 0) { sprintf(errmsg, "(%s): unknown type \"%s\"", name, sbuf); error(USER, errmsg); } @@ -88,7 +83,7 @@ int (*f)(); fgetword(sbuf, MAXSTR, fp); thisobj.oname = sbuf; /* get arguments */ - if (thisobj.otype == -1) { + if (thisobj.otype == MOD_ALIAS) { fscanf(fp, "%*s"); return; } @@ -97,25 +92,9 @@ int (*f)(); objerror(&thisobj, USER, errmsg); } thisobj.os = NULL; - thisobj.lastrno = -1; /* call function */ (*f)(&thisobj); /* free memory */ - if (thisobj.os != NULL) - switch (thisobj.otype) { - case OBJ_CONE: - case OBJ_CUP: - case OBJ_CYLINDER: - case OBJ_TUBE: - case OBJ_RING: - freecone(&thisobj); - break; - case OBJ_FACE: - freeface(&thisobj); - break; - case OBJ_INSTANCE: - freeinstance(&thisobj); - break; - } freefargs(&thisobj.oargs); + free_os(&thisobj); }