|
|
1.1 root 1: #ifndef BUILDOBJ_H
2: #define BUILDOBJ_H
3:
4: /*
5: * This file declares structures and function prototypes for some routines
6: * useful for building up objects a piece at a time.
7: */
8:
9: /*
10: *-IMPORTS:
11: * <sys/compat.h>
12: * EXTERN_C_BEGIN
13: * EXTERN_C_END
14: * VOID
15: * PROTO ()
16: * <stddef.h>
17: * size_t
18: */
19:
20: #include <sys/compat.h>
21: #include <stddef.h>
22:
23: /*
24: * The following code can be used as the basis of a system for building up
25: * objects such as symbol-table entries incrementally. It's kind of like the
26: * GNU obstack system (and clearly inspired by it), but it's not free
27: * software. It's also a little more clearly laid out, and easier to
28: * understand and modify, and slower.
29: */
30:
31: #ifndef BUILD_T
32: #define BUILD_T
33: typedef struct builder build_t;
34: #endif
35:
36:
37: /*
38: * Return values from build functions.
39: */
40:
41: enum {
42: BUILD_CORRUPT = -10,
43: BUILD_STACK_EMPTY = -9,
44: BUILD_BAD_NESTING = -8,
45: BUILD_NOT_LAST = -7,
46: BUILD_SIZE_OVERFLOW = -6,
47: BUILD_NO_MEMORY = -5,
48: BUILD_NO_OBJECT = -4,
49: BUILD_OBJECT_BEGUN = -3,
50: BUILD_NULL_BASE = -2,
51: BUILD_NULL_HEAP = -1,
52: BUILD_OK
53: };
54:
55: /*
56: * Special value for "init" parameter in functions below that causes newly
57: * allocated memory to be cleared.
58: */
59:
60: #define INIT_ZERO ((VOID *) 1)
61:
62:
63: EXTERN_C_BEGIN
64:
65: build_t * builder_alloc PROTO ((size_t _chunksize, size_t _align));
66: void builder_free PROTO ((build_t * _heap));
67:
68: VOID * build_malloc PROTO ((build_t * _heap, size_t _size));
69:
70: int build_begin PROTO ((build_t * _heap, size_t _size,
71: CONST VOID * _init));
72: int build_add PROTO ((build_t * _heap, size_t _size,
73: CONST VOID * _init));
74: int build_addchar PROTO ((build_t * _heap, char _ch));
75: VOID * build_end PROTO ((build_t * _heap, size_t * _size));
76:
77: int build_release PROTO ((build_t * _heap, CONST VOID * _base));
78:
79: CONST char * build_error PROTO ((int _errcode));
80:
81: int build_push PROTO ((build_t * _heap));
82: int build_pop PROTO ((build_t * _heap));
83:
84: EXTERN_C_END
85:
86: #endif /* ! defined (BUILDOBJ_H) */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.