home *** CD-ROM | disk | FTP | other *** search
- /*
- jains.c 4/16/89
-
- % ja_Ins and ja_Del
-
- OWL 1.1
- Copyright (c) 1986-1989 by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- */
-
- #include "oakhead.h"
- #include "jadecl.h"
-
- boolean ja_Ins(ja, eltno, count, isize)
- jarray ja;
- unsigned int eltno;
- unsigned int count;
- unsigned int isize;
- /*
- Inserts 'count' blank slots into a jarray
-
- 'isize' is the size to insert to (i.e., the elements
- are slid up until this point. Without this information
- the array would be realloc'd on every Insert)
- (isize is the number of used elements AFTER the insertion)
-
- returns FALSE if unsuccessful.
- */
- {
- SIZE_T eltsize;
-
- eltsize = (ja->eltsize == 0) ? sizeof(VOID *) : ja->eltsize;
-
- if (isize >= ja->size) {
- /* resize the array */
- if (!ja_Resize(ja, isize)) {
- return(FALSE);
- }
- }
-
- /* slide lower region over to upper */
- memmove(
- (VOID *) ((char *) ja->array + ((eltno + count) * eltsize)),
- (VOID *) ((char *) ja->array + (eltno * eltsize)),
- (isize - (eltno + count)) * eltsize);
-
- /* zero out new slots */
- memset((VOID *) ((char *) ja->array + (eltno * eltsize)), 0, count * eltsize);
-
- return(TRUE);
- }
-
- void ja_Del(ja, eltno, count)
- jarray ja;
- unsigned int eltno;
- unsigned int count;
- /*
- Deletes 'count' slots from a jarray
- Zeroes out slots at the end.
- */
- {
- SIZE_T eltsize;
-
- eltsize = (ja->eltsize == 0) ? sizeof(VOID *) : ja->eltsize;
-
- /* pull in upper region over lower */
- memmove((VOID *) ((char *) ja->array + (eltno * eltsize)),
- (VOID *) ((char *) ja->array + ((eltno + count) * eltsize)),
- (ja->size - (eltno + count)) * eltsize);
-
- /* zero out end slots */
- memset((VOID *) ((char *) ja->array + ((ja->size - count) * eltsize)), 0, count * eltsize);
- }
-