Changeset e1b136bf for keybinding.c
- Timestamp:
- May 11, 2009, 9:50:58 PM (16 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
- File:
-
- 1 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 }
Note: See TracChangeset
for help on using the changeset viewer.