aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2006-01-30 06:11:36 +0000
committerreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2006-01-30 06:11:36 +0000
commitf521492608acc6f19b5053512fe9eb68fb92ac79 (patch)
treebc0cc8b97e0431b5d58fae80d619eae61b04507e
parent2523e50fbb5a076f9535c18dcce9ed7a0716e28d (diff)
downloadlcd4linux-f521492608acc6f19b5053512fe9eb68fb92ac79.tar.gz
[lcd4linux @ 2006-01-30 06:11:36 by reinelt]
changed Result->length to Result->size git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@627 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
-rw-r--r--evaluator.c45
-rw-r--r--evaluator.h7
2 files changed, 28 insertions, 24 deletions
diff --git a/evaluator.c b/evaluator.c
index c26fb72..86235a1 100644
--- a/evaluator.c
+++ b/evaluator.c
@@ -1,4 +1,4 @@
-/* $Id: evaluator.c,v 1.28 2006/01/30 05:47:38 reinelt Exp $
+/* $Id: evaluator.c,v 1.29 2006/01/30 06:11:36 reinelt Exp $
*
* expression evaluation
*
@@ -23,6 +23,9 @@
*
*
* $Log: evaluator.c,v $
+ * Revision 1.29 2006/01/30 06:11:36 reinelt
+ * changed Result->length to Result->size
+ *
* Revision 1.28 2006/01/30 05:47:38 reinelt
* graphic subsystem changed to full-color RGBA
*
@@ -315,8 +318,8 @@ static int nFunction = 0;
void DelResult(RESULT * result)
{
result->type = 0;
+ result->size = 0;
result->number = 0.0;
- result->length = -1;
if (result->string) {
free(result->string);
result->string = NULL;
@@ -341,8 +344,8 @@ static RESULT *NewResult(void)
return NULL;
}
result->type = 0;
+ result->size = 0;
result->number = 0.0;
- result->length = -1;
result->string = NULL;
return result;
@@ -360,8 +363,8 @@ RESULT *SetResult(RESULT ** result, const int type, const void *value)
if (type == R_NUMBER) {
(*result)->type = R_NUMBER;
+ (*result)->size = 0;
(*result)->number = *(double *) value;
- (*result)->length = -1;
(*result)->string = NULL;
}
@@ -369,16 +372,15 @@ RESULT *SetResult(RESULT ** result, const int type, const void *value)
int len = strlen((char *) value);
(*result)->type = R_STRING;
(*result)->number = 0.0;
- if ((*result)->string == NULL || len > (*result)->length) {
+ if ((*result)->string == NULL || len >= (*result)->size) {
/* buffer is either empty or too small */
if ((*result)->string)
free((*result)->string);
/* allocate memory in multiples of CHUNK_SIZE */
- /* note that length does not count the trailing \0 */
- (*result)->length = CHUNK_SIZE * (len / CHUNK_SIZE + 1) - 1;
- (*result)->string = malloc((*result)->length + 1);
+ (*result)->size = CHUNK_SIZE * (len / CHUNK_SIZE + 1);
+ (*result)->string = malloc((*result)->size);
}
- strncpy((*result)->string, value, (*result)->length + 1);
+ strncpy((*result)->string, value, (*result)->size);
} else {
error("Evaluator: internal error: invalid result type %d", type);
return NULL;
@@ -399,20 +401,19 @@ static RESULT *CopyResult(RESULT ** result, RESULT * value)
(*result)->number = value->number;
if (value->string == NULL) {
+ (*result)->size = 0;
if ((*result)->string)
free((*result)->string);
(*result)->string = NULL;
- (*result)->length = -1;
} else {
/* is buffer large enough? */
- if ((*result)->string == NULL || value->length > (*result)->length) {
+ if ((*result)->string == NULL || value->size > (*result)->size) {
if ((*result)->string)
free((*result)->string);
- (*result)->length = value->length;
- (*result)->string = malloc((*result)->length + 1);
- /* length does not count the trailing \0 */
+ (*result)->size = value->size;
+ (*result)->string = malloc((*result)->size);
}
- strncpy((*result)->string, value->string, (*result)->length + 1);
+ strncpy((*result)->string, value->string, (*result)->size);
}
return *result;
}
@@ -455,9 +456,9 @@ char *R2S(RESULT * result)
result->type |= R_STRING;
if (result->string)
free(result->string);
- result->length = CHUNK_SIZE - 1;
- result->string = malloc(result->length + 1);
- snprintf(result->string, result->length, "%g", result->number);
+ result->size = CHUNK_SIZE;
+ result->string = malloc(result->size);
+ snprintf(result->string, result->size, "%g", result->number);
return result->string;
}
@@ -1309,12 +1310,12 @@ int Eval(void *tree, RESULT * result)
ret = EvalTree(Tree);
result->type = Tree->Result->type;
+ result->size = Tree->Result->size;
result->number = Tree->Result->number;
- result->length = Tree->Result->length;
- if (result->length >= 0) {
- result->string = malloc(result->length + 1);
+ if (result->size > 0) {
+ result->string = malloc(result->size);
if (Tree->Result->string != NULL) {
- strncpy(result->string, Tree->Result->string, result->length + 1);
+ strncpy(result->string, Tree->Result->string, result->size);
} else
result->string[0] = '\0';
} else {
diff --git a/evaluator.h b/evaluator.h
index 6c3016c..10bd807 100644
--- a/evaluator.h
+++ b/evaluator.h
@@ -1,4 +1,4 @@
-/* $Id: evaluator.h,v 1.11 2005/05/08 04:32:44 reinelt Exp $
+/* $Id: evaluator.h,v 1.12 2006/01/30 06:11:36 reinelt Exp $
*
* expression evaluation
*
@@ -23,6 +23,9 @@
*
*
* $Log: evaluator.h,v $
+ * Revision 1.12 2006/01/30 06:11:36 reinelt
+ * changed Result->length to Result->size
+ *
* Revision 1.11 2005/05/08 04:32:44 reinelt
* CodingStyle added and applied
*
@@ -90,8 +93,8 @@
typedef struct {
int type;
+ int size;
double number;
- int length;
char *string;
} RESULT;