home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QBasic & Borland Pascal & C
/
Delphi5.iso
/
C
/
Samples
/
CSAPE32.ARJ
/
SOURCE
/
CSSRC
/
SDALLOC.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-10-22
|
2KB
|
85 lines
/*
sdalloc.c jdc 10/27/88
% sed_Alloc
C-scape 3.2
Copyright (c) 1988 by Oakland Group, Inc.
ALL RIGHTS RESERVED.
Revision History:
---------------------
4/28/89 jdc preened
6/21/89 jmd made a boolean, added comments
7/06/89 jdc varsize == 0 var now gets set to NULL (VAR_TED case)
8/14/89 jdc added bob support
11/16/89 jmd fixed infinite recursion bug and size == 0 bug
3/28/90 jmd ansi-fied
10/22/90 bkd added alignment stuff.
*/
#include "sed.h"
#include "sfile.h"
boolean sd_alloc(sed_type sed, boolean dobobs)
/*
Allocate space for a sed's variables.
Returns FALSE if it fails.
if dobobs is TRUE, allocate space for all child seds.
*/
{
unsigned int size;
int i;
bob_type child;
char *data;
/* if we've already allocated storage, release it */
if (sed_GetMenu(sed)->varblock != NULL) {
ofree(CSA_VARBLOCK, (VOID *) sed_GetMenu(sed)->varblock);
sed_GetMenu(sed)->varblock = NULL;
}
/* figure out how much space we need */
for (i = 0, size = 0; i < sed_GetFieldCount(sed); i++) {
size += oroundup(sed_GetVarSize(sed, i), O_ALIGNSIZE);
}
if (size != 0) {
/* allocate the space */
if ((sed_GetMenu(sed)->varblock = (VOID *) ocalloc(CSA_VARBLOCK, 1, size)) == NULL) {
return(FALSE);
}
/* point the field variables to the space */
for (i = 0, data = (char *)(sed_GetMenu(sed)->varblock); i < sed_GetFieldCount(sed); i++) {
if ((size = oroundup(sed_GetVarSize(sed, i), O_ALIGNSIZE)) == 0) {
sed_SetVar(sed, i, NULL);
}
else {
sed_SetVar(sed, i, (VOID *)data);
}
data += size;
}
}
/* allocate space for our child seds--if we're supposed to */
if (dobobs) {
for (i = 0; i < sed_GetMenu(sed)->bobcount; i++) {
/* pull the bob out the bob array */
child = sed_GetFieldBob(sed, ia_Get(sed_GetMenu(sed)->boba, i));
/* check if the bob is a sed */
if (bob_IsSed(child)) {
if (!sd_alloc(child, dobobs)) {
return(FALSE);
}
}
}
}
return(TRUE);
}