X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?p=YACASL2.git;a=blobdiff_plain;f=src%2Flabel.c;fp=src%2Flabel.c;h=04a757d905e7c7fbcd705df70fa2b7397c3ec056;hp=a8baa1df2b585e91c12e7be3d09f799d6cafc338;hb=6b30a23640168f0b99e70ad87ab4c5a98015ee02;hpb=6eb54846c27b216d7602a5107d9383f8f4324d71 diff --git a/src/label.c b/src/label.c index a8baa1d..04a757d 100644 --- a/src/label.c +++ b/src/label.c @@ -11,6 +11,23 @@ static int labelcnt = 0; /* ラベル数 */ static LABELTAB *labels[LABELTABSIZE]; /* ラベル表 */ +/** + * ラベルのエラー定義 + */ +static CERR cerr_label[] = { + { 101, "label already defined" }, + { 102, "label table is full" }, + { 103, "label not found" }, +}; + +/** + * ラベルのエラーをエラーリストに追加 + */ +void addcerrlist_label() +{ + addcerrlist(ARRAYSIZE(cerr_label), cerr_label); +} + /** * プログラム名とラベルに対応するハッシュ値を返す */ @@ -61,7 +78,7 @@ WORD getlabel(const char *prog, const char *label) bool addlabel(const char *prog, const char *label, WORD adr) { assert(label != NULL); - LABELTAB *np; + LABELTAB *p; unsigned hashval; /* 登録されたラベルを検索。すでに登録されている場合はエラー発生 */ @@ -70,23 +87,23 @@ bool addlabel(const char *prog, const char *label, WORD adr) return false; } /* メモリを確保 */ - np = malloc_chk(sizeof(LABELTAB), "labels.next"); + p = malloc_chk(sizeof(LABELTAB), "labels.next"); /* プログラム名を設定 */ if(prog == NULL) { - np->prog = NULL; + p->prog = NULL; } else { - np->prog = strdup_chk(prog, "labels.prog"); + p->prog = strdup_chk(prog, "labels.prog"); } /* ラベルを設定 */ - np->label = strdup_chk(label, "labels.label"); + p->label = strdup_chk(label, "labels.label"); /* アドレスを設定 */ - np->adr = adr; + p->adr = adr; /* ラベル数を設定 */ labelcnt++; /* ハッシュ表へ追加 */ hashval = labelhash(prog, label); - np->next = labels[hashval]; - labels[hashval] = np; + p->next = labels[hashval]; + labels[hashval] = p; return true; } @@ -103,29 +120,29 @@ int compare_adr(const void *a, const void *b) */ void printlabel() { - int i, asize = 0; + int i, s = 0; LABELTAB *p; - LABELARRAY *ar[labelcnt]; + LABELARRAY *l[labelcnt]; for(i = 0; i < LABELTABSIZE; i++) { for(p = labels[i]; p != NULL; p = p->next) { assert(p->label != NULL); - ar[asize] = malloc_chk(sizeof(LABELARRAY), "ar[]"); + l[s] = malloc_chk(sizeof(LABELARRAY), "l[]"); if(p->prog == NULL) { - ar[asize]->prog = NULL; + l[s]->prog = NULL; } else { - ar[asize]->prog = strdup_chk(p->prog, "ar[].prog"); + l[s]->prog = strdup_chk(p->prog, "l[].prog"); } - ar[asize]->label = strdup_chk(p->label, "ar[].label"); - ar[asize++]->adr = p->adr; + l[s]->label = strdup_chk(p->label, "l[].label"); + l[s++]->adr = p->adr; } } - qsort(ar, asize, sizeof(*ar), compare_adr); - for(i = 0; i < asize; i++) { - if(ar[i]->prog != NULL) { - fprintf(stdout, "%s.", ar[i]->prog); + qsort(l, s, sizeof(*l), compare_adr); + for(i = 0; i < s; i++) { + if(l[i]->prog != NULL) { + fprintf(stdout, "%s.", l[i]->prog); } - fprintf(stdout, "%s ---> #%04X\n", ar[i]->label, ar[i]->adr); + fprintf(stdout, "%s ---> #%04X\n", l[i]->label, l[i]->adr); } }