[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 | |
---|
[8ee73f8d] | 15 | MODULE = owl PACKAGE = owl |
---|
| 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 |
---|
| 41 | |
---|
| 42 | char * |
---|
| 43 | zephyr_getrealm() |
---|
| 44 | CODE: |
---|
[8a54409] | 45 | RETVAL = owl_zephyr_get_realm(); |
---|
[f1e629d] | 46 | OUTPUT: |
---|
| 47 | RETVAL |
---|
| 48 | |
---|
| 49 | char * |
---|
| 50 | zephyr_getsender() |
---|
| 51 | CODE: |
---|
[8a54409] | 52 | RETVAL = owl_zephyr_get_sender(); |
---|
[f1e629d] | 53 | OUTPUT: |
---|
| 54 | RETVAL |
---|
| 55 | |
---|
[e1c4636] | 56 | void |
---|
[f1e629d] | 57 | zephyr_zwrite(cmd,msg) |
---|
[e1c4636] | 58 | char *cmd |
---|
| 59 | char *msg |
---|
| 60 | PREINIT: |
---|
| 61 | int i; |
---|
| 62 | CODE: |
---|
| 63 | i = owl_zwrite_create_and_send_from_line(cmd, msg); |
---|
| 64 | |
---|
| 65 | char * |
---|
| 66 | ztext_stylestrip(ztext) |
---|
| 67 | char *ztext |
---|
| 68 | PREINIT: |
---|
| 69 | char *rv = NULL; |
---|
| 70 | CODE: |
---|
[1fd0b25] | 71 | rv = owl_function_ztext_stylestrip(ztext); |
---|
[e1c4636] | 72 | RETVAL = rv; |
---|
| 73 | OUTPUT: |
---|
| 74 | RETVAL |
---|
| 75 | CLEANUP: |
---|
| 76 | if (rv) owl_free(rv); |
---|
| 77 | |
---|
[6922edd] | 78 | void |
---|
| 79 | new_command_internal(name, func, summary, usage, description) |
---|
| 80 | char *name |
---|
| 81 | SV *func |
---|
| 82 | char *summary |
---|
| 83 | char *usage |
---|
| 84 | char *description |
---|
| 85 | PREINIT: |
---|
| 86 | owl_cmd cmd; |
---|
| 87 | CODE: |
---|
[db8b00b] | 88 | { |
---|
| 89 | if(!SV_IS_CODEREF(func)) { |
---|
| 90 | croak("Command function must be a coderef!"); |
---|
| 91 | } |
---|
[6922edd] | 92 | SvREFCNT_inc(func); |
---|
| 93 | cmd.name = name; |
---|
| 94 | cmd.cmd_perl = func; |
---|
| 95 | cmd.summary = summary; |
---|
| 96 | cmd.usage = usage; |
---|
| 97 | cmd.description = description; |
---|
| 98 | cmd.validctx = OWL_CTX_ANY; |
---|
| 99 | cmd.cmd_aliased_to = NULL; |
---|
| 100 | cmd.cmd_args_fn = NULL; |
---|
| 101 | cmd.cmd_v_fn = NULL; |
---|
| 102 | cmd.cmd_i_fn = NULL; |
---|
| 103 | cmd.cmd_ctxargs_fn = NULL; |
---|
| 104 | cmd.cmd_ctxv_fn = NULL; |
---|
| 105 | cmd.cmd_ctxi_fn = NULL; |
---|
| 106 | owl_cmddict_add_cmd(owl_global_get_cmddict(&g), &cmd); |
---|
[db8b00b] | 107 | } |
---|
[dd16bdd] | 108 | |
---|
[1b6b2f3] | 109 | void queue_message(msg) |
---|
[dd16bdd] | 110 | SV *msg |
---|
| 111 | PREINIT: |
---|
| 112 | char * key; |
---|
| 113 | char * val; |
---|
| 114 | owl_message *m; |
---|
| 115 | HV * hash; |
---|
| 116 | HE * ent; |
---|
| 117 | I32 count; |
---|
| 118 | I32 len; |
---|
| 119 | CODE: |
---|
[1b6b2f3] | 120 | { |
---|
[dd16bdd] | 121 | if(!SvROK(msg) || SvTYPE(SvRV(msg)) != SVt_PVHV) { |
---|
| 122 | croak("Usage: owl::queue_message($message)"); |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | hash = (HV*)SvRV(msg); |
---|
| 126 | m = owl_malloc(sizeof(owl_message)); |
---|
| 127 | owl_message_init(m); |
---|
| 128 | |
---|
| 129 | count = hv_iterinit(hash); |
---|
| 130 | while((ent = hv_iternext(hash))) { |
---|
| 131 | key = hv_iterkey(ent, &len); |
---|
| 132 | val = SvPV_nolen(hv_iterval(hash, ent)); |
---|
| 133 | if(!strcmp(key, "type")) { |
---|
| 134 | owl_message_set_type(m, owl_message_parse_type(val)); |
---|
| 135 | } else if(!strcmp(key, "direction")) { |
---|
| 136 | owl_message_set_direction(m, owl_message_parse_direction(val)); |
---|
[3c9012b] | 137 | } else if(!strcmp(key, "isprivate")) { |
---|
| 138 | SV * v = hv_iterval(hash, ent); |
---|
| 139 | if(SvTRUE(v)) { |
---|
| 140 | owl_message_set_isprivate(m); |
---|
| 141 | } |
---|
[dd16bdd] | 142 | } else { |
---|
| 143 | owl_message_set_attribute(m, key, val); |
---|
| 144 | } |
---|
| 145 | } |
---|
[1b6b2f3] | 146 | if(owl_message_is_type_admin(m)) { |
---|
| 147 | if(!owl_message_get_attribute_value(m, "adminheader")) |
---|
| 148 | owl_message_set_attribute(m, "adminheader", ""); |
---|
| 149 | } |
---|
[dd16bdd] | 150 | |
---|
| 151 | owl_global_messagequeue_addmsg(&g, m); |
---|
[1b6b2f3] | 152 | } |
---|
[db8b00b] | 153 | |
---|
| 154 | void start_question(line, callback) |
---|
| 155 | char *line |
---|
| 156 | SV *callback |
---|
| 157 | PREINIT: |
---|
| 158 | CODE: |
---|
| 159 | { |
---|
| 160 | if(!SV_IS_CODEREF(callback)) |
---|
| 161 | croak("Callback must be a subref"); |
---|
| 162 | |
---|
| 163 | owl_function_start_question(line); |
---|
| 164 | |
---|
| 165 | SvREFCNT_inc(callback); |
---|
| 166 | owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); |
---|
| 167 | owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | void start_password(line, callback) |
---|
| 171 | char *line |
---|
| 172 | SV *callback |
---|
| 173 | PREINIT: |
---|
| 174 | CODE: |
---|
| 175 | { |
---|
| 176 | if(!SV_IS_CODEREF(callback)) |
---|
| 177 | croak("Callback must be a subref"); |
---|
| 178 | |
---|
| 179 | owl_function_start_password(line); |
---|
| 180 | |
---|
| 181 | SvREFCNT_inc(callback); |
---|
| 182 | owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); |
---|
| 183 | owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | void start_edit_win(line, callback) |
---|
| 187 | char *line |
---|
| 188 | SV *callback |
---|
| 189 | PREINIT: |
---|
| 190 | owl_editwin * e; |
---|
| 191 | char buff[1024]; |
---|
| 192 | CODE: |
---|
| 193 | { |
---|
| 194 | if(!SV_IS_CODEREF(callback)) |
---|
| 195 | croak("Callback must be a subref"); |
---|
| 196 | |
---|
| 197 | e = owl_global_get_typwin(&g); |
---|
| 198 | owl_editwin_new_style(e, OWL_EDITWIN_STYLE_MULTILINE, |
---|
| 199 | owl_global_get_msg_history(&g)); |
---|
| 200 | owl_editwin_clear(e); |
---|
| 201 | owl_editwin_set_dotsend(e); |
---|
| 202 | snprintf(buff, 1023, "----> %s\n", line); |
---|
| 203 | owl_editwin_set_locktext(e, buff); |
---|
| 204 | |
---|
| 205 | owl_global_set_typwin_active(&g); |
---|
| 206 | |
---|
| 207 | SvREFCNT_inc(callback); |
---|
| 208 | owl_editwin_set_cbdata(owl_global_get_typwin(&g), callback); |
---|
| 209 | owl_editwin_set_callback(owl_global_get_typwin(&g), owl_perlconfig_edit_callback); |
---|
| 210 | } |
---|
[6b3f797] | 211 | |
---|
| 212 | |
---|
| 213 | char * |
---|
| 214 | get_data_dir () |
---|
| 215 | CODE: |
---|
| 216 | RETVAL = (char *) DATADIR; |
---|
| 217 | OUTPUT: |
---|
| 218 | RETVAL |
---|
[b6a253c] | 219 | |
---|
| 220 | void |
---|
| 221 | popless_text(text) |
---|
| 222 | char *text |
---|
| 223 | CODE: |
---|
| 224 | { |
---|
| 225 | owl_function_popless_text(text); |
---|
| 226 | } |
---|
| 227 | |
---|
| 228 | void |
---|
| 229 | popless_ztext(text) |
---|
| 230 | char *text |
---|
| 231 | CODE: |
---|
| 232 | { |
---|
| 233 | owl_fmtext fm; |
---|
| 234 | owl_fmtext_init_null(&fm); |
---|
| 235 | owl_fmtext_append_ztext(&fm, text); |
---|
| 236 | owl_function_popless_fmtext(&fm); |
---|
| 237 | owl_fmtext_free(&fm); |
---|
| 238 | } |
---|