| 1 |
– |
/* Copyright (c) 1994 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 |
|
* readobj.c - routines for reading in object descriptions. |
| 6 |
|
* |
| 7 |
< |
* 7/28/85 |
| 7 |
> |
* External symbols declared in object.h |
| 8 |
|
*/ |
| 9 |
|
|
| 10 |
+ |
#include "copyright.h" |
| 11 |
+ |
|
| 12 |
|
#include "standard.h" |
| 13 |
|
|
| 14 |
|
#include "object.h" |
| 17 |
|
|
| 18 |
|
#include <ctype.h> |
| 19 |
|
|
| 21 |
– |
extern char *fgetword(), *strcpy(); |
| 22 |
– |
|
| 20 |
|
OBJREC *objblock[MAXOBJBLK]; /* our objects */ |
| 21 |
|
OBJECT nobjects = 0; /* # of objects */ |
| 22 |
|
|
| 23 |
|
|
| 24 |
+ |
void |
| 25 |
|
readobj(inpspec) /* read in an object file or stream */ |
| 26 |
|
char *inpspec; |
| 27 |
|
{ |
| 30 |
– |
FILE *popen(); |
| 31 |
– |
char *fgetline(); |
| 28 |
|
OBJECT lastobj; |
| 29 |
|
FILE *infp; |
| 30 |
< |
char buf[512]; |
| 30 |
> |
char buf[1024]; |
| 31 |
|
register int c; |
| 32 |
|
|
| 33 |
|
lastobj = nobjects; |
| 68 |
|
} |
| 69 |
|
|
| 70 |
|
|
| 71 |
+ |
void |
| 72 |
|
getobject(name, fp) /* read the next object */ |
| 73 |
|
char *name; |
| 74 |
|
FILE *fp; |
| 135 |
|
{ |
| 136 |
|
register int i; |
| 137 |
|
|
| 138 |
< |
if ((nobjects & 077) == 0) { /* new block */ |
| 138 |
> |
if ((nobjects & (OBJBLKSIZ-1)) == 0) { /* new block */ |
| 139 |
|
errno = 0; |
| 140 |
< |
i = nobjects >> 6; |
| 140 |
> |
i = nobjects >> OBJBLKSHFT; |
| 141 |
|
if (i >= MAXOBJBLK) |
| 142 |
|
return(OVOID); |
| 143 |
< |
objblock[i] = (OBJREC *)bmalloc(0100*sizeof(OBJREC)); |
| 143 |
> |
objblock[i] = (OBJREC *)calloc(OBJBLKSIZ, sizeof(OBJREC)); |
| 144 |
|
if (objblock[i] == NULL) |
| 145 |
|
return(OVOID); |
| 146 |
|
} |
| 147 |
|
return(nobjects++); |
| 148 |
+ |
} |
| 149 |
+ |
|
| 150 |
+ |
void |
| 151 |
+ |
freeobjects(firstobj, nobjs) /* free a range of objects */ |
| 152 |
+ |
OBJECT firstobj, nobjs; |
| 153 |
+ |
{ |
| 154 |
+ |
register int obj; |
| 155 |
+ |
/* check bounds */ |
| 156 |
+ |
if (firstobj < 0) |
| 157 |
+ |
return; |
| 158 |
+ |
if (nobjs <= 0) |
| 159 |
+ |
return; |
| 160 |
+ |
if (firstobj + nobjs > nobjects) |
| 161 |
+ |
return; |
| 162 |
+ |
/* clear objects */ |
| 163 |
+ |
for (obj = firstobj+nobjs; obj-- > firstobj; ) { |
| 164 |
+ |
register OBJREC *o = objptr(obj); |
| 165 |
+ |
free_os(o); /* free client memory */ |
| 166 |
+ |
freeqstr(o->oname); |
| 167 |
+ |
freefargs(&o->oargs); |
| 168 |
+ |
bzero(o, sizeof(OBJREC)); |
| 169 |
+ |
} |
| 170 |
+ |
clearobjndx(); |
| 171 |
+ |
/* free objects off end */ |
| 172 |
+ |
for (obj = nobjects; obj-- > 0; ) |
| 173 |
+ |
if (objptr(obj)->oname != NULL) |
| 174 |
+ |
break; |
| 175 |
+ |
++obj; |
| 176 |
+ |
while (nobjects > obj) /* free empty end blocks */ |
| 177 |
+ |
if ((--nobjects & (OBJBLKSIZ-1)) == 0) { |
| 178 |
+ |
int i = nobjects >> OBJBLKSHFT; |
| 179 |
+ |
free((void *)objblock[i]); |
| 180 |
+ |
objblock[i] = NULL; |
| 181 |
+ |
} |
| 182 |
|
} |