--- var.c 2001/11/13 19:32:03 1.12
+++ var.c 2001/11/14 09:47:02 1.13
@@ -45,101 +45,88 @@
"a-zA-Z0-9_" /* namechars */
};
-/* Routines for manipulation of tokenbufs. */
+/* Routines for manipulation of token buffers. */
-#define VAR_INITIAL_BUFFER_SIZE 64
+#define TOKENBUF_INITIAL_BUFSIZE 64
typedef struct {
const char *begin;
const char *end;
size_t buffer_size;
-} tokenbuf;
+} tokenbuf_t;
-static void init_tokenbuf(tokenbuf *buf)
+static void tokenbuf_init(tokenbuf_t *buf)
{
- buf->begin = buf->end = NULL;
+ buf->begin = NULL;
+ buf->end = NULL;
buf->buffer_size = 0;
return;
}
-static void move_tokenbuf(tokenbuf *src, tokenbuf *dst)
+static void tokenbuf_move(tokenbuf_t *src, tokenbuf_t *dst)
{
dst->begin = src->begin;
dst->end = src->end;
dst->buffer_size = src->buffer_size;
- init_tokenbuf(src);
+ tokenbuf_init(src);
return;
}
-static int assign_to_tokenbuf(tokenbuf *buf, const char *data, size_t len)
+static int tokenbuf_assign(tokenbuf_t *buf, const char *data, size_t len)
{
- char *p = malloc(len + 1);
- if (p) {
- memcpy(p, data, len);
- buf->begin = p;
- buf->end = p + len;
- buf->buffer_size = len + 1;
- *((char *) (buf->end)) = '\0';
- return 1;
- } else
+ char *p;
+
+ if ((p = malloc(len + 1)) == NULL)
return 0;
+ memcpy(p, data, len);
+ buf->begin = p;
+ buf->end = p + len;
+ buf->buffer_size = len + 1;
+ *((char *)(buf->end)) = '\0';
+ return 1;
}
-static int append_to_tokenbuf(tokenbuf *output, const char *data,
- size_t len)
+static int tokenbuf_append(tokenbuf_t *output, const char *data, size_t len)
{
char *new_buffer;
size_t new_size;
+ char *tmp;
/* Is the tokenbuffer initialized at all? If not, allocate a
standard-sized buffer to begin with. */
-
if (output->begin == NULL) {
- if ((output->begin = output->end =
- malloc(VAR_INITIAL_BUFFER_SIZE)) == NULL)
+ if ((output->begin = output->end = malloc(TOKENBUF_INITIAL_BUFSIZE)) == NULL)
return 0;
- else
- output->buffer_size = VAR_INITIAL_BUFFER_SIZE;
+ output->buffer_size = TOKENBUF_INITIAL_BUFSIZE;
}
- /* Does the token contain text, but no buffer has been allocated
- yet? */
-
+ /* Does the token contain text, but no buffer has been allocated yet? */
if (output->buffer_size == 0) {
/* Check whether data borders to output. If, we can append
simly by increasing the end pointer. */
-
if (output->end == data) {
output->end += len;
return 1;
}
-
/* OK, so copy the contents of output into an allocated buffer
so that we can append that way. */
-
- else {
- char *tmp = malloc(output->end - output->begin + len + 1);
- if (!tmp)
- return 0;
- memcpy(tmp, output->begin, output->end - output->begin);
- output->buffer_size = output->end - output->begin;
- output->begin = tmp;
- output->end = tmp + output->buffer_size;
- output->buffer_size += len + 1;
- }
+ if ((tmp = malloc(output->end - output->begin + len + 1)) == NULL)
+ return 0;
+ memcpy(tmp, output->begin, output->end - output->begin);
+ output->buffer_size = output->end - output->begin;
+ output->begin = tmp;
+ output->end = tmp + output->buffer_size;
+ output->buffer_size += len + 1;
}
/* Does the token fit into the current buffer? If not, realloc a
larger buffer that fits. */
-
if ((output->buffer_size - (output->end - output->begin)) <= len) {
new_size = output->buffer_size;
do {
new_size *= 2;
- }
- while ((new_size - (output->end - output->begin)) <= len);
- new_buffer = realloc((char *) output->begin, new_size);
- if (new_buffer == NULL)
+ } while ((new_size - (output->end - output->begin)) <= len);
+ if ((new_buffer = realloc((char *)output->begin, new_size)) == NULL)
return 0;
output->end = new_buffer + (output->end - output->begin);
output->begin = new_buffer;
@@ -147,26 +134,27 @@
}
/* Append the data at the end of the current buffer. */
-
memcpy((char *)output->end, data, len);
output->end += len;
*((char *)output->end) = '\0';
return 1;
}
-static void free_tokenbuf(tokenbuf *buf)
+static void tokenbuf_free(tokenbuf_t *buf)
{
if (buf->begin != NULL && buf->buffer_size > 0)
- free((char *) buf->begin);
+ free((char *)buf->begin);
buf->begin = buf->end = NULL;
buf->buffer_size = 0;
return;
}
-static size_t tokenbuf2int(tokenbuf *number)
+static size_t tokenbuf_toint(tokenbuf_t *number)
{
const char *p;
- size_t num = 0;
+ size_t num;
+
+ num = 0;
for (p = number->begin; p != number->end; ++p) {
num *= 10;
num += *p - '0';
@@ -376,9 +364,9 @@
/* The recursive-descent parser for variable expressions. */
static int variable(const char *, const char *, const var_config_t *,
- const char[256], var_cb_t, void *, int, tokenbuf *);
+ const char[256], var_cb_t, void *, int, tokenbuf_t *);
static int command(const char *, const char *, const var_config_t *,
- const char[256], var_cb_t, void *, int, tokenbuf *);
+ const char[256], var_cb_t, void *, int, tokenbuf_t *);
static int text(const char *begin, const char *end, char varinit,
char escape)
@@ -447,21 +435,21 @@
const var_config_t *config,
const char nameclass[256], var_cb_t lookup,
void *lookup_context, int force_expand,
- tokenbuf *result)
+ tokenbuf_t *result)
{
const char *p = begin;
const char *data;
size_t len, buffer_size;
int failed = 0;
int rc;
- tokenbuf name;
- tokenbuf tmp;
+ tokenbuf_t name;
+ tokenbuf_t tmp;
/* Clear the tokenbufs to make sure we have a defined state. */
- init_tokenbuf(&name);
- init_tokenbuf(&tmp);
- init_tokenbuf(result);
+ tokenbuf_init(&name);
+ tokenbuf_init(&tmp);
+ tokenbuf_init(result);
/* Expect STARTDELIM. */
@@ -479,7 +467,7 @@
if (rc < 0)
goto error_return;
else if (rc > 0) {
- if (!append_to_tokenbuf(&name, p, rc)) {
+ if (!tokenbuf_append(&name, p, rc)) {
rc = VAR_OUT_OF_MEMORY;
goto error_return;
} else
@@ -491,7 +479,7 @@
if (rc < 0)
goto error_return;
else if (rc > 0) {
- if (!append_to_tokenbuf(&name, tmp.begin, tmp.end - tmp.begin)) {
+ if (!tokenbuf_append(&name, tmp.begin, tmp.end - tmp.begin)) {
rc = VAR_OUT_OF_MEMORY;
goto error_return;
} else
@@ -551,7 +539,7 @@
if (p[-1] == ':') {
/* Parse and execute commands. */
- free_tokenbuf(&tmp);
+ tokenbuf_free(&tmp);
--p;
while (p != end && *p == ':') {
++p;
@@ -579,23 +567,23 @@
/* Exit gracefully. */
- free_tokenbuf(&name);
- free_tokenbuf(&tmp);
+ tokenbuf_free(&name);
+ tokenbuf_free(&tmp);
return p - begin;
/* Exit in case of an error. */
error_return:
- free_tokenbuf(&name);
- free_tokenbuf(&tmp);
- free_tokenbuf(result);
+ tokenbuf_free(&name);
+ tokenbuf_free(&tmp);
+ tokenbuf_free(result);
return rc;
}
static int variable(const char *begin, const char *end,
const var_config_t *config, const char nameclass[256],
var_cb_t lookup, void *lookup_context,
- int force_expand, tokenbuf *result)
+ int force_expand, tokenbuf_t *result)
{
const char *p = begin;
const char *data;
@@ -605,7 +593,7 @@
/* Clear the result tokenbuf to make sure we're in a defined
state. */
- init_tokenbuf(result);
+ tokenbuf_init(result);
/* Expect VARINIT. */
@@ -655,14 +643,14 @@
const var_config_t *config,
const char nameclass[256], var_cb_t lookup,
void *lookup_context, int force_expand,
- tokenbuf *result)
+ tokenbuf_t *result)
{
const char *p = begin;
- tokenbuf tmp;
+ tokenbuf_t tmp;
int rc;
- init_tokenbuf(result);
- init_tokenbuf(&tmp);
+ tokenbuf_init(result);
+ tokenbuf_init(&tmp);
if (begin == end)
return 0;
@@ -672,7 +660,7 @@
if (rc < 0)
goto error_return;
else if (rc > 0) {
- if (!append_to_tokenbuf(result, p, rc)) {
+ if (!tokenbuf_append(result, p, rc)) {
rc = VAR_OUT_OF_MEMORY;
goto error_return;
} else
@@ -685,7 +673,7 @@
goto error_return;
else if (rc > 0) {
p += rc;
- if (!append_to_tokenbuf
+ if (!tokenbuf_append
(result, tmp.begin, tmp.end - tmp.begin)) {
rc = VAR_OUT_OF_MEMORY;
goto error_return;
@@ -694,12 +682,12 @@
}
while (rc > 0);
- free_tokenbuf(&tmp);
+ tokenbuf_free(&tmp);
return p - begin;
error_return:
- free_tokenbuf(&tmp);
- free_tokenbuf(result);
+ tokenbuf_free(&tmp);
+ tokenbuf_free(result);
return rc;
}
@@ -707,14 +695,14 @@
const var_config_t *config,
const char nameclass[256], var_cb_t lookup,
void *lookup_context, int force_expand,
- tokenbuf *result)
+ tokenbuf_t *result)
{
const char *p = begin;
- tokenbuf tmp;
+ tokenbuf_t tmp;
int rc;
- init_tokenbuf(result);
- init_tokenbuf(&tmp);
+ tokenbuf_init(result);
+ tokenbuf_init(&tmp);
if (begin == end)
return 0;
@@ -724,7 +712,7 @@
if (rc < 0)
goto error_return;
else if (rc > 0) {
- if (!append_to_tokenbuf(result, p, rc)) {
+ if (!tokenbuf_append(result, p, rc)) {
rc = VAR_OUT_OF_MEMORY;
goto error_return;
} else
@@ -737,7 +725,7 @@
goto error_return;
else if (rc > 0) {
p += rc;
- if (!append_to_tokenbuf
+ if (!tokenbuf_append
(result, tmp.begin, tmp.end - tmp.begin)) {
rc = VAR_OUT_OF_MEMORY;
goto error_return;
@@ -746,17 +734,17 @@
}
while (rc > 0);
- free_tokenbuf(&tmp);
+ tokenbuf_free(&tmp);
return p - begin;
error_return:
- free_tokenbuf(&tmp);
- free_tokenbuf(result);
+ tokenbuf_free(&tmp);
+ tokenbuf_free(result);
return rc;
}
-static int expand_class_description(tokenbuf *src, tokenbuf *dst)
+static int expand_class_description(tokenbuf_t *src, tokenbuf_t *dst)
{
unsigned char c, d;
const char *p = src->begin;
@@ -765,12 +753,12 @@
if (*p > p[2])
return VAR_INCORRECT_TRANSPOSE_CLASS_SPEC;
for (c = *p, d = p[2]; c <= d; ++c) {
- if (!append_to_tokenbuf(dst, (char *) &c, 1))
+ if (!tokenbuf_append(dst, (char *) &c, 1))
return VAR_OUT_OF_MEMORY;
}
p += 3;
} else {
- if (!append_to_tokenbuf(dst, p, 1))
+ if (!tokenbuf_append(dst, p, 1))
return VAR_OUT_OF_MEMORY;
else
++p;
@@ -779,16 +767,16 @@
return VAR_OK;
}
-static int transpose(tokenbuf *data, tokenbuf *search,
- tokenbuf *replace)
+static int transpose(tokenbuf_t *data, tokenbuf_t *search,
+ tokenbuf_t *replace)
{
- tokenbuf srcclass, dstclass;
+ tokenbuf_t srcclass, dstclass;
const char *p;
int rc;
size_t i;
- init_tokenbuf(&srcclass);
- init_tokenbuf(&dstclass);
+ tokenbuf_init(&srcclass);
+ tokenbuf_init(&dstclass);
if ((rc = expand_class_description(search, &srcclass)) != VAR_OK)
goto error_return;
@@ -805,13 +793,13 @@
}
if (data->buffer_size == 0) {
- tokenbuf tmp;
- if (!assign_to_tokenbuf
+ tokenbuf_t tmp;
+ if (!tokenbuf_assign
(&tmp, data->begin, data->end - data->begin)) {
rc = VAR_OUT_OF_MEMORY;
goto error_return;
}
- move_tokenbuf(&tmp, data);
+ tokenbuf_move(&tmp, data);
}
for (p = data->begin; p != data->end; ++p) {
@@ -823,25 +811,25 @@
}
}
- free_tokenbuf(&srcclass);
- free_tokenbuf(&dstclass);
+ tokenbuf_free(&srcclass);
+ tokenbuf_free(&dstclass);
return VAR_OK;
error_return:
- free_tokenbuf(search);
- free_tokenbuf(replace);
- free_tokenbuf(&srcclass);
- free_tokenbuf(&dstclass);
+ tokenbuf_free(search);
+ tokenbuf_free(replace);
+ tokenbuf_free(&srcclass);
+ tokenbuf_free(&dstclass);
return rc;
}
-static int cut_out_offset(tokenbuf *data, tokenbuf *number1,
- tokenbuf *number2, int isrange)
+static int cut_out_offset(tokenbuf_t *data, tokenbuf_t *number1,
+ tokenbuf_t *number2, int isrange)
{
- tokenbuf res;
+ tokenbuf_t res;
const char *p;
- size_t num1 = tokenbuf2int(number1);
- size_t num2 = tokenbuf2int(number2);
+ size_t num1 = tokenbuf_toint(number1);
+ size_t num2 = tokenbuf_toint(number2);
/* Determine begin of result string. */
@@ -853,70 +841,70 @@
/* If num2 is zero, we copy the rest from there. */
if (num2 == 0) {
- if (!assign_to_tokenbuf(&res, p, data->end - p))
+ if (!tokenbuf_assign(&res, p, data->end - p))
return VAR_OUT_OF_MEMORY;
} else { /* OK, then use num2. */
if (isrange) {
if ((p + num2) > data->end)
return VAR_RANGE_OUT_OF_BOUNDS;
- if (!assign_to_tokenbuf(&res, p, num2))
+ if (!tokenbuf_assign(&res, p, num2))
return VAR_OUT_OF_MEMORY;
} else {
if (num2 < num1)
return VAR_OFFSET_LOGIC_ERROR;
if ((data->begin + num2) > data->end)
return VAR_RANGE_OUT_OF_BOUNDS;
- if (!assign_to_tokenbuf(&res, p, (data->begin + num2) - p))
+ if (!tokenbuf_assign(&res, p, (data->begin + num2) - p))
return VAR_OUT_OF_MEMORY;
}
}
- free_tokenbuf(data);
- move_tokenbuf(&res, data);
+ tokenbuf_free(data);
+ tokenbuf_move(&res, data);
return VAR_OK;
}
-static int expand_regex_replace(const char *data, tokenbuf *orig,
- regmatch_t *pmatch, tokenbuf *expanded)
+static int expand_regex_replace(const char *data, tokenbuf_t *orig,
+ regmatch_t *pmatch, tokenbuf_t *expanded)
{
const char *p = orig->begin;
size_t i;
- init_tokenbuf(expanded);
+ tokenbuf_init(expanded);
while (p != orig->end) {
if (*p == '\\') {
if (orig->end - p <= 1) {
- free_tokenbuf(expanded);
+ tokenbuf_free(expanded);
return VAR_INCOMPLETE_QUOTED_PAIR;
} else
++p;
if (*p == '\\') {
- if (!append_to_tokenbuf(expanded, p, 1)) {
- free_tokenbuf(expanded);
+ if (!tokenbuf_append(expanded, p, 1)) {
+ tokenbuf_free(expanded);
return VAR_OUT_OF_MEMORY;
}
++p;
continue;
}
if (!isdigit((int)*p)) {
- free_tokenbuf(expanded);
+ tokenbuf_free(expanded);
return VAR_UNKNOWN_QUOTED_PAIR_IN_REPLACE;
}
i = *p - '0';
++p;
if (pmatch[i].rm_so == -1) {
- free_tokenbuf(expanded);
+ tokenbuf_free(expanded);
return VAR_SUBMATCH_OUT_OF_RANGE;
}
- if (!append_to_tokenbuf(expanded, data + pmatch[i].rm_so,
+ if (!tokenbuf_append(expanded, data + pmatch[i].rm_so,
pmatch[i].rm_eo - pmatch[i].rm_so)) {
- free_tokenbuf(expanded);
+ tokenbuf_free(expanded);
return VAR_OUT_OF_MEMORY;
}
} else {
- if (!append_to_tokenbuf(expanded, p, 1)) {
- free_tokenbuf(expanded);
+ if (!tokenbuf_append(expanded, p, 1)) {
+ tokenbuf_free(expanded);
return VAR_OUT_OF_MEMORY;
}
++p;
@@ -926,8 +914,8 @@
return VAR_OK;
}
-static int search_and_replace(tokenbuf *data, tokenbuf *search,
- tokenbuf *replace, tokenbuf *flags)
+static int search_and_replace(tokenbuf_t *data, tokenbuf_t *search,
+ tokenbuf_t *replace, tokenbuf_t *flags)
{
const char *p;
int case_insensitive = 0;
@@ -955,8 +943,8 @@
}
if (no_regex) {
- tokenbuf tmp;
- init_tokenbuf(&tmp);
+ tokenbuf_t tmp;
+ tokenbuf_init(&tmp);
for (p = data->begin; p != data->end;) {
if (case_insensitive)
@@ -966,18 +954,18 @@
rc = strncmp(p, search->begin,
search->end - search->begin);
if (rc != 0) { /* no match, copy character */
- if (!append_to_tokenbuf(&tmp, p, 1)) {
- free_tokenbuf(&tmp);
+ if (!tokenbuf_append(&tmp, p, 1)) {
+ tokenbuf_free(&tmp);
return VAR_OUT_OF_MEMORY;
}
++p;
} else {
- append_to_tokenbuf(&tmp, replace->begin,
+ tokenbuf_append(&tmp, replace->begin,
replace->end - replace->begin);
p += search->end - search->begin;
if (!global) {
- if (!append_to_tokenbuf(&tmp, p, data->end - p)) {
- free_tokenbuf(&tmp);
+ if (!tokenbuf_append(&tmp, p, data->end - p)) {
+ tokenbuf_free(&tmp);
return VAR_OUT_OF_MEMORY;
}
break;
@@ -985,12 +973,12 @@
}
}
- free_tokenbuf(data);
- move_tokenbuf(&tmp, data);
+ tokenbuf_free(data);
+ tokenbuf_move(&tmp, data);
} else {
- tokenbuf tmp;
- tokenbuf mydata;
- tokenbuf myreplace;
+ tokenbuf_t tmp;
+ tokenbuf_t mydata;
+ tokenbuf_t myreplace;
regex_t preg;
regmatch_t pmatch[10];
int regexec_flag;
@@ -998,12 +986,12 @@
/* Copy the pattern and the data to our own buffer to make
sure they're terminated with a null byte. */
- if (!assign_to_tokenbuf
+ if (!tokenbuf_assign
(&tmp, search->begin, search->end - search->begin))
return VAR_OUT_OF_MEMORY;
- if (!assign_to_tokenbuf
+ if (!tokenbuf_assign
(&mydata, data->begin, data->end - data->begin)) {
- free_tokenbuf(&tmp);
+ tokenbuf_free(&tmp);
return VAR_OUT_OF_MEMORY;
}
@@ -1011,9 +999,9 @@
rc = regcomp(&preg, tmp.begin,
REG_EXTENDED | ((case_insensitive) ? REG_ICASE : 0));
- free_tokenbuf(&tmp);
+ tokenbuf_free(&tmp);
if (rc != 0) {
- free_tokenbuf(&mydata);
+ tokenbuf_free(&mydata);
return VAR_INVALID_REGEX_IN_REPLACE;
}
@@ -1028,69 +1016,69 @@
if (regexec
(&preg, p, sizeof(pmatch) / sizeof(regmatch_t), pmatch,
regexec_flag) == REG_NOMATCH) {
- append_to_tokenbuf(&tmp, p, mydata.end - p);
+ tokenbuf_append(&tmp, p, mydata.end - p);
break;
} else {
rc = expand_regex_replace(p, replace, pmatch, &myreplace);
if (rc != VAR_OK) {
regfree(&preg);
- free_tokenbuf(&tmp);
- free_tokenbuf(&mydata);
+ tokenbuf_free(&tmp);
+ tokenbuf_free(&mydata);
return rc;
}
- if (!append_to_tokenbuf(&tmp, p, pmatch[0].rm_so) ||
- !append_to_tokenbuf(&tmp, myreplace.begin,
+ if (!tokenbuf_append(&tmp, p, pmatch[0].rm_so) ||
+ !tokenbuf_append(&tmp, myreplace.begin,
myreplace.end - myreplace.begin)) {
regfree(&preg);
- free_tokenbuf(&tmp);
- free_tokenbuf(&mydata);
- free_tokenbuf(&myreplace);
+ tokenbuf_free(&tmp);
+ tokenbuf_free(&mydata);
+ tokenbuf_free(&myreplace);
return VAR_OUT_OF_MEMORY;
} else {
p += (pmatch[0].rm_eo > 0) ? pmatch[0].rm_eo : 1;
- free_tokenbuf(&myreplace);
+ tokenbuf_free(&myreplace);
}
if (!global) {
- append_to_tokenbuf(&tmp, p, mydata.end - p);
+ tokenbuf_append(&tmp, p, mydata.end - p);
break;
}
}
}
regfree(&preg);
- free_tokenbuf(data);
- move_tokenbuf(&tmp, data);
- free_tokenbuf(&mydata);
+ tokenbuf_free(data);
+ tokenbuf_move(&tmp, data);
+ tokenbuf_free(&mydata);
}
return VAR_OK;
}
-static int padding(tokenbuf *data, tokenbuf *widthstr, tokenbuf *fill,
+static int padding(tokenbuf_t *data, tokenbuf_t *widthstr, tokenbuf_t *fill,
char position)
{
- tokenbuf result;
- size_t width = tokenbuf2int(widthstr);
+ tokenbuf_t result;
+ size_t width = tokenbuf_toint(widthstr);
int i;
if (fill->begin == fill->end)
return VAR_EMPTY_PADDING_FILL_STRING;
- init_tokenbuf(&result);
+ tokenbuf_init(&result);
if (position == 'l') {
i = width - (data->end - data->begin);
if (i > 0) {
i = i / (fill->end - fill->begin);
while (i > 0) {
- if (!append_to_tokenbuf
+ if (!tokenbuf_append
(data, fill->begin, fill->end - fill->begin))
return VAR_OUT_OF_MEMORY;
--i;
}
i = (width - (data->end - data->begin)) % (fill->end -
fill->begin);
- if (!append_to_tokenbuf(data, fill->begin, i))
+ if (!tokenbuf_append(data, fill->begin, i))
return VAR_OUT_OF_MEMORY;
}
} else if (position == 'r') {
@@ -1098,27 +1086,27 @@
if (i > 0) {
i = i / (fill->end - fill->begin);
while (i > 0) {
- if (!append_to_tokenbuf
+ if (!tokenbuf_append
(&result, fill->begin, fill->end - fill->begin)) {
- free_tokenbuf(&result);
+ tokenbuf_free(&result);
return VAR_OUT_OF_MEMORY;
}
--i;
}
i = (width - (data->end - data->begin)) % (fill->end -
fill->begin);
- if (!append_to_tokenbuf(&result, fill->begin, i)) {
- free_tokenbuf(&result);
+ if (!tokenbuf_append(&result, fill->begin, i)) {
+ tokenbuf_free(&result);
return VAR_OUT_OF_MEMORY;
}
- if (!append_to_tokenbuf
+ if (!tokenbuf_append
(&result, data->begin, data->end - data->begin)) {
- free_tokenbuf(&result);
+ tokenbuf_free(&result);
return VAR_OUT_OF_MEMORY;
}
- free_tokenbuf(data);
- move_tokenbuf(&result, data);
+ tokenbuf_free(data);
+ tokenbuf_move(&result, data);
}
} else if (position == 'c') {
i = (width - (data->end - data->begin)) / 2;
@@ -1127,25 +1115,25 @@
i = i / (fill->end - fill->begin);
while (i > 0) {
- if (!append_to_tokenbuf
+ if (!tokenbuf_append
(&result, fill->begin, fill->end - fill->begin)) {
- free_tokenbuf(&result);
+ tokenbuf_free(&result);
return VAR_OUT_OF_MEMORY;
}
--i;
}
i = ((width - (data->end - data->begin)) / 2) % (fill->end -
fill->begin);
- if (!append_to_tokenbuf(&result, fill->begin, i)) {
- free_tokenbuf(&result);
+ if (!tokenbuf_append(&result, fill->begin, i)) {
+ tokenbuf_free(&result);
return VAR_OUT_OF_MEMORY;
}
/* Append the actual data string. */
- if (!append_to_tokenbuf
+ if (!tokenbuf_append
(&result, data->begin, data->end - data->begin)) {
- free_tokenbuf(&result);
+ tokenbuf_free(&result);
return VAR_OUT_OF_MEMORY;
}
@@ -1154,23 +1142,23 @@
i = width - (result.end - result.begin);
i = i / (fill->end - fill->begin);
while (i > 0) {
- if (!append_to_tokenbuf
+ if (!tokenbuf_append
(&result, fill->begin, fill->end - fill->begin)) {
- free_tokenbuf(&result);
+ tokenbuf_free(&result);
return VAR_OUT_OF_MEMORY;
}
--i;
}
i = width - (result.end - result.begin);
- if (!append_to_tokenbuf(&result, fill->begin, i)) {
- free_tokenbuf(&result);
+ if (!tokenbuf_append(&result, fill->begin, i)) {
+ tokenbuf_free(&result);
return VAR_OUT_OF_MEMORY;
}
/* Move string from temporary buffer to data buffer. */
- free_tokenbuf(data);
- move_tokenbuf(&result, data);
+ tokenbuf_free(data);
+ tokenbuf_move(&result, data);
}
}
@@ -1180,21 +1168,21 @@
static int command(const char *begin, const char *end,
const var_config_t *config, const char nameclass[256],
var_cb_t lookup, void *lookup_context, int force_expand,
- tokenbuf *data)
+ tokenbuf_t *data)
{
const char *p = begin;
- tokenbuf tmptokbuf;
- tokenbuf search, replace, flags;
- tokenbuf number1, number2;
+ tokenbuf_t tmptokbuf;
+ tokenbuf_t search, replace, flags;
+ tokenbuf_t number1, number2;
int isrange;
int rc;
- init_tokenbuf(&tmptokbuf);
- init_tokenbuf(&search);
- init_tokenbuf(&replace);
- init_tokenbuf(&flags);
- init_tokenbuf(&number1);
- init_tokenbuf(&number2);
+ tokenbuf_init(&tmptokbuf);
+ tokenbuf_init(&search);
+ tokenbuf_init(&replace);
+ tokenbuf_init(&flags);
+ tokenbuf_init(&number1);
+ tokenbuf_init(&number2);
if (begin == end)
return 0;
@@ -1207,7 +1195,7 @@
we have to copy it before modifying the contents. */
if (data->buffer_size == 0) {
- if (!assign_to_tokenbuf
+ if (!tokenbuf_assign
(data, data->begin, data->end - data->begin)) {
rc = VAR_OUT_OF_MEMORY;
goto error_return;
@@ -1223,7 +1211,7 @@
if (data->begin) {
char *ptr;
if (data->buffer_size == 0) {
- if (!assign_to_tokenbuf
+ if (!tokenbuf_assign
(data, data->begin, data->end - data->begin)) {
rc = VAR_OUT_OF_MEMORY;
goto error_return;
@@ -1275,8 +1263,8 @@
if (data->begin) {
char buf[1024];
sprintf(buf, "%d", data->end - data->begin);
- free_tokenbuf(data);
- if (!assign_to_tokenbuf(data, buf, strlen(buf))) {
+ tokenbuf_free(data);
+ if (!tokenbuf_assign(data, buf, strlen(buf))) {
rc = VAR_OUT_OF_MEMORY;
goto error_return;
}
@@ -1296,8 +1284,8 @@
} else
p += rc;
if (data->begin != NULL && data->begin == data->end) {
- free_tokenbuf(data);
- move_tokenbuf(&tmptokbuf, data);
+ tokenbuf_free(data);
+ tokenbuf_move(&tmptokbuf, data);
}
break;
@@ -1314,10 +1302,10 @@
p += rc;
if (data->begin != NULL) {
if (data->begin == data->end) {
- free_tokenbuf(data);
- move_tokenbuf(&tmptokbuf, data);
+ tokenbuf_free(data);
+ tokenbuf_move(&tmptokbuf, data);
} else {
- free_tokenbuf(data);
+ tokenbuf_free(data);
data->begin = data->end = "";
data->buffer_size = 0;
}
@@ -1337,8 +1325,8 @@
p += rc;
if (data->begin != NULL) {
if (data->begin != data->end) {
- free_tokenbuf(data);
- move_tokenbuf(&tmptokbuf, data);
+ tokenbuf_free(data);
+ tokenbuf_move(&tmptokbuf, data);
}
}
break;
@@ -1493,22 +1481,22 @@
/* Exit gracefully. */
- free_tokenbuf(&tmptokbuf);
- free_tokenbuf(&search);
- free_tokenbuf(&replace);
- free_tokenbuf(&flags);
- free_tokenbuf(&number1);
- free_tokenbuf(&number2);
+ tokenbuf_free(&tmptokbuf);
+ tokenbuf_free(&search);
+ tokenbuf_free(&replace);
+ tokenbuf_free(&flags);
+ tokenbuf_free(&number1);
+ tokenbuf_free(&number2);
return p - begin;
error_return:
- free_tokenbuf(data);
- free_tokenbuf(&tmptokbuf);
- free_tokenbuf(&search);
- free_tokenbuf(&replace);
- free_tokenbuf(&flags);
- free_tokenbuf(&number1);
- free_tokenbuf(&number2);
+ tokenbuf_free(data);
+ tokenbuf_free(&tmptokbuf);
+ tokenbuf_free(&search);
+ tokenbuf_free(&replace);
+ tokenbuf_free(&flags);
+ tokenbuf_free(&number1);
+ tokenbuf_free(&number2);
return rc;
}
@@ -1516,17 +1504,17 @@
const var_config_t *config,
const char nameclass[256], var_cb_t lookup,
void *lookup_context, int force_expand,
- tokenbuf *output)
+ tokenbuf_t *output)
{
int rc;
- tokenbuf result;
+ tokenbuf_t result;
- init_tokenbuf(&result);
+ tokenbuf_init(&result);
do {
rc = text(begin, end, config->varinit, config->escape);
if (rc > 0) {
- if (!append_to_tokenbuf(output, begin, rc)) {
+ if (!tokenbuf_append(output, begin, rc)) {
rc = VAR_OUT_OF_MEMORY;
goto error_return;
}
@@ -1537,7 +1525,7 @@
rc = variable(begin, end, config, nameclass, lookup,
lookup_context, force_expand, &result);
if (rc > 0) {
- if (!append_to_tokenbuf
+ if (!tokenbuf_append
(output, result.begin, result.end - result.begin)) {
rc = VAR_OUT_OF_MEMORY;
goto error_return;
@@ -1556,7 +1544,7 @@
return VAR_OK;
error_return:
- free_tokenbuf(&result);
+ tokenbuf_free(&result);
return rc;
}
@@ -1567,7 +1555,7 @@
{
char nameclass[256];
var_rc_t rc;
- tokenbuf output;
+ tokenbuf_t output;
/* Expand the class description for valid variable names. */
@@ -1593,7 +1581,7 @@
rc = input(input_buf, input_buf + input_len, config, nameclass,
lookup, lookup_context, force_expand, &output);
if (rc != VAR_OK) {
- free_tokenbuf(&output);
+ tokenbuf_free(&output);
return rc;
}
*result = (char *) output.begin;
|