Changeset 5643f99


Ignore:
Timestamp:
Mar 21, 2010, 1:12:11 AM (10 years ago)
Author:
Leonid Grinberg <leonidg@mit.edu>
Branches:
master, release-1.6, release-1.7, release-1.8, release-1.9
Children:
8a921b5
Parents:
51dbfb5
Message:
Abstract owl_keybinding_make_keys from owl_keybinding_init
File:
1 edited

Legend:

Unmodified
Added
Removed
  • keybinding.c

    r920201c r5643f99  
    1414int owl_keybinding_init(owl_keybinding *kb, const char *keyseq, const char *command, void (*function_fn)(void), const char *desc)
    1515{
    16   char **ktokens;
    17   int    nktokens, i;
    18  
    1916  owl_function_debugmsg("owl_keybinding_init: creating binding for <%s> with desc: <%s>", keyseq, desc);
    2017  if (command && !function_fn) {
     
    2623  }
    2724
     25  if (owl_keybinding_make_keys(kb, keyseq) != 0) {
     26    return(-1);
     27  }
     28
     29  if (command) kb->command = owl_strdup(command);
     30  kb->function_fn = function_fn;
     31  if (desc) kb->desc = owl_strdup(desc);
     32  else kb->desc = NULL;
     33  return(0);
     34}
     35
     36int owl_keybinding_make_keys(owl_keybinding *kb, const char *keyseq)
     37{
     38  char **ktokens;
     39  int    nktokens, i;
     40
    2841  ktokens = atokenize(keyseq, " ", &nktokens);
    2942  if (!ktokens) return(-1);
     
    3346  }
    3447  kb->keys = owl_malloc(nktokens*sizeof(int));
    35   for (i=0; i<nktokens; i++) {
     48  for (i = 0; i < nktokens; i++) {
    3649    kb->keys[i] = owl_keypress_fromstring(ktokens[i]);
    3750    if (kb->keys[i] == ERR) {
     
    4255  }
    4356  kb->len = nktokens;
    44 
    4557  atokenize_delete(ktokens, nktokens);
    46 
    47   if (command) kb->command = owl_strdup(command);
    48   kb->function_fn = function_fn;
    49   if (desc) kb->desc = owl_strdup(desc);
    50   else kb->desc = NULL;
    5158  return(0);
    5259}
Note: See TracChangeset for help on using the changeset viewer.