11 static int labelcnt = 0; /* ラベル数 */
12 static LABELTAB *labels[LABELTABSIZE]; /* ラベル表 */
17 static CERR cerr_label[] = {
18 { 101, "label already defined" },
19 { 102, "label table is full" },
20 { 103, "label not found" },
26 void addcerrlist_label()
28 addcerrlist(ARRAYSIZE(cerr_label), cerr_label);
32 * プログラム名とラベルに対応するハッシュ値を返す
34 unsigned labelhash(const char *prog, const char *label)
41 keys[i] = malloc_chk(sizeof(HKEY), "labelhash.key");
42 keys[i]->type = CHARS;
43 keys[i]->val.s = strdup_chk(prog, "labelhash.key.val");
46 keys[i] = malloc_chk(sizeof(HKEY), "labelhash.key");
47 keys[i]->type = CHARS;
48 keys[i]->val.s = strdup_chk(label, "labelhash.key.val");
49 h = hash(i+1, keys, LABELTABSIZE);
50 for(j = 0; j < i + 1; j++) {
58 * プログラム名とラベルに対応するアドレスをラベル表から検索する
60 WORD getlabel(const char *prog, const char *label)
62 assert(prog != NULL && label != NULL);
65 for(p = labels[labelhash(prog, label)]; p != NULL; p = p->next) {
66 if((*prog == '\0' || (strcmp(prog, p->prog) == 0)) &&
67 strcmp(label, p->label) == 0)
76 * プログラム名、ラベル、アドレスをラベル表に追加する
78 bool addlabel(const char *prog, const char *label, WORD adr)
80 assert(label != NULL);
84 /* 登録されたラベルを検索。すでに登録されている場合はエラー発生 */
85 if(getlabel(prog, label) != 0xFFFF) {
86 setcerr(101, label); /* label already defined */
90 p = malloc_chk(sizeof(LABELTAB), "labels.next");
92 p->prog = strdup_chk(prog, "labels.prog");
94 p->label = strdup_chk(label, "labels.label");
100 hashval = labelhash(prog, label);
101 p->next = labels[hashval];
109 int compare_adr(const void *a, const void *b)
111 return (**(LABELARRAY **)a).adr - (**(LABELARRAY **)b).adr;
123 l = calloc_chk(labelcnt, sizeof(LABELARRAY **), "labels");
124 for(i = 0; i < LABELTABSIZE; i++) {
125 for(p = labels[i]; p != NULL; p = p->next) {
126 assert(p->label != NULL);
127 l[s] = malloc_chk(sizeof(LABELARRAY), "lables");
128 l[s]->prog = strdup_chk(p->prog, "labels.prog");
129 l[s]->label = strdup_chk(p->label, "labels.label");
130 l[s++]->adr = p->adr;
133 qsort(l, s, sizeof(*l), compare_adr);
134 for(i = 0; i < s; i++) {
135 if(*(l[i]->prog) != '\0') {
136 fprintf(stdout, "%s.", l[i]->prog);
138 fprintf(stdout, "%s ---> #%04X\n", l[i]->label, l[i]->adr);
151 for(i = 0; i < LABELTABSIZE; i++) {
152 for(p = labels[i]; p != NULL; p = q) {