Add functions to convert ksyms
authorAlexey Gladkov <gladkov.alexey@gmail.com>
Sat, 4 Jan 2014 06:55:55 +0000 (10:55 +0400)
committerAlexey Gladkov <gladkov.alexey@gmail.com>
Sat, 4 Jan 2014 06:55:55 +0000 (10:55 +0400)
Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
src/libkeymap/keymap/dump.h
src/libkeymap/ksyms.c

index d3c926f..e38e478 100644 (file)
@@ -85,6 +85,24 @@ void lk_dump_funcs(struct lk_ctx *ctx, FILE *fd);
  */
 void lk_dump_diacs(struct lk_ctx *ctx, FILE *fd);
 
+/**
+ * Converts a number to a string representation of the character.
+ * @param ctx is a keymap library context.
+ * @param code is a numeric representation of ksym.
+ *
+ * @return a string representation of the code.
+ */
+char *lk_code_to_ksym(struct lk_ctx *ctx, int code);
+
+/**
+ * Converts a string to a numeric representation of the character.
+ * @param ctx is a keymap library context.
+ * @param code is a string representation of ksym.
+ *
+ * @return a unicode representation of the code.
+ */
+int lk_ksym_to_unicode(struct lk_ctx *ctx, const char *code);
+
 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);
index 0c2d6c1..1290203 100644 (file)
@@ -210,6 +210,18 @@ codetoksym(struct lk_ctx *ctx, int code) {
        return NULL;
 }
 
+char *
+lk_code_to_ksym(struct lk_ctx *ctx, int code)
+{
+       const char *sym;
+
+       sym = codetoksym(ctx, code);
+       if (!sym)
+               return NULL;
+
+       return strdup(sym);
+}
+
 /* Functions for loadkeys. */
 
 static int
@@ -336,6 +348,12 @@ ksymtocode(struct lk_ctx *ctx, const char *s, int direction) {
 }
 
 int
+lk_ksym_to_unicode(struct lk_ctx *ctx, const char *s)
+{
+       return ksymtocode(ctx, s, TO_UNICODE);
+}
+
+int
 convert_code(struct lk_ctx *ctx, int code, int direction)
 {
        const char *ksym;