X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?p=YACASL2.git;a=blobdiff_plain;f=src%2Flabel.c;h=d740b2e368f2a69eb4771ef4f3c6a2b8d016014a;hp=5a0b4cc9aa540cbaa3cd20bbf9938a81076f10fb;hb=555e213c3a100db431fec78cbba6dfed8e541e2a;hpb=0423c8cffe1e1a480222b0a80ecd31957edec06d diff --git a/src/label.c b/src/label.c index 5a0b4cc..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 *label, const char *prog) +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,8 +39,10 @@ bool addlabel(const char *prog, const char *label, WORD adr) { LABELTAB *np; unsigned hashval; + char *keys[2]; + int i = 0; - if(getlabel(label, prog) != 0xFFFF) { + if(getlabel(prog, label) != 0xFFFF) { setcerr(101, label); /* label already defined */ return false; } @@ -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;