ren: do not hyphenate last lines, if the 2nd bit of .hy is set
[neatroff.git] / map.c
blob7da6d9ccba0382d6a2ebe838f7a04f30648bb6ea
1 #include <stdio.h>
2 #include <string.h>
3 #include "roff.h"
5 /* register, macro, or environments names with more than two characters */
6 static char keys[NREGS][GNLEN];
7 static int nkeys = 1;
8 /* per starting character name lists */
9 static int key_head[256];
10 static int key_next[NREGS];
12 /* return the index of s in keys[]; insert it if not in keys[] */
13 static int key_get(char *s)
15 int head = (unsigned char) s[0];
16 int i = key_head[head];
17 while (i > 0) {
18 if (!strcmp(keys[i], s))
19 return i;
20 i = key_next[i];
22 i = nkeys++;
23 strcpy(keys[i], s);
24 key_next[i] = key_head[head];
25 key_head[head] = i;
26 return i;
29 /* map register names to [0..NREGS * 2) */
30 int map(char *s)
32 if (n_cp || !s[1] || !s[2])
33 return REG(s[0], s[1]);
34 return NREGS + key_get(s);
37 /* returns a static buffer */
38 char *map_name(int id)
40 static char map_buf[NMLEN];
41 if (id >= NREGS)
42 return keys[id - NREGS];
43 map_buf[0] = (id >> 8) & 0xff;
44 map_buf[1] = id & 0xff;
45 map_buf[2] = '\0';
46 return map_buf;