[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 |
---|
[b67ab6b] | 258 | create_style(name, object) |
---|
[b6c067a] | 259 | char *name |
---|
[864ed35] | 260 | SV *object |
---|
[b6c067a] | 261 | PREINIT: |
---|
| 262 | owl_style *s; |
---|
| 263 | CODE: |
---|
| 264 | { |
---|
| 265 | s = owl_malloc(sizeof(owl_style)); |
---|
[864ed35] | 266 | owl_style_create_perl(s, name, object); |
---|
[b6c067a] | 267 | owl_global_add_style(&g, s); |
---|
| 268 | } |
---|
[c2c5c77] | 269 | |
---|
| 270 | int |
---|
| 271 | getnumcolors() |
---|
| 272 | CODE: |
---|
| 273 | RETVAL = owl_function_get_color_count(); |
---|
| 274 | OUTPUT: |
---|
| 275 | RETVAL |
---|
| 276 | |
---|
| 277 | void |
---|
| 278 | _remove_filter(filterName) |
---|
| 279 | char *filterName |
---|
| 280 | CODE: |
---|
| 281 | { |
---|
| 282 | /* Don't delete the current view, or the 'all' filter */ |
---|
| 283 | if (strcmp(filterName, owl_view_get_filtname(owl_global_get_current_view(&g))) |
---|
| 284 | && strcmp(filterName, "all")) { |
---|
| 285 | owl_global_remove_filter(&g,filterName); |
---|
| 286 | } |
---|
| 287 | } |
---|
[f6b319c] | 288 | |
---|
| 289 | char * |
---|
| 290 | wordwrap(in, cols) |
---|
| 291 | char *in |
---|
| 292 | int cols |
---|
| 293 | PREINIT: |
---|
| 294 | char *rv = NULL; |
---|
| 295 | CODE: |
---|
[a695a68] | 296 | rv = owl_text_wordwrap(in, cols); |
---|
[f6b319c] | 297 | RETVAL = rv; |
---|
| 298 | OUTPUT: |
---|
| 299 | RETVAL |
---|
| 300 | CLEANUP: |
---|
| 301 | if (rv) owl_free(rv); |
---|
[a695a68] | 302 | |
---|
| 303 | void |
---|
| 304 | new_variable_string_internal(name, ival, summ, desc) |
---|
| 305 | char * name |
---|
| 306 | char * ival |
---|
| 307 | char * summ |
---|
| 308 | char * desc |
---|
| 309 | CODE: |
---|
| 310 | owl_variable_dict_newvar_string(owl_global_get_vardict(&g), |
---|
| 311 | name, |
---|
| 312 | summ, |
---|
| 313 | desc, |
---|
| 314 | ival); |
---|
| 315 | |
---|
| 316 | void |
---|
| 317 | new_variable_int_internal(name, ival, summ, desc) |
---|
| 318 | char * name |
---|
| 319 | int ival |
---|
| 320 | char * summ |
---|
| 321 | char * desc |
---|
| 322 | CODE: |
---|
| 323 | owl_variable_dict_newvar_int(owl_global_get_vardict(&g), |
---|
| 324 | name, |
---|
| 325 | summ, |
---|
| 326 | desc, |
---|
| 327 | ival); |
---|
| 328 | |
---|
| 329 | void |
---|
| 330 | new_variable_bool_internal(name, ival, summ, desc) |
---|
| 331 | char * name |
---|
| 332 | int ival |
---|
| 333 | char * summ |
---|
| 334 | char * desc |
---|
| 335 | CODE: |
---|
| 336 | owl_variable_dict_newvar_bool(owl_global_get_vardict(&g), |
---|
| 337 | name, |
---|
| 338 | summ, |
---|
| 339 | desc, |
---|
| 340 | ival); |
---|
[9c7a701] | 341 | |
---|
| 342 | void |
---|
| 343 | add_dispatch(fd, cb) |
---|
| 344 | int fd |
---|
| 345 | SV * cb |
---|
| 346 | CODE: |
---|
| 347 | SvREFCNT_inc(cb); |
---|
| 348 | owl_select_add_perl_dispatch(fd, cb); |
---|
| 349 | |
---|
| 350 | void |
---|
| 351 | remove_dispatch(fd) |
---|
| 352 | int fd |
---|
| 353 | CODE: |
---|
| 354 | owl_select_remove_perl_dispatch(fd); |
---|