Main Page   Compound List   File List   Compound Members   File Members  

zclassmap.vtc

Go to the documentation of this file.
00001 /* -*- C -*- */
00022 func cmp2(a, b) [t] {
00023     t = stricmp(a[0], b[0]);
00024     return (t != 0) ? t : stricmp(a[1], b[1]);
00025 }
00026 
00027 class_map ?:= bimap_make(.stricmp, .stricmp);
00028 instance_map ?:= bimap_make(.cmp2, .stricmp);
00029 
00030 func Class(class, abbrev) {
00031     bimap_insert(class_map, class, abbrev);
00032 }
00033 
00034 func Instance(class, instance, abbrev) {
00035     bimap_insert(instance_map, table(class, instance), abbrev);
00036 }
00037 
00038 /* Returns abbrev name for a class */
00039 func mapped_class(class) 
00040 {
00041   return bimap_find_left(class_map, class);
00042 }
00043 
00044 /* Returns class name for an abbrev */
00045 func unmapped_class(abbrev)
00046 {
00047   return bimap_find_right(class_map, abbrev);
00048 }
00049 
00050 /* Returns abbrev name for a class and instance */
00051 func mapped_instance(class, instance)
00052 {
00053   return bimap_find_left(instance_map, table(class, instance));
00054 }
00055 
00056 /* Returns a 2-element array with (class, instance) for an abbrev */
00057 func unmapped_instance(abbrev)
00058 {
00059   return bimap_find_right(instance_map, abbrev);
00060 }
00061 
00062 func save_maps(fp) [i] {
00063     for (i = 0; i < class_map->num; i++) {
00064         fprintf(fp, "Class(%s, %s);\n",
00065                 stringconst(class_map->left[i]),
00066                 stringconst(class_map->right[i]));
00067     }
00068     for (i = 0; i < instance_map->num; i++) {
00069         fprintf(fp, "Instance(%s, %s, %s);\n",
00070                 stringconst(instance_map->left[i][0]),
00071                 stringconst(instance_map->left[i][1]),
00072                 stringconst(instance_map->right[i]));
00073     }
00074 }
00075 add_to_hook(save_hook, .save_maps);
00076 
00077 add_cmd("class", 2, .Class, "/class <class> <abbrev>");
00078 add_cmd("instance", 3, .Instance, "/instance <class> <instance> <abbrev>");
00079 
00080 /* style maps */
00081 
00082 class_style_map ?:= make_tree(.stricmp);
00083 instance_style_map ?:= make_tree(.cmp2);
00084 
00085 func name_to_style(name) {
00086     if (strcmp(name, "S_NORM") == 0) return S_NORM;
00087     if (strcmp(name, "S_HILITE") == 0) return S_HILITE;
00088     return find_style(name);
00089 }
00090 
00091 func style_to_name(style) {
00092     if (style == S_NORM) return "S_NORM";
00093     if (style == S_HILITE) return "S_HILITE";
00094     return get_style_name(style);
00095 }
00096 
00097 func Class_style(class, style) {
00098     insert_tree(class_style_map, class, name_to_style(style));
00099 }
00100 
00101 func Instance_style(class, instance, style) {
00102     insert_tree(instance_style_map, table(class, instance),
00103                 name_to_style(style));
00104 }
00105 
00106 func save_class_style(class, style, fp) {
00107     fprintf(fp, "Class_style(%s, %s);\n",
00108             stringconst(class),
00109             stringconst(style_to_name(style)));
00110 }
00111 
00112 func save_instance_style(ci, style, fp) {
00113     fprintf(fp, "Instance_style(%s, %s, %s);\n",
00114             stringconst(ci[0]),
00115             stringconst(ci[1]),
00116             stringconst(style_to_name(style)));
00117 }
00118 
00119 func save_style_maps(fp) [i] {
00120     traverse_tree(class_style_map, .save_class_style, fp);
00121     traverse_tree(instance_style_map, .save_instance_style, fp);
00122 }
00123 
00124 func style_of_zephyr(z) [style]
00125 {
00126     style ?:= find_tree(instance_style_map, table(z->class, z->instance));
00127     style ?:= find_tree(class_style_map, z->class) ?: S_NORM;
00128     return style;
00129 }
00130 
00131 add_to_hook(save_hook, .save_style_maps);
00132 
00133 add_cmd("class_style", 2, .Class_style, "/class_style <class> <style>");
00134 add_cmd("instance_style", 3, .Instance_style, "/instance_style <class> <instance> <style>");
00135 
00136 

Generated at Mon Aug 13 16:45:52 2001 for dzm-vtc by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001