hyph: do not read more than GNLEN characters in hy_cget()
[neatroff.git] / map.c
blobee5e6a1bba13d926e988c34f632ff23a23d25204
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);
24 return MAPBEG + i;
27 /* return the name mapped to id; returns a static buffer */
28 char *map_name(int id)
30 static char map_buf[NMLEN];
31 if (id >= MAPBEG)
32 return dict_key(mapdict, id - MAPBEG);
33 map_buf[0] = '.';
34 map_buf[1] = id;
35 map_buf[2] = '\0';
36 return map_buf;
39 void map_done(void)
41 if (mapdict)
42 dict_free(mapdict);