| 1 | /* Copyright (c) 1979 Regents of the University of California */ |
| 2 | |
| 3 | static char sccsid[] = "@(#)UNPACK.c 1.1 %G%"; |
| 4 | |
| 5 | #include "h01errs.h" |
| 6 | |
| 7 | /* |
| 8 | * unpack(z,a,i) |
| 9 | * |
| 10 | * with: z and a as in pack |
| 11 | * |
| 12 | * semantics: for j := u to v do |
| 13 | * a[j-u+i] := z[j] |
| 14 | */ |
| 15 | |
| 16 | UNPACK(i, a, z, size_a, lb_a, ub_a, size_z) |
| 17 | |
| 18 | int i; /* subscript into a to begin packing */ |
| 19 | char *a; /* pointer to structure a */ |
| 20 | char *z; /* pointer to structure z */ |
| 21 | int size_a; /* sizeof(a_type) */ |
| 22 | int lb_a; /* lower bound of structure a */ |
| 23 | int ub_a; /* (upper bound of a) - (lb_a + sizeof(z_type)) */ |
| 24 | int size_z; /* sizeof(z_type) */ |
| 25 | { |
| 26 | int subscr; |
| 27 | register char *cp; |
| 28 | register char *zp = z; |
| 29 | register char *limit; |
| 30 | |
| 31 | subscr = i - lb_a; |
| 32 | if (subscr < 0 || subscr > ub_a) { |
| 33 | ERROR(EPACK, i); |
| 34 | return; |
| 35 | } |
| 36 | cp = &a[subscr * size_a]; |
| 37 | limit = cp + size_z; |
| 38 | do { |
| 39 | *cp++ = *zp++; |
| 40 | } while (cp < limit); |
| 41 | } |