aboutsummaryrefslogtreecommitdiff
path: root/sys/imio/iki/stf/stfreblk.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/imio/iki/stf/stfreblk.x
downloadiraf-osx-40e5a5811c6ffce9b0974e93cdd927cbcf60c157.tar.gz
Repatch (from linux) of OSX IRAF
Diffstat (limited to 'sys/imio/iki/stf/stfreblk.x')
-rw-r--r--sys/imio/iki/stf/stfreblk.x65
1 files changed, 65 insertions, 0 deletions
diff --git a/sys/imio/iki/stf/stfreblk.x b/sys/imio/iki/stf/stfreblk.x
new file mode 100644
index 00000000..9519bd08
--- /dev/null
+++ b/sys/imio/iki/stf/stfreblk.x
@@ -0,0 +1,65 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <imhdr.h>
+include <imio.h>
+include "stf.h"
+
+# STF_REBLOCK -- If the user area is not blocked to fixed length records, e.g.,
+# as is possible in a new copy image, reblock it fixed length.
+
+procedure stf_reblock (im)
+
+pointer im # image descriptor
+
+pointer sp, lbuf, op, ua
+int fd, spool, nlines, nchars, sz_userarea, len_hdrmem
+errchk stropen, open, getline, putline, realloc, seek, fcopyo
+int open(), stropen(), getline()
+
+begin
+ call smark (sp)
+ call salloc (lbuf, SZ_LINE, TY_CHAR)
+
+ ua = IM_USERAREA(im)
+ fd = stropen (Memc[ua], ARB, READ_ONLY)
+ spool = open ("rb_spool", READ_WRITE, SPOOL_FILE)
+
+ # Reblock into a spool file, counting the lines.
+ for (nlines=0; ; nlines=nlines+1) {
+ nchars = getline (fd, Memc[lbuf])
+ if (nchars <= 0)
+ break
+
+ for (op=nchars; op <= FITS_RECLEN; op=op+1)
+ Memc[lbuf+op-1] = ' '
+ Memc[lbuf+FITS_RECLEN] = '\n'
+ Memc[lbuf+FITS_RECLEN+1] = EOS
+
+ call putline (spool, Memc[lbuf])
+ }
+
+ call close (fd)
+
+ # Reallocate header the right size.
+ sz_userarea = nlines * (FITS_RECLEN+1) + SZ_EXTRASPACE
+
+ IM_HDRLEN(im) = LEN_IMHDR +
+ (sz_userarea - SZ_EXTRASPACE + SZ_MII_INT-1) / SZ_MII_INT
+ len_hdrmem = LEN_IMHDR +
+ (sz_userarea+1 + SZ_MII_INT-1) / SZ_MII_INT
+
+ if (IM_LENHDRMEM(im) < len_hdrmem) {
+ IM_LENHDRMEM(im) = len_hdrmem
+ call realloc (im, IM_LENHDRMEM(im) + LEN_IMDES, TY_STRUCT)
+ }
+
+ # Move spooled data back to user area.
+ ua = IM_USERAREA(im)
+ fd = stropen (Memc[ua], sz_userarea, NEW_FILE)
+ call seek (spool, BOFL)
+ call fcopyo (spool, fd)
+
+ call close (fd)
+ call close (spool)
+ call sfree (sp)
+end