Changeset a999d9e


Ignore:
Timestamp:
Jan 7, 2010, 6:54:14 PM (14 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, release-1.10, release-1.6, release-1.7, release-1.8, release-1.9
Children:
2a17b63
Parents:
8a2815b
git-author:
Nelson Elhage <nelhage@mit.edu> (12/30/09 17:21:54)
git-committer:
Nelson Elhage <nelhage@mit.edu> (01/07/10 18:54:14)
Message:
Replace the global context with a context stack.

For now, we only use the top element of the stack.
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • global.c

    rb752f1e ra999d9e  
    2929  }
    3030
    31   owl_context_init(&g->ctx);
    32   owl_context_set_startup(&g->ctx);
     31  g->context_stack = NULL;
     32  owl_global_push_context(g, OWL_CTX_STARTUP, NULL, NULL);
     33
    3334  g->curmsg=0;
    3435  g->topmsg=0;
     
    167168
    168169owl_context *owl_global_get_context(owl_global *g) {
    169   return(&g->ctx);
    170 }
    171                          
     170  if (!g->context_stack)
     171    return NULL;
     172  return g->context_stack->data;
     173}
     174
     175static void owl_global_lookup_keymap(owl_global *g) {
     176  owl_context *c = owl_global_get_context(g);
     177  if (!c || !c->keymap)
     178    return;
     179
     180  if (!owl_keyhandler_activate(owl_global_get_keyhandler(g), c->keymap)) {
     181    owl_function_error("Unable to activate keymap '%s'", c->keymap);
     182  }
     183}
     184
     185void owl_global_push_context(owl_global *g, int mode, void *data, const char *keymap) {
     186  owl_context *c;
     187  if (!(mode & OWL_CTX_MODE_BITS))
     188    mode |= OWL_CTX_INTERACTIVE;
     189  c = owl_malloc(sizeof *c);
     190  c->mode = mode;
     191  c->data = data;
     192  c->keymap = owl_strdup(keymap);
     193  g->context_stack = g_list_prepend(g->context_stack, c);
     194  owl_global_lookup_keymap(g);
     195}
     196
     197void owl_global_pop_context(owl_global *g) {
     198  owl_context *c;
     199  if (!g->context_stack)
     200    return;
     201  c = owl_global_get_context(g);
     202  g->context_stack = g_list_delete_link(g->context_stack,
     203                                        g->context_stack);
     204  owl_free(c->keymap);
     205  owl_free(c);
     206  owl_global_lookup_keymap(g);
     207}
     208
    172209int owl_global_get_lines(const owl_global *g) {
    173210  return(g->lines);
  • owl.h

    rb752f1e ra999d9e  
    290290  int   mode;
    291291  void *data;           /* determined by mode */
     292  char *keymap;
    292293} owl_context;
    293294
     
    544545  owl_vardict vars;
    545546  owl_cmddict cmds;
    546   owl_context ctx;
     547  GList *context_stack;
    547548  owl_errqueue errqueue;
    548549  int lines, cols;
  • tester.c

    rf0f2eec ra999d9e  
    1818  owl_errqueue_init(owl_global_get_errqueue(&g));
    1919  owl_obarray_init(&(g.obarray));
     20  g.context_stack = NULL;
     21  owl_global_push_context(&g, OWL_CTX_STARTUP, NULL, NULL);
    2022
    2123  numtests = 0;
Note: See TracChangeset for help on using the changeset viewer.