xref: /original-bsd/usr.bin/pascal/libpc/UNPACK.c (revision c3e32dec)
1 /*-
2  * Copyright (c) 1979, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)UNPACK.c	8.1 (Berkeley) 06/06/93";
10 #endif /* not lint */
11 
12 /*
13  * unpack(z,a,i)
14  *
15  * with:	z and a as in pack
16  *
17  * semantics:	for j := u to v do
18  *			a[j-u+i] := z[j]
19  */
20 
21 UNPACK(i, a, z, size_a, lb_a, ub_a, size_z)
22 
23 	long	i;	/* subscript into a to begin packing */
24 	char	*a;	/* pointer to structure a */
25 	char	*z;	/* pointer to structure z */
26 	long	size_a;	/* sizeof(a_type) */
27 	long	lb_a;	/* lower bound of structure a */
28 	long	ub_a;	/* (upper bound of a) - (lb_a + sizeof(z_type)) */
29 	long	size_z;	/* sizeof(z_type) */
30 {
31 	int		subscr;
32 	register char	*cp;
33 	register char	*zp = z;
34 	register char	*limit;
35 
36 	subscr = i - lb_a;
37 	if (subscr < 0 || subscr > ub_a) {
38 		ERROR("i = %D: Bad i to unpack(z,a,i)\n", i);
39 		return;
40 	}
41 	cp = &a[subscr * size_a];
42 	limit = cp + size_z;
43 	do	{
44 		*cp++ = *zp++;
45 	} while (cp < limit);
46 }
47