char keys_only = 0;
char diac_only = 0;
- struct lk_ctx ctx;
+ struct lk_ctx *ctx;
set_progname(argv[0]);
bindtextdomain(PACKAGE_NAME, LOCALEDIR);
textdomain(PACKAGE_NAME);
- lk_init(&ctx);
+ ctx = lk_init();
+ if (!ctx) {
+ exit(EXIT_FAILURE);
+ }
while ((c = getopt_long(argc, argv,
short_opts, long_opts, NULL)) != -1) {
diac_only = 1;
break;
case 'v':
- lk_set_log_priority(&ctx, LOG_INFO);
+ lk_set_log_priority(ctx, LOG_INFO);
break;
case 'c':
- if ((lk_set_charset(&ctx, optarg)) != 0) {
+ if ((lk_set_charset(ctx, optarg)) != 0) {
fprintf(stderr, _("unknown charset %s - ignoring charset request\n"),
optarg);
usage();
}
if (kbd_mode == K_UNICODE) {
- lk_set_parser_flags(&ctx, LK_FLAG_PREFER_UNICODE);
+ lk_set_parser_flags(ctx, LK_FLAG_PREFER_UNICODE);
}
- if ((rc = lk_kernel_keymap(&ctx, fd)) < 0)
+ if ((rc = lk_kernel_keymap(ctx, fd)) < 0)
goto fail;
if (short_info || long_info) {
- lk_dump_summary(&ctx, stdout, fd);
+ lk_dump_summary(ctx, stdout, fd);
if (long_info) {
printf(_("Symbols recognized by %s:\n(numeric value, symbol)\n\n"),
if (!diac_only) {
#endif
if (!funcs_only) {
- lk_dump_keymap(&ctx, stdout, table, numeric);
+ lk_dump_keymap(ctx, stdout, table, numeric);
}
#ifdef KDGKBDIACR
}
if (!funcs_only && !keys_only)
- lk_dump_diacs(&ctx, stdout);
+ lk_dump_diacs(ctx, stdout);
#endif
- fail: lk_free(&ctx);
+ fail: lk_free(ctx);
close(fd);
if (rc < 0)
$(headers) \
array.c \
findfile.c common.c kernel.c dump.c kmap.c summary.c loadkeys.c \
+ contextP.h \
parser.y parser.h analyze.l analyze.h \
modifiers.c modifiers.h \
ksyms.c ksyms.h $(ksyms_headers) \
#include <stdlib.h>
#include <unistd.h> /* readlink */
-#include "ksyms.h"
#include "nls.h"
#include "kbd.h"
+#include "contextP.h"
+#include "ksyms.h"
#include "paths.h"
#include "parser.h"
#include <stdlib.h>
#include <stdarg.h>
+#include "keymap.h"
+
#include "kbd.h"
#include "nls.h"
-#include "keymap.h"
+#include "contextP.h"
void __attribute__ ((format (printf, 6, 7)))
lk_log(struct lk_ctx *ctx, int priority,
return 0;
}
-int
-lk_init(struct lk_ctx *ctx)
+struct lk_ctx *
+lk_init(void)
{
+ struct lk_ctx *ctx;
+
+ ctx = malloc(sizeof(struct lk_ctx));
if (!ctx)
- return -1;
+ return NULL;
memset(ctx, 0, sizeof(struct lk_ctx));
init_array(ctx, &ctx->func_table, sizeof(void*)) < 0 ||
init_array(ctx, &ctx->accent_table, sizeof(void*)) < 0 ||
init_array(ctx, &ctx->key_constant, sizeof(char)) < 0 ||
- init_array(ctx, &ctx->key_line, sizeof(int)) < 0)
- return -1;
+ init_array(ctx, &ctx->key_line, sizeof(int)) < 0) {
+ lk_free(ctx);
+ return NULL;
+ }
- return 0;
+ return ctx;
}
--- /dev/null
+#ifndef LK_CONTEXTP_H
+#define LK_CONTEXTP_H
+
+#include "keymap.h"
+
+/**
+ * @brief Copy of struct kbdiacruc.
+ */
+struct kb_diacr {
+ unsigned int diacr, base, result;
+};
+
+/**
+ * @brief The maximum number of include levels.
+ */
+#define MAX_INCLUDE_DEPTH 20
+
+/**
+ * @brief Opaque object representing the library context.
+ */
+struct lk_ctx {
+ /**
+ * Parser flags that are set outside the library.
+ */
+ lk_flags flags;
+
+ /**
+ * Keywords used in keymap files.
+ */
+ lk_keywords keywords;
+
+ /**
+ * Key translation table (keycode to action code).
+ */
+ struct lk_array *keymap;
+
+ /**
+ * Function key string entry.
+ */
+ struct lk_array *func_table;
+
+ /**
+ * Accent table.
+ */
+ struct lk_array *accent_table;
+
+ /**
+ * User defined logging function.
+ */
+ void (*log_fn)(void *data, int priority,
+ const char *file, int line, const char *fn,
+ const char *format, va_list args);
+
+ /**
+ * The data passed to the @ref log_fn logging function as the first argument.
+ */
+ void *log_data;
+
+ /**
+ * Logging priority used by @ref log_fn logging function.
+ */
+ int log_priority;
+
+ /**
+ * User defined charset.
+ */
+ unsigned int charset;
+
+ /* Fields used by keymap parser */
+
+ struct lk_array *key_constant;
+ struct lk_array *key_line;
+ int mod;
+ lkfile_t *stack[MAX_INCLUDE_DEPTH];
+};
+
+#endif /* LK_CONTEXTP_H */
#include <ctype.h>
#include <unistd.h>
+#include "keymap.h"
+
+#include "contextP.h"
#include "ksyms.h"
#include "modifiers.h"
#include "nls.h"
-#include "keymap.h"
-
#define U(x) ((x) ^ 0xf000)
static void
*/
#include <string.h>
#include <errno.h>
-
#include <sys/ioctl.h>
-#include "nls.h"
#include "keymap.h"
+#include "nls.h"
+#include "contextP.h"
+
int
lk_kernel_keys(struct lk_ctx *ctx, int fd)
{
#include <keymap/context.h>
/** Initializes the structures necessary to read and/or parse keymap.
- * @param ctx is a keymap library context.
*
- * @return 0 on success, -1 on error.
+ * @return a pointer to keymap library context or NULL.
*/
-int lk_init(struct lk_ctx *ctx);
+struct lk_ctx *lk_init(void);
/** Free keymap resources.
* @param ctx is a keymap library context.
-#ifndef LK_DATA_H
-#define LK_DATA_H
+#ifndef LK_CONTEXT_H
+#define LK_CONTEXT_H
#include <linux/kd.h>
#include <linux/keyboard.h>
#include <keymap/array.h>
/**
- * @brief Copy of struct kbdiacruc.
- */
-struct kb_diacr {
- unsigned int diacr, base, result;
-};
-
-/**
* @brief Parser flags that are set outside the library.
*/
typedef enum {
} lk_keywords;
/**
- * @brief The maximum number of include levels.
- */
-#define MAX_INCLUDE_DEPTH 20
-
-/**
* @brief Opaque object representing the library context.
*/
-struct lk_ctx {
- /**
- * Parser flags that are set outside the library.
- */
- lk_flags flags;
-
- /**
- * Keywords used in keymap files.
- */
- lk_keywords keywords;
-
- /**
- * Key translation table (keycode to action code).
- */
- struct lk_array *keymap;
-
- /**
- * Function key string entry.
- */
- struct lk_array *func_table;
-
- /**
- * Accent table.
- */
- struct lk_array *accent_table;
-
- /** @protected
- * User defined logging function.
- */
- void (*log_fn)(void *data, int priority,
- const char *file, int line, const char *fn,
- const char *format, va_list args);
-
- /** @protected
- * The data passed to the @ref log_fn logging function as the first argument.
- */
- void *log_data;
-
- /** @protected
- * Logging priority used by @ref log_fn logging function.
- */
- int log_priority;
-
- /** @protected
- * User defined charset.
- */
- unsigned int charset;
-
- /* Fields used by keymap parser */
-
- struct lk_array *key_constant; /**< @private */
- struct lk_array *key_line; /**< @private */
- int mod; /**< @private */
- lkfile_t *stack[MAX_INCLUDE_DEPTH]; /**< @private */
-};
+struct lk_ctx;
-#endif /* LK_DATA_H */
+#endif /* LK_CONTEXT_H */
} lk_table_shape;
/**
+ * @brief General information about the keymap.
+ */
+struct kmapinfo {
+ lk_flags flags; /**< Parser flags that are set outside the library */
+ lk_keywords keywords; /**< Keywords used in keymap files */
+ size_t keymaps; /**< Number of keymaps in actual use */
+ size_t keymaps_alloced; /**< Number of keymaps dynamically allocated */
+ size_t functions; /**< Number of function keys */
+ size_t composes; /**< Number of compose definitions in actual use */
+};
+
+/**
* Outputs a keymap in binary format.
* @param ctx is a keymap library context.
* @param fd is a FILE pointer for output.
*/
void lk_dump_diacs(struct lk_ctx *ctx, FILE *fd);
+int lk_get_kmapinfo(struct lk_ctx *ctx, struct kmapinfo *res);
void lk_dump_summary(struct lk_ctx *ctx, FILE *fd, int console);
void lk_dump_symbols(FILE *fd);
#include "keymap.h"
+#include "contextP.h"
#include "ksyms.h"
#include "modifiers.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
-#include "ksyms.h"
-#include "nls.h"
#include "keymap.h"
+#include "contextP.h"
+#include "ksyms.h"
+#include "nls.h"
+
#include "syms.cp1250.h"
#include "syms.ethiopic.h"
#include "syms.iso8859_15.h"
#include <linux/keyboard.h>
#include <unistd.h>
+#include "keymap.h"
+
#include "nls.h"
#include "kbd.h"
-#include "keymap.h"
+#include "contextP.h"
#include "ksyms.h"
static int
#include "nls.h"
#include "kbd.h"
+#include "contextP.h"
#include "ksyms.h"
#include "modifiers.h"
*/
#include <string.h>
#include <errno.h>
-
#include <sys/ioctl.h>
+#include "keymap.h"
+
+#include "nls.h"
+#include "contextP.h"
#include "ksyms.h"
#include "modifiers.h"
-#include "nls.h"
-#include "keymap.h"
static char
valid_type(int fd, int t)
return i - 1;
}
+int
+lk_get_kmapinfo(struct lk_ctx *ctx, struct kmapinfo *res)
+{
+ int i;
+
+ if (!ctx)
+ return -1;
+
+ res->flags = ctx->flags;
+ res->keywords = ctx->keywords;
+ res->keymaps = ctx->keymap->count;
+ res->functions = ctx->func_table->count;
+ res->composes = ctx->accent_table->count;
+
+ res->keymaps_alloced = 0;
+
+ for (i = 0; i < MAX_NR_KEYMAPS; i++) {
+ if (lk_get_key(ctx, i, 0) == K_ALLOCATED) {
+ res->keymaps_alloced++;
+ }
+ }
+
+ return 0;
+}
+
#define NR_TYPES 15
void
lk_dump_summary(struct lk_ctx *ctx, FILE *fd, int console)
{
- int i, allocct = 0;
+ int i;
+ struct kmapinfo info;
- for (i = 0; i < MAX_NR_KEYMAPS; i++) {
- if (lk_get_key(ctx, i, 0) == K_ALLOCATED)
- allocct++;
- }
+ if (lk_get_kmapinfo(ctx, &info) < 0)
+ return;
fprintf(fd, _("keycode range supported by kernel: 1 - %d\n"),
NR_KEYS - 1);
fprintf(fd, _("max number of actions bindable to a key: %d\n"),
MAX_NR_KEYMAPS);
fprintf(fd, _("number of keymaps in actual use: %u\n"),
- (unsigned int) ctx->keymap->count);
+ (unsigned int) info.keymaps);
- if (allocct)
- fprintf(fd, _("of which %d dynamically allocated\n"), allocct);
+ fprintf(fd, _("of which %u dynamically allocated\n"),
+ (unsigned int) info.keymaps_alloced);
fprintf(fd, _("ranges of action codes supported by kernel:\n"));
fprintf(fd, _("max nr of compose definitions: %d\n"),
MAX_DIACR);
fprintf(fd, _("nr of compose definitions in actual use: %u\n"),
- (unsigned int) ctx->accent_table->count);
+ (unsigned int) info.composes);
}
void
const char *const *dirpath;
const char *dirpath2[] = { 0, 0 };
- struct lk_ctx ctx;
+ struct lk_ctx *ctx;
lk_flags flags = 0;
int c, i, rc = -1;
progname = set_progname(argv[0]);
- lk_init(&ctx);
+ ctx = lk_init();
+ if (!ctx) {
+ exit(EXIT_FAILURE);
+ }
while ((c = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) {
switch (c) {
options |= OPT_B;
break;
case 'c':
- ctx.flags |= LK_FLAG_CLEAR_COMPOSE;
+ flags |= LK_FLAG_CLEAR_COMPOSE;
break;
case 'C':
console = optarg;
flags |= LK_FLAG_PREFER_UNICODE;
break;
case 'q':
- lk_set_log_priority(&ctx, LOG_ERR);
+ lk_set_log_priority(ctx, LOG_ERR);
break;
case 'v':
- lk_set_log_priority(&ctx, LOG_INFO);
+ lk_set_log_priority(ctx, LOG_INFO);
break;
case 'V':
fprintf(stdout, _("%s from %s\n"), progname, PACKAGE_STRING);
}
}
- lk_set_parser_flags(&ctx, flags);
+ lk_set_parser_flags(ctx, flags);
dirpath = dirpath1;
if ((ev = getenv("LOADKEYS_KEYMAP_PATH")) != NULL) {
exit(EXIT_FAILURE);
}
- if ((rc = lk_parse_keymap(&ctx, &f)) == -1)
+ if ((rc = lk_parse_keymap(ctx, &f)) == -1)
goto fail;
f.fd = stdin;
strcpy(f.pathname, "<stdin>");
- if ((rc = lk_parse_keymap(&ctx, &f)) == -1)
+ if ((rc = lk_parse_keymap(ctx, &f)) == -1)
goto fail;
}
goto fail;
}
- if ((rc = lk_parse_keymap(&ctx, &f)) == -1)
+ if ((rc = lk_parse_keymap(ctx, &f)) == -1)
goto fail;
}
if (options & OPT_B) {
- rc = lk_dump_bkeymap(&ctx, stdout);
+ rc = lk_dump_bkeymap(ctx, stdout);
} else if (options & OPT_M) {
- rc = lk_dump_ctable(&ctx, stdout);
+ rc = lk_dump_ctable(ctx, stdout);
} else {
- rc = lk_load_keymap(&ctx, fd, kbd_mode);
+ rc = lk_load_keymap(ctx, fd, kbd_mode);
}
- fail: lk_free(&ctx);
+ fail: lk_free(ctx);
lk_fpclose(&f);
close(fd);
int main(int argc, char **argv)
{
- struct lk_ctx ctx;
+ struct lk_ctx *ctx;
lkfile_t f;
- lk_init(&ctx);
+ ctx = lk_init();
f.pipe = 0;
strcpy(f.pathname, argv[1]);
f.fd = fopen( argv[1], "r");
- lk_parse_keymap(&ctx, &f);
- lk_dump_bkeymap(&ctx, stdout);
+ lk_parse_keymap(ctx, &f);
+ lk_dump_bkeymap(ctx, stdout);
- lk_free(&ctx);
+ lk_free(ctx);
return 0;
}
{
char *s;
lkfile_t f;
- struct lk_ctx ctx;
- lk_init(&ctx);
- ctx.log_fn = NULL;
+ struct lk_ctx *ctx;
+
+ ctx = lk_init();
+ lk_set_log_fn(ctx, NULL, NULL);
f.pipe = 0;
strcpy(f.pathname, "charset-keymap0.map");
f.fd = fopen(DATADIR "/charset-keymap0.map", "r");
- fail_if(lk_parse_keymap(&ctx, &f) != 0, "Unable to parse keymap");
+ fail_if(lk_parse_keymap(ctx, &f) != 0, "Unable to parse keymap");
- s = lk_get_charset(&ctx);
+ s = lk_get_charset(ctx);
fail_if(strcmp(s, "iso-8859-2"), "Unable to parse charset");
- lk_free(&ctx);
+ lk_free(ctx);
}
END_TEST
{
char *s;
lkfile_t f;
- struct lk_ctx ctx;
- lk_init(&ctx);
- ctx.log_fn = NULL;
-
- f.pipe = 0;
- strcpy(f.pathname, "null");
- f.fd = fopen("/dev/null", "r");
+ struct lk_ctx *ctx;
- fail_if(lk_parse_keymap(&ctx, &f) != 0, "Unable to parse keymap");
-
- s = lk_get_charset(&ctx);
-
- fail_if(s != NULL, "Wrong charset");
-
- lk_free(&ctx);
-}
-END_TEST
-
-START_TEST(test2)
-{
- char *s;
- lkfile_t f;
- struct lk_ctx ctx;
- lk_init(&ctx);
- ctx.log_fn = NULL;
+ ctx = lk_init();
+ lk_set_log_fn(ctx, NULL, NULL);
f.pipe = 0;
strcpy(f.pathname, "null");
f.fd = fopen("/dev/null", "r");
- fail_if(lk_parse_keymap(&ctx, &f) != 0, "Unable to parse keymap");
+ fail_if(lk_parse_keymap(ctx, &f) != 0, "Unable to parse keymap");
- fail_if(lk_get_charset(NULL), "Wrong charset index");
+ s = lk_get_charset(ctx);
- ctx.charset = -1;
- fail_if(lk_get_charset(&ctx), "Wrong charset index");
-
- ctx.charset = 255;
- fail_if(lk_get_charset(&ctx), "Wrong charset index");
+ fail_if(s != NULL, "Wrong charset");
- lk_free(&ctx);
+ lk_free(ctx);
}
END_TEST
tcase_add_test(tc_core, test0);
tcase_add_test(tc_core, test1);
- tcase_add_test(tc_core, test2);
suite_add_tcase(s, tc_core);
return s;
{
lk_table_shape table;
char numeric;
- struct lk_ctx ctx;
+ struct lk_ctx *ctx;
lkfile_t f;
if (argc == 1) {
numeric = (!strcasecmp(argv[3], "TRUE")) ? 1 : 0;
- lk_init(&ctx);
- ctx.flags |= LK_FLAG_PREFER_UNICODE;
+ ctx = lk_init();
+ lk_set_parser_flags(ctx, LK_FLAG_PREFER_UNICODE);
f.pipe = 0;
strcpy(f.pathname, argv[1]);
f.fd = fopen( argv[1], "r");
- lk_parse_keymap(&ctx, &f);
- lk_dump_keymap(&ctx, stdout, table, numeric);
- lk_dump_diacs(&ctx, stdout);
+ lk_parse_keymap(ctx, &f);
+ lk_dump_keymap(ctx, stdout, table, numeric);
+ lk_dump_diacs(ctx, stdout);
- lk_free(&ctx);
+ lk_free(ctx);
return 0;
}
START_TEST(test_create_0)
{
- struct lk_ctx ctx;
- fail_unless(lk_init(&ctx) == 0,
- "Unable to initialize structure by valid pointer");
-}
-END_TEST
+ struct lk_ctx *ctx;
-START_TEST(test_create_1)
-{
- fail_if(lk_init(NULL) == 0,
- "Possible to initialize structure by NULL");
+ ctx = lk_init();
+
+ fail_if(ctx == NULL,
+ "Unable to initialize structure by valid pointer");
+ lk_free(ctx);
}
END_TEST
START_TEST(test_free_0)
{
- struct lk_ctx ctx;
+ struct lk_ctx *ctx;
- fail_unless(lk_init(&ctx) == 0,
+ ctx = lk_init();
+
+ fail_if(ctx == NULL,
"Unable to initialize structure by valid pointer");
- fail_unless(lk_free(&ctx) == 0,
+ fail_unless(lk_free(ctx) == 0,
"Unable to free by valid pointer");
-
- lk_free(&ctx);
}
END_TEST
START_TEST(test_free_1)
{
- fail_if(lk_free(NULL) == 0,
+ fail_if(lk_free(NULL) == 0,
"Possible to free NULL pointer");
}
END_TEST
TCase *tc_core = tcase_create(NULL);
tcase_add_test(tc_core, test_create_0);
- tcase_add_test(tc_core, test_create_1);
tcase_add_test(tc_core, test_free_0);
tcase_add_test(tc_core, test_free_1);
START_TEST(test_add_key_0)
{
- struct lk_ctx ctx;
- lk_init(&ctx);
- ctx.log_fn = NULL;
+ struct lk_ctx *ctx;
- fail_if(lk_add_key(&ctx, 0, NR_KEYS + 1, 0) != 0,
+ ctx = lk_init();
+ lk_set_log_fn(ctx, NULL, NULL);
+
+ fail_if(lk_add_key(ctx, 0, NR_KEYS + 1, 0) != 0,
"Unable to use index > NR_KEYS");
- fail_if(lk_add_key(&ctx, MAX_NR_KEYMAPS + 1, 0, 0) != 0,
+ fail_if(lk_add_key(ctx, MAX_NR_KEYMAPS + 1, 0, 0) != 0,
"Unable to use table > MAX_NR_KEYMAPS");
- lk_free(&ctx);
+ lk_free(ctx);
}
END_TEST
START_TEST(test_add_key_1)
{
- struct lk_ctx ctx;
- lk_init(&ctx);
- ctx.log_fn = NULL;
+ struct lk_ctx *ctx;
+
+ ctx = lk_init();
+ lk_set_log_fn(ctx, NULL, NULL);
- fail_unless(lk_add_key(&ctx, 0, 0, 0) == 0,
+ fail_unless(lk_add_key(ctx, 0, 0, 0) == 0,
"Unable to add keycode = 0");
- fail_unless(lk_add_key(&ctx, 0, 0, 16) == 0,
+ fail_unless(lk_add_key(ctx, 0, 0, 16) == 0,
"Unable to add keycode = 16");
- fail_unless(lk_add_key(&ctx, 1, 1, K_HOLE) == 0,
+ fail_unless(lk_add_key(ctx, 1, 1, K_HOLE) == 0,
"Unable to add keycode = K_HOLE");
- lk_free(&ctx);
+ lk_free(ctx);
}
END_TEST
START_TEST(test_add_key_2)
{
- struct lk_ctx ctx;
- lk_init(&ctx);
- ctx.log_fn = NULL;
+ struct lk_ctx *ctx;
- ctx.flags |= LK_KEYWORD_ALTISMETA;
+ ctx = lk_init();
+ lk_set_log_fn(ctx, NULL, NULL);
+ lk_set_parser_flags(ctx, LK_KEYWORD_ALTISMETA);
- fail_unless(lk_add_key(&ctx, 0, 0, 16) == 0,
+ fail_unless(lk_add_key(ctx, 0, 0, 16) == 0,
"Unable to add keycode");
- fail_unless(lk_get_key(&ctx, 0, 0) == 16,
+ fail_unless(lk_get_key(ctx, 0, 0) == 16,
"Unable to get keycode");
- lk_free(&ctx);
+ lk_free(ctx);
}
END_TEST
"\033[6~", 0, 0, 0, 0
};
int i;
- struct lk_ctx ctx;
+ struct lk_ctx *ctx;
- lk_init(&ctx);
- ctx.log_fn = NULL;
+ ctx = lk_init();
+ lk_set_log_fn(ctx, NULL, NULL);
for (i = 0; i < 30; i++) {
struct kbsentry ke;
ke.kb_string[sizeof(ke.kb_string) - 1] = 0;
ke.kb_func = i;
- fail_if(lk_add_func(&ctx, ke) == -1,
+ fail_if(lk_add_func(ctx, ke) == -1,
"Unable to add function");
}
- lk_free(&ctx);
+ lk_free(ctx);
}
END_TEST
START_TEST(test_add_diacr_0)
{
int i = MAX_DIACR + 10;
- struct lk_ctx ctx;
- lk_init(&ctx);
- ctx.log_fn = NULL;
+ struct lk_ctx *ctx;
+
+ ctx = lk_init();
+ lk_set_log_fn(ctx, NULL, NULL);
while (i > 0) {
- fail_if(lk_add_diacr(&ctx, 0, 0, 0) != 0,
+ fail_if(lk_add_diacr(ctx, 0, 0, 0) != 0,
"Unable to add diacr");
i--;
}
- lk_free(&ctx);
+ lk_free(ctx);
}
END_TEST
START_TEST(test_add_map_border)
{
- struct lk_ctx ctx;
+ struct lk_ctx *ctx;
- lk_init(&ctx);
- ctx.log_fn = NULL;
+ ctx = lk_init();
+ lk_set_log_fn(ctx, NULL, NULL);
- fail_unless(lk_add_map(&ctx, MAX_NR_KEYMAPS) == 0,
+ fail_unless(lk_add_map(ctx, MAX_NR_KEYMAPS) == 0,
"Unable to define map == MAX_NR_KEYMAPS");
- fail_unless(lk_add_map(&ctx, MAX_NR_KEYMAPS*2) == 0,
+ fail_unless(lk_add_map(ctx, MAX_NR_KEYMAPS*2) == 0,
"Unable to define map == MAX_NR_KEYMAPS*2");
- fail_unless(lk_add_map(&ctx, 0) == 0,
+ fail_unless(lk_add_map(ctx, 0) == 0,
"Unable to define map");
- fail_unless(lk_add_map(&ctx, 0) == 0,
+ fail_unless(lk_add_map(ctx, 0) == 0,
"Unable to define map");
- lk_free(&ctx);
+ lk_free(ctx);
}
END_TEST
START_TEST(test_add_map_0)
{
- struct lk_ctx ctx;
+ struct lk_ctx *ctx;
+ struct kmapinfo info;
- lk_init(&ctx);
- ctx.log_fn = NULL;
+ ctx = lk_init();
+ lk_set_log_fn(ctx, NULL, NULL);
- fail_if(lk_add_map(&ctx, 0) != 0, "Unable to define map");
- fail_if(ctx.keymap->count != 1, "Wrong keymap number");
+ fail_if(lk_add_map(ctx, 0) != 0, "Unable to define map");
+ lk_get_kmapinfo(ctx, &info);
+ fail_if(info.keymaps != 1, "Wrong keymap number");
- fail_if(lk_add_map(&ctx, 0) != 0, "Unable to define map");
- fail_if(ctx.keymap->count != 1, "Wrong keymap number");
+ fail_if(lk_add_map(ctx, 0) != 0, "Unable to define map");
+ lk_get_kmapinfo(ctx, &info);
+ fail_if(info.keymaps != 1, "Wrong keymap number");
- fail_if(lk_add_map(&ctx, 1) != 0, "Unable to define map");
- fail_if(ctx.keymap->count != 2, "Wrong keymap number");
+ fail_if(lk_add_map(ctx, 1) != 0, "Unable to define map");
+ lk_get_kmapinfo(ctx, &info);
+ fail_if(info.keymaps != 2, "Wrong keymap number");
- fail_if(lk_add_map(&ctx, 2) != 0, "Unable to define map");
- fail_if(ctx.keymap->count != 3, "Wrong keymap number");
+ fail_if(lk_add_map(ctx, 2) != 0, "Unable to define map");
+ lk_get_kmapinfo(ctx, &info);
+ fail_if(info.keymaps != 3, "Wrong keymap number");
- lk_free(&ctx);
+ lk_free(ctx);
}
END_TEST
int main(int argc, char **argv)
{
- struct lk_ctx ctx;
+ struct lk_ctx *ctx;
lkfile_t f;
- lk_init(&ctx);
+ ctx = lk_init();
f.pipe = 0;
strcpy(f.pathname, argv[1]);
f.fd = fopen( argv[1], "r");
- lk_parse_keymap(&ctx, &f);
- lk_dump_ctable(&ctx, stdout);
+ lk_parse_keymap(ctx, &f);
+ lk_dump_ctable(ctx, stdout);
- lk_free(&ctx);
+ lk_free(ctx);
return 0;
}
{
int c;
lkfile_t f;
- struct lk_ctx ctx;
+ struct lk_ctx *ctx;
- lk_init(&ctx);
- ctx.log_fn = NULL;
+ ctx = lk_init();
+ lk_set_log_fn(ctx, NULL, NULL);
f.pipe = 0;
strcpy(f.pathname, "keymap0.map");
f.fd = fopen(DATADIR "/keymap0.map", "r");
- fail_if(lk_parse_keymap(&ctx, &f) != 0, "Unable to parse keymap");
+ fail_if(lk_parse_keymap(ctx, &f) != 0, "Unable to parse keymap");
- c = lk_get_key(&ctx, 0, 16);
+ c = lk_get_key(ctx, 0, 16);
fail_if(KVAL(c) != 'q', "Unable to get keycode 16");
- c = lk_get_key(&ctx, 0, 17);
+ c = lk_get_key(ctx, 0, 17);
fail_if(KVAL(c) != 'w', "Unable to get keycode 17");
- c = lk_get_key(&ctx, 0, 18);
+ c = lk_get_key(ctx, 0, 18);
fail_if(KVAL(c) != 'e', "Unable to get keycode 18");
- c = lk_get_key(&ctx, 0, 19);
+ c = lk_get_key(ctx, 0, 19);
fail_if(KVAL(c) != 'r', "Unable to get keycode 19");
- c = lk_get_key(&ctx, 0, 20);
+ c = lk_get_key(ctx, 0, 20);
fail_if(KVAL(c) != 't', "Unable to get keycode 20");
- c = lk_get_key(&ctx, 0, 21);
+ c = lk_get_key(ctx, 0, 21);
fail_if(KVAL(c) != 'y', "Unable to get keycode 21");
- lk_free(&ctx);
+ lk_free(ctx);
}
END_TEST
{
int c;
lkfile_t f;
- struct lk_ctx ctx;
+ struct lk_ctx *ctx;
- lk_init(&ctx);
- ctx.log_fn = NULL;
+ ctx = lk_init();
+ lk_set_log_fn(ctx, NULL, NULL);
f.pipe = 0;
strcpy(f.pathname, "keymap1.map");
f.fd = fopen(DATADIR "/keymap1.map", "r");
- fail_if(lk_parse_keymap(&ctx, &f) != 0, "Unable to parse keymap");
+ fail_if(lk_parse_keymap(ctx, &f) != 0, "Unable to parse keymap");
- c = lk_get_key(&ctx, 0, 16);
+ c = lk_get_key(ctx, 0, 16);
fail_if(KVAL(c) != 'q', "Unable to get keycode");
- c = lk_get_key(&ctx, 1, 16);
+ c = lk_get_key(ctx, 1, 16);
fail_if(KVAL(c) != 'Q', "Unable to get keycode");
- lk_free(&ctx);
+ lk_free(ctx);
}
END_TEST
{
int i = 0;
lkfile_t f;
- struct lk_ctx ctx;
+ struct lk_ctx *ctx;
- lk_init(&ctx);
- ctx.log_fn = NULL;
+ ctx = lk_init();
+ lk_set_log_fn(ctx, NULL, NULL);
f.pipe = 0;
strcpy(f.pathname, "keymap2.map");
f.fd = fopen(DATADIR "/keymap2.map", "r");
- fail_if(lk_parse_keymap(&ctx, &f) != 0, "Unable to parse keymap");
+ fail_if(lk_parse_keymap(ctx, &f) != 0, "Unable to parse keymap");
while (i < MAX_NR_KEYMAPS) {
- int c = lk_get_key(&ctx, i, 17);
+ int c = lk_get_key(ctx, i, 17);
fail_if(KVAL(c) != 'x', "Unable to get keycode");
i++;
}
- lk_free(&ctx);
+ lk_free(ctx);
}
END_TEST
int i;
char str[] = "qwertyuiopasdfghjklzxcvbnm";
lkfile_t f;
- struct lk_ctx ctx;
+ struct lk_ctx *ctx;
- lk_init(&ctx);
- ctx.log_fn = NULL;
+ ctx = lk_init();
+ lk_set_log_fn(ctx, NULL, NULL);
f.pipe = 0;
strcpy(f.pathname, "keymap3.map");
f.fd = fopen(DATADIR "/keymap3.map", "r");
- fail_if(lk_parse_keymap(&ctx, &f) != 0, "Unable to parse keymap");
+ fail_if(lk_parse_keymap(ctx, &f) != 0, "Unable to parse keymap");
for (i = 0; i < 26; i++) {
- int c = lk_get_key(&ctx, i, 17);
+ int c = lk_get_key(ctx, i, 17);
fail_if(KVAL(c) != str[i], "Unable to get keycode");
}
- lk_free(&ctx);
+ lk_free(ctx);
}
END_TEST
{
int c;
lkfile_t f;
- struct lk_ctx ctx;
+ struct lk_ctx *ctx;
- lk_init(&ctx);
- ctx.log_fn = NULL;
+ ctx = lk_init();
+ lk_set_log_fn(ctx, NULL, NULL);
f.pipe = 0;
strcpy(f.pathname, "keymap4.map");
f.fd = fopen(DATADIR "/keymap4.map", "r");
- fail_if(lk_parse_keymap(&ctx, &f) != 0, "Unable to parse keymap");
+ fail_if(lk_parse_keymap(ctx, &f) != 0, "Unable to parse keymap");
- c = lk_get_key(&ctx, 0, 16);
+ c = lk_get_key(ctx, 0, 16);
fail_if(KVAL(c) != 'q', "Unable to get keycode");
- c = lk_get_key(&ctx, 0, 17);
+ c = lk_get_key(ctx, 0, 17);
fail_if(KVAL(c) != 'w', "Include40.map failed");
- c = lk_get_key(&ctx, 0, 18);
+ c = lk_get_key(ctx, 0, 18);
fail_if(KVAL(c) != 'e', "Include41.map failed");
- lk_free(&ctx);
+ lk_free(ctx);
}
END_TEST
int i;
lkfile_t f;
struct kbsentry kbs;
- struct lk_ctx ctx;
+ struct lk_ctx *ctx;
- lk_init(&ctx);
- ctx.log_fn = NULL;
+ ctx = lk_init();
+ lk_set_log_fn(ctx, NULL, NULL);
f.pipe = 0;
strcpy(f.pathname, "keymap5.map");
f.fd = fopen(DATADIR "/keymap5.map", "r");
- fail_if(lk_parse_keymap(&ctx, &f) != 0, "Unable to parse keymap");
+ fail_if(lk_parse_keymap(ctx, &f) != 0, "Unable to parse keymap");
for(i = 0; i < MAX_NR_FUNC; i++) {
kbs.kb_func = i;
kbs.kb_string[0] = 0;
- fail_if(lk_get_func(&ctx, &kbs) != 0,
+ fail_if(lk_get_func(ctx, &kbs) != 0,
"Unable to get func %d", i);
}
- lk_free(&ctx);
+ lk_free(ctx);
}
END_TEST
{
lkfile_t f;
struct kbsentry kbs;
- struct lk_ctx ctx;
+ struct lk_ctx *ctx;
- lk_init(&ctx);
- ctx.log_fn = NULL;
+ ctx = lk_init();
+ lk_set_log_fn(ctx, NULL, NULL);
f.pipe = 0;
strcpy(f.pathname, "keymap6.map");
f.fd = fopen(DATADIR "/keymap6.map", "r");
- fail_if(lk_parse_keymap(&ctx, &f) != 0, "Unable to parse keymap");
+ fail_if(lk_parse_keymap(ctx, &f) != 0, "Unable to parse keymap");
kbs.kb_func = 0;
kbs.kb_string[0] = 0;
- fail_if(lk_get_func(&ctx, &kbs) != 0, "Unable to get func 0");
+ fail_if(lk_get_func(ctx, &kbs) != 0, "Unable to get func 0");
kbs.kb_func = 1;
kbs.kb_string[0] = 0;
- fail_if(lk_get_func(&ctx, &kbs) != 0, "Unable to get func 1");
+ fail_if(lk_get_func(ctx, &kbs) != 0, "Unable to get func 1");
kbs.kb_func = 2;
kbs.kb_string[0] = 0;
- fail_if(lk_get_func(&ctx, &kbs) != -1, "Possible to get not alloced func");
+ fail_if(lk_get_func(ctx, &kbs) != -1, "Possible to get not alloced func");
- lk_free(&ctx);
+ lk_free(ctx);
}
END_TEST