[dd16bdd] | 1 | /* -*- mode: c; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
---|
[83a9b63] | 2 | static const char fileIdent[] = "$Id$"; |
---|
| 3 | |
---|
[8a54409] | 4 | #ifdef HAVE_LIBZEPHYR |
---|
[f1e629d] | 5 | #include <zephyr/zephyr.h> |
---|
[8a54409] | 6 | #endif |
---|
[f1e629d] | 7 | #include <EXTERN.h> |
---|
[8ee73f8d] | 8 | |
---|
[1152d45] | 9 | #define OWL_PERL |
---|
| 10 | #include "owl.h" |
---|
| 11 | SV *owl_perlconfig_curmessage2hashref(void); |
---|
[8ee73f8d] | 12 | |
---|
[db8b00b] | 13 | #define SV_IS_CODEREF(sv) (SvROK((sv)) && SvTYPE(SvRV((sv))) == SVt_PVCV) |
---|
| 14 | |
---|
[8203afd] | 15 | MODULE = BarnOwl PACKAGE = BarnOwl |
---|
[8ee73f8d] | 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 | |
---|
[f1e629d] | 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 |
---|
[7f792c1] | 41 | |
---|
| 42 | time_t |
---|
| 43 | getidletime() |
---|
| 44 | CODE: |
---|
| 45 | RETVAL = owl_global_get_idletime(&g); |
---|
| 46 | OUTPUT: |
---|
| 47 | RETVAL |
---|
[f1e629d] | 48 | |
---|
| 49 | char * |
---|
| 50 | zephyr_getrealm() |
---|
| 51 | CODE: |
---|
[8a54409] | 52 | RETVAL = owl_zephyr_get_realm(); |
---|
[f1e629d] | 53 | OUTPUT: |
---|
| 54 | RETVAL |
---|
| 55 | |
---|
| 56 | char * |
---|
| 57 | zephyr_getsender() |
---|
| 58 | CODE: |
---|
[8a54409] | 59 | RETVAL = owl_zephyr_get_sender(); |
---|
[f1e629d] | 60 | OUTPUT: |
---|
| 61 | RETVAL |
---|
| 62 | |
---|
[e1c4636] | 63 | void |
---|
[f1e629d] | 64 | zephyr_zwrite(cmd,msg) |
---|
[e1c4636] | 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: |
---|
[1fd0b25] | 78 | rv = owl_function_ztext_stylestrip(ztext); |
---|
[e1c4636] | 79 | RETVAL = rv; |
---|
| 80 | OUTPUT: |
---|
| 81 | RETVAL |
---|
| 82 | CLEANUP: |
---|
| 83 | if (rv) owl_free(rv); |
---|
| 84 | |
---|
[6922edd] | 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: |
---|
[db8b00b] | 95 | { |
---|
| 96 | if(!SV_IS_CODEREF(func)) { |
---|
| 97 | croak("Command function must be a coderef!"); |
---|
| 98 | } |
---|
[6922edd] | 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); |
---|
[db8b00b] | 114 | } |
---|
[dd16bdd] | 115 | |
---|
[1b6b2f3] | 116 | void queue_message(msg) |
---|
[dd16bdd] | 117 | SV *msg |
---|
| 118 | PREINIT: |
---|
| 119 | owl_message *m; |
---|
| 120 | CODE: |
---|
[1b6b2f3] | 121 | { |
---|
[dd16bdd] | 122 | if(!SvROK(msg) || SvTYPE(SvRV(msg)) != SVt_PVHV) { |
---|
[3066d23] | 123 | croak("Usage: BarnOwl::queue_message($message)"); |
---|
[dd16bdd] | 124 | } |
---|
[17eed9c] | 125 | |
---|
[30678ae] | 126 | m = owl_perlconfig_hashref2message(msg); |
---|
[dd16bdd] | 127 | |
---|
| 128 | owl_global_messagequeue_addmsg(&g, m); |
---|
[1b6b2f3] | 129 | } |
---|
[db8b00b] | 130 | |
---|
[1c2e0b3] | 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) { |
---|
[3066d23] | 138 | croak("Usage: BarnOwl::add_message($message)"); |
---|
[1c2e0b3] | 139 | } |
---|
| 140 | |
---|
| 141 | if (owl_global_is_displayoutgoing(&g)) { |
---|
| 142 | m = owl_perlconfig_hashref2message(msg); |
---|
| 143 | owl_function_add_message(m); |
---|
| 144 | } |
---|
| 145 | } |
---|
| 146 | |
---|
[3066d23] | 147 | void log_message(msg) |
---|
| 148 | SV *msg |
---|
| 149 | PREINIT: |
---|
| 150 | owl_message *m; |
---|
| 151 | CODE: |
---|
| 152 | { |
---|
| 153 | if(!SvROK(msg) || SvTYPE(SvRV(msg)) != SVt_PVHV) { |
---|
| 154 | croak("Usage: BarnOwl::log_message($message)"); |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | m = owl_perlconfig_hashref2message(msg); |
---|
| 158 | owl_log_message(m); |
---|
| 159 | owl_message_free(m); |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | void add_and_log_message(msg) |
---|
| 163 | SV *msg |
---|
| 164 | PREINIT: |
---|
| 165 | owl_message *m; |
---|
| 166 | CODE: |
---|
| 167 | { |
---|
| 168 | if(!SvROK(msg) || SvTYPE(SvRV(msg)) != SVt_PVHV) { |
---|
| 169 | croak("Usage: BarnOwl::add_and_log_message($message)"); |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | m = owl_perlconfig_hashref2message(msg); |
---|
| 173 | owl_log_message(m); |
---|
| 174 | if (owl_global_is_displayoutgoing(&g)) { |
---|
| 175 | owl_function_add_message(m); |
---|
| 176 | } else { |
---|
| 177 | owl_message_free(m); |
---|
| 178 | } |
---|
| 179 | } |
---|
| 180 | |
---|
[1c2e0b3] | 181 | void admin_message(header, body) |
---|
| 182 | char *header |
---|
| 183 | char *body |
---|
| 184 | CODE: |
---|
| 185 | { |
---|
| 186 | owl_function_adminmsg(header, body); |
---|
| 187 | } |
---|
| 188 | |
---|
[db8b00b] | 189 | void start_question(line, callback) |
---|
| 190 | char *line |
---|
| 191 | SV *callback |
---|
| 192 | PREINIT: |
---|
| 193 | CODE: |
---|
| 194 | { |
---|
| 195 | if(!SV_IS_CODEREF(callback)) |
---|
| 196 | croak("Callback must be a subref"); |
---|
| 197 | |
---|
| 198 | owl_function_start_question(line); |
---|
| 199 | |
---|
| 200 | SvREFCNT_inc(callback); |
---|
| 201 | owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); |
---|
| 202 | owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | void start_password(line, callback) |
---|
| 206 | char *line |
---|
| 207 | SV *callback |
---|
| 208 | PREINIT: |
---|
| 209 | CODE: |
---|
| 210 | { |
---|
| 211 | if(!SV_IS_CODEREF(callback)) |
---|
| 212 | croak("Callback must be a subref"); |
---|
| 213 | |
---|
| 214 | owl_function_start_password(line); |
---|
| 215 | |
---|
| 216 | SvREFCNT_inc(callback); |
---|
| 217 | owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); |
---|
| 218 | owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); |
---|
| 219 | } |
---|
| 220 | |
---|
| 221 | void start_edit_win(line, callback) |
---|
| 222 | char *line |
---|
| 223 | SV *callback |
---|
| 224 | PREINIT: |
---|
| 225 | owl_editwin * e; |
---|
| 226 | char buff[1024]; |
---|
| 227 | CODE: |
---|
| 228 | { |
---|
| 229 | if(!SV_IS_CODEREF(callback)) |
---|
| 230 | croak("Callback must be a subref"); |
---|
| 231 | |
---|
| 232 | e = owl_global_get_typwin(&g); |
---|
| 233 | owl_editwin_new_style(e, OWL_EDITWIN_STYLE_MULTILINE, |
---|
| 234 | owl_global_get_msg_history(&g)); |
---|
| 235 | owl_editwin_clear(e); |
---|
| 236 | owl_editwin_set_dotsend(e); |
---|
| 237 | snprintf(buff, 1023, "----> %s\n", line); |
---|
| 238 | owl_editwin_set_locktext(e, buff); |
---|
| 239 | |
---|
| 240 | owl_global_set_typwin_active(&g); |
---|
| 241 | |
---|
| 242 | SvREFCNT_inc(callback); |
---|
| 243 | owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); |
---|
| 244 | owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); |
---|
| 245 | } |
---|
[6b3f797] | 246 | |
---|
| 247 | |
---|
| 248 | char * |
---|
| 249 | get_data_dir () |
---|
| 250 | CODE: |
---|
| 251 | RETVAL = (char *) DATADIR; |
---|
| 252 | OUTPUT: |
---|
| 253 | RETVAL |
---|
[b6a253c] | 254 | |
---|
| 255 | void |
---|
| 256 | popless_text(text) |
---|
| 257 | char *text |
---|
| 258 | CODE: |
---|
| 259 | { |
---|
| 260 | owl_function_popless_text(text); |
---|
| 261 | } |
---|
| 262 | |
---|
| 263 | void |
---|
| 264 | popless_ztext(text) |
---|
| 265 | char *text |
---|
| 266 | CODE: |
---|
| 267 | { |
---|
| 268 | owl_fmtext fm; |
---|
| 269 | owl_fmtext_init_null(&fm); |
---|
| 270 | owl_fmtext_append_ztext(&fm, text); |
---|
| 271 | owl_function_popless_fmtext(&fm); |
---|
| 272 | owl_fmtext_free(&fm); |
---|
| 273 | } |
---|
[0ff2528] | 274 | |
---|
| 275 | void |
---|
| 276 | error(text) |
---|
| 277 | char *text |
---|
| 278 | CODE: |
---|
| 279 | { |
---|
| 280 | owl_function_error("%s", text); |
---|
| 281 | } |
---|
[b6c067a] | 282 | |
---|
| 283 | void |
---|
| 284 | _create_style(name, function, description) |
---|
| 285 | char *name |
---|
| 286 | char *function |
---|
| 287 | char *description |
---|
| 288 | PREINIT: |
---|
| 289 | /* This is to allow us to bootstrap the default style before the |
---|
| 290 | command architecture has been initialized */ |
---|
| 291 | owl_style *s; |
---|
| 292 | CODE: |
---|
| 293 | { |
---|
| 294 | s = owl_malloc(sizeof(owl_style)); |
---|
| 295 | owl_style_create_perl(s, name, function, description); |
---|
| 296 | owl_global_add_style(&g, s); |
---|
| 297 | } |
---|
[c2c5c77] | 298 | |
---|
| 299 | int |
---|
| 300 | getnumcolors() |
---|
| 301 | CODE: |
---|
| 302 | RETVAL = owl_function_get_color_count(); |
---|
| 303 | OUTPUT: |
---|
| 304 | RETVAL |
---|
| 305 | |
---|
| 306 | void |
---|
| 307 | _remove_filter(filterName) |
---|
| 308 | char *filterName |
---|
| 309 | CODE: |
---|
| 310 | { |
---|
| 311 | /* Don't delete the current view, or the 'all' filter */ |
---|
| 312 | if (strcmp(filterName, owl_view_get_filtname(owl_global_get_current_view(&g))) |
---|
| 313 | && strcmp(filterName, "all")) { |
---|
| 314 | owl_global_remove_filter(&g,filterName); |
---|
| 315 | } |
---|
| 316 | } |
---|
[f6b319c] | 317 | |
---|
| 318 | char * |
---|
| 319 | wordwrap(in, cols) |
---|
| 320 | char *in |
---|
| 321 | int cols |
---|
| 322 | PREINIT: |
---|
| 323 | char *rv = NULL; |
---|
| 324 | CODE: |
---|
| 325 | rv = owl_text_wordwrap(in, cols); |
---|
| 326 | RETVAL = rv; |
---|
| 327 | OUTPUT: |
---|
| 328 | RETVAL |
---|
| 329 | CLEANUP: |
---|
| 330 | if (rv) owl_free(rv); |
---|