aboutsummaryrefslogtreecommitdiff
path: root/sys/osb/chrupk.c
blob: f909c8d9ceba76b4b46a70893260cc3081f36756 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
 */

#define	import_spp
#define import_knames
#include <iraf.h>

/* CHRUPK -- Unpack a byte string into XCHAR.  This routine does not
 * know about EOS terminators.  The input and output arrays may be the same.
 * Note that while XCHAR is signed, the signedness of the C char is unspecified,
 * hence we pack the chars into unsigned bytes and restore the sign explicitly.
 */
CHRUPK (a, a_off, b, b_off, nchars)
XCHAR	*a, *b;
XINT	*a_off, *b_off, *nchars;
{
	register unsigned char *ip;
	register XCHAR	*op;
	register int	n, ch;

	/* Set pointers to last char plus one so that we can unpack the array
	 * in the reverse direction.
	 */
	n = *nchars;
	ip = &((unsigned char *)a)[*a_off-1+n];
	op = &b[*b_off-1+n];

	/* Unpack string from right to left.
	 */
	while (--n >= 0)
	    *--op = ((ch = *--ip) <= 127) ? ch : ch - 256;
}