static struct variable*
find_var(char* name, char* value, struct list* hash)
{
- int n, found = 0;
+ int n;
struct variable *p;
n = get_bucket_number(name);
-
- if (isupper(*name)){
- LIST_FOREACH(p, hash + n)
- if (!strcasecmp(p->name,name)){
- found = 1;
- break;
- }
- } else {
- LIST_FOREACH(p, hash + n)
- if (!strcmp(p->name, name)){
- found = 1;
- break;
+ int nocase = !isupper(*name);
+ LIST_FOREACH(p, hash + n)
+ if (!(nocase ? strcasecmp : strcmp)(p->name,name)){
+ if (value){
+ free(p->value);
+ p->value = value;
+ p->modified = 1;
}
- }
-
- if (found && value){
- free(p->value);
- p->value = value;
- p->modified = 1;
- } else if (found && !value)
- return p;
- else {
- p = xmalloc(sizeof(struct variable));
- p->name = name;
- p->value = (value? value:xstrdup(""));
- p->modified = 1;
-
- list_add_last(hash+n, &p->car);
- }
+ return p;
+ }
+ p = xmalloc(sizeof(struct variable));
+ p->name = xstrdup(name);
+ p->value = (value? value:xstrdup(""));
+ p->modified = 1;
+ list_add_last(hash+n, &p->car);
return p;
}
return regex_cmp(left,right);
case CC('!','~'):
return !regex_cmp(left,right);
+ default:
+ die("Brrrchlemst!");
} //TODO: add numbers
} else {
return (left || right) && !(left && right);
case '!':
return !left;
+ default:
+ die("Brrrchlemst!");
}
}
}