From cbd2e1f8450c79a88ab705ebd5f4efb025036636 Mon Sep 17 00:00:00 2001 From: Anicka Bernathova Date: Mon, 14 Jul 2008 00:37:12 +0200 Subject: [PATCH] cleanup --- Makefile | 2 +- int.c | 48 +++++++++++++++++++----------------------------- 2 files changed, 20 insertions(+), 30 deletions(-) diff --git a/Makefile b/Makefile index a699fee..beb1a6e 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ all: brum CC=gcc -CFLAGS=-Wall -W -Wno-pointer-sign -g +CFLAGS=-Wall -W -Wno-pointer-sign -Wstrict-prototypes -Wmissing-prototypes -O2 -g LDLIBS=-lpcre brum: brum.c cond.tab.o int.o lex.o ham.o lists.o diff --git a/int.c b/int.c index a948180..8da089b 100644 --- a/int.c +++ b/int.c @@ -42,40 +42,26 @@ get_bucket_number(char* name) 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; } @@ -220,6 +206,8 @@ interp_cond(struct tree* t, struct list* hash) return regex_cmp(left,right); case CC('!','~'): return !regex_cmp(left,right); + default: + die("Brrrchlemst!"); } //TODO: add numbers } else { @@ -238,6 +226,8 @@ interp_cond(struct tree* t, struct list* hash) return (left || right) && !(left && right); case '!': return !left; + default: + die("Brrrchlemst!"); } } } -- 2.39.2