3 api_define_type
*create_adt(char * orig
, char *dest
)
6 adt
=(api_define_type
*)mbkalloc(sizeof(api_define_type
));
7 adt
->ORIG
=mbkstrdup(orig
);
8 adt
->DEST
=mbkstrdup(dest
);
12 chain_list
*dup_adt_list(chain_list
*cl
)
15 if (cl
==NULL
) return cl
;
16 adt
=(api_define_type
*)mbkalloc(sizeof(api_define_type
));
17 adt
->ORIG
=mbkstrdup(((api_define_type
*)cl
->DATA
)->ORIG
);
18 adt
->DEST
=mbkstrdup(((api_define_type
*)cl
->DATA
)->DEST
);
19 return addchain(dup_adt_list(cl
->NEXT
), adt
);
22 void free_adt_list(chain_list
*cl
)
26 for (ch
=cl
; ch
!=NULL
; ch
=ch
->NEXT
)
28 adt
=(api_define_type
*)ch
->DATA
;
36 int gen_find_template_corresp(ht
*base_ht
, chain_list
*defines
, char *name
, char *result
)
38 char buf
[1024], *end
, *start
;
49 end
=strchr(start
, '.');
50 if (end
!=NULL
) *end
='\0';
51 for (cl
=defines
; cl
!=NULL
; cl
=cl
->NEXT
)
53 adt
=(api_define_type
*)cl
->DATA
;
54 if (strcasecmp(adt
->ORIG
, start
)==0) break;
56 if (cl
!=NULL
&& end
!=NULL
)
63 if ((l
=gethtitem(base_ht
, namealloc(start
)))==EMPTYHT
)
66 defines
=((template_corresp
*)l
)->defines
;
69 } while (cl
!=NULL
&& end
!=NULL
);
74 strcpy(result
, start
);
76 strcpy(result
, adt
->DEST
);
79 strcpy(result
,"<not found>");
83 template_corresp
*gen_get_template_corresp(ht
*base_ht
, char *name
)
86 if ((l
=gethtitem(base_ht
, namealloc(name
)))==EMPTYHT
) return NULL
;
87 return (template_corresp
*)l
;
90 template_corresp
*gen_add_template_corresp(ht
*base_ht
, char *new_name
, char *orig_name
, chain_list
*defines
)
94 tc
=(template_corresp
*)mbkalloc(sizeof(template_corresp
));
95 tc
->new_name
=namealloc(new_name
);
96 tc
->orig_name
=namealloc(orig_name
);
97 tc
->defines
=dup_adt_list(defines
);
99 addhtitem(base_ht
, tc
->new_name
, (long)tc
);
104 int gen_find_reverse_template_corresp(chain_list
*defines
, char *name
, char *result
)
107 api_define_type
*adt
;
109 for (cl
=defines
; cl
!=NULL
; cl
=cl
->NEXT
)
111 adt
=(api_define_type
*)cl
->DATA
;
112 if (strcasecmp(adt
->DEST
, name
)==0) break;
117 strcpy(result
,"<not found>");
121 strcpy(result
, adt
->ORIG
);