1 | /* -*- mode: c; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
---|
2 | static const char fileIdent[] = "$Id$"; |
---|
3 | |
---|
4 | #ifdef HAVE_LIBZEPHYR |
---|
5 | #include <zephyr/zephyr.h> |
---|
6 | #endif |
---|
7 | #include <EXTERN.h> |
---|
8 | |
---|
9 | #define OWL_PERL |
---|
10 | #include "owl.h" |
---|
11 | SV *owl_perlconfig_curmessage2hashref(void); |
---|
12 | |
---|
13 | #define SV_IS_CODEREF(sv) (SvROK((sv)) && SvTYPE(SvRV((sv))) == SVt_PVCV) |
---|
14 | |
---|
15 | MODULE = BarnOwl PACKAGE = BarnOwl |
---|
16 | |
---|
17 | char * |
---|
18 | command(cmd) |
---|
19 | char *cmd |
---|
20 | PREINIT: |
---|
21 | char *rv = NULL; |
---|
22 | CODE: |
---|
23 | rv = owl_function_command(cmd); |
---|
24 | RETVAL = rv; |
---|
25 | OUTPUT: |
---|
26 | RETVAL |
---|
27 | CLEANUP: |
---|
28 | if (rv) owl_free(rv); |
---|
29 | |
---|
30 | SV * |
---|
31 | getcurmsg() |
---|
32 | CODE: |
---|
33 | ST(0) = owl_perlconfig_curmessage2hashref(); |
---|
34 | |
---|
35 | int |
---|
36 | getnumcols() |
---|
37 | CODE: |
---|
38 | RETVAL = owl_global_get_cols(&g); |
---|
39 | OUTPUT: |
---|
40 | RETVAL |
---|
41 | |
---|
42 | time_t |
---|
43 | getidletime() |
---|
44 | CODE: |
---|
45 | RETVAL = owl_global_get_idletime(&g); |
---|
46 | OUTPUT: |
---|
47 | RETVAL |
---|
48 | |
---|
49 | char * |
---|
50 | zephyr_getrealm() |
---|
51 | CODE: |
---|
52 | RETVAL = owl_zephyr_get_realm(); |
---|
53 | OUTPUT: |
---|
54 | RETVAL |
---|
55 | |
---|
56 | char * |
---|
57 | zephyr_getsender() |
---|
58 | CODE: |
---|
59 | RETVAL = owl_zephyr_get_sender(); |
---|
60 | OUTPUT: |
---|
61 | RETVAL |
---|
62 | |
---|
63 | void |
---|
64 | zephyr_zwrite(cmd,msg) |
---|
65 | char *cmd |
---|
66 | char *msg |
---|
67 | PREINIT: |
---|
68 | int i; |
---|
69 | CODE: |
---|
70 | i = owl_zwrite_create_and_send_from_line(cmd, msg); |
---|
71 | |
---|
72 | char * |
---|
73 | ztext_stylestrip(ztext) |
---|
74 | char *ztext |
---|
75 | PREINIT: |
---|
76 | char *rv = NULL; |
---|
77 | CODE: |
---|
78 | rv = owl_function_ztext_stylestrip(ztext); |
---|
79 | RETVAL = rv; |
---|
80 | OUTPUT: |
---|
81 | RETVAL |
---|
82 | CLEANUP: |
---|
83 | if (rv) owl_free(rv); |
---|
84 | |
---|
85 | void |
---|
86 | new_command_internal(name, func, summary, usage, description) |
---|
87 | char *name |
---|
88 | SV *func |
---|
89 | char *summary |
---|
90 | char *usage |
---|
91 | char *description |
---|
92 | PREINIT: |
---|
93 | owl_cmd cmd; |
---|
94 | CODE: |
---|
95 | { |
---|
96 | if(!SV_IS_CODEREF(func)) { |
---|
97 | croak("Command function must be a coderef!"); |
---|
98 | } |
---|
99 | SvREFCNT_inc(func); |
---|
100 | cmd.name = name; |
---|
101 | cmd.cmd_perl = func; |
---|
102 | cmd.summary = summary; |
---|
103 | cmd.usage = usage; |
---|
104 | cmd.description = description; |
---|
105 | cmd.validctx = OWL_CTX_ANY; |
---|
106 | cmd.cmd_aliased_to = NULL; |
---|
107 | cmd.cmd_args_fn = NULL; |
---|
108 | cmd.cmd_v_fn = NULL; |
---|
109 | cmd.cmd_i_fn = NULL; |
---|
110 | cmd.cmd_ctxargs_fn = NULL; |
---|
111 | cmd.cmd_ctxv_fn = NULL; |
---|
112 | cmd.cmd_ctxi_fn = NULL; |
---|
113 | owl_cmddict_add_cmd(owl_global_get_cmddict(&g), &cmd); |
---|
114 | } |
---|
115 | |
---|
116 | void queue_message(msg) |
---|
117 | SV *msg |
---|
118 | PREINIT: |
---|
119 | owl_message *m; |
---|
120 | CODE: |
---|
121 | { |
---|
122 | if(!SvROK(msg) || SvTYPE(SvRV(msg)) != SVt_PVHV) { |
---|
123 | croak("Usage: owl::queue_message($message)"); |
---|
124 | } |
---|
125 | |
---|
126 | m = owl_perlconfig_hashref2message(msg); |
---|
127 | |
---|
128 | owl_global_messagequeue_addmsg(&g, m); |
---|
129 | } |
---|
130 | |
---|
131 | void add_message(msg) |
---|
132 | SV *msg |
---|
133 | PREINIT: |
---|
134 | owl_message *m; |
---|
135 | CODE: |
---|
136 | { |
---|
137 | if(!SvROK(msg) || SvTYPE(SvRV(msg)) != SVt_PVHV) { |
---|
138 | croak("Usage: owl::add_message($message)"); |
---|
139 | } |
---|
140 | |
---|
141 | if (owl_global_is_displayoutgoing(&g)) { |
---|
142 | m = owl_perlconfig_hashref2message(msg); |
---|
143 | owl_function_add_message(m); |
---|
144 | } |
---|
145 | } |
---|
146 | |
---|
147 | void admin_message(header, body) |
---|
148 | char *header |
---|
149 | char *body |
---|
150 | CODE: |
---|
151 | { |
---|
152 | owl_function_adminmsg(header, body); |
---|
153 | } |
---|
154 | |
---|
155 | void start_question(line, callback) |
---|
156 | char *line |
---|
157 | SV *callback |
---|
158 | PREINIT: |
---|
159 | CODE: |
---|
160 | { |
---|
161 | if(!SV_IS_CODEREF(callback)) |
---|
162 | croak("Callback must be a subref"); |
---|
163 | |
---|
164 | owl_function_start_question(line); |
---|
165 | |
---|
166 | SvREFCNT_inc(callback); |
---|
167 | owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); |
---|
168 | owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); |
---|
169 | } |
---|
170 | |
---|
171 | void start_password(line, callback) |
---|
172 | char *line |
---|
173 | SV *callback |
---|
174 | PREINIT: |
---|
175 | CODE: |
---|
176 | { |
---|
177 | if(!SV_IS_CODEREF(callback)) |
---|
178 | croak("Callback must be a subref"); |
---|
179 | |
---|
180 | owl_function_start_password(line); |
---|
181 | |
---|
182 | SvREFCNT_inc(callback); |
---|
183 | owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); |
---|
184 | owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); |
---|
185 | } |
---|
186 | |
---|
187 | void start_edit_win(line, callback) |
---|
188 | char *line |
---|
189 | SV *callback |
---|
190 | PREINIT: |
---|
191 | owl_editwin * e; |
---|
192 | char buff[1024]; |
---|
193 | CODE: |
---|
194 | { |
---|
195 | if(!SV_IS_CODEREF(callback)) |
---|
196 | croak("Callback must be a subref"); |
---|
197 | |
---|
198 | e = owl_global_get_typwin(&g); |
---|
199 | owl_editwin_new_style(e, OWL_EDITWIN_STYLE_MULTILINE, |
---|
200 | owl_global_get_msg_history(&g)); |
---|
201 | owl_editwin_clear(e); |
---|
202 | owl_editwin_set_dotsend(e); |
---|
203 | snprintf(buff, 1023, "----> %s\n", line); |
---|
204 | owl_editwin_set_locktext(e, buff); |
---|
205 | |
---|
206 | owl_global_set_typwin_active(&g); |
---|
207 | |
---|
208 | SvREFCNT_inc(callback); |
---|
209 | owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); |
---|
210 | owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); |
---|
211 | } |
---|
212 | |
---|
213 | |
---|
214 | char * |
---|
215 | get_data_dir () |
---|
216 | CODE: |
---|
217 | RETVAL = (char *) DATADIR; |
---|
218 | OUTPUT: |
---|
219 | RETVAL |
---|
220 | |
---|
221 | void |
---|
222 | popless_text(text) |
---|
223 | char *text |
---|
224 | CODE: |
---|
225 | { |
---|
226 | owl_function_popless_text(text); |
---|
227 | } |
---|
228 | |
---|
229 | void |
---|
230 | popless_ztext(text) |
---|
231 | char *text |
---|
232 | CODE: |
---|
233 | { |
---|
234 | owl_fmtext fm; |
---|
235 | owl_fmtext_init_null(&fm); |
---|
236 | owl_fmtext_append_ztext(&fm, text); |
---|
237 | owl_function_popless_fmtext(&fm); |
---|
238 | owl_fmtext_free(&fm); |
---|
239 | } |
---|