1 #pragma ident "%Z%%M% %I% %E% SMI"
4 * This file is part of libdyn.a, the C Dynamic Object library. It
5 * contains the source code for the functions DynGet() and DynAdd().
7 * There are no restrictions on this code; however, if you make any
8 * changes, I request that you document them so that I do not get
9 * credit or blame for your modifications.
11 * Written by Barr3y Jaspan, Student Information Processing Board (SIPB)
12 * and MIT-Project Athena, 1989.
24 fprintf(stderr
, "dyn: array: returning array pointer %d.\n",
30 DynPtr
DynGet(obj
, num
)
36 fprintf(stderr
, "dyn: get: bad index %d\n", num
);
40 if (num
>= obj
->num_el
) {
42 fprintf(stderr
, "dyn: get: highest element is %d.\n",
48 fprintf(stderr
, "dyn: get: Returning address %d + %d.\n",
49 obj
->array
, obj
->el_size
*num
);
51 return (DynPtr
) obj
->array
+ obj
->el_size
*num
;
60 ret
= DynPut(obj
, el
, obj
->num_el
);
69 * WARNING! There is a reason this function is not documented in the
70 * man page. If DynPut used to mutate already existing elements,
71 * everything will go fine. If it is used to add new elements
72 * directly, however, the state within the object (such as
73 * obj->num_el) will not be updated properly and many other functions
74 * in the library will lose. Have a nice day.
76 int DynPut(obj
, el_in
, idx
)
81 DynPtr el
= (DynPtr
) el_in
;
85 fprintf(stderr
, "dyn: put: Writing %d bytes from %d to %d + %d\n",
86 obj
->el_size
, el
, obj
->array
, idx
*obj
->el_size
);
88 if ((ret
= _DynResize(obj
, idx
)) != DYN_OK
)
92 memmove(obj
->array
+ idx
*obj
->el_size
, el
, obj
->el_size
);
94 bcopy(el
, obj
->array
+ idx
*obj
->el_size
, obj
->el_size
);
98 fprintf(stderr
, "dyn: put: done.\n");