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(label != NULL);
65 for(p = labels[labelhash(prog, label)]; p != NULL; p = p->next) {
66 if((prog == NULL || (p->prog != NULL && 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");
95 p->prog = strdup_chk(prog, "labels.prog");
98 p->label = strdup_chk(label, "labels.label");
104 hashval = labelhash(prog, label);
105 p->next = labels[hashval];
113 int compare_adr(const void *a, const void *b)
115 return (**(LABELARRAY **)a).adr - (**(LABELARRAY **)b).adr;
125 LABELARRAY *l[labelcnt];
127 for(i = 0; i < LABELTABSIZE; i++) {
128 for(p = labels[i]; p != NULL; p = p->next) {
129 assert(p->label != NULL);
130 l[s] = malloc_chk(sizeof(LABELARRAY), "l[]");
131 if(p->prog == NULL) {
134 l[s]->prog = strdup_chk(p->prog, "l[].prog");
136 l[s]->label = strdup_chk(p->label, "l[].label");
137 l[s++]->adr = p->adr;
140 qsort(l, s, sizeof(*l), compare_adr);
141 for(i = 0; i < s; i++) {
142 if(l[i]->prog != NULL) {
143 fprintf(stdout, "%s.", l[i]->prog);
145 fprintf(stdout, "%s ---> #%04X\n", l[i]->label, l[i]->adr);
157 for(i = 0; i < LABELTABSIZE; i++) {
158 for(p = labels[i]; p != NULL; p = q) {