Lines Matching refs:kt
70 static int _kt_extend_table(KeyTab *kt);
79 static KtKeyMatch _kt_locate_keybinding(KeyTab *kt, const char *binary_keyseq,
90 KeyTab *kt; /* The object to be returned */
94 kt = (KeyTab *) malloc(sizeof(KeyTab));
95 if(!kt) {
104 kt->err = NULL;
105 kt->size = KT_TABLE_INC;
106 kt->nkey = 0;
107 kt->table = NULL;
108 kt->actions = NULL;
109 kt->smem = NULL;
113 kt->err = _new_ErrMsg();
114 if(!kt->err)
115 return _del_KeyTab(kt);
119 kt->table = (KeySym *) malloc(sizeof(kt->table[0]) * kt->size);
120 if(!kt->table) {
122 return _del_KeyTab(kt);
127 kt->actions = _new_HashTable(NULL, KT_HASH_SIZE, IGNORE_CASE, NULL, 0);
128 if(!kt->actions)
129 return _del_KeyTab(kt);
134 kt->smem = _new_StringMem(KT_TABLE_INC);
135 if(!kt->smem)
136 return _del_KeyTab(kt);
137 return kt;
144 * kt KeyTab * The object to be deleted.
148 KeyTab *_del_KeyTab(KeyTab *kt)
150 if(kt) {
151 if(kt->table)
152 free(kt->table);
153 kt->actions = _del_HashTable(kt->actions);
154 kt->smem = _del_StringMem(kt->smem, 1);
155 kt->err = _del_ErrMsg(kt->err);
156 free(kt);
165 * kt KeyTab * The table to be extended.
170 static int _kt_extend_table(KeyTab *kt)
175 KeySym *newtab = (KeySym *) realloc(kt->table, sizeof(kt->table[0]) *
176 (kt->size + KT_TABLE_INC));
181 _err_record_msg(kt->err, "Can't extend keybinding table", END_ERR_MSG);
188 kt->table = newtab;
189 kt->size += KT_TABLE_INC;
197 * kt KeyTab * The table to add the binding to.
207 int _kt_set_keybinding(KeyTab *kt, KtBinder binder, const char *keyseq,
215 if(kt==NULL || !keyseq) {
217 if(kt)
218 _err_record_msg(kt->err, "NULL argument(s)", END_ERR_MSG);
228 Symbol *sym = _find_HashSymbol(kt->actions, action);
230 _err_record_msg(kt->err, "Unknown key-binding action: ", action,
241 return _kt_set_keyfn(kt, binder, keyseq, keyfn, data);
249 * kt KeyTab * The table to add the binding to.
260 int _kt_set_keyfn(KeyTab *kt, KtBinder binder, const char *keyseq,
273 if(kt==NULL || !keyseq) {
275 if(kt)
276 _err_record_msg(kt->err, "NULL argument(s)", END_ERR_MSG);
289 binary = _new_StringMemString(kt->smem, size + 1);
292 _err_record_msg(kt->err, "Insufficient memory to record key sequence",
300 binary = _del_StringMemString(kt->smem, binary);
306 switch(_kt_locate_keybinding(kt, binary, nc, &first, &last)) {
314 _kt_assign_action(kt->table + first, binder, keyfn, data);
316 _del_StringMemString(kt->smem, kt->table[first].keyseq);
317 memmove(kt->table + first, kt->table + first + 1,
318 (kt->nkey - first - 1) * sizeof(kt->table[0]));
319 kt->nkey--;
321 binary = _del_StringMemString(kt->smem, binary);
330 _err_record_msg(kt->err, "Can't bind \"", keyseq,
333 binary = _del_StringMemString(kt->smem, binary);
350 if(kt->nkey + 1 > kt->size) {
351 if(_kt_extend_table(kt)) {
352 binary = _del_StringMemString(kt->smem, binary);
359 if(last < kt->nkey) {
360 memmove(kt->table + last + 1, kt->table + last,
361 (kt->nkey - last) * sizeof(kt->table[0]));
366 sym = kt->table + last;
376 kt->nkey++;
380 binary = _del_StringMemString(kt->smem, binary);
391 * kt KeyTab * The keybinding table to lookup in.
408 static KtKeyMatch _kt_locate_keybinding(KeyTab *kt, const char *binary_keyseq,
419 top = kt->nkey - 1;
422 test = _kt_compare_strings(kt->table[mid].keyseq, kt->table[mid].nc,
444 if(*last < kt->nkey && kt->table[*last].nc > nc &&
445 _kt_compare_strings(kt->table[*last].keyseq, nc, binary_keyseq, nc)==0) {
447 while(*last+1 < kt->nkey && kt->table[*last+1].nc > nc &&
448 _kt_compare_strings(kt->table[*last+1].keyseq, nc, binary_keyseq, nc)==0)
463 * kt KeyTab * The keybinding table to lookup in.
482 KtKeyMatch _kt_lookup_keybinding(KeyTab *kt, const char *binary_keyseq,
491 if(!kt || !binary_keyseq || !matches || !nmatch || nc < 0) {
493 if(kt)
494 _err_record_msg(kt->err, "NULL argument(s)", END_ERR_MSG);
501 status = _kt_locate_keybinding(kt, binary_keyseq, nc, &first, &last);
509 *matches = kt->table + first;
653 * kt KeyTab * The key-binding table.
663 int _kt_set_action(KeyTab *kt, const char *action, KtKeyFn *fn, void *data)
669 if(!kt || !action) {
671 if(kt)
672 _err_record_msg(kt->err, "NULL argument(s)", END_ERR_MSG);
679 sym = _del_HashSymbol(kt->actions, action);
685 sym = _find_HashSymbol(kt->actions, action);
694 if(!_new_HashSymbol(kt->actions, action, 0, (void (*)(void))fn, data, 0)) {
695 _err_record_msg(kt->err, "Insufficient memory to record key-binding action",
787 * kt KeyTab * The table of key bindings.
790 void _kt_clear_bindings(KeyTab *kt, KtBinder binder)
797 if(!kt)
802 for(oldkey=0; oldkey<kt->nkey; oldkey++)
803 _kt_assign_action(kt->table + oldkey, binder, 0, NULL);
808 for(oldkey=0; oldkey<kt->nkey; oldkey++) {
809 KeySym *sym = kt->table + oldkey;
811 _del_StringMemString(kt->smem, sym->keyseq);
814 kt->table[newkey] = *sym;
821 kt->nkey = newkey;
933 * kt KeyTab * The table of key bindings.
941 int _kt_add_bindings(KeyTab *kt, KtBinder binder, const KtKeyBinding *bindings,
948 if(!kt || !bindings) {
950 if(kt)
951 _err_record_msg(kt->err, "NULL argument(s)", END_ERR_MSG);
958 if(_kt_set_keybinding(kt, binder, bindings[i].keyseq, bindings[i].action))
968 * kt KeyTab * The table of key bindings.
981 int _kt_lookup_action(KeyTab *kt, const char *action,
988 if(!kt || !action) {
990 if(kt)
991 _err_record_msg(kt->err, "NULL argument(s)", END_ERR_MSG);
997 sym = _find_HashSymbol(kt->actions, action);
1016 * kt KeyTab * The table of key bindings.
1021 const char *_kt_last_error(KeyTab *kt)
1023 return kt ? _err_get_msg(kt->err) : "NULL KeyTab argument";