--- var.c 2001/11/14 09:47:02 1.13
+++ var.c 2001/11/14 11:11:01 1.14
@@ -187,7 +187,7 @@
while (*desc != '\0') {
if (desc[1] == '-' && desc[2] != '\0') {
if (desc[0] > desc[2])
- return VAR_INCORRECT_CLASS_SPEC;
+ return VAR_ERR_INCORRECT_CLASS_SPEC;
expand_range(desc[0], desc[2], class);
desc += 3;
} else {
@@ -212,13 +212,13 @@
unsigned char c;
if (end - *src < 3)
- return VAR_INCOMPLETE_OCTAL;
+ return VAR_ERR_INCOMPLETE_OCTAL;
if (!isoct(**src) || !isoct((*src)[1]) || !isoct((*src)[2]))
- return VAR_INVALID_OCTAL;
+ return VAR_ERR_INVALID_OCTAL;
c = **src - '0';
if (c > 3)
- return VAR_OCTAL_TOO_LARGE;
+ return VAR_ERR_OCTAL_TOO_LARGE;
c *= 8;
++(*src);
@@ -248,9 +248,9 @@
unsigned char c = 0;
if (end - *src < 2)
- return VAR_INCOMPLETE_HEX;
+ return VAR_ERR_INCOMPLETE_HEX;
if (!ishex(**src) || !ishex((*src)[1]))
- return VAR_INVALID_HEX;
+ return VAR_ERR_INVALID_HEX;
if (**src >= '0' && **src <= '9')
c = **src - '0';
@@ -285,7 +285,7 @@
++(*src);
}
if (*src == end)
- return VAR_INCOMPLETE_GROUPED_HEX;
+ return VAR_ERR_INCOMPLETE_GROUPED_HEX;
return VAR_OK;
}
@@ -293,7 +293,7 @@
static var_rc_t expand_hex(const char **src, char **dst, const char *end)
{
if (*src == end)
- return VAR_INCOMPLETE_HEX;
+ return VAR_ERR_INCOMPLETE_HEX;
if (**src == '{') {
++(*src);
return expand_grouped_hex(src, dst, end);
@@ -310,7 +310,7 @@
while (src < end) {
if (*src == '\\') {
if (++src == end)
- return VAR_INCOMPLETE_NAMED_CHARACTER;
+ return VAR_ERR_INCOMPLETE_NAMED_CHARACTER;
switch (*src) {
case '\\':
if (!unescape_all) {
@@ -375,7 +375,7 @@
for (p = begin; p != end && *p != varinit; ++p) {
if (*p == escape) {
if (p + 1 == end)
- return VAR_INCOMPLETE_QUOTED_PAIR;
+ return VAR_ERR_INCOMPLETE_QUOTED_PAIR;
else
++p;
}
@@ -405,7 +405,7 @@
for (p = begin; p != end && *p != config->varinit && *p != '/'; ++p) {
if (*p == config->escape) {
if (p + 1 == end)
- return VAR_INCOMPLETE_QUOTED_PAIR;
+ return VAR_ERR_INCOMPLETE_QUOTED_PAIR;
else
++p;
}
@@ -422,7 +422,7 @@
&& *p != ':'; ++p) {
if (*p == config->escape) {
if (p + 1 == end)
- return VAR_INCOMPLETE_QUOTED_PAIR;
+ return VAR_ERR_INCOMPLETE_QUOTED_PAIR;
else
++p;
}
@@ -457,7 +457,7 @@
return 0;
if (++p == end)
- return VAR_INCOMPLETE_VARIABLE_SPEC;
+ return VAR_ERR_INCOMPLETE_VARIABLE_SPEC;
/* Get the name of the variable to expand. The name may consist of
an arbitrary number of VARNAMEs and VARIABLEs. */
@@ -468,7 +468,7 @@
goto error_return;
else if (rc > 0) {
if (!tokenbuf_append(&name, p, rc)) {
- rc = VAR_OUT_OF_MEMORY;
+ rc = VAR_ERR_OUT_OF_MEMORY;
goto error_return;
} else
p += rc;
@@ -480,7 +480,7 @@
goto error_return;
else if (rc > 0) {
if (!tokenbuf_append(&name, tmp.begin, tmp.end - tmp.begin)) {
- rc = VAR_OUT_OF_MEMORY;
+ rc = VAR_ERR_OUT_OF_MEMORY;
goto error_return;
} else
p += rc;
@@ -492,7 +492,7 @@
do. */
if (name.begin == name.end) {
- rc = VAR_INCOMPLETE_VARIABLE_SPEC;
+ rc = VAR_ERR_INCOMPLETE_VARIABLE_SPEC;
goto error_return;
}
@@ -500,7 +500,7 @@
expect an ENDDELIM here. */
if (p == end || (*p != config->enddelim && *p != ':')) {
- rc = VAR_INCOMPLETE_VARIABLE_SPEC;
+ rc = VAR_ERR_INCOMPLETE_VARIABLE_SPEC;
goto error_return;
} else
++p;
@@ -516,7 +516,7 @@
force_expand flag. */
if (force_expand) {
- rc = VAR_UNDEFINED_VARIABLE;
+ rc = VAR_ERR_UNDEFINED_VARIABLE;
goto error_return;
} else {
/* Initialize result to point back to the original text in
@@ -557,7 +557,7 @@
}
if (p == end || *p != config->enddelim) {
- rc = VAR_INCOMPLETE_VARIABLE_SPEC;
+ rc = VAR_ERR_INCOMPLETE_VARIABLE_SPEC;
goto error_return;
}
++p;
@@ -601,7 +601,7 @@
return 0;
if (++p == end)
- return VAR_INCOMPLETE_VARIABLE_SPEC;
+ return VAR_ERR_INCOMPLETE_VARIABLE_SPEC;
/* Try to read the variable name. If that fails, we're parsing a
complex expression. */
@@ -615,7 +615,7 @@
return rc2;
else if (rc2 == 0) {
if (force_expand)
- return VAR_UNDEFINED_VARIABLE;
+ return VAR_ERR_UNDEFINED_VARIABLE;
else {
result->begin = begin;
result->end = begin + 1 + rc;
@@ -661,7 +661,7 @@
goto error_return;
else if (rc > 0) {
if (!tokenbuf_append(result, p, rc)) {
- rc = VAR_OUT_OF_MEMORY;
+ rc = VAR_ERR_OUT_OF_MEMORY;
goto error_return;
} else
p += rc;
@@ -675,7 +675,7 @@
p += rc;
if (!tokenbuf_append
(result, tmp.begin, tmp.end - tmp.begin)) {
- rc = VAR_OUT_OF_MEMORY;
+ rc = VAR_ERR_OUT_OF_MEMORY;
goto error_return;
}
}
@@ -713,7 +713,7 @@
goto error_return;
else if (rc > 0) {
if (!tokenbuf_append(result, p, rc)) {
- rc = VAR_OUT_OF_MEMORY;
+ rc = VAR_ERR_OUT_OF_MEMORY;
goto error_return;
} else
p += rc;
@@ -727,7 +727,7 @@
p += rc;
if (!tokenbuf_append
(result, tmp.begin, tmp.end - tmp.begin)) {
- rc = VAR_OUT_OF_MEMORY;
+ rc = VAR_ERR_OUT_OF_MEMORY;
goto error_return;
}
}
@@ -751,15 +751,15 @@
while (p != src->end) {
if ((src->end - p) >= 3 && p[1] == '-') {
if (*p > p[2])
- return VAR_INCORRECT_TRANSPOSE_CLASS_SPEC;
+ return VAR_ERR_INCORRECT_TRANSPOSE_CLASS_SPEC;
for (c = *p, d = p[2]; c <= d; ++c) {
if (!tokenbuf_append(dst, (char *) &c, 1))
- return VAR_OUT_OF_MEMORY;
+ return VAR_ERR_OUT_OF_MEMORY;
}
p += 3;
} else {
if (!tokenbuf_append(dst, p, 1))
- return VAR_OUT_OF_MEMORY;
+ return VAR_ERR_OUT_OF_MEMORY;
else
++p;
}
@@ -784,11 +784,11 @@
goto error_return;
if (srcclass.begin == srcclass.end) {
- rc = VAR_EMPTY_TRANSPOSE_CLASS;
+ rc = VAR_ERR_EMPTY_TRANSPOSE_CLASS;
goto error_return;
}
if ((srcclass.end - srcclass.begin) != (dstclass.end - dstclass.begin)) {
- rc = VAR_TRANSPOSE_CLASSES_MISMATCH;
+ rc = VAR_ERR_TRANSPOSE_CLASSES_MISMATCH;
goto error_return;
}
@@ -796,7 +796,7 @@
tokenbuf_t tmp;
if (!tokenbuf_assign
(&tmp, data->begin, data->end - data->begin)) {
- rc = VAR_OUT_OF_MEMORY;
+ rc = VAR_ERR_OUT_OF_MEMORY;
goto error_return;
}
tokenbuf_move(&tmp, data);
@@ -834,7 +834,7 @@
/* Determine begin of result string. */
if ((data->end - data->begin) < num1)
- return VAR_OFFSET_OUT_OF_BOUNDS;
+ return VAR_ERR_OFFSET_OUT_OF_BOUNDS;
else
p = data->begin + num1;
@@ -842,21 +842,21 @@
if (num2 == 0) {
if (!tokenbuf_assign(&res, p, data->end - p))
- return VAR_OUT_OF_MEMORY;
+ return VAR_ERR_OUT_OF_MEMORY;
} else { /* OK, then use num2. */
if (isrange) {
if ((p + num2) > data->end)
- return VAR_RANGE_OUT_OF_BOUNDS;
+ return VAR_ERR_RANGE_OUT_OF_BOUNDS;
if (!tokenbuf_assign(&res, p, num2))
- return VAR_OUT_OF_MEMORY;
+ return VAR_ERR_OUT_OF_MEMORY;
} else {
if (num2 < num1)
- return VAR_OFFSET_LOGIC_ERROR;
+ return VAR_ERR_OFFSET_LOGIC;
if ((data->begin + num2) > data->end)
- return VAR_RANGE_OUT_OF_BOUNDS;
+ return VAR_ERR_RANGE_OUT_OF_BOUNDS;
if (!tokenbuf_assign(&res, p, (data->begin + num2) - p))
- return VAR_OUT_OF_MEMORY;
+ return VAR_ERR_OUT_OF_MEMORY;
}
}
tokenbuf_free(data);
@@ -876,36 +876,36 @@
if (*p == '\\') {
if (orig->end - p <= 1) {
tokenbuf_free(expanded);
- return VAR_INCOMPLETE_QUOTED_PAIR;
+ return VAR_ERR_INCOMPLETE_QUOTED_PAIR;
} else
++p;
if (*p == '\\') {
if (!tokenbuf_append(expanded, p, 1)) {
tokenbuf_free(expanded);
- return VAR_OUT_OF_MEMORY;
+ return VAR_ERR_OUT_OF_MEMORY;
}
++p;
continue;
}
if (!isdigit((int)*p)) {
tokenbuf_free(expanded);
- return VAR_UNKNOWN_QUOTED_PAIR_IN_REPLACE;
+ return VAR_ERR_UNKNOWN_QUOTED_PAIR_IN_REPLACE;
}
i = *p - '0';
++p;
if (pmatch[i].rm_so == -1) {
tokenbuf_free(expanded);
- return VAR_SUBMATCH_OUT_OF_RANGE;
+ return VAR_ERR_SUBMATCH_OUT_OF_RANGE;
}
if (!tokenbuf_append(expanded, data + pmatch[i].rm_so,
pmatch[i].rm_eo - pmatch[i].rm_so)) {
tokenbuf_free(expanded);
- return VAR_OUT_OF_MEMORY;
+ return VAR_ERR_OUT_OF_MEMORY;
}
} else {
if (!tokenbuf_append(expanded, p, 1)) {
tokenbuf_free(expanded);
- return VAR_OUT_OF_MEMORY;
+ return VAR_ERR_OUT_OF_MEMORY;
}
++p;
}
@@ -924,7 +924,7 @@
int rc;
if (search->begin == search->end)
- return VAR_EMPTY_SEARCH_STRING;
+ return VAR_ERR_EMPTY_SEARCH_STRING;
for (p = flags->begin; p != flags->end; ++p) {
switch (tolower(*p)) {
@@ -938,7 +938,7 @@
no_regex = 1;
break;
default:
- return VAR_UNKNOWN_REPLACE_FLAG;
+ return VAR_ERR_UNKNOWN_REPLACE_FLAG;
}
}
@@ -956,7 +956,7 @@
if (rc != 0) { /* no match, copy character */
if (!tokenbuf_append(&tmp, p, 1)) {
tokenbuf_free(&tmp);
- return VAR_OUT_OF_MEMORY;
+ return VAR_ERR_OUT_OF_MEMORY;
}
++p;
} else {
@@ -966,7 +966,7 @@
if (!global) {
if (!tokenbuf_append(&tmp, p, data->end - p)) {
tokenbuf_free(&tmp);
- return VAR_OUT_OF_MEMORY;
+ return VAR_ERR_OUT_OF_MEMORY;
}
break;
}
@@ -988,11 +988,11 @@
if (!tokenbuf_assign
(&tmp, search->begin, search->end - search->begin))
- return VAR_OUT_OF_MEMORY;
+ return VAR_ERR_OUT_OF_MEMORY;
if (!tokenbuf_assign
(&mydata, data->begin, data->end - data->begin)) {
tokenbuf_free(&tmp);
- return VAR_OUT_OF_MEMORY;
+ return VAR_ERR_OUT_OF_MEMORY;
}
/* Compile the pattern. */
@@ -1002,7 +1002,7 @@
tokenbuf_free(&tmp);
if (rc != 0) {
tokenbuf_free(&mydata);
- return VAR_INVALID_REGEX_IN_REPLACE;
+ return VAR_ERR_INVALID_REGEX_IN_REPLACE;
}
/* Match the pattern and create the result string in the tmp
@@ -1033,7 +1033,7 @@
tokenbuf_free(&tmp);
tokenbuf_free(&mydata);
tokenbuf_free(&myreplace);
- return VAR_OUT_OF_MEMORY;
+ return VAR_ERR_OUT_OF_MEMORY;
} else {
p += (pmatch[0].rm_eo > 0) ? pmatch[0].rm_eo : 1;
tokenbuf_free(&myreplace);
@@ -1062,7 +1062,7 @@
int i;
if (fill->begin == fill->end)
- return VAR_EMPTY_PADDING_FILL_STRING;
+ return VAR_ERR_EMPTY_PADDING_FILL_STRING;
tokenbuf_init(&result);
@@ -1073,13 +1073,13 @@
while (i > 0) {
if (!tokenbuf_append
(data, fill->begin, fill->end - fill->begin))
- return VAR_OUT_OF_MEMORY;
+ return VAR_ERR_OUT_OF_MEMORY;
--i;
}
i = (width - (data->end - data->begin)) % (fill->end -
fill->begin);
if (!tokenbuf_append(data, fill->begin, i))
- return VAR_OUT_OF_MEMORY;
+ return VAR_ERR_OUT_OF_MEMORY;
}
} else if (position == 'r') {
i = width - (data->end - data->begin);
@@ -1089,7 +1089,7 @@
if (!tokenbuf_append
(&result, fill->begin, fill->end - fill->begin)) {
tokenbuf_free(&result);
- return VAR_OUT_OF_MEMORY;
+ return VAR_ERR_OUT_OF_MEMORY;
}
--i;
}
@@ -1097,12 +1097,12 @@
fill->begin);
if (!tokenbuf_append(&result, fill->begin, i)) {
tokenbuf_free(&result);
- return VAR_OUT_OF_MEMORY;
+ return VAR_ERR_OUT_OF_MEMORY;
}
if (!tokenbuf_append
(&result, data->begin, data->end - data->begin)) {
tokenbuf_free(&result);
- return VAR_OUT_OF_MEMORY;
+ return VAR_ERR_OUT_OF_MEMORY;
}
tokenbuf_free(data);
@@ -1118,7 +1118,7 @@
if (!tokenbuf_append
(&result, fill->begin, fill->end - fill->begin)) {
tokenbuf_free(&result);
- return VAR_OUT_OF_MEMORY;
+ return VAR_ERR_OUT_OF_MEMORY;
}
--i;
}
@@ -1126,7 +1126,7 @@
fill->begin);
if (!tokenbuf_append(&result, fill->begin, i)) {
tokenbuf_free(&result);
- return VAR_OUT_OF_MEMORY;
+ return VAR_ERR_OUT_OF_MEMORY;
}
/* Append the actual data string. */
@@ -1134,7 +1134,7 @@
if (!tokenbuf_append
(&result, data->begin, data->end - data->begin)) {
tokenbuf_free(&result);
- return VAR_OUT_OF_MEMORY;
+ return VAR_ERR_OUT_OF_MEMORY;
}
/* Append the suffix. */
@@ -1145,14 +1145,14 @@
if (!tokenbuf_append
(&result, fill->begin, fill->end - fill->begin)) {
tokenbuf_free(&result);
- return VAR_OUT_OF_MEMORY;
+ return VAR_ERR_OUT_OF_MEMORY;
}
--i;
}
i = width - (result.end - result.begin);
if (!tokenbuf_append(&result, fill->begin, i)) {
tokenbuf_free(&result);
- return VAR_OUT_OF_MEMORY;
+ return VAR_ERR_OUT_OF_MEMORY;
}
/* Move string from temporary buffer to data buffer. */
@@ -1197,7 +1197,7 @@
if (data->buffer_size == 0) {
if (!tokenbuf_assign
(data, data->begin, data->end - data->begin)) {
- rc = VAR_OUT_OF_MEMORY;
+ rc = VAR_ERR_OUT_OF_MEMORY;
goto error_return;
}
}
@@ -1213,7 +1213,7 @@
if (data->buffer_size == 0) {
if (!tokenbuf_assign
(data, data->begin, data->end - data->begin)) {
- rc = VAR_OUT_OF_MEMORY;
+ rc = VAR_ERR_OUT_OF_MEMORY;
goto error_return;
}
}
@@ -1227,7 +1227,7 @@
++p;
rc = number(p, end);
if (rc == 0) {
- rc = VAR_MISSING_START_OFFSET;
+ rc = VAR_ERR_MISSING_START_OFFSET;
goto error_return;
} else {
number1.begin = p;
@@ -1243,7 +1243,7 @@
isrange = 1;
++p;
} else {
- rc = VAR_INVALID_OFFSET_DELIMITER;
+ rc = VAR_ERR_INVALID_OFFSET_DELIMITER;
goto error_return;
}
@@ -1265,7 +1265,7 @@
sprintf(buf, "%d", data->end - data->begin);
tokenbuf_free(data);
if (!tokenbuf_assign(data, buf, strlen(buf))) {
- rc = VAR_OUT_OF_MEMORY;
+ rc = VAR_ERR_OUT_OF_MEMORY;
goto error_return;
}
}
@@ -1279,7 +1279,7 @@
if (rc < 0)
goto error_return;
else if (rc == 0) {
- rc = VAR_MISSING_PARAMETER_IN_COMMAND;
+ rc = VAR_ERR_MISSING_PARAMETER_IN_COMMAND;
goto error_return;
} else
p += rc;
@@ -1296,7 +1296,7 @@
if (rc < 0)
goto error_return;
else if (rc == 0) {
- rc = VAR_MISSING_PARAMETER_IN_COMMAND;
+ rc = VAR_ERR_MISSING_PARAMETER_IN_COMMAND;
goto error_return;
} else
p += rc;
@@ -1319,7 +1319,7 @@
if (rc < 0)
goto error_return;
else if (rc == 0) {
- rc = VAR_MISSING_PARAMETER_IN_COMMAND;
+ rc = VAR_ERR_MISSING_PARAMETER_IN_COMMAND;
goto error_return;
} else
p += rc;
@@ -1335,7 +1335,7 @@
++p;
if (*p != '/')
- return VAR_MALFORMATTED_REPLACE;
+ return VAR_ERR_MALFORMATTED_REPLACE;
else
++p;
@@ -1347,7 +1347,7 @@
p += rc;
if (*p != '/') {
- rc = VAR_MALFORMATTED_REPLACE;
+ rc = VAR_ERR_MALFORMATTED_REPLACE;
goto error_return;
} else
++p;
@@ -1360,7 +1360,7 @@
p += rc;
if (*p != '/') {
- rc = VAR_MALFORMATTED_REPLACE;
+ rc = VAR_ERR_MALFORMATTED_REPLACE;
goto error_return;
} else
++p;
@@ -1386,7 +1386,7 @@
++p;
if (*p != '/')
- return VAR_MALFORMATTED_TRANSPOSE;
+ return VAR_ERR_MALFORMATTED_TRANSPOSE;
else
++p;
@@ -1398,7 +1398,7 @@
p += rc;
if (*p != '/') {
- rc = VAR_MALFORMATTED_TRANSPOSE;
+ rc = VAR_ERR_MALFORMATTED_TRANSPOSE;
goto error_return;
} else
++p;
@@ -1411,7 +1411,7 @@
p += rc;
if (*p != '/') {
- rc = VAR_MALFORMATTED_TRANSPOSE;
+ rc = VAR_ERR_MALFORMATTED_TRANSPOSE;
goto error_return;
} else
++p;
@@ -1428,13 +1428,13 @@
++p;
if (*p != '/')
- return VAR_MALFORMATTED_PADDING;
+ return VAR_ERR_MALFORMATTED_PADDING;
else
++p;
rc = number(p, end);
if (rc == 0) {
- rc = VAR_MISSING_PADDING_WIDTH;
+ rc = VAR_ERR_MISSING_PADDING_WIDTH;
goto error_return;
} else {
number1.begin = p;
@@ -1444,7 +1444,7 @@
}
if (*p != '/') {
- rc = VAR_MALFORMATTED_PADDING;
+ rc = VAR_ERR_MALFORMATTED_PADDING;
goto error_return;
} else
++p;
@@ -1457,13 +1457,13 @@
p += rc;
if (*p != '/') {
- rc = VAR_MALFORMATTED_PADDING;
+ rc = VAR_ERR_MALFORMATTED_PADDING;
goto error_return;
} else
++p;
if (*p != 'l' && *p != 'c' && *p != 'r') {
- rc = VAR_MALFORMATTED_PADDING;
+ rc = VAR_ERR_MALFORMATTED_PADDING;
goto error_return;
} else
++p;
@@ -1476,7 +1476,7 @@
break;
default:
- return VAR_UNKNOWN_COMMAND_CHAR;
+ return VAR_ERR_UNKNOWN_COMMAND_CHAR;
}
/* Exit gracefully. */
@@ -1515,7 +1515,7 @@
rc = text(begin, end, config->varinit, config->escape);
if (rc > 0) {
if (!tokenbuf_append(output, begin, rc)) {
- rc = VAR_OUT_OF_MEMORY;
+ rc = VAR_ERR_OUT_OF_MEMORY;
goto error_return;
}
begin += rc;
@@ -1527,7 +1527,7 @@
if (rc > 0) {
if (!tokenbuf_append
(output, result.begin, result.end - result.begin)) {
- rc = VAR_OUT_OF_MEMORY;
+ rc = VAR_ERR_OUT_OF_MEMORY;
goto error_return;
} else
begin += rc;
@@ -1537,7 +1537,7 @@
while (rc > 0);
if (begin != end) {
- rc = VAR_INPUT_ISNT_TEXT_NOR_VARIABLE;
+ rc = VAR_ERR_INPUT_ISNT_TEXT_NOR_VARIABLE;
goto error_return;
}
@@ -1572,7 +1572,7 @@
nameclass[(int) config->startdelim] ||
nameclass[(int) config->enddelim] ||
nameclass[(int) config->escape])
- return VAR_INVALID_CONFIGURATION;
+ return VAR_ERR_INVALID_CONFIGURATION;
/* Call the parser. */
|