From fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 8 Jul 2015 20:46:52 -0400 Subject: Initial commit --- local/src/bswap.x | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 local/src/bswap.x (limited to 'local/src/bswap.x') 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 + +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 -- cgit