Debian Codegraph @

external/bdwgc/include/ec.h

raw
1 # ifndef EC_H
2 # define EC_H
3
4 # ifndef CORD_H
5 # include "cord.h"
6 # endif
7
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11
12 /* Extensible cords are strings that may be destructively appended to. */
13 /* They allow fast construction of cords from characters that are */
14 /* being read from a stream. */
15 /*
16 * A client might look like:
17 *
18 * {
19 * CORD_ec x;
20 * CORD result;
21 * char c;
22 * FILE *f;
23 *
24 * ...
25 * CORD_ec_init(x);
26 * while(...) {
27 * c = getc(f);
28 * ...
29 * CORD_ec_append(x, c);
30 * }
31 * result = CORD_balance(CORD_ec_to_cord(x));
32 *
33 * If a C string is desired as the final result, the call to CORD_balance
34 * may be replaced by a call to CORD_to_char_star.
35 */
36
37 # ifndef CORD_BUFSZ
38 # define CORD_BUFSZ 128
39 # endif
40
41 typedef struct CORD_ec_struct {
42 CORD ec_cord;
43 char * ec_bufptr;
44 char ec_buf[CORD_BUFSZ+1];
45 } CORD_ec[1];
46
47 /* This structure represents the concatenation of ec_cord with */
48 /* ec_buf[0 ... (ec_bufptr-ec_buf-1)] */
49
50 /* Flush the buffer part of the extended chord into ec_cord. */
51 /* Note that this is almost the only real function, and it is */
52 /* implemented in 6 lines in cordxtra.c */
53 void CORD_ec_flush_buf(CORD_ec x);
54
55 /* Convert an extensible cord to a cord. */
56 # define CORD_ec_to_cord(x) (CORD_ec_flush_buf(x), (x)[0].ec_cord)
57
58 /* Initialize an extensible cord. */
59 #define CORD_ec_init(x) \
60 ((x)[0].ec_cord = 0, (void)((x)[0].ec_bufptr = (x)[0].ec_buf))
61
62 /* Append a character to an extensible cord. */
63 #define CORD_ec_append(x, c) \
64 (((x)[0].ec_bufptr == (x)[0].ec_buf + CORD_BUFSZ ? \
65 (CORD_ec_flush_buf(x), 0) : 0), \
66 (void)(*(x)[0].ec_bufptr++ = (c)))
67
68 /* Append a cord to an extensible cord. Structure remains shared with */
69 /* original. */
70 void CORD_ec_append_cord(CORD_ec x, CORD s);
71
72 #ifdef __cplusplus
73 } /* extern "C" */
74 #endif
75
76 # endif /* EC_H */