[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 |
---|
| 258 | _create_style(name, function, description) |
---|
| 259 | char *name |
---|
| 260 | char *function |
---|
| 261 | char *description |
---|
| 262 | PREINIT: |
---|
| 263 | /* This is to allow us to bootstrap the default style before the |
---|
| 264 | command architecture has been initialized */ |
---|
| 265 | owl_style *s; |
---|
| 266 | CODE: |
---|
| 267 | { |
---|
| 268 | s = owl_malloc(sizeof(owl_style)); |
---|
| 269 | owl_style_create_perl(s, name, function, description); |
---|
| 270 | owl_global_add_style(&g, s); |
---|
| 271 | } |
---|
[c2c5c77] | 272 | |
---|
| 273 | int |
---|
| 274 | getnumcolors() |
---|
| 275 | CODE: |
---|
| 276 | RETVAL = owl_function_get_color_count(); |
---|
| 277 | OUTPUT: |
---|
| 278 | RETVAL |
---|
| 279 | |
---|
| 280 | void |
---|
| 281 | _remove_filter(filterName) |
---|
| 282 | char *filterName |
---|
| 283 | CODE: |
---|
| 284 | { |
---|
| 285 | /* Don't delete the current view, or the 'all' filter */ |
---|
| 286 | if (strcmp(filterName, owl_view_get_filtname(owl_global_get_current_view(&g))) |
---|
| 287 | && strcmp(filterName, "all")) { |
---|
| 288 | owl_global_remove_filter(&g,filterName); |
---|
| 289 | } |
---|
| 290 | } |
---|
[f6b319c] | 291 | |
---|
| 292 | char * |
---|
| 293 | wordwrap(in, cols) |
---|
| 294 | char *in |
---|
| 295 | int cols |
---|
| 296 | PREINIT: |
---|
| 297 | char *rv = NULL; |
---|
| 298 | CODE: |
---|
[a695a68] | 299 | rv = owl_text_wordwrap(in, cols); |
---|
[f6b319c] | 300 | RETVAL = rv; |
---|
| 301 | OUTPUT: |
---|
| 302 | RETVAL |
---|
| 303 | CLEANUP: |
---|
| 304 | if (rv) owl_free(rv); |
---|
[a695a68] | 305 | |
---|
| 306 | void |
---|
| 307 | new_variable_string_internal(name, ival, summ, desc) |
---|
| 308 | char * name |
---|
| 309 | char * ival |
---|
| 310 | char * summ |
---|
| 311 | char * desc |
---|
| 312 | CODE: |
---|
| 313 | owl_variable_dict_newvar_string(owl_global_get_vardict(&g), |
---|
| 314 | name, |
---|
| 315 | summ, |
---|
| 316 | desc, |
---|
| 317 | ival); |
---|
| 318 | |
---|
| 319 | void |
---|
| 320 | new_variable_int_internal(name, ival, summ, desc) |
---|
| 321 | char * name |
---|
| 322 | int ival |
---|
| 323 | char * summ |
---|
| 324 | char * desc |
---|
| 325 | CODE: |
---|
| 326 | owl_variable_dict_newvar_int(owl_global_get_vardict(&g), |
---|
| 327 | name, |
---|
| 328 | summ, |
---|
| 329 | desc, |
---|
| 330 | ival); |
---|
| 331 | |
---|
| 332 | void |
---|
| 333 | new_variable_bool_internal(name, ival, summ, desc) |
---|
| 334 | char * name |
---|
| 335 | int ival |
---|
| 336 | char * summ |
---|
| 337 | char * desc |
---|
| 338 | CODE: |
---|
| 339 | owl_variable_dict_newvar_bool(owl_global_get_vardict(&g), |
---|
| 340 | name, |
---|
| 341 | summ, |
---|
| 342 | desc, |
---|
| 343 | ival); |
---|