babel-1.6
|
Makefile,
README.1ST,
addh.c,
addh2.c,
aromatic.c,
assbnd.c,
asstypes.c,
babel.h,
bblmacs.h,
bblmast.h,
bbltyp.h,
block.c,
bndord.c,
bo.c,
buildct.c,
combine.c,
convert.c,
delatms.c,
delh2o.c,
element.lis,
filesrch.c,
fileutil.c,
gastchg.c,
gauss.hdr,
htoend.c,
int2cart.c,
intcart.c,
menus.c,
miniums.c,
molwt.c,
new.lis,
nodummy.c,
orient.c,
precip.c,
printbad.c,
progress.c,
psgvb.hdr,
quanta.lis,
rdalch.c,
rdampout.c,
rdbalst.c,
rdbgf.c,
rdboogie.c,
rdc3d.c,
rdcacao.c,
rdcadpac.c,
rdcharmm.c,
rdcsd.c,
rddock.c,
rddpdb.c,
rdelmnts.c,
rdfdat.c,
rdfeat.c,
rdfract.c,
rdg96.c,
rdgamout.c,
rdgauout.c,
rdgzmat.c,
rdhin.c,
rdinsite.c,
rdint.c,
rdirc.c,
rdisis.c,
rdm3d.c,
rdmacmod.c,
rdmacmol.c,
rdmdl.c,
rdmicro.c,
rdmm2.c,
rdmm2in.c,
rdmm3.c,
rdmolen.c,
rdmopac.c,
rdmopcrt.c,
rdpcmod.c,
rdpdb.c,
rdprep.c,
rdpsgout.c,
rdpsgvin.c,
rdquanta.c,
rdschak.c,
rdshelx.c,
rdsmiles.c,
rdspart.c,
rdspmm.c,
rdspsemi.c,
rdsybmol.c,
rdsybyl.c,
rdtypes.c,
rdunichm.c,
rdwiz.c,
rdxed.c,
rdxyz.c,
renum.c,
report.c,
rings.c,
ringutil.c,
sets.c,
smilesto.c,
spline.c,
strngutl.c,
tokenst.c,
tosmiles.c,
tree.c,
typbybo.c,
types.lis,
umslist.c,
utils.c,
vectors.c,
wralch.c,
wrbalst.c,
wrbgf.c,
wrbmin.c,
wrbox.c,
wrc3d.c,
wrcacao.c,
wrcache.c,
wrcacint.c,
wrchdrw.c,
wrcontmp.c,
wrcsr.c,
wrcssr.c,
wrdock.c,
wrdpdb.c,
wrfeat.c,
wrfh.c,
wrg96.c,
wrgamess.c,
wrgau.c,
wrgaucrt.c,
wrhin.c,
wricon.c,
wrint.c,
wrisis.c,
wrm3d.c,
wrmaccs.c,
wrmacmod.c,
wrmcmol.c,
wrmdl.c,
wrmicro.c,
wrmimic.c,
wrmiv.c,
wrmm2.c,
wrmm3.c,
wrmopac.c,
wrpcmod.c,
wrpdb.c,
wrpsgv.c,
wrpsgvz.c,
wrsmiles.c,
wrspart.c,
wrsybmol.c,
wrsybyl.c,
wrtinker.c,
wrtorlst.c,
wrunichm.c,
wrwiz.c,
wrxed.c,
wrxyz.c
|
|
|
/*
block.c
allows multiple arrays to be malloc'ed in one easy step
Simon Kilvington, University of Southampton, 1995
*/
#include "bbltyp.h"
/* the routine that does all the work */
static int block__doalloc(int, block_ptr *, const char *, va_list);
/*
block_alloc
allocates a block of memory for a set of arrays
the types string determines what the arrays are arrays of, one char per array, types are:
c - char
i - int
f - float
d - double
B - int
v - void *
eg int *intarray;
float *floatarray1, *floatarray2;
block_alloc(&handle, "iff", &intarray, nentries1, &floatarray1, nentries2, &floatarray2, nentries3);
...code...
block_free(&handle);
returns TRUE if all went well
*/
int
block_alloc(block_ptr *handle, const char *types, ...)
{
int okay;
va_list ap;
va_start(ap, types);
okay = block__doalloc(FALSE, handle, types, ap);
va_end(ap);
return okay;
}
/*
block_calloc
as block_alloc, but all the space is initialised to 0
*/
int
block_calloc(block_ptr *handle, const char *types, ...)
{
int okay;
va_list ap;
va_start(ap, types);
okay = block__doalloc(TRUE, handle, types, ap);
va_end(ap);
return okay;
}
/*
block_free
deallocates space claimed with block_[c]alloc
*/
void
block_free(block_ptr *handle)
{
free(*handle);
*handle = NULL;
return;
}
/*
block__doalloc
does all the work for both the above alloc'ing routines
*/
#define typesize(CHAR, TYPE) if(types[i] == CHAR) { \
(void) va_arg(ap, TYPE **); \
size += va_arg(ap, int) * sizeof(TYPE); \
continue; }
#define typeptr(CHAR, TYPE) if(types[i] == CHAR) { \
array = (void *) va_arg(ap, TYPE **); \
*((TYPE **) array) = (TYPE *) ((long) (*handle) + ptr); \
ptr += va_arg(ap, int) * sizeof(TYPE); \
continue; }
static int
block__doalloc(int clear, block_ptr *handle, const char *types, va_list initap)
{
va_list ap;
int i, size;
long ptr;
void *array;
/* calc how much space we are gonna need */
ap = initap;
size = 0;
for(i=0; types[i] != '\0'; i++)
{
typesize('c', char);
typesize('i', int);
typesize('f', float);
typesize('d', double);
typesize('B', int);
typesize('v', void *);
}
*handle = (block_ptr) ((clear) ? calloc(size, 1) : malloc(size));
/* set up the ptrs if we can alloc the memory */
if(*handle != NULL)
{
ap = initap;
ptr = 0;
for(i=0; types[i] != '\0'; i++)
{
typeptr('c', char);
typeptr('i', int);
typeptr('f', float);
typeptr('d', double);
typeptr('B', int);
typeptr('v', void *);
}
}
return (*handle != NULL);
}
|