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