ren: add .it
[neatroff.git] / map.c
blob0a9705989d4147caa285598d7c9e6c6eb9c60d1b
1 #include <stdio.h>
2 #include <string.h>
3 #include "roff.h"
5 static char keys[NREGS][GNLEN];
6 static int nkeys;
8 /* map register names to [0..NREGS * 2) */
9 int map(char *s)
11 int i;
12 if (n_cp || !s[1] || !s[2])
13 return REG(s[0], s[1]);
14 for (i = 0; i < nkeys; i++)
15 if (keys[i][0] == s[0] && !strcmp(keys[i], s))
16 return NREGS + i;
17 strcpy(keys[nkeys++], s);
18 return NREGS + nkeys - 1;
21 /* returns a static buffer */
22 char *map_name(int id)
24 static char map_buf[NMLEN];
25 if (id >= NREGS)
26 return keys[id - NREGS];
27 map_buf[0] = (id >> 8) & 0xff;
28 map_buf[1] = id & 0xff;
29 map_buf[2] = '\0';
30 return map_buf;