/* Add a value to the list */ int exprValListAdd(exprValList *vlist, char *name, EXPRTYPE val) { exprVal *tmp; exprVal *cur; int result; if(vlist == NULL) return EXPR_ERROR_NULLPOINTER; /* Make sure the name is valid */ if(!exprValidIdent(name)) return EXPR_ERROR_BADIDENTIFIER; if(vlist->head == NULL) { /* Create the node right here */ tmp = exprCreateVal(name, val, NULL); if(tmp == NULL) return EXPR_ERROR_MEMORY; vlist->head = tmp; return EXPR_ERROR_NOERROR; } /* See if already exists */ cur = vlist->head; while(cur) { result = strcmp(name, cur->vname); if(result == 0) return EXPR_ERROR_ALREADYEXISTS; cur = cur->next; } /* We did not find it, create it and add it to the beginning */ tmp = exprCreateVal(name, val, NULL); if(tmp == NULL) return EXPR_ERROR_MEMORY; tmp->next = vlist->head; vlist->head = tmp; return EXPR_ERROR_NOERROR; }
/* This routine will create the function object */ exprFunc *exprCreateFunc(exprFuncType ptr, char *name, int min, int max, int refmin, int refmax) { exprFunc *tmp; char *vtmp; /* Make sure the name is valid */ if(!exprValidIdent(name)) return NULL; /* Create it */ tmp = exprAllocMem(sizeof(exprFunc)); if(tmp == NULL) return NULL; /* Allocate space for the name */ vtmp = exprAllocMem(strlen(name) + 1); if(vtmp == NULL) { exprFreeMem(tmp); return NULL; } /* Set the memory to zero */ memset(tmp, 0, sizeof(exprFunc)); /* Copy the data over */ strcpy(vtmp, name); tmp->fname = vtmp; tmp->fptr = ptr; tmp->min = min; tmp->max = max; tmp->refmin = refmin; tmp->refmax = refmax; return tmp; }