[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 | |
---|
[74fc22a] | 15 | /************************************************************* |
---|
| 16 | * NOTE |
---|
| 17 | ************************************************************* |
---|
| 18 | * These functions, when they are intended to be user-visible, |
---|
| 19 | * are document in perlwrap.pm. If you add functions to this |
---|
| 20 | * file, add the appropriate documentation there! |
---|
| 21 | * |
---|
| 22 | * If the function is simple enough, we simply define its |
---|
| 23 | * entire functionality here in XS. If, however, it needs |
---|
| 24 | * complex argument processing or something, we define a |
---|
| 25 | * simple version here that takes arguments in as flat a |
---|
| 26 | * manner as possible, to simplify the XS code, with a name |
---|
| 27 | * with a trailing `_internal', and write a perl wrapper in |
---|
| 28 | * perlwrap.pm that munges the arguments as appropriate and |
---|
| 29 | * calls the internal version. |
---|
| 30 | */ |
---|
[8ee73f8d] | 31 | |
---|
[65fea01] | 32 | MODULE = BarnOwl PACKAGE = BarnOwl |
---|
| 33 | |
---|
[8ee73f8d] | 34 | char * |
---|
| 35 | command(cmd) |
---|
| 36 | char *cmd |
---|
| 37 | PREINIT: |
---|
| 38 | char *rv = NULL; |
---|
| 39 | CODE: |
---|
| 40 | rv = owl_function_command(cmd); |
---|
| 41 | RETVAL = rv; |
---|
| 42 | OUTPUT: |
---|
| 43 | RETVAL |
---|
| 44 | CLEANUP: |
---|
| 45 | if (rv) owl_free(rv); |
---|
| 46 | |
---|
[f1e629d] | 47 | SV * |
---|
| 48 | getcurmsg() |
---|
| 49 | CODE: |
---|
| 50 | ST(0) = owl_perlconfig_curmessage2hashref(); |
---|
| 51 | |
---|
| 52 | int |
---|
| 53 | getnumcols() |
---|
| 54 | CODE: |
---|
| 55 | RETVAL = owl_global_get_cols(&g); |
---|
| 56 | OUTPUT: |
---|
| 57 | RETVAL |
---|
[7f792c1] | 58 | |
---|
| 59 | time_t |
---|
| 60 | getidletime() |
---|
| 61 | CODE: |
---|
| 62 | RETVAL = owl_global_get_idletime(&g); |
---|
| 63 | OUTPUT: |
---|
| 64 | RETVAL |
---|
[f1e629d] | 65 | |
---|
| 66 | char * |
---|
| 67 | zephyr_getrealm() |
---|
| 68 | CODE: |
---|
[8a54409] | 69 | RETVAL = owl_zephyr_get_realm(); |
---|
[f1e629d] | 70 | OUTPUT: |
---|
| 71 | RETVAL |
---|
| 72 | |
---|
| 73 | char * |
---|
| 74 | zephyr_getsender() |
---|
| 75 | CODE: |
---|
[8a54409] | 76 | RETVAL = owl_zephyr_get_sender(); |
---|
[f1e629d] | 77 | OUTPUT: |
---|
| 78 | RETVAL |
---|
| 79 | |
---|
[e1c4636] | 80 | void |
---|
[f1e629d] | 81 | zephyr_zwrite(cmd,msg) |
---|
[e1c4636] | 82 | char *cmd |
---|
| 83 | char *msg |
---|
| 84 | PREINIT: |
---|
| 85 | int i; |
---|
| 86 | CODE: |
---|
| 87 | i = owl_zwrite_create_and_send_from_line(cmd, msg); |
---|
| 88 | |
---|
| 89 | char * |
---|
| 90 | ztext_stylestrip(ztext) |
---|
| 91 | char *ztext |
---|
| 92 | PREINIT: |
---|
| 93 | char *rv = NULL; |
---|
| 94 | CODE: |
---|
[1fd0b25] | 95 | rv = owl_function_ztext_stylestrip(ztext); |
---|
[e1c4636] | 96 | RETVAL = rv; |
---|
| 97 | OUTPUT: |
---|
| 98 | RETVAL |
---|
| 99 | CLEANUP: |
---|
| 100 | if (rv) owl_free(rv); |
---|
| 101 | |
---|
[acb13bb] | 102 | char * |
---|
| 103 | zephyr_getsubs() |
---|
| 104 | PREINIT: |
---|
| 105 | char *rv = NULL; |
---|
| 106 | CODE: |
---|
| 107 | rv = owl_zephyr_getsubs(); |
---|
| 108 | RETVAL = rv; |
---|
| 109 | OUTPUT: |
---|
| 110 | RETVAL |
---|
| 111 | CLEANUP: |
---|
| 112 | if (rv) owl_free(rv); |
---|
| 113 | |
---|
[6922edd] | 114 | void |
---|
| 115 | new_command_internal(name, func, summary, usage, description) |
---|
| 116 | char *name |
---|
| 117 | SV *func |
---|
| 118 | char *summary |
---|
| 119 | char *usage |
---|
| 120 | char *description |
---|
| 121 | PREINIT: |
---|
| 122 | owl_cmd cmd; |
---|
| 123 | CODE: |
---|
[db8b00b] | 124 | { |
---|
| 125 | if(!SV_IS_CODEREF(func)) { |
---|
| 126 | croak("Command function must be a coderef!"); |
---|
| 127 | } |
---|
[6922edd] | 128 | SvREFCNT_inc(func); |
---|
| 129 | cmd.name = name; |
---|
| 130 | cmd.cmd_perl = func; |
---|
| 131 | cmd.summary = summary; |
---|
| 132 | cmd.usage = usage; |
---|
| 133 | cmd.description = description; |
---|
| 134 | cmd.validctx = OWL_CTX_ANY; |
---|
| 135 | cmd.cmd_aliased_to = NULL; |
---|
| 136 | cmd.cmd_args_fn = NULL; |
---|
| 137 | cmd.cmd_v_fn = NULL; |
---|
| 138 | cmd.cmd_i_fn = NULL; |
---|
| 139 | cmd.cmd_ctxargs_fn = NULL; |
---|
| 140 | cmd.cmd_ctxv_fn = NULL; |
---|
| 141 | cmd.cmd_ctxi_fn = NULL; |
---|
| 142 | owl_cmddict_add_cmd(owl_global_get_cmddict(&g), &cmd); |
---|
[db8b00b] | 143 | } |
---|
[dd16bdd] | 144 | |
---|
[1b6b2f3] | 145 | void queue_message(msg) |
---|
[dd16bdd] | 146 | SV *msg |
---|
| 147 | PREINIT: |
---|
| 148 | owl_message *m; |
---|
| 149 | CODE: |
---|
[1b6b2f3] | 150 | { |
---|
[dd16bdd] | 151 | if(!SvROK(msg) || SvTYPE(SvRV(msg)) != SVt_PVHV) { |
---|
[3066d23] | 152 | croak("Usage: BarnOwl::queue_message($message)"); |
---|
[dd16bdd] | 153 | } |
---|
[17eed9c] | 154 | |
---|
[30678ae] | 155 | m = owl_perlconfig_hashref2message(msg); |
---|
[dd16bdd] | 156 | |
---|
| 157 | owl_global_messagequeue_addmsg(&g, m); |
---|
[1b6b2f3] | 158 | } |
---|
[db8b00b] | 159 | |
---|
[1c2e0b3] | 160 | void admin_message(header, body) |
---|
| 161 | char *header |
---|
| 162 | char *body |
---|
| 163 | CODE: |
---|
| 164 | { |
---|
| 165 | owl_function_adminmsg(header, body); |
---|
| 166 | } |
---|
| 167 | |
---|
[db8b00b] | 168 | void start_question(line, callback) |
---|
| 169 | char *line |
---|
| 170 | SV *callback |
---|
| 171 | PREINIT: |
---|
| 172 | CODE: |
---|
| 173 | { |
---|
| 174 | if(!SV_IS_CODEREF(callback)) |
---|
| 175 | croak("Callback must be a subref"); |
---|
| 176 | |
---|
| 177 | owl_function_start_question(line); |
---|
| 178 | |
---|
| 179 | SvREFCNT_inc(callback); |
---|
| 180 | owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); |
---|
| 181 | owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | void start_password(line, callback) |
---|
| 185 | char *line |
---|
| 186 | SV *callback |
---|
| 187 | PREINIT: |
---|
| 188 | CODE: |
---|
| 189 | { |
---|
| 190 | if(!SV_IS_CODEREF(callback)) |
---|
| 191 | croak("Callback must be a subref"); |
---|
| 192 | |
---|
| 193 | owl_function_start_password(line); |
---|
| 194 | |
---|
| 195 | SvREFCNT_inc(callback); |
---|
| 196 | owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); |
---|
| 197 | owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); |
---|
| 198 | } |
---|
| 199 | |
---|
| 200 | void start_edit_win(line, callback) |
---|
| 201 | char *line |
---|
| 202 | SV *callback |
---|
| 203 | PREINIT: |
---|
| 204 | owl_editwin * e; |
---|
| 205 | char buff[1024]; |
---|
| 206 | CODE: |
---|
| 207 | { |
---|
| 208 | if(!SV_IS_CODEREF(callback)) |
---|
| 209 | croak("Callback must be a subref"); |
---|
| 210 | |
---|
| 211 | e = owl_global_get_typwin(&g); |
---|
| 212 | owl_editwin_new_style(e, OWL_EDITWIN_STYLE_MULTILINE, |
---|
| 213 | owl_global_get_msg_history(&g)); |
---|
| 214 | owl_editwin_clear(e); |
---|
| 215 | owl_editwin_set_dotsend(e); |
---|
| 216 | snprintf(buff, 1023, "----> %s\n", line); |
---|
| 217 | owl_editwin_set_locktext(e, buff); |
---|
| 218 | |
---|
| 219 | owl_global_set_typwin_active(&g); |
---|
| 220 | |
---|
| 221 | SvREFCNT_inc(callback); |
---|
| 222 | owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); |
---|
| 223 | owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); |
---|
| 224 | } |
---|
[6b3f797] | 225 | |
---|
| 226 | |
---|
| 227 | char * |
---|
| 228 | get_data_dir () |
---|
| 229 | CODE: |
---|
[b363d83] | 230 | RETVAL = (char *) owl_get_datadir(); |
---|
[6b3f797] | 231 | OUTPUT: |
---|
| 232 | RETVAL |
---|
[b6a253c] | 233 | |
---|
[b363d83] | 234 | char * |
---|
| 235 | get_config_dir () |
---|
| 236 | CODE: |
---|
| 237 | RETVAL = (char *) owl_global_get_confdir(&g); |
---|
| 238 | OUTPUT: |
---|
| 239 | RETVAL |
---|
| 240 | |
---|
[b6a253c] | 241 | void |
---|
| 242 | popless_text(text) |
---|
| 243 | char *text |
---|
| 244 | CODE: |
---|
| 245 | { |
---|
| 246 | owl_function_popless_text(text); |
---|
| 247 | } |
---|
| 248 | |
---|
| 249 | void |
---|
| 250 | popless_ztext(text) |
---|
| 251 | char *text |
---|
| 252 | CODE: |
---|
| 253 | { |
---|
| 254 | owl_fmtext fm; |
---|
| 255 | owl_fmtext_init_null(&fm); |
---|
| 256 | owl_fmtext_append_ztext(&fm, text); |
---|
| 257 | owl_function_popless_fmtext(&fm); |
---|
| 258 | owl_fmtext_free(&fm); |
---|
| 259 | } |
---|
[0ff2528] | 260 | |
---|
| 261 | void |
---|
| 262 | error(text) |
---|
| 263 | char *text |
---|
| 264 | CODE: |
---|
| 265 | { |
---|
| 266 | owl_function_error("%s", text); |
---|
| 267 | } |
---|
[b6c067a] | 268 | |
---|
| 269 | void |
---|
[b67ab6b] | 270 | create_style(name, object) |
---|
[b6c067a] | 271 | char *name |
---|
[864ed35] | 272 | SV *object |
---|
[b6c067a] | 273 | PREINIT: |
---|
| 274 | owl_style *s; |
---|
| 275 | CODE: |
---|
| 276 | { |
---|
| 277 | s = owl_malloc(sizeof(owl_style)); |
---|
[864ed35] | 278 | owl_style_create_perl(s, name, object); |
---|
[b6c067a] | 279 | owl_global_add_style(&g, s); |
---|
| 280 | } |
---|
[c2c5c77] | 281 | |
---|
| 282 | int |
---|
| 283 | getnumcolors() |
---|
| 284 | CODE: |
---|
| 285 | RETVAL = owl_function_get_color_count(); |
---|
| 286 | OUTPUT: |
---|
| 287 | RETVAL |
---|
| 288 | |
---|
| 289 | void |
---|
| 290 | _remove_filter(filterName) |
---|
| 291 | char *filterName |
---|
| 292 | CODE: |
---|
| 293 | { |
---|
| 294 | /* Don't delete the current view, or the 'all' filter */ |
---|
| 295 | if (strcmp(filterName, owl_view_get_filtname(owl_global_get_current_view(&g))) |
---|
| 296 | && strcmp(filterName, "all")) { |
---|
| 297 | owl_global_remove_filter(&g,filterName); |
---|
| 298 | } |
---|
| 299 | } |
---|
[f6b319c] | 300 | |
---|
| 301 | char * |
---|
| 302 | wordwrap(in, cols) |
---|
| 303 | char *in |
---|
| 304 | int cols |
---|
| 305 | PREINIT: |
---|
| 306 | char *rv = NULL; |
---|
| 307 | CODE: |
---|
[a695a68] | 308 | rv = owl_text_wordwrap(in, cols); |
---|
[f6b319c] | 309 | RETVAL = rv; |
---|
| 310 | OUTPUT: |
---|
| 311 | RETVAL |
---|
| 312 | CLEANUP: |
---|
| 313 | if (rv) owl_free(rv); |
---|
[a695a68] | 314 | |
---|
| 315 | void |
---|
| 316 | new_variable_string_internal(name, ival, summ, desc) |
---|
| 317 | char * name |
---|
| 318 | char * ival |
---|
| 319 | char * summ |
---|
| 320 | char * desc |
---|
| 321 | CODE: |
---|
| 322 | owl_variable_dict_newvar_string(owl_global_get_vardict(&g), |
---|
| 323 | name, |
---|
| 324 | summ, |
---|
| 325 | desc, |
---|
| 326 | ival); |
---|
| 327 | |
---|
| 328 | void |
---|
| 329 | new_variable_int_internal(name, ival, summ, desc) |
---|
| 330 | char * name |
---|
| 331 | int ival |
---|
| 332 | char * summ |
---|
| 333 | char * desc |
---|
| 334 | CODE: |
---|
| 335 | owl_variable_dict_newvar_int(owl_global_get_vardict(&g), |
---|
| 336 | name, |
---|
| 337 | summ, |
---|
| 338 | desc, |
---|
| 339 | ival); |
---|
| 340 | |
---|
| 341 | void |
---|
| 342 | new_variable_bool_internal(name, ival, summ, desc) |
---|
| 343 | char * name |
---|
| 344 | int ival |
---|
| 345 | char * summ |
---|
| 346 | char * desc |
---|
| 347 | CODE: |
---|
| 348 | owl_variable_dict_newvar_bool(owl_global_get_vardict(&g), |
---|
| 349 | name, |
---|
| 350 | summ, |
---|
| 351 | desc, |
---|
| 352 | ival); |
---|
[9c7a701] | 353 | |
---|
| 354 | void |
---|
| 355 | add_dispatch(fd, cb) |
---|
| 356 | int fd |
---|
| 357 | SV * cb |
---|
| 358 | CODE: |
---|
| 359 | SvREFCNT_inc(cb); |
---|
| 360 | owl_select_add_perl_dispatch(fd, cb); |
---|
| 361 | |
---|
| 362 | void |
---|
| 363 | remove_dispatch(fd) |
---|
| 364 | int fd |
---|
| 365 | CODE: |
---|
| 366 | owl_select_remove_perl_dispatch(fd); |
---|