[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 | |
---|
[6922edd] | 102 | void |
---|
| 103 | new_command_internal(name, func, summary, usage, description) |
---|
| 104 | char *name |
---|
| 105 | SV *func |
---|
| 106 | char *summary |
---|
| 107 | char *usage |
---|
| 108 | char *description |
---|
| 109 | PREINIT: |
---|
| 110 | owl_cmd cmd; |
---|
| 111 | CODE: |
---|
[db8b00b] | 112 | { |
---|
| 113 | if(!SV_IS_CODEREF(func)) { |
---|
| 114 | croak("Command function must be a coderef!"); |
---|
| 115 | } |
---|
[6922edd] | 116 | SvREFCNT_inc(func); |
---|
| 117 | cmd.name = name; |
---|
| 118 | cmd.cmd_perl = func; |
---|
| 119 | cmd.summary = summary; |
---|
| 120 | cmd.usage = usage; |
---|
| 121 | cmd.description = description; |
---|
| 122 | cmd.validctx = OWL_CTX_ANY; |
---|
| 123 | cmd.cmd_aliased_to = NULL; |
---|
| 124 | cmd.cmd_args_fn = NULL; |
---|
| 125 | cmd.cmd_v_fn = NULL; |
---|
| 126 | cmd.cmd_i_fn = NULL; |
---|
| 127 | cmd.cmd_ctxargs_fn = NULL; |
---|
| 128 | cmd.cmd_ctxv_fn = NULL; |
---|
| 129 | cmd.cmd_ctxi_fn = NULL; |
---|
| 130 | owl_cmddict_add_cmd(owl_global_get_cmddict(&g), &cmd); |
---|
[db8b00b] | 131 | } |
---|
[dd16bdd] | 132 | |
---|
[1b6b2f3] | 133 | void queue_message(msg) |
---|
[dd16bdd] | 134 | SV *msg |
---|
| 135 | PREINIT: |
---|
| 136 | owl_message *m; |
---|
| 137 | CODE: |
---|
[1b6b2f3] | 138 | { |
---|
[dd16bdd] | 139 | if(!SvROK(msg) || SvTYPE(SvRV(msg)) != SVt_PVHV) { |
---|
[3066d23] | 140 | croak("Usage: BarnOwl::queue_message($message)"); |
---|
[dd16bdd] | 141 | } |
---|
[17eed9c] | 142 | |
---|
[30678ae] | 143 | m = owl_perlconfig_hashref2message(msg); |
---|
[dd16bdd] | 144 | |
---|
| 145 | owl_global_messagequeue_addmsg(&g, m); |
---|
[1b6b2f3] | 146 | } |
---|
[db8b00b] | 147 | |
---|
[1c2e0b3] | 148 | void admin_message(header, body) |
---|
| 149 | char *header |
---|
| 150 | char *body |
---|
| 151 | CODE: |
---|
| 152 | { |
---|
| 153 | owl_function_adminmsg(header, body); |
---|
| 154 | } |
---|
| 155 | |
---|
[db8b00b] | 156 | void start_question(line, callback) |
---|
| 157 | char *line |
---|
| 158 | SV *callback |
---|
| 159 | PREINIT: |
---|
| 160 | CODE: |
---|
| 161 | { |
---|
| 162 | if(!SV_IS_CODEREF(callback)) |
---|
| 163 | croak("Callback must be a subref"); |
---|
| 164 | |
---|
| 165 | owl_function_start_question(line); |
---|
| 166 | |
---|
| 167 | SvREFCNT_inc(callback); |
---|
| 168 | owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); |
---|
| 169 | owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | void start_password(line, callback) |
---|
| 173 | char *line |
---|
| 174 | SV *callback |
---|
| 175 | PREINIT: |
---|
| 176 | CODE: |
---|
| 177 | { |
---|
| 178 | if(!SV_IS_CODEREF(callback)) |
---|
| 179 | croak("Callback must be a subref"); |
---|
| 180 | |
---|
| 181 | owl_function_start_password(line); |
---|
| 182 | |
---|
| 183 | SvREFCNT_inc(callback); |
---|
| 184 | owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); |
---|
| 185 | owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | void start_edit_win(line, callback) |
---|
| 189 | char *line |
---|
| 190 | SV *callback |
---|
| 191 | PREINIT: |
---|
| 192 | owl_editwin * e; |
---|
| 193 | char buff[1024]; |
---|
| 194 | CODE: |
---|
| 195 | { |
---|
| 196 | if(!SV_IS_CODEREF(callback)) |
---|
| 197 | croak("Callback must be a subref"); |
---|
| 198 | |
---|
| 199 | e = owl_global_get_typwin(&g); |
---|
| 200 | owl_editwin_new_style(e, OWL_EDITWIN_STYLE_MULTILINE, |
---|
| 201 | owl_global_get_msg_history(&g)); |
---|
| 202 | owl_editwin_clear(e); |
---|
| 203 | owl_editwin_set_dotsend(e); |
---|
| 204 | snprintf(buff, 1023, "----> %s\n", line); |
---|
| 205 | owl_editwin_set_locktext(e, buff); |
---|
| 206 | |
---|
| 207 | owl_global_set_typwin_active(&g); |
---|
| 208 | |
---|
| 209 | SvREFCNT_inc(callback); |
---|
| 210 | owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); |
---|
| 211 | owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); |
---|
| 212 | } |
---|
[6b3f797] | 213 | |
---|
| 214 | |
---|
| 215 | char * |
---|
| 216 | get_data_dir () |
---|
| 217 | CODE: |
---|
[b363d83] | 218 | RETVAL = (char *) owl_get_datadir(); |
---|
[6b3f797] | 219 | OUTPUT: |
---|
| 220 | RETVAL |
---|
[b6a253c] | 221 | |
---|
[b363d83] | 222 | char * |
---|
| 223 | get_config_dir () |
---|
| 224 | CODE: |
---|
| 225 | RETVAL = (char *) owl_global_get_confdir(&g); |
---|
| 226 | OUTPUT: |
---|
| 227 | RETVAL |
---|
| 228 | |
---|
[b6a253c] | 229 | void |
---|
| 230 | popless_text(text) |
---|
| 231 | char *text |
---|
| 232 | CODE: |
---|
| 233 | { |
---|
| 234 | owl_function_popless_text(text); |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | void |
---|
| 238 | popless_ztext(text) |
---|
| 239 | char *text |
---|
| 240 | CODE: |
---|
| 241 | { |
---|
| 242 | owl_fmtext fm; |
---|
| 243 | owl_fmtext_init_null(&fm); |
---|
| 244 | owl_fmtext_append_ztext(&fm, text); |
---|
| 245 | owl_function_popless_fmtext(&fm); |
---|
| 246 | owl_fmtext_free(&fm); |
---|
| 247 | } |
---|
[0ff2528] | 248 | |
---|
| 249 | void |
---|
| 250 | error(text) |
---|
| 251 | char *text |
---|
| 252 | CODE: |
---|
| 253 | { |
---|
| 254 | owl_function_error("%s", text); |
---|
| 255 | } |
---|
[b6c067a] | 256 | |
---|
| 257 | void |
---|
[864ed35] | 258 | _create_style(name, object) |
---|
[b6c067a] | 259 | char *name |
---|
[864ed35] | 260 | SV *object |
---|
[b6c067a] | 261 | PREINIT: |
---|
| 262 | /* This is to allow us to bootstrap the default style before the |
---|
| 263 | command architecture has been initialized */ |
---|
| 264 | owl_style *s; |
---|
| 265 | CODE: |
---|
| 266 | { |
---|
| 267 | s = owl_malloc(sizeof(owl_style)); |
---|
[864ed35] | 268 | owl_style_create_perl(s, name, object); |
---|
[b6c067a] | 269 | owl_global_add_style(&g, s); |
---|
| 270 | } |
---|
[c2c5c77] | 271 | |
---|
| 272 | int |
---|
| 273 | getnumcolors() |
---|
| 274 | CODE: |
---|
| 275 | RETVAL = owl_function_get_color_count(); |
---|
| 276 | OUTPUT: |
---|
| 277 | RETVAL |
---|
| 278 | |
---|
| 279 | void |
---|
| 280 | _remove_filter(filterName) |
---|
| 281 | char *filterName |
---|
| 282 | CODE: |
---|
| 283 | { |
---|
| 284 | /* Don't delete the current view, or the 'all' filter */ |
---|
| 285 | if (strcmp(filterName, owl_view_get_filtname(owl_global_get_current_view(&g))) |
---|
| 286 | && strcmp(filterName, "all")) { |
---|
| 287 | owl_global_remove_filter(&g,filterName); |
---|
| 288 | } |
---|
| 289 | } |
---|
[f6b319c] | 290 | |
---|
| 291 | char * |
---|
| 292 | wordwrap(in, cols) |
---|
| 293 | char *in |
---|
| 294 | int cols |
---|
| 295 | PREINIT: |
---|
| 296 | char *rv = NULL; |
---|
| 297 | CODE: |
---|
[a695a68] | 298 | rv = owl_text_wordwrap(in, cols); |
---|
[f6b319c] | 299 | RETVAL = rv; |
---|
| 300 | OUTPUT: |
---|
| 301 | RETVAL |
---|
| 302 | CLEANUP: |
---|
| 303 | if (rv) owl_free(rv); |
---|
[a695a68] | 304 | |
---|
| 305 | void |
---|
| 306 | new_variable_string_internal(name, ival, summ, desc) |
---|
| 307 | char * name |
---|
| 308 | char * ival |
---|
| 309 | char * summ |
---|
| 310 | char * desc |
---|
| 311 | CODE: |
---|
| 312 | owl_variable_dict_newvar_string(owl_global_get_vardict(&g), |
---|
| 313 | name, |
---|
| 314 | summ, |
---|
| 315 | desc, |
---|
| 316 | ival); |
---|
| 317 | |
---|
| 318 | void |
---|
| 319 | new_variable_int_internal(name, ival, summ, desc) |
---|
| 320 | char * name |
---|
| 321 | int ival |
---|
| 322 | char * summ |
---|
| 323 | char * desc |
---|
| 324 | CODE: |
---|
| 325 | owl_variable_dict_newvar_int(owl_global_get_vardict(&g), |
---|
| 326 | name, |
---|
| 327 | summ, |
---|
| 328 | desc, |
---|
| 329 | ival); |
---|
| 330 | |
---|
| 331 | void |
---|
| 332 | new_variable_bool_internal(name, ival, summ, desc) |
---|
| 333 | char * name |
---|
| 334 | int ival |
---|
| 335 | char * summ |
---|
| 336 | char * desc |
---|
| 337 | CODE: |
---|
| 338 | owl_variable_dict_newvar_bool(owl_global_get_vardict(&g), |
---|
| 339 | name, |
---|
| 340 | summ, |
---|
| 341 | desc, |
---|
| 342 | ival); |
---|
[9c7a701] | 343 | |
---|
| 344 | void |
---|
| 345 | add_dispatch(fd, cb) |
---|
| 346 | int fd |
---|
| 347 | SV * cb |
---|
| 348 | CODE: |
---|
| 349 | SvREFCNT_inc(cb); |
---|
| 350 | owl_select_add_perl_dispatch(fd, cb); |
---|
| 351 | |
---|
| 352 | void |
---|
| 353 | remove_dispatch(fd) |
---|
| 354 | int fd |
---|
| 355 | CODE: |
---|
| 356 | owl_select_remove_perl_dispatch(fd); |
---|