Set charset through the struct kmap
authorAlexey Gladkov <gladkov.alexey@gmail.com>
Thu, 21 Feb 2013 08:03:36 +0000 (12:03 +0400)
committerAlexey Gladkov <gladkov.alexey@gmail.com>
Thu, 21 Feb 2013 08:03:36 +0000 (12:03 +0400)
Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
src/libkeymap/dump.c
src/libkeymap/keymap.h
src/libkeymap/keymap/charset.h [new file with mode: 0644]
src/libkeymap/keymap/data.h
src/libkeymap/ksyms.c
src/libkeymap/ksyms.h
src/libkeymap/parser.y

index bbf0723..f3a48d1 100644 (file)
@@ -286,7 +286,7 @@ print_mod(FILE *fd, int x)
 }
 
 static void
-print_keysym(FILE *fd, int code, char numeric)
+print_keysym(struct keymap *kmap, FILE *fd, int code, char numeric)
 {
        unsigned int t;
        int v;
@@ -297,7 +297,7 @@ print_keysym(FILE *fd, int code, char numeric)
        t = KTYP(code);
        v = KVAL(code);
        if (t >= syms_size) {
-               if (!numeric && (p = codetoksym(code)) != NULL)
+               if (!numeric && (p = codetoksym(kmap, code)) != NULL)
                        fprintf(fd, "%-16s", p);
                else
                        fprintf(fd, "U+%04x          ", code ^ 0xf000);
@@ -320,13 +320,13 @@ print_keysym(FILE *fd, int code, char numeric)
 }
 
 static void
-print_bind(FILE *fd, int bufj, int i, int j, char numeric)
+print_bind(struct keymap *kmap, FILE *fd, int bufj, int i, int j, char numeric)
 {
        if(j)
                fprintf(fd, "\t");
        print_mod(fd, j);
        fprintf(fd, "keycode %3d =", i);
-       print_keysym(fd, bufj, numeric);
+       print_keysym(kmap, fd, bufj, numeric);
        fprintf(fd, "\n");
 }
 
@@ -400,7 +400,7 @@ no_shorthands:
                        fprintf(fd, "keycode %3d =", i);
 
                        for (j = 0; j < keymapnr; j++)
-                               print_keysym(fd, buf[j], numeric);
+                               print_keysym(kmap, fd, buf[j], numeric);
 
                        fprintf(fd, "\n");
                        continue;
@@ -409,7 +409,7 @@ no_shorthands:
                if (table_shape == SEPARATE_LINES) {
                        for (j = 0; j < keymapnr; j++) {
                                //if (buf[j] != K_HOLE)
-                               print_bind(fd, buf[j], i, kmap->defining[j]-1, numeric);
+                               print_bind(kmap, fd, buf[j], i, kmap->defining[j]-1, numeric);
                        }
 
                        fprintf(fd, "\n");
@@ -478,7 +478,7 @@ unexpected:
                if (isasexpected) {
                        /* print only a single entry */
                        /* suppress the + for ordinary a-zA-Z */
-                       print_keysym(fd, K(KT_LATIN, val), numeric);
+                       print_keysym(kmap, fd, K(KT_LATIN, val), numeric);
                        fprintf(fd, "\n");
                } else {
                        /* choose between single entry line followed by exceptions,
@@ -499,13 +499,13 @@ unexpected:
 
                        if (bad <= count && bad < keymapnr-1) {
                                if (buf[0] != K_HOLE) {
-                                       print_keysym(fd, buf[0], numeric);
+                                       print_keysym(kmap, fd, buf[0], numeric);
                                }
                                fprintf(fd, "\n");
 
                                for (j = 1; j < keymapnr; j++) {
                                        if (buf[j] != buf[0] && !zapped[j]) {
-                                               print_bind(fd, buf[j], i, kmap->defining[j]-1, numeric);
+                                               print_bind(kmap, fd, buf[j], i, kmap->defining[j]-1, numeric);
                                        }
                                }
                        } else {
@@ -514,15 +514,15 @@ unexpected:
                                        (j == 0 || table_shape != UNTIL_HOLE ||
                                        kmap->defining[j]-1 == kmap->defining[j-1]-1+1);
                                     j++) {
-                                       //print_bind(fd, buf[j], i, kmap->defining[j]-1, numeric);
-                                       print_keysym(fd, buf[j], numeric);
+                                       //print_bind(kmap, fd, buf[j], i, kmap->defining[j]-1, numeric);
+                                       print_keysym(kmap, fd, buf[j], numeric);
                                }
 
                                fprintf(fd, "\n");
 
                                for (; j < keymapnr; j++) {
                                        if (buf[j] != K_HOLE) {
-                                               print_bind(fd, buf[j], i, kmap->defining[j]-1, numeric);
+                                               print_bind(kmap, fd, buf[j], i, kmap->defining[j]-1, numeric);
                                        }
                                }
                        }
index 59b31b7..6ed71c2 100644 (file)
@@ -8,5 +8,6 @@
 #include <keymap/logging.h>
 #include <keymap/parse.h>
 #include <keymap/findfile.h>
+#include <keymap/charset.h>
 
 #endif /* LK_KEYMAP_H */
diff --git a/src/libkeymap/keymap/charset.h b/src/libkeymap/keymap/charset.h
new file mode 100644 (file)
index 0000000..0dc69af
--- /dev/null
@@ -0,0 +1,9 @@
+#ifndef LK_CHARSET_H
+#define LK_CHARSET_H
+
+#include <keymap/data.h>
+
+void lk_list_charsets(FILE *f);
+int lk_set_charset(struct keymap *kmap, const char *name);
+
+#endif /* LK_CHARSET_H */
index aefcad5..29ca660 100644 (file)
@@ -57,6 +57,8 @@ struct keymap {
 
        int prefer_unicode;    
 
+       unsigned int charset;
+
        int rvalct;
        int state_ptr;
        lkfile_t *stack[MAX_INCLUDE_DEPTH];
index 494e193..a67ef45 100644 (file)
@@ -80,12 +80,11 @@ struct cs {
 };
 
 static unsigned int charsets_size = sizeof(charsets) / sizeof(charsets[0]);
-static unsigned int kmap_charset = 0;
 
 /* Functions for both dumpkeys and loadkeys. */
 
 void
-list_charsets(FILE *f) {
+lk_list_charsets(FILE *f) {
        int lth,ct;
        unsigned int i, j;
        char *mm[] = { "iso-8859-", "koi8-" };
@@ -118,12 +117,12 @@ list_charsets(FILE *f) {
 }
 
 int
-set_charset(const char *charset) {
+lk_set_charset(struct keymap *kmap, const char *charset) {
        unsigned int i;
 
        for (i = 1; i < charsets_size; i++) {
                if (!strcasecmp(charsets[i].charset, charset)) {
-                       kmap_charset = i;
+                       kmap->charset = i;
                        return 0;
                }
        }
@@ -131,7 +130,7 @@ set_charset(const char *charset) {
 }
 
 const char *
-codetoksym(int code) {
+codetoksym(struct keymap *kmap, int code) {
        unsigned int i;
        int j;
        sym *p;
@@ -152,7 +151,7 @@ codetoksym(int code) {
                if (KTYP(code) > KT_LATIN)
                        return syms[KTYP(code)].table[KVAL(code)];
 
-               i = kmap_charset;
+               i = kmap->charset;
                while (1) {
                        p = charsets[i].charnames;
                        if (p) {
@@ -166,7 +165,7 @@ codetoksym(int code) {
 
                        if (i == charsets_size)
                                i = 0;
-                       if (i == kmap_charset)
+                       if (i == kmap->charset)
                                break;
                }
        }
@@ -177,7 +176,7 @@ codetoksym(int code) {
                if (code < 0x80)
                        return iso646_syms[code];
 
-               i = kmap_charset;
+               i = kmap->charset;
                while (1) {
                        p = charsets[i].charnames;
                        if (p) {
@@ -191,7 +190,7 @@ codetoksym(int code) {
 
                        if (i == charsets_size)
                                i = 0;
-                       if (i == kmap_charset)
+                       if (i == kmap->charset)
                                break;
                }
 
@@ -206,10 +205,10 @@ static int
 kt_latin(struct keymap *kmap, const char *s, int direction) {
        int i, max;
 
-       if (kmap_charset) {
-               sym *p = charsets[kmap_charset].charnames;
+       if (kmap->charset) {
+               sym *p = charsets[kmap->charset].charnames;
 
-               for (i = charsets[kmap_charset].start; i < 256; i++, p++) {
+               for (i = charsets[kmap->charset].start; i < 256; i++, p++) {
                        if(p->name[0] && !strcmp(s, p->name))
                                return K(KT_LATIN, i);
                }
@@ -263,7 +262,7 @@ ksymtocode(struct keymap *kmap, const char *s, int direction) {
                        return ksymtocode(kmap, synonyms[i].official_name, direction);
 
        if (direction == TO_UNICODE) {
-               i = kmap_charset;
+               i = kmap->charset;
 
                while (1) {
                        p = charsets[i].charnames;
@@ -278,7 +277,7 @@ ksymtocode(struct keymap *kmap, const char *s, int direction) {
 
                        if (i == charsets_size)
                                i = 0;
-                       if (i == kmap_charset)
+                       if (i == kmap->charset)
                                break;
                }
        } else /* if (!chosen_charset[0]) */ {
@@ -355,7 +354,7 @@ convert_code(struct keymap *kmap, int code, int direction)
        else {
                /* depending on direction, this will give us either an 8-bit
                 * K(KTYP, KVAL) or a Unicode keysym xor 0xf000 */
-               ksym = codetoksym(code);
+               ksym = codetoksym(kmap, code);
                if (ksym)
                        result = ksymtocode(kmap, ksym, direction);
                else
index 5f7a592..d92a924 100644 (file)
@@ -32,9 +32,7 @@ extern const unsigned int syn_size;
 #define TO_8BIT 0
 #define TO_UNICODE 1
 
-extern int set_charset(const char *name);
-extern const char *codetoksym(int code);
-extern void list_charsets(FILE *f);
+extern const char *codetoksym(struct keymap *kmap, int code);
 extern int ksymtocode(struct keymap *kmap, const char *s, int direction);
 extern int convert_code(struct keymap *kmap, int code, int direction);
 extern int add_capslock(struct keymap *kmap, int code);
index 7580e55..1c51cba 100644 (file)
@@ -702,7 +702,7 @@ line                : EOL
                ;
 charsetline    : CHARSET STRLITERAL EOL
                        {
-                               if (set_charset((char *) $2.data)) {
+                               if (lk_set_charset(kmap, (char *) $2.data)) {
                                        log_error(kmap,
                                                _("unknown charset %s - ignoring charset request\n"),
                                                (char *) $2.data);