6 * Map DVI (ditroff output) character names to
7 * font indexes and back
14 extern char *xmalloc(int);
16 #define allocHash() ((DviCharNameHash *) xmalloc (sizeof (DviCharNameHash)))
19 struct map_list
*next
;
23 static struct map_list
*world
;
25 static int standard_maps_loaded
= 0;
26 static void load_standard_maps (void);
27 static int hash_name (const char *);
28 static void dispose_hash(DviCharNameMap
*);
29 static void compute_hash(DviCharNameMap
*);
32 DviFindMap (char *encoding
)
36 if (!standard_maps_loaded
)
37 load_standard_maps ();
38 for (m
= world
; m
; m
=m
->next
)
39 if (!strcmp (m
->map
->encoding
, encoding
))
45 DviRegisterMap (DviCharNameMap
*map
)
49 if (!standard_maps_loaded
)
50 load_standard_maps ();
51 for (m
= world
; m
; m
= m
->next
)
52 if (!strcmp (m
->map
->encoding
, map
->encoding
))
55 m
= (struct map_list
*) xmalloc (sizeof *m
);
65 dispose_hash (DviCharNameMap
*map
)
67 DviCharNameHash
**buckets
;
68 DviCharNameHash
*h
, *next
;
71 buckets
= map
->buckets
;
72 for (i
= 0; i
< DVI_HASH_SIZE
; i
++) {
73 for (h
= buckets
[i
]; h
; h
=next
) {
81 hash_name (const char *name
)
86 i
= (i
<< 1) ^ *name
++;
93 compute_hash (DviCharNameMap
*map
)
95 DviCharNameHash
**buckets
;
99 buckets
= map
->buckets
;
100 for (i
= 0; i
< DVI_HASH_SIZE
; i
++)
102 for (c
= 0; c
< DVI_MAP_SIZE
; c
++)
103 for (s
= 0; s
< DVI_MAX_SYNONYMS
; s
++) {
104 if (!map
->dvi_names
[c
][s
])
106 i
= hash_name (map
->dvi_names
[c
][s
]) % DVI_HASH_SIZE
;
108 h
->next
= buckets
[i
];
110 h
->name
= map
->dvi_names
[c
][s
];
117 DviCharIndex (DviCharNameMap
*map
, const char *name
)
122 i
= hash_name (name
) % DVI_HASH_SIZE
;
123 for (h
= map
->buckets
[i
]; h
; h
=h
->next
)
124 if (!strcmp (h
->name
, name
))
129 static DviCharNameMap ISO8859_1_map
= {
167 { "\"", "dq", /* 34 */},
168 { "#", "sh", /* 35 */},
169 { "$", "Do", /* 36 */},
172 { "'", "cq", /* 39 */},
180 { "/", "sl", /* 47 */},
197 { "@", "at", /* 64 */},
224 { "[", "lB", /* 91 */},
225 { "\\", "rs", /* 92 */},
226 { "]", "rB", /* 93 */},
227 { "^", "a^", "ha", /* 94 */},
229 { "`", "oq", /* 96 */},
256 { "{", "lC", /* 123 */},
257 { "|", "ba", /* 124 */},
258 { "}", "rC", /* 125 */},
259 { "~", "a~", "ti", /* 126 */},
306 { "-", "hy", /* 173 */},
391 static DviCharNameMap Adobe_Symbol_map
= {
392 "adobe-fontspecific",
430 { "#", "sh", /* 35 */},
438 { "+", "pl", /* 43 */},
440 { "\\-", "mi", /* 45 */},
442 { "/", "sl", /* 47 */},
456 { "=", "eq", /* 61 */},
486 { "[", "lB", /* 91 */},
487 { "tf", "3d", /* 92 */},
488 { "]", "rB", /* 93 */},
491 { "radicalex", /* 96 */},
518 { "lC", "{", /* 123 */},
519 { "ba", "|", /* 124 */},
520 { "rC", "}", /* 125 */},
568 { "ua", "arrowverttp", /* 173 */},
570 { "da", "arrowvertbt", /* 175 */},
582 { "~=", "~~", /* 187 */},
584 { "arrowvertex", /* 189 */},
609 { "sr", "sqrt", /* 214 */},
625 { "parenlefttp", /* 230 */},
626 { "parenleftex", /* 231 */},
627 { "parenleftbt", /* 232 */},
628 { "bracketlefttp", "lc", /* 233 */},
629 { "bracketleftex", /* 234 */},
630 { "bracketleftbt", "lf", /* 235 */},
631 { "bracelefttp", "lt", /* 236 */},
632 { "braceleftmid", "lk", /* 237 */},
633 { "braceleftbt", "lb", /* 238 */},
634 { "bracerightex", "braceleftex", "braceex", "bv", /* 239 */},
637 { "is", "integral", /* 242 */},
641 { "parenrighttp", /* 246 */},
642 { "parenrightex", /* 247 */},
643 { "parenrightbt", /* 248 */},
644 { "bracketrighttp", "rc", /* 249 */},
645 { "bracketrightex", /* 250 */},
646 { "bracketrightbt", "rf", /* 251 */},
647 { "bracerighttp", "rt", /* 252 */},
648 { "bracerightmid", "rk", /* 253 */},
649 { "bracerightbt", "rb", /* 254 */},
655 load_standard_maps (void)
657 standard_maps_loaded
= 1;
658 DviRegisterMap (&ISO8859_1_map
);
659 DviRegisterMap (&Adobe_Symbol_map
);