diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2015-07-08 20:46:52 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2015-07-08 20:46:52 -0400 |
commit | fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4 (patch) | |
tree | bdda434976bc09c864f2e4fa6f16ba1952b1e555 /sys/mwcs/mwallocd.x | |
download | iraf-linux-fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4.tar.gz |
Initial commit
Diffstat (limited to 'sys/mwcs/mwallocd.x')
-rw-r--r-- | sys/mwcs/mwallocd.x | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/sys/mwcs/mwallocd.x b/sys/mwcs/mwallocd.x new file mode 100644 index 00000000..96623015 --- /dev/null +++ b/sys/mwcs/mwallocd.x @@ -0,0 +1,39 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include "mwcs.h" + +# MW_ALLOCD -- Allocate space in the data buffer. The size of the buffer +# is automatically increased if necessary. Note that reallocation of the +# buffer may cause it to move, hence all data items are referred to by their +# offset in the buffer, rather than by an absolute pointer. + +int procedure mw_allocd (mw, nelem) + +pointer mw #I pointer to MWCS descriptor +int nelem #I number of elements to alloc space for + +int dbufused, dbuflen, offset +errchk realloc + +begin + dbufused = MI_DBUFUSED(mw) + dbuflen = MI_DBUFLEN(mw) + offset = dbufused + 1 + + # Increase buffer size? + if (dbufused + nelem > dbuflen) { + dbuflen = dbuflen + INC_SZDBUF + while (dbufused + nelem > dbuflen) + dbuflen = dbuflen + INC_SZDBUF + + call realloc (MI_DBUF(mw), dbuflen, TY_DOUBLE) + call aclrd (D(mw,offset), dbuflen - offset + 1) + MI_DBUFLEN(mw) = dbuflen + } + + # Allocate the space in the buffer, and return the buffer offset + # of the allocated area. + + MI_DBUFUSED(mw) = max (0, dbufused + nelem) + return (offset) +end |