1 /* Copyright (C) 2014-2018 Free Software Foundation, Inc.
3 This file is part of groff.
5 groff is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free
7 Software Foundation, either version 2 of the License, or
8 (at your option) any later version.
10 groff is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 The GNU General Public License version 2 (GPL2) is available in the
16 internet at <http://www.gnu.org/licenses/gpl-2.0.txt>. */
21 * Map DVI (ditroff output) character names to
22 * font indexes and back
29 extern char *xmalloc(int);
31 #define allocHash() ((DviCharNameHash *) xmalloc (sizeof (DviCharNameHash)))
34 struct map_list *next;
38 static struct map_list *world;
40 static int standard_maps_loaded = 0;
41 static void load_standard_maps (void);
42 static int hash_name (const char *);
43 static void dispose_hash(DviCharNameMap *);
44 static void compute_hash(DviCharNameMap *);
47 DviFindMap (char *encoding)
51 if (!standard_maps_loaded)
52 load_standard_maps ();
53 for (m = world; m; m=m->next)
54 if (!strcmp (m->map->encoding, encoding))
60 DviRegisterMap (DviCharNameMap *map)
64 if (!standard_maps_loaded)
65 load_standard_maps ();
66 for (m = world; m; m = m->next)
67 if (!strcmp (m->map->encoding, map->encoding))
70 m = (struct map_list *) xmalloc (sizeof *m);
80 dispose_hash (DviCharNameMap *map)
82 DviCharNameHash **buckets;
83 DviCharNameHash *h, *next;
86 buckets = map->buckets;
87 for (i = 0; i < DVI_HASH_SIZE; i++) {
88 for (h = buckets[i]; h; h=next) {
96 hash_name (const char *name)
101 i = (i << 1) ^ *name++;
108 compute_hash (DviCharNameMap *map)
110 DviCharNameHash **buckets;
114 buckets = map->buckets;
115 for (i = 0; i < DVI_HASH_SIZE; i++)
117 for (c = 0; c < DVI_MAP_SIZE; c++)
118 for (s = 0; s < DVI_MAX_SYNONYMS; s++) {
119 if (!map->dvi_names[c][s])
121 i = hash_name (map->dvi_names[c][s]) % DVI_HASH_SIZE;
123 h->next = buckets[i];
125 h->name = map->dvi_names[c][s];
132 DviCharIndex (DviCharNameMap *map, const char *name)
137 i = hash_name (name) % DVI_HASH_SIZE;
138 for (h = map->buckets[i]; h; h=h->next)
139 if (!strcmp (h->name, name))
144 static DviCharNameMap ISO8859_1_map = {
182 { "\"", "dq", /* 34 */},
183 { "#", "sh", /* 35 */},
184 { "$", "Do", /* 36 */},
187 { "'", "cq", /* 39 */},
195 { "/", "sl", /* 47 */},
212 { "@", "at", /* 64 */},
239 { "[", "lB", /* 91 */},
240 { "\\", "rs", /* 92 */},
241 { "]", "rB", /* 93 */},
242 { "^", "a^", "ha", /* 94 */},
244 { "`", "oq", /* 96 */},
271 { "{", "lC", /* 123 */},
272 { "|", "ba", /* 124 */},
273 { "}", "rC", /* 125 */},
274 { "~", "a~", "ti", /* 126 */},
321 { "-", "hy", /* 173 */},
407 static DviCharNameMap Adobe_Symbol_map = {
408 "adobe-fontspecific",
446 { "#", "sh", /* 35 */},
454 { "+", "pl", /* 43 */},
456 { "\\-", "mi", /* 45 */},
458 { "/", "sl", /* 47 */},
472 { "=", "eq", /* 61 */},
502 { "[", "lB", /* 91 */},
503 { "tf", "3d", /* 92 */},
504 { "]", "rB", /* 93 */},
507 { "radicalex", /* 96 */},
534 { "lC", "{", /* 123 */},
535 { "ba", "|", /* 124 */},
536 { "rC", "}", /* 125 */},
584 { "ua", "arrowverttp", /* 173 */},
586 { "da", "arrowvertbt", /* 175 */},
598 { "~=", "~~", /* 187 */},
600 { "arrowvertex", /* 189 */},
625 { "sr", "sqrt", /* 214 */},
641 { "parenlefttp", /* 230 */},
642 { "parenleftex", /* 231 */},
643 { "parenleftbt", /* 232 */},
644 { "bracketlefttp", "lc", /* 233 */},
645 { "bracketleftex", /* 234 */},
646 { "bracketleftbt", "lf", /* 235 */},
647 { "bracelefttp", "lt", /* 236 */},
648 { "braceleftmid", "lk", /* 237 */},
649 { "braceleftbt", "lb", /* 238 */},
650 { "bracerightex", "braceleftex", "braceex", "bv", /* 239 */},
653 { "is", "integral", /* 242 */},
657 { "parenrighttp", /* 246 */},
658 { "parenrightex", /* 247 */},
659 { "parenrightbt", /* 248 */},
660 { "bracketrighttp", "rc", /* 249 */},
661 { "bracketrightex", /* 250 */},
662 { "bracketrightbt", "rf", /* 251 */},
663 { "bracerighttp", "rt", /* 252 */},
664 { "bracerightmid", "rk", /* 253 */},
665 { "bracerightbt", "rb", /* 254 */},
672 load_standard_maps (void)
674 standard_maps_loaded = 1;
675 DviRegisterMap (&ISO8859_1_map);
676 DviRegisterMap (&Adobe_Symbol_map);