grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / classes / zune / texteditor / mcc / Grow.c
blobe2fcc459d4f713dcae89554f568831ba7d372cfb
1 /***************************************************************************
3 TextEditor.mcc - Textediting MUI Custom Class
4 Copyright (C) 1997-2000 Allan Odgaard
5 Copyright (C) 2005-2014 TextEditor.mcc Open Source Team
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 TextEditor class Support Site: http://www.sf.net/projects/texteditor-mcc
19 $Id$
21 ***************************************************************************/
23 #include <string.h>
25 #include <proto/exec.h>
27 #include "private.h"
28 #include "Debug.h"
30 /// InitGrow()
31 // Initialize a grow structure
32 void InitGrow(struct Grow *grow, APTR pool, int itemSize)
34 ENTER();
36 grow->array = NULL;
37 grow->itemSize = itemSize;
38 grow->itemCount = 0;
39 grow->maxItemCount = 0;
40 grow->pool = pool;
42 LEAVE();
45 ///
46 /// FreeGrow()
47 // Free the allocated memory of a grow structure and reinitialize it
48 void FreeGrow(struct Grow *grow)
50 ENTER();
52 if(grow->array != NULL)
53 FreeVecPooled(grow->pool, grow->array);
55 grow->array = NULL;
56 grow->itemCount = 0;
57 grow->maxItemCount = 0;
59 LEAVE();
62 ///
63 /// AddToGrow()
64 // Adds a new item to the given grow structure.
65 void AddToGrow(struct Grow *grow, void *newItem)
67 ENTER();
69 if(grow->itemCount+1 > grow->maxItemCount)
71 char *new_array;
73 // we reserve 8 new items
74 if((new_array = AllocVecPooled(grow->pool, (grow->maxItemCount+8) * grow->itemSize)) != NULL)
76 // Copy old contents into new array
77 if(grow->array != NULL)
79 memcpy(new_array, grow->array, grow->itemCount * grow->itemSize);
80 FreeVecPooled(grow->pool, grow->array);
83 grow->array = new_array;
84 grow->maxItemCount += 8;
88 // copy the new item to the grow structure only if there is space left
89 if(grow->itemCount < grow->maxItemCount)
91 memcpy(&grow->array[grow->itemCount * grow->itemSize], newItem, grow->itemSize);
92 grow->itemCount++;
95 LEAVE();
98 ///
99 /// RemoveFromGrow()
100 // Remove the last item from a grow structure
101 void RemoveFromGrow(struct Grow *grow)
103 ENTER();
105 if(grow->itemCount > 0)
106 grow->itemCount--;
108 LEAVE();