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 "rtprocess.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 |
> |
char *fgetline(); |
31 |
|
FILE *infp; |
32 |
|
char buf[512]; |
33 |
|
register int c; |
52 |
|
} else if (c == '!') { /* command */ |
53 |
|
ungetc(c, infp); |
54 |
|
fgetline(buf, sizeof(buf), infp); |
55 |
< |
readobj(buf, callback); |
55 |
> |
readobj2(buf, callback); |
56 |
|
} else { /* object */ |
57 |
|
ungetc(c, infp); |
58 |
< |
getobject(input, infp, callback); |
58 |
> |
getobject2(input, infp, callback); |
59 |
|
} |
60 |
|
} |
61 |
|
if (input[0] == '!') |
65 |
|
} |
66 |
|
|
67 |
|
|
68 |
< |
getobject(name, fp, f) /* read the next object */ |
69 |
< |
char *name; |
70 |
< |
FILE *fp; |
71 |
< |
int (*f)(); |
68 |
> |
static void |
69 |
> |
getobject2( /* read the next object */ |
70 |
> |
char *name, |
71 |
> |
FILE *fp, |
72 |
> |
ro_cbfunc f |
73 |
> |
) |
74 |
|
{ |
75 |
|
char sbuf[MAXSTR]; |
76 |
|
OBJREC thisobj; |
79 |
|
thisobj.omod = OVOID; |
80 |
|
/* get type */ |
81 |
|
fgetword(sbuf, MAXSTR, fp); |
82 |
< |
if (!strcmp(sbuf, ALIASID)) |
82 |
< |
thisobj.otype = -1; |
83 |
< |
else if ((thisobj.otype = otype(sbuf)) < 0) { |
82 |
> |
if ((thisobj.otype = otype(sbuf)) < 0) { |
83 |
|
sprintf(errmsg, "(%s): unknown type \"%s\"", name, sbuf); |
84 |
|
error(USER, errmsg); |
85 |
|
} |
87 |
|
fgetword(sbuf, MAXSTR, fp); |
88 |
|
thisobj.oname = sbuf; |
89 |
|
/* get arguments */ |
90 |
< |
if (thisobj.otype == -1) { |
90 |
> |
if (thisobj.otype == MOD_ALIAS) { |
91 |
|
fscanf(fp, "%*s"); |
92 |
|
return; |
93 |
|
} |
99 |
|
/* call function */ |
100 |
|
(*f)(&thisobj); |
101 |
|
/* free memory */ |
103 |
– |
if (thisobj.os != NULL) |
104 |
– |
switch (thisobj.otype) { |
105 |
– |
case OBJ_CONE: |
106 |
– |
case OBJ_CUP: |
107 |
– |
case OBJ_CYLINDER: |
108 |
– |
case OBJ_TUBE: |
109 |
– |
case OBJ_RING: |
110 |
– |
freecone(&thisobj); |
111 |
– |
break; |
112 |
– |
case OBJ_FACE: |
113 |
– |
freeface(&thisobj); |
114 |
– |
break; |
115 |
– |
case OBJ_INSTANCE: |
116 |
– |
freeinstance(&thisobj); |
117 |
– |
break; |
118 |
– |
} |
102 |
|
freefargs(&thisobj.oargs); |
103 |
+ |
free_os(&thisobj); |
104 |
|
} |