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)
28 for(np = labels[labelhash(prog, label)]; np != NULL; np = np->next) {
29 if((prog == NULL || (np->prog != NULL && strcmp(prog, np->prog) == 0)) &&
30 strcmp(label, np->label) == 0)
39 bool addlabel(const char *prog, const char *label, WORD adr)
46 if(getlabel(prog, label) != 0xFFFF) {
47 setcerr(101, label); /* label already defined */
50 np = malloc(sizeof(*np));
51 if(np == NULL || (np->label = strdup(label)) == NULL ||
52 (prog != NULL && (np->prog = strdup(prog)) == NULL))
54 setcerr(102, NULL); /* label table is full */
58 keys[i++] = strdup(prog);
61 keys[i] = strdup(label);
62 hashval = labelhash(prog, label);
63 np->next = labels[hashval];
69 int compare_adr(const void *a, const void *b)
71 return (**(const LABELARRAY **)a).adr - (**(const LABELARRAY **)b).adr;
79 LABELARRAY *ar[labelcnt];
81 for(i = 0; i < LABELTABSIZE; i++) {
82 for(np = labels[i]; np != NULL; np = np->next) {
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;
90 qsort(ar, asize, sizeof(*ar), compare_adr);
91 for(i = 0; i < asize; i++) {
92 if(ar[i]->prog != NULL) {
93 fprintf(stdout, "%s.", ar[i]->prog);
95 fprintf(stdout, "%s ---> #%04X\n", ar[i]->label, ar[i]->adr);
104 for(i = 0; i < LABELTABSIZE; i++) {
105 for(np = labels[i]; np != NULL; np = nq) {