home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c185 / 2.ddi / OWLSRC.EXE / CSCAPE / SOURCE / JAINS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-06  |  1.8 KB  |  77 lines

  1. /*
  2.     jains.c  4/16/89
  3.  
  4.     % ja_Ins and ja_Del
  5.  
  6.     OWL 1.1
  7.     Copyright (c) 1986-1989 by Oakland Group, Inc.
  8.     ALL RIGHTS RESERVED.
  9.  
  10.     Revision History:
  11.     -----------------
  12. */
  13.  
  14. #include "oakhead.h"
  15. #include "jadecl.h"
  16.  
  17. boolean ja_Ins(ja, eltno, count, isize)
  18.     jarray ja;
  19.     unsigned int eltno;
  20.     unsigned int count;
  21.     unsigned int isize;
  22. /*
  23.     Inserts 'count' blank slots into a jarray
  24.  
  25.     'isize' is the size to insert to (i.e., the elements
  26.     are slid up until this point.  Without this information
  27.     the array would be realloc'd on every Insert)
  28.     (isize is the number of used elements AFTER the insertion)
  29.  
  30.     returns FALSE if unsuccessful.
  31. */
  32. {
  33.     SIZE_T eltsize;
  34.  
  35.     eltsize = (ja->eltsize == 0) ? sizeof(VOID *) : ja->eltsize;
  36.  
  37.     if (isize >= ja->size) {
  38.         /* resize the array */
  39.         if (!ja_Resize(ja, isize)) {
  40.             return(FALSE);
  41.         }
  42.     }
  43.  
  44.     /* slide lower region over to upper */
  45.     memmove(
  46.             (VOID *) ((char *) ja->array + ((eltno + count) * eltsize)),
  47.             (VOID *) ((char *) ja->array + (eltno * eltsize)),
  48.             (isize - (eltno + count)) * eltsize);
  49.  
  50.     /* zero out new slots */
  51.     memset((VOID *) ((char *) ja->array + (eltno * eltsize)), 0, count * eltsize);
  52.  
  53.     return(TRUE);
  54. }
  55.  
  56. void ja_Del(ja, eltno, count)
  57.     jarray ja;
  58.     unsigned int eltno;
  59.     unsigned int count;
  60. /*
  61.     Deletes 'count' slots from a jarray
  62.     Zeroes out slots at the end.
  63. */
  64. {
  65.     SIZE_T eltsize;
  66.  
  67.     eltsize = (ja->eltsize == 0) ? sizeof(VOID *) : ja->eltsize;
  68.  
  69.     /* pull in upper region over lower */
  70.     memmove((VOID *) ((char *) ja->array + (eltno * eltsize)),
  71.             (VOID *) ((char *) ja->array + ((eltno + count) * eltsize)),
  72.             (ja->size - (eltno + count)) * eltsize);
  73.  
  74.     /* zero out end slots */
  75.     memset((VOID *) ((char *) ja->array + ((ja->size - count) * eltsize)), 0, count * eltsize);
  76. }
  77.