font: unmap glyphs with .fmap
[neatroff.git] / map.c
blobf71d124b1ce78908a26b2412a02257694f0af7c1
1 /* mapping register/macro names to indices */
2 #include <stdio.h>
3 #include <string.h>
4 #include "roff.h"
6 #define MAPBEG 256 /* the entries reserved for .x names */
8 /* register, macro, or environments names */
9 static struct dict *mapdict;
11 /* map register names to [0..NREGS] */
12 int map(char *s)
14 int i;
15 if (s[0] == '.' && s[1] && !s[2]) /* ".x" is mapped to 'x' */
16 return (unsigned char) s[1];
17 if (!mapdict)
18 mapdict = dict_make(-1, 1, 1);
19 i = dict_idx(mapdict, s);
20 if (i < 0) {
21 dict_put(mapdict, s, 0);
22 i = dict_idx(mapdict, s);
23 if (MAPBEG + i >= NREGS)
24 errdie("neatroff: increase NREGS\n");
26 return MAPBEG + i;
29 /* return the name mapped to id; returns a static buffer */
30 char *map_name(int id)
32 static char map_buf[NMLEN];
33 if (id >= MAPBEG)
34 return dict_key(mapdict, id - MAPBEG);
35 map_buf[0] = '.';
36 map_buf[1] = id;
37 map_buf[2] = '\0';
38 return map_buf;
41 void map_done(void)
43 if (mapdict)
44 dict_free(mapdict);