aboutsummaryrefslogtreecommitdiff
path: root/local/src/bswap.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 /local/src/bswap.x
downloadiraf-osx-40e5a5811c6ffce9b0974e93cdd927cbcf60c157.tar.gz
Repatch (from linux) of OSX IRAF
Diffstat (limited to 'local/src/bswap.x')
-rw-r--r--local/src/bswap.x42
1 files changed, 42 insertions, 0 deletions
diff --git a/local/src/bswap.x b/local/src/bswap.x
new file mode 100644
index 00000000..d9fad447
--- /dev/null
+++ b/local/src/bswap.x
@@ -0,0 +1,42 @@
+include <mach.h>
+
+define SZ_IOBUF 2048
+
+
+# BSWAP -- Copy a file, swapping the bytes.
+
+procedure t_bswap()
+
+bool wordswap
+int in, out, nchars
+pointer sp, input, output, bp
+int open(), read()
+bool clgetb()
+
+begin
+ call smark (sp)
+ call salloc (input, SZ_FNAME, TY_CHAR)
+ call salloc (output, SZ_FNAME, TY_CHAR)
+ call salloc (bp, SZ_IOBUF, TY_CHAR)
+
+ call clgstr ("input", Memc[input], SZ_FNAME)
+ call clgstr ("output", Memc[output], SZ_FNAME)
+ wordswap = clgetb ("wordswap")
+
+ in = open (Memc[input], READ_ONLY, BINARY_FILE)
+ out = open (Memc[output], NEW_FILE, BINARY_FILE)
+
+ repeat {
+ nchars = read (in, Memc[bp], SZ_IOBUF)
+ if (nchars > 0) {
+ if (wordswap)
+ call bswap4 (Memc[bp], 1, Memc[bp], 1, nchars * SZB_CHAR)
+ else
+ call bswap2 (Memc[bp], 1, Memc[bp], 1, nchars * SZB_CHAR)
+ call write (out, Memc[bp], nchars)
+ }
+ } until (nchars == EOF)
+
+ call close (in)
+ call close (out)
+end