t40c term[] count fix
[minix.git] / drivers / tty / keymaps / genmap.c
blob29d3b49c0258816a8f055836d9f30a1ec12cca95
1 /* genmap - output binary keymap Author: Marcus Hampel
2 */
3 #include <sys/types.h>
4 #ifdef __minix
5 #include <minix/keymap.h>
6 #else
7 #include "../../../include/minix/keymap.h"
8 #endif
9 #include <fcntl.h>
10 #include <unistd.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <errno.h>
16 * if we crosscompile those might not be defined,
18 #ifndef u16_t
19 #include <stdint.h>
20 typedef uint16_t u16_t;
21 #endif
23 #ifndef u8_t
24 #include <stdint.h>
25 typedef uint8_t u8_t;
26 #endif
28 u16_t keymap[NR_SCAN_CODES * MAP_COLS] = {
29 #include KEYSRC
32 u8_t comprmap[4 + NR_SCAN_CODES * MAP_COLS * 9/8 * 2 + 1];
34 void tell(const char *s)
36 write(2, s, strlen(s));
39 int main(void)
41 u8_t *cm, *fb;
42 u16_t *km;
43 int n;
45 /* Compress the keymap. */
46 memcpy(comprmap, KEY_MAGIC, 4);
47 cm = comprmap + 4;
48 n = 8;
49 for (km = keymap; km < keymap + NR_SCAN_CODES * MAP_COLS; km++) {
50 if (n == 8) {
51 /* Allocate a new flag byte. */
52 fb = cm;
53 *cm++ = 0;
54 n= 0;
56 *cm++ = (*km & 0x00FF); /* Low byte. */
57 if (*km & 0xFF00) {
58 *cm++ = (*km >> 8); /* High byte only when set. */
59 *fb |= (1 << n); /* Set a flag if so. */
61 n++;
64 /* Don't store trailing zeros. */
65 while (cm > comprmap && cm[-1] == 0) cm--;
67 /* Emit the compressed keymap. */
68 if (write(1, comprmap, cm - comprmap) < 0) {
69 int err = errno;
71 tell("genmap: ");
72 tell(strerror(err));
73 tell("\n");
74 exit(1);
76 exit(0);