Now that we have printer device it makes sense to build Print module.
[AROS-Contrib.git] / rexx / src / darray.c
blob62c498f58ed3419569c75fff4bd253a4b067373d
1 /*
2 * $Header$
3 * $Log$
4 * Revision 1.1 2001/04/04 05:43:39 wang
5 * First commit: compiles on Linux, Amiga, Windows, Windows CE, generic gcc
7 * Revision 1.2 1999/03/10 16:53:32 bnv
8 * Added MSC support
10 * Revision 1.1 1998/07/02 17:34:50 bnv
11 * Initial revision
15 #include <bmem.h>
16 #include <darray.h>
18 /* ------------- DA_Add --------------- */
19 long
20 DA_Add( DArray *array, void *dat)
22 long newsize,pos;
24 if (array->lastitem==array->allocateditems) { /* Increase size */
25 newsize = array->allocateditems + array->increase;
26 if (array->pdata)
27 array->pdata = REALLOC(array->pdata,newsize*sizeof(void*));
28 else
29 array->pdata = MALLOC(newsize*sizeof(void*),"DArray");
30 MEMSET(array->pdata + array->lastitem, 0,
31 (newsize-array->lastitem)*sizeof(void*));
32 array->allocateditems = newsize;
34 pos = array->lastitem; /* keep position of addition */
35 array->pdata[array->lastitem++] = dat;
36 array->items++;
37 return pos; /* return position */
38 } /* DA_Add */
40 /* ------------- DA_AddAtFree --------------- */
41 long
42 DA_AddAtFree( DArray *array, void *dat)
44 long pos;
46 if (array->items==array->allocateditems)
47 return DA_Add(array,dat);
48 else { /* search for a free position */
49 for (pos=0; pos<array->lastitem; pos++)
50 if (array->pdata[pos]==NULL)
51 break;
52 array->pdata[pos] = dat;
53 if (pos==array->lastitem)
54 array->lastitem++;
56 array->items++;
57 return pos;
58 } /* DA_AddAtFree */
60 /* ---------------- DA_Del ------------------ */
61 void
62 DA_Del( DArray *array, long it )
64 if (array->pdata[it]) {
65 array->pdata[it] = 0;
66 if (it==array->lastitem-1)
67 array->lastitem--;
68 array->items--;
70 } /* DA_Del */