[7d4fbcd] | 1 | #include <stdio.h> |
---|
| 2 | #include <stdlib.h> |
---|
| 3 | #include <unistd.h> |
---|
| 4 | #include <signal.h> |
---|
[789462a] | 5 | #include <netinet/in.h> |
---|
[7d4fbcd] | 6 | #include <string.h> |
---|
| 7 | #include <time.h> |
---|
[2adaf1d] | 8 | #include <sys/types.h> |
---|
| 9 | #include <sys/stat.h> |
---|
[8f44c6b] | 10 | #include <sys/wait.h> |
---|
| 11 | #include <errno.h> |
---|
[d09e5a1] | 12 | #include <signal.h> |
---|
[7d4fbcd] | 13 | #include "owl.h" |
---|
[d564c3d] | 14 | #include "filterproc.h" |
---|
[7d4fbcd] | 15 | |
---|
[6829afc] | 16 | CALLER_OWN char *owl_function_command(const char *cmdbuff) |
---|
[d54838d] | 17 | { |
---|
[7d4fbcd] | 18 | owl_function_debugmsg("executing command: %s", cmdbuff); |
---|
| 19 | return owl_cmddict_execute(owl_global_get_cmddict(&g), |
---|
| 20 | owl_global_get_context(&g), cmdbuff); |
---|
| 21 | } |
---|
| 22 | |
---|
[6829afc] | 23 | CALLER_OWN char *owl_function_command_argv(const char *const *argv, int argc) |
---|
[c4ba74d] | 24 | { |
---|
| 25 | return owl_cmddict_execute_argv(owl_global_get_cmddict(&g), |
---|
| 26 | owl_global_get_context(&g), |
---|
| 27 | argv, argc); |
---|
| 28 | } |
---|
| 29 | |
---|
[e19eb97] | 30 | void owl_function_command_norv(const char *cmdbuff) |
---|
[d54838d] | 31 | { |
---|
[7d4fbcd] | 32 | char *rv; |
---|
[4b464a4] | 33 | rv=owl_function_command(cmdbuff); |
---|
[3b8a563] | 34 | g_free(rv); |
---|
[7d4fbcd] | 35 | } |
---|
| 36 | |
---|
[e19eb97] | 37 | void owl_function_command_alias(const char *alias_from, const char *alias_to) |
---|
[d54838d] | 38 | { |
---|
[7d4fbcd] | 39 | owl_cmddict_add_alias(owl_global_get_cmddict(&g), alias_from, alias_to); |
---|
| 40 | } |
---|
| 41 | |
---|
[0a0fb74] | 42 | const owl_cmd *owl_function_get_cmd(const char *name) |
---|
[d54838d] | 43 | { |
---|
[7d4fbcd] | 44 | return owl_cmddict_find(owl_global_get_cmddict(&g), name); |
---|
| 45 | } |
---|
| 46 | |
---|
[c79a047] | 47 | void owl_function_show_commands(void) |
---|
[d54838d] | 48 | { |
---|
[ce68f23] | 49 | GPtrArray *l; |
---|
[7d4fbcd] | 50 | owl_fmtext fm; |
---|
| 51 | |
---|
| 52 | owl_fmtext_init_null(&fm); |
---|
| 53 | owl_fmtext_append_bold(&fm, "Commands: "); |
---|
| 54 | owl_fmtext_append_normal(&fm, "(use 'show command <name>' for details)\n"); |
---|
[ce68f23] | 55 | l = owl_cmddict_get_names(owl_global_get_cmddict(&g)); |
---|
| 56 | owl_fmtext_append_list(&fm, l, "\n", owl_function_cmd_describe); |
---|
[7d4fbcd] | 57 | owl_fmtext_append_normal(&fm, "\n"); |
---|
| 58 | owl_function_popless_fmtext(&fm); |
---|
[ce68f23] | 59 | owl_ptr_array_free(l, g_free); |
---|
[7ab0020] | 60 | owl_fmtext_cleanup(&fm); |
---|
[7d4fbcd] | 61 | } |
---|
| 62 | |
---|
[e19eb97] | 63 | void owl_function_show_view(const char *viewname) |
---|
[ef56a67] | 64 | { |
---|
[9e5c9f3] | 65 | const owl_view *v; |
---|
[ef56a67] | 66 | owl_fmtext fm; |
---|
| 67 | |
---|
| 68 | /* we only have the one view right now */ |
---|
| 69 | v=owl_global_get_current_view(&g); |
---|
| 70 | if (viewname && strcmp(viewname, owl_view_get_name(v))) { |
---|
[ec6ff52] | 71 | owl_function_error("No view named '%s'", viewname); |
---|
[ef56a67] | 72 | return; |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | owl_fmtext_init_null(&fm); |
---|
| 76 | owl_view_to_fmtext(v, &fm); |
---|
| 77 | owl_function_popless_fmtext(&fm); |
---|
[7ab0020] | 78 | owl_fmtext_cleanup(&fm); |
---|
[ef56a67] | 79 | } |
---|
| 80 | |
---|
[c79a047] | 81 | void owl_function_show_styles(void) { |
---|
[ce68f23] | 82 | GPtrArray *l; |
---|
[f1e629d] | 83 | owl_fmtext fm; |
---|
| 84 | |
---|
| 85 | owl_fmtext_init_null(&fm); |
---|
| 86 | owl_fmtext_append_bold(&fm, "Styles:\n"); |
---|
[ce68f23] | 87 | l = owl_global_get_style_names(&g); |
---|
| 88 | owl_fmtext_append_list(&fm, l, "\n", owl_function_style_describe); |
---|
[f1e629d] | 89 | owl_fmtext_append_normal(&fm, "\n"); |
---|
| 90 | owl_function_popless_fmtext(&fm); |
---|
[ce68f23] | 91 | owl_ptr_array_free(l, g_free); |
---|
[7ab0020] | 92 | owl_fmtext_cleanup(&fm); |
---|
[f1e629d] | 93 | } |
---|
| 94 | |
---|
[6829afc] | 95 | CALLER_OWN char *owl_function_style_describe(const char *name) |
---|
[d427f08] | 96 | { |
---|
[e19eb97] | 97 | const char *desc; |
---|
[65b2173] | 98 | char *s; |
---|
[1fdab04] | 99 | const owl_style *style; |
---|
[f1e629d] | 100 | style = owl_global_get_style_by_name(&g, name); |
---|
| 101 | if (style) { |
---|
| 102 | desc = owl_style_get_description(style); |
---|
| 103 | } else { |
---|
| 104 | desc = "???"; |
---|
| 105 | } |
---|
[3472845] | 106 | s = g_strdup_printf("%-20s - %s%s", name, |
---|
| 107 | 0 == owl_style_validate(style) ? "" : "[INVALID] ", |
---|
| 108 | desc); |
---|
[f1e629d] | 109 | return s; |
---|
| 110 | } |
---|
[ef56a67] | 111 | |
---|
[6829afc] | 112 | CALLER_OWN char *owl_function_cmd_describe(const char *name) |
---|
[d54838d] | 113 | { |
---|
[0a0fb74] | 114 | const owl_cmd *cmd = owl_cmddict_find(owl_global_get_cmddict(&g), name); |
---|
[7d4fbcd] | 115 | if (cmd) return owl_cmd_describe(cmd); |
---|
| 116 | else return(NULL); |
---|
| 117 | } |
---|
| 118 | |
---|
[e19eb97] | 119 | void owl_function_show_command(const char *name) |
---|
[d54838d] | 120 | { |
---|
[7d4fbcd] | 121 | owl_function_help_for_command(name); |
---|
| 122 | } |
---|
| 123 | |
---|
[c79a047] | 124 | void owl_function_show_license(void) |
---|
[debb15d] | 125 | { |
---|
[e19eb97] | 126 | const char *text; |
---|
[debb15d] | 127 | |
---|
| 128 | text="" |
---|
[b8a3e00] | 129 | "BarnOwl version " OWL_VERSION_STRING "\n" |
---|
[b03c714] | 130 | "Copyright (c) 2006-2011 The BarnOwl Developers. All rights reserved.\n" |
---|
[debb15d] | 131 | "Copyright (c) 2004 James Kretchmar. All rights reserved.\n" |
---|
| 132 | "\n" |
---|
| 133 | "Redistribution and use in source and binary forms, with or without\n" |
---|
| 134 | "modification, are permitted provided that the following conditions are\n" |
---|
| 135 | "met:\n" |
---|
| 136 | "\n" |
---|
| 137 | " * Redistributions of source code must retain the above copyright\n" |
---|
| 138 | " notice, this list of conditions and the following disclaimer.\n" |
---|
| 139 | "\n" |
---|
| 140 | " * Redistributions in binary form must reproduce the above copyright\n" |
---|
| 141 | " notice, this list of conditions and the following disclaimer in\n" |
---|
| 142 | " the documentation and/or other materials provided with the\n" |
---|
| 143 | " distribution.\n" |
---|
| 144 | "\n" |
---|
| 145 | " * Redistributions in any form must be accompanied by information on\n" |
---|
| 146 | " how to obtain complete source code for the Owl software and any\n" |
---|
| 147 | " accompanying software that uses the Owl software. The source code\n" |
---|
| 148 | " must either be included in the distribution or be available for no\n" |
---|
| 149 | " more than the cost of distribution plus a nominal fee, and must be\n" |
---|
| 150 | " freely redistributable under reasonable conditions. For an\n" |
---|
| 151 | " executable file, complete source code means the source code for\n" |
---|
| 152 | " all modules it contains. It does not include source code for\n" |
---|
| 153 | " modules or files that typically accompany the major components of\n" |
---|
| 154 | " the operating system on which the executable file runs.\n" |
---|
| 155 | "\n" |
---|
| 156 | "THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\n" |
---|
| 157 | "IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n" |
---|
| 158 | "WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR\n" |
---|
| 159 | "NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE\n" |
---|
| 160 | "LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n" |
---|
| 161 | "CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n" |
---|
| 162 | "SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR\n" |
---|
| 163 | "BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n" |
---|
| 164 | "WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE\n" |
---|
| 165 | "OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN\n" |
---|
| 166 | "IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"; |
---|
| 167 | owl_function_popless_text(text); |
---|
| 168 | } |
---|
| 169 | |
---|
[c79a047] | 170 | void owl_function_show_quickstart(void) |
---|
[799b60e] | 171 | { |
---|
[e19eb97] | 172 | const char *message = |
---|
[799b60e] | 173 | "Move between messages with the arrow keys, and press 'r' to reply.\n" |
---|
| 174 | "For more info, press 'h' or visit http://barnowl.mit.edu/\n\n" |
---|
| 175 | #ifdef HAVE_LIBZEPHYR |
---|
| 176 | "@b(Zephyr:)\n" |
---|
| 177 | "To send a message to a user, type ':zwrite @b(username)'. You can also\n" |
---|
| 178 | "press 'z' and then type the username. To subscribe to a class, type\n" |
---|
| 179 | "':sub @b(class)', and then type ':zwrite -c @b(class)' to send.\n\n" |
---|
| 180 | #endif |
---|
| 181 | "@b(AIM:)\n" |
---|
| 182 | "Log in to AIM with ':aimlogin @b(screenname)'. Use ':aimwrite @b(screenname)',\n" |
---|
| 183 | "or 'a' and then the screen name, to send someone a message.\n\n" |
---|
| 184 | ; |
---|
| 185 | |
---|
| 186 | if (owl_perlconfig_is_function("BarnOwl::Hooks::_get_quickstart")) { |
---|
| 187 | char *perlquickstart = owl_perlconfig_execute("BarnOwl::Hooks::_get_quickstart()"); |
---|
| 188 | if (perlquickstart) { |
---|
[3472845] | 189 | char *result = g_strdup_printf("%s%s", message, perlquickstart); |
---|
[799b60e] | 190 | owl_function_adminmsg("BarnOwl Quickstart", result); |
---|
[ddbbcffa] | 191 | g_free(result); |
---|
| 192 | g_free(perlquickstart); |
---|
[799b60e] | 193 | return; |
---|
| 194 | } |
---|
| 195 | } |
---|
| 196 | owl_function_adminmsg("BarnOwl Quickstart", message); |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | |
---|
[15b34fd] | 200 | /* Create an admin message, append it to the global list of messages |
---|
| 201 | * and redisplay if necessary. |
---|
| 202 | */ |
---|
[e19eb97] | 203 | void owl_function_adminmsg(const char *header, const char *body) |
---|
[d54838d] | 204 | { |
---|
[7d4fbcd] | 205 | owl_message *m; |
---|
[4b464a4] | 206 | |
---|
[96828e4] | 207 | m=g_new(owl_message, 1); |
---|
[15b34fd] | 208 | owl_message_create_admin(m, header, body); |
---|
| 209 | |
---|
[8fec514] | 210 | /* add it to the global list and current view */ |
---|
[7d4fbcd] | 211 | owl_messagelist_append_element(owl_global_get_msglist(&g), m); |
---|
| 212 | owl_view_consider_message(owl_global_get_current_view(&g), m); |
---|
| 213 | |
---|
[15b34fd] | 214 | /* do followlast if necessary */ |
---|
| 215 | if (owl_global_should_followlast(&g)) owl_function_lastmsg_noredisplay(); |
---|
[7d4fbcd] | 216 | |
---|
[15b34fd] | 217 | /* redisplay etc. */ |
---|
[7d4fbcd] | 218 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 219 | } |
---|
| 220 | |
---|
[e5da3fe] | 221 | /* Queues outgoing zephyrs; if z sends to n people, queue n messages |
---|
| 222 | * (except in case of cc). If there are no recipients queues 1 |
---|
| 223 | * message. |
---|
[15b34fd] | 224 | */ |
---|
[e5da3fe] | 225 | void owl_function_add_outgoing_zephyrs(const owl_zwrite *z) |
---|
[d09e5a1] | 226 | { |
---|
[e5da3fe] | 227 | if (z->cc || owl_zwrite_get_numrecips(z) == 0) { |
---|
| 228 | /* create the message */ |
---|
| 229 | owl_message *m = g_new(owl_message, 1); |
---|
| 230 | owl_message_create_from_zwrite(m, z, owl_zwrite_get_message(z), 0); |
---|
[d09e5a1] | 231 | |
---|
[e5da3fe] | 232 | owl_global_messagequeue_addmsg(&g, m); |
---|
| 233 | } else { |
---|
| 234 | int i; |
---|
| 235 | for (i = 0; i < owl_zwrite_get_numrecips(z); i++) { |
---|
| 236 | /* create the message */ |
---|
| 237 | owl_message *m = g_new(owl_message, 1); |
---|
| 238 | owl_message_create_from_zwrite(m, z, owl_zwrite_get_message(z), i); |
---|
[15b34fd] | 239 | |
---|
[e5da3fe] | 240 | owl_global_messagequeue_addmsg(&g, m); |
---|
| 241 | } |
---|
| 242 | } |
---|
[15b34fd] | 243 | } |
---|
| 244 | |
---|
| 245 | /* Create an outgoing AIM message, returns a pointer to the created |
---|
| 246 | * message or NULL if we're not logged into AIM (and thus unable to |
---|
| 247 | * create the message). Does not put it on the global queue. Use |
---|
[e5da3fe] | 248 | * owl_global_messagequeue_addmsg() for that. |
---|
[15b34fd] | 249 | */ |
---|
[6829afc] | 250 | CALLER_OWN owl_message *owl_function_make_outgoing_aim(const char *body, const char *to) |
---|
[15b34fd] | 251 | { |
---|
| 252 | owl_message *m; |
---|
| 253 | |
---|
| 254 | /* error if we're not logged into aim */ |
---|
| 255 | if (!owl_global_is_aimloggedin(&g)) return(NULL); |
---|
| 256 | |
---|
[96828e4] | 257 | m=g_new(owl_message, 1); |
---|
[d559df9] | 258 | owl_message_create_aim(m, |
---|
| 259 | owl_global_get_aim_screenname(&g), |
---|
| 260 | to, |
---|
| 261 | body, |
---|
| 262 | OWL_MESSAGE_DIRECTION_OUT, |
---|
| 263 | 0); |
---|
[15b34fd] | 264 | return(m); |
---|
[d09e5a1] | 265 | } |
---|
| 266 | |
---|
[15b34fd] | 267 | /* Create an outgoing loopback message and return a pointer to it. |
---|
| 268 | * Does not append it to the global queue, use |
---|
[13fe062] | 269 | * owl_global_messagequeue_addmsg() for that. |
---|
[15b34fd] | 270 | */ |
---|
[6829afc] | 271 | CALLER_OWN owl_message *owl_function_make_outgoing_loopback(const char *body) |
---|
[37eab7f] | 272 | { |
---|
| 273 | owl_message *m; |
---|
| 274 | |
---|
| 275 | /* create the message */ |
---|
[96828e4] | 276 | m=g_new(owl_message, 1); |
---|
[37eab7f] | 277 | owl_message_create_loopback(m, body); |
---|
| 278 | owl_message_set_direction_out(m); |
---|
| 279 | |
---|
[15b34fd] | 280 | return(m); |
---|
[37eab7f] | 281 | } |
---|
| 282 | |
---|
[1b1cd2c] | 283 | void owl_function_start_edit_win(const char *line, void (*callback)(owl_editwin *), void *data, void (*cleanup)(void *)) |
---|
[d54838d] | 284 | { |
---|
[7d4fbcd] | 285 | owl_editwin *e; |
---|
[c394de8] | 286 | owl_context *ctx; |
---|
[bdbec0a] | 287 | char *s; |
---|
| 288 | |
---|
| 289 | /* create and setup the editwin */ |
---|
[58d47ca] | 290 | e = owl_global_set_typwin_active(&g, OWL_EDITWIN_STYLE_MULTILINE, |
---|
| 291 | owl_global_get_msg_history(&g)); |
---|
[bdbec0a] | 292 | owl_editwin_set_dotsend(e); |
---|
[3472845] | 293 | s = g_strdup_printf("----> %s\n", line); |
---|
[bdbec0a] | 294 | owl_editwin_set_locktext(e, s); |
---|
[ddbbcffa] | 295 | g_free(s); |
---|
[bdbec0a] | 296 | |
---|
[38cc669] | 297 | owl_editwin_set_cbdata(e, data, cleanup); |
---|
| 298 | owl_editwin_set_callback(e, callback); |
---|
[4a41f16] | 299 | ctx = owl_editcontext_new(OWL_CTX_EDITMULTI, e, "editmulti", |
---|
| 300 | owl_global_deactivate_editcontext, &g); |
---|
[c394de8] | 301 | owl_global_push_context_obj(&g, ctx); |
---|
| 302 | |
---|
[bdbec0a] | 303 | } |
---|
| 304 | |
---|
[987cf3f] | 305 | static void owl_function_write_setup(const char *noun) |
---|
[bdbec0a] | 306 | { |
---|
| 307 | |
---|
| 308 | if (!owl_global_get_lockout_ctrld(&g)) |
---|
| 309 | owl_function_makemsg("Type your %s below. " |
---|
| 310 | "End with ^D or a dot on a line by itself." |
---|
| 311 | " ^C will quit.", noun); |
---|
| 312 | else |
---|
| 313 | owl_function_makemsg("Type your %s below. " |
---|
| 314 | "End with a dot on a line by itself. ^C will quit.", |
---|
| 315 | noun); |
---|
| 316 | } |
---|
| 317 | |
---|
[987cf3f] | 318 | void owl_function_zwrite_setup(owl_zwrite *z) |
---|
[bdbec0a] | 319 | { |
---|
[7d4fbcd] | 320 | /* send a ping if necessary */ |
---|
| 321 | if (owl_global_is_txping(&g)) { |
---|
[987cf3f] | 322 | owl_zwrite_send_ping(z); |
---|
[7d4fbcd] | 323 | } |
---|
| 324 | |
---|
[987cf3f] | 325 | |
---|
| 326 | owl_function_write_setup("zephyr"); |
---|
| 327 | owl_function_start_edit_win(z->zwriteline, |
---|
| 328 | &owl_callback_zwrite, |
---|
| 329 | z, (void(*)(void*))owl_zwrite_delete); |
---|
[7d4fbcd] | 330 | } |
---|
| 331 | |
---|
[3f82515] | 332 | void owl_function_aimwrite_setup(const char *to) |
---|
[d09e5a1] | 333 | { |
---|
[3f82515] | 334 | /* TODO: We probably actually want an owl_aimwrite object like |
---|
| 335 | * owl_zwrite. */ |
---|
[3472845] | 336 | char *line = g_strdup_printf("aimwrite %s", to); |
---|
[987cf3f] | 337 | owl_function_write_setup("message"); |
---|
| 338 | owl_function_start_edit_win(line, |
---|
| 339 | &owl_callback_aimwrite, |
---|
[d4927a7] | 340 | g_strdup(to), |
---|
[ddbbcffa] | 341 | g_free); |
---|
| 342 | g_free(line); |
---|
[d09e5a1] | 343 | } |
---|
| 344 | |
---|
[c79a047] | 345 | void owl_function_loopwrite_setup(void) |
---|
[37eab7f] | 346 | { |
---|
[987cf3f] | 347 | owl_function_write_setup("message"); |
---|
| 348 | owl_function_start_edit_win("loopwrite", |
---|
| 349 | &owl_callback_loopwrite, |
---|
[9359e5a] | 350 | NULL, NULL); |
---|
[1b6b2f3] | 351 | } |
---|
| 352 | |
---|
| 353 | void owl_callback_zwrite(owl_editwin *e) { |
---|
[987cf3f] | 354 | owl_zwrite *z = owl_editwin_get_cbdata(e); |
---|
| 355 | owl_function_zwrite(z, owl_editwin_get_text(e)); |
---|
[37eab7f] | 356 | } |
---|
| 357 | |
---|
[e5da3fe] | 358 | /* send, log and display outgoing zephyrs. If 'msg' is NULL the |
---|
| 359 | * message is expected to be set from the zwrite line itself |
---|
[9ceee9d] | 360 | */ |
---|
[c23f678] | 361 | #ifdef HAVE_LIBZEPHYR |
---|
[987cf3f] | 362 | void owl_function_zwrite(owl_zwrite *z, const char *msg) |
---|
[d54838d] | 363 | { |
---|
[0743696] | 364 | int ret; |
---|
[d309eb3] | 365 | |
---|
[987cf3f] | 366 | if(strcmp(z->cmd, "zcrypt") == 0) { |
---|
| 367 | owl_function_zcrypt(z, msg); |
---|
[a5fc448] | 368 | return; |
---|
| 369 | } |
---|
| 370 | |
---|
[9ceee9d] | 371 | /* create the zwrite and send the message */ |
---|
[987cf3f] | 372 | owl_zwrite_populate_zsig(z); |
---|
[9ceee9d] | 373 | if (msg) { |
---|
[987cf3f] | 374 | owl_zwrite_set_message(z, msg); |
---|
[d309eb3] | 375 | } |
---|
[0743696] | 376 | ret = owl_zwrite_send_message(z); |
---|
| 377 | if (ret != 0) { |
---|
| 378 | owl_function_makemsg("Error sending zephyr: %s", error_message(ret)); |
---|
| 379 | return; |
---|
| 380 | } |
---|
[9ceee9d] | 381 | owl_function_makemsg("Waiting for ack..."); |
---|
[d309eb3] | 382 | |
---|
[15b34fd] | 383 | /* If it's personal */ |
---|
[987cf3f] | 384 | if (owl_zwrite_is_personal(z)) { |
---|
[15b34fd] | 385 | /* create the outgoing message */ |
---|
[e5da3fe] | 386 | owl_function_add_outgoing_zephyrs(z); |
---|
[9ceee9d] | 387 | } |
---|
[d309eb3] | 388 | } |
---|
[c23f678] | 389 | #else |
---|
| 390 | void owl_function_zwrite(owl_zwrite *z, const char *msg) { |
---|
| 391 | } |
---|
| 392 | #endif |
---|
[d309eb3] | 393 | |
---|
[e5da3fe] | 394 | /* send, log and display outgoing zcrypt zephyrs. If 'msg' is NULL |
---|
[ce7db4d] | 395 | * the message is expected to be set from the zwrite line itself |
---|
| 396 | */ |
---|
[987cf3f] | 397 | void owl_function_zcrypt(owl_zwrite *z, const char *msg) |
---|
[d54838d] | 398 | { |
---|
[9ceee9d] | 399 | char *cryptmsg; |
---|
[d564c3d] | 400 | const char *argv[7]; |
---|
[9a7b4f2] | 401 | char *zcrypt; |
---|
[d564c3d] | 402 | int rv, status; |
---|
[96582d5] | 403 | char *old_msg; |
---|
[7d4fbcd] | 404 | |
---|
| 405 | /* create the zwrite and send the message */ |
---|
[987cf3f] | 406 | owl_zwrite_populate_zsig(z); |
---|
[ce7db4d] | 407 | if (msg) { |
---|
[987cf3f] | 408 | owl_zwrite_set_message(z, msg); |
---|
[ce7db4d] | 409 | } |
---|
[d4927a7] | 410 | old_msg = g_strdup(owl_zwrite_get_message(z)); |
---|
[d564c3d] | 411 | |
---|
[3472845] | 412 | zcrypt = g_strdup_printf("%s/zcrypt", owl_get_bindir()); |
---|
[d564c3d] | 413 | argv[0] = "zcrypt"; |
---|
| 414 | argv[1] = "-E"; |
---|
[987cf3f] | 415 | argv[2] = "-c"; argv[3] = owl_zwrite_get_class(z); |
---|
| 416 | argv[4] = "-i"; argv[5] = owl_zwrite_get_instance(z); |
---|
[d564c3d] | 417 | argv[6] = NULL; |
---|
| 418 | |
---|
[987cf3f] | 419 | rv = call_filter(zcrypt, argv, owl_zwrite_get_message(z), &cryptmsg, &status); |
---|
[9a7b4f2] | 420 | |
---|
[ddbbcffa] | 421 | g_free(zcrypt); |
---|
[d564c3d] | 422 | |
---|
| 423 | if (rv || status) { |
---|
[3b8a563] | 424 | g_free(cryptmsg); |
---|
[ddbbcffa] | 425 | g_free(old_msg); |
---|
[ec6ff52] | 426 | owl_function_error("Error in zcrypt, possibly no key found. Message not sent."); |
---|
[9ceee9d] | 427 | owl_function_beep(); |
---|
| 428 | return; |
---|
| 429 | } |
---|
| 430 | |
---|
[7bfc613] | 431 | owl_zwrite_set_message_raw(z, cryptmsg); |
---|
[987cf3f] | 432 | owl_zwrite_set_opcode(z, "crypt"); |
---|
[7bfc613] | 433 | |
---|
[987cf3f] | 434 | owl_zwrite_send_message(z); |
---|
[7d4fbcd] | 435 | owl_function_makemsg("Waiting for ack..."); |
---|
| 436 | |
---|
[15b34fd] | 437 | /* If it's personal */ |
---|
[987cf3f] | 438 | if (owl_zwrite_is_personal(z)) { |
---|
[c43c77b] | 439 | /* Create the outgoing message. Restore the un-crypted message for display. */ |
---|
[7bfc613] | 440 | owl_zwrite_set_message_raw(z, old_msg); |
---|
[e5da3fe] | 441 | owl_function_add_outgoing_zephyrs(z); |
---|
[7d4fbcd] | 442 | } |
---|
| 443 | |
---|
| 444 | /* free the zwrite */ |
---|
[ddbbcffa] | 445 | g_free(cryptmsg); |
---|
[7d4fbcd] | 446 | } |
---|
| 447 | |
---|
[1b6b2f3] | 448 | void owl_callback_aimwrite(owl_editwin *e) { |
---|
[3f82515] | 449 | char *to = owl_editwin_get_cbdata(e); |
---|
| 450 | owl_function_aimwrite(to, owl_editwin_get_text(e), true); |
---|
[1b6b2f3] | 451 | } |
---|
| 452 | |
---|
[3f82515] | 453 | void owl_function_aimwrite(const char *to, const char *msg, bool unwrap) |
---|
[d09e5a1] | 454 | { |
---|
[ec6ff52] | 455 | int ret; |
---|
[65b2173] | 456 | char *format_msg; |
---|
[15b34fd] | 457 | owl_message *m; |
---|
[f82e233] | 458 | |
---|
| 459 | /* make a formatted copy of the message */ |
---|
[d4927a7] | 460 | format_msg = g_strdup(msg); |
---|
[3f82515] | 461 | if (unwrap) |
---|
| 462 | owl_text_wordunwrap(format_msg); |
---|
[ec6ff52] | 463 | |
---|
[f82e233] | 464 | /* send the message */ |
---|
| 465 | ret=owl_aim_send_im(to, format_msg); |
---|
[ec6ff52] | 466 | if (!ret) { |
---|
| 467 | owl_function_makemsg("AIM message sent."); |
---|
| 468 | } else { |
---|
| 469 | owl_function_error("Could not send AIM message."); |
---|
| 470 | } |
---|
[d09e5a1] | 471 | |
---|
[15b34fd] | 472 | /* create the outgoing message */ |
---|
| 473 | m=owl_function_make_outgoing_aim(msg, to); |
---|
| 474 | |
---|
[3c7d086a] | 475 | if (m) { |
---|
[13a3c1db] | 476 | owl_global_messagequeue_addmsg(&g, m); |
---|
[15b34fd] | 477 | } else { |
---|
[3c7d086a] | 478 | owl_function_error("Could not create outgoing AIM message"); |
---|
[d09e5a1] | 479 | } |
---|
[f82e233] | 480 | |
---|
[ddbbcffa] | 481 | g_free(format_msg); |
---|
[d09e5a1] | 482 | } |
---|
| 483 | |
---|
[e19eb97] | 484 | void owl_function_send_aimawymsg(const char *to, const char *msg) |
---|
[9854278] | 485 | { |
---|
| 486 | int ret; |
---|
| 487 | char *format_msg; |
---|
[15b34fd] | 488 | owl_message *m; |
---|
[9854278] | 489 | |
---|
| 490 | /* make a formatted copy of the message */ |
---|
[d4927a7] | 491 | format_msg=g_strdup(msg); |
---|
[9854278] | 492 | owl_text_wordunwrap(format_msg); |
---|
| 493 | |
---|
| 494 | /* send the message */ |
---|
| 495 | ret=owl_aim_send_awaymsg(to, format_msg); |
---|
| 496 | if (!ret) { |
---|
| 497 | /* owl_function_makemsg("AIM message sent."); */ |
---|
| 498 | } else { |
---|
| 499 | owl_function_error("Could not send AIM message."); |
---|
| 500 | } |
---|
| 501 | |
---|
[15b34fd] | 502 | /* create the message */ |
---|
| 503 | m=owl_function_make_outgoing_aim(msg, to); |
---|
| 504 | if (m) { |
---|
[13a3c1db] | 505 | owl_global_messagequeue_addmsg(&g, m); |
---|
[15b34fd] | 506 | } else { |
---|
| 507 | owl_function_error("Could not create AIM message"); |
---|
[9854278] | 508 | } |
---|
[ddbbcffa] | 509 | g_free(format_msg); |
---|
[9854278] | 510 | } |
---|
| 511 | |
---|
[1b6b2f3] | 512 | void owl_callback_loopwrite(owl_editwin *e) { |
---|
| 513 | owl_function_loopwrite(owl_editwin_get_text(e)); |
---|
| 514 | } |
---|
| 515 | |
---|
[e19eb97] | 516 | void owl_function_loopwrite(const char *msg) |
---|
[37eab7f] | 517 | { |
---|
[15b34fd] | 518 | owl_message *min, *mout; |
---|
[37eab7f] | 519 | |
---|
| 520 | /* create a message and put it on the message queue. This simulates |
---|
| 521 | * an incoming message */ |
---|
[96828e4] | 522 | min=g_new(owl_message, 1); |
---|
[4211f50b] | 523 | mout=owl_function_make_outgoing_loopback(msg); |
---|
[13a3c1db] | 524 | |
---|
[37eab7f] | 525 | if (owl_global_is_displayoutgoing(&g)) { |
---|
[13a3c1db] | 526 | owl_global_messagequeue_addmsg(&g, mout); |
---|
[15b34fd] | 527 | } else { |
---|
[91634ec] | 528 | owl_message_delete(mout); |
---|
[37eab7f] | 529 | } |
---|
| 530 | |
---|
[13a3c1db] | 531 | owl_message_create_loopback(min, msg); |
---|
| 532 | owl_message_set_direction_in(min); |
---|
| 533 | owl_global_messagequeue_addmsg(&g, min); |
---|
| 534 | |
---|
[37eab7f] | 535 | /* fake a makemsg */ |
---|
| 536 | owl_function_makemsg("loopback message sent"); |
---|
| 537 | } |
---|
| 538 | |
---|
[b950088] | 539 | /* If filter is non-null, looks for the next message matching |
---|
| 540 | * that filter. If skip_deleted, skips any deleted messages. |
---|
| 541 | * If last_if_none, will stop at the last message in the view |
---|
| 542 | * if no matching messages are found. */ |
---|
[e19eb97] | 543 | void owl_function_nextmsg_full(const char *filter, int skip_deleted, int last_if_none) |
---|
[d54838d] | 544 | { |
---|
[b950088] | 545 | int curmsg, i, viewsize, found; |
---|
[9e5c9f3] | 546 | const owl_view *v; |
---|
[4542047] | 547 | const owl_filter *f = NULL; |
---|
[c08c70a] | 548 | const owl_message *m; |
---|
[7d4fbcd] | 549 | |
---|
| 550 | v=owl_global_get_current_view(&g); |
---|
[b950088] | 551 | |
---|
| 552 | if (filter) { |
---|
| 553 | f=owl_global_get_filter(&g, filter); |
---|
| 554 | if (!f) { |
---|
[ec6ff52] | 555 | owl_function_error("No %s filter defined", filter); |
---|
[b950088] | 556 | return; |
---|
| 557 | } |
---|
[7d4fbcd] | 558 | } |
---|
| 559 | |
---|
[b950088] | 560 | curmsg=owl_global_get_curmsg(&g); |
---|
| 561 | viewsize=owl_view_get_size(v); |
---|
| 562 | found=0; |
---|
[7d4fbcd] | 563 | |
---|
[b950088] | 564 | /* just check to make sure we're in bounds... */ |
---|
| 565 | if (curmsg>viewsize-1) curmsg=viewsize-1; |
---|
| 566 | if (curmsg<0) curmsg=0; |
---|
[7d4fbcd] | 567 | |
---|
[b950088] | 568 | for (i=curmsg+1; i<viewsize; i++) { |
---|
| 569 | m=owl_view_get_element(v, i); |
---|
| 570 | if (skip_deleted && owl_message_is_delete(m)) continue; |
---|
| 571 | if (f && !owl_filter_message_match(f, m)) continue; |
---|
| 572 | found = 1; |
---|
| 573 | break; |
---|
| 574 | } |
---|
| 575 | |
---|
| 576 | if (i>owl_view_get_size(v)-1) i=owl_view_get_size(v)-1; |
---|
[5763474] | 577 | if (i<0) i=0; |
---|
[b950088] | 578 | |
---|
| 579 | if (!found) { |
---|
[799b60e] | 580 | owl_function_makemsg("already at last%s message%s%s%s", |
---|
[b950088] | 581 | skip_deleted?" non-deleted":"", |
---|
[799b60e] | 582 | filter?" in ":"", filter?filter:"", |
---|
| 583 | owl_mainwin_is_curmsg_truncated(owl_global_get_mainwin(&g)) ? |
---|
| 584 | ", press Enter to scroll" : ""); |
---|
[5a6e6b9] | 585 | /* if (!skip_deleted) owl_function_beep(); */ |
---|
[7d4fbcd] | 586 | } |
---|
| 587 | |
---|
[b950088] | 588 | if (last_if_none || found) { |
---|
| 589 | owl_global_set_curmsg(&g, i); |
---|
| 590 | owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS); |
---|
| 591 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 592 | owl_global_set_direction_downwards(&g); |
---|
| 593 | } |
---|
| 594 | } |
---|
[7d4fbcd] | 595 | |
---|
[e19eb97] | 596 | void owl_function_prevmsg_full(const char *filter, int skip_deleted, int first_if_none) |
---|
[d54838d] | 597 | { |
---|
[402eb16f] | 598 | int curmsg, i, found; |
---|
[9e5c9f3] | 599 | const owl_view *v; |
---|
[4542047] | 600 | const owl_filter *f = NULL; |
---|
[c08c70a] | 601 | const owl_message *m; |
---|
[7d4fbcd] | 602 | |
---|
| 603 | v=owl_global_get_current_view(&g); |
---|
| 604 | |
---|
[b950088] | 605 | if (filter) { |
---|
| 606 | f=owl_global_get_filter(&g, filter); |
---|
| 607 | if (!f) { |
---|
[ec6ff52] | 608 | owl_function_error("No %s filter defined", filter); |
---|
[b950088] | 609 | return; |
---|
[7d4fbcd] | 610 | } |
---|
[b950088] | 611 | } |
---|
[7d4fbcd] | 612 | |
---|
[b950088] | 613 | curmsg=owl_global_get_curmsg(&g); |
---|
| 614 | found=0; |
---|
| 615 | |
---|
| 616 | /* just check to make sure we're in bounds... */ |
---|
| 617 | if (curmsg<0) curmsg=0; |
---|
| 618 | |
---|
| 619 | for (i=curmsg-1; i>=0; i--) { |
---|
| 620 | m=owl_view_get_element(v, i); |
---|
| 621 | if (skip_deleted && owl_message_is_delete(m)) continue; |
---|
| 622 | if (f && !owl_filter_message_match(f, m)) continue; |
---|
| 623 | found = 1; |
---|
| 624 | break; |
---|
| 625 | } |
---|
| 626 | |
---|
| 627 | if (i<0) i=0; |
---|
| 628 | |
---|
| 629 | if (!found) { |
---|
[f51bc78] | 630 | owl_function_makemsg("already at first%s message%s%s", |
---|
[b950088] | 631 | skip_deleted?" non-deleted":"", |
---|
| 632 | filter?" in ":"", filter?filter:""); |
---|
[5a6e6b9] | 633 | /* if (!skip_deleted) owl_function_beep(); */ |
---|
[b950088] | 634 | } |
---|
| 635 | |
---|
| 636 | if (first_if_none || found) { |
---|
| 637 | owl_global_set_curmsg(&g, i); |
---|
| 638 | owl_function_calculate_topmsg(OWL_DIRECTION_UPWARDS); |
---|
| 639 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 640 | owl_global_set_direction_upwards(&g); |
---|
[7d4fbcd] | 641 | } |
---|
| 642 | } |
---|
| 643 | |
---|
[c79a047] | 644 | void owl_function_nextmsg(void) |
---|
[d54838d] | 645 | { |
---|
[b950088] | 646 | owl_function_nextmsg_full(NULL, 0, 1); |
---|
| 647 | } |
---|
[7d4fbcd] | 648 | |
---|
[c79a047] | 649 | void owl_function_prevmsg(void) |
---|
[d54838d] | 650 | { |
---|
[b950088] | 651 | owl_function_prevmsg_full(NULL, 0, 1); |
---|
| 652 | } |
---|
[7d4fbcd] | 653 | |
---|
[c79a047] | 654 | void owl_function_nextmsg_notdeleted(void) |
---|
[d54838d] | 655 | { |
---|
[b950088] | 656 | owl_function_nextmsg_full(NULL, 1, 1); |
---|
| 657 | } |
---|
[7d4fbcd] | 658 | |
---|
[c79a047] | 659 | void owl_function_prevmsg_notdeleted(void) |
---|
[d54838d] | 660 | { |
---|
[b950088] | 661 | owl_function_prevmsg_full(NULL, 1, 1); |
---|
[7d4fbcd] | 662 | } |
---|
| 663 | |
---|
[b950088] | 664 | /* if move_after is 1, moves after the delete */ |
---|
[d54838d] | 665 | void owl_function_deletecur(int move_after) |
---|
| 666 | { |
---|
[7d4fbcd] | 667 | int curmsg; |
---|
| 668 | owl_view *v; |
---|
| 669 | |
---|
| 670 | v=owl_global_get_current_view(&g); |
---|
| 671 | |
---|
| 672 | /* bail if there's no current message */ |
---|
| 673 | if (owl_view_get_size(v) < 1) { |
---|
[ec6ff52] | 674 | owl_function_error("No current message to delete"); |
---|
[7d4fbcd] | 675 | return; |
---|
| 676 | } |
---|
| 677 | |
---|
| 678 | /* mark the message for deletion */ |
---|
| 679 | curmsg=owl_global_get_curmsg(&g); |
---|
| 680 | owl_view_delete_element(v, curmsg); |
---|
| 681 | |
---|
[b950088] | 682 | if (move_after) { |
---|
| 683 | /* move the poiner in the appropriate direction |
---|
| 684 | * to the next undeleted msg */ |
---|
| 685 | if (owl_global_get_direction(&g)==OWL_DIRECTION_UPWARDS) { |
---|
| 686 | owl_function_prevmsg_notdeleted(); |
---|
| 687 | } else { |
---|
| 688 | owl_function_nextmsg_notdeleted(); |
---|
| 689 | } |
---|
[7d4fbcd] | 690 | } |
---|
| 691 | } |
---|
| 692 | |
---|
[d54838d] | 693 | void owl_function_undeletecur(int move_after) |
---|
| 694 | { |
---|
[7d4fbcd] | 695 | int curmsg; |
---|
| 696 | owl_view *v; |
---|
| 697 | |
---|
| 698 | v=owl_global_get_current_view(&g); |
---|
| 699 | |
---|
| 700 | if (owl_view_get_size(v) < 1) { |
---|
[ec6ff52] | 701 | owl_function_error("No current message to undelete"); |
---|
[7d4fbcd] | 702 | return; |
---|
| 703 | } |
---|
| 704 | curmsg=owl_global_get_curmsg(&g); |
---|
| 705 | |
---|
| 706 | owl_view_undelete_element(v, curmsg); |
---|
| 707 | |
---|
[b950088] | 708 | if (move_after) { |
---|
| 709 | if (owl_global_get_direction(&g)==OWL_DIRECTION_UPWARDS) { |
---|
| 710 | if (curmsg>0) { |
---|
| 711 | owl_function_prevmsg(); |
---|
| 712 | } else { |
---|
| 713 | owl_function_nextmsg(); |
---|
| 714 | } |
---|
[7d4fbcd] | 715 | } else { |
---|
[b950088] | 716 | owl_function_nextmsg(); |
---|
[7d4fbcd] | 717 | } |
---|
| 718 | } |
---|
| 719 | |
---|
| 720 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 721 | } |
---|
| 722 | |
---|
[c79a047] | 723 | void owl_function_expunge(void) |
---|
[d54838d] | 724 | { |
---|
[7d4fbcd] | 725 | int curmsg; |
---|
[c08c70a] | 726 | const owl_message *m; |
---|
[7d4fbcd] | 727 | owl_messagelist *ml; |
---|
| 728 | owl_view *v; |
---|
[486688f] | 729 | int lastmsgid=0; |
---|
[7d4fbcd] | 730 | |
---|
| 731 | curmsg=owl_global_get_curmsg(&g); |
---|
| 732 | v=owl_global_get_current_view(&g); |
---|
| 733 | ml=owl_global_get_msglist(&g); |
---|
| 734 | |
---|
| 735 | m=owl_view_get_element(v, curmsg); |
---|
[486688f] | 736 | if (m) lastmsgid = owl_message_get_id(m); |
---|
[7d4fbcd] | 737 | |
---|
| 738 | /* expunge the message list */ |
---|
| 739 | owl_messagelist_expunge(ml); |
---|
| 740 | |
---|
| 741 | /* update all views (we only have one right now) */ |
---|
| 742 | owl_view_recalculate(v); |
---|
| 743 | |
---|
[486688f] | 744 | /* find where the new position should be |
---|
| 745 | (as close as possible to where we last where) */ |
---|
| 746 | curmsg = owl_view_get_nearest_to_msgid(v, lastmsgid); |
---|
| 747 | if (curmsg>owl_view_get_size(v)-1) curmsg = owl_view_get_size(v)-1; |
---|
| 748 | if (curmsg<0) curmsg = 0; |
---|
| 749 | owl_global_set_curmsg(&g, curmsg); |
---|
| 750 | owl_function_calculate_topmsg(OWL_DIRECTION_NONE); |
---|
[7d4fbcd] | 751 | /* if there are no messages set the direction to down in case we |
---|
| 752 | delete everything upwards */ |
---|
| 753 | owl_global_set_direction_downwards(&g); |
---|
| 754 | |
---|
| 755 | owl_function_makemsg("Messages expunged"); |
---|
| 756 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 757 | } |
---|
| 758 | |
---|
[c79a047] | 759 | void owl_function_firstmsg(void) |
---|
[d54838d] | 760 | { |
---|
[7d4fbcd] | 761 | owl_global_set_curmsg(&g, 0); |
---|
| 762 | owl_global_set_topmsg(&g, 0); |
---|
| 763 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 764 | owl_global_set_direction_downwards(&g); |
---|
| 765 | } |
---|
| 766 | |
---|
[c79a047] | 767 | void owl_function_lastmsg_noredisplay(void) |
---|
[d54838d] | 768 | { |
---|
[5eeea3b] | 769 | int oldcurmsg, curmsg; |
---|
[9e5c9f3] | 770 | const owl_view *v; |
---|
[7d4fbcd] | 771 | |
---|
| 772 | v=owl_global_get_current_view(&g); |
---|
[5eeea3b] | 773 | oldcurmsg=owl_global_get_curmsg(&g); |
---|
| 774 | curmsg=owl_view_get_size(v)-1; |
---|
[7d4fbcd] | 775 | if (curmsg<0) curmsg=0; |
---|
| 776 | owl_global_set_curmsg(&g, curmsg); |
---|
[5eeea3b] | 777 | if (oldcurmsg < curmsg) { |
---|
| 778 | owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS); |
---|
| 779 | } else if (curmsg<owl_view_get_size(v)) { |
---|
| 780 | /* If already at the end, blank the screen and move curmsg |
---|
| 781 | * past the end of the messages. */ |
---|
| 782 | owl_global_set_topmsg(&g, curmsg+1); |
---|
| 783 | owl_global_set_curmsg(&g, curmsg+1); |
---|
| 784 | } |
---|
[6b580b0] | 785 | /* owl_mainwin_redisplay(owl_global_get_mainwin(&g)); */ |
---|
[7d4fbcd] | 786 | owl_global_set_direction_downwards(&g); |
---|
| 787 | } |
---|
| 788 | |
---|
[c79a047] | 789 | void owl_function_lastmsg(void) |
---|
[d54838d] | 790 | { |
---|
[7d4fbcd] | 791 | owl_function_lastmsg_noredisplay(); |
---|
| 792 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 793 | } |
---|
| 794 | |
---|
[c79a047] | 795 | void owl_function_shift_right(void) |
---|
[d54838d] | 796 | { |
---|
[7d4fbcd] | 797 | owl_global_set_rightshift(&g, owl_global_get_rightshift(&g)+10); |
---|
| 798 | } |
---|
| 799 | |
---|
[c79a047] | 800 | void owl_function_shift_left(void) |
---|
[d54838d] | 801 | { |
---|
[7d4fbcd] | 802 | int shift; |
---|
| 803 | |
---|
| 804 | shift=owl_global_get_rightshift(&g); |
---|
[8c97fa1] | 805 | if (shift > 0) { |
---|
| 806 | owl_global_set_rightshift(&g, MAX(shift - 10, 0)); |
---|
[7d4fbcd] | 807 | } else { |
---|
| 808 | owl_function_beep(); |
---|
[f51bc78] | 809 | owl_function_makemsg("Already full left"); |
---|
[7d4fbcd] | 810 | } |
---|
| 811 | } |
---|
| 812 | |
---|
[c79a047] | 813 | void owl_function_unsuball(void) |
---|
[d54838d] | 814 | { |
---|
[7d4fbcd] | 815 | unsuball(); |
---|
| 816 | owl_function_makemsg("Unsubscribed from all messages."); |
---|
| 817 | } |
---|
| 818 | |
---|
[95474d7] | 819 | |
---|
| 820 | /* Load zephyr subscriptions from the named 'file' and load zephyr's |
---|
| 821 | * default subscriptions as well. An error message is printed if |
---|
| 822 | * 'file' can't be opened or if zephyr reports an error in |
---|
| 823 | * subscribing. |
---|
| 824 | * |
---|
| 825 | * If 'file' is NULL, this look for the default filename |
---|
| 826 | * $HOME/.zephyr.subs. If the file can not be opened in this case |
---|
| 827 | * only, no error message is printed. |
---|
| 828 | */ |
---|
[e19eb97] | 829 | void owl_function_loadsubs(const char *file) |
---|
[d54838d] | 830 | { |
---|
[4357be8] | 831 | int ret, ret2; |
---|
[e19eb97] | 832 | const char *foo; |
---|
[65b2173] | 833 | char *path; |
---|
[ecd5dc5] | 834 | |
---|
[95474d7] | 835 | if (file==NULL) { |
---|
| 836 | ret=owl_zephyr_loadsubs(NULL, 0); |
---|
| 837 | } else { |
---|
[27d8d83] | 838 | path = owl_util_makepath(file); |
---|
| 839 | ret=owl_zephyr_loadsubs(path, 1); |
---|
[ddbbcffa] | 840 | g_free(path); |
---|
[95474d7] | 841 | } |
---|
[ecd5dc5] | 842 | |
---|
[4357be8] | 843 | /* for backwards compatibility for now */ |
---|
| 844 | ret2=owl_zephyr_loaddefaultsubs(); |
---|
| 845 | |
---|
[ecd5dc5] | 846 | if (!owl_context_is_interactive(owl_global_get_context(&g))) return; |
---|
[95474d7] | 847 | |
---|
| 848 | foo=file?file:"file"; |
---|
| 849 | if (ret==0 && ret2==0) { |
---|
| 850 | if (!file) { |
---|
| 851 | owl_function_makemsg("Subscribed to messages."); |
---|
| 852 | } else { |
---|
| 853 | owl_function_makemsg("Subscribed to messages from %s", file); |
---|
| 854 | } |
---|
[7d4fbcd] | 855 | } else if (ret==-1) { |
---|
[95474d7] | 856 | owl_function_error("Could not read %s", foo); |
---|
[7d4fbcd] | 857 | } else { |
---|
[95474d7] | 858 | owl_function_error("Error subscribing to messages"); |
---|
[7d4fbcd] | 859 | } |
---|
| 860 | } |
---|
| 861 | |
---|
[e19eb97] | 862 | void owl_function_loadloginsubs(const char *file) |
---|
[d54838d] | 863 | { |
---|
[7933748] | 864 | int ret; |
---|
[ecd5dc5] | 865 | |
---|
[7933748] | 866 | ret=owl_zephyr_loadloginsubs(file); |
---|
[ecd5dc5] | 867 | |
---|
| 868 | if (!owl_context_is_interactive(owl_global_get_context(&g))) return; |
---|
[7933748] | 869 | if (ret==0) { |
---|
| 870 | } else if (ret==-1) { |
---|
[ec6ff52] | 871 | owl_function_error("Could not open file for login subscriptions."); |
---|
[7933748] | 872 | } else { |
---|
[ec6ff52] | 873 | owl_function_error("Error subscribing to login messages from file."); |
---|
[7933748] | 874 | } |
---|
| 875 | } |
---|
| 876 | |
---|
[1b6b2f3] | 877 | void owl_callback_aimlogin(owl_editwin *e) { |
---|
[8dfb59c] | 878 | char *user = owl_editwin_get_cbdata(e); |
---|
| 879 | owl_function_aimlogin(user, |
---|
[db8b00b] | 880 | owl_editwin_get_text(e)); |
---|
[1b6b2f3] | 881 | } |
---|
| 882 | |
---|
[e19eb97] | 883 | void owl_function_aimlogin(const char *user, const char *passwd) { |
---|
[4211f50b] | 884 | int ret; |
---|
| 885 | |
---|
| 886 | /* clear the buddylist */ |
---|
| 887 | owl_buddylist_clear(owl_global_get_buddylist(&g)); |
---|
| 888 | |
---|
| 889 | /* try to login */ |
---|
| 890 | ret=owl_aim_login(user, passwd); |
---|
| 891 | if (ret) owl_function_makemsg("Warning: login for %s failed.\n", user); |
---|
| 892 | } |
---|
| 893 | |
---|
[c79a047] | 894 | void owl_function_suspend(void) |
---|
[d54838d] | 895 | { |
---|
[7d4fbcd] | 896 | endwin(); |
---|
| 897 | printf("\n"); |
---|
| 898 | kill(getpid(), SIGSTOP); |
---|
| 899 | |
---|
| 900 | /* resize to reinitialize all the windows when we come back */ |
---|
| 901 | owl_command_resize(); |
---|
| 902 | } |
---|
| 903 | |
---|
[c79a047] | 904 | void owl_function_zaway_toggle(void) |
---|
[d54838d] | 905 | { |
---|
[7d4fbcd] | 906 | if (!owl_global_is_zaway(&g)) { |
---|
| 907 | owl_global_set_zaway_msg(&g, owl_global_get_zaway_msg_default(&g)); |
---|
| 908 | owl_function_zaway_on(); |
---|
| 909 | } else { |
---|
| 910 | owl_function_zaway_off(); |
---|
| 911 | } |
---|
| 912 | } |
---|
| 913 | |
---|
[c79a047] | 914 | void owl_function_zaway_on(void) |
---|
[d54838d] | 915 | { |
---|
[7d4fbcd] | 916 | owl_global_set_zaway_on(&g); |
---|
[4b660cc] | 917 | owl_function_makemsg("zaway set (%s)", owl_global_get_zaway_msg(&g)); |
---|
[7d4fbcd] | 918 | } |
---|
| 919 | |
---|
[c79a047] | 920 | void owl_function_zaway_off(void) |
---|
[d54838d] | 921 | { |
---|
[7d4fbcd] | 922 | owl_global_set_zaway_off(&g); |
---|
[4b660cc] | 923 | owl_function_makemsg("zaway off"); |
---|
| 924 | } |
---|
| 925 | |
---|
[c79a047] | 926 | void owl_function_aaway_toggle(void) |
---|
[4b660cc] | 927 | { |
---|
| 928 | if (!owl_global_is_aaway(&g)) { |
---|
| 929 | owl_global_set_aaway_msg(&g, owl_global_get_aaway_msg_default(&g)); |
---|
| 930 | owl_function_aaway_on(); |
---|
| 931 | } else { |
---|
| 932 | owl_function_aaway_off(); |
---|
| 933 | } |
---|
| 934 | } |
---|
| 935 | |
---|
[c79a047] | 936 | void owl_function_aaway_on(void) |
---|
[4b660cc] | 937 | { |
---|
| 938 | owl_global_set_aaway_on(&g); |
---|
| 939 | /* owl_aim_set_awaymsg(owl_global_get_zaway_msg(&g)); */ |
---|
| 940 | owl_function_makemsg("AIM away set (%s)", owl_global_get_aaway_msg(&g)); |
---|
| 941 | } |
---|
| 942 | |
---|
[c79a047] | 943 | void owl_function_aaway_off(void) |
---|
[4b660cc] | 944 | { |
---|
| 945 | owl_global_set_aaway_off(&g); |
---|
| 946 | /* owl_aim_set_awaymsg(""); */ |
---|
| 947 | owl_function_makemsg("AIM away off"); |
---|
[7d4fbcd] | 948 | } |
---|
| 949 | |
---|
[c79a047] | 950 | void owl_function_quit(void) |
---|
[d54838d] | 951 | { |
---|
[7d4fbcd] | 952 | char *ret; |
---|
| 953 | |
---|
| 954 | /* zlog out if we need to */ |
---|
[7433402] | 955 | if (owl_global_is_havezephyr(&g) && |
---|
| 956 | owl_global_is_shutdownlogout(&g)) { |
---|
[31e48a3] | 957 | owl_zephyr_zlog_out(); |
---|
[7d4fbcd] | 958 | } |
---|
| 959 | |
---|
| 960 | /* execute the commands in shutdown */ |
---|
[0337203] | 961 | ret = owl_perlconfig_execute("BarnOwl::Hooks::_shutdown();"); |
---|
[3b8a563] | 962 | g_free(ret); |
---|
[7d4fbcd] | 963 | |
---|
[d09e5a1] | 964 | /* signal our child process, if any */ |
---|
| 965 | if (owl_global_get_newmsgproc_pid(&g)) { |
---|
| 966 | kill(owl_global_get_newmsgproc_pid(&g), SIGHUP); |
---|
| 967 | } |
---|
[8c46404] | 968 | |
---|
| 969 | /* Quit AIM */ |
---|
| 970 | if (owl_global_is_aimloggedin(&g)) { |
---|
| 971 | owl_aim_logout(); |
---|
| 972 | } |
---|
| 973 | |
---|
[7d4fbcd] | 974 | owl_function_debugmsg("Quitting Owl"); |
---|
[3ecd78b] | 975 | owl_select_quit_loop(); |
---|
[7d4fbcd] | 976 | } |
---|
| 977 | |
---|
[d54838d] | 978 | void owl_function_calculate_topmsg(int direction) |
---|
| 979 | { |
---|
[aa2f33b3] | 980 | int recwinlines, topmsg, curmsg; |
---|
[9e5c9f3] | 981 | const owl_view *v; |
---|
[7d4fbcd] | 982 | |
---|
| 983 | v=owl_global_get_current_view(&g); |
---|
[aa2f33b3] | 984 | curmsg=owl_global_get_curmsg(&g); |
---|
| 985 | topmsg=owl_global_get_topmsg(&g); |
---|
[7d4fbcd] | 986 | recwinlines=owl_global_get_recwin_lines(&g); |
---|
| 987 | |
---|
[f9c43ae] | 988 | /* |
---|
[7d4fbcd] | 989 | if (owl_view_get_size(v) < 1) { |
---|
| 990 | return; |
---|
| 991 | } |
---|
[f9c43ae] | 992 | */ |
---|
[aa2f33b3] | 993 | |
---|
| 994 | switch (owl_global_get_scrollmode(&g)) { |
---|
| 995 | case OWL_SCROLLMODE_TOP: |
---|
[f9c43ae] | 996 | topmsg = owl_function_calculate_topmsg_top(direction, v, curmsg, topmsg, recwinlines); |
---|
[aa2f33b3] | 997 | break; |
---|
| 998 | case OWL_SCROLLMODE_NEARTOP: |
---|
[f9c43ae] | 999 | topmsg = owl_function_calculate_topmsg_neartop(direction, v, curmsg, topmsg, recwinlines); |
---|
[aa2f33b3] | 1000 | break; |
---|
| 1001 | case OWL_SCROLLMODE_CENTER: |
---|
[f9c43ae] | 1002 | topmsg = owl_function_calculate_topmsg_center(direction, v, curmsg, topmsg, recwinlines); |
---|
[aa2f33b3] | 1003 | break; |
---|
| 1004 | case OWL_SCROLLMODE_PAGED: |
---|
[f9c43ae] | 1005 | topmsg = owl_function_calculate_topmsg_paged(direction, v, curmsg, topmsg, recwinlines, 0); |
---|
[aa2f33b3] | 1006 | break; |
---|
| 1007 | case OWL_SCROLLMODE_PAGEDCENTER: |
---|
[f9c43ae] | 1008 | topmsg = owl_function_calculate_topmsg_paged(direction, v, curmsg, topmsg, recwinlines, 1); |
---|
[aa2f33b3] | 1009 | break; |
---|
| 1010 | case OWL_SCROLLMODE_NORMAL: |
---|
| 1011 | default: |
---|
[f9c43ae] | 1012 | topmsg = owl_function_calculate_topmsg_normal(direction, v, curmsg, topmsg, recwinlines); |
---|
[aa2f33b3] | 1013 | } |
---|
[3a2daac] | 1014 | owl_function_debugmsg("Calculated a topmsg of %i", topmsg); |
---|
[aa2f33b3] | 1015 | owl_global_set_topmsg(&g, topmsg); |
---|
| 1016 | } |
---|
| 1017 | |
---|
| 1018 | /* Returns what the new topmsg should be. |
---|
| 1019 | * Passed the last direction of movement, |
---|
| 1020 | * the current view, |
---|
| 1021 | * the current message number in the view, |
---|
| 1022 | * the top message currently being displayed, |
---|
| 1023 | * and the number of lines in the recwin. |
---|
| 1024 | */ |
---|
[9e5c9f3] | 1025 | int owl_function_calculate_topmsg_top(int direction, const owl_view *v, int curmsg, int topmsg, int recwinlines) |
---|
[d54838d] | 1026 | { |
---|
[f9c43ae] | 1027 | return(curmsg); |
---|
[aa2f33b3] | 1028 | } |
---|
| 1029 | |
---|
[9e5c9f3] | 1030 | int owl_function_calculate_topmsg_neartop(int direction, const owl_view *v, int curmsg, int topmsg, int recwinlines) |
---|
[d54838d] | 1031 | { |
---|
[aa2f33b3] | 1032 | if (curmsg>0 |
---|
| 1033 | && (owl_message_get_numlines(owl_view_get_element(v, curmsg-1)) |
---|
| 1034 | < recwinlines/2)) { |
---|
[f9c43ae] | 1035 | return(curmsg-1); |
---|
[aa2f33b3] | 1036 | } else { |
---|
[f9c43ae] | 1037 | return(curmsg); |
---|
[aa2f33b3] | 1038 | } |
---|
| 1039 | } |
---|
| 1040 | |
---|
[9e5c9f3] | 1041 | int owl_function_calculate_topmsg_center(int direction, const owl_view *v, int curmsg, int topmsg, int recwinlines) |
---|
[d54838d] | 1042 | { |
---|
[aa2f33b3] | 1043 | int i, last, lines; |
---|
| 1044 | |
---|
| 1045 | last = curmsg; |
---|
| 1046 | lines = 0; |
---|
| 1047 | for (i=curmsg-1; i>=0; i--) { |
---|
| 1048 | lines += owl_message_get_numlines(owl_view_get_element(v, i)); |
---|
| 1049 | if (lines > recwinlines/2) break; |
---|
| 1050 | last = i; |
---|
| 1051 | } |
---|
[f9c43ae] | 1052 | return(last); |
---|
[aa2f33b3] | 1053 | } |
---|
| 1054 | |
---|
[9e5c9f3] | 1055 | int owl_function_calculate_topmsg_paged(int direction, const owl_view *v, int curmsg, int topmsg, int recwinlines, int center_on_page) |
---|
[d54838d] | 1056 | { |
---|
[aa2f33b3] | 1057 | int i, last, lines, savey; |
---|
| 1058 | |
---|
| 1059 | /* If we're off the top of the screen, scroll up such that the |
---|
| 1060 | * curmsg is near the botton of the screen. */ |
---|
| 1061 | if (curmsg < topmsg) { |
---|
| 1062 | last = curmsg; |
---|
| 1063 | lines = 0; |
---|
| 1064 | for (i=curmsg; i>=0; i--) { |
---|
| 1065 | lines += owl_message_get_numlines(owl_view_get_element(v, i)); |
---|
| 1066 | if (lines > recwinlines) break; |
---|
| 1067 | last = i; |
---|
| 1068 | } |
---|
| 1069 | if (center_on_page) { |
---|
[f9c43ae] | 1070 | return(owl_function_calculate_topmsg_center(direction, v, curmsg, 0, recwinlines)); |
---|
[aa2f33b3] | 1071 | } else { |
---|
[f9c43ae] | 1072 | return(last); |
---|
[aa2f33b3] | 1073 | } |
---|
| 1074 | } |
---|
| 1075 | |
---|
| 1076 | /* Find number of lines from top to bottom of curmsg (store in savey) */ |
---|
| 1077 | savey=0; |
---|
| 1078 | for (i=topmsg; i<=curmsg; i++) { |
---|
| 1079 | savey+=owl_message_get_numlines(owl_view_get_element(v, i)); |
---|
| 1080 | } |
---|
| 1081 | |
---|
| 1082 | /* if we're off the bottom of the screen, scroll down */ |
---|
| 1083 | if (savey > recwinlines) { |
---|
| 1084 | if (center_on_page) { |
---|
[f9c43ae] | 1085 | return(owl_function_calculate_topmsg_center(direction, v, curmsg, 0, recwinlines)); |
---|
[aa2f33b3] | 1086 | } else { |
---|
[f9c43ae] | 1087 | return(curmsg); |
---|
[aa2f33b3] | 1088 | } |
---|
| 1089 | } |
---|
| 1090 | |
---|
| 1091 | /* else just stay as we are... */ |
---|
[f9c43ae] | 1092 | return(topmsg); |
---|
[aa2f33b3] | 1093 | } |
---|
| 1094 | |
---|
[9e5c9f3] | 1095 | int owl_function_calculate_topmsg_normal(int direction, const owl_view *v, int curmsg, int topmsg, int recwinlines) |
---|
[d54838d] | 1096 | { |
---|
[801b7ac] | 1097 | int savey, i, foo, y; |
---|
[f9c43ae] | 1098 | |
---|
[88736cb] | 1099 | if (curmsg<0) return(topmsg); |
---|
| 1100 | |
---|
[f9c43ae] | 1101 | /* If we're off the top of the screen then center */ |
---|
| 1102 | if (curmsg<topmsg) { |
---|
| 1103 | topmsg=owl_function_calculate_topmsg_center(direction, v, curmsg, 0, recwinlines); |
---|
| 1104 | } |
---|
| 1105 | |
---|
[801b7ac] | 1106 | /* If curmsg is so far past topmsg that there are more messages than |
---|
| 1107 | lines, skip the line counting that follows because we're |
---|
| 1108 | certainly off screen. */ |
---|
| 1109 | savey=curmsg-topmsg; |
---|
| 1110 | if (savey <= recwinlines) { |
---|
| 1111 | /* Find number of lines from top to bottom of curmsg (store in savey) */ |
---|
| 1112 | savey = 0; |
---|
| 1113 | for (i=topmsg; i<=curmsg; i++) { |
---|
| 1114 | savey+=owl_message_get_numlines(owl_view_get_element(v, i)); |
---|
| 1115 | } |
---|
[7d4fbcd] | 1116 | } |
---|
| 1117 | |
---|
[f9c43ae] | 1118 | /* If we're off the bottom of the screen, set the topmsg to curmsg |
---|
| 1119 | * and scroll upwards */ |
---|
| 1120 | if (savey > recwinlines) { |
---|
| 1121 | topmsg=curmsg; |
---|
[801b7ac] | 1122 | savey=owl_message_get_numlines(owl_view_get_element(v, curmsg)); |
---|
[f9c43ae] | 1123 | direction=OWL_DIRECTION_UPWARDS; |
---|
[7d4fbcd] | 1124 | } |
---|
[f9c43ae] | 1125 | |
---|
[7d4fbcd] | 1126 | /* If our bottom line is less than 1/4 down the screen then scroll up */ |
---|
| 1127 | if (direction == OWL_DIRECTION_UPWARDS || direction == OWL_DIRECTION_NONE) { |
---|
| 1128 | if (savey < (recwinlines / 4)) { |
---|
| 1129 | y=0; |
---|
[801b7ac] | 1130 | for (i=curmsg; i>=0; i--) { |
---|
| 1131 | foo=owl_message_get_numlines(owl_view_get_element(v, i)); |
---|
[7d4fbcd] | 1132 | /* will we run the curmsg off the screen? */ |
---|
| 1133 | if ((foo+y) >= recwinlines) { |
---|
[801b7ac] | 1134 | i++; |
---|
| 1135 | if (i>curmsg) i=curmsg; |
---|
[7d4fbcd] | 1136 | break; |
---|
| 1137 | } |
---|
| 1138 | /* have saved 1/2 the screen space? */ |
---|
| 1139 | y+=foo; |
---|
| 1140 | if (y > (recwinlines / 2)) break; |
---|
| 1141 | } |
---|
[801b7ac] | 1142 | if (i<0) i=0; |
---|
| 1143 | return(i); |
---|
[7d4fbcd] | 1144 | } |
---|
| 1145 | } |
---|
| 1146 | |
---|
| 1147 | if (direction == OWL_DIRECTION_DOWNWARDS || direction == OWL_DIRECTION_NONE) { |
---|
| 1148 | /* If curmsg bottom line is more than 3/4 down the screen then scroll down */ |
---|
| 1149 | if (savey > ((recwinlines * 3)/4)) { |
---|
| 1150 | y=0; |
---|
| 1151 | /* count lines from the top until we can save 1/2 the screen size */ |
---|
[801b7ac] | 1152 | for (i=topmsg; i<curmsg; i++) { |
---|
| 1153 | y+=owl_message_get_numlines(owl_view_get_element(v, i)); |
---|
[7d4fbcd] | 1154 | if (y > (recwinlines / 2)) break; |
---|
| 1155 | } |
---|
[801b7ac] | 1156 | if (i==curmsg) { |
---|
| 1157 | i--; |
---|
[7d4fbcd] | 1158 | } |
---|
[801b7ac] | 1159 | return(i+1); |
---|
[7d4fbcd] | 1160 | } |
---|
| 1161 | } |
---|
[aa2f33b3] | 1162 | |
---|
[f9c43ae] | 1163 | return(topmsg); |
---|
[7d4fbcd] | 1164 | } |
---|
| 1165 | |
---|
[c79a047] | 1166 | void owl_function_resize(void) |
---|
[d54838d] | 1167 | { |
---|
[7d4fbcd] | 1168 | owl_global_set_resize_pending(&g); |
---|
| 1169 | } |
---|
| 1170 | |
---|
[4479497] | 1171 | void G_GNUC_PRINTF(1, 2) owl_function_debugmsg(const char *fmt, ...) |
---|
[d54838d] | 1172 | { |
---|
[7d4fbcd] | 1173 | FILE *file; |
---|
| 1174 | time_t now; |
---|
| 1175 | va_list ap; |
---|
| 1176 | va_start(ap, fmt); |
---|
| 1177 | |
---|
[52761cc] | 1178 | if (!owl_global_is_debug_fast(&g)) |
---|
| 1179 | return; |
---|
[7d4fbcd] | 1180 | |
---|
[d12a8c7] | 1181 | file = owl_global_get_debug_file_handle(&g); |
---|
[52761cc] | 1182 | if (!file) /* XXX should report this */ |
---|
| 1183 | return; |
---|
[7d4fbcd] | 1184 | |
---|
[52761cc] | 1185 | now = time(NULL); |
---|
[7d4fbcd] | 1186 | |
---|
[52761cc] | 1187 | fprintf(file, "[%d - %.24s - %lds]: ", |
---|
| 1188 | (int) getpid(), ctime(&now), now - owl_global_get_starttime(&g)); |
---|
[7d4fbcd] | 1189 | vfprintf(file, fmt, ap); |
---|
[52761cc] | 1190 | putc('\n', file); |
---|
[d12a8c7] | 1191 | fflush(file); |
---|
[7d4fbcd] | 1192 | |
---|
| 1193 | va_end(ap); |
---|
| 1194 | } |
---|
| 1195 | |
---|
[c79a047] | 1196 | void owl_function_beep(void) |
---|
[d54838d] | 1197 | { |
---|
[7d4fbcd] | 1198 | if (owl_global_is_bell(&g)) { |
---|
| 1199 | beep(); |
---|
| 1200 | } |
---|
| 1201 | } |
---|
| 1202 | |
---|
[e19eb97] | 1203 | int owl_function_subscribe(const char *class, const char *inst, const char *recip) |
---|
[d54838d] | 1204 | { |
---|
[7d4fbcd] | 1205 | int ret; |
---|
| 1206 | |
---|
| 1207 | ret=owl_zephyr_sub(class, inst, recip); |
---|
| 1208 | if (ret) { |
---|
[ec6ff52] | 1209 | owl_function_error("Error subscribing."); |
---|
[7d4fbcd] | 1210 | } else { |
---|
| 1211 | owl_function_makemsg("Subscribed."); |
---|
| 1212 | } |
---|
[3617286] | 1213 | return(ret); |
---|
[7d4fbcd] | 1214 | } |
---|
| 1215 | |
---|
[e19eb97] | 1216 | void owl_function_unsubscribe(const char *class, const char *inst, const char *recip) |
---|
[d54838d] | 1217 | { |
---|
[7d4fbcd] | 1218 | int ret; |
---|
| 1219 | |
---|
| 1220 | ret=owl_zephyr_unsub(class, inst, recip); |
---|
| 1221 | if (ret) { |
---|
[ec6ff52] | 1222 | owl_function_error("Error subscribing."); |
---|
[7d4fbcd] | 1223 | } else { |
---|
| 1224 | owl_function_makemsg("Unsubscribed."); |
---|
| 1225 | } |
---|
| 1226 | } |
---|
| 1227 | |
---|
[b343c2c] | 1228 | static void _dirty_everything(gpointer data, gpointer user_data) { |
---|
| 1229 | owl_window *w = data; |
---|
[e8128c5] | 1230 | if (!owl_window_is_realized(w)) |
---|
| 1231 | return; |
---|
| 1232 | owl_window_dirty(w); |
---|
[b343c2c] | 1233 | owl_window_children_foreach(w, _dirty_everything, NULL); |
---|
[7d4fbcd] | 1234 | } |
---|
| 1235 | |
---|
[c79a047] | 1236 | void owl_function_full_redisplay(void) |
---|
[d54838d] | 1237 | { |
---|
[1d81c51] | 1238 | /* Ask every widget to redraw itself. */ |
---|
[b343c2c] | 1239 | _dirty_everything(owl_window_get_screen(), NULL); |
---|
[1d81c51] | 1240 | /* Force ncurses to redisplay everything. */ |
---|
| 1241 | clearok(stdscr, TRUE); |
---|
[7d4fbcd] | 1242 | } |
---|
| 1243 | |
---|
[e19eb97] | 1244 | void owl_function_popless_text(const char *text) |
---|
[d54838d] | 1245 | { |
---|
[7d4fbcd] | 1246 | owl_popwin *pw; |
---|
| 1247 | owl_viewwin *v; |
---|
| 1248 | |
---|
[9eb38bb] | 1249 | if (owl_global_get_popwin(&g) || owl_global_get_viewwin(&g)) { |
---|
[4cf7b1b] | 1250 | owl_function_error("Popwin already in use."); |
---|
| 1251 | return; |
---|
| 1252 | } |
---|
[03ca005] | 1253 | pw = owl_popwin_new(); |
---|
| 1254 | owl_global_set_popwin(&g, pw); |
---|
| 1255 | owl_popwin_up(pw); |
---|
[9eb38bb] | 1256 | |
---|
| 1257 | v = owl_viewwin_new_text(owl_popwin_get_content(pw), text); |
---|
| 1258 | owl_global_set_viewwin(&g, v); |
---|
| 1259 | |
---|
[07b59ea] | 1260 | owl_global_push_context(&g, OWL_CTX_POPLESS, v, "popless", NULL); |
---|
[7d4fbcd] | 1261 | } |
---|
| 1262 | |
---|
[075ba92] | 1263 | void owl_function_popless_fmtext(const owl_fmtext *fm) |
---|
[d54838d] | 1264 | { |
---|
[7d4fbcd] | 1265 | owl_popwin *pw; |
---|
| 1266 | owl_viewwin *v; |
---|
| 1267 | |
---|
[9eb38bb] | 1268 | if (owl_global_get_popwin(&g) || owl_global_get_viewwin(&g)) { |
---|
[4cf7b1b] | 1269 | owl_function_error("Popwin already in use."); |
---|
| 1270 | return; |
---|
| 1271 | } |
---|
[03ca005] | 1272 | pw = owl_popwin_new(); |
---|
| 1273 | owl_global_set_popwin(&g, pw); |
---|
| 1274 | owl_popwin_up(pw); |
---|
[9eb38bb] | 1275 | |
---|
| 1276 | v = owl_viewwin_new_fmtext(owl_popwin_get_content(pw), fm); |
---|
| 1277 | owl_global_set_viewwin(&g, v); |
---|
| 1278 | |
---|
[07b59ea] | 1279 | owl_global_push_context(&g, OWL_CTX_POPLESS, v, "popless", NULL); |
---|
[f17bff98] | 1280 | } |
---|
| 1281 | |
---|
[e19eb97] | 1282 | void owl_function_popless_file(const char *filename) |
---|
[f17bff98] | 1283 | { |
---|
| 1284 | owl_fmtext fm; |
---|
| 1285 | FILE *file; |
---|
[b7ee89b] | 1286 | char *s = NULL; |
---|
[f17bff98] | 1287 | |
---|
| 1288 | file=fopen(filename, "r"); |
---|
| 1289 | if (!file) { |
---|
| 1290 | owl_function_error("Could not open file: %s", filename); |
---|
| 1291 | return; |
---|
| 1292 | } |
---|
| 1293 | |
---|
| 1294 | owl_fmtext_init_null(&fm); |
---|
[b7ee89b] | 1295 | while (owl_getline(&s, file)) |
---|
| 1296 | owl_fmtext_append_normal(&fm, s); |
---|
[ddbbcffa] | 1297 | g_free(s); |
---|
[f17bff98] | 1298 | |
---|
| 1299 | owl_function_popless_fmtext(&fm); |
---|
[7ab0020] | 1300 | owl_fmtext_cleanup(&fm); |
---|
[f17bff98] | 1301 | fclose(file); |
---|
[7d4fbcd] | 1302 | } |
---|
| 1303 | |
---|
[c79a047] | 1304 | void owl_function_about(void) |
---|
[d54838d] | 1305 | { |
---|
[2101a50] | 1306 | owl_function_popless_text( |
---|
[b8a3e00] | 1307 | "This is BarnOwl version " OWL_VERSION_STRING ".\n\n" |
---|
| 1308 | "BarnOwl is a fork of the Owl zephyr client, written and\n" |
---|
[2101a50] | 1309 | "maintained by Alejandro Sedeno and Nelson Elhage at the\n" |
---|
| 1310 | "Massachusetts Institute of Technology. \n" |
---|
| 1311 | "\n" |
---|
| 1312 | "Owl was written by James Kretchmar. The first version, 0.5, was\n" |
---|
| 1313 | "released in March 2002.\n" |
---|
| 1314 | "\n" |
---|
| 1315 | "The name 'owl' was chosen in reference to the owls in the\n" |
---|
| 1316 | "Harry Potter novels, who are tasked with carrying messages\n" |
---|
[b8a3e00] | 1317 | "between Witches and Wizards. The name 'BarnOwl' was chosen\n" |
---|
[2101a50] | 1318 | "because we feel our owls should live closer to our ponies.\n" |
---|
| 1319 | "\n" |
---|
[b03c714] | 1320 | "Copyright (c) 2006-2011 The BarnOwl Developers. All rights reserved.\n" |
---|
[2101a50] | 1321 | "Copyright (c) 2004 James Kretchmar. All rights reserved.\n" |
---|
| 1322 | "Copyright 2002 Massachusetts Institute of Technology\n" |
---|
| 1323 | "\n" |
---|
| 1324 | "This program is free software. You can redistribute it and/or\n" |
---|
| 1325 | "modify under the terms of the Sleepycat License. Use the \n" |
---|
| 1326 | "':show license' command to display the full license\n" |
---|
| 1327 | ); |
---|
[7d4fbcd] | 1328 | } |
---|
| 1329 | |
---|
[c79a047] | 1330 | void owl_function_info(void) |
---|
[d54838d] | 1331 | { |
---|
[c08c70a] | 1332 | const owl_message *m; |
---|
[5789230] | 1333 | owl_fmtext fm, attrfm; |
---|
[9e5c9f3] | 1334 | const owl_view *v; |
---|
[09489b89] | 1335 | #ifdef HAVE_LIBZEPHYR |
---|
[1077891a] | 1336 | const ZNotice_t *n; |
---|
[09489b89] | 1337 | #endif |
---|
[7d4fbcd] | 1338 | |
---|
[d0d65df] | 1339 | owl_fmtext_init_null(&fm); |
---|
| 1340 | |
---|
[7d4fbcd] | 1341 | v=owl_global_get_current_view(&g); |
---|
[5eeea3b] | 1342 | m=owl_view_get_element(v, owl_global_get_curmsg(&g)); |
---|
| 1343 | if (!m || owl_view_get_size(v)==0) { |
---|
[ec6ff52] | 1344 | owl_function_error("No message selected\n"); |
---|
[7d4fbcd] | 1345 | return; |
---|
| 1346 | } |
---|
| 1347 | |
---|
[5789230] | 1348 | owl_fmtext_append_bold(&fm, "General Information:\n"); |
---|
[57609b3] | 1349 | owl_fmtext_appendf_normal(&fm, " Msg Id : %i\n", owl_message_get_id(m)); |
---|
[df0d93a] | 1350 | |
---|
[5789230] | 1351 | owl_fmtext_append_normal(&fm, " Type : "); |
---|
[37eab7f] | 1352 | owl_fmtext_append_bold(&fm, owl_message_get_type(m)); |
---|
[df0d93a] | 1353 | owl_fmtext_append_normal(&fm, "\n"); |
---|
| 1354 | |
---|
[4b464a4] | 1355 | if (owl_message_is_direction_in(m)) { |
---|
[5789230] | 1356 | owl_fmtext_append_normal(&fm, " Direction : in\n"); |
---|
[4b464a4] | 1357 | } else if (owl_message_is_direction_out(m)) { |
---|
[5789230] | 1358 | owl_fmtext_append_normal(&fm, " Direction : out\n"); |
---|
[4b464a4] | 1359 | } else if (owl_message_is_direction_none(m)) { |
---|
[5789230] | 1360 | owl_fmtext_append_normal(&fm, " Direction : none\n"); |
---|
[4b464a4] | 1361 | } else { |
---|
[5789230] | 1362 | owl_fmtext_append_normal(&fm, " Direction : unknown\n"); |
---|
[4b464a4] | 1363 | } |
---|
[df0d93a] | 1364 | |
---|
[57609b3] | 1365 | owl_fmtext_appendf_normal(&fm, " Time : %s\n", owl_message_get_timestr(m)); |
---|
[4b464a4] | 1366 | |
---|
[df0d93a] | 1367 | if (!owl_message_is_type_admin(m)) { |
---|
[57609b3] | 1368 | owl_fmtext_appendf_normal(&fm, " Sender : %s\n", owl_message_get_sender(m)); |
---|
| 1369 | owl_fmtext_appendf_normal(&fm, " Recipient : %s\n", owl_message_get_recipient(m)); |
---|
[df0d93a] | 1370 | } |
---|
[57609b3] | 1371 | |
---|
[0ff8fb57] | 1372 | if (owl_message_is_type_zephyr(m)) { |
---|
[5789230] | 1373 | owl_fmtext_append_bold(&fm, "\nZephyr Specific Information:\n"); |
---|
[0ff8fb57] | 1374 | |
---|
[57609b3] | 1375 | owl_fmtext_appendf_normal(&fm, " Class : %s\n", owl_message_get_class(m)); |
---|
| 1376 | owl_fmtext_appendf_normal(&fm, " Instance : %s\n", owl_message_get_instance(m)); |
---|
| 1377 | owl_fmtext_appendf_normal(&fm, " Opcode : %s\n", owl_message_get_opcode(m)); |
---|
[09489b89] | 1378 | #ifdef HAVE_LIBZEPHYR |
---|
[d0d65df] | 1379 | if (owl_message_is_direction_in(m)) { |
---|
[259e60a8] | 1380 | char *tmpbuff; |
---|
| 1381 | int i, fields; |
---|
[09489b89] | 1382 | |
---|
[d0d65df] | 1383 | n=owl_message_get_notice(m); |
---|
[df0d93a] | 1384 | |
---|
[5a95b69] | 1385 | if (!owl_message_is_pseudo(m)) { |
---|
| 1386 | owl_fmtext_append_normal(&fm, " Kind : "); |
---|
| 1387 | if (n->z_kind==UNSAFE) { |
---|
| 1388 | owl_fmtext_append_normal(&fm, "UNSAFE\n"); |
---|
| 1389 | } else if (n->z_kind==UNACKED) { |
---|
| 1390 | owl_fmtext_append_normal(&fm, "UNACKED\n"); |
---|
| 1391 | } else if (n->z_kind==ACKED) { |
---|
| 1392 | owl_fmtext_append_normal(&fm, "ACKED\n"); |
---|
| 1393 | } else if (n->z_kind==HMACK) { |
---|
| 1394 | owl_fmtext_append_normal(&fm, "HMACK\n"); |
---|
| 1395 | } else if (n->z_kind==HMCTL) { |
---|
| 1396 | owl_fmtext_append_normal(&fm, "HMCTL\n"); |
---|
| 1397 | } else if (n->z_kind==SERVACK) { |
---|
| 1398 | owl_fmtext_append_normal(&fm, "SERVACK\n"); |
---|
| 1399 | } else if (n->z_kind==SERVNAK) { |
---|
| 1400 | owl_fmtext_append_normal(&fm, "SERVNACK\n"); |
---|
| 1401 | } else if (n->z_kind==CLIENTACK) { |
---|
| 1402 | owl_fmtext_append_normal(&fm, "CLIENTACK\n"); |
---|
| 1403 | } else if (n->z_kind==STAT) { |
---|
| 1404 | owl_fmtext_append_normal(&fm, "STAT\n"); |
---|
| 1405 | } else { |
---|
| 1406 | owl_fmtext_append_normal(&fm, "ILLEGAL VALUE\n"); |
---|
| 1407 | } |
---|
[d0d65df] | 1408 | } |
---|
[57609b3] | 1409 | owl_fmtext_appendf_normal(&fm, " Host : %s\n", owl_message_get_hostname(m)); |
---|
[5a95b69] | 1410 | |
---|
| 1411 | if (!owl_message_is_pseudo(m)) { |
---|
| 1412 | owl_fmtext_append_normal(&fm, "\n"); |
---|
[57609b3] | 1413 | owl_fmtext_appendf_normal(&fm, " Port : %i\n", ntohs(n->z_port)); |
---|
[f12d199] | 1414 | owl_fmtext_appendf_normal(&fm, " Auth : %s\n", owl_zephyr_get_authstr(n)); |
---|
[57609b3] | 1415 | |
---|
| 1416 | /* FIXME make these more descriptive */ |
---|
[f12d199] | 1417 | owl_fmtext_appendf_normal(&fm, " Checkd Ath: %i\n", n->z_checked_auth); |
---|
[57609b3] | 1418 | owl_fmtext_appendf_normal(&fm, " Multi notc: %s\n", n->z_multinotice); |
---|
| 1419 | owl_fmtext_appendf_normal(&fm, " Num other : %i\n", n->z_num_other_fields); |
---|
| 1420 | owl_fmtext_appendf_normal(&fm, " Msg Len : %i\n", n->z_message_len); |
---|
[5a95b69] | 1421 | |
---|
| 1422 | fields=owl_zephyr_get_num_fields(n); |
---|
[57609b3] | 1423 | owl_fmtext_appendf_normal(&fm, " Fields : %i\n", fields); |
---|
| 1424 | |
---|
[259e60a8] | 1425 | for (i = 0; i < fields; i++) { |
---|
| 1426 | tmpbuff = owl_zephyr_get_field_as_utf8(n, i + 1); |
---|
| 1427 | |
---|
| 1428 | g_strdelimit(tmpbuff, "\n", '~'); |
---|
| 1429 | g_strdelimit(tmpbuff, "\r", '!'); |
---|
| 1430 | |
---|
| 1431 | owl_fmtext_appendf_normal(&fm, " Field %i : %s\n", i + 1, tmpbuff); |
---|
| 1432 | g_free(tmpbuff); |
---|
[5a95b69] | 1433 | } |
---|
[57609b3] | 1434 | owl_fmtext_appendf_normal(&fm, " Default Fm: %s\n", n->z_default_format); |
---|
[d0d65df] | 1435 | } |
---|
[57609b3] | 1436 | |
---|
[7d4fbcd] | 1437 | } |
---|
[57609b3] | 1438 | #endif |
---|
[7d4fbcd] | 1439 | } |
---|
[0ff8fb57] | 1440 | |
---|
[5789230] | 1441 | owl_fmtext_append_bold(&fm, "\nOwl Message Attributes:\n"); |
---|
| 1442 | owl_message_attributes_tofmtext(m, &attrfm); |
---|
| 1443 | owl_fmtext_append_fmtext(&fm, &attrfm); |
---|
[d0d65df] | 1444 | |
---|
| 1445 | owl_function_popless_fmtext(&fm); |
---|
[7ab0020] | 1446 | owl_fmtext_cleanup(&fm); |
---|
| 1447 | owl_fmtext_cleanup(&attrfm); |
---|
[7d4fbcd] | 1448 | } |
---|
| 1449 | |
---|
[5639bf2] | 1450 | /* print the current message in a popup window. |
---|
| 1451 | * Use the 'default' style regardless of whatever |
---|
| 1452 | * style the user may be using |
---|
| 1453 | */ |
---|
[c79a047] | 1454 | void owl_function_curmsg_to_popwin(void) |
---|
[d54838d] | 1455 | { |
---|
[9e5c9f3] | 1456 | const owl_view *v; |
---|
[c08c70a] | 1457 | const owl_message *m; |
---|
[1fdab04] | 1458 | const owl_style *s; |
---|
[5639bf2] | 1459 | owl_fmtext fm; |
---|
[7d4fbcd] | 1460 | |
---|
[5639bf2] | 1461 | v=owl_global_get_current_view(&g); |
---|
| 1462 | s=owl_global_get_style_by_name(&g, "default"); |
---|
[7d4fbcd] | 1463 | |
---|
[5eeea3b] | 1464 | m=owl_view_get_element(v, owl_global_get_curmsg(&g)); |
---|
| 1465 | |
---|
| 1466 | if (!m || owl_view_get_size(v)==0) { |
---|
[ec6ff52] | 1467 | owl_function_error("No current message"); |
---|
[7d4fbcd] | 1468 | return; |
---|
| 1469 | } |
---|
| 1470 | |
---|
[5639bf2] | 1471 | owl_fmtext_init_null(&fm); |
---|
| 1472 | owl_style_get_formattext(s, &fm, m); |
---|
| 1473 | |
---|
| 1474 | owl_function_popless_fmtext(&fm); |
---|
[7ab0020] | 1475 | owl_fmtext_cleanup(&fm); |
---|
[7d4fbcd] | 1476 | } |
---|
| 1477 | |
---|
[d54838d] | 1478 | void owl_function_page_curmsg(int step) |
---|
| 1479 | { |
---|
[7d4fbcd] | 1480 | /* scroll down or up within the current message IF the message is truncated */ |
---|
| 1481 | |
---|
| 1482 | int offset, curmsg, lines; |
---|
[9e5c9f3] | 1483 | const owl_view *v; |
---|
[7d4fbcd] | 1484 | owl_message *m; |
---|
| 1485 | |
---|
| 1486 | offset=owl_global_get_curmsg_vert_offset(&g); |
---|
| 1487 | v=owl_global_get_current_view(&g); |
---|
| 1488 | curmsg=owl_global_get_curmsg(&g); |
---|
| 1489 | m=owl_view_get_element(v, curmsg); |
---|
[5eeea3b] | 1490 | if (!m || owl_view_get_size(v)==0) return; |
---|
[7d4fbcd] | 1491 | lines=owl_message_get_numlines(m); |
---|
| 1492 | |
---|
| 1493 | if (offset==0) { |
---|
| 1494 | /* Bail if the curmsg isn't the last one displayed */ |
---|
| 1495 | if (curmsg != owl_mainwin_get_last_msg(owl_global_get_mainwin(&g))) { |
---|
[f51bc78] | 1496 | owl_function_makemsg("The entire message is already displayed"); |
---|
[7d4fbcd] | 1497 | return; |
---|
| 1498 | } |
---|
| 1499 | |
---|
| 1500 | /* Bail if we're not truncated */ |
---|
| 1501 | if (!owl_mainwin_is_curmsg_truncated(owl_global_get_mainwin(&g))) { |
---|
[f51bc78] | 1502 | owl_function_makemsg("The entire message is already displayed"); |
---|
[7d4fbcd] | 1503 | return; |
---|
| 1504 | } |
---|
| 1505 | } |
---|
| 1506 | |
---|
| 1507 | |
---|
| 1508 | /* don't scroll past the last line */ |
---|
| 1509 | if (step>0) { |
---|
| 1510 | if (offset+step > lines-1) { |
---|
| 1511 | owl_global_set_curmsg_vert_offset(&g, lines-1); |
---|
| 1512 | } else { |
---|
| 1513 | owl_global_set_curmsg_vert_offset(&g, offset+step); |
---|
| 1514 | } |
---|
| 1515 | } |
---|
| 1516 | |
---|
| 1517 | /* would we be before the beginning of the message? */ |
---|
| 1518 | if (step<0) { |
---|
| 1519 | if (offset+step<0) { |
---|
| 1520 | owl_global_set_curmsg_vert_offset(&g, 0); |
---|
| 1521 | } else { |
---|
| 1522 | owl_global_set_curmsg_vert_offset(&g, offset+step); |
---|
| 1523 | } |
---|
| 1524 | } |
---|
| 1525 | |
---|
| 1526 | /* redisplay */ |
---|
| 1527 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 1528 | } |
---|
| 1529 | |
---|
[d54838d] | 1530 | void owl_function_resize_typwin(int newsize) |
---|
| 1531 | { |
---|
[7d4fbcd] | 1532 | owl_global_set_typwin_lines(&g, newsize); |
---|
[f6fae8d] | 1533 | owl_mainpanel_layout_contents(&g.mainpanel); |
---|
[7d4fbcd] | 1534 | } |
---|
| 1535 | |
---|
[c79a047] | 1536 | void owl_function_mainwin_pagedown(void) |
---|
[d54838d] | 1537 | { |
---|
[7d4fbcd] | 1538 | int i; |
---|
| 1539 | |
---|
| 1540 | i=owl_mainwin_get_last_msg(owl_global_get_mainwin(&g)); |
---|
| 1541 | if (i<0) return; |
---|
[f2e36b5] | 1542 | if (owl_mainwin_is_last_msg_truncated(owl_global_get_mainwin(&g)) |
---|
| 1543 | && (owl_global_get_curmsg(&g) < i) |
---|
| 1544 | && (i>0)) { |
---|
| 1545 | i--; |
---|
| 1546 | } |
---|
[7d4fbcd] | 1547 | owl_global_set_curmsg(&g, i); |
---|
| 1548 | owl_function_nextmsg(); |
---|
| 1549 | } |
---|
| 1550 | |
---|
[c79a047] | 1551 | void owl_function_mainwin_pageup(void) |
---|
[d54838d] | 1552 | { |
---|
[7d4fbcd] | 1553 | owl_global_set_curmsg(&g, owl_global_get_topmsg(&g)); |
---|
| 1554 | owl_function_prevmsg(); |
---|
| 1555 | } |
---|
| 1556 | |
---|
[c79a047] | 1557 | void owl_function_getsubs(void) |
---|
[d54838d] | 1558 | { |
---|
[09489b89] | 1559 | char *buff; |
---|
[7d4fbcd] | 1560 | |
---|
[09489b89] | 1561 | buff=owl_zephyr_getsubs(); |
---|
[7d4fbcd] | 1562 | |
---|
[09489b89] | 1563 | if (buff) { |
---|
| 1564 | owl_function_popless_text(buff); |
---|
| 1565 | } else { |
---|
| 1566 | owl_function_popless_text("Error getting subscriptions"); |
---|
[7d4fbcd] | 1567 | } |
---|
[09489b89] | 1568 | |
---|
[ddbbcffa] | 1569 | g_free(buff); |
---|
[7d4fbcd] | 1570 | } |
---|
| 1571 | |
---|
[c79a047] | 1572 | void owl_function_printallvars(void) |
---|
[d54838d] | 1573 | { |
---|
[e19eb97] | 1574 | const char *name; |
---|
[010a951] | 1575 | char *var; |
---|
[ce68f23] | 1576 | GPtrArray *varnames; |
---|
| 1577 | int i; |
---|
[b4c270c] | 1578 | GString *str = g_string_new(""); |
---|
[7d4fbcd] | 1579 | |
---|
[b4c270c] | 1580 | g_string_append_printf(str, "%-20s = %s\n", "VARIABLE", "VALUE"); |
---|
| 1581 | g_string_append_printf(str, "%-20s %s\n", "--------", "-----"); |
---|
[ce68f23] | 1582 | varnames = owl_variable_dict_get_names(owl_global_get_vardict(&g)); |
---|
| 1583 | for (i = 0; i < varnames->len; i++) { |
---|
| 1584 | name = varnames->pdata[i]; |
---|
[7d4fbcd] | 1585 | if (name && name[0]!='_') { |
---|
[b4c270c] | 1586 | g_string_append_printf(str, "\n%-20s = ", name); |
---|
[010a951] | 1587 | var = owl_variable_get_tostring(owl_global_get_vardict(&g), name); |
---|
| 1588 | if (var) { |
---|
| 1589 | g_string_append(str, var); |
---|
| 1590 | g_free(var); |
---|
| 1591 | } |
---|
[7d4fbcd] | 1592 | } |
---|
| 1593 | } |
---|
[b4c270c] | 1594 | g_string_append(str, "\n"); |
---|
[ce68f23] | 1595 | owl_ptr_array_free(varnames, g_free); |
---|
[b4c270c] | 1596 | |
---|
| 1597 | owl_function_popless_text(str->str); |
---|
[d222c44] | 1598 | g_string_free(str, true); |
---|
[7d4fbcd] | 1599 | } |
---|
| 1600 | |
---|
[c79a047] | 1601 | void owl_function_show_variables(void) |
---|
[d54838d] | 1602 | { |
---|
[ce68f23] | 1603 | GPtrArray *varnames; |
---|
[7d4fbcd] | 1604 | owl_fmtext fm; |
---|
[ce68f23] | 1605 | int i; |
---|
[e19eb97] | 1606 | const char *varname; |
---|
[7d4fbcd] | 1607 | |
---|
| 1608 | owl_fmtext_init_null(&fm); |
---|
| 1609 | owl_fmtext_append_bold(&fm, |
---|
| 1610 | "Variables: (use 'show variable <name>' for details)\n"); |
---|
[ce68f23] | 1611 | varnames = owl_variable_dict_get_names(owl_global_get_vardict(&g)); |
---|
| 1612 | for (i = 0; i < varnames->len; i++) { |
---|
| 1613 | varname = varnames->pdata[i]; |
---|
[7d4fbcd] | 1614 | if (varname && varname[0]!='_') { |
---|
[aa2f33b3] | 1615 | owl_variable_describe(owl_global_get_vardict(&g), varname, &fm); |
---|
[7d4fbcd] | 1616 | } |
---|
| 1617 | } |
---|
[ce68f23] | 1618 | owl_ptr_array_free(varnames, g_free); |
---|
[7d4fbcd] | 1619 | owl_function_popless_fmtext(&fm); |
---|
[7ab0020] | 1620 | owl_fmtext_cleanup(&fm); |
---|
[7d4fbcd] | 1621 | } |
---|
| 1622 | |
---|
[e19eb97] | 1623 | void owl_function_show_variable(const char *name) |
---|
[d54838d] | 1624 | { |
---|
[7d4fbcd] | 1625 | owl_fmtext fm; |
---|
| 1626 | |
---|
| 1627 | owl_fmtext_init_null(&fm); |
---|
| 1628 | owl_variable_get_help(owl_global_get_vardict(&g), name, &fm); |
---|
| 1629 | owl_function_popless_fmtext(&fm); |
---|
[7ab0020] | 1630 | owl_fmtext_cleanup(&fm); |
---|
[7d4fbcd] | 1631 | } |
---|
| 1632 | |
---|
| 1633 | /* note: this applies to global message list, not to view. |
---|
| 1634 | * If flag is 1, deletes. If flag is 0, undeletes. */ |
---|
[d54838d] | 1635 | void owl_function_delete_by_id(int id, int flag) |
---|
| 1636 | { |
---|
[3eb599d] | 1637 | const owl_messagelist *ml; |
---|
[7d4fbcd] | 1638 | owl_message *m; |
---|
| 1639 | ml = owl_global_get_msglist(&g); |
---|
| 1640 | m = owl_messagelist_get_by_id(ml, id); |
---|
| 1641 | if (m) { |
---|
| 1642 | if (flag == 1) { |
---|
| 1643 | owl_message_mark_delete(m); |
---|
| 1644 | } else if (flag == 0) { |
---|
| 1645 | owl_message_unmark_delete(m); |
---|
| 1646 | } |
---|
| 1647 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 1648 | } else { |
---|
[ec6ff52] | 1649 | owl_function_error("No message with id %d: unable to mark for (un)delete",id); |
---|
[7d4fbcd] | 1650 | } |
---|
| 1651 | } |
---|
| 1652 | |
---|
[c79a047] | 1653 | void owl_function_delete_automsgs(void) |
---|
[d54838d] | 1654 | { |
---|
[7d4fbcd] | 1655 | /* mark for deletion all messages in the current view that match the |
---|
| 1656 | * 'trash' filter */ |
---|
| 1657 | |
---|
| 1658 | int i, j, count; |
---|
| 1659 | owl_message *m; |
---|
[9e5c9f3] | 1660 | const owl_view *v; |
---|
[4542047] | 1661 | const owl_filter *f; |
---|
[7d4fbcd] | 1662 | |
---|
| 1663 | /* get the trash filter */ |
---|
| 1664 | f=owl_global_get_filter(&g, "trash"); |
---|
| 1665 | if (!f) { |
---|
[ec6ff52] | 1666 | owl_function_error("No trash filter defined"); |
---|
[7d4fbcd] | 1667 | return; |
---|
| 1668 | } |
---|
| 1669 | |
---|
| 1670 | v=owl_global_get_current_view(&g); |
---|
| 1671 | |
---|
| 1672 | count=0; |
---|
| 1673 | j=owl_view_get_size(v); |
---|
| 1674 | for (i=0; i<j; i++) { |
---|
| 1675 | m=owl_view_get_element(v, i); |
---|
| 1676 | if (owl_filter_message_match(f, m)) { |
---|
| 1677 | count++; |
---|
| 1678 | owl_message_mark_delete(m); |
---|
| 1679 | } |
---|
| 1680 | } |
---|
| 1681 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
[1c6c4d3] | 1682 | owl_function_makemsg("%i messages marked for deletion", count); |
---|
[7d4fbcd] | 1683 | } |
---|
| 1684 | |
---|
[c79a047] | 1685 | void owl_function_status(void) |
---|
[d54838d] | 1686 | { |
---|
[49a8434] | 1687 | char buff[MAXPATHLEN+1]; |
---|
[7d4fbcd] | 1688 | time_t start; |
---|
| 1689 | int up, days, hours, minutes; |
---|
[a352335c] | 1690 | owl_fmtext fm; |
---|
| 1691 | |
---|
| 1692 | owl_fmtext_init_null(&fm); |
---|
[7d4fbcd] | 1693 | |
---|
| 1694 | start=owl_global_get_starttime(&g); |
---|
| 1695 | |
---|
[d9b0b972] | 1696 | owl_fmtext_append_normal(&fm, "General Information:\n"); |
---|
| 1697 | |
---|
| 1698 | owl_fmtext_append_normal(&fm, " Version: "); |
---|
[a352335c] | 1699 | owl_fmtext_append_normal(&fm, OWL_VERSION_STRING); |
---|
| 1700 | owl_fmtext_append_normal(&fm, "\n"); |
---|
| 1701 | |
---|
[cdd3959] | 1702 | owl_fmtext_append_normal(&fm, " Startup Arguments: "); |
---|
[a352335c] | 1703 | owl_fmtext_append_normal(&fm, owl_global_get_startupargs(&g)); |
---|
| 1704 | owl_fmtext_append_normal(&fm, "\n"); |
---|
[b6a7367] | 1705 | |
---|
| 1706 | owl_fmtext_append_normal(&fm, " Current Directory: "); |
---|
[49a8434] | 1707 | if(getcwd(buff, MAXPATHLEN) == NULL) { |
---|
| 1708 | owl_fmtext_append_normal(&fm, "<Error in getcwd>"); |
---|
| 1709 | } else { |
---|
| 1710 | owl_fmtext_append_normal(&fm, buff); |
---|
| 1711 | } |
---|
[b6a7367] | 1712 | owl_fmtext_append_normal(&fm, "\n"); |
---|
| 1713 | |
---|
[c1d166b] | 1714 | owl_fmtext_appendf_normal(&fm, " Startup Time: %s", ctime(&start)); |
---|
[7d4fbcd] | 1715 | |
---|
| 1716 | up=owl_global_get_runtime(&g); |
---|
| 1717 | days=up/86400; |
---|
| 1718 | up-=days*86400; |
---|
| 1719 | hours=up/3600; |
---|
| 1720 | up-=hours*3600; |
---|
| 1721 | minutes=up/60; |
---|
| 1722 | up-=minutes*60; |
---|
[c1d166b] | 1723 | owl_fmtext_appendf_normal(&fm, " Run Time: %i days %2.2i:%2.2i:%2.2i\n", days, hours, minutes, up); |
---|
[7d4fbcd] | 1724 | |
---|
[d9b0b972] | 1725 | owl_fmtext_append_normal(&fm, "\nProtocol Options:\n"); |
---|
| 1726 | owl_fmtext_append_normal(&fm, " Zephyr included : "); |
---|
| 1727 | if (owl_global_is_havezephyr(&g)) { |
---|
| 1728 | owl_fmtext_append_normal(&fm, "yes\n"); |
---|
[7d4fbcd] | 1729 | } else { |
---|
[d9b0b972] | 1730 | owl_fmtext_append_normal(&fm, "no\n"); |
---|
[7d4fbcd] | 1731 | } |
---|
[d9b0b972] | 1732 | owl_fmtext_append_normal(&fm, " AIM included : yes\n"); |
---|
| 1733 | owl_fmtext_append_normal(&fm, " Loopback included : yes\n"); |
---|
| 1734 | |
---|
[8262340] | 1735 | |
---|
[d9b0b972] | 1736 | owl_fmtext_append_normal(&fm, "\nBuild Options:\n"); |
---|
| 1737 | owl_fmtext_append_normal(&fm, " Stderr redirection : "); |
---|
| 1738 | #if OWL_STDERR_REDIR |
---|
| 1739 | owl_fmtext_append_normal(&fm, "yes\n"); |
---|
| 1740 | #else |
---|
| 1741 | owl_fmtext_append_normal(&fm, "no\n"); |
---|
| 1742 | #endif |
---|
| 1743 | |
---|
| 1744 | |
---|
| 1745 | owl_fmtext_append_normal(&fm, "\nAIM Status:\n"); |
---|
| 1746 | owl_fmtext_append_normal(&fm, " Logged in: "); |
---|
[a352335c] | 1747 | if (owl_global_is_aimloggedin(&g)) { |
---|
| 1748 | owl_fmtext_append_normal(&fm, owl_global_get_aim_screenname(&g)); |
---|
| 1749 | owl_fmtext_append_normal(&fm, "\n"); |
---|
| 1750 | } else { |
---|
[d9b0b972] | 1751 | owl_fmtext_append_normal(&fm, "(not logged in)\n"); |
---|
[a352335c] | 1752 | } |
---|
[d9b0b972] | 1753 | |
---|
| 1754 | owl_fmtext_append_normal(&fm, " Processing events: "); |
---|
[a352335c] | 1755 | if (owl_global_is_doaimevents(&g)) { |
---|
[d9b0b972] | 1756 | owl_fmtext_append_normal(&fm, "yes\n"); |
---|
[a352335c] | 1757 | } else { |
---|
[d9b0b972] | 1758 | owl_fmtext_append_normal(&fm, "no\n"); |
---|
[a352335c] | 1759 | } |
---|
| 1760 | |
---|
| 1761 | owl_function_popless_fmtext(&fm); |
---|
[7ab0020] | 1762 | owl_fmtext_cleanup(&fm); |
---|
[7d4fbcd] | 1763 | } |
---|
| 1764 | |
---|
[c79a047] | 1765 | void owl_function_show_term(void) |
---|
[d54838d] | 1766 | { |
---|
[7d4fbcd] | 1767 | owl_fmtext fm; |
---|
| 1768 | |
---|
| 1769 | owl_fmtext_init_null(&fm); |
---|
[c1d166b] | 1770 | owl_fmtext_appendf_normal(&fm, "Terminal Lines: %i\nTerminal Columns: %i\n", |
---|
[7d4fbcd] | 1771 | owl_global_get_lines(&g), |
---|
| 1772 | owl_global_get_cols(&g)); |
---|
| 1773 | |
---|
[7b4f3be] | 1774 | if (has_colors()) { |
---|
[7d4fbcd] | 1775 | owl_fmtext_append_normal(&fm, "Color: Yes\n"); |
---|
[9efa5bd] | 1776 | owl_fmtext_appendf_normal(&fm, "Number of color pairs: %i\n", owl_util_get_colorpairs()); |
---|
[c1d166b] | 1777 | owl_fmtext_appendf_normal(&fm, "Can change colors: %s\n", can_change_color() ? "yes" : "no"); |
---|
[7d4fbcd] | 1778 | } else { |
---|
| 1779 | owl_fmtext_append_normal(&fm, "Color: No\n"); |
---|
| 1780 | } |
---|
| 1781 | |
---|
| 1782 | owl_function_popless_fmtext(&fm); |
---|
[7ab0020] | 1783 | owl_fmtext_cleanup(&fm); |
---|
[7d4fbcd] | 1784 | } |
---|
| 1785 | |
---|
[e7cc1c3] | 1786 | /* if type = 0 then normal reply. |
---|
| 1787 | * if type = 1 then it's a reply to sender |
---|
| 1788 | * if enter = 0 then allow the command to be edited |
---|
| 1789 | * if enter = 1 then don't wait for editing |
---|
| 1790 | */ |
---|
[d54838d] | 1791 | void owl_function_reply(int type, int enter) |
---|
| 1792 | { |
---|
[740d5f7] | 1793 | char *buff=NULL; |
---|
[c08c70a] | 1794 | const owl_message *m; |
---|
[4542047] | 1795 | const owl_filter *f; |
---|
[7d4fbcd] | 1796 | |
---|
| 1797 | if (owl_view_get_size(owl_global_get_current_view(&g))==0) { |
---|
[ec6ff52] | 1798 | owl_function_error("No message selected"); |
---|
[7d4fbcd] | 1799 | } else { |
---|
[5ebc202] | 1800 | char *cmd; |
---|
[7d4fbcd] | 1801 | |
---|
| 1802 | m=owl_view_get_element(owl_global_get_current_view(&g), owl_global_get_curmsg(&g)); |
---|
[5eeea3b] | 1803 | if (!m) { |
---|
[ec6ff52] | 1804 | owl_function_error("No message selected"); |
---|
[5eeea3b] | 1805 | return; |
---|
| 1806 | } |
---|
| 1807 | |
---|
[7d4fbcd] | 1808 | /* first check if we catch the reply-lockout filter */ |
---|
| 1809 | f=owl_global_get_filter(&g, "reply-lockout"); |
---|
| 1810 | if (f) { |
---|
| 1811 | if (owl_filter_message_match(f, m)) { |
---|
[ec6ff52] | 1812 | owl_function_error("Sorry, replies to this message have been disabled by the reply-lockout filter"); |
---|
[7d4fbcd] | 1813 | return; |
---|
| 1814 | } |
---|
| 1815 | } |
---|
[4b464a4] | 1816 | |
---|
[2c09826] | 1817 | /* then check if it's a question and just bring up the command prompt */ |
---|
| 1818 | if (owl_message_is_question(m)) { |
---|
| 1819 | owl_function_start_command(""); |
---|
| 1820 | return; |
---|
| 1821 | } |
---|
| 1822 | |
---|
[740d5f7] | 1823 | if((type == 0 && |
---|
| 1824 | (cmd=owl_perlconfig_message_call_method(m, "replycmd", 0, NULL))) || |
---|
| 1825 | (type == 1 && |
---|
| 1826 | (cmd=owl_perlconfig_message_call_method(m, "replysendercmd", 0, NULL)))) { |
---|
| 1827 | buff = cmd; |
---|
[d09e5a1] | 1828 | } |
---|
[1b6b2f3] | 1829 | |
---|
[e0540e4] | 1830 | if(!buff) { |
---|
| 1831 | owl_function_error("I don't know how to reply to that message."); |
---|
| 1832 | return; |
---|
| 1833 | } |
---|
[740d5f7] | 1834 | |
---|
[d09e5a1] | 1835 | if (enter) { |
---|
| 1836 | owl_history *hist = owl_global_get_cmd_history(&g); |
---|
[b470451] | 1837 | owl_history_store(hist, buff, false); |
---|
[d09e5a1] | 1838 | owl_function_command_norv(buff); |
---|
| 1839 | } else { |
---|
| 1840 | owl_function_start_command(buff); |
---|
[7d4fbcd] | 1841 | } |
---|
[ddbbcffa] | 1842 | g_free(buff); |
---|
[7d4fbcd] | 1843 | } |
---|
| 1844 | } |
---|
| 1845 | |
---|
[e19eb97] | 1846 | void owl_function_zlocate(int argc, const char *const *argv, int auth) |
---|
[d54838d] | 1847 | { |
---|
[2527615] | 1848 | owl_fmtext fm; |
---|
[dca3b27] | 1849 | char *ptr; |
---|
| 1850 | char *result; |
---|
[2527615] | 1851 | int i; |
---|
| 1852 | |
---|
| 1853 | owl_fmtext_init_null(&fm); |
---|
[7d4fbcd] | 1854 | |
---|
[2527615] | 1855 | for (i=0; i<argc; i++) { |
---|
[dca3b27] | 1856 | ptr = long_zuser(argv[i]); |
---|
| 1857 | result = owl_zephyr_zlocate(ptr, auth); |
---|
| 1858 | owl_fmtext_append_normal(&fm, result); |
---|
[ddbbcffa] | 1859 | g_free(result); |
---|
| 1860 | g_free(ptr); |
---|
[7d4fbcd] | 1861 | } |
---|
| 1862 | |
---|
[2527615] | 1863 | owl_function_popless_fmtext(&fm); |
---|
[7ab0020] | 1864 | owl_fmtext_cleanup(&fm); |
---|
[7d4fbcd] | 1865 | } |
---|
| 1866 | |
---|
[5934b87] | 1867 | void owl_callback_command(owl_editwin *e) |
---|
| 1868 | { |
---|
| 1869 | char *rv; |
---|
| 1870 | const char *line = owl_editwin_get_text(e); |
---|
| 1871 | |
---|
| 1872 | rv = owl_function_command(line); |
---|
| 1873 | if (rv) { |
---|
| 1874 | owl_function_makemsg("%s", rv); |
---|
[ddbbcffa] | 1875 | g_free(rv); |
---|
[5934b87] | 1876 | } |
---|
| 1877 | } |
---|
| 1878 | |
---|
[e19eb97] | 1879 | void owl_function_start_command(const char *line) |
---|
[d54838d] | 1880 | { |
---|
[7d4fbcd] | 1881 | owl_editwin *tw; |
---|
[c394de8] | 1882 | owl_context *ctx; |
---|
[7d4fbcd] | 1883 | |
---|
[58d47ca] | 1884 | tw = owl_global_set_typwin_active(&g, OWL_EDITWIN_STYLE_ONELINE, owl_global_get_cmd_history(&g)); |
---|
[10b866d] | 1885 | |
---|
[7d4fbcd] | 1886 | owl_editwin_set_locktext(tw, "command: "); |
---|
| 1887 | |
---|
[47519e1b] | 1888 | owl_editwin_insert_string(tw, line); |
---|
[cf83b7a] | 1889 | |
---|
[4a41f16] | 1890 | ctx = owl_editcontext_new(OWL_CTX_EDITLINE, tw, "editline", |
---|
| 1891 | owl_global_deactivate_editcontext, &g); |
---|
[c394de8] | 1892 | owl_global_push_context_obj(&g, ctx); |
---|
[5934b87] | 1893 | owl_editwin_set_callback(tw, owl_callback_command); |
---|
[cf83b7a] | 1894 | } |
---|
| 1895 | |
---|
[6829afc] | 1896 | CALLER_OWN owl_editwin *owl_function_start_question(const char *line) |
---|
[cf83b7a] | 1897 | { |
---|
| 1898 | owl_editwin *tw; |
---|
[c394de8] | 1899 | owl_context *ctx; |
---|
[cf83b7a] | 1900 | |
---|
[58d47ca] | 1901 | tw = owl_global_set_typwin_active(&g, OWL_EDITWIN_STYLE_ONELINE, owl_global_get_cmd_history(&g)); |
---|
[cf83b7a] | 1902 | |
---|
| 1903 | owl_editwin_set_locktext(tw, line); |
---|
| 1904 | |
---|
[4a41f16] | 1905 | ctx = owl_editcontext_new(OWL_CTX_EDITRESPONSE, tw, "editresponse", |
---|
| 1906 | owl_global_deactivate_editcontext, &g); |
---|
[c394de8] | 1907 | owl_global_push_context_obj(&g, ctx); |
---|
[9186c75] | 1908 | return tw; |
---|
[7d4fbcd] | 1909 | } |
---|
| 1910 | |
---|
[6829afc] | 1911 | CALLER_OWN owl_editwin *owl_function_start_password(const char *line) |
---|
[453bd70] | 1912 | { |
---|
| 1913 | owl_editwin *tw; |
---|
[c394de8] | 1914 | owl_context *ctx; |
---|
[453bd70] | 1915 | |
---|
[58d47ca] | 1916 | tw = owl_global_set_typwin_active(&g, OWL_EDITWIN_STYLE_ONELINE, NULL); |
---|
| 1917 | |
---|
[453bd70] | 1918 | owl_editwin_set_echochar(tw, '*'); |
---|
| 1919 | |
---|
| 1920 | owl_editwin_set_locktext(tw, line); |
---|
| 1921 | |
---|
[4a41f16] | 1922 | ctx = owl_editcontext_new(OWL_CTX_EDITRESPONSE, tw, "editresponse", |
---|
| 1923 | owl_global_deactivate_editcontext, &g); |
---|
[c394de8] | 1924 | owl_global_push_context_obj(&g, ctx); |
---|
[9186c75] | 1925 | return tw; |
---|
[453bd70] | 1926 | } |
---|
| 1927 | |
---|
[6829afc] | 1928 | CALLER_OWN char *owl_function_exec(int argc, const char *const *argv, const char *buff, int type) |
---|
[d54838d] | 1929 | { |
---|
[7d4fbcd] | 1930 | /* if type == 1 display in a popup |
---|
| 1931 | * if type == 2 display an admin messages |
---|
| 1932 | * if type == 0 return output |
---|
| 1933 | * else display in a popup |
---|
| 1934 | */ |
---|
[e19eb97] | 1935 | const char *redirect = " 2>&1 < /dev/null"; |
---|
[65b2173] | 1936 | char *newbuff; |
---|
[b7ee89b] | 1937 | char *out; |
---|
[7d4fbcd] | 1938 | FILE *p; |
---|
| 1939 | |
---|
[2a2bb60] | 1940 | #if OWL_STDERR_REDIR |
---|
| 1941 | redirect = " < /dev/null"; |
---|
| 1942 | #endif |
---|
| 1943 | |
---|
[7d4fbcd] | 1944 | if (argc<2) { |
---|
[ec6ff52] | 1945 | owl_function_error("Wrong number of arguments to the exec command"); |
---|
[7d4fbcd] | 1946 | return NULL; |
---|
| 1947 | } |
---|
| 1948 | |
---|
| 1949 | buff = skiptokens(buff, 1); |
---|
[1a30f05] | 1950 | newbuff = g_strdup_printf("exec%s; %s", redirect, buff); |
---|
[7d4fbcd] | 1951 | |
---|
[7ba9e0de] | 1952 | if (type == OWL_OUTPUT_POPUP) { |
---|
[afbf668] | 1953 | owl_popexec_new(newbuff); |
---|
[7d4fbcd] | 1954 | } else { |
---|
[b7ee89b] | 1955 | p = popen(newbuff, "r"); |
---|
| 1956 | out = owl_slurp(p); |
---|
[afbf668] | 1957 | pclose(p); |
---|
| 1958 | |
---|
[2cfc6d7] | 1959 | if (type == OWL_OUTPUT_RETURN) { |
---|
[ddbbcffa] | 1960 | g_free(newbuff); |
---|
[afbf668] | 1961 | return out; |
---|
[7ba9e0de] | 1962 | } else if (type == OWL_OUTPUT_ADMINMSG) { |
---|
[afbf668] | 1963 | owl_function_adminmsg(buff, out); |
---|
| 1964 | } |
---|
[ddbbcffa] | 1965 | g_free(out); |
---|
[7d4fbcd] | 1966 | } |
---|
[ddbbcffa] | 1967 | g_free(newbuff); |
---|
[7d4fbcd] | 1968 | return NULL; |
---|
| 1969 | } |
---|
| 1970 | |
---|
[6829afc] | 1971 | CALLER_OWN char *owl_function_perl(int argc, const char *const *argv, const char *buff, int type) |
---|
[d54838d] | 1972 | { |
---|
[7d4fbcd] | 1973 | /* if type == 1 display in a popup |
---|
| 1974 | * if type == 2 display an admin messages |
---|
| 1975 | * if type == 0 return output |
---|
| 1976 | * else display in a popup |
---|
| 1977 | */ |
---|
| 1978 | char *perlout; |
---|
| 1979 | |
---|
| 1980 | if (argc<2) { |
---|
[ec6ff52] | 1981 | owl_function_error("Wrong number of arguments to perl command"); |
---|
[7d4fbcd] | 1982 | return NULL; |
---|
| 1983 | } |
---|
| 1984 | |
---|
| 1985 | /* consume first token (argv[0]) */ |
---|
| 1986 | buff = skiptokens(buff, 1); |
---|
| 1987 | |
---|
[f1e629d] | 1988 | perlout = owl_perlconfig_execute(buff); |
---|
[7d4fbcd] | 1989 | if (perlout) { |
---|
[7ba9e0de] | 1990 | if (type == OWL_OUTPUT_POPUP) { |
---|
[7d4fbcd] | 1991 | owl_function_popless_text(perlout); |
---|
[7ba9e0de] | 1992 | } else if (type == OWL_OUTPUT_ADMINMSG) { |
---|
[7d4fbcd] | 1993 | owl_function_adminmsg(buff, perlout); |
---|
[7ba9e0de] | 1994 | } else if (type == OWL_OUTPUT_RETURN) { |
---|
[7d4fbcd] | 1995 | return perlout; |
---|
| 1996 | } |
---|
[ddbbcffa] | 1997 | g_free(perlout); |
---|
[7d4fbcd] | 1998 | } |
---|
| 1999 | return NULL; |
---|
| 2000 | } |
---|
| 2001 | |
---|
[5e0b690] | 2002 | /* Change the filter associated with the current view. |
---|
| 2003 | * This also figures out which message in the new filter |
---|
| 2004 | * should have the pointer. |
---|
| 2005 | */ |
---|
[e19eb97] | 2006 | void owl_function_change_currentview_filter(const char *filtname) |
---|
[c3ab155] | 2007 | { |
---|
| 2008 | owl_view *v; |
---|
| 2009 | owl_filter *f; |
---|
| 2010 | int curid=-1, newpos, curmsg; |
---|
[c08c70a] | 2011 | const owl_message *curm=NULL; |
---|
[c3ab155] | 2012 | |
---|
| 2013 | v=owl_global_get_current_view(&g); |
---|
| 2014 | |
---|
| 2015 | curmsg=owl_global_get_curmsg(&g); |
---|
| 2016 | if (curmsg==-1) { |
---|
| 2017 | owl_function_debugmsg("Hit the curmsg==-1 case in change_view"); |
---|
| 2018 | } else { |
---|
| 2019 | curm=owl_view_get_element(v, curmsg); |
---|
| 2020 | if (curm) { |
---|
| 2021 | curid=owl_message_get_id(curm); |
---|
| 2022 | owl_view_save_curmsgid(v, curid); |
---|
| 2023 | } |
---|
| 2024 | } |
---|
| 2025 | |
---|
| 2026 | f=owl_global_get_filter(&g, filtname); |
---|
| 2027 | if (!f) { |
---|
[ec6ff52] | 2028 | owl_function_error("Unknown filter %s", filtname); |
---|
[c3ab155] | 2029 | return; |
---|
| 2030 | } |
---|
| 2031 | |
---|
| 2032 | owl_view_new_filter(v, f); |
---|
| 2033 | |
---|
| 2034 | /* Figure out what to set the current message to. |
---|
| 2035 | * - If the view we're leaving has messages in it, go to the closest message |
---|
| 2036 | * to the last message pointed to in that view. |
---|
| 2037 | * - If the view we're leaving is empty, try to restore the position |
---|
| 2038 | * from the last time we were in the new view. */ |
---|
| 2039 | if (curm) { |
---|
| 2040 | newpos = owl_view_get_nearest_to_msgid(v, curid); |
---|
| 2041 | } else { |
---|
| 2042 | newpos = owl_view_get_nearest_to_saved(v); |
---|
| 2043 | } |
---|
| 2044 | |
---|
| 2045 | owl_global_set_curmsg(&g, newpos); |
---|
| 2046 | owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS); |
---|
| 2047 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 2048 | owl_global_set_direction_downwards(&g); |
---|
| 2049 | } |
---|
[7d4fbcd] | 2050 | |
---|
[5e0b690] | 2051 | /* Create a new filter, or replace an existing one |
---|
| 2052 | * with a new definition. |
---|
| 2053 | */ |
---|
[e19eb97] | 2054 | void owl_function_create_filter(int argc, const char *const *argv) |
---|
[d54838d] | 2055 | { |
---|
[7d4fbcd] | 2056 | owl_filter *f; |
---|
[9e5c9f3] | 2057 | const owl_view *v; |
---|
[23fddad] | 2058 | int inuse = 0; |
---|
[7d4fbcd] | 2059 | |
---|
| 2060 | if (argc < 2) { |
---|
[ec6ff52] | 2061 | owl_function_error("Wrong number of arguments to filter command"); |
---|
[7d4fbcd] | 2062 | return; |
---|
| 2063 | } |
---|
| 2064 | |
---|
[3895e23] | 2065 | owl_function_debugmsg("owl_function_create_filter: starting to create filter named %s", argv[1]); |
---|
| 2066 | |
---|
[7d4fbcd] | 2067 | v=owl_global_get_current_view(&g); |
---|
| 2068 | |
---|
| 2069 | /* don't touch the all filter */ |
---|
| 2070 | if (!strcmp(argv[1], "all")) { |
---|
[ec6ff52] | 2071 | owl_function_error("You may not change the 'all' filter."); |
---|
[7d4fbcd] | 2072 | return; |
---|
| 2073 | } |
---|
| 2074 | |
---|
| 2075 | /* deal with the case of trying change the filter color */ |
---|
| 2076 | if (argc==4 && !strcmp(argv[2], "-c")) { |
---|
| 2077 | f=owl_global_get_filter(&g, argv[1]); |
---|
| 2078 | if (!f) { |
---|
[ec6ff52] | 2079 | owl_function_error("The filter '%s' does not exist.", argv[1]); |
---|
[7d4fbcd] | 2080 | return; |
---|
| 2081 | } |
---|
[601733d] | 2082 | if (owl_util_string_to_color(argv[3])==OWL_COLOR_INVALID) { |
---|
[12c35df] | 2083 | owl_function_error("The color '%s' is not available.", argv[3]); |
---|
| 2084 | return; |
---|
| 2085 | } |
---|
[8fa9562] | 2086 | owl_filter_set_fgcolor(f, owl_util_string_to_color(argv[3])); |
---|
| 2087 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 2088 | return; |
---|
| 2089 | } |
---|
| 2090 | if (argc==4 && !strcmp(argv[2], "-b")) { |
---|
| 2091 | f=owl_global_get_filter(&g, argv[1]); |
---|
| 2092 | if (!f) { |
---|
| 2093 | owl_function_error("The filter '%s' does not exist.", argv[1]); |
---|
| 2094 | return; |
---|
| 2095 | } |
---|
[601733d] | 2096 | if (owl_util_string_to_color(argv[3])==OWL_COLOR_INVALID) { |
---|
[8fa9562] | 2097 | owl_function_error("The color '%s' is not available.", argv[3]); |
---|
| 2098 | return; |
---|
| 2099 | } |
---|
| 2100 | owl_filter_set_bgcolor(f, owl_util_string_to_color(argv[3])); |
---|
[7d4fbcd] | 2101 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 2102 | return; |
---|
| 2103 | } |
---|
| 2104 | |
---|
| 2105 | /* create the filter and check for errors */ |
---|
[23fddad] | 2106 | f = owl_filter_new(argv[1], argc-2, argv+2); |
---|
| 2107 | if (f == NULL) { |
---|
[40458b9] | 2108 | owl_function_error("Invalid filter"); |
---|
[7d4fbcd] | 2109 | return; |
---|
| 2110 | } |
---|
| 2111 | |
---|
| 2112 | /* if the named filter is in use by the current view, remember it */ |
---|
| 2113 | if (!strcmp(owl_view_get_filtname(v), argv[1])) { |
---|
| 2114 | inuse=1; |
---|
| 2115 | } |
---|
| 2116 | |
---|
| 2117 | /* if the named filter already exists, nuke it */ |
---|
| 2118 | if (owl_global_get_filter(&g, argv[1])) { |
---|
| 2119 | owl_global_remove_filter(&g, argv[1]); |
---|
| 2120 | } |
---|
| 2121 | |
---|
| 2122 | /* add the filter */ |
---|
| 2123 | owl_global_add_filter(&g, f); |
---|
| 2124 | |
---|
| 2125 | /* if it was in use by the current view then update */ |
---|
| 2126 | if (inuse) { |
---|
[3895e23] | 2127 | owl_function_change_currentview_filter(argv[1]); |
---|
[7d4fbcd] | 2128 | } |
---|
| 2129 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 2130 | } |
---|
| 2131 | |
---|
[3895e23] | 2132 | /* If 'filtername' does not start with 'not-' create a filter named |
---|
| 2133 | * 'not-<filtername>' defined as "not filter <filtername>". If the |
---|
| 2134 | * filter 'not-<filtername>' already exists, do not overwrite it. If |
---|
| 2135 | * 'filtername' begins with 'not-' and a filter 'filtername' already |
---|
| 2136 | * exists, then do nothing. If the filter 'filtername' does not |
---|
| 2137 | * exist, create it and define it as 'not filter <filtername>' |
---|
| 2138 | * |
---|
| 2139 | * Returns the name of the negated filter, which the caller must free. |
---|
| 2140 | */ |
---|
[6829afc] | 2141 | CALLER_OWN char *owl_function_create_negative_filter(const char *filtername) |
---|
[3895e23] | 2142 | { |
---|
| 2143 | char *newname; |
---|
[4542047] | 2144 | const owl_filter *tmpfilt; |
---|
[e19eb97] | 2145 | const char *argv[5]; |
---|
[3895e23] | 2146 | |
---|
| 2147 | owl_function_debugmsg("owl_function_create_negative_filter"); |
---|
| 2148 | |
---|
| 2149 | if (!strncmp(filtername, "not-", 4)) { |
---|
[d4927a7] | 2150 | newname=g_strdup(filtername+4); |
---|
[3895e23] | 2151 | } else { |
---|
[3472845] | 2152 | newname=g_strdup_printf("not-%s", filtername); |
---|
[3895e23] | 2153 | } |
---|
| 2154 | |
---|
| 2155 | tmpfilt=owl_global_get_filter(&g, newname); |
---|
| 2156 | if (!tmpfilt) { |
---|
| 2157 | argv[0]="filter"; /* anything is fine here */ |
---|
| 2158 | argv[1]=newname; |
---|
| 2159 | argv[2]="not"; |
---|
| 2160 | argv[3]="filter"; |
---|
| 2161 | argv[4]=filtername; |
---|
| 2162 | owl_function_create_filter(5, argv); |
---|
| 2163 | } |
---|
| 2164 | |
---|
| 2165 | owl_function_debugmsg("owl_function_create_negative_filter: returning with %s", newname); |
---|
| 2166 | return(newname); |
---|
| 2167 | } |
---|
| 2168 | |
---|
[c79a047] | 2169 | void owl_function_show_filters(void) |
---|
[d54838d] | 2170 | { |
---|
[4542047] | 2171 | const owl_filter *f; |
---|
[129e609] | 2172 | GList *fl; |
---|
[7d4fbcd] | 2173 | owl_fmtext fm; |
---|
| 2174 | |
---|
| 2175 | owl_fmtext_init_null(&fm); |
---|
| 2176 | |
---|
| 2177 | owl_fmtext_append_bold(&fm, "Filters:\n"); |
---|
| 2178 | |
---|
[129e609] | 2179 | for (fl = g.filterlist; fl; fl = g_list_next(fl)) { |
---|
| 2180 | f = fl->data; |
---|
[7d4fbcd] | 2181 | owl_fmtext_append_normal(&fm, " "); |
---|
[7b4f3be] | 2182 | owl_fmtext_append_normal_color(&fm, owl_filter_get_name(f), |
---|
| 2183 | owl_filter_get_fgcolor(f), |
---|
| 2184 | owl_filter_get_bgcolor(f)); |
---|
[7d4fbcd] | 2185 | owl_fmtext_append_normal(&fm, "\n"); |
---|
| 2186 | } |
---|
| 2187 | owl_function_popless_fmtext(&fm); |
---|
[7ab0020] | 2188 | owl_fmtext_cleanup(&fm); |
---|
[7d4fbcd] | 2189 | } |
---|
| 2190 | |
---|
[e19eb97] | 2191 | void owl_function_show_filter(const char *name) |
---|
[d54838d] | 2192 | { |
---|
[4542047] | 2193 | const owl_filter *f; |
---|
[cdc6ff1] | 2194 | char *buff, *tmp; |
---|
[7d4fbcd] | 2195 | |
---|
| 2196 | f=owl_global_get_filter(&g, name); |
---|
| 2197 | if (!f) { |
---|
[ec6ff52] | 2198 | owl_function_error("There is no filter named %s", name); |
---|
[7d4fbcd] | 2199 | return; |
---|
| 2200 | } |
---|
[cdc6ff1] | 2201 | tmp = owl_filter_print(f); |
---|
[3472845] | 2202 | buff = g_strdup_printf("%s: %s", owl_filter_get_name(f), tmp); |
---|
[7d4fbcd] | 2203 | owl_function_popless_text(buff); |
---|
[ddbbcffa] | 2204 | g_free(buff); |
---|
| 2205 | g_free(tmp); |
---|
[7d4fbcd] | 2206 | } |
---|
| 2207 | |
---|
[c79a047] | 2208 | void owl_function_show_zpunts(void) |
---|
[d54838d] | 2209 | { |
---|
[4542047] | 2210 | const owl_filter *f; |
---|
[e6d7e4e] | 2211 | const GPtrArray *fl; |
---|
[0504f63] | 2212 | char *tmp; |
---|
[7d4fbcd] | 2213 | owl_fmtext fm; |
---|
[e6d7e4e] | 2214 | int i; |
---|
[7d4fbcd] | 2215 | |
---|
| 2216 | owl_fmtext_init_null(&fm); |
---|
| 2217 | |
---|
| 2218 | fl=owl_global_get_puntlist(&g); |
---|
| 2219 | owl_fmtext_append_bold(&fm, "Active zpunt filters:\n"); |
---|
| 2220 | |
---|
[e6d7e4e] | 2221 | for (i = 0; i < fl->len; i++) { |
---|
| 2222 | f = fl->pdata[i]; |
---|
[e3a75ed] | 2223 | owl_fmtext_appendf_normal(&fm, "[% 2d] ", i+1); |
---|
[0504f63] | 2224 | tmp = owl_filter_print(f); |
---|
| 2225 | owl_fmtext_append_normal(&fm, tmp); |
---|
[ddbbcffa] | 2226 | g_free(tmp); |
---|
[7d4fbcd] | 2227 | } |
---|
| 2228 | owl_function_popless_fmtext(&fm); |
---|
[7ab0020] | 2229 | owl_fmtext_cleanup(&fm); |
---|
[7d4fbcd] | 2230 | } |
---|
| 2231 | |
---|
[3abf28b] | 2232 | /* Create a filter for a class, instance if one doesn't exist. If |
---|
| 2233 | * instance is NULL then catch all messgaes in the class. Returns the |
---|
[c7fe23e] | 2234 | * name of the filter or null. The caller must free this name. |
---|
[66e409c] | 2235 | * If 'related' is nonzero, encompass unclasses and .d classes as well. |
---|
[3abf28b] | 2236 | */ |
---|
[6829afc] | 2237 | CALLER_OWN char *owl_function_classinstfilt(const char *c, const char *i, int related) |
---|
[d54838d] | 2238 | { |
---|
[7d4fbcd] | 2239 | owl_filter *f; |
---|
[c426bc2] | 2240 | char *filtname; |
---|
[d54838d] | 2241 | char *tmpclass, *tmpinstance = NULL; |
---|
[7a20e4c] | 2242 | char *class, *instance = NULL; |
---|
[c426bc2] | 2243 | GString *buf; |
---|
[7d4fbcd] | 2244 | |
---|
[66e409c] | 2245 | if (related) { |
---|
| 2246 | class = owl_util_baseclass(c); |
---|
| 2247 | if (i) { |
---|
| 2248 | instance = owl_util_baseclass(i); |
---|
| 2249 | } |
---|
| 2250 | } else { |
---|
[d4927a7] | 2251 | class = g_strdup(c); |
---|
[66e409c] | 2252 | if (i) { |
---|
[d4927a7] | 2253 | instance = g_strdup(i); |
---|
[66e409c] | 2254 | } |
---|
[7a20e4c] | 2255 | } |
---|
| 2256 | |
---|
[7d4fbcd] | 2257 | /* name for the filter */ |
---|
| 2258 | if (!instance) { |
---|
[3472845] | 2259 | filtname = g_strdup_printf("%sclass-%s", related ? "related-" : "", class); |
---|
[7d4fbcd] | 2260 | } else { |
---|
[3472845] | 2261 | filtname = g_strdup_printf("%sclass-%s-instance-%s", related ? "related-" : "", class, instance); |
---|
[7d4fbcd] | 2262 | } |
---|
[ed2412d] | 2263 | /* downcase it */ |
---|
[28ee32b] | 2264 | { |
---|
| 2265 | char *temp = g_utf8_strdown(filtname, -1); |
---|
| 2266 | if (temp) { |
---|
[ddbbcffa] | 2267 | g_free(filtname); |
---|
[28ee32b] | 2268 | filtname = temp; |
---|
| 2269 | } |
---|
| 2270 | } |
---|
[ed2412d] | 2271 | |
---|
[7d4fbcd] | 2272 | /* if it already exists then go with it. This lets users override */ |
---|
| 2273 | if (owl_global_get_filter(&g, filtname)) { |
---|
[ff426f9] | 2274 | goto done; |
---|
[7d4fbcd] | 2275 | } |
---|
| 2276 | |
---|
| 2277 | /* create the new filter */ |
---|
[995eb4b] | 2278 | tmpclass=owl_text_quote(class, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); |
---|
[ed2412d] | 2279 | if (instance) { |
---|
[995eb4b] | 2280 | tmpinstance=owl_text_quote(instance, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); |
---|
[ed2412d] | 2281 | } |
---|
[a0e6082] | 2282 | |
---|
[c426bc2] | 2283 | buf = g_string_new(""); |
---|
| 2284 | owl_string_appendf_quoted(buf, |
---|
| 2285 | related ? "class ^(un)*%q(\\.d)*$" : "class ^%q$", |
---|
| 2286 | tmpclass); |
---|
| 2287 | |
---|
[d54838d] | 2288 | if (tmpinstance) { |
---|
[c426bc2] | 2289 | owl_string_appendf_quoted(buf, |
---|
| 2290 | related ? |
---|
| 2291 | " and ( instance ^(un)*%q(\\.d)*$ )" : |
---|
| 2292 | " and instance ^%q$", |
---|
| 2293 | tmpinstance); |
---|
[7d4fbcd] | 2294 | } |
---|
[ddbbcffa] | 2295 | g_free(tmpclass); |
---|
| 2296 | g_free(tmpinstance); |
---|
[7d4fbcd] | 2297 | |
---|
[c426bc2] | 2298 | f = owl_filter_new_fromstring(filtname, buf->str); |
---|
| 2299 | g_string_free(buf, true); |
---|
[c7fe23e] | 2300 | if (f == NULL) { |
---|
| 2301 | /* Couldn't make a filter for some reason. Return NULL. */ |
---|
| 2302 | owl_function_error("Error creating filter '%s'", filtname); |
---|
[ddbbcffa] | 2303 | g_free(filtname); |
---|
[c7fe23e] | 2304 | filtname = NULL; |
---|
| 2305 | goto done; |
---|
| 2306 | } |
---|
[7d4fbcd] | 2307 | |
---|
| 2308 | /* add it to the global list */ |
---|
| 2309 | owl_global_add_filter(&g, f); |
---|
| 2310 | |
---|
[ff426f9] | 2311 | done: |
---|
[ddbbcffa] | 2312 | g_free(class); |
---|
[3b8a563] | 2313 | g_free(instance); |
---|
[ed2412d] | 2314 | return(filtname); |
---|
[7d4fbcd] | 2315 | } |
---|
| 2316 | |
---|
[3abf28b] | 2317 | /* Create a filter for personal zephyrs to or from the specified |
---|
| 2318 | * zephyr user. Includes login/logout notifications for the user. |
---|
[811644f] | 2319 | * The name of the filter will be 'user-<shortuser>'. If a filter already |
---|
[3abf28b] | 2320 | * exists with this name, no new filter will be created. This allows |
---|
| 2321 | * the configuration to override this function. Returns the name of |
---|
| 2322 | * the filter, which the caller must free. |
---|
| 2323 | */ |
---|
[6829afc] | 2324 | CALLER_OWN char *owl_function_zuserfilt(const char *longuser) |
---|
[d54838d] | 2325 | { |
---|
[7d4fbcd] | 2326 | owl_filter *f; |
---|
[811644f] | 2327 | char *argbuff, *esclonguser, *shortuser, *filtname; |
---|
[7d4fbcd] | 2328 | |
---|
| 2329 | /* name for the filter */ |
---|
[811644f] | 2330 | shortuser = short_zuser(longuser); |
---|
[3472845] | 2331 | filtname = g_strdup_printf("user-%s", shortuser); |
---|
[ddbbcffa] | 2332 | g_free(shortuser); |
---|
[7d4fbcd] | 2333 | |
---|
| 2334 | /* if it already exists then go with it. This lets users override */ |
---|
| 2335 | if (owl_global_get_filter(&g, filtname)) { |
---|
[6cc3306] | 2336 | return filtname; |
---|
[7d4fbcd] | 2337 | } |
---|
| 2338 | |
---|
| 2339 | /* create the new-internal filter */ |
---|
[1d12db24] | 2340 | esclonguser = owl_text_quote(longuser, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); |
---|
| 2341 | |
---|
[a5f477c] | 2342 | argbuff=owl_string_build_quoted("( type ^zephyr$ and filter personal and " |
---|
| 2343 | "( ( direction ^in$ and sender ^%q$ ) or ( direction ^out$ and " |
---|
| 2344 | "recipient ^%q$ ) ) ) or ( ( class ^login$ ) and ( sender ^%q$ ) )", |
---|
| 2345 | esclonguser, esclonguser, esclonguser); |
---|
[ddbbcffa] | 2346 | g_free(esclonguser); |
---|
[7d4fbcd] | 2347 | |
---|
[23fddad] | 2348 | f = owl_filter_new_fromstring(filtname, argbuff); |
---|
[ddbbcffa] | 2349 | g_free(argbuff); |
---|
[c7fe23e] | 2350 | |
---|
| 2351 | if (f == NULL) { |
---|
| 2352 | /* Couldn't make a filter for some reason. Return NULL. */ |
---|
| 2353 | owl_function_error("Error creating filter '%s'", filtname); |
---|
[ddbbcffa] | 2354 | g_free(filtname); |
---|
[c7fe23e] | 2355 | return NULL; |
---|
| 2356 | } |
---|
[7d4fbcd] | 2357 | |
---|
| 2358 | /* add it to the global list */ |
---|
| 2359 | owl_global_add_filter(&g, f); |
---|
| 2360 | |
---|
[ed2412d] | 2361 | return(filtname); |
---|
[7d4fbcd] | 2362 | } |
---|
| 2363 | |
---|
[3abf28b] | 2364 | /* Create a filter for AIM IM messages to or from the specified |
---|
| 2365 | * screenname. The name of the filter will be 'aimuser-<user>'. If a |
---|
| 2366 | * filter already exists with this name, no new filter will be |
---|
| 2367 | * created. This allows the configuration to override this function. |
---|
| 2368 | * Returns the name of the filter, which the caller must free. |
---|
| 2369 | */ |
---|
[6829afc] | 2370 | CALLER_OWN char *owl_function_aimuserfilt(const char *user) |
---|
[3abf28b] | 2371 | { |
---|
| 2372 | owl_filter *f; |
---|
| 2373 | char *argbuff, *filtname; |
---|
[af9b92e] | 2374 | char *escuser; |
---|
[3abf28b] | 2375 | |
---|
| 2376 | /* name for the filter */ |
---|
[3472845] | 2377 | filtname=g_strdup_printf("aimuser-%s", user); |
---|
[3abf28b] | 2378 | |
---|
| 2379 | /* if it already exists then go with it. This lets users override */ |
---|
| 2380 | if (owl_global_get_filter(&g, filtname)) { |
---|
[d4927a7] | 2381 | return(g_strdup(filtname)); |
---|
[3abf28b] | 2382 | } |
---|
| 2383 | |
---|
| 2384 | /* create the new-internal filter */ |
---|
[af9b92e] | 2385 | escuser = owl_text_quote(user, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); |
---|
| 2386 | |
---|
[3472845] | 2387 | argbuff = g_strdup_printf( |
---|
[9a2ae6c] | 2388 | "( type ^aim$ and ( ( sender ^%1$s$ and recipient ^%2$s$ ) or " |
---|
| 2389 | "( sender ^%2$s$ and recipient ^%1$s$ ) ) )", |
---|
| 2390 | escuser, owl_global_get_aim_screenname_for_filters(&g)); |
---|
[ddbbcffa] | 2391 | g_free(escuser); |
---|
[3abf28b] | 2392 | |
---|
[23fddad] | 2393 | f = owl_filter_new_fromstring(filtname, argbuff); |
---|
[ddbbcffa] | 2394 | g_free(argbuff); |
---|
[c7fe23e] | 2395 | |
---|
| 2396 | if (f == NULL) { |
---|
| 2397 | owl_function_error("Error creating filter '%s'", filtname); |
---|
[ddbbcffa] | 2398 | g_free(filtname); |
---|
[c7fe23e] | 2399 | return NULL; |
---|
| 2400 | } |
---|
[3abf28b] | 2401 | |
---|
| 2402 | /* add it to the global list */ |
---|
| 2403 | owl_global_add_filter(&g, f); |
---|
| 2404 | |
---|
| 2405 | return(filtname); |
---|
| 2406 | } |
---|
| 2407 | |
---|
[6829afc] | 2408 | CALLER_OWN char *owl_function_typefilt(const char *type) |
---|
[d54838d] | 2409 | { |
---|
[f73e519] | 2410 | owl_filter *f; |
---|
[1d12db24] | 2411 | char *argbuff, *filtname, *esctype; |
---|
[f73e519] | 2412 | |
---|
| 2413 | /* name for the filter */ |
---|
[3472845] | 2414 | filtname=g_strdup_printf("type-%s", type); |
---|
[f73e519] | 2415 | |
---|
| 2416 | /* if it already exists then go with it. This lets users override */ |
---|
| 2417 | if (owl_global_get_filter(&g, filtname)) { |
---|
| 2418 | return filtname; |
---|
| 2419 | } |
---|
| 2420 | |
---|
| 2421 | /* create the new-internal filter */ |
---|
[1d12db24] | 2422 | esctype = owl_text_quote(type, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); |
---|
| 2423 | |
---|
[42115bf9] | 2424 | argbuff = owl_string_build_quoted("type ^%q$", esctype); |
---|
[ddbbcffa] | 2425 | g_free(esctype); |
---|
[f73e519] | 2426 | |
---|
[23fddad] | 2427 | f = owl_filter_new_fromstring(filtname, argbuff); |
---|
[ddbbcffa] | 2428 | g_free(argbuff); |
---|
[c7fe23e] | 2429 | |
---|
| 2430 | if (f == NULL) { |
---|
| 2431 | owl_function_error("Error creating filter '%s'", filtname); |
---|
[ddbbcffa] | 2432 | g_free(filtname); |
---|
[c7fe23e] | 2433 | return NULL; |
---|
| 2434 | } |
---|
[f73e519] | 2435 | |
---|
| 2436 | /* add it to the global list */ |
---|
| 2437 | owl_global_add_filter(&g, f); |
---|
| 2438 | |
---|
| 2439 | return filtname; |
---|
| 2440 | } |
---|
| 2441 | |
---|
[7d4fbcd] | 2442 | /* If flag is 1, marks for deletion. If flag is 0, |
---|
| 2443 | * unmarks for deletion. */ |
---|
[d54838d] | 2444 | void owl_function_delete_curview_msgs(int flag) |
---|
| 2445 | { |
---|
[9e5c9f3] | 2446 | const owl_view *v; |
---|
[7d4fbcd] | 2447 | int i, j; |
---|
| 2448 | |
---|
| 2449 | v=owl_global_get_current_view(&g); |
---|
| 2450 | j=owl_view_get_size(v); |
---|
| 2451 | for (i=0; i<j; i++) { |
---|
| 2452 | if (flag == 1) { |
---|
| 2453 | owl_message_mark_delete(owl_view_get_element(v, i)); |
---|
| 2454 | } else if (flag == 0) { |
---|
| 2455 | owl_message_unmark_delete(owl_view_get_element(v, i)); |
---|
| 2456 | } |
---|
| 2457 | } |
---|
| 2458 | |
---|
| 2459 | owl_function_makemsg("%i messages marked for %sdeletion", j, flag?"":"un"); |
---|
| 2460 | |
---|
| 2461 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 2462 | } |
---|
| 2463 | |
---|
[6829afc] | 2464 | static CALLER_OWN char *owl_function_smartfilter_cc(const owl_message *m) |
---|
[d427f08] | 2465 | { |
---|
[ecaec21] | 2466 | const char *ccs; |
---|
[d222c44] | 2467 | char *ccs_quoted; |
---|
[ecaec21] | 2468 | char *filtname; |
---|
| 2469 | owl_filter *f; |
---|
[d222c44] | 2470 | GString *buf; |
---|
[ecaec21] | 2471 | |
---|
| 2472 | ccs = owl_message_get_attribute_value(m, "zephyr_ccs"); |
---|
| 2473 | |
---|
[3472845] | 2474 | filtname = g_strdup_printf("conversation-%s", ccs); |
---|
[7865479] | 2475 | g_strdelimit(filtname, " ", '-'); |
---|
[ecaec21] | 2476 | |
---|
| 2477 | if (owl_global_get_filter(&g, filtname)) { |
---|
| 2478 | return filtname; |
---|
| 2479 | } |
---|
| 2480 | |
---|
[d222c44] | 2481 | buf = g_string_new("type ^zephyr$ and filter personal and " |
---|
| 2482 | "zephyr_ccs ^"); |
---|
| 2483 | ccs_quoted = owl_text_quote(ccs, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); |
---|
| 2484 | owl_string_append_quoted_arg(buf, ccs_quoted); |
---|
| 2485 | g_string_append_c(buf, '$'); |
---|
[ddbbcffa] | 2486 | g_free(ccs_quoted); |
---|
[ecaec21] | 2487 | |
---|
[d222c44] | 2488 | f = owl_filter_new_fromstring(filtname, buf->str); |
---|
| 2489 | g_string_free(buf, true); |
---|
[ecaec21] | 2490 | |
---|
[c7fe23e] | 2491 | if (f == NULL) { |
---|
| 2492 | owl_function_error("Error creating filter '%s'", filtname); |
---|
[ddbbcffa] | 2493 | g_free(filtname); |
---|
[c7fe23e] | 2494 | return NULL; |
---|
| 2495 | } |
---|
| 2496 | |
---|
[ecaec21] | 2497 | owl_global_add_filter(&g, f); |
---|
| 2498 | |
---|
| 2499 | return filtname; |
---|
| 2500 | } |
---|
| 2501 | |
---|
[3abf28b] | 2502 | /* Create a filter based on the current message. Returns the name of |
---|
| 2503 | * a filter or null. The caller must free this name. |
---|
| 2504 | * |
---|
| 2505 | * if the curmsg is a personal zephyr return a filter name |
---|
[e6d989f] | 2506 | * to the zephyr conversation with that user. |
---|
[3abf28b] | 2507 | * If the curmsg is a zephyr class message, instance foo, recip *, |
---|
| 2508 | * return a filter name to the class, inst. |
---|
| 2509 | * If the curmsg is a zephyr class message and type==0 then |
---|
| 2510 | * return a filter name for just the class. |
---|
| 2511 | * If the curmsg is a zephyr class message and type==1 then |
---|
| 2512 | * return a filter name for the class and instance. |
---|
| 2513 | * If the curmsg is a personal AIM message returna filter |
---|
| 2514 | * name to the AIM conversation with that user |
---|
| 2515 | */ |
---|
[6829afc] | 2516 | CALLER_OWN char *owl_function_smartfilter(int type, int invert_related) |
---|
[d54838d] | 2517 | { |
---|
[9e5c9f3] | 2518 | const owl_view *v; |
---|
[c08c70a] | 2519 | const owl_message *m; |
---|
[811644f] | 2520 | char *filtname = NULL; |
---|
| 2521 | const char *argv[2], *zperson; |
---|
[8a5b5a1] | 2522 | int related = owl_global_is_narrow_related(&g) ^ invert_related; |
---|
| 2523 | |
---|
[7d4fbcd] | 2524 | v=owl_global_get_current_view(&g); |
---|
| 2525 | m=owl_view_get_element(v, owl_global_get_curmsg(&g)); |
---|
| 2526 | |
---|
[5eeea3b] | 2527 | if (!m || owl_view_get_size(v)==0) { |
---|
[ec6ff52] | 2528 | owl_function_error("No message selected\n"); |
---|
[4b464a4] | 2529 | return(NULL); |
---|
[7d4fbcd] | 2530 | } |
---|
| 2531 | |
---|
[f73e519] | 2532 | /* very simple handling of admin messages for now */ |
---|
[4b464a4] | 2533 | if (owl_message_is_type_admin(m)) { |
---|
[3abf28b] | 2534 | return(owl_function_typefilt("admin")); |
---|
| 2535 | } |
---|
| 2536 | |
---|
[995eb4b] | 2537 | /* very simple handling of loopback messages for now */ |
---|
| 2538 | if (owl_message_is_type_loopback(m)) { |
---|
| 2539 | return(owl_function_typefilt("loopback")); |
---|
| 2540 | } |
---|
| 2541 | |
---|
[3abf28b] | 2542 | /* aim messages */ |
---|
| 2543 | if (owl_message_is_type_aim(m)) { |
---|
| 2544 | if (owl_message_is_direction_in(m)) { |
---|
| 2545 | filtname=owl_function_aimuserfilt(owl_message_get_sender(m)); |
---|
| 2546 | } else if (owl_message_is_direction_out(m)) { |
---|
| 2547 | filtname=owl_function_aimuserfilt(owl_message_get_recipient(m)); |
---|
| 2548 | } |
---|
| 2549 | return(filtname); |
---|
[7d4fbcd] | 2550 | } |
---|
| 2551 | |
---|
[4b464a4] | 2552 | /* narrow personal and login messages to the sender or recip as appropriate */ |
---|
[25729b2] | 2553 | if (owl_message_is_type_zephyr(m)) { |
---|
[0ef0e8f] | 2554 | if (owl_message_is_personal(m) || owl_message_is_loginout(m)) { |
---|
[ecaec21] | 2555 | if (owl_message_get_attribute_value(m, "zephyr_ccs") != NULL) { |
---|
| 2556 | return owl_function_smartfilter_cc(m); |
---|
| 2557 | } |
---|
| 2558 | |
---|
[4b464a4] | 2559 | if (owl_message_is_direction_in(m)) { |
---|
[811644f] | 2560 | zperson = owl_message_get_sender(m); |
---|
[4b464a4] | 2561 | } else { |
---|
[811644f] | 2562 | zperson = owl_message_get_recipient(m); |
---|
[4b464a4] | 2563 | } |
---|
[811644f] | 2564 | filtname = owl_function_zuserfilt(zperson); |
---|
| 2565 | return filtname; |
---|
[7d4fbcd] | 2566 | } |
---|
| 2567 | |
---|
[25729b2] | 2568 | /* narrow class MESSAGE, instance foo, recip * messages to class, inst */ |
---|
[ce74deb] | 2569 | if (!strcasecmp(owl_message_get_class(m), "message")) { |
---|
[66e409c] | 2570 | filtname=owl_function_classinstfilt(owl_message_get_class(m), owl_message_get_instance(m), related); |
---|
[25729b2] | 2571 | return(filtname); |
---|
| 2572 | } |
---|
| 2573 | |
---|
| 2574 | /* otherwise narrow to the class */ |
---|
| 2575 | if (type==0) { |
---|
[66e409c] | 2576 | filtname=owl_function_classinstfilt(owl_message_get_class(m), NULL, related); |
---|
[25729b2] | 2577 | } else if (type==1) { |
---|
[66e409c] | 2578 | filtname=owl_function_classinstfilt(owl_message_get_class(m), owl_message_get_instance(m), related); |
---|
[25729b2] | 2579 | } |
---|
[4b464a4] | 2580 | return(filtname); |
---|
[7d4fbcd] | 2581 | } |
---|
| 2582 | |
---|
[25729b2] | 2583 | /* pass it off to perl */ |
---|
[66e409c] | 2584 | argv[0] = type ? "1" : "0"; |
---|
| 2585 | argv[1] = related ? "1" : "0"; |
---|
| 2586 | return owl_perlconfig_message_call_method(m, "smartfilter", 2, argv); |
---|
[7d4fbcd] | 2587 | } |
---|
| 2588 | |
---|
[d54838d] | 2589 | void owl_function_smartzpunt(int type) |
---|
| 2590 | { |
---|
[d36f2cb] | 2591 | /* Starts a zpunt command based on the current class,instance pair. |
---|
| 2592 | * If type=0, uses just class. If type=1, uses instance as well. */ |
---|
[9e5c9f3] | 2593 | const owl_view *v; |
---|
[c08c70a] | 2594 | const owl_message *m; |
---|
[d222c44] | 2595 | const char *mclass, *minst; |
---|
| 2596 | GString *buf; |
---|
[d36f2cb] | 2597 | |
---|
| 2598 | v=owl_global_get_current_view(&g); |
---|
| 2599 | m=owl_view_get_element(v, owl_global_get_curmsg(&g)); |
---|
| 2600 | |
---|
[5eeea3b] | 2601 | if (!m || owl_view_get_size(v)==0) { |
---|
[ec6ff52] | 2602 | owl_function_error("No message selected\n"); |
---|
[d36f2cb] | 2603 | return; |
---|
| 2604 | } |
---|
| 2605 | |
---|
| 2606 | /* for now we skip admin messages. */ |
---|
[4b464a4] | 2607 | if (owl_message_is_type_admin(m) |
---|
[5789230] | 2608 | || owl_message_is_loginout(m) |
---|
[4b464a4] | 2609 | || !owl_message_is_type_zephyr(m)) { |
---|
[ec6ff52] | 2610 | owl_function_error("smartzpunt doesn't support this message type."); |
---|
[d36f2cb] | 2611 | return; |
---|
| 2612 | } |
---|
| 2613 | |
---|
[cee1f25] | 2614 | mclass = owl_message_get_class(m); |
---|
| 2615 | minst = owl_message_get_instance(m); |
---|
[d36f2cb] | 2616 | if (!mclass || !*mclass || *mclass==' ' |
---|
| 2617 | || (!strcasecmp(mclass, "message") && !strcasecmp(minst, "personal")) |
---|
| 2618 | || (type && (!minst || !*minst|| *minst==' '))) { |
---|
[ec6ff52] | 2619 | owl_function_error("smartzpunt can't safely do this for <%s,%s>", |
---|
[d36f2cb] | 2620 | mclass, minst); |
---|
| 2621 | } else { |
---|
[d222c44] | 2622 | buf = g_string_new("start-command zpunt "); |
---|
| 2623 | owl_string_append_quoted_arg(buf, mclass); |
---|
[d36f2cb] | 2624 | if (type) { |
---|
[d222c44] | 2625 | g_string_append_c(buf, ' '); |
---|
| 2626 | owl_string_append_quoted_arg(buf, minst); |
---|
[d36f2cb] | 2627 | } else { |
---|
[d222c44] | 2628 | g_string_append(buf, " *"); |
---|
[d36f2cb] | 2629 | } |
---|
[c809f5e] | 2630 | owl_function_command_norv(buf->str); |
---|
[d222c44] | 2631 | g_string_free(buf, true); |
---|
[d36f2cb] | 2632 | } |
---|
| 2633 | } |
---|
| 2634 | |
---|
[5e0b690] | 2635 | /* Set the color of the current view's filter to |
---|
| 2636 | * be 'color' |
---|
| 2637 | */ |
---|
[e19eb97] | 2638 | void owl_function_color_current_filter(const char *fgcolor, const char *bgcolor) |
---|
[d54838d] | 2639 | { |
---|
[e19eb97] | 2640 | const char *name; |
---|
[7d4fbcd] | 2641 | |
---|
| 2642 | name=owl_view_get_filtname(owl_global_get_current_view(&g)); |
---|
[8fa9562] | 2643 | owl_function_color_filter(name, fgcolor, bgcolor); |
---|
[5e0b690] | 2644 | } |
---|
| 2645 | |
---|
| 2646 | /* Set the color of the filter 'filter' to be 'color'. If the color |
---|
| 2647 | * name does not exist, return -1, if the filter does not exist or is |
---|
| 2648 | * the "all" filter, return -2. Return 0 on success |
---|
| 2649 | */ |
---|
[e19eb97] | 2650 | int owl_function_color_filter(const char *filtname, const char *fgcolor, const char *bgcolor) |
---|
[5e0b690] | 2651 | { |
---|
| 2652 | owl_filter *f; |
---|
| 2653 | |
---|
| 2654 | f=owl_global_get_filter(&g, filtname); |
---|
[7d4fbcd] | 2655 | if (!f) { |
---|
[ec6ff52] | 2656 | owl_function_error("Unknown filter"); |
---|
[5e0b690] | 2657 | return(-2); |
---|
[7d4fbcd] | 2658 | } |
---|
| 2659 | |
---|
| 2660 | /* don't touch the all filter */ |
---|
[5e0b690] | 2661 | if (!strcmp(filtname, "all")) { |
---|
[ec6ff52] | 2662 | owl_function_error("You may not change the 'all' filter."); |
---|
[5e0b690] | 2663 | return(-2); |
---|
[7d4fbcd] | 2664 | } |
---|
| 2665 | |
---|
[601733d] | 2666 | if (owl_util_string_to_color(fgcolor)==OWL_COLOR_INVALID) { |
---|
[8fa9562] | 2667 | owl_function_error("No color named '%s' avilable.", fgcolor); |
---|
[5e0b690] | 2668 | return(-1); |
---|
[12c35df] | 2669 | } |
---|
[8fa9562] | 2670 | |
---|
| 2671 | |
---|
| 2672 | if (bgcolor != NULL) { |
---|
[601733d] | 2673 | if (owl_util_string_to_color(bgcolor)==OWL_COLOR_INVALID) { |
---|
[8fa9562] | 2674 | owl_function_error("No color named '%s' avilable.", bgcolor); |
---|
| 2675 | return(-1); |
---|
| 2676 | } |
---|
| 2677 | owl_filter_set_bgcolor(f, owl_util_string_to_color(bgcolor)); |
---|
| 2678 | } |
---|
| 2679 | owl_filter_set_fgcolor(f, owl_util_string_to_color(fgcolor)); |
---|
| 2680 | |
---|
[7d4fbcd] | 2681 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
[5e0b690] | 2682 | return(0); |
---|
[7d4fbcd] | 2683 | } |
---|
| 2684 | |
---|
[c79a047] | 2685 | void owl_function_show_colors(void) |
---|
[d54838d] | 2686 | { |
---|
[7d4fbcd] | 2687 | owl_fmtext fm; |
---|
[c2c5c77] | 2688 | int i; |
---|
| 2689 | |
---|
[7d4fbcd] | 2690 | owl_fmtext_init_null(&fm); |
---|
[82b734a] | 2691 | owl_fmtext_append_normal(&fm,"default: "); |
---|
[8fa9562] | 2692 | owl_fmtext_append_normal_color(&fm, "default\n", OWL_COLOR_DEFAULT, OWL_COLOR_DEFAULT); |
---|
[ca9142e] | 2693 | |
---|
[82b734a] | 2694 | owl_fmtext_append_normal(&fm,"black: "); |
---|
| 2695 | owl_fmtext_append_normal_color(&fm, "black\n", OWL_COLOR_BLACK, OWL_COLOR_DEFAULT); |
---|
| 2696 | |
---|
[ca9142e] | 2697 | owl_fmtext_append_normal(&fm,"red: "); |
---|
[8fa9562] | 2698 | owl_fmtext_append_normal_color(&fm, "red\n", OWL_COLOR_RED, OWL_COLOR_DEFAULT); |
---|
[ca9142e] | 2699 | |
---|
| 2700 | owl_fmtext_append_normal(&fm,"green: "); |
---|
[8fa9562] | 2701 | owl_fmtext_append_normal_color(&fm, "green\n", OWL_COLOR_GREEN, OWL_COLOR_DEFAULT); |
---|
[ca9142e] | 2702 | |
---|
| 2703 | owl_fmtext_append_normal(&fm,"yellow: "); |
---|
[8fa9562] | 2704 | owl_fmtext_append_normal_color(&fm, "yellow\n", OWL_COLOR_YELLOW, OWL_COLOR_DEFAULT); |
---|
[ca9142e] | 2705 | |
---|
| 2706 | owl_fmtext_append_normal(&fm,"blue: "); |
---|
[8fa9562] | 2707 | owl_fmtext_append_normal_color(&fm, "blue\n", OWL_COLOR_BLUE, OWL_COLOR_DEFAULT); |
---|
[ca9142e] | 2708 | |
---|
| 2709 | owl_fmtext_append_normal(&fm,"magenta: "); |
---|
[8fa9562] | 2710 | owl_fmtext_append_normal_color(&fm, "magenta\n", OWL_COLOR_MAGENTA, OWL_COLOR_DEFAULT); |
---|
[ca9142e] | 2711 | |
---|
| 2712 | owl_fmtext_append_normal(&fm,"cyan: "); |
---|
[8fa9562] | 2713 | owl_fmtext_append_normal_color(&fm, "cyan\n", OWL_COLOR_CYAN, OWL_COLOR_DEFAULT); |
---|
[ca9142e] | 2714 | |
---|
| 2715 | owl_fmtext_append_normal(&fm,"white: "); |
---|
[8fa9562] | 2716 | owl_fmtext_append_normal_color(&fm, "white\n", OWL_COLOR_WHITE, OWL_COLOR_DEFAULT); |
---|
[7d4fbcd] | 2717 | |
---|
[c2c5c77] | 2718 | for(i = 8; i < COLORS; ++i) { |
---|
[3472845] | 2719 | char* str1 = g_strdup_printf("%4i: ",i); |
---|
| 2720 | char* str2 = g_strdup_printf("%i\n",i); |
---|
[c2c5c77] | 2721 | owl_fmtext_append_normal(&fm,str1); |
---|
| 2722 | owl_fmtext_append_normal_color(&fm, str2, i, OWL_COLOR_DEFAULT); |
---|
[ddbbcffa] | 2723 | g_free(str1); |
---|
| 2724 | g_free(str2); |
---|
[c2c5c77] | 2725 | } |
---|
| 2726 | |
---|
[7d4fbcd] | 2727 | owl_function_popless_fmtext(&fm); |
---|
[7ab0020] | 2728 | owl_fmtext_cleanup(&fm); |
---|
[7d4fbcd] | 2729 | } |
---|
| 2730 | |
---|
[5bb6c21] | 2731 | /* add the given class, inst, recip to the punt list for filtering. |
---|
| 2732 | * if direction==0 then punt |
---|
| 2733 | * if direction==1 then unpunt |
---|
| 2734 | */ |
---|
[e19eb97] | 2735 | void owl_function_zpunt(const char *class, const char *inst, const char *recip, int direction) |
---|
[d54838d] | 2736 | { |
---|
[78f6c35] | 2737 | GPtrArray *argv; |
---|
[bc08664] | 2738 | char *quoted; |
---|
[7d4fbcd] | 2739 | |
---|
[78f6c35] | 2740 | argv = g_ptr_array_new(); |
---|
[5bb6c21] | 2741 | if (!strcmp(class, "*")) { |
---|
[78f6c35] | 2742 | g_ptr_array_add(argv, g_strdup("class")); |
---|
| 2743 | g_ptr_array_add(argv, g_strdup(".*")); |
---|
[5bb6c21] | 2744 | } else { |
---|
[bc08664] | 2745 | quoted=owl_text_quote(class, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); |
---|
[78f6c35] | 2746 | g_ptr_array_add(argv, g_strdup("class")); |
---|
| 2747 | g_ptr_array_add(argv, g_strdup_printf("^(un)*%s(\\.d)*$", quoted)); |
---|
[ddbbcffa] | 2748 | g_free(quoted); |
---|
[5bb6c21] | 2749 | } |
---|
| 2750 | if (!strcmp(inst, "*")) { |
---|
[78f6c35] | 2751 | g_ptr_array_add(argv, g_strdup("and")); |
---|
| 2752 | g_ptr_array_add(argv, g_strdup("instance")); |
---|
| 2753 | g_ptr_array_add(argv, g_strdup(".*")); |
---|
[7d4fbcd] | 2754 | } else { |
---|
[bc08664] | 2755 | quoted=owl_text_quote(inst, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); |
---|
[78f6c35] | 2756 | g_ptr_array_add(argv, g_strdup("and")); |
---|
| 2757 | g_ptr_array_add(argv, g_strdup("instance")); |
---|
| 2758 | g_ptr_array_add(argv, g_strdup_printf("^(un)*%s(\\.d)*$", quoted)); |
---|
[ddbbcffa] | 2759 | g_free(quoted); |
---|
[7d4fbcd] | 2760 | } |
---|
[c894c15] | 2761 | if (!strcmp(recip, "*")) { |
---|
[78f6c35] | 2762 | /* nothing */ |
---|
[c894c15] | 2763 | } else { |
---|
[e6c59ba] | 2764 | if(!strcmp(recip, "%me%")) { |
---|
| 2765 | recip = owl_zephyr_get_sender(); |
---|
| 2766 | } |
---|
[bc08664] | 2767 | quoted=owl_text_quote(recip, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); |
---|
[78f6c35] | 2768 | g_ptr_array_add(argv, g_strdup("and")); |
---|
| 2769 | g_ptr_array_add(argv, g_strdup("recipient")); |
---|
| 2770 | g_ptr_array_add(argv, g_strdup_printf("^%s$", quoted)); |
---|
[ddbbcffa] | 2771 | g_free(quoted); |
---|
[5bb6c21] | 2772 | } |
---|
[ce7b824] | 2773 | |
---|
[78f6c35] | 2774 | owl_function_punt(argv->len, (const char *const*) argv->pdata, direction); |
---|
[3cdd6d2] | 2775 | owl_ptr_array_free(argv, g_free); |
---|
[ce7b824] | 2776 | } |
---|
| 2777 | |
---|
[78f6c35] | 2778 | void owl_function_punt(int argc, const char *const *argv, int direction) |
---|
[ce7b824] | 2779 | { |
---|
| 2780 | owl_filter *f; |
---|
[e6d7e4e] | 2781 | GPtrArray *fl; |
---|
| 2782 | int i; |
---|
[ce7b824] | 2783 | fl=owl_global_get_puntlist(&g); |
---|
| 2784 | |
---|
| 2785 | /* first, create the filter */ |
---|
[78f6c35] | 2786 | f = owl_filter_new("punt-filter", argc, argv); |
---|
[23fddad] | 2787 | if (f == NULL) { |
---|
[ec6ff52] | 2788 | owl_function_error("Error creating filter for zpunt"); |
---|
[7d4fbcd] | 2789 | return; |
---|
| 2790 | } |
---|
| 2791 | |
---|
| 2792 | /* Check for an identical filter */ |
---|
[e6d7e4e] | 2793 | for (i = 0; i < fl->len; i++) { |
---|
| 2794 | if (owl_filter_equiv(f, fl->pdata[i])) { |
---|
[ce7b824] | 2795 | owl_function_debugmsg("found an equivalent punt filter"); |
---|
[7d4fbcd] | 2796 | /* if we're punting, then just silently bow out on this duplicate */ |
---|
| 2797 | if (direction==0) { |
---|
[23fddad] | 2798 | owl_filter_delete(f); |
---|
[7d4fbcd] | 2799 | return; |
---|
| 2800 | } |
---|
| 2801 | |
---|
| 2802 | /* if we're unpunting, then remove this filter from the puntlist */ |
---|
| 2803 | if (direction==1) { |
---|
[e6d7e4e] | 2804 | owl_filter_delete(g_ptr_array_remove_index(fl, i)); |
---|
[23fddad] | 2805 | owl_filter_delete(f); |
---|
[7d4fbcd] | 2806 | return; |
---|
| 2807 | } |
---|
| 2808 | } |
---|
| 2809 | } |
---|
| 2810 | |
---|
[697221f] | 2811 | if (direction == 0) { |
---|
| 2812 | owl_function_debugmsg("punting"); |
---|
| 2813 | /* If we're punting, add the filter to the global punt list */ |
---|
[e6d7e4e] | 2814 | g_ptr_array_add(fl, f); |
---|
[697221f] | 2815 | } else if (direction == 1) { |
---|
| 2816 | owl_function_makemsg("No matching punt filter"); |
---|
| 2817 | } |
---|
[7d4fbcd] | 2818 | } |
---|
| 2819 | |
---|
[c79a047] | 2820 | void owl_function_show_keymaps(void) |
---|
[d54838d] | 2821 | { |
---|
[ce68f23] | 2822 | GPtrArray *l; |
---|
[7d4fbcd] | 2823 | owl_fmtext fm; |
---|
[afa200a] | 2824 | const owl_keymap *km; |
---|
[12bc46a] | 2825 | const owl_keyhandler *kh; |
---|
[ce68f23] | 2826 | int i; |
---|
[e19eb97] | 2827 | const char *kmname; |
---|
[7d4fbcd] | 2828 | |
---|
[1aee7d9] | 2829 | kh = owl_global_get_keyhandler(&g); |
---|
[7d4fbcd] | 2830 | owl_fmtext_init_null(&fm); |
---|
| 2831 | owl_fmtext_append_bold(&fm, "Keymaps: "); |
---|
| 2832 | owl_fmtext_append_normal(&fm, "(use 'show keymap <name>' for details)\n"); |
---|
[ce68f23] | 2833 | l = owl_keyhandler_get_keymap_names(kh); |
---|
| 2834 | owl_fmtext_append_list(&fm, l, "\n", owl_function_keymap_summary); |
---|
[7d4fbcd] | 2835 | owl_fmtext_append_normal(&fm, "\n"); |
---|
[1aee7d9] | 2836 | |
---|
[ce68f23] | 2837 | for (i = 0; i < l->len; i++) { |
---|
| 2838 | kmname = l->pdata[i]; |
---|
[1aee7d9] | 2839 | km = owl_keyhandler_get_keymap(kh, kmname); |
---|
| 2840 | owl_fmtext_append_bold(&fm, "\n\n----------------------------------------------------------------------------------------------------\n\n"); |
---|
[13ebf92] | 2841 | owl_keymap_get_details(km, &fm, 0); |
---|
[1aee7d9] | 2842 | } |
---|
| 2843 | owl_fmtext_append_normal(&fm, "\n"); |
---|
| 2844 | |
---|
[7d4fbcd] | 2845 | owl_function_popless_fmtext(&fm); |
---|
[ce68f23] | 2846 | owl_ptr_array_free(l, g_free); |
---|
[7ab0020] | 2847 | owl_fmtext_cleanup(&fm); |
---|
[7d4fbcd] | 2848 | } |
---|
| 2849 | |
---|
[6829afc] | 2850 | CALLER_OWN char *owl_function_keymap_summary(const char *name) |
---|
[d54838d] | 2851 | { |
---|
[afa200a] | 2852 | const owl_keymap *km |
---|
[7d4fbcd] | 2853 | = owl_keyhandler_get_keymap(owl_global_get_keyhandler(&g), name); |
---|
| 2854 | if (km) return owl_keymap_summary(km); |
---|
| 2855 | else return(NULL); |
---|
| 2856 | } |
---|
| 2857 | |
---|
| 2858 | /* TODO: implement for real */ |
---|
[e19eb97] | 2859 | void owl_function_show_keymap(const char *name) |
---|
[d54838d] | 2860 | { |
---|
[1fd0b25] | 2861 | owl_fmtext fm; |
---|
[afa200a] | 2862 | const owl_keymap *km; |
---|
[7d4fbcd] | 2863 | |
---|
| 2864 | owl_fmtext_init_null(&fm); |
---|
| 2865 | km = owl_keyhandler_get_keymap(owl_global_get_keyhandler(&g), name); |
---|
| 2866 | if (km) { |
---|
[13ebf92] | 2867 | owl_keymap_get_details(km, &fm, 1); |
---|
[7d4fbcd] | 2868 | } else { |
---|
| 2869 | owl_fmtext_append_normal(&fm, "No such keymap...\n"); |
---|
| 2870 | } |
---|
| 2871 | owl_function_popless_fmtext(&fm); |
---|
[7ab0020] | 2872 | owl_fmtext_cleanup(&fm); |
---|
[7d4fbcd] | 2873 | } |
---|
| 2874 | |
---|
[e19eb97] | 2875 | void owl_function_help_for_command(const char *cmdname) |
---|
[d54838d] | 2876 | { |
---|
[1fd0b25] | 2877 | owl_fmtext fm; |
---|
[7d4fbcd] | 2878 | |
---|
| 2879 | owl_fmtext_init_null(&fm); |
---|
| 2880 | owl_cmd_get_help(owl_global_get_cmddict(&g), cmdname, &fm); |
---|
| 2881 | owl_function_popless_fmtext(&fm); |
---|
[7ab0020] | 2882 | owl_fmtext_cleanup(&fm); |
---|
[7d4fbcd] | 2883 | } |
---|
[1fd0b25] | 2884 | |
---|
|
---|