Rev | Line | |
---|
[9] | 1 | /* genmap - output binary keymap Author: Marcus Hampel
|
---|
| 2 | */
|
---|
| 3 | #include <sys/types.h>
|
---|
| 4 | #include <minix/keymap.h>
|
---|
| 5 | #include <fcntl.h>
|
---|
| 6 | #include <unistd.h>
|
---|
| 7 | #include <stdlib.h>
|
---|
| 8 | #include <string.h>
|
---|
| 9 | #include <errno.h>
|
---|
| 10 |
|
---|
| 11 | #include KEYSRC
|
---|
| 12 |
|
---|
| 13 | u8_t comprmap[4 + NR_SCAN_CODES * MAP_COLS * 9/8 * 2 + 1];
|
---|
| 14 |
|
---|
| 15 | void tell(const char *s)
|
---|
| 16 | {
|
---|
| 17 | write(2, s, strlen(s));
|
---|
| 18 | }
|
---|
| 19 |
|
---|
| 20 | int main(void)
|
---|
| 21 | {
|
---|
| 22 | u8_t *cm, *fb;
|
---|
| 23 | u16_t *km;
|
---|
| 24 | int n;
|
---|
| 25 |
|
---|
| 26 | /* Compress the keymap. */
|
---|
| 27 | memcpy(comprmap, KEY_MAGIC, 4);
|
---|
| 28 | cm = comprmap + 4;
|
---|
| 29 | n = 8;
|
---|
| 30 | for (km = keymap; km < keymap + NR_SCAN_CODES * MAP_COLS; km++) {
|
---|
| 31 | if (n == 8) {
|
---|
| 32 | /* Allocate a new flag byte. */
|
---|
| 33 | fb = cm;
|
---|
| 34 | *cm++ = 0;
|
---|
| 35 | n= 0;
|
---|
| 36 | }
|
---|
| 37 | *cm++ = (*km & 0x00FF); /* Low byte. */
|
---|
| 38 | if (*km & 0xFF00) {
|
---|
| 39 | *cm++ = (*km >> 8); /* High byte only when set. */
|
---|
| 40 | *fb |= (1 << n); /* Set a flag if so. */
|
---|
| 41 | }
|
---|
| 42 | n++;
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | /* Don't store trailing zeros. */
|
---|
| 46 | while (cm > comprmap && cm[-1] == 0) cm--;
|
---|
| 47 |
|
---|
| 48 | /* Emit the compressed keymap. */
|
---|
| 49 | if (write(1, comprmap, cm - comprmap) < 0) {
|
---|
| 50 | int err = errno;
|
---|
| 51 |
|
---|
| 52 | tell("genmap: ");
|
---|
| 53 | tell(strerror(err));
|
---|
| 54 | tell("\n");
|
---|
| 55 | exit(1);
|
---|
| 56 | }
|
---|
| 57 | exit(0);
|
---|
| 58 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.