[7d4fbcd] | 1 | #include <string.h> |
---|
[1aee7d9] | 2 | #include "owl.h" |
---|
| 3 | |
---|
| 4 | static const char fileIdent[] = "$Id$"; |
---|
[7d4fbcd] | 5 | |
---|
| 6 | #define SET_ACTIVE(ctx, new) ctx->mode = ((ctx->mode)&~OWL_CTX_ACTIVE_BITS)|new |
---|
| 7 | #define SET_MODE(ctx, new) ctx->mode = ((ctx->mode)&~OWL_CTX_MODE_BITS)|new |
---|
| 8 | |
---|
| 9 | int owl_context_init(owl_context *ctx) { |
---|
| 10 | ctx->mode = OWL_CTX_STARTUP; |
---|
| 11 | ctx->data = NULL; |
---|
| 12 | return 0; |
---|
| 13 | } |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | /* returns whether test matches the current context */ |
---|
| 17 | int owl_context_matches(owl_context *ctx, int test) { |
---|
[10b866d] | 18 | /*owl_function_debugmsg(", current: 0x%04x test: 0x%04x\n", ctx->mode, test);*/ |
---|
[7d4fbcd] | 19 | if ((((ctx->mode&OWL_CTX_MODE_BITS) & test) |
---|
| 20 | || !(test&OWL_CTX_MODE_BITS)) |
---|
| 21 | && |
---|
| 22 | (((ctx->mode&OWL_CTX_ACTIVE_BITS) & test) |
---|
| 23 | || !(test&OWL_CTX_ACTIVE_BITS))) { |
---|
| 24 | return 1; |
---|
| 25 | } else { |
---|
| 26 | return 0; |
---|
| 27 | } |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | void *owl_context_get_data(owl_context *ctx) { |
---|
| 31 | return ctx->data; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | int owl_context_get_mode(owl_context *ctx) { |
---|
| 35 | return ctx->mode & OWL_CTX_MODE_BITS; |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | int owl_context_get_active(owl_context *ctx) { |
---|
| 39 | return ctx->mode & OWL_CTX_ACTIVE_BITS; |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | int owl_context_is_startup(owl_context *ctx) { |
---|
| 43 | return (ctx->mode & OWL_CTX_STARTUP)?1:0; |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | void owl_context_set_startup(owl_context *ctx) { |
---|
| 48 | SET_MODE(ctx, OWL_CTX_STARTUP); |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | void owl_context_set_readconfig(owl_context *ctx) { |
---|
| 52 | SET_MODE(ctx, OWL_CTX_READCONFIG); |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | void owl_context_set_interactive(owl_context *ctx) { |
---|
| 56 | SET_MODE(ctx, OWL_CTX_INTERACTIVE); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | void owl_context_set_popless(owl_context *ctx, owl_viewwin *vw) { |
---|
| 60 | ctx->data = (void*)vw; |
---|
| 61 | SET_ACTIVE(ctx, OWL_CTX_POPLESS); |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | void owl_context_set_recv(owl_context *ctx) { |
---|
| 65 | SET_ACTIVE(ctx, OWL_CTX_RECV); |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | void owl_context_set_editmulti(owl_context *ctx, owl_editwin *ew) { |
---|
| 69 | ctx->data = (void*)ew; |
---|
| 70 | SET_ACTIVE(ctx, OWL_CTX_EDITMULTI); |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | void owl_context_set_editline(owl_context *ctx, owl_editwin *ew) { |
---|
| 74 | ctx->data = (void*)ew; |
---|
| 75 | SET_ACTIVE(ctx, OWL_CTX_EDITLINE); |
---|
| 76 | } |
---|
| 77 | |
---|