Changeset e1b136bf
- Timestamp:
- May 11, 2009, 9:50:58 PM (15 years ago)
- Branches:
- master, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- 70110286, dfaa47d
- Parents:
- fa8f439
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
keybinding.c
r1716fed re1b136bf 34 34 return(-1); 35 35 } 36 kb-> j = owl_malloc((nktokens+1)*sizeof(int));36 kb->keys = owl_malloc(nktokens*sizeof(int)); 37 37 for (i=0; i<nktokens; i++) { 38 kb-> j[i] = owl_keypress_fromstring(ktokens[i]);39 if (kb-> j[i] == ERR) {38 kb->keys[i] = owl_keypress_fromstring(ktokens[i]); 39 if (kb->keys[i] == ERR) { 40 40 atokenize_free(ktokens, nktokens); 41 owl_free(kb-> j);41 owl_free(kb->keys); 42 42 return(-1); 43 43 } 44 44 } 45 kb-> j[i] = 0;45 kb->len = nktokens; 46 46 47 47 atokenize_free(ktokens, nktokens); … … 57 57 void owl_keybinding_free(owl_keybinding *kb) 58 58 { 59 if (kb-> j) owl_free(kb->j);59 if (kb->keys) owl_free(kb->keys); 60 60 if (kb->desc) owl_free(kb->desc); 61 61 if (kb->command) owl_free(kb->command); … … 80 80 81 81 /* returns 0 on success */ 82 int owl_keybinding_stack_tostring(int *j, char *buff, int bufflen)82 int owl_keybinding_stack_tostring(int *j, int len, char *buff, int bufflen) 83 83 { 84 84 char *pos = buff; … … 86 86 int i, n; 87 87 88 for (i=0; j[i]; i++) {88 for (i=0; i < len; i++) { 89 89 owl_keypress_tostring(j[i], 0, pos, rem-1); 90 if ( j[i+1]) strcat(pos, " ");90 if (i < len - 1) strcat(pos, " "); 91 91 n = strlen(pos); 92 92 pos += n; … … 99 99 int owl_keybinding_tostring(owl_keybinding *kb, char *buff, int bufflen) 100 100 { 101 return owl_keybinding_stack_tostring(kb-> j, buff, bufflen);101 return owl_keybinding_stack_tostring(kb->keys, kb->len, buff, bufflen); 102 102 } 103 103 … … 108 108 109 109 /* returns 0 on no match, 1 on subset match, and 2 on complete match */ 110 int owl_keybinding_match(owl_keybinding *kb, int *kpstack)110 int owl_keybinding_match(owl_keybinding *kb, owl_keyhandler *kh) 111 111 { 112 int *kbstack = kb->j; 113 114 while (*kbstack && *kpstack) { 115 if (*kbstack != *kpstack) { 112 int i; 113 for(i = 0; i <= kh->kpstackpos && i < kb->len; i++) { 114 if(kb->keys[i] != kh->kpstack[i]) 116 115 return 0; 117 }118 kbstack++; kpstack++;119 116 } 120 if (!*kpstack && !*kbstack) { 117 118 /* If we've made it to this point, then they match as far as they are. */ 119 if(kb->len == kh->kpstackpos + 1) { 120 /* Equal length */ 121 121 return 2; 122 } else if (!*kpstack) {122 } else if(kb->len > kh->kpstackpos + 1) { 123 123 return 1; 124 } else {125 return 0;126 124 } 125 126 return 0; 127 127 } 128 128 … … 130 130 int owl_keybinding_equal(owl_keybinding *kb1, owl_keybinding *kb2) 131 131 { 132 int *j1 = kb1->j; 133 int *j2 = kb2->j; 134 while (*j1 && *j2) { 135 if (*(j1++) != *(j2++)) return(0); 132 int i; 133 134 if(kb1->len != kb2->len) return 0; 135 136 for(i = 0; i < kb1->len; i++) { 137 if(kb1->keys[i] != kb2->keys[i]) 138 return 0; 136 139 } 137 if (*j1 != *j2) return(0); 138 return (1);140 141 return 1; 139 142 } -
keymap.c
r428834d re1b136bf 213 213 } 214 214 215 /* temporarily disallow C-`/C-SPACE until we fix associated bugs */216 if (j.ch == ERR || j.ch == 0) {217 return(-1);218 }219 220 /*221 owl_function_debugmsg("processkey: got key %d, active keymap %s, stack at %d",222 j, kh->active->name, kh->kpstackpos);223 */224 225 215 /* deal with ESC prefixing */ 226 216 if (!kh->in_esc && j.ch == 27) { … … 253 243 for (i=owl_list_get_size(&km->bindings)-1; i>=0; i--) { 254 244 kb = (owl_keybinding*)owl_list_get_element(&km->bindings, i); 255 match = owl_keybinding_match(kb, kh ->kpstack);245 match = owl_keybinding_match(kb, kh); 256 246 if (match == 1) { /* subset match */ 257 247 … … 290 280 { 291 281 char kbbuff[500]; 292 owl_keybinding_stack_tostring(kh->kpstack, k bbuff, 500);282 owl_keybinding_stack_tostring(kh->kpstack, kh->kpstackpos+1, kbbuff, 500); 293 283 owl_function_makemsg("'%s' is not a valid key in this context.", kbbuff); 294 284 owl_keyhandler_reset(kh); -
owl.h
radee9cc re1b136bf 444 444 445 445 typedef struct _owl_keybinding { 446 int *j; /* keypress stack (0-terminated) */ 446 int *keys; /* keypress stack */ 447 int len; /* length of stack */ 447 448 int type; /* command or function? */ 448 449 char *desc; /* description (or "*user*") */
Note: See TracChangeset
for help on using the changeset viewer.