10 * A type capable of representing a self-resizing string with
13 typedef struct string_s string_t;
16 * Function: string_create
17 * Create a string object
19 string_t *string_create(void);
22 * Function: string_buffer
23 * Return the raw buffer of a string object
25 char *string_buffer(string_t *string);
28 * Function: string_cat
29 * Append a character to a string object
31 void string_cat(string_t *string, char ch);
34 * Function: string_catf
35 * Append a formatted string to a string object
37 void string_catf(string_t *string, const char *fmt, ...);
40 * Function: string_quote
41 * Escape a string's quotes
43 char *string_quote(char *p);
46 * Function: string_length
47 * Get the length of the given string
49 size_t string_length(string_t *string);
53 * A key value associative table
55 typedef struct table_s table_t;
63 * Function: table_create
64 * Creates a table_t object
66 void *table_create(void *parent);
69 * Funciton: table_find
70 * Searches for a given value in the table based on the
71 * key associated with it.
73 void *table_find(table_t *table, const char *key);
76 * Function: table_insert
77 * Inserts a value for the given key as an entry in the
80 void table_insert(table_t *table, char *key, void *value);
83 * Function: table_parent
84 * Returns the parent opaque object for the given table to
85 * be used as the argument to a new table.
87 void *table_parent(table_t *table);
90 * Function: table_values
91 * Generates a list of all the values in the table, useful for
92 * iterating over the values.
94 list_t *table_values(table_t *table);
97 * Function: table_keys
98 * Generate a list of all the keys in the table, useful for
99 * iteration over the keys.
101 list_t *table_keys(table_t *table);
104 * Macro: SENTINEL_TABLE
105 * Initialize an empty table in place
107 #define SENTINEL_TABLE ((table_t) { \
108 .list = &SENTINEL_LIST, \
113 #define MIN(A, B) (((A) < (B)) ? (A) : (B))
114 #define MAX(A, B) (((A) > (B)) ? (A) : (B))
117 * Function: memory_allocate
118 * Allocate some memory
120 void *memory_allocate(size_t bytes);
124 * A class container describing a pair
127 /* Variable: first */
129 /* Variable: second */
134 * Function: pair_create
135 * Used to create a <pair_t>.
138 * first - Pointer to first object
139 * second - Pointer to second object
142 * A pointer to a constructed <pair_t> containing first and last
143 * pointers which point to the same address as the ones supplied
144 * as parameters to this function.
146 pair_t *pair_create(void *first, void *last);
148 /* String utilities */
149 int strcasecmp(const char *s1, const char *s2);
150 int strncasecmp(const char *s1, const char *s2, size_t n);
151 size_t getline(char **line, size_t *n, FILE *stream);
154 * Macro: bool_stringa
155 * Returns a "true" or "false" for an expression that evaluates to a
156 * boolean representation enforced with cast-to-bool `!!`
158 #define bool_string(BOOL) \
159 ((!!(BOOL)) ? "true" : "false")