1 |
– |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* readobj2.c - routines for reading in object descriptions. |
6 |
|
*/ |
7 |
|
|
8 |
< |
#include "standard.h" |
8 |
> |
#include <ctype.h> |
9 |
> |
#include <stdio.h> |
10 |
|
|
11 |
+ |
#include "platform.h" |
12 |
+ |
#include "paths.h" |
13 |
+ |
#include "rtmath.h" |
14 |
+ |
#include "rtio.h" |
15 |
+ |
#include "rterror.h" |
16 |
|
#include "object.h" |
14 |
– |
|
17 |
|
#include "otypes.h" |
18 |
+ |
#include "oconv.h" |
19 |
|
|
17 |
– |
#include <ctype.h> |
20 |
|
|
21 |
< |
extern char *fgetword(); |
21 |
> |
static void getobject2(char *name, FILE *fp, ro_cbfunc f); |
22 |
|
|
21 |
– |
OBJREC *objblock[MAXOBJBLK]; /* our objects */ |
22 |
– |
OBJECT nobjects = 0; /* # of objects */ |
23 |
– |
int newobject() {return(0);} |
23 |
|
|
24 |
< |
|
25 |
< |
readobj(input, callback) /* read in an object file or stream */ |
26 |
< |
char *input; |
27 |
< |
int (*callback)(); |
24 |
> |
void |
25 |
> |
readobj2( /* read in an object file or stream */ |
26 |
> |
char *input, |
27 |
> |
ro_cbfunc callback |
28 |
> |
) |
29 |
|
{ |
30 |
– |
FILE *popen(); |
31 |
– |
char *fgets(), *fgetline(); |
30 |
|
FILE *infp; |
31 |
< |
char buf[512]; |
31 |
> |
char buf[2048]; |
32 |
|
register int c; |
33 |
|
|
34 |
|
if (input == NULL) { |
51 |
|
} else if (c == '!') { /* command */ |
52 |
|
ungetc(c, infp); |
53 |
|
fgetline(buf, sizeof(buf), infp); |
54 |
< |
readobj(buf, callback); |
54 |
> |
readobj2(buf, callback); |
55 |
|
} else { /* object */ |
56 |
|
ungetc(c, infp); |
57 |
< |
getobject(input, infp, callback); |
57 |
> |
getobject2(input, infp, callback); |
58 |
|
} |
59 |
|
} |
60 |
< |
if (input[0] == '!') |
61 |
< |
pclose(infp); |
62 |
< |
else |
60 |
> |
if (input[0] == '!') { |
61 |
> |
if (pclose(infp) != 0) { |
62 |
> |
sprintf(errmsg, "bad status from \"%s\"", input); |
63 |
> |
error(SYSTEM, errmsg); |
64 |
> |
} |
65 |
> |
} else |
66 |
|
fclose(infp); |
67 |
|
} |
68 |
|
|
69 |
|
|
70 |
< |
getobject(name, fp, f) /* read the next object */ |
71 |
< |
char *name; |
72 |
< |
FILE *fp; |
73 |
< |
int (*f)(); |
70 |
> |
static void |
71 |
> |
getobject2( /* read the next object */ |
72 |
> |
char *name, |
73 |
> |
FILE *fp, |
74 |
> |
ro_cbfunc f |
75 |
> |
) |
76 |
|
{ |
77 |
|
char sbuf[MAXSTR]; |
78 |
|
OBJREC thisobj; |
81 |
|
thisobj.omod = OVOID; |
82 |
|
/* get type */ |
83 |
|
fgetword(sbuf, MAXSTR, fp); |
84 |
< |
if (!strcmp(sbuf, ALIASID)) |
82 |
< |
thisobj.otype = -1; |
83 |
< |
else if ((thisobj.otype = otype(sbuf)) < 0) { |
84 |
> |
if ((thisobj.otype = otype(sbuf)) < 0) { |
85 |
|
sprintf(errmsg, "(%s): unknown type \"%s\"", name, sbuf); |
86 |
|
error(USER, errmsg); |
87 |
|
} |
89 |
|
fgetword(sbuf, MAXSTR, fp); |
90 |
|
thisobj.oname = sbuf; |
91 |
|
/* get arguments */ |
92 |
< |
if (thisobj.otype == -1) { |
92 |
> |
if (thisobj.otype == MOD_ALIAS) { |
93 |
|
fscanf(fp, "%*s"); |
94 |
|
return; |
95 |
|
} |
98 |
|
objerror(&thisobj, USER, errmsg); |
99 |
|
} |
100 |
|
thisobj.os = NULL; |
100 |
– |
thisobj.lastrno = -1; |
101 |
|
/* call function */ |
102 |
|
(*f)(&thisobj); |
103 |
|
/* free memory */ |
104 |
– |
if (thisobj.os != NULL) |
105 |
– |
switch (thisobj.otype) { |
106 |
– |
case OBJ_CONE: |
107 |
– |
case OBJ_CUP: |
108 |
– |
case OBJ_CYLINDER: |
109 |
– |
case OBJ_TUBE: |
110 |
– |
case OBJ_RING: |
111 |
– |
freecone(&thisobj); |
112 |
– |
break; |
113 |
– |
case OBJ_FACE: |
114 |
– |
freeface(&thisobj); |
115 |
– |
break; |
116 |
– |
case OBJ_INSTANCE: |
117 |
– |
freeinstance(&thisobj); |
118 |
– |
break; |
119 |
– |
} |
104 |
|
freefargs(&thisobj.oargs); |
105 |
+ |
free_os(&thisobj); |
106 |
|
} |