Changeset cf83b7a for keymap.c


Ignore:
Timestamp:
Jun 30, 2003, 6:12:40 PM (17 years ago)
Author:
James M. Kretchmar <kretch@mit.edu>
Branches:
master, barnowl_perlaim, debian, owl, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
453bd70
Parents:
c9334b1
Message:
Started adding code to do question/response stuff
File:
1 edited

Legend:

Unmodified
Added
Removed
  • keymap.c

    rf87c490 rcf83b7a  
    55
    66/* returns 0 on success */
    7 int owl_keymap_init(owl_keymap *km, char *name, char *desc, void (*default_fn)(int), void (*prealways_fn)(int), void (*postalways_fn)(int)) {
     7int owl_keymap_init(owl_keymap *km, char *name, char *desc, void (*default_fn)(int), void (*prealways_fn)(int), void (*postalways_fn)(int))
     8{
    89  if (!name || !desc) return(-1);
    910  if ((km->name = owl_strdup(name)) == NULL) return(-1);
     
    1819
    1920/* note that this will free the memory for the bindings! */
    20 void owl_keymap_free(owl_keymap *km) {
     21void owl_keymap_free(owl_keymap *km)
     22{
    2123  owl_free(km->name);
    2224  owl_free(km->desc);
     
    2426}
    2527
    26 void owl_keymap_set_submap(owl_keymap *km, owl_keymap *submap) {
     28void owl_keymap_set_submap(owl_keymap *km, owl_keymap *submap)
     29{
    2730  km->submap = submap;
    2831}
    2932
    3033/* creates and adds a key binding */
    31 int owl_keymap_create_binding(owl_keymap *km, char *keyseq, char *command, void (*function_fn)(void), char *desc) {
     34int owl_keymap_create_binding(owl_keymap *km, char *keyseq, char *command, void (*function_fn)(void), char *desc)
     35{
    3236  owl_keybinding *kb, *curkb;
    3337  int i;
     
    5256
    5357/* returns a summary line describing this keymap.  the caller must free. */
    54 char *owl_keymap_summary(owl_keymap *km) {
     58char *owl_keymap_summary(owl_keymap *km)
     59{
    5560  char *s;
    5661  int slen;
     
    6368
    6469/* Appends details about the keymap to fm */
    65 void owl_keymap_get_details(owl_keymap *km, owl_fmtext *fm) {
     70void owl_keymap_get_details(owl_keymap *km, owl_fmtext *fm)
     71{
    6672  int i, nbindings;
    6773  owl_keybinding *kb;
     
    131137/* NOTE: keyhandler has private access to the internals of keymap */
    132138
    133 int owl_keyhandler_init(owl_keyhandler *kh) {
     139int owl_keyhandler_init(owl_keyhandler *kh)
     140{
    134141  if (0 != owl_dict_create(&kh->keymaps)) return(-1);
    135142  kh->active = NULL;
     
    139146
    140147/* adds a new keymap */
    141 void owl_keyhandler_add_keymap(owl_keyhandler *kh, owl_keymap *km) {
     148void owl_keyhandler_add_keymap(owl_keyhandler *kh, owl_keymap *km)
     149{
    142150  owl_dict_insert_element(&kh->keymaps, km->name, km, NULL);
    143151}
    144152
    145 owl_keymap *owl_keyhandler_create_and_add_keymap(owl_keyhandler *kh, char *name, char *desc, void (*default_fn)(int), void (*prealways_fn)(int), void (*postalways_fn)(int)) {
     153owl_keymap *owl_keyhandler_create_and_add_keymap(owl_keyhandler *kh, char *name, char *desc, void (*default_fn)(int), void (*prealways_fn)(int), void (*postalways_fn)(int))
     154{
    146155  owl_keymap *km;
    147156  km = (owl_keymap*)owl_malloc(sizeof(owl_keymap));
     
    153162
    154163/* resets state and clears out key stack */
    155 void owl_keyhandler_reset(owl_keyhandler *kh) {
     164void owl_keyhandler_reset(owl_keyhandler *kh)
     165{
    156166  kh->in_esc = 0;
    157167  memset(kh->kpstack, 0, (OWL_KEYMAP_MAXSTACK+1)*sizeof(int));
     
    159169}
    160170
    161 owl_keymap *owl_keyhandler_get_keymap(owl_keyhandler *kh, char *mapname) {
     171owl_keymap *owl_keyhandler_get_keymap(owl_keyhandler *kh, char *mapname)
     172{
    162173  return (owl_keymap*)owl_dict_find_element(&kh->keymaps, mapname);
    163174}
    164175
    165176/* free the list with owl_cmddict_namelist_free */
    166 void owl_keyhandler_get_keymap_names(owl_keyhandler *kh, owl_list *l) {
     177void owl_keyhandler_get_keymap_names(owl_keyhandler *kh, owl_list *l)
     178{
    167179  owl_dict_get_keys(&kh->keymaps, l);
    168180}
    169181
    170 void owl_keyhandler_keymap_namelist_free(owl_list *l) {
     182void owl_keyhandler_keymap_namelist_free(owl_list *l)
     183{
    171184  owl_list_free_all(l, owl_free);
    172185}
     
    176189/* sets the active keymap, which will also reset any key state.
    177190 * returns the new keymap, or NULL on failure. */
    178 owl_keymap *owl_keyhandler_activate(owl_keyhandler *kh, char *mapname) {
     191owl_keymap *owl_keyhandler_activate(owl_keyhandler *kh, char *mapname)
     192{
    179193  owl_keymap *km;
    180194  if (kh->active && !strcmp(mapname, kh->active->name)) return(kh->active);
     
    188202/* processes a keypress.  returns 0 if the keypress was handled,
    189203 * 1 if not handled, -1 on error, and -2 if j==ERR. */
    190 int owl_keyhandler_process(owl_keyhandler *kh, int j) {
     204int owl_keyhandler_process(owl_keyhandler *kh, int j)
     205{
    191206  owl_keymap     *km;
    192207  owl_keybinding *kb;
     
    272287}
    273288
    274 void owl_keyhandler_invalidkey(owl_keyhandler *kh) {
     289void owl_keyhandler_invalidkey(owl_keyhandler *kh)
     290{
    275291    char kbbuff[500];
    276292    owl_keybinding_stack_tostring(kh->kpstack, kbbuff, 500);
Note: See TracChangeset for help on using the changeset viewer.