Changeset ea43085 for functions.c
- Timestamp:
- Jun 22, 2013, 9:49:47 PM (11 years ago)
- Parents:
- 96d80e9 (diff), c474a97 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
functions.c
rc474a97 r60e8617 1 #include "owl.h" 2 #include "filterproc.h" 1 3 #include <stdio.h> 2 #include <stdlib.h>3 #include <unistd.h>4 #include <signal.h>5 #include <netinet/in.h>6 #include <string.h>7 #include <time.h>8 #include <sys/types.h>9 4 #include <sys/stat.h> 10 5 #include <sys/wait.h> 11 #include <errno.h> 12 #include <signal.h> 13 #include "owl.h" 14 #include "filterproc.h" 15 16 char *owl_function_command(const char *cmdbuff) 6 7 CALLER_OWN char *owl_function_command(const char *cmdbuff) 17 8 { 18 9 owl_function_debugmsg("executing command: %s", cmdbuff); … … 21 12 } 22 13 23 char *owl_function_command_argv(const char *const *argv, int argc)14 CALLER_OWN char *owl_function_command_argv(const char *const *argv, int argc) 24 15 { 25 16 return owl_cmddict_execute_argv(owl_global_get_cmddict(&g), … … 47 38 void owl_function_show_commands(void) 48 39 { 49 owl_listl;40 GPtrArray *l; 50 41 owl_fmtext fm; 51 42 … … 53 44 owl_fmtext_append_bold(&fm, "Commands: "); 54 45 owl_fmtext_append_normal(&fm, "(use 'show command <name>' for details)\n"); 55 owl_list_create(&l); 56 owl_cmddict_get_names(owl_global_get_cmddict(&g), &l); 57 owl_fmtext_append_list(&fm, &l, "\n", owl_function_cmd_describe); 46 l = owl_cmddict_get_names(owl_global_get_cmddict(&g)); 47 owl_fmtext_append_list(&fm, l, "\n", owl_function_cmd_describe); 58 48 owl_fmtext_append_normal(&fm, "\n"); 59 49 owl_function_popless_fmtext(&fm); 60 owl_ list_cleanup(&l, g_free);50 owl_ptr_array_free(l, g_free); 61 51 owl_fmtext_cleanup(&fm); 62 52 } … … 81 71 82 72 void owl_function_show_styles(void) { 83 owl_listl;73 GPtrArray *l; 84 74 owl_fmtext fm; 85 75 86 76 owl_fmtext_init_null(&fm); 87 77 owl_fmtext_append_bold(&fm, "Styles:\n"); 88 owl_list_create(&l); 89 owl_global_get_style_names(&g, &l); 90 owl_fmtext_append_list(&fm, &l, "\n", owl_function_style_describe); 78 l = owl_global_get_style_names(&g); 79 owl_fmtext_append_list(&fm, l, "\n", owl_function_style_describe); 91 80 owl_fmtext_append_normal(&fm, "\n"); 92 81 owl_function_popless_fmtext(&fm); 93 owl_ list_cleanup(&l, g_free);82 owl_ptr_array_free(l, g_free); 94 83 owl_fmtext_cleanup(&fm); 95 84 } 96 85 97 static void _owl_function_timer_append_fmtext(gpointer data, gpointer user_data) { 98 owl_fmtext *fm = user_data; 99 owl_timer *timer = data; 100 char *str = g_strdup_printf("- %s: in %d seconds", 101 timer->name ? timer->name : "(unnamed)", 102 (int)(timer->time - time(NULL))); 103 owl_fmtext_append_normal(fm, str); 104 g_free(str); 105 if (timer->interval) { 106 str = g_strdup_printf(", repeat every %d seconds", timer->interval); 107 owl_fmtext_append_normal(fm, str); 108 g_free(str); 109 } 110 owl_fmtext_append_normal(fm, "\n"); 111 } 112 113 void owl_function_show_timers(void) { 114 owl_fmtext fm; 115 GList **timers; 116 117 owl_fmtext_init_null(&fm); 118 owl_fmtext_append_bold(&fm, "Active timers:\n"); 119 120 timers = owl_global_get_timerlist(&g); 121 g_list_foreach(*timers, _owl_function_timer_append_fmtext, &fm); 122 123 owl_function_popless_fmtext(&fm); 124 owl_fmtext_cleanup(&fm); 125 } 126 127 char *owl_function_style_describe(const char *name) { 86 CALLER_OWN char *owl_function_style_describe(const char *name) 87 { 128 88 const char *desc; 129 89 char *s; … … 141 101 } 142 102 143 char *owl_function_cmd_describe(const char *name)103 CALLER_OWN char *owl_function_cmd_describe(const char *name) 144 104 { 145 105 const owl_cmd *cmd = owl_cmddict_find(owl_global_get_cmddict(&g), name); … … 158 118 159 119 text="" 160 " barnowl version " OWL_VERSION_STRING "\n"120 "BarnOwl version " OWL_VERSION_STRING "\n" 161 121 "Copyright (c) 2006-2011 The BarnOwl Developers. All rights reserved.\n" 162 122 "Copyright (c) 2004 James Kretchmar. All rights reserved.\n" … … 175 135 "\n" 176 136 " * Redistributions in any form must be accompanied by information on\n" 177 " how to obtain complete source code for the Owl software and any\n"178 " accompanying software that uses the Owl software. The source code\n"137 " how to obtain complete source code for the BarnOwl software and any\n" 138 " accompanying software that uses the BarnOwl software. The source code\n" 179 139 " must either be included in the distribution or be available for no\n" 180 140 " more than the cost of distribution plus a nominal fee, and must be\n" … … 244 204 245 205 /* do followlast if necessary */ 246 if (owl_global_should_followlast(&g)) owl_function_lastmsg _noredisplay();206 if (owl_global_should_followlast(&g)) owl_function_lastmsg(); 247 207 248 208 /* redisplay etc. */ … … 256 216 void owl_function_add_outgoing_zephyrs(const owl_zwrite *z) 257 217 { 258 if (z->cc || owl_zwrite_get_numrecips(z) == 0) {218 if (z->cc && owl_zwrite_is_personal(z)) { 259 219 /* create the message */ 260 220 owl_message *m = g_new(owl_message, 1); … … 265 225 int i; 266 226 for (i = 0; i < owl_zwrite_get_numrecips(z); i++) { 227 owl_message *m; 228 229 if (!owl_zwrite_recip_is_personal(owl_zwrite_get_recip_n(z, i))) 230 continue; 231 267 232 /* create the message */ 268 owl_message *m = g_new(owl_message, 1);233 m = g_new(owl_message, 1); 269 234 owl_message_create_from_zwrite(m, z, owl_zwrite_get_message(z), i); 270 235 … … 279 244 * owl_global_messagequeue_addmsg() for that. 280 245 */ 281 owl_message *owl_function_make_outgoing_aim(const char *body, const char *to)246 CALLER_OWN owl_message *owl_function_make_outgoing_aim(const char *body, const char *to) 282 247 { 283 248 owl_message *m; … … 300 265 * owl_global_messagequeue_addmsg() for that. 301 266 */ 302 owl_message *owl_function_make_outgoing_loopback(const char *body)267 CALLER_OWN owl_message *owl_function_make_outgoing_loopback(const char *body) 303 268 { 304 269 owl_message *m; … … 312 277 } 313 278 314 void owl_function_start_edit_win(const char *line, void (*callback)(owl_editwin *), void *data, void (*cleanup)(void *))279 owl_editwin *owl_function_start_edit_win(const char *line) 315 280 { 316 281 owl_editwin *e; … … 326 291 g_free(s); 327 292 328 owl_editwin_set_cbdata(e, data, cleanup);329 owl_editwin_set_callback(e, callback);330 293 ctx = owl_editcontext_new(OWL_CTX_EDITMULTI, e, "editmulti", 331 294 owl_global_deactivate_editcontext, &g); 332 295 owl_global_push_context_obj(&g, ctx); 333 296 return e; 334 297 } 335 298 … … 349 312 void owl_function_zwrite_setup(owl_zwrite *z) 350 313 { 314 owl_editwin *e; 351 315 /* send a ping if necessary */ 352 316 if (owl_global_is_txping(&g)) { … … 356 320 357 321 owl_function_write_setup("zephyr"); 358 owl_function_start_edit_win(z->zwriteline,359 &owl_callback_zwrite,360 z, (void(*)(void*))owl_zwrite_delete);322 e = owl_function_start_edit_win(z->zwriteline); 323 owl_editwin_set_cbdata(e, z, (void (*)(void *))owl_zwrite_delete); 324 owl_editwin_set_callback(e, &owl_callback_zwrite); 361 325 } 362 326 363 327 void owl_function_aimwrite_setup(const char *to) 364 328 { 329 owl_editwin *e; 365 330 /* TODO: We probably actually want an owl_aimwrite object like 366 331 * owl_zwrite. */ 367 332 char *line = g_strdup_printf("aimwrite %s", to); 368 333 owl_function_write_setup("message"); 369 owl_function_start_edit_win(line, 370 &owl_callback_aimwrite, 371 g_strdup(to), 372 g_free); 334 e = owl_function_start_edit_win(line); 335 owl_editwin_set_cbdata(e, g_strdup(to), g_free); 336 owl_editwin_set_callback(e, &owl_callback_aimwrite); 373 337 g_free(line); 374 338 } … … 376 340 void owl_function_loopwrite_setup(void) 377 341 { 342 owl_editwin *e; 378 343 owl_function_write_setup("message"); 379 owl_function_start_edit_win("loopwrite", 380 &owl_callback_loopwrite, 381 NULL, NULL); 382 } 383 384 void owl_callback_zwrite(owl_editwin *e) { 344 e = owl_function_start_edit_win("loopwrite"); 345 owl_editwin_set_callback(e, &owl_callback_loopwrite); 346 } 347 348 void owl_callback_zwrite(owl_editwin *e, bool success) 349 { 350 if (!success) return; 385 351 owl_zwrite *z = owl_editwin_get_cbdata(e); 386 352 owl_function_zwrite(z, owl_editwin_get_text(e)); … … 412 378 owl_function_makemsg("Waiting for ack..."); 413 379 414 /* If it's personal */ 415 if (owl_zwrite_is_personal(z)) { 416 /* create the outgoing message */ 417 owl_function_add_outgoing_zephyrs(z); 418 } 380 /* create the outgoing message */ 381 owl_function_add_outgoing_zephyrs(z); 419 382 } 420 383 #else … … 441 404 old_msg = g_strdup(owl_zwrite_get_message(z)); 442 405 443 zcrypt = g_ strdup_printf("%s/zcrypt", owl_get_bindir());444 argv[0] = "zcrypt";406 zcrypt = g_build_filename(owl_get_bindir(), "zcrypt", NULL); 407 argv[0] = zcrypt; 445 408 argv[1] = "-E"; 446 409 argv[2] = "-c"; argv[3] = owl_zwrite_get_class(z); … … 448 411 argv[6] = NULL; 449 412 450 rv = call_filter( zcrypt,argv, owl_zwrite_get_message(z), &cryptmsg, &status);413 rv = call_filter(argv, owl_zwrite_get_message(z), &cryptmsg, &status); 451 414 452 415 g_free(zcrypt); … … 466 429 owl_function_makemsg("Waiting for ack..."); 467 430 468 /* If it's personal */ 469 if (owl_zwrite_is_personal(z)) { 470 /* Create the outgoing message. Restore the un-crypted message for display. */ 471 owl_zwrite_set_message_raw(z, old_msg); 472 owl_function_add_outgoing_zephyrs(z); 473 } 474 475 /* free the zwrite */ 431 /* Create the outgoing message. Restore the un-crypted message for display. */ 432 owl_zwrite_set_message_raw(z, old_msg); 433 owl_function_add_outgoing_zephyrs(z); 434 435 /* Clean up. */ 476 436 g_free(cryptmsg); 477 } 478 479 void owl_callback_aimwrite(owl_editwin *e) { 437 g_free(old_msg); 438 } 439 440 void owl_callback_aimwrite(owl_editwin *e, bool success) 441 { 442 if (!success) return; 480 443 char *to = owl_editwin_get_cbdata(e); 481 444 owl_function_aimwrite(to, owl_editwin_get_text(e), true); … … 541 504 } 542 505 543 void owl_callback_loopwrite(owl_editwin *e) { 506 void owl_callback_loopwrite(owl_editwin *e, bool success) 507 { 508 if (!success) return; 544 509 owl_function_loopwrite(owl_editwin_get_text(e)); 545 510 } … … 691 656 { 692 657 owl_function_prevmsg_full(NULL, 1, 1); 658 } 659 660 void owl_function_delete_and_expunge_message(int n) 661 { 662 owl_messagelist *ml = owl_global_get_msglist(&g); 663 owl_view *v = owl_global_get_current_view(&g); 664 int lastmsgid = owl_function_get_curmsg_id(v); 665 666 /* delete and expunge the message */ 667 owl_messagelist_delete_and_expunge_element(ml, n); 668 669 owl_function_redisplay_to_nearest(lastmsgid, v); 670 } 671 672 void owl_function_delete_and_expunge_cur(bool exclaim_success) 673 { 674 int curmsg; 675 const owl_view *v = owl_global_get_current_view(&g); 676 677 /* bail if there's no current message */ 678 if (owl_view_get_size(v) < 1) { 679 owl_function_error("No current message to delete"); 680 return; 681 } 682 683 /* delete the current message */ 684 curmsg = owl_global_get_curmsg(&g); 685 owl_function_delete_and_expunge_message(curmsg); 686 if (exclaim_success) 687 owl_function_makemsg("Message deleted and expunged"); 693 688 } 694 689 … … 752 747 } 753 748 749 /* returns the current message id, if it exists. Otherwise returns 750 * -1 if we are past the end of the message list, and 0 otherwise. */ 751 int owl_function_get_curmsg_id(const owl_view *v) 752 { 753 int curmsg = owl_global_get_curmsg(&g); 754 const owl_message *m = owl_view_get_element(v, curmsg); 755 if (m) 756 return owl_message_get_id(m); 757 if (curmsg > 0) /* past the end of the message list (probably) */ 758 return -1; 759 return 0; 760 } 761 762 /* redisplays the view to the nearest message to the id given. 763 * if msgid < 0, redisplay to past the end of the message list */ 764 void owl_function_redisplay_to_nearest(int msgid, owl_view *v) 765 { 766 int curmsg; 767 /* update all views (we only have one right now) */ 768 owl_view_recalculate(v); 769 770 /* find where the new position should be */ 771 if (msgid < 0) { 772 /* If already at the end, blank the screen and move curmsg 773 * past the end of the messages. */ 774 curmsg = owl_view_get_size(v); 775 owl_global_set_topmsg(&g, curmsg); 776 owl_global_set_curmsg(&g, curmsg); 777 } else { 778 curmsg = owl_view_get_nearest_to_msgid(v, msgid); 779 if (curmsg > owl_view_get_size(v) - 1) 780 curmsg = owl_view_get_size(v) - 1; 781 if (curmsg < 0) 782 curmsg = 0; 783 owl_global_set_curmsg(&g, curmsg); 784 owl_function_calculate_topmsg(OWL_DIRECTION_NONE); 785 } 786 /* if there are no messages set the direction to down in case we 787 * delete everything upwards */ 788 owl_global_set_direction_downwards(&g); 789 790 owl_mainwin_redisplay(owl_global_get_mainwin(&g)); 791 } 792 754 793 void owl_function_expunge(void) 755 794 { 756 int curmsg; 757 const owl_message *m; 758 owl_messagelist *ml; 759 owl_view *v; 760 int lastmsgid=0; 761 762 curmsg=owl_global_get_curmsg(&g); 763 v=owl_global_get_current_view(&g); 764 ml=owl_global_get_msglist(&g); 765 766 m=owl_view_get_element(v, curmsg); 767 if (m) lastmsgid = owl_message_get_id(m); 795 owl_messagelist *ml = owl_global_get_msglist(&g); 796 owl_view *v = owl_global_get_current_view(&g); 797 int lastmsgid = owl_function_get_curmsg_id(v); 768 798 769 799 /* expunge the message list */ 770 800 owl_messagelist_expunge(ml); 771 801 772 /* update all views (we only have one right now) */ 773 owl_view_recalculate(v); 774 775 /* find where the new position should be 776 (as close as possible to where we last where) */ 777 curmsg = owl_view_get_nearest_to_msgid(v, lastmsgid); 778 if (curmsg>owl_view_get_size(v)-1) curmsg = owl_view_get_size(v)-1; 779 if (curmsg<0) curmsg = 0; 780 owl_global_set_curmsg(&g, curmsg); 781 owl_function_calculate_topmsg(OWL_DIRECTION_NONE); 782 /* if there are no messages set the direction to down in case we 783 delete everything upwards */ 784 owl_global_set_direction_downwards(&g); 802 owl_function_redisplay_to_nearest(lastmsgid, v); 785 803 786 804 owl_function_makemsg("Messages expunged"); 787 owl_mainwin_redisplay(owl_global_get_mainwin(&g));788 805 } 789 806 … … 796 813 } 797 814 798 void owl_function_lastmsg _noredisplay(void)815 void owl_function_lastmsg(void) 799 816 { 800 817 int oldcurmsg, curmsg; … … 814 831 owl_global_set_curmsg(&g, curmsg+1); 815 832 } 816 /* owl_mainwin_redisplay(owl_global_get_mainwin(&g)); */833 owl_mainwin_redisplay(owl_global_get_mainwin(&g)); 817 834 owl_global_set_direction_downwards(&g); 818 }819 820 void owl_function_lastmsg(void)821 {822 owl_function_lastmsg_noredisplay();823 owl_mainwin_redisplay(owl_global_get_mainwin(&g));824 835 } 825 836 … … 844 855 void owl_function_unsuball(void) 845 856 { 846 unsuball();847 owl_function_makemsg("Unsubscribed from all messages.");857 if (unsuball()) 858 owl_function_makemsg("Unsubscribed from all messages."); 848 859 } 849 860 … … 860 871 void owl_function_loadsubs(const char *file) 861 872 { 862 int ret, ret2; 863 const char *foo; 873 int ret, ret2, ret3; 864 874 char *path; 865 875 … … 873 883 874 884 /* for backwards compatibility for now */ 875 ret2=owl_zephyr_loaddefaultsubs(); 885 ret2 = owl_zephyr_loaddefaultsubs(); 886 ret3 = owl_zephyr_loadbarnowldefaultsubs(); 876 887 877 888 if (!owl_context_is_interactive(owl_global_get_context(&g))) return; 878 889 879 foo=file?file:"file"; 880 if (ret==0 && ret2==0) { 890 if (ret == 0 && ret2 == 0 && ret3 == 0) { 881 891 if (!file) { 882 892 owl_function_makemsg("Subscribed to messages."); … … 884 894 owl_function_makemsg("Subscribed to messages from %s", file); 885 895 } 886 } else if (ret ==-1) {887 owl_function_error("Could not read %s", f oo);888 } else {896 } else if (ret == -1) { 897 owl_function_error("Could not read %s", file ? file : "file"); 898 } else if (ret2 == -1) { 889 899 owl_function_error("Error subscribing to messages"); 900 } else { 901 owl_function_error("Error subscribing to instanced personals"); 890 902 } 891 903 } … … 906 918 } 907 919 908 void owl_callback_aimlogin(owl_editwin *e) { 920 void owl_callback_aimlogin(owl_editwin *e, bool success) 921 { 922 if (!success) return; 909 923 char *user = owl_editwin_get_cbdata(e); 910 924 owl_function_aimlogin(user, … … 1003 1017 } 1004 1018 1005 owl_function_debugmsg("Quitting Owl");1019 owl_function_debugmsg("Quitting BarnOwl"); 1006 1020 owl_select_quit_loop(); 1007 1021 } … … 1202 1216 void G_GNUC_PRINTF(1, 2) owl_function_debugmsg(const char *fmt, ...) 1203 1217 { 1218 char *tmpbuff; 1204 1219 FILE *file; 1205 1220 time_t now; … … 1216 1231 now = time(NULL); 1217 1232 1218 fprintf(file, "[%d - %.24s - %lds]: ", 1219 (int) getpid(), ctime(&now), now - owl_global_get_starttime(&g)); 1233 tmpbuff = owl_util_format_time(localtime(&now)); 1234 fprintf(file, "[%d - %s - %lds]: ", 1235 (int) getpid(), tmpbuff, now - owl_global_get_starttime(&g)); 1236 g_free(tmpbuff); 1220 1237 vfprintf(file, fmt, ap); 1221 1238 putc('\n', file); … … 1336 1353 { 1337 1354 owl_function_popless_text( 1338 "This is barnowl version " OWL_VERSION_STRING ".\n\n"1339 " barnowl is a fork of the Owl zephyr client, written and\n"1355 "This is BarnOwl version " OWL_VERSION_STRING ".\n\n" 1356 "BarnOwl is a fork of the Owl zephyr client, written and\n" 1340 1357 "maintained by Alejandro Sedeno and Nelson Elhage at the\n" 1341 1358 "Massachusetts Institute of Technology. \n" … … 1346 1363 "The name 'owl' was chosen in reference to the owls in the\n" 1347 1364 "Harry Potter novels, who are tasked with carrying messages\n" 1348 "between Witches and Wizards. The name ' barnowl' was chosen\n"1365 "between Witches and Wizards. The name 'BarnOwl' was chosen\n" 1349 1366 "because we feel our owls should live closer to our ponies.\n" 1350 1367 "\n" … … 1364 1381 owl_fmtext fm, attrfm; 1365 1382 const owl_view *v; 1383 char *time; 1366 1384 #ifdef HAVE_LIBZEPHYR 1367 1385 const ZNotice_t *n; … … 1394 1412 } 1395 1413 1396 owl_fmtext_appendf_normal(&fm, " Time : %s\n", owl_message_get_timestr(m)); 1414 time = owl_message_format_time(m); 1415 owl_fmtext_appendf_normal(&fm, " Time : %s\n", time); 1416 g_free(time); 1397 1417 1398 1418 if (!owl_message_is_type_admin(m)) { … … 1408 1428 owl_fmtext_appendf_normal(&fm, " Opcode : %s\n", owl_message_get_opcode(m)); 1409 1429 #ifdef HAVE_LIBZEPHYR 1410 if (owl_message_is_direction_in(m)) { 1411 char *tmpbuff; 1430 n = owl_message_get_notice(m); 1431 if (n != NULL) { 1432 char *tmpbuff, *tmpbuff2; 1412 1433 int i, fields; 1413 1414 n=owl_message_get_notice(m); 1434 const char *f; 1415 1435 1416 1436 if (!owl_message_is_pseudo(m)) { … … 1454 1474 owl_fmtext_appendf_normal(&fm, " Fields : %i\n", fields); 1455 1475 1456 for (i = 0; i < fields; i++) { 1457 tmpbuff = owl_zephyr_get_field_as_utf8(n, i + 1); 1458 1459 g_strdelimit(tmpbuff, "\n", '~'); 1460 g_strdelimit(tmpbuff, "\r", '!'); 1461 1462 owl_fmtext_appendf_normal(&fm, " Field %i : %s\n", i + 1, tmpbuff); 1463 g_free(tmpbuff); 1476 for (i = 0, f = owl_zephyr_first_raw_field(n); f != NULL; 1477 i++, f = owl_zephyr_next_raw_field(n, f)) { 1478 tmpbuff = owl_zephyr_field_as_utf8(n, f); 1479 tmpbuff2 = owl_text_indent(tmpbuff, 14, false); 1480 owl_fmtext_appendf_normal(&fm, " Field %i : %s\n", i + 1, tmpbuff2); 1481 g_free(tmpbuff2); 1482 g_free(tmpbuff); 1464 1483 } 1465 owl_fmtext_appendf_normal(&fm, " Default Fm: %s\n", n->z_default_format); 1484 tmpbuff = owl_text_indent(n->z_default_format, 14, false); 1485 owl_fmtext_appendf_normal(&fm, " Default Fm: %s\n", tmpbuff); 1486 g_free(tmpbuff); 1466 1487 } 1467 1488 … … 1470 1491 } 1471 1492 1472 owl_fmtext_append_bold(&fm, "\n Owl Message Attributes:\n");1493 owl_fmtext_append_bold(&fm, "\nBarnOwl Message Attributes:\n"); 1473 1494 owl_message_attributes_tofmtext(m, &attrfm); 1474 1495 owl_fmtext_append_fmtext(&fm, &attrfm); … … 1603 1624 void owl_function_printallvars(void) 1604 1625 { 1626 const owl_variable *v; 1605 1627 const char *name; 1606 1628 char *var; 1607 owl_listvarnames;1608 int i , numvarnames;1629 GPtrArray *varnames; 1630 int i; 1609 1631 GString *str = g_string_new(""); 1610 1632 1611 1633 g_string_append_printf(str, "%-20s = %s\n", "VARIABLE", "VALUE"); 1612 1634 g_string_append_printf(str, "%-20s %s\n", "--------", "-----"); 1613 owl_list_create(&varnames); 1614 owl_variable_dict_get_names(owl_global_get_vardict(&g), &varnames); 1615 numvarnames = owl_list_get_size(&varnames); 1616 for (i=0; i<numvarnames; i++) { 1617 name = owl_list_get_element(&varnames, i); 1635 varnames = owl_variable_dict_get_names(owl_global_get_vardict(&g)); 1636 for (i = 0; i < varnames->len; i++) { 1637 name = varnames->pdata[i]; 1618 1638 if (name && name[0]!='_') { 1619 1639 g_string_append_printf(str, "\n%-20s = ", name); 1620 var = owl_variable_get_tostring(owl_global_get_vardict(&g), name); 1640 v = owl_variable_get_var(owl_global_get_vardict(&g), name); 1641 var = owl_variable_get_tostring(v); 1621 1642 if (var) { 1622 g_string_append(str, var); 1623 g_free(var); 1643 g_string_append(str, var); 1644 g_free(var); 1645 } else { 1646 g_string_append(str, "<null>"); 1624 1647 } 1625 1648 } 1626 1649 } 1627 1650 g_string_append(str, "\n"); 1628 owl_ list_cleanup(&varnames, g_free);1651 owl_ptr_array_free(varnames, g_free); 1629 1652 1630 1653 owl_function_popless_text(str->str); … … 1634 1657 void owl_function_show_variables(void) 1635 1658 { 1636 owl_list varnames; 1659 const owl_variable *v; 1660 GPtrArray *varnames; 1637 1661 owl_fmtext fm; 1638 int i , numvarnames;1662 int i; 1639 1663 const char *varname; 1640 1664 … … 1642 1666 owl_fmtext_append_bold(&fm, 1643 1667 "Variables: (use 'show variable <name>' for details)\n"); 1644 owl_list_create(&varnames); 1645 owl_variable_dict_get_names(owl_global_get_vardict(&g), &varnames); 1646 numvarnames = owl_list_get_size(&varnames); 1647 for (i=0; i<numvarnames; i++) { 1648 varname = owl_list_get_element(&varnames, i); 1668 varnames = owl_variable_dict_get_names(owl_global_get_vardict(&g)); 1669 for (i = 0; i < varnames->len; i++) { 1670 varname = varnames->pdata[i]; 1649 1671 if (varname && varname[0]!='_') { 1650 owl_variable_describe(owl_global_get_vardict(&g), varname, &fm); 1651 } 1652 } 1653 owl_list_cleanup(&varnames, g_free); 1672 v = owl_variable_get_var(owl_global_get_vardict(&g), varname); 1673 owl_variable_describe(v, &fm); 1674 } 1675 } 1676 owl_ptr_array_free(varnames, g_free); 1654 1677 owl_function_popless_fmtext(&fm); 1655 1678 owl_fmtext_cleanup(&fm); … … 1658 1681 void owl_function_show_variable(const char *name) 1659 1682 { 1683 const owl_variable *v; 1660 1684 owl_fmtext fm; 1661 1685 1662 1686 owl_fmtext_init_null(&fm); 1663 owl_variable_get_help(owl_global_get_vardict(&g), name, &fm); 1687 v = owl_variable_get_var(owl_global_get_vardict(&g), name); 1688 if (v) 1689 owl_variable_get_help(v, &fm); 1690 else 1691 owl_fmtext_append_normal(&fm, "No such variable...\n"); 1664 1692 owl_function_popless_fmtext(&fm); 1665 1693 owl_fmtext_cleanup(&fm); 1694 } 1695 1696 void owl_function_delete_and_expunge_by_id(int id, bool exclaim_success) 1697 { 1698 const owl_messagelist *ml = owl_global_get_msglist(&g); 1699 int msg = owl_messagelist_get_index_by_id(ml, id); 1700 if (msg < 0) { 1701 owl_function_error("No message with id %d: unable to delete", id); 1702 } else { 1703 owl_function_delete_and_expunge_message(msg); 1704 if (exclaim_success) 1705 owl_function_makemsg("Message deleted and expunged"); 1706 } 1666 1707 } 1667 1708 … … 1720 1761 void owl_function_status(void) 1721 1762 { 1763 char *tmpbuff; 1722 1764 char buff[MAXPATHLEN+1]; 1723 1765 time_t start; … … 1747 1789 owl_fmtext_append_normal(&fm, "\n"); 1748 1790 1749 owl_fmtext_appendf_normal(&fm, " Startup Time: %s", ctime(&start)); 1791 tmpbuff = owl_util_format_time(localtime(&start)); 1792 owl_fmtext_appendf_normal(&fm, " Startup Time: %s\n", tmpbuff); 1793 g_free(tmpbuff); 1750 1794 1751 1795 up=owl_global_get_runtime(&g); … … 1870 1914 if (enter) { 1871 1915 owl_history *hist = owl_global_get_cmd_history(&g); 1872 owl_history_store(hist, buff); 1873 owl_history_reset(hist); 1916 owl_history_store(hist, buff, false); 1874 1917 owl_function_command_norv(buff); 1875 1918 } else { … … 1901 1944 } 1902 1945 1903 void owl_callback_command(owl_editwin *e) 1904 { 1946 void owl_callback_command(owl_editwin *e, bool success) 1947 { 1948 if (!success) return; 1905 1949 char *rv; 1906 1950 const char *line = owl_editwin_get_text(e); … … 1913 1957 } 1914 1958 1915 voidowl_function_start_command(const char *line)1959 owl_editwin *owl_function_start_command(const char *line) 1916 1960 { 1917 1961 owl_editwin *tw; … … 1928 1972 owl_global_push_context_obj(&g, ctx); 1929 1973 owl_editwin_set_callback(tw, owl_callback_command); 1974 return tw; 1930 1975 } 1931 1976 … … 1962 2007 } 1963 2008 1964 char *owl_function_exec(int argc, const char *const *argv, const char *buff, int type)2009 CALLER_OWN char *owl_function_exec(int argc, const char *const *argv, const char *buff, int type) 1965 2010 { 1966 2011 /* if type == 1 display in a popup … … 2005 2050 } 2006 2051 2007 char *owl_function_perl(int argc, const char *const *argv, const char *buff, int type)2052 CALLER_OWN char *owl_function_perl(int argc, const char *const *argv, const char *buff, int type) 2008 2053 { 2009 2054 /* if type == 1 display in a popup … … 2086 2131 2087 2132 /* Create a new filter, or replace an existing one 2088 * with a new definition. 2133 * with a new definition. Returns true on success. 2089 2134 */ 2090 voidowl_function_create_filter(int argc, const char *const *argv)2135 bool owl_function_create_filter(int argc, const char *const *argv) 2091 2136 { 2092 2137 owl_filter *f; … … 2096 2141 if (argc < 2) { 2097 2142 owl_function_error("Wrong number of arguments to filter command"); 2098 return ;2143 return false; 2099 2144 } 2100 2145 … … 2106 2151 if (!strcmp(argv[1], "all")) { 2107 2152 owl_function_error("You may not change the 'all' filter."); 2108 return ;2153 return false; 2109 2154 } 2110 2155 … … 2114 2159 if (!f) { 2115 2160 owl_function_error("The filter '%s' does not exist.", argv[1]); 2116 return ;2161 return false; 2117 2162 } 2118 2163 if (owl_util_string_to_color(argv[3])==OWL_COLOR_INVALID) { 2119 2164 owl_function_error("The color '%s' is not available.", argv[3]); 2120 return ;2165 return false; 2121 2166 } 2122 2167 owl_filter_set_fgcolor(f, owl_util_string_to_color(argv[3])); 2123 2168 owl_mainwin_redisplay(owl_global_get_mainwin(&g)); 2124 return ;2169 return false; 2125 2170 } 2126 2171 if (argc==4 && !strcmp(argv[2], "-b")) { … … 2128 2173 if (!f) { 2129 2174 owl_function_error("The filter '%s' does not exist.", argv[1]); 2130 return ;2175 return false; 2131 2176 } 2132 2177 if (owl_util_string_to_color(argv[3])==OWL_COLOR_INVALID) { 2133 2178 owl_function_error("The color '%s' is not available.", argv[3]); 2134 return ;2179 return false; 2135 2180 } 2136 2181 owl_filter_set_bgcolor(f, owl_util_string_to_color(argv[3])); 2137 2182 owl_mainwin_redisplay(owl_global_get_mainwin(&g)); 2138 return ;2183 return true; 2139 2184 } 2140 2185 … … 2142 2187 f = owl_filter_new(argv[1], argc-2, argv+2); 2143 2188 if (f == NULL) { 2144 owl_function_error("Invalid filter ");2145 return ;2189 owl_function_error("Invalid filter: %s", argv[1]); 2190 return false; 2146 2191 } 2147 2192 … … 2164 2209 } 2165 2210 owl_mainwin_redisplay(owl_global_get_mainwin(&g)); 2211 return true; 2166 2212 } 2167 2213 … … 2175 2221 * Returns the name of the negated filter, which the caller must free. 2176 2222 */ 2177 char *owl_function_create_negative_filter(const char *filtername)2223 CALLER_OWN char *owl_function_create_negative_filter(const char *filtername) 2178 2224 { 2179 2225 char *newname; … … 2245 2291 { 2246 2292 const owl_filter *f; 2247 const owl_list*fl;2293 const GPtrArray *fl; 2248 2294 char *tmp; 2249 2295 owl_fmtext fm; 2250 int i , j;2296 int i; 2251 2297 2252 2298 owl_fmtext_init_null(&fm); 2253 2299 2254 2300 fl=owl_global_get_puntlist(&g); 2255 j=owl_list_get_size(fl);2256 2301 owl_fmtext_append_bold(&fm, "Active zpunt filters:\n"); 2257 2302 2258 for (i =0; i<j; i++) {2259 f =owl_list_get_element(fl, i);2303 for (i = 0; i < fl->len; i++) { 2304 f = fl->pdata[i]; 2260 2305 owl_fmtext_appendf_normal(&fm, "[% 2d] ", i+1); 2261 2306 tmp = owl_filter_print(f); … … 2272 2317 * If 'related' is nonzero, encompass unclasses and .d classes as well. 2273 2318 */ 2274 char *owl_function_classinstfilt(const char *c, const char *i, int related)2319 CALLER_OWN char *owl_function_classinstfilt(const char *c, const char *i, int related) 2275 2320 { 2276 2321 owl_filter *f; … … 2359 2404 * the filter, which the caller must free. 2360 2405 */ 2361 char *owl_function_zuserfilt(const char *longuser)2406 CALLER_OWN char *owl_function_zuserfilt(const char *longuser) 2362 2407 { 2363 2408 owl_filter *f; … … 2405 2450 * Returns the name of the filter, which the caller must free. 2406 2451 */ 2407 char *owl_function_aimuserfilt(const char *user)2452 CALLER_OWN char *owl_function_aimuserfilt(const char *user) 2408 2453 { 2409 2454 owl_filter *f; … … 2416 2461 /* if it already exists then go with it. This lets users override */ 2417 2462 if (owl_global_get_filter(&g, filtname)) { 2418 return (g_strdup(filtname));2463 return filtname; 2419 2464 } 2420 2465 … … 2443 2488 } 2444 2489 2445 char *owl_function_typefilt(const char *type)2490 CALLER_OWN char *owl_function_typefilt(const char *type) 2446 2491 { 2447 2492 owl_filter *f; … … 2499 2544 } 2500 2545 2501 static char *owl_function_smartfilter_cc(const owl_message *m) { 2546 static CALLER_OWN char *owl_function_smartfilter_cc(const owl_message *m) 2547 { 2502 2548 const char *ccs; 2503 2549 char *ccs_quoted; … … 2550 2596 * name to the AIM conversation with that user 2551 2597 */ 2552 char *owl_function_smartfilter(int type, int invert_related)2598 CALLER_OWN char *owl_function_smartfilter(int type, int invert_related) 2553 2599 { 2554 2600 const owl_view *v; … … 2809 2855 2810 2856 owl_function_punt(argv->len, (const char *const*) argv->pdata, direction); 2811 g_ptr_array_foreach(argv, (GFunc)g_free, NULL); 2812 g_ptr_array_free(argv, true); 2857 owl_ptr_array_free(argv, g_free); 2813 2858 } 2814 2859 … … 2816 2861 { 2817 2862 owl_filter *f; 2818 owl_list*fl;2819 int i , j;2863 GPtrArray *fl; 2864 int i; 2820 2865 fl=owl_global_get_puntlist(&g); 2821 2866 … … 2828 2873 2829 2874 /* Check for an identical filter */ 2830 j=owl_list_get_size(fl); 2831 for (i=0; i<j; i++) { 2832 if (owl_filter_equiv(f, owl_list_get_element(fl, i))) { 2875 for (i = 0; i < fl->len; i++) { 2876 if (owl_filter_equiv(f, fl->pdata[i])) { 2833 2877 owl_function_debugmsg("found an equivalent punt filter"); 2834 2878 /* if we're punting, then just silently bow out on this duplicate */ … … 2840 2884 /* if we're unpunting, then remove this filter from the puntlist */ 2841 2885 if (direction==1) { 2842 owl_filter_delete(owl_list_get_element(fl, i)); 2843 owl_list_remove_element(fl, i); 2886 owl_filter_delete(g_ptr_array_remove_index(fl, i)); 2844 2887 owl_filter_delete(f); 2845 2888 return; … … 2851 2894 owl_function_debugmsg("punting"); 2852 2895 /* If we're punting, add the filter to the global punt list */ 2853 owl_list_append_element(fl, f);2896 g_ptr_array_add(fl, f); 2854 2897 } else if (direction == 1) { 2855 2898 owl_function_makemsg("No matching punt filter"); … … 2859 2902 void owl_function_show_keymaps(void) 2860 2903 { 2861 owl_listl;2904 GPtrArray *l; 2862 2905 owl_fmtext fm; 2863 2906 const owl_keymap *km; 2864 2907 const owl_keyhandler *kh; 2865 int i , numkm;2908 int i; 2866 2909 const char *kmname; 2867 2910 … … 2870 2913 owl_fmtext_append_bold(&fm, "Keymaps: "); 2871 2914 owl_fmtext_append_normal(&fm, "(use 'show keymap <name>' for details)\n"); 2872 owl_list_create(&l); 2873 owl_keyhandler_get_keymap_names(kh, &l); 2874 owl_fmtext_append_list(&fm, &l, "\n", owl_function_keymap_summary); 2915 l = owl_keyhandler_get_keymap_names(kh); 2916 owl_fmtext_append_list(&fm, l, "\n", owl_function_keymap_summary); 2875 2917 owl_fmtext_append_normal(&fm, "\n"); 2876 2918 2877 numkm = owl_list_get_size(&l); 2878 for (i=0; i<numkm; i++) { 2879 kmname = owl_list_get_element(&l, i); 2919 for (i = 0; i < l->len; i++) { 2920 kmname = l->pdata[i]; 2880 2921 km = owl_keyhandler_get_keymap(kh, kmname); 2881 2922 owl_fmtext_append_bold(&fm, "\n\n----------------------------------------------------------------------------------------------------\n\n"); … … 2885 2926 2886 2927 owl_function_popless_fmtext(&fm); 2887 owl_ list_cleanup(&l, g_free);2928 owl_ptr_array_free(l, g_free); 2888 2929 owl_fmtext_cleanup(&fm); 2889 2930 } 2890 2931 2891 char *owl_function_keymap_summary(const char *name)2932 CALLER_OWN char *owl_function_keymap_summary(const char *name) 2892 2933 { 2893 2934 const owl_keymap *km … … 3003 3044 /* strips formatting from ztext and returns the unformatted text. 3004 3045 * caller is responsible for freeing. */ 3005 char *owl_function_ztext_stylestrip(const char *zt)3046 CALLER_OWN char *owl_function_ztext_stylestrip(const char *zt) 3006 3047 { 3007 3048 owl_fmtext fm; … … 3026 3067 #ifdef HAVE_LIBZEPHYR 3027 3068 int x; 3028 owl_listanyone;3069 GPtrArray *anyone; 3029 3070 const char *user; 3030 3071 char *tmp; … … 3046 3087 idle=owl_buddy_get_idle_time(b); 3047 3088 if (idle!=0) { 3048 timestr=owl_util_ minutes_to_timestr(idle);3089 timestr=owl_util_format_minutes(idle); 3049 3090 } else { 3050 3091 timestr=g_strdup(""); … … 3061 3102 } else { 3062 3103 owl_fmtext_append_bold(&fm, "Zephyr users logged in:\n"); 3063 owl_list_create(&anyone); 3064 ret=owl_zephyr_get_anyone_list(&anyone, filename); 3065 if (ret) { 3104 anyone = owl_zephyr_get_anyone_list(filename); 3105 if (anyone == NULL) { 3066 3106 if (errno == ENOENT) { 3067 3107 owl_fmtext_append_normal(&fm, " You have not added any zephyr buddies. Use the\n"); … … 3073 3113 } 3074 3114 } else { 3075 j=owl_list_get_size(&anyone); 3076 for (i=0; i<j; i++) { 3077 user=owl_list_get_element(&anyone, i); 3115 for (i = 0; i < anyone->len; i++) { 3116 user = anyone->pdata[i]; 3078 3117 ret=ZLocateUser(zstr(user), &numlocs, ZAUTH); 3079 3118 … … 3107 3146 } 3108 3147 } 3109 owl_ list_cleanup(&anyone, g_free);3148 owl_ptr_array_free(anyone, g_free); 3110 3149 } 3111 3150 } … … 3184 3223 } 3185 3224 3186 /* if it exited, fork & execa new one */3225 /* if it exited, spawn a new one */ 3187 3226 if (owl_global_get_newmsgproc_pid(&g)==0) { 3188 pid_t i;3189 3227 int myargc; 3190 i=fork(); 3191 if (i) { 3192 /* parent set the child's pid */ 3193 owl_global_set_newmsgproc_pid(&g, i); 3194 owl_function_debugmsg("I'm the parent and I started a new newmsgproc with pid %i", i); 3195 } else { 3196 /* child exec's the program */ 3197 char **parsed; 3198 parsed=owl_parseline(owl_global_get_newmsgproc(&g), &myargc); 3199 if (myargc < 0) { 3200 owl_function_debugmsg("Could not parse newmsgproc '%s': unbalanced quotes?", owl_global_get_newmsgproc(&g)); 3201 } 3202 if (myargc <= 0) { 3203 _exit(127); 3204 } 3205 owl_function_debugmsg("About to exec \"%s\" with %d arguments", parsed[0], myargc); 3206 3207 execvp(parsed[0], parsed); 3208 3209 3210 /* was there an error exec'ing? */ 3211 owl_function_debugmsg("Cannot run newmsgproc '%s': cannot exec '%s': %s", 3212 owl_global_get_newmsgproc(&g), parsed[0], strerror(errno)); 3213 _exit(127); 3228 char **argv = owl_parseline(owl_global_get_newmsgproc(&g), &myargc); 3229 if (myargc < 0) { 3230 owl_function_debugmsg("Could not parse newmsgproc '%s': unbalanced quotes?", 3231 owl_global_get_newmsgproc(&g)); 3232 } else if (myargc > 0) { 3233 /* Spawn the child. */ 3234 GPid pid; 3235 GError *error = NULL; 3236 owl_function_debugmsg("About to exec \"%s\" with %d arguments", argv[0], myargc); 3237 if (g_spawn_async(NULL, argv, NULL, 3238 G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, 3239 NULL, NULL, &pid, &error)) { 3240 owl_global_set_newmsgproc_pid(&g, pid); 3241 owl_function_debugmsg("I'm the parent and I started a new newmsgproc with pid %i", pid); 3242 } else { 3243 owl_function_debugmsg("Cannot run newmsgproc '%s': %s", 3244 owl_global_get_newmsgproc(&g), error->message); 3245 g_error_free(error); 3246 } 3214 3247 } 3248 g_strfreev(argv); 3215 3249 } 3216 3250 } … … 3381 3415 char *buff; 3382 3416 3383 now=time(NULL); 3384 date=g_strdup(ctime(&now)); 3385 date[strlen(date)-1]='\0'; 3417 now = time(NULL); 3418 date = owl_util_format_time(localtime(&now)); 3386 3419 3387 3420 buff = g_strdup_printf("%s %s", date, string); … … 3424 3457 { 3425 3458 #ifdef HAVE_LIBZEPHYR 3426 int i , j;3427 owl_listanyone;3459 int i; 3460 GPtrArray *anyone; 3428 3461 GList **zaldlist; 3429 3462 GList *zaldptr; … … 3445 3478 *zaldlist = NULL; 3446 3479 3447 owl_list_create(&anyone); 3448 owl_zephyr_get_anyone_list(&anyone, NULL); 3449 j = owl_list_get_size(&anyone); 3450 for (i = 0; i < j; i++) { 3451 user = owl_list_get_element(&anyone, i); 3452 zald = g_new(ZAsyncLocateData_t, 1); 3453 if (ZRequestLocations(zstr(user), zald, UNACKED, ZAUTH) == ZERR_NONE) { 3454 *zaldlist = g_list_append(*zaldlist, zald); 3455 } else { 3456 g_free(zald); 3457 } 3458 } 3459 3460 owl_list_cleanup(&anyone, g_free); 3480 anyone = owl_zephyr_get_anyone_list(NULL); 3481 if (anyone != NULL) { 3482 for (i = 0; i < anyone->len; i++) { 3483 user = anyone->pdata[i]; 3484 zald = g_new(ZAsyncLocateData_t, 1); 3485 if (ZRequestLocations(zstr(user), zald, UNACKED, ZAUTH) == ZERR_NONE) { 3486 *zaldlist = g_list_append(*zaldlist, zald); 3487 } else { 3488 g_free(zald); 3489 } 3490 } 3491 owl_ptr_array_free(anyone, g_free); 3492 } 3461 3493 #endif 3462 3494 } 3463 3495 3464 void owl_function_aimsearch_results(const char *email, owl_list*namelist)3496 void owl_function_aimsearch_results(const char *email, GPtrArray *namelist) 3465 3497 { 3466 3498 owl_fmtext fm; 3467 int i , j;3499 int i; 3468 3500 3469 3501 owl_fmtext_init_null(&fm); … … 3472 3504 owl_fmtext_append_normal(&fm, ":\n"); 3473 3505 3474 j=owl_list_get_size(namelist); 3475 for (i=0; i<j; i++) { 3506 for (i = 0; i < namelist->len; i++) { 3476 3507 owl_fmtext_append_normal(&fm, " "); 3477 owl_fmtext_append_normal(&fm, owl_list_get_element(namelist, i));3508 owl_fmtext_append_normal(&fm, namelist->pdata[i]); 3478 3509 owl_fmtext_append_normal(&fm, "\n"); 3479 3510 }
Note: See TracChangeset
for help on using the changeset viewer.