1 | #include <string.h> |
---|
2 | #include "owl.h" |
---|
3 | |
---|
4 | #define SET_ACTIVE(ctx, new) ctx->mode = ((ctx->mode)&~OWL_CTX_ACTIVE_BITS)|new |
---|
5 | #define SET_MODE(ctx, new) ctx->mode = ((ctx->mode)&~OWL_CTX_MODE_BITS)|new |
---|
6 | |
---|
7 | int owl_context_init(owl_context *ctx) |
---|
8 | { |
---|
9 | ctx->mode = OWL_CTX_STARTUP; |
---|
10 | ctx->data = NULL; |
---|
11 | return 0; |
---|
12 | } |
---|
13 | |
---|
14 | |
---|
15 | /* returns whether test matches the current context */ |
---|
16 | int owl_context_matches(owl_context *ctx, int test) |
---|
17 | { |
---|
18 | /*owl_function_debugmsg(", current: 0x%04x test: 0x%04x\n", ctx->mode, test);*/ |
---|
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 | { |
---|
32 | return ctx->data; |
---|
33 | } |
---|
34 | |
---|
35 | int owl_context_get_mode(owl_context *ctx) |
---|
36 | { |
---|
37 | return ctx->mode & OWL_CTX_MODE_BITS; |
---|
38 | } |
---|
39 | |
---|
40 | int owl_context_get_active(owl_context *ctx) |
---|
41 | { |
---|
42 | return ctx->mode & OWL_CTX_ACTIVE_BITS; |
---|
43 | } |
---|
44 | |
---|
45 | int owl_context_is_startup(owl_context *ctx) |
---|
46 | { |
---|
47 | return (ctx->mode & OWL_CTX_STARTUP)?1:0; |
---|
48 | } |
---|
49 | |
---|
50 | int owl_context_is_interactive(owl_context *ctx) |
---|
51 | { |
---|
52 | return(ctx->mode & OWL_CTX_INTERACTIVE)?1:0; |
---|
53 | } |
---|
54 | |
---|
55 | void owl_context_set_startup(owl_context *ctx) |
---|
56 | { |
---|
57 | SET_MODE(ctx, OWL_CTX_STARTUP); |
---|
58 | } |
---|
59 | |
---|
60 | void owl_context_set_readconfig(owl_context *ctx) |
---|
61 | { |
---|
62 | SET_MODE(ctx, OWL_CTX_READCONFIG); |
---|
63 | } |
---|
64 | |
---|
65 | void owl_context_set_interactive(owl_context *ctx) |
---|
66 | { |
---|
67 | SET_MODE(ctx, OWL_CTX_INTERACTIVE); |
---|
68 | } |
---|
69 | |
---|
70 | void owl_context_set_popless(owl_context *ctx, owl_viewwin *vw) |
---|
71 | { |
---|
72 | ctx->data = (void*)vw; |
---|
73 | SET_ACTIVE(ctx, OWL_CTX_POPLESS); |
---|
74 | } |
---|
75 | |
---|
76 | void owl_context_set_recv(owl_context *ctx) |
---|
77 | { |
---|
78 | SET_ACTIVE(ctx, OWL_CTX_RECV); |
---|
79 | } |
---|
80 | |
---|
81 | void owl_context_set_editmulti(owl_context *ctx, owl_editwin *ew) |
---|
82 | { |
---|
83 | ctx->data = (void*)ew; |
---|
84 | SET_ACTIVE(ctx, OWL_CTX_EDITMULTI); |
---|
85 | } |
---|
86 | |
---|
87 | void owl_context_set_editline(owl_context *ctx, owl_editwin *ew) |
---|
88 | { |
---|
89 | ctx->data = (void*)ew; |
---|
90 | SET_ACTIVE(ctx, OWL_CTX_EDITLINE); |
---|
91 | } |
---|
92 | |
---|
93 | void owl_context_set_editresponse(owl_context *ctx, owl_editwin *ew) |
---|
94 | { |
---|
95 | ctx->data = (void*)ew; |
---|
96 | SET_ACTIVE(ctx, OWL_CTX_EDITRESPONSE); |
---|
97 | } |
---|
98 | |
---|