X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?p=YACASL2.git;a=blobdiff_plain;f=src%2Flabel.c;h=d740b2e368f2a69eb4771ef4f3c6a2b8d016014a;hp=035665ad450ee4e14dab63d869c7b0c37ffcfd26;hb=cc884e475afe3f48804b35336e68bce4088be61a;hpb=534506a757688db300328b7141bab4d6d0bd4e29 diff --git a/src/label.c b/src/label.c index 035665a..d740b2e 100644 --- a/src/label.c +++ b/src/label.c @@ -3,13 +3,31 @@ LABELTAB *labels[LABELTABSIZE]; +/* プログラム名とラベルに対応するハッシュ値を返す */ +unsigned labelhash(const char *prog, const char *label) +{ + HKEY *keys[2]; + int i = 0; + if(prog != NULL) { + keys[i] = malloc(sizeof(HKEY)); + keys[i]->type = CHARS; + keys[i++]->val.s = strdup(prog); + } + keys[i] = malloc(sizeof(HKEY)); + keys[i]->type = CHARS; + keys[i]->val.s = strdup(label); + /* ハッシュ値を返す */ + return hash(i+1, keys, LABELTABSIZE); +} + /* ラベル表からアドレスを検索する */ WORD getlabel(const char *prog, const char *label) { LABELTAB *np; - - for(np = labels[hash(label, LABELTABSIZE)]; np != NULL; np = np->next) { - if(strcmp(label, np->label) == 0) { + for(np = labels[labelhash(prog, label)]; np != NULL; np = np->next) { + if((prog == NULL || (np->prog != NULL && strcmp(prog, np->prog) == 0)) && + strcmp(label, np->label) == 0) + { return np->adr; } } @@ -21,6 +39,8 @@ bool addlabel(const char *prog, const char *label, WORD adr) { LABELTAB *np; unsigned hashval; + char *keys[2]; + int i = 0; if(getlabel(prog, label) != 0xFFFF) { setcerr(101, label); /* label already defined */ @@ -33,7 +53,11 @@ bool addlabel(const char *prog, const char *label, WORD adr) setcerr(102, NULL); /* label table is full */ return false; } - hashval = hash(label, LABELTABSIZE); + if(prog != NULL) { + keys[i++] = strdup(prog); + } + keys[i] = strdup(label);; + hashval = labelhash(prog, label); np->next = labels[hashval]; labels[hashval] = np; np->adr = adr;