ksyms: Use struct keymap
authorAlexey Gladkov <gladkov.alexey@gmail.com>
Fri, 7 Sep 2012 13:50:59 +0000 (17:50 +0400)
committerAlexey Gladkov <gladkov.alexey@gmail.com>
Fri, 7 Sep 2012 13:50:59 +0000 (17:50 +0400)
Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
src/ksyms.c
src/ksyms.h
src/loadkeys.analyze.l
src/loadkeys.parse.y

index dfb8760..fbc186f 100644 (file)
@@ -5,6 +5,8 @@
 #include "ksyms.h"
 #include "nls.h"
 
+#include "loadkeys.keymap.h"
+
 /* Keysyms whose KTYP is KT_LATIN or KT_LETTER and whose KVAL is 0..127. */
 
 static const char *iso646_syms[] = {
@@ -1760,17 +1762,17 @@ codetoksym(int code) {
 /* Functions for loadkeys. */
 
 int
-ksymtocode(int try_unicode, const char *s, int direction) {
+ksymtocode(struct keymap *kmap, const char *s, int direction) {
        unsigned int i;
        int j, jmax;
        int keycode;
        sym *p;
 
        if (direction == TO_AUTO)
-               direction = try_unicode ? TO_UNICODE : TO_8BIT;
+               direction = kmap->prefer_unicode ? TO_UNICODE : TO_8BIT;
 
        if (!strncmp(s, "Meta_", 5)) {
-               keycode = ksymtocode(try_unicode, s+5, TO_8BIT);
+               keycode = ksymtocode(kmap, s+5, TO_8BIT);
                if (KTYP(keycode) == KT_LATIN)
                        return K(KT_META, KVAL(keycode));
 
@@ -1790,7 +1792,7 @@ ksymtocode(int try_unicode, const char *s, int direction) {
 
        for (i = 0; i < syn_size; i++)
                if (!strcmp(s, synonyms[i].synonym))
-                       return ksymtocode(try_unicode, synonyms[i].official_name, direction);
+                       return ksymtocode(kmap, synonyms[i].official_name, direction);
 
        if (direction == TO_UNICODE) {
                for (i = 0; i < sizeof(charsets)/sizeof(charsets[0]); i++) {
@@ -1848,7 +1850,7 @@ ksymtocode(int try_unicode, const char *s, int direction) {
 }
 
 int
-convert_code(int try_unicode, int code, int direction)
+convert_code(struct keymap *kmap, int code, int direction)
 {
        const char *ksym;
        int unicode_forced = (direction == TO_UNICODE);
@@ -1856,7 +1858,7 @@ convert_code(int try_unicode, int code, int direction)
        int result;
 
        if (direction == TO_AUTO)
-               direction = try_unicode ? TO_UNICODE : TO_8BIT;
+               direction = kmap->prefer_unicode ? TO_UNICODE : TO_8BIT;
 
        if (KTYP(code) == KT_META)
                return code;
@@ -1875,7 +1877,7 @@ convert_code(int try_unicode, int code, int direction)
                 * K(KTYP, KVAL) or a Unicode keysym xor 0xf000 */
                ksym = codetoksym(code);
                if (ksym)
-                       result = ksymtocode(try_unicode, ksym, direction);
+                       result = ksymtocode(kmap, ksym, direction);
                else
                        result = code;
        }
@@ -1889,14 +1891,14 @@ convert_code(int try_unicode, int code, int direction)
 }
 
 int
-add_capslock(int try_unicode, int code)
+add_capslock(struct keymap *kmap, int code)
 {
-       if (KTYP(code) == KT_LATIN && (!try_unicode || code < 0x80))
+       if (KTYP(code) == KT_LATIN && (!(kmap->prefer_unicode) || code < 0x80))
                return K(KT_LETTER, KVAL(code));
        else if ((code ^ 0xf000) < 0x100)
                /* Unicode Latin-1 Supplement */
                /* a bit dirty to use KT_LETTER here, but it should work */
                return K(KT_LETTER, code ^ 0xf000);
        else
-               return convert_code(try_unicode, code, TO_AUTO);
+               return convert_code(kmap, code, TO_AUTO);
 }
index 4fb4277..98687ac 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef KSYMS_H
 #define KSYMS_H
 
+#include "loadkeys.keymap.h"
+
 typedef struct {
        unsigned short uni;
        const char *name;
@@ -33,8 +35,8 @@ extern const unsigned int syn_size;
 extern int set_charset(const char *name);
 extern const char *codetoksym(int code);
 extern void list_charsets(FILE *f);
-extern int ksymtocode(int try_unicode, const char *s, int direction);
-extern int convert_code(int try_unicode, int code, int direction);
-extern int add_capslock(int try_unicode, 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);
 
 #endif
index 3356ae1..95051f3 100644 (file)
@@ -365,7 +365,7 @@ To                      to|To|TO
                                yylval->num = strtol(yytext, NULL, 0);
                                return(NUMBER);
                        }
-<RVALUE>{Literal}      {       return((yylval->num = ksymtocode(yyextra->prefer_unicode, yytext, TO_AUTO)) == -1 ? ERROR : LITERAL);   }
+<RVALUE>{Literal}      {       return((yylval->num = ksymtocode(yyextra, yytext, TO_AUTO)) == -1 ? ERROR : LITERAL);   }
 \-                     {       return(DASH);           }
 \,                     {       return(COMMA);          }
 \+                     {       return(PLUS);           }
index 6b890d5..6db9fa1 100644 (file)
@@ -291,9 +291,9 @@ compose(struct keymap *kmap, int diacr, int base, int res)
        }
 
        ptr = &(kmap->accent_table[kmap->accent_table_size++]);
-       ptr->diacr  = convert_code(kmap->prefer_unicode, diacr, direction);
-       ptr->base   = convert_code(kmap->prefer_unicode, base, direction);
-       ptr->result = convert_code(kmap->prefer_unicode, res, direction);
+       ptr->diacr  = convert_code(kmap, diacr, direction);
+       ptr->base   = convert_code(kmap, base, direction);
+       ptr->result = convert_code(kmap, res, direction);
 
        return 0;
 }
@@ -922,12 +922,12 @@ rvalue1           : rvalue
                                kmap->key_buf[kmap->rvalct++] = $1;
                        }
                ;
-rvalue         : NUMBER        { $$ = convert_code(kmap->prefer_unicode, $1, TO_AUTO);         }
-                | PLUS NUMBER  { $$ = add_capslock(kmap->prefer_unicode, $2);                  }
-               | UNUMBER       { $$ = convert_code(kmap->prefer_unicode, $1^0xf000, TO_AUTO);  }
-               | PLUS UNUMBER  { $$ = add_capslock(kmap->prefer_unicode, $2^0xf000);           }
+rvalue         : NUMBER        { $$ = convert_code(kmap, $1, TO_AUTO);         }
+                | PLUS NUMBER  { $$ = add_capslock(kmap, $2);                  }
+               | UNUMBER       { $$ = convert_code(kmap, $1^0xf000, TO_AUTO);  }
+               | PLUS UNUMBER  { $$ = add_capslock(kmap, $2^0xf000);           }
                | LITERAL       { $$ = $1;                                      }
-                | PLUS LITERAL { $$ = add_capslock(kmap->prefer_unicode, $2);                  }
+                | PLUS LITERAL { $$ = add_capslock(kmap, $2);                  }
                ;
 %%