Changeset b13daa0
- Timestamp:
- Mar 24, 2011, 4:09:22 PM (13 years ago)
- Branches:
- master, release-1.10, release-1.8, release-1.9
- Children:
- 45e2c95
- Parents:
- c809f5e
- git-author:
- David Benjamin <davidben@mit.edu> (03/10/11 15:14:32)
- git-committer:
- David Benjamin <davidben@mit.edu> (03/24/11 16:09:22)
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
keybinding.c
rd4927a7 rb13daa0 11 11 */ 12 12 13 static int owl_keybinding_make_keys(owl_keybinding *kb, const char *keyseq); 14 13 15 /* sets up a new keybinding for a command */ 14 int owl_keybinding_init(owl_keybinding *kb,const char *keyseq, const char *command, void (*function_fn)(void), const char *desc)16 owl_keybinding *owl_keybinding_new(const char *keyseq, const char *command, void (*function_fn)(void), const char *desc) 15 17 { 18 owl_keybinding *kb = g_new(owl_keybinding, 1); 19 16 20 owl_function_debugmsg("owl_keybinding_init: creating binding for <%s> with desc: <%s>", keyseq, desc); 17 if (command && !function_fn) { 21 if (command && function_fn) { 22 g_free(kb); 23 return NULL; 24 } else if (command && !function_fn) { 18 25 kb->type = OWL_KEYBINDING_COMMAND; 19 26 } else if (!command && function_fn) { 20 27 kb->type = OWL_KEYBINDING_FUNCTION; 21 28 } else { 22 return(-1);29 kb->type = OWL_KEYBINDING_NOOP; 23 30 } 24 31 25 32 if (owl_keybinding_make_keys(kb, keyseq) != 0) { 26 return(-1); 33 g_free(kb); 34 return NULL; 27 35 } 28 36 29 if (command)kb->command = g_strdup(command);37 kb->command = g_strdup(command); 30 38 kb->function_fn = function_fn; 31 if (desc) kb->desc = g_strdup(desc); 32 else kb->desc = NULL; 33 return(0); 39 kb->desc = g_strdup(desc); 40 return kb; 34 41 } 35 42 36 int owl_keybinding_make_keys(owl_keybinding *kb, const char *keyseq)43 static int owl_keybinding_make_keys(owl_keybinding *kb, const char *keyseq) 37 44 { 38 45 char **ktokens; … … 59 66 } 60 67 61 /* Releases data associated with a keybinding */62 void owl_keybinding_ cleanup(owl_keybinding *kb)68 /* Releases data associated with a keybinding, and the kb itself */ 69 void owl_keybinding_delete(owl_keybinding *kb) 63 70 { 64 71 if (kb->keys) g_free(kb->keys); 65 72 if (kb->desc) g_free(kb->desc); 66 73 if (kb->command) g_free(kb->command); 67 }68 69 /* Releases data associated with a keybinding, and the kb itself */70 void owl_keybinding_delete(owl_keybinding *kb)71 {72 owl_keybinding_cleanup(kb);73 74 g_free(kb); 74 75 } -
keymap.c
rf25df21 rb13daa0 38 38 int i; 39 39 40 if ((kb = g_new(owl_keybinding, 1)) == NULL) return(-1); 41 if (0 != owl_keybinding_init(kb, keyseq, command, function_fn, desc)) { 42 g_free(kb); 43 return(-1); 44 } 40 kb = owl_keybinding_new(keyseq, command, function_fn, desc); 41 if (kb == NULL) 42 return -1; 45 43 /* see if another matching binding, and if so remove it. 46 44 * otherwise just add this one. … … 63 61 int i; 64 62 65 if ((kb = g_new(owl_keybinding, 1)) == NULL) return(-1); 66 if (0 != owl_keybinding_make_keys(kb, keyseq)) { 67 g_free(kb); 68 return(-1); 69 } 63 kb = owl_keybinding_new(keyseq, NULL, NULL, NULL); 64 if (kb == NULL) 65 return -1; 70 66 71 67 for (i = owl_list_get_size(&km->bindings)-1; i >= 0; i--) { … … 74 70 owl_list_remove_element(&km->bindings, i); 75 71 owl_keybinding_delete(curkb); 72 owl_keybinding_delete(kb); 76 73 return(0); 77 74 } 78 75 } 76 owl_keybinding_delete(kb); 79 77 return(-2); 80 78 } -
owl.h
r41f0cf3 rb13daa0 186 186 #define OWL_KEYMAP_MAXSTACK 20 187 187 188 #define OWL_KEYBINDING_NOOP 0 /* dummy binding that does nothing */ 188 189 #define OWL_KEYBINDING_COMMAND 1 /* command string */ 189 190 #define OWL_KEYBINDING_FUNCTION 2 /* function taking no args */
Note: See TracChangeset
for help on using the changeset viewer.