Last active
November 14, 2016 10:44
-
-
Save legionus/06c766259141cccf776625684021e9a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <keymap.h> | |
int main(int argc, char **argv) | |
{ | |
lk_table_shape table = LK_SHAPE_DEFAULT; | |
int rc = -1; | |
char numeric = 0; | |
char *env; | |
struct lk_ctx *ctx; | |
lk_flags flags = 0; | |
lkfile_t f; | |
if (argc == 1) { | |
printf("Usage: %s <keymap>\n", argv[0]); | |
exit(EXIT_FAILURE); | |
} | |
ctx = lk_init(); | |
if ((env = getenv("CHARSET")) != NULL) { | |
if ((lk_set_charset(ctx, env)) != 0) { | |
fprintf(stderr, "unknown charset %s\n", env); | |
goto fail; | |
} | |
} | |
if ((env = getenv("SHAPE")) != NULL) { | |
if (!strcasecmp(env, "FULLTABLE")) table = LK_SHAPE_FULL_TABLE; | |
else if (!strcasecmp(env, "SEPARATELINES")) table = LK_SHAPE_SEPARATE_LINES; | |
else if (!strcasecmp(env, "UNTILHOLE")) table = LK_SHAPE_UNTIL_HOLE; | |
} | |
if ((env = getenv("NUMERIC")) != NULL) { | |
numeric = 1; | |
} | |
if ((env = getenv("UNICODE")) != NULL) { | |
flags |= LK_FLAG_UNICODE_MODE; | |
flags |= LK_FLAG_PREFER_UNICODE; | |
} | |
lk_set_parser_flags(ctx, flags); | |
f.pipe = 0; | |
strcpy(f.pathname, argv[1]); | |
f.fd = fopen(argv[1], "r"); | |
if (f.fd == NULL) { | |
perror("unable to open keymap file"); | |
goto fail; | |
} | |
if (lk_parse_keymap(ctx, &f) < 0) { | |
perror("unable to parse keymap"); | |
goto fail; | |
} | |
if ((env = getenv("DUMPMODE")) != NULL) { | |
if (!strcasecmp(env, "BINARY")) rc = lk_dump_bkeymap(ctx, stdout); | |
else if (!strcasecmp(env, "CTABLE")) rc = lk_dump_ctable(ctx, stdout); | |
} else { | |
lk_dump_keymap(ctx, stdout, table, numeric); | |
lk_dump_diacs(ctx, stdout); | |
rc = 0; | |
} | |
fail: | |
lk_free(ctx); | |
lk_fpclose(&f); | |
if (rc < 0) | |
exit(EXIT_FAILURE); | |
exit(EXIT_SUCCESS); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment