Debian Codegraph @

src/asm/dynabuf.h

raw symbols SCIP
1 //
2 // ACME - a crossassembler for producing 6502/65c02/65816 code.
3 // Copyright (C) 1998-2006 Marco Baye
4 // Have a look at "acme.c" for further info
5 //
6 // Dynamic buffer stuff
7 #ifndef dynabuf_H
8 #define dynabuf_H
9
10 #include "config.h"
11
12
13 // Macros
14 #define DYNABUF_CLEAR(db) {db->size = 0;}
15 #define DYNABUF_APPEND(db, byte) do {\
16 if(db->size == db->reserved)\
17 DynaBuf_enlarge(db);\
18 db->buffer[(db->size)++] = byte;\
19 } while(0)
20 // The next one is dangerous - the buffer location can change when a character
21 // is appended. So after calling this, don't change the buffer as long as you
22 // use the address.
23 #define GLOBALDYNABUF_CURRENT (GlobalDynaBuf->buffer)
24
25
26 // dynamic buffer structure
27 struct dynabuf_t {
28 char* buffer; // pointer to buffer
29 int size; // size of buffer's used portion
30 int reserved; // total size of buffer
31 };
32 typedef struct dynabuf_t dynabuf_t;
33
34
35 // Variables
36 extern dynabuf_t* GlobalDynaBuf; // global dynamic buffer
37
38
39 // Prototypes
40
41 // create global DynaBuf (call once on program startup)
42 extern void DynaBuf_init(void);
43 // create (private) DynaBuf
44 extern dynabuf_t* DynaBuf_create(int initial_size);
45 // call whenever buffer is too small
46 extern void DynaBuf_enlarge(dynabuf_t* db);
47 // return malloc'd copy of buffer contents
48 extern char* DynaBuf_get_copy(dynabuf_t* db);
49 // copy string to buffer (without terminator)
50 extern void DynaBuf_add_string(dynabuf_t* db, const char*);
51 // add string version of int to buffer (without terminator)
52 extern void DynaBuf_add_signed_long(dynabuf_t* db, signed long value);
53 // add string version of float to buffer (without terminator)
54 extern void DynaBuf_add_double(dynabuf_t* db, double value);
55 // converts buffer contents to lower case
56 extern void DynaBuf_to_lower(dynabuf_t* target, dynabuf_t* source);
57 // add char to buffer
58 extern void DynaBuf_append(dynabuf_t* db, char);
59
60
61 #endif