ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/readobj.c
(Generate patch)

Comparing ray/src/common/readobj.c (file contents):
Revision 1.2 by greg, Wed Oct 4 16:32:04 1989 UTC vs.
Revision 2.5 by greg, Thu Jul 18 17:58:01 1996 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1986 Regents of the University of California */
1 > /* Copyright (c) 1994 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 18 | Line 18 | static char SCCSid[] = "$SunId$ LBL";
18  
19   #include  <ctype.h>
20  
21 + extern char  *fgetword(), *strcpy();
22 +
23   OBJREC  *objblock[MAXOBJBLK];           /* our objects */
24 < int  nobjects = 0;                      /* # of objects */
24 > OBJECT  nobjects = 0;                   /* # of objects */
25  
26  
27 < readobj(input)                  /* read in an object file or stream */
28 < char  *input;
27 > readobj(inpspec)                /* read in an object file or stream */
28 > char  *inpspec;
29   {
30          FILE  *popen();
31 <        char  *fgets(), *fgetline();
31 >        char  *fgetline();
32 >        OBJECT  lastobj;
33          FILE  *infp;
34 <        char  buf[512];
34 >        char  buf[1024];
35          register int  c;
36  
37 <        if (input == NULL) {
37 >        lastobj = nobjects;
38 >        if (inpspec == NULL) {
39                  infp = stdin;
40 <                input = "standard input";
41 <        } else if (input[0] == '!') {
42 <                if ((infp = popen(input+1, "r")) == NULL) {
43 <                        sprintf(errmsg, "cannot execute \"%s\"", input);
40 >                inpspec = "standard input";
41 >        } else if (inpspec[0] == '!') {
42 >                if ((infp = popen(inpspec+1, "r")) == NULL) {
43 >                        sprintf(errmsg, "cannot execute \"%s\"", inpspec);
44                          error(SYSTEM, errmsg);
45                  }
46 <        } else if ((infp = fopen(input, "r")) == NULL) {
47 <                sprintf(errmsg, "cannot open scene file \"%s\"", input);
46 >        } else if ((infp = fopen(inpspec, "r")) == NULL) {
47 >                sprintf(errmsg, "cannot open scene file \"%s\"", inpspec);
48                  error(SYSTEM, errmsg);
49          }
50          while ((c = getc(infp)) != EOF) {
# Line 54 | Line 58 | char  *input;
58                          readobj(buf);
59                  } else {                                /* object */
60                          ungetc(c, infp);
61 <                        getobject(input, infp);
61 >                        getobject(inpspec, infp);
62                  }
63          }
64 <        if (input[0] == '!')
64 >        if (inpspec[0] == '!')
65                  pclose(infp);
66          else
67                  fclose(infp);
68 +        if (nobjects == lastobj) {
69 +                sprintf(errmsg, "(%s): empty file", inpspec);
70 +                error(WARNING, errmsg);
71 +        }
72   }
73  
74  
# Line 70 | Line 78 | FILE  *fp;
78   {
79          OBJECT  obj;
80          char  sbuf[MAXSTR];
81 +        int  rval;
82          register OBJREC  *objp;
83  
84          if ((obj = newobject()) == OVOID)
85                  error(SYSTEM, "out of object space");
86          objp = objptr(obj);
87                                          /* get modifier */
88 <        fscanf(fp, "%s", sbuf);
88 >        strcpy(sbuf, "EOF");
89 >        fgetword(sbuf, MAXSTR, fp);
90          if (!strcmp(sbuf, VOIDID))
91                  objp->omod = OVOID;
92          else if ((objp->omod = modifier(sbuf)) == OVOID) {
# Line 84 | Line 94 | FILE  *fp;
94                  error(USER, errmsg);
95          }
96                                          /* get type */
97 <        fscanf(fp, "%s", sbuf);
97 >        strcpy(sbuf, "EOF");
98 >        fgetword(sbuf, MAXSTR, fp);
99          if (!strcmp(sbuf, ALIASID))
100                  objp->otype = -1;
101          else if ((objp->otype = otype(sbuf)) < 0) {
# Line 92 | Line 103 | FILE  *fp;
103                  error(USER, errmsg);
104          }
105                                          /* get identifier */
106 <        fscanf(fp, "%s", sbuf);
106 >        sbuf[0] = '\0';
107 >        fgetword(sbuf, MAXSTR, fp);
108          objp->oname = savqstr(sbuf);
109                                          /* get arguments */
110          if (objp->otype == -1) {
111                  register OBJECT  alias;
112 <                fscanf(fp, "%s", sbuf);
112 >                strcpy(sbuf, "EOF");
113 >                fgetword(sbuf, MAXSTR, fp);
114                  if ((alias = modifier(sbuf)) == OVOID) {
115                          sprintf(errmsg,
116                          "(%s): bad reference \"%s\" for %s \"%s\"",
# Line 105 | Line 118 | FILE  *fp;
118                          error(USER, errmsg);
119                  }
120                  objp->otype = objptr(alias)->otype;
121 <                bcopy(&objptr(alias)->oargs, &objp->oargs, sizeof(FUNARGS));
122 <        } else if (readfargs(&objp->oargs, fp) < 0) {
121 >                copystruct(&objp->oargs, &objptr(alias)->oargs);
122 >        } else if ((rval = readfargs(&objp->oargs, fp)) == 0) {
123                  sprintf(errmsg, "(%s): bad arguments", name);
124                  objerror(objp, USER, errmsg);
125 +        } else if (rval < 0) {
126 +                sprintf(errmsg, "(%s): error reading scene", name);
127 +                error(SYSTEM, errmsg);
128          }
129                                          /* initialize */
130          objp->os = NULL;
115        objp->lastrno = -1;
131  
132          insertobject(obj);              /* add to global structure */
133   }
134  
135  
121 readfargs(fa, fp)               /* read function arguments from stream */
122 register FUNARGS  *fa;
123 FILE  *fp;
124 {
125        char  sbuf[MAXSTR];
126        int  n;
127        register int  i;
128
129        if (fscanf(fp, "%d", &n) != 1 || n < 0)
130                return(-1);
131        if (fa->nsargs = n) {
132                fa->sarg = (char **)bmalloc(n*sizeof(char *));
133                if (fa->sarg == NULL)
134                        goto memerr;
135                for (i = 0; i < fa->nsargs; i++) {
136                        if (fscanf(fp, "%s", sbuf) != 1)
137                                return(-1);
138                        fa->sarg[i] = savestr(sbuf);
139                }
140        } else
141                fa->sarg = NULL;
142        if (fscanf(fp, "%d", &n) != 1 || n < 0)
143                return(-1);
144 #ifdef  IARGS
145        if (fa->niargs = n) {
146                fa->iarg = (long *)bmalloc(n*sizeof(int));
147                if (fa->iarg == NULL)
148                        goto memerr;
149                for (i = 0; i < n; i++)
150                        if (fscanf(fp, "%ld", &fa->iarg[i]) != 1)
151                                return(-1);
152        } else
153                fa->iarg = NULL;
154 #else
155        if (n != 0)
156                return(-1);
157 #endif
158        if (fscanf(fp, "%d", &n) != 1 || n < 0)
159                return(-1);
160        if (fa->nfargs = n) {
161                fa->farg = (double *)bmalloc(n*sizeof(double));
162                if (fa->farg == NULL)
163                        goto memerr;
164                for (i = 0; i < n; i++)
165                        if (fscanf(fp, "%lf", &fa->farg[i]) != 1)
166                                return(-1);
167        } else
168                fa->farg = NULL;
169        return(0);
170 memerr:
171        error(SYSTEM, "out of memory in readfargs");
172 }
173
174
136   int
137   newobject()                             /* get a new object */
138   {
# Line 182 | Line 143 | newobject()                            /* get a new object */
143                  i = nobjects >> 6;
144                  if (i >= MAXOBJBLK)
145                          return(OVOID);
146 <                objblock[i] = (OBJREC *)malloc(0100*sizeof(OBJREC));
146 >                objblock[i] = (OBJREC *)bmalloc(0100*sizeof(OBJREC));
147                  if (objblock[i] == NULL)
148                          return(OVOID);
149          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines