X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flabel.c;h=efa52c31e06e8ed525f34ffc654eda955c435ff9;hb=refs%2Ftags%2Fv0.1p45;hp=04a757d905e7c7fbcd705df70fa2b7397c3ec056;hpb=6b30a23640168f0b99e70ad87ab4c5a98015ee02;p=YACASL2.git diff --git a/src/label.c b/src/label.c index 04a757d..efa52c3 100644 --- a/src/label.c +++ b/src/label.c @@ -37,7 +37,7 @@ unsigned labelhash(const char *prog, const char *label) int i = 0, j; unsigned h; - if(prog != NULL) { + if(*prog != '\0') { keys[i] = malloc_chk(sizeof(HKEY), "labelhash.key"); keys[i]->type = CHARS; keys[i]->val.s = strdup_chk(prog, "labelhash.key.val"); @@ -59,11 +59,11 @@ unsigned labelhash(const char *prog, const char *label) */ WORD getlabel(const char *prog, const char *label) { - assert(label != NULL); + assert(prog != NULL && label != NULL); LABELTAB *p; for(p = labels[labelhash(prog, label)]; p != NULL; p = p->next) { - if((prog == NULL || (p->prog != NULL && strcmp(prog, p->prog) == 0)) && + if((*prog == '\0' || (strcmp(prog, p->prog) == 0)) && strcmp(label, p->label) == 0) { return p->adr; @@ -89,11 +89,7 @@ bool addlabel(const char *prog, const char *label, WORD adr) /* メモリを確保 */ p = malloc_chk(sizeof(LABELTAB), "labels.next"); /* プログラム名を設定 */ - if(prog == NULL) { - p->prog = NULL; - } else { - p->prog = strdup_chk(prog, "labels.prog"); - } + p->prog = strdup_chk(prog, "labels.prog"); /* ラベルを設定 */ p->label = strdup_chk(label, "labels.label"); /* アドレスを設定 */ @@ -122,28 +118,26 @@ void printlabel() { int i, s = 0; LABELTAB *p; - LABELARRAY *l[labelcnt]; + LABELARRAY **l; + l = calloc_chk(labelcnt, sizeof(LABELARRAY **), "labels"); for(i = 0; i < LABELTABSIZE; i++) { for(p = labels[i]; p != NULL; p = p->next) { assert(p->label != NULL); - l[s] = malloc_chk(sizeof(LABELARRAY), "l[]"); - if(p->prog == NULL) { - l[s]->prog = NULL; - } else { - l[s]->prog = strdup_chk(p->prog, "l[].prog"); - } - l[s]->label = strdup_chk(p->label, "l[].label"); + l[s] = malloc_chk(sizeof(LABELARRAY), "lables"); + l[s]->prog = strdup_chk(p->prog, "labels.prog"); + l[s]->label = strdup_chk(p->label, "labels.label"); l[s++]->adr = p->adr; } } qsort(l, s, sizeof(*l), compare_adr); for(i = 0; i < s; i++) { - if(l[i]->prog != NULL) { + if(*(l[i]->prog) != '\0') { fprintf(stdout, "%s.", l[i]->prog); } fprintf(stdout, "%s ---> #%04X\n", l[i]->label, l[i]->adr); } + FREE(l); } /**