diff options
author | Alexey Gladkov <gladkov.alexey@gmail.com> | 2013-07-24 18:28:13 +0400 |
---|---|---|
committer | Alexey Gladkov <gladkov.alexey@gmail.com> | 2013-07-24 18:28:13 +0400 |
commit | 35ae251b740c992e87d9bdd31da9e502919b4763 (patch) | |
tree | 5c5be888a7c4089b67d95f83a877d8e3d35046a6 | |
parent | 6373de5bfc437f60a925ca894308fbbb8b758dc1 (diff) | |
download | kbd-loadkeys.tar.gz |
Move lk_ctx content to private part of libraryloadkeys
Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
-rw-r--r-- | src/dumpkeys.c | 23 | ||||
-rw-r--r-- | src/libkeymap/Makefile.am | 1 | ||||
-rw-r--r-- | src/libkeymap/analyze.l | 3 | ||||
-rw-r--r-- | src/libkeymap/common.c | 21 | ||||
-rw-r--r-- | src/libkeymap/contextP.h | 77 | ||||
-rw-r--r-- | src/libkeymap/dump.c | 5 | ||||
-rw-r--r-- | src/libkeymap/kernel.c | 5 | ||||
-rw-r--r-- | src/libkeymap/keymap/common.h | 5 | ||||
-rw-r--r-- | src/libkeymap/keymap/context.h | 74 | ||||
-rw-r--r-- | src/libkeymap/kmap.c | 1 | ||||
-rw-r--r-- | src/libkeymap/ksyms.c | 6 | ||||
-rw-r--r-- | src/libkeymap/loadkeys.c | 4 | ||||
-rw-r--r-- | src/libkeymap/parser.y | 1 | ||||
-rw-r--r-- | src/libkeymap/summary.c | 7 | ||||
-rw-r--r-- | src/loadkeys.c | 29 |
15 files changed, 148 insertions, 114 deletions
diff --git a/src/dumpkeys.c b/src/dumpkeys.c index aece68fb..cc7ae365 100644 --- a/src/dumpkeys.c +++ b/src/dumpkeys.c @@ -80,7 +80,7 @@ main (int argc, char *argv[]) { char keys_only = 0; char diac_only = 0; - struct lk_ctx ctx; + struct lk_ctx *ctx; set_progname(argv[0]); @@ -88,7 +88,10 @@ main (int argc, char *argv[]) { 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) { @@ -122,10 +125,10 @@ main (int argc, char *argv[]) { 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(); @@ -153,14 +156,14 @@ main (int argc, char *argv[]) { } 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"), @@ -174,16 +177,16 @@ main (int argc, char *argv[]) { 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) diff --git a/src/libkeymap/Makefile.am b/src/libkeymap/Makefile.am index 07d14ade..037dade3 100644 --- a/src/libkeymap/Makefile.am +++ b/src/libkeymap/Makefile.am @@ -41,6 +41,7 @@ libkeymap_la_SOURCES = \ $(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) \ diff --git a/src/libkeymap/analyze.l b/src/libkeymap/analyze.l index 887deddd..b6f96fdc 100644 --- a/src/libkeymap/analyze.l +++ b/src/libkeymap/analyze.l @@ -2,9 +2,10 @@ #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" diff --git a/src/libkeymap/common.c b/src/libkeymap/common.c index cda0f230..0abe214e 100644 --- a/src/libkeymap/common.c +++ b/src/libkeymap/common.c @@ -2,9 +2,11 @@ #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, @@ -136,11 +138,14 @@ init_array(struct lk_ctx *ctx, struct lk_array **arr, size_t size) 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)); @@ -151,10 +156,12 @@ lk_init(struct lk_ctx *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; } diff --git a/src/libkeymap/contextP.h b/src/libkeymap/contextP.h new file mode 100644 index 00000000..d327a1dd --- /dev/null +++ b/src/libkeymap/contextP.h @@ -0,0 +1,77 @@ +#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; + + /** @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 */ +}; + +#endif /* LK_DATA_H */ diff --git a/src/libkeymap/dump.c b/src/libkeymap/dump.c index 8eceb9ae..3cab7466 100644 --- a/src/libkeymap/dump.c +++ b/src/libkeymap/dump.c @@ -14,12 +14,13 @@ #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 diff --git a/src/libkeymap/kernel.c b/src/libkeymap/kernel.c index 16fd3b80..9d1f55a1 100644 --- a/src/libkeymap/kernel.c +++ b/src/libkeymap/kernel.c @@ -8,12 +8,13 @@ */ #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) { diff --git a/src/libkeymap/keymap/common.h b/src/libkeymap/keymap/common.h index 5857c0e0..55deef50 100644 --- a/src/libkeymap/keymap/common.h +++ b/src/libkeymap/keymap/common.h @@ -8,11 +8,10 @@ #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. diff --git a/src/libkeymap/keymap/context.h b/src/libkeymap/keymap/context.h index ffc8300d..0a017455 100644 --- a/src/libkeymap/keymap/context.h +++ b/src/libkeymap/keymap/context.h @@ -1,5 +1,5 @@ -#ifndef LK_DATA_H -#define LK_DATA_H +#ifndef LK_CONTEXT_H +#define LK_CONTEXT_H #include <linux/kd.h> #include <linux/keyboard.h> @@ -7,13 +7,6 @@ #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 { @@ -34,67 +27,8 @@ 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 */ diff --git a/src/libkeymap/kmap.c b/src/libkeymap/kmap.c index ba3cd7b7..ca97ed56 100644 --- a/src/libkeymap/kmap.c +++ b/src/libkeymap/kmap.c @@ -6,6 +6,7 @@ #include "keymap.h" +#include "contextP.h" #include "ksyms.h" #include "modifiers.h" diff --git a/src/libkeymap/ksyms.c b/src/libkeymap/ksyms.c index 05a5de4a..0c2d6c11 100644 --- a/src/libkeymap/ksyms.c +++ b/src/libkeymap/ksyms.c @@ -2,11 +2,13 @@ #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" diff --git a/src/libkeymap/loadkeys.c b/src/libkeymap/loadkeys.c index a2a2a7ff..8834cc04 100644 --- a/src/libkeymap/loadkeys.c +++ b/src/libkeymap/loadkeys.c @@ -6,9 +6,11 @@ #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 diff --git a/src/libkeymap/parser.y b/src/libkeymap/parser.y index 7dcc4666..627494a3 100644 --- a/src/libkeymap/parser.y +++ b/src/libkeymap/parser.y @@ -15,6 +15,7 @@ #include "nls.h" #include "kbd.h" +#include "contextP.h" #include "ksyms.h" #include "modifiers.h" diff --git a/src/libkeymap/summary.c b/src/libkeymap/summary.c index 4d4527e1..26439341 100644 --- a/src/libkeymap/summary.c +++ b/src/libkeymap/summary.c @@ -8,14 +8,15 @@ */ #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) diff --git a/src/loadkeys.c b/src/loadkeys.c index 8a247ba0..6b23f688 100644 --- a/src/loadkeys.c +++ b/src/loadkeys.c @@ -94,7 +94,7 @@ main(int argc, char *argv[]) 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; @@ -111,7 +111,10 @@ main(int argc, char *argv[]) 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) { @@ -122,7 +125,7 @@ main(int argc, char *argv[]) options |= OPT_B; break; case 'c': - ctx.flags |= LK_FLAG_CLEAR_COMPOSE; + flags |= LK_FLAG_CLEAR_COMPOSE; break; case 'C': console = optarg; @@ -142,10 +145,10 @@ main(int argc, char *argv[]) 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); @@ -196,7 +199,7 @@ main(int argc, char *argv[]) } } - lk_set_parser_flags(&ctx, flags); + lk_set_parser_flags(ctx, flags); dirpath = dirpath1; if ((ev = getenv("LOADKEYS_KEYMAP_PATH")) != NULL) { @@ -212,7 +215,7 @@ main(int argc, char *argv[]) exit(EXIT_FAILURE); } - if ((rc = lk_parse_keymap(&ctx, &f)) == -1) + if ((rc = lk_parse_keymap(ctx, &f)) == -1) goto fail; @@ -220,7 +223,7 @@ main(int argc, char *argv[]) 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; } @@ -234,19 +237,19 @@ main(int argc, char *argv[]) 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); |