home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 1: Amiga
/
FrozenFish-Apr94.iso
/
bbs
/
alib
/
d1xx
/
d105
/
bison.lha
/
Bison
/
allocate.c
next >
Wrap
C/C++ Source or Header
|
1987-10-25
|
2KB
|
88 lines
/* Allocate and clear storage for bison,
copyright (C) 1984 Bob Corbett and Richard Stallman
Permission is granted to anyone to make or distribute verbatim copies of this program
provided that the copyright notice and this permission notice are preserved;
and provided that the recipient is not asked to waive or limit his right to
redistribute copies as permitted by this permission notice;
and provided that anyone possessing an executable copy
is granted access to copy the source code, in machine-readable form,
in some reasonable manner.
Permission is granted to distribute derived works or enhanced versions of
this program under the above conditions with the additional condition
that the entire derivative or enhanced work
must be covered by a permission notice identical to this one.
Anything distributed as part of a package containing portions derived
from this program, which cannot in current practice perform its function usefully
in the absense of what was derived directly from this program,
is to be considered as forming, together with the latter,
a single work derived from this program,
which must be entirely covered by a permission notice identical to this one
in order for distribution of the package to be permitted.
In other words, you are welcome to use, share and improve this program.
You are forbidden to forbid anyone else to use, share and improve
what you give them. Help stamp out software-hoarding! */
#include <stdio.h>
char *
allocate(n)
register unsigned n;
{
register char *block;
#ifdef amiga
extern char *calloc();
#else
register char *cp;
register char *cend;
extern char *malloc();
#endif
#ifdef amiga
block = calloc(n+4,1);
#else
block = malloc(n);
#endif
if (block == NULL)
{
fprintf(stderr, "storage limit exceeded");
done(1);
}
#ifdef amiga
block[0] = 'A';
block[1] = 'M';
block[2] = 'E';
block[3] = 'N';
return(block+4);
#else
for(cp = block, cend = block+n; cp < cend; *cp++ = 0);
return (block);
#endif
}
#ifdef amiga
void
bisonfree(loc)
char *loc;
{
register unsigned long l1, l2;
register char *p;
if (loc == (char *)0)
return;
l1 = (unsigned long)loc;
l2 = l1 - 4;
if (l2 > l1)
return; /* check for wrap */
p = (char *)l2;
if (p[0] != 'A' || p[1] != 'M' || p[2] != 'E' || p[3] != 'M')
return; /* Not allocated memory */
free(p); /* Free the real location */
}
#endif