4 int labelcnt = 0; /* ラベル数 */
5 LABELTAB *labels[LABELTABSIZE]; /* ラベル表 */
7 /* プログラム名とラベルに対応するハッシュ値を返す */
8 unsigned labelhash(const char *prog, const char *label)
13 keys[i] = malloc(sizeof(HKEY));
14 keys[i]->type = CHARS;
15 keys[i++]->val.s = strdup(prog);
17 keys[i] = malloc(sizeof(HKEY));
18 keys[i]->type = CHARS;
19 keys[i]->val.s = strdup(label);
21 return hash(i+1, keys, LABELTABSIZE);
25 WORD getlabel(const char *prog, const char *label)
27 assert(label != NULL);
29 for(np = labels[labelhash(prog, label)]; np != NULL; np = np->next) {
30 if((prog == NULL || (np->prog != NULL && strcmp(prog, np->prog) == 0)) &&
31 strcmp(label, np->label) == 0)
39 /* プログラム名、ラベル、アドレスをラベル表に追加する */
40 bool addlabel(const char *prog, const char *label, WORD adr)
42 assert(label != NULL);
46 /* 登録されたラベルを検索。すでに登録されている場合はエラー発生 */
47 if(getlabel(prog, label) != 0xFFFF) {
48 setcerr(101, label); /* label already defined */
51 /* プログラム名、ラベル、アドレスを設定。メモリーを確保できない場合はエラー発生 */
52 if((np = malloc(sizeof(LABELTAB))) == NULL || (np->label = strdup(label)) == NULL ||
53 (prog != NULL && (np->prog = strdup(prog)) == NULL))
55 setcerr(102, NULL); /* label table is full */
62 hashval = labelhash(prog, label);
63 np->next = labels[hashval];
68 int compare_adr(const void *a, const void *b)
70 return (**(LABELARRAY **)a).adr - (**(LABELARRAY **)b).adr;
78 LABELARRAY *ar[labelcnt];
80 for(i = 0; i < LABELTABSIZE; i++) {
81 for(np = labels[i]; np != NULL; np = np->next) {
82 assert(np->label != NULL);
83 ar[asize] = malloc(sizeof(LABELARRAY));
84 ar[asize]->prog = (np->prog == NULL ? NULL : strdup(np->prog));
85 ar[asize]->label = strdup(np->label);
86 ar[asize++]->adr = np->adr;
89 qsort(ar, asize, sizeof(*ar), compare_adr);
90 for(i = 0; i < asize; i++) {
91 if(ar[i]->prog != NULL) {
92 fprintf(stdout, "%s.", ar[i]->prog);
94 fprintf(stdout, "%s ---> #%04X\n", ar[i]->label, ar[i]->adr);
103 for(i = 0; i < LABELTABSIZE; i++) {
104 for(np = labels[i]; np != NULL; np = nq) {
106 if(np->prog != NULL) {