date and time created 80/10/31 14:39:48 by mckusick
[unix-history] / usr / src / usr.bin / pascal / libpc / PACK.c
CommitLineData
a5f90adb
KM
1/* Copyright (c) 1979 Regents of the University of California */
2
3static char sccsid[] = "@(#)PACK.c 1.1 %G%";
4
5#include "h01errs.h"
6
7/*
8 * pack(a,i,z)
9 *
10 * with: a: array[m..n] of t
11 * z: packed array[u..v] of t
12 *
13 * semantics: for j := u to v do
14 * z[j] := a[j-u+i];
15 *
16 * need to check:
17 * 1. i >= m
18 * 2. i+(v-u) <= n (i.e. i-m <= (n-m)-(v-u))
19 *
20 * on stack: lv(z), lv(a), rv(i) (len 4)
21 *
22 * move w(t)*(v-u+1) bytes from lv(a)+w(t)*(i-m) to lv(z)
23 */
24
25PACK(i, a, z, size_a, lb_a, ub_a, size_z)
26
27 int i; /* subscript into a to begin packing */
28 char *a; /* pointer to structure a */
29 char *z; /* pointer to structure z */
30 int size_a; /* sizeof(a_type) */
31 int lb_a; /* lower bound of structure a */
32 int ub_a; /* (upper bound of a) - (lb_a + sizeof(z_type)) */
33 int size_z; /* sizeof(z_type) */
34{
35 int subscr;
36 register char *cp;
37 register char *zp = z;
38 register char *limit;
39
40 subscr = i - lb_a;
41 if (subscr < 0 || subscr > ub_a) {
42 ERROR(EPACK, i);
43 return;
44 }
45 cp = &a[subscr * size_a];
46 limit = cp + size_z;
47 do {
48 *zp++ = *cp++;
49 } while (cp < limit);
50}