=== modified file 'termkey.c' --- termkey.c 2008-02-10 19:03:36 +0000 +++ termkey.c 2008-02-10 18:40:27 +0000 @@ -6,12 +6,6 @@ #include -struct keyinfo { - termkey_keysym sym; - int modifier_mask; - int modifier_set; -}; - struct termkey { int fd; int flags; @@ -25,15 +19,15 @@ const char **keynames; // There are 32 C0 codes - struct keyinfo c0[32]; + termkey_keysym c0[32]; // There are 64 codes 0x40 - 0x7F - struct keyinfo csi_ss3s[64]; - struct keyinfo ss3s[64]; + termkey_keysym csi_ss3s[64]; + termkey_keysym ss3s[64]; char ss3_kpalts[64]; int ncsifuncs; - struct keyinfo *csifuncs; + termkey_keysym *csifuncs; }; termkey_t *termkey_new_full(int fd, int flags, size_t buffsize) @@ -78,12 +72,12 @@ int i; for(i = 0; i < 32; i++) { - tk->c0[i].sym = TERMKEY_SYM_UNKNOWN; + tk->c0[i] = TERMKEY_SYM_UNKNOWN; } for(i = 0; i < 64; i++) { - tk->csi_ss3s[i].sym = TERMKEY_SYM_UNKNOWN; - tk->ss3s[i].sym = TERMKEY_SYM_UNKNOWN; + tk->csi_ss3s[i] = TERMKEY_SYM_UNKNOWN; + tk->ss3s[i] = TERMKEY_SYM_UNKNOWN; tk->ss3_kpalts[i] = 0; } @@ -98,7 +92,7 @@ tk->keynames[i] = NULL; for(i = 0; i < tk->ncsifuncs; i++) - tk->csifuncs[i].sym = TERMKEY_SYM_NONE; + tk->csifuncs[i] = TERMKEY_SYM_NONE; // Special built-in names termkey_register_keyname(tk, TERMKEY_SYM_NONE, "NONE"); @@ -125,8 +119,6 @@ termkey_register_csi_ss3(tk, TERMKEY_SYM_F3, 'R', "F3"); termkey_register_csi_ss3(tk, TERMKEY_SYM_F4, 'S', "F4"); - termkey_register_csi_ss3_full(tk, TERMKEY_SYM_TAB, TERMKEY_KEYMOD_SHIFT, TERMKEY_KEYMOD_SHIFT, 'Z', NULL); - termkey_register_ss3kpalt(tk, TERMKEY_SYM_KPENTER, 'M', "KPEnter", 0); termkey_register_ss3kpalt(tk, TERMKEY_SYM_KPEQUALS, 'X', "KPEquals", '='); termkey_register_ss3kpalt(tk, TERMKEY_SYM_KPMULT, 'j', "KPMult", '*'); @@ -217,12 +209,9 @@ if(codepoint < 0x20) { // C0 range key->code = 0; - key->modifiers = 0; - if(!(tk->flags & TERMKEY_FLAG_NOINTERPRET) && tk->c0[codepoint].sym != TERMKEY_SYM_UNKNOWN) { - key->code = tk->c0[codepoint].sym; - key->modifiers |= tk->c0[codepoint].modifier_set; - } + if(!(tk->flags & TERMKEY_FLAG_NOINTERPRET) && tk->c0[codepoint] != TERMKEY_SYM_UNKNOWN) + key->code = tk->c0[codepoint]; if(!key->code) { key->code = codepoint + 0x40; @@ -230,6 +219,7 @@ key->flags = 0; } else { + key->modifiers = 0; key->flags = TERMKEY_KEYFLAG_SPECIAL; } } @@ -321,20 +311,15 @@ eatbytes(tk, csi_end + 1); - if(args > 1 && arg[1] != -1) - key->modifiers = arg[1] - 1; - + key->modifiers = 0; key->flags = TERMKEY_KEYFLAG_SPECIAL; if(cmd == '~') { if(arg[0] == 27) { do_codepoint(tk, arg[2], key); } - else if(arg[0] >= 0 && arg[0] < tk->ncsifuncs) { - key->code = tk->csifuncs[arg[0]].sym; - key->modifiers &= ~(tk->csifuncs[arg[0]].modifier_mask); - key->modifiers |= tk->csifuncs[arg[0]].modifier_set; - } + else if(arg[0] >= 0 && arg[0] < tk->ncsifuncs) + key->code = tk->csifuncs[arg[0]]; else key->code = TERMKEY_SYM_UNKNOWN; @@ -343,14 +328,15 @@ } else { // We know from the logic above that cmd must be >= 0x40 and < 0x80 - key->code = tk->csi_ss3s[cmd - 0x40].sym; - key->modifiers &= ~(tk->csi_ss3s[cmd - 0x40].modifier_mask); - key->modifiers |= tk->csi_ss3s[cmd - 0x40].modifier_set; + key->code = tk->csi_ss3s[cmd - 0x40]; if(key->code == TERMKEY_SYM_UNKNOWN) fprintf(stderr, "CSI arg1=%d arg2=%d cmd=%c\n", arg[0], arg[1], cmd); } + if(args > 1 && arg[1] != -1) + key->modifiers |= arg[1] - 1; + return TERMKEY_RES_KEY; } @@ -366,8 +352,7 @@ if(cmd < 0x40 || cmd >= 0x80) return TERMKEY_SYM_UNKNOWN; - key->code = tk->csi_ss3s[cmd - 0x40].sym; - key->modifiers = tk->csi_ss3s[cmd - 0x40].modifier_set; + key->code = tk->csi_ss3s[cmd - 0x40]; if(key->code == TERMKEY_SYM_UNKNOWN) { if(tk->flags & TERMKEY_FLAG_CONVERTKP && tk->ss3_kpalts[cmd - 0x40]) { @@ -381,13 +366,13 @@ return TERMKEY_RES_KEY; } - key->code = tk->ss3s[cmd - 0x40].sym; - key->modifiers = tk->ss3s[cmd - 0x40].modifier_set; + key->code = tk->ss3s[cmd - 0x40]; } if(key->code == TERMKEY_SYM_UNKNOWN) fprintf(stderr, "SS3 %c (0x%02x)\n", cmd, cmd); + key->modifiers = 0; key->flags = TERMKEY_KEYFLAG_SPECIAL; return TERMKEY_RES_KEY; @@ -600,11 +585,6 @@ termkey_keysym termkey_register_c0(termkey_t *tk, termkey_keysym code, unsigned char ctrl, const char *name) { - return termkey_register_c0_full(tk, code, 0, 0, ctrl, name); -} - -termkey_keysym termkey_register_c0_full(termkey_t *tk, termkey_keysym code, int modifier_set, int modifier_mask, unsigned char ctrl, const char *name) -{ if(ctrl >= 0x20) { fprintf(stderr, "Cannot register C0 key at ctrl 0x%02x - out of bounds\n", ctrl); return -1; @@ -613,20 +593,13 @@ if(name) code = termkey_register_keyname(tk, code, name); - tk->c0[ctrl].sym = code; - tk->c0[ctrl].modifier_set = modifier_set; - tk->c0[ctrl].modifier_mask = modifier_mask; + tk->c0[ctrl] = code; return code; } termkey_keysym termkey_register_csi_ss3(termkey_t *tk, termkey_keysym code, unsigned char cmd, const char *name) { - return termkey_register_csi_ss3_full(tk, code, 0, 0, cmd, name); -} - -termkey_keysym termkey_register_csi_ss3_full(termkey_t *tk, termkey_keysym code, int modifier_set, int modifier_mask, unsigned char cmd, const char *name) -{ if(cmd < 0x40 || cmd >= 0x80) { fprintf(stderr, "Cannot register CSI/SS3 key at cmd 0x%02x - out of bounds\n", cmd); return -1; @@ -635,20 +608,13 @@ if(name) code = termkey_register_keyname(tk, code, name); - tk->csi_ss3s[cmd - 0x40].sym = code; - tk->csi_ss3s[cmd - 0x40].modifier_set = modifier_set; - tk->csi_ss3s[cmd - 0x40].modifier_mask = modifier_mask; + tk->csi_ss3s[cmd - 0x40] = code; return code; } termkey_keysym termkey_register_ss3kpalt(termkey_t *tk, termkey_keysym code, unsigned char cmd, const char *name, char kpalt) { - return termkey_register_ss3kpalt_full(tk, code, 0, 0, cmd, name, kpalt); -} - -termkey_keysym termkey_register_ss3kpalt_full(termkey_t *tk, termkey_keysym code, int modifier_set, int modifier_mask, unsigned char cmd, const char *name, char kpalt) -{ if(cmd < 0x40 || cmd >= 0x80) { fprintf(stderr, "Cannot register SS3 key at cmd 0x%02x - out of bounds\n", cmd); return -1; @@ -657,9 +623,7 @@ if(name) code = termkey_register_keyname(tk, code, name); - tk->ss3s[cmd - 0x40].sym = code; - tk->ss3s[cmd - 0x40].modifier_set = modifier_set; - tk->ss3s[cmd - 0x40].modifier_mask = modifier_mask; + tk->ss3s[cmd - 0x40] = code; tk->ss3_kpalts[cmd - 0x40] = kpalt; return code; @@ -667,28 +631,21 @@ termkey_keysym termkey_register_csifunc(termkey_t *tk, termkey_keysym code, int number, const char *name) { - return termkey_register_csifunc_full(tk, code, 0, 0, number, name); -} - -termkey_keysym termkey_register_csifunc_full(termkey_t *tk, termkey_keysym code, int modifier_set, int modifier_mask, int number, const char *name) -{ if(name) code = termkey_register_keyname(tk, code, name); if(number >= tk->ncsifuncs) { - struct keyinfo *new_csifuncs = realloc(tk->csifuncs, sizeof(new_csifuncs[0]) * (number + 1)); + termkey_keysym *new_csifuncs = realloc(tk->csifuncs, sizeof(new_csifuncs[0]) * (number + 1)); tk->csifuncs = new_csifuncs; // Fill in the hole for(int i = tk->ncsifuncs; i < number; i++) - tk->csifuncs[i].sym = TERMKEY_SYM_UNKNOWN; + tk->csifuncs[i] = TERMKEY_SYM_UNKNOWN; tk->ncsifuncs = number + 1; } - tk->csifuncs[number].sym = code; - tk->csifuncs[number].modifier_set = modifier_set; - tk->csifuncs[number].modifier_mask = modifier_mask; + tk->csifuncs[number] = code; return code; } === modified file 'termkey.h' --- termkey.h 2008-02-10 19:03:36 +0000 +++ termkey.h 2008-02-10 17:46:48 +0000 @@ -124,10 +124,6 @@ termkey_keysym termkey_register_ss3kpalt(termkey_t *tk, termkey_keysym code, unsigned char cmd, const char *name, char kpalt); termkey_keysym termkey_register_csifunc(termkey_t *tk, termkey_keysym code, int number, const char *name); -termkey_keysym termkey_register_c0_full(termkey_t *tk, termkey_keysym code, int modifier_set, int modifier_mask, unsigned char ctrl, const char *name); -termkey_keysym termkey_register_csi_ss3_full(termkey_t *tk, termkey_keysym code, int modifier_set, int modifier_mask, unsigned char cmd, const char *name); -termkey_keysym termkey_register_ss3kpalt_full(termkey_t *tk, termkey_keysym code, int modifier_set, int modifier_mask, unsigned char cmd, const char *name, char kpalt); -termkey_keysym termkey_register_csifunc_full(termkey_t *tk, termkey_keysym code, int modifier_set, int modifier_mask, int number, const char *name); const char *termkey_describe_sym(termkey_t *tk, termkey_keysym code);