[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 | |
---|
[ecd5dc5] | 46 | int owl_context_is_interactive(owl_context *ctx) { |
---|
| 47 | return(ctx->mode & OWL_CTX_INTERACTIVE)?1:0; |
---|
| 48 | } |
---|
[7d4fbcd] | 49 | |
---|
| 50 | void owl_context_set_startup(owl_context *ctx) { |
---|
| 51 | SET_MODE(ctx, OWL_CTX_STARTUP); |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | void owl_context_set_readconfig(owl_context *ctx) { |
---|
| 55 | SET_MODE(ctx, OWL_CTX_READCONFIG); |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | void owl_context_set_interactive(owl_context *ctx) { |
---|
| 59 | SET_MODE(ctx, OWL_CTX_INTERACTIVE); |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | void owl_context_set_popless(owl_context *ctx, owl_viewwin *vw) { |
---|
| 63 | ctx->data = (void*)vw; |
---|
| 64 | SET_ACTIVE(ctx, OWL_CTX_POPLESS); |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | void owl_context_set_recv(owl_context *ctx) { |
---|
| 68 | SET_ACTIVE(ctx, OWL_CTX_RECV); |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | void owl_context_set_editmulti(owl_context *ctx, owl_editwin *ew) { |
---|
| 72 | ctx->data = (void*)ew; |
---|
| 73 | SET_ACTIVE(ctx, OWL_CTX_EDITMULTI); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | void owl_context_set_editline(owl_context *ctx, owl_editwin *ew) { |
---|
| 77 | ctx->data = (void*)ew; |
---|
| 78 | SET_ACTIVE(ctx, OWL_CTX_EDITLINE); |
---|
| 79 | } |
---|
| 80 | |
---|