#include "dynstring.h"
-void init_dynstring(void)
+void init_dynstring(struct croma_block *b)
{
- TAILQ_INIT(&dstrings_head);
+ if (b == NULL)
+ return;
+
+ TAILQ_INIT(&b->dstrings_head);
}
-struct dstring* alloc_and_insert_string(size_t len)
+struct dstring* alloc_and_insert_string(struct ccroma_block *b, size_t len)
{
+ if (b == NULL)
+ return NULL;
+
struct dstring *s = calloc(len, sizeof(char));
if (s == NULL)
fail("Unable to alloc() memory");
- TAILQ_INSERT_TAIL(&dstrings_head, s, strings);
+ TAILQ_INSERT_TAIL(&b->dstrings_head, s, strings);
return block;
}
-struct dstring* alloc_after(struct dstring *before)
+struct dstring* alloc_after(struct croma_block *b, struct dstring *before)
{
- if (before == NULL)
+ if (b == NULL || before == NULL)
return NULL;
struct dstring *ptr;
- TAILQ_FOREACH(ptr, &dstrings_head, strings) {
+ TAILQ_FOREACH(ptr, &b->dstrings_head, strings) {
if (strncmp(ptr->p, before->p, 32) == 0)
{
struct dstring *s = calloc(len, sizeof(char));
return ptr;
}
-void free_dstring(struct dstring *s)
+void free_dstring(struct croma_block *b, struct dstring *s)
{
- if (s == NULL)
+ if (b == NULL || s == NULL)
return;
- TAILQ_REMOVE(&dstrings_head, s, strings);
+ TAILQ_REMOVE(&b->dstrings_head, s, strings);
if (s->p != NULL)
free(s->p);
return;
}
-void free_all_dstrings(void)
+void free_all_dstrings(struct croma_block *b)
{
+ if (b == NULL)
+ return;
+
struct dstring *s;
- TAILQ_FOREACH(s, &dstrings_head, strings) {
+ TAILQ_FOREACH(s, &b->dstrings_head, strings) {
TAILQ_REMOVE(&dstrings_head, s, strings);
free_dstring(s);
}
/*
break_after breaks a string after *s and allocates it after "before".
*/
-struct dstring* break_after(struct dstring *before, char *s)
+struct dstring* break_after(struct croma_block *b, struct dstring *before, char *s)
{
- if (before == NULL)
+ if (b == NULL || before == NULL)
return NULL;
int s_len = before->length - (s - p); /* the length of the string after s */
#include <stdlib.h>
#include "queue.h"
+#include "macro.h"
struct dstring {
char *p;
TAILQ_ENTRY(dstring) strings;
};
-TAILQ_HEAD(dstring_heads, dstring) dstrings_head;
-
-void init_dynstring(void);
-struct dstring* alloc_and_insert_string(size_t len);
-struct dstring* alloc_after(struct dstring *before);
-void free_dstring(struct dstring *s);
-void free_all_dstrings(void);
+void init_dynstring(struct croma_block *b);
+struct dstring* alloc_and_insert_string(struct croma_block *b, size_t len);
+struct dstring* alloc_after(struct croma_block *b, struct dstring *before);
+void free_dstring(struct croma_block *b, struct dstring *s);
+void free_all_dstrings(struct croma_block *b);
struct dstring* break_after(struct dstring *before, char *s);