xref: /csrg-svn/usr.bin/pascal/libpc/PACK.c (revision 62092)
140865Sbostic /*-
2*62092Sbostic  * Copyright (c) 1979, 1993
3*62092Sbostic  *	The Regents of the University of California.  All rights reserved.
440865Sbostic  *
540865Sbostic  * %sccs.include.redist.c%
640865Sbostic  */
71669Smckusick 
840865Sbostic #ifndef lint
9*62092Sbostic static char sccsid[] = "@(#)PACK.c	8.1 (Berkeley) 06/06/93";
1040865Sbostic #endif /* not lint */
111669Smckusick 
121669Smckusick /*
131669Smckusick  * pack(a,i,z)
141669Smckusick  *
151669Smckusick  * with:	a: array[m..n] of t
161669Smckusick  *	z: packed array[u..v] of t
171669Smckusick  *
181669Smckusick  * semantics:	for j := u to v do
191669Smckusick  *			z[j] := a[j-u+i];
201669Smckusick  *
211669Smckusick  * need to check:
221669Smckusick  *	1. i >= m
231669Smckusick  *	2. i+(v-u) <= n		(i.e. i-m <= (n-m)-(v-u))
241669Smckusick  *
251669Smckusick  * on stack:	lv(z), lv(a), rv(i) (len 4)
261669Smckusick  *
271669Smckusick  * move w(t)*(v-u+1) bytes from lv(a)+w(t)*(i-m) to lv(z)
281669Smckusick  */
291669Smckusick 
PACK(i,a,z,size_a,lb_a,ub_a,size_z)301669Smckusick PACK(i, a, z, size_a, lb_a, ub_a, size_z)
311669Smckusick 
323015Smckusic 	long	i;	/* subscript into a to begin packing */
331669Smckusick 	char	*a;	/* pointer to structure a */
341669Smckusick 	char	*z;	/* pointer to structure z */
353015Smckusic 	long	size_a;	/* sizeof(a_type) */
363015Smckusic 	long	lb_a;	/* lower bound of structure a */
373015Smckusic 	long	ub_a;	/* (upper bound of a) - (lb_a + sizeof(z_type)) */
383015Smckusic 	long	size_z;	/* sizeof(z_type) */
391669Smckusick {
401669Smckusick 	int		subscr;
411669Smckusick 	register char	*cp;
421669Smckusick 	register char	*zp = z;
431669Smckusick 	register char	*limit;
441669Smckusick 
451669Smckusick 	subscr = i - lb_a;
461669Smckusick 	if (subscr < 0 || subscr > ub_a) {
473868Smckusic 		ERROR("i = %D: Bad i to pack(a,i,z)\n", i);
481669Smckusick 		return;
491669Smckusick 	}
501669Smckusick 	cp = &a[subscr * size_a];
511669Smckusick 	limit = cp + size_z;
521669Smckusick 	do	{
531669Smckusick 		*zp++ = *cp++;
541669Smckusick 	} while (cp < limit);
551669Smckusick }
56