4 int labelcnt = 0; /* ラベル数 */
5 LABELTAB *labels[LABELTABSIZE]; /* ラベル表 */
7 /* プログラム名とラベルに対応するハッシュ値を返す */
8 unsigned labelhash(const char *prog, const char *label)
14 keys[i] = malloc_chk(sizeof(HKEY), "labelhash.key[]");
15 keys[i]->type = CHARS;
16 keys[i]->val.s = strdup_chk(prog, "labelhash.key[].val");
18 keys[i] = malloc_chk(sizeof(HKEY), "labelhash.key[]");
19 keys[i]->type = CHARS;
20 keys[i]->val.s = strdup_chk(label, "labelhash.key[].val");
22 return hash(i+1, keys, LABELTABSIZE);
26 WORD getlabel(const char *prog, const char *label)
28 assert(label != NULL);
31 for(np = labels[labelhash(prog, label)]; np != NULL; np = np->next) {
32 if((prog == NULL || (np->prog != NULL && strcmp(prog, np->prog) == 0)) &&
33 strcmp(label, np->label) == 0)
41 /* プログラム名、ラベル、アドレスをラベル表に追加する */
42 bool addlabel(const char *prog, const char *label, WORD adr)
44 assert(label != NULL);
48 /* 登録されたラベルを検索。すでに登録されている場合はエラー発生 */
49 if(getlabel(prog, label) != 0xFFFF) {
50 setcerr(101, label); /* label already defined */
54 np = malloc_chk(sizeof(LABELTAB), "labels.next");
59 np->prog = strdup_chk(prog, "labels.prog");
62 np->label = strdup_chk(label, "labels.label");
68 hashval = labelhash(prog, label);
69 np->next = labels[hashval];
74 int compare_adr(const void *a, const void *b)
76 return (**(LABELARRAY **)a).adr - (**(LABELARRAY **)b).adr;
84 LABELARRAY *ar[labelcnt];
86 for(i = 0; i < LABELTABSIZE; i++) {
87 for(np = labels[i]; np != NULL; np = np->next) {
88 assert(np->label != NULL);
89 ar[asize] = malloc_chk(sizeof(LABELARRAY), "ar[]");
90 if(np->prog == NULL) {
91 ar[asize]->prog = NULL;
93 ar[asize]->prog = strdup_chk(np->prog, "ar[].prog");
95 ar[asize]->label = strdup_chk(np->label, "ar[].label");
96 ar[asize++]->adr = np->adr;
99 qsort(ar, asize, sizeof(*ar), compare_adr);
100 for(i = 0; i < asize; i++) {
101 if(ar[i]->prog != NULL) {
102 fprintf(stdout, "%s.", ar[i]->prog);
104 fprintf(stdout, "%s ---> #%04X\n", ar[i]->label, ar[i]->adr);
114 for(i = 0; i < LABELTABSIZE; i++) {
115 for(np = labels[i]; np != NULL; np = nq) {
117 if(np->prog != NULL) {
120 free_chk(np->label, "np.label");