[18] | 1 | /* grow.h -- Growing arrays, growing buffers and string pools
|
---|
| 2 | Copyright (c) 1993-1995 Eberhard Mattes
|
---|
| 3 |
|
---|
| 4 | This file is part of emx.
|
---|
| 5 |
|
---|
| 6 | emx is free software; you can redistribute it and/or modify
|
---|
| 7 | it under the terms of the GNU General Public License as published by
|
---|
| 8 | the Free Software Foundation; either version 2, or (at your option)
|
---|
| 9 | any later version.
|
---|
| 10 |
|
---|
| 11 | emx is distributed in the hope that it will be useful,
|
---|
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 14 | GNU General Public License for more details.
|
---|
| 15 |
|
---|
| 16 | You should have received a copy of the GNU General Public License
|
---|
| 17 | along with emx; see the file COPYING. If not, write to
|
---|
| 18 | the Free Software Foundation, 59 Temple Place - Suite 330,
|
---|
| 19 | Boston, MA 02111-1307, USA. */
|
---|
| 20 |
|
---|
| 21 |
|
---|
| 22 | #define GROW_INIT {0, 0, 0, 0, NULL}
|
---|
| 23 | #define BUFFER_INIT {0, 0, NULL}
|
---|
| 24 |
|
---|
| 25 | struct grow
|
---|
| 26 | {
|
---|
| 27 | int count;
|
---|
| 28 | int alloc;
|
---|
| 29 | int size;
|
---|
| 30 | int inc;
|
---|
| 31 | void **ptr;
|
---|
| 32 | };
|
---|
| 33 |
|
---|
| 34 | struct buffer
|
---|
| 35 | {
|
---|
| 36 | size_t size;
|
---|
| 37 | size_t alloc;
|
---|
| 38 | byte *buf;
|
---|
| 39 | };
|
---|
| 40 |
|
---|
| 41 | /* Note: PTR is a pointer to a pointer */
|
---|
| 42 | void grow_init (struct grow *g, void *ptr, size_t size, int inc);
|
---|
| 43 | void grow_free (struct grow *g);
|
---|
| 44 | void grow_to (struct grow *g, int new_count);
|
---|
| 45 | void grow_by (struct grow *g, int inc);
|
---|
| 46 |
|
---|
| 47 | void buffer_init (struct buffer *b);
|
---|
| 48 | void buffer_free (struct buffer *b);
|
---|
| 49 | void buffer_byte (struct buffer *b, byte x);
|
---|
| 50 | void buffer_word (struct buffer *b, word x);
|
---|
| 51 | void buffer_dword (struct buffer *b, dword x);
|
---|
| 52 | void buffer_mem (struct buffer *b, const void *mem, int len);
|
---|
| 53 | void buffer_nstr (struct buffer *b, const char *str);
|
---|
| 54 | void buffer_enc (struct buffer *b, const char *str);
|
---|
| 55 | void buffer_patch_word (struct buffer *b, int index, word x);
|
---|
| 56 |
|
---|
| 57 | struct strpool *strpool_init (void);
|
---|
| 58 | void strpool_free (struct strpool *p);
|
---|
| 59 | const char *strpool_addn (struct strpool *p, const char *s, int len);
|
---|
| 60 | const char *strpool_add (struct strpool *p, const char *s);
|
---|
[3669] | 61 | const char *strpool_addnu (struct strpool *p, const char *s, int len);
|
---|
| 62 | const char *strpool_addu (struct strpool *p, const char *s);
|
---|
| 63 | int strpool_len (const char *s);
|
---|
| 64 |
|
---|