aboutsummaryrefslogtreecommitdiff
path: root/sys/mwcs/mwallocs.x
diff options
context:
space:
mode:
authorJoe Hunkeler <jhunkeler@gmail.com>2015-08-11 16:51:37 -0400
committerJoe Hunkeler <jhunkeler@gmail.com>2015-08-11 16:51:37 -0400
commit40e5a5811c6ffce9b0974e93cdd927cbcf60c157 (patch)
tree4464880c571602d54f6ae114729bf62a89518057 /sys/mwcs/mwallocs.x
downloadiraf-osx-40e5a5811c6ffce9b0974e93cdd927cbcf60c157.tar.gz
Repatch (from linux) of OSX IRAF
Diffstat (limited to 'sys/mwcs/mwallocs.x')
-rw-r--r--sys/mwcs/mwallocs.x42
1 files changed, 42 insertions, 0 deletions
diff --git a/sys/mwcs/mwallocs.x b/sys/mwcs/mwallocs.x
new file mode 100644
index 00000000..6a9caf5b
--- /dev/null
+++ b/sys/mwcs/mwallocs.x
@@ -0,0 +1,42 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include "mwcs.h"
+
+# MW_ALLOCS -- Allocate space in the global string 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. Since we
+# are allocating space for string data, a space for the EOS is automatically
+# allocated in addition to space for the indicated number of data chars.
+
+int procedure mw_allocs (mw, nchars)
+
+pointer mw #I pointer to MWCS descriptor
+int nchars #I number of chars to allocate space for
+
+int sbufused, sbuflen, offset, nelem
+errchk realloc
+
+begin
+ sbufused = MI_SBUFUSED(mw)
+ sbuflen = MI_SBUFLEN(mw)
+ offset = sbufused + 1
+ nelem = nchars + 1
+
+ # Increase buffer size?
+ if (sbufused + nelem > sbuflen) {
+ sbuflen = sbuflen + INC_SZSBUF
+ while (sbufused + nelem > sbuflen)
+ sbuflen = sbuflen + INC_SZSBUF
+
+ call realloc (MI_SBUF(mw), sbuflen, TY_CHAR)
+ call aclrc (S(mw,offset), sbuflen - offset + 1)
+ MI_SBUFLEN(mw) = sbuflen
+ }
+
+ # Allocate the space in the buffer, and return the buffer offset
+ # of the allocated area.
+
+ MI_SBUFUSED(mw) = max (0, sbufused + nelem)
+ return (offset)
+end