Changeset fe7ece2
- Timestamp:
- Jul 9, 2011, 4:10:45 PM (13 years ago)
- Parents:
- 786a410 (diff), caac19d (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. - Files:
-
- 26 edited
Legend:
- Unmodified
- Added
- Removed
-
commands.c
ra16d7e5 rfe7ece2 693 693 "current view.\n"), 694 694 OWLCMD_ALIAS("del", "delete"), 695 696 OWLCMD_ARGS("delete-and-expunge", owl_command_delete_and_expunge, OWL_CTX_INTERACTIVE, 697 "delete a message", 698 "delete-and-expunge [-id msgid] [-q | --quiet]", 699 "If no message id is specified the current message is deleted.\n" 700 "Otherwise the message with the given message id is deleted.\n" 701 "If --quiet is specified, then there is no message displayed on\n" 702 "success.\n"), 703 OWLCMD_ALIAS("delx", "delete-and-expunge"), 695 704 696 705 OWLCMD_ARGS("undelete", owl_command_undelete, OWL_CTX_INTERACTIVE, … … 2354 2363 } 2355 2364 2365 char *owl_command_delete_and_expunge(int argc, const char *const *argv, const char *buff) 2366 { 2367 bool exclaim_success = true; 2368 2369 if (argc > 1 && (!strcmp(argv[1], "-q") || !strcmp(argv[1], "--quiet"))) { 2370 exclaim_success = false; 2371 argc--; 2372 argv++; 2373 } else if (!strcmp(argv[argc - 1], "-q") || !strcmp(argv[argc - 1], "--quiet")) { 2374 exclaim_success = false; 2375 argc--; 2376 } 2377 2378 if (argc == 1) { 2379 owl_function_delete_and_expunge_cur(exclaim_success); 2380 return NULL; 2381 } 2382 2383 if (argc == 3 && (!strcmp(argv[1], "-id") || !strcmp(argv[1], "--id"))) { 2384 owl_function_delete_and_expunge_by_id(atoi(argv[2]), exclaim_success); 2385 return NULL; 2386 } 2387 2388 owl_function_makemsg("Unknown arguments to delete-and-expunge command"); 2389 return NULL; 2390 } 2391 2356 2392 char *owl_command_undelete(int argc, const char *const *argv, const char *buff) 2357 2393 { -
functions.c
ra16d7e5 rfe7ece2 662 662 } 663 663 664 void owl_function_delete_and_expunge_message(int n) 665 { 666 owl_messagelist *ml = owl_global_get_msglist(&g); 667 owl_view *v = owl_global_get_current_view(&g); 668 int lastmsgid = owl_function_get_curmsg_id(v); 669 670 /* delete and expunge the message */ 671 owl_messagelist_delete_and_expunge_element(ml, n); 672 673 owl_function_redisplay_to_nearest(lastmsgid, v); 674 } 675 676 void owl_function_delete_and_expunge_cur(bool exclaim_success) 677 { 678 int curmsg; 679 const owl_view *v = owl_global_get_current_view(&g); 680 681 /* bail if there's no current message */ 682 if (owl_view_get_size(v) < 1) { 683 owl_function_error("No current message to delete"); 684 return; 685 } 686 687 /* delete the current message */ 688 curmsg = owl_global_get_curmsg(&g); 689 owl_function_delete_and_expunge_message(curmsg); 690 if (exclaim_success) 691 owl_function_makemsg("Message deleted and expunged"); 692 } 693 664 694 /* if move_after is 1, moves after the delete */ 665 695 void owl_function_deletecur(int move_after) … … 721 751 } 722 752 753 /* returns the current message id, if it exists. Otherwise returns 754 * -1 if we are past the end of the message list, and 0 otherwise. */ 755 int owl_function_get_curmsg_id(const owl_view *v) 756 { 757 int curmsg = owl_global_get_curmsg(&g); 758 const owl_message *m = owl_view_get_element(v, curmsg); 759 if (m) 760 return owl_message_get_id(m); 761 if (curmsg > 0) /* past the end of the message list (probably) */ 762 return -1; 763 return 0; 764 } 765 766 /* redisplays the view to the nearest message to the id given. 767 * if msgid < 0, redisplay to past the end of the message list */ 768 void owl_function_redisplay_to_nearest(int msgid, owl_view *v) 769 { 770 int curmsg; 771 /* update all views (we only have one right now) */ 772 owl_view_recalculate(v); 773 774 /* find where the new position should be */ 775 if (msgid < 0) { 776 /* If already at the end, blank the screen and move curmsg 777 * past the end of the messages. */ 778 curmsg = owl_view_get_size(v); 779 owl_global_set_topmsg(&g, curmsg); 780 owl_global_set_curmsg(&g, curmsg); 781 } else { 782 curmsg = owl_view_get_nearest_to_msgid(v, msgid); 783 if (curmsg > owl_view_get_size(v) - 1) 784 curmsg = owl_view_get_size(v) - 1; 785 if (curmsg < 0) 786 curmsg = 0; 787 owl_global_set_curmsg(&g, curmsg); 788 owl_function_calculate_topmsg(OWL_DIRECTION_NONE); 789 } 790 /* if there are no messages set the direction to down in case we 791 * delete everything upwards */ 792 owl_global_set_direction_downwards(&g); 793 794 owl_mainwin_redisplay(owl_global_get_mainwin(&g)); 795 } 796 723 797 void owl_function_expunge(void) 724 798 { 725 int curmsg; 726 const owl_message *m; 727 owl_messagelist *ml; 728 owl_view *v; 729 int lastmsgid=0; 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); 736 if (m) lastmsgid = owl_message_get_id(m); 799 owl_messagelist *ml = owl_global_get_msglist(&g); 800 owl_view *v = owl_global_get_current_view(&g); 801 int lastmsgid = owl_function_get_curmsg_id(v); 737 802 738 803 /* expunge the message list */ 739 804 owl_messagelist_expunge(ml); 740 805 741 /* update all views (we only have one right now) */ 742 owl_view_recalculate(v); 743 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); 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); 806 owl_function_redisplay_to_nearest(lastmsgid, v); 754 807 755 808 owl_function_makemsg("Messages expunged"); 756 owl_mainwin_redisplay(owl_global_get_mainwin(&g));757 809 } 758 810 … … 1642 1694 } 1643 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 } 1707 } 1708 1644 1709 /* note: this applies to global message list, not to view. 1645 1710 * If flag is 1, deletes. If flag is 0, undeletes. */ -
messagelist.c
r901cee9 rfe7ece2 30 30 } 31 31 32 owl_message *owl_messagelist_get_by_id(const owl_messagelist *ml, int target_id)32 int owl_messagelist_get_index_by_id(const owl_messagelist *ml, int target_id) 33 33 { 34 /* return the message with id == 'id'. If it doesn't exist return NULL. */34 /* return the message index with id == 'id'. If it doesn't exist return -1. */ 35 35 int first, last, mid, msg_id; 36 36 owl_message *m; … … 43 43 msg_id = owl_message_get_id(m); 44 44 if (msg_id == target_id) { 45 return (m);45 return mid; 46 46 } else if (msg_id < target_id) { 47 47 first = mid + 1; … … 50 50 } 51 51 } 52 return(NULL); 52 return -1; 53 } 54 55 owl_message *owl_messagelist_get_by_id(const owl_messagelist *ml, int target_id) 56 { 57 /* return the message with id == 'id'. If it doesn't exist return NULL. */ 58 int n = owl_messagelist_get_index_by_id(ml, target_id); 59 if (n < 0) return NULL; 60 return ml->list->pdata[n]; 53 61 } 54 62 … … 71 79 owl_message_unmark_delete(ml->list->pdata[n]); 72 80 return(0); 81 } 82 83 void owl_messagelist_delete_and_expunge_element(owl_messagelist *ml, int n) 84 { 85 owl_message_delete(g_ptr_array_remove_index(ml->list, n)); 73 86 } 74 87 -
perl/lib/BarnOwl.pm
r785ee77 rfe7ece2 105 105 Enqueue a message in the BarnOwl message list, logging it and 106 106 processing it appropriately. C<MESSAGE> should be an instance of 107 BarnOwl::Message or a subclass. 107 BarnOwl::Message or a subclass. Returns the queued message. This 108 is useful for, e.g., deleting a message from the message list. 108 109 109 110 =head2 admin_message HEADER BODY -
perl/lib/BarnOwl/Message.pm
rd1ae4a4 rcaac19d 81 81 sub short_personal_context { return ""; } 82 82 83 sub delete_and_expunge { 84 my ($m) = @_; 85 &BarnOwl::command("delete-and-expunge --quiet --id " . $m->id); 86 } 87 83 88 sub delete { 84 89 my ($m) = @_; -
perlglue.xs
rce68f23 rcaac19d 143 143 g_free(rv); 144 144 145 void 145 SV * 146 146 queue_message(msg) 147 147 SV *msg … … 157 157 158 158 owl_global_messagequeue_addmsg(&g, m); 159 } 159 160 RETVAL = owl_perlconfig_message2hashref(m); 161 } 162 OUTPUT: 163 RETVAL 160 164 161 165 void -
doc/barnowl.1
rfa1b15b rbad4496 1 .TH barnowl 1 "23 Jun 2008"1 .TH BARNOWL 1 "24 Jun 2011" 2 2 .SH NAME 3 barnowl \- ttybased zephyr client3 BarnOwl \- tty\(hybased zephyr client 4 4 .SH SYNOPSIS 5 5 .B barnowl 6 [ \-n 7 ] 8 [ \-d 9 ] 10 [ \-D 11 ] 12 [ \-v 13 ] 14 [ \-h 15 ] 16 [ \-c 17 .I configfile 18 ] 19 [ \-t 20 .I tty 21 ] 22 [ \-s 23 .I configdir 24 ] 6 [\-n] 7 [\-d] 8 [\-D] 9 [\-v] 10 [\-h] 11 [\-c \fICONFIGFILE\fP] 12 [\-t \fITTY\fP] 13 [\-s \fICONFIGDIR\fP] 25 14 .br 26 15 .SH DESCRIPTION 27 16 .B BarnOwl 28 is a fully integrated tty 29 it supports AOL Instant Messenger, MIT Zephyr, and Jabber. It is30 curses -based, allows for emacs-style editing of outgoing messagesand31 uses perl as an extension and configuration language. BarnOwlwill17 is a fully integrated tty\(hybased instant messaging client. Currently 18 it supports AOL Instant Messenger, MIT Zephyr, Jabber, IRC, and Twitter. It is 19 curses\(hybased, allows for emacs\(hystyle editing of outgoing messages, and 20 uses Perl as an extension and configuration language. \fBBarnOwl\fP will 32 21 also run happily without a configuration file. 33 22 34 Once BarnOwl is started, typing 'h'will display a help screen.35 Typing \ ':\' enters command mode, allowing the user to type a barnowl23 Once \fBBarnOwl\fP is started, typing \(oqh\(cq will display a help screen. 24 Typing \(oq:\(cq enters command mode, allowing the user to type a \fBBarnOwl\fP 36 25 command line. 37 26 38 .PP 39 .SH USE 40 The following command line options are avilable when running barnowl: 27 .SH OPTIONS 28 The following command\-line options are avilable when running \fBBarnOwl\fP: 29 .TP 30 \fB\-n\fP, \fB\-\-no\-subs\fP 31 Do not subscribe to zephyr messages on startup. By default, \fBBarnOwl\fP 32 subscribes to the default subscriptions and to anything found in 33 \fI~/.zephyr.subs\fP. When this option is used, no subscriptions are loaded. 41 34 42 .B \-n 43 .IP 44 Do not subscribe to zephyr messages on startup. By default BarnOwl 45 subscribes to the default subscriptions and to anything found in 46 ~/.zephyr.subs. When this option is used no subscriptions are loaded. 47 .LP 35 .TP 36 \fB\-c\fP, \fB\-\-config\-file\fP=\fIFILE\fP 37 Specify an alternate config file for \fBBarnOwl\fP to use. By default, 38 \fBBarnOwl\fP uses \fI~/.barnowlconf\fP if it exists, and \fI~/.owlconf\fP otherwise. 48 39 49 .B \-c \fIconfigfile\fP 50 .IP 51 Specifiy an alternate config file for BarnOwl to use. By default, 52 barnowl uses ~/.barnowlconf if it exists, and ~/.owlconf otherwise. 53 .LP 40 .TP 41 \fB\-s\fP, \fB\-\-config\-dir\fP=\fIDIR\fP 42 Specify an alternate configuration directory. By default, \fBBarnOwl\fP uses 43 \fI~/.owl/\fP. 54 44 55 .B \-s \fIconfigdir\fP 56 .IP 57 Specify an alternate configuration directory. By default, BarnOwl uses 58 ~/.owl/. 59 .LP 45 .TP 46 \fB\-t\fP, \fB\-\-tty\fP=\fITTY\fP 47 Specify the tty name to use for the zephyr location. 60 48 61 .B \-t \fItty\fP 62 .IP 63 Specifiy the tty name to use for the zephyr location. 64 .LP 49 .TP 50 \fB\-v\fP, \fB\-\-version\fP 51 Print the version number of \fBBarnOwl\fP and exit. 65 52 66 . B \-v67 .IP68 Print the version number of barnowl and exit. 69 .LP 53 .TP 54 \fB\-d\fP, \fB\-\-debug\fP 55 Enable debugging. By default, debugging information is placed in 56 \fI/var/tmp/barnowl\-debug.PID\fP. 70 57 71 .B \-d 72 .IP 73 Enable debugging. By default debugging information is placed in 74 /var/tmp/owldebug. 75 .LP 58 .TP 59 \fB\-h\fP, \fB\-\-help\fP 60 Print command\(hyline option help. 76 61 77 .B \-D 78 .IP 79 Enable debugging, but first delete any existing debugging file. 80 .LP 81 82 .B \-h 83 .IP 84 Print command line option help. 85 .LP 86 87 .SH AUTHOR 62 .SH AUTHORS 88 63 Written by Nelson Elhage and Alejandro Sedeno at the Massachusetts 89 Institute of Technology. Based on Owl by James Kretchmar.64 Institute of Technology. Based on Owl by James Kretchmar. 90 65 91 66 Comments, questions, and bug reports may be mailed to 92 \fBbug -barnowl@mit.edu\fP.67 \fBbug\-barnowl@mit.edu\fP. -
filterelement.c
rd4927a7 r7756dde 104 104 } 105 105 106 /* XXX: Our boolea operators short-circuit here. The original owl did106 /* XXX: Our boolean operators short-circuit here. The original owl did 107 107 not. Do we care? 108 108 */ -
help.c
rce68f23 ra16d7e5 4 4 void owl_help(void) 5 5 { 6 const owl_variable *v; 6 7 owl_fmtext fm; 7 8 const char *varname; … … 69 70 " w Open a URL in the current message\n" 70 71 " C-l Refresh the screen\n" 71 " C-z Suspend Owl\n"72 " C-z Suspend BarnOwl\n" 72 73 " h Print this help message\n" 73 74 " : , M-x Enter command mode\n" … … 83 84 owl_fmtext_append_normal 84 85 (&fm, 85 " quit, exit Exit owl\n"86 " quit, exit Exit BarnOwl\n" 86 87 " help Get help about commands\n" 87 " show Show information about owl (see detailed help)\n"88 " show Show information about BarnOwl (see detailed help)\n" 88 89 "\n" 89 90 " zwrite Send a zephyr\n" … … 101 102 " set Set a variable (see list below)\n" 102 103 " print Print a variable's value (variables listed below)\n" 103 " startup Set a command to be run at every Owl startup\n"104 " unstartup Remove a command to be run at every Owl startup\n"104 " startup Set a command to be run at every BarnOwl startup\n" 105 " unstartup Remove a command to be run at every BarnOwl startup\n" 105 106 "\n" 106 107 " getsubs Print a list of current subscriptions\n" … … 121 122 " dump Dump messagelist as text to a file\n" 122 123 "\n" 123 " about Print information about owl\n"124 " status Print status information about the running owl\n"125 " version Print the version number of owl\n"124 " about Print information about BarnOwl\n" 125 " status Print status information about the running BarnOwl\n" 126 " version Print the version number of BarnOwl\n" 126 127 "\n"); 127 128 … … 133 134 varname = varnames->pdata[i]; 134 135 if (varname && varname[0]!='_') { 135 owl_variable_describe(owl_global_get_vardict(&g), varname, &fm); 136 v = owl_variable_get_var(owl_global_get_vardict(&g), varname); 137 owl_variable_describe(v, &fm); 136 138 } 137 139 } -
m4/ax_check_flag.m4
rf2a96c0 r82e93c9 72 72 # exception to the GPL to apply to your modified version as well. 73 73 74 #serial 274 #serial 3 75 75 76 76 AC_DEFUN([AX_CHECK_PREPROC_FLAG], … … 81 81 CPPFLAGS="$CPPFLAGS $4 $1" 82 82 AC_PREPROC_IFELSE([AC_LANG_PROGRAM()], 83 [AS_VAR_SET( [CACHEVAR],[yes])],84 [AS_VAR_SET( [CACHEVAR],[no])])83 [AS_VAR_SET(CACHEVAR,[yes])], 84 [AS_VAR_SET(CACHEVAR,[no])]) 85 85 CPPFLAGS=$ax_check_save_flags]) 86 AS_ VAR_IF([CACHEVAR], "yes",86 AS_IF([test x"AS_VAR_GET(CACHEVAR)" = xyes], 87 87 [m4_default([$2], :)], 88 88 [m4_default([$3], :)]) … … 97 97 _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1" 98 98 AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], 99 [AS_VAR_SET( [CACHEVAR],[yes])],100 [AS_VAR_SET( [CACHEVAR],[no])])99 [AS_VAR_SET(CACHEVAR,[yes])], 100 [AS_VAR_SET(CACHEVAR,[no])]) 101 101 _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags]) 102 AS_ VAR_IF([CACHEVAR], "yes",102 AS_IF([test x"AS_VAR_GET(CACHEVAR)" = xyes], 103 103 [m4_default([$2], :)], 104 104 [m4_default([$3], :)]) … … 112 112 LDFLAGS="$LDFLAGS $4 $1" 113 113 AC_LINK_IFELSE([AC_LANG_PROGRAM()], 114 [AS_VAR_SET( [CACHEVAR],[yes])],115 [AS_VAR_SET( [CACHEVAR],[no])])114 [AS_VAR_SET(CACHEVAR,[yes])], 115 [AS_VAR_SET(CACHEVAR,[no])]) 116 116 LDFLAGS=$ax_check_save_flags]) 117 AS_ VAR_IF([CACHEVAR], "yes",117 AS_IF([test x"AS_VAR_GET(CACHEVAR)" = xyes], 118 118 [m4_default([$2], :)], 119 119 [m4_default([$3], :)]) … … 124 124 AC_DEFUN([AX_APPEND_FLAG], 125 125 [AC_PREREQ(2.59) dnl for _AC_LANG_PREFIX 126 AC_REQUIRE([AC_PROG_GREP]) 127 AS_VAR_PUSHDEF([FLAGS], [m4_default($2,_AC_LANG_PREFIX[]FLAGS)])dnl 128 AS_VAR_SET_IF([FLAGS], 129 [AS_IF([AS_ECHO(" $[]FLAGS ") | $GREP " $1 " 2>&1 >/dev/null], 130 [AC_RUN_LOG([: FLAGS already contains $1])], 131 [AC_RUN_LOG([: FLAGS="$FLAGS $1"]) 132 AS_VAR_APPEND([FLAGS], [" $1"])])], 133 [AS_VAR_SET([FLAGS],[$1])]) 126 AS_VAR_PUSHDEF([FLAGS], [m4_default($2,_AC_LANG_PREFIX[FLAGS])])dnl 127 AS_VAR_SET_IF(FLAGS, 128 [case " AS_VAR_GET(FLAGS) " in 129 *" $1 "*) 130 AC_RUN_LOG([: FLAGS already contains $1]) 131 ;; 132 *) 133 AC_RUN_LOG([: FLAGS="$FLAGS $1"]) 134 AS_VAR_SET(FLAGS, ["AS_VAR_GET(FLAGS) $1"]) 135 ;; 136 esac], 137 [AS_VAR_SET(FLAGS,["$1"])]) 134 138 AS_VAR_POPDEF([FLAGS])dnl 135 139 ])dnl AX_APPEND_FLAG -
owl.c
r2244836 rb8a3e00 89 89 break; 90 90 case 'v': 91 printf("This is barnowl version %s\n", OWL_VERSION_STRING);91 printf("This is BarnOwl version %s\n", OWL_VERSION_STRING); 92 92 exit(0); 93 93 case 'h': … … 584 584 owl_function_adminmsg("", 585 585 "-----------------------------------------------------------------------\n" 586 "Welcome to barnowl version " OWL_VERSION_STRING ".\n"586 "Welcome to BarnOwl version " OWL_VERSION_STRING ".\n" 587 587 "To see a quick introduction, type ':show quickstart'. \n" 588 588 "Press 'h' for on-line help. \n" -
owl_perl.h
r06adc25 rb8a3e00 13 13 * * args - a code block responsible for pushing args (other than the object) 14 14 * * err - a string with a %s format specifier to log in case of error 15 * * fatalp - if true, perl errors terminate barnowl15 * * fatalp - if true, perl errors terminate BarnOwl 16 16 * * ret - a code block executed if the call succeeded 17 17 * -
perl/lib/BarnOwl/Hooks.pm
r3aa0522 rb8a3e00 146 146 } 147 147 148 # These are the internal hooks called by the barnowl C code, which148 # These are the internal hooks called by the BarnOwl C code, which 149 149 # take care of dispatching to the appropriate perl hooks, and deal 150 150 # with compatibility by calling the old, fixed-name hooks. -
perl/lib/Module/Install/BarnOwl.pm
r3519d06 rb8a3e00 8 8 =head1 DESCRIPTION 9 9 10 Module::Install::BarnOwl is a M::I module to help building barnowl10 Module::Install::BarnOwl is a M::I module to help building BarnOwl 11 11 modules, 12 12 … … 28 28 29 29 As well as make rules to generate Jabber.par, and to put some 30 additional barnowl-specific information into META.yml30 additional BarnOwl-specific information into META.yml 31 31 32 32 =cut -
perl/modules/IRC/lib/BarnOwl/Module/IRC.pm
r5c6d661 rb8a3e00 10 10 =head1 DESCRIPTION 11 11 12 This module implements IRC support for barnowl.12 This module implements IRC support for BarnOwl. 13 13 14 14 =cut -
perl/modules/Jabber/lib/BarnOwl/Module/Jabber.pm
rc8d9f84 rb8a3e00 10 10 =head1 DESCRIPTION 11 11 12 This module implements Jabber support for barnowl.12 This module implements Jabber support for BarnOwl. 13 13 14 14 =cut … … 36 36 if($IO::Socket::SSL::VERSION eq "0.97") { 37 37 BarnOwl::error("You are using IO::Socket:SSL 0.97, which \n" . 38 "contains bugs causing it not to work with barnowl's\n" .38 "contains bugs causing it not to work with BarnOwl's\n" . 39 39 "Jabber support. We recommend updating to the latest\n" . 40 40 "IO::Socket::SSL from CPAN. \n"); -
perl/modules/Jabber/lib/BarnOwl/Module/Jabber/ConnectionManager.pm
r2cca044 rb8a3e00 8 8 =head1 DESCRIPTION 9 9 10 A class to keep track of all the active connection in the barnowl11 jabber module10 A class to keep track of all the active connection in the BarnOwl 11 Jabber module 12 12 13 13 =cut -
perl/modules/Twitter/README
r8c6e2c1 rb8a3e00 118 118 the sender. Has no effect if poll_for_tweets is false. 119 119 120 * oauth_key, oauth_secret (strings, default barnowl's consumer credentials)120 * oauth_key, oauth_secret (strings, default BarnOwl's consumer credentials) 121 121 These are the OAuth consumer key and secret to use to negotiate an 122 122 OAuth connection to Twitter. These credentials must be enabled for -
perl/modules/Twitter/lib/BarnOwl/Module/Twitter.pm
rf6e1262 rb8a3e00 193 193 194 194 sub poll_messages { 195 # If we are reloaded into a barnowl with the old195 # If we are reloaded into a BarnOwl with the old 196 196 # BarnOwl::Module::Twitter loaded, it still has a main loop hook 197 197 # that will call this function every second. If we just delete it, -
runtests.sh
r5aa33fd r786a410 5 5 export BARNOWL_BIN_DIR="$SRCDIR/" 6 6 7 HARNESS_PERL=./tester exec prove t/7 HARNESS_PERL=./tester exec prove --failures t/ -
scripts/do-release
r74312ad rb8a3e00 9 9 cat >&2 <<EOF 10 10 Usage: $0 [options] 11 Generate a barnowl release tarball.11 Generate a BarnOwl release tarball. 12 12 13 13 OPTIONS: … … 37 37 else 38 38 VERS=$(perl -ne 'print $1 if m{^AC_INIT\(\[[^\]]+\],\s*\[([^\]]+)\]}' configure.ac) \ 39 || die "Unable to parse barnowl version"39 || die "Unable to parse BarnOwl version" 40 40 fi 41 41 TAG=barnowl-$VERS -
scripts/locker-build
r4f5e38f r401752a 119 119 $MAKE -j$CPUS all || die "make failed" 120 120 121 $MAKE check || die "Unit tests failed" 122 121 123 if [ -n "$DRYRUN" ]; then 122 124 echo "Build completed; Dropping to a shell..." -
stubgen.pl
rfd03b12 rca54fd6 14 14 if ($vartype =~ /^BOOL/) { 15 15 print "void owl_global_set_${altvarname}_on(owl_global *g) {\n"; 16 print " owl_variable_set_bool_on( &g->vars, \"$varname\");\n}\n";16 print " owl_variable_set_bool_on(owl_variable_get_var(&g->vars, \"$varname\"));\n}\n"; 17 17 print "void owl_global_set_${altvarname}_off(owl_global *g) {\n"; 18 print " owl_variable_set_bool_off( &g->vars, \"$varname\");\n}\n";18 print " owl_variable_set_bool_off(owl_variable_get_var(&g->vars, \"$varname\"));\n}\n"; 19 19 print "int owl_global_is_$altvarname(const owl_global *g) {\n"; 20 print " return owl_variable_get_bool( &g->vars, \"$varname\");\n}\n";20 print " return owl_variable_get_bool(owl_variable_get_var(&g->vars, \"$varname\"));\n}\n"; 21 21 } elsif ($vartype =~ /^PATH/ or $vartype =~ /^STRING/) { 22 22 print "void owl_global_set_$altvarname(owl_global *g, const char *text) {\n"; 23 print " owl_variable_set_string( &g->vars, \"$varname\", text);\n}\n";23 print " owl_variable_set_string(owl_variable_get_var(&g->vars, \"$varname\"), text);\n}\n"; 24 24 print "const char *owl_global_get_$altvarname(const owl_global *g) {\n"; 25 print " return owl_variable_get_string( &g->vars, \"$varname\");\n}\n";25 print " return owl_variable_get_string(owl_variable_get_var(&g->vars, \"$varname\"));\n}\n"; 26 26 } elsif ($vartype =~ /^INT/ or $vartype =~ /^ENUM/) { 27 27 print "void owl_global_set_$altvarname(owl_global *g, int n) {\n"; 28 print " owl_variable_set_int( &g->vars, \"$varname\", n);\n}\n";28 print " owl_variable_set_int(owl_variable_get_var(&g->vars, \"$varname\"), n);\n}\n"; 29 29 print "int owl_global_get_$altvarname(const owl_global *g) {\n"; 30 print " return owl_variable_get_int( &g->vars, \"$varname\");\n}\n";30 print " return owl_variable_get_int(owl_variable_get_var(&g->vars, \"$varname\"));\n}\n"; 31 31 } 32 32 } -
tester.c
r25891a8 r14c9e05 4 4 #undef WINDOW 5 5 6 #include <errno.h> 6 7 #include <unistd.h> 8 #include <pwd.h> 9 #include <stdio.h> 7 10 #include <stdlib.h> 11 #include <string.h> 12 #include <sys/types.h> 8 13 9 14 #undef instr … … 124 129 #define FAIL_UNLESS(desc,pred) do { int __pred = (pred); \ 125 130 numtests++; \ 126 printf("%s % s", (__pred)?"ok":(numfailed++,"not ok"), desc);\131 printf("%s %d %s", (__pred) ? "ok" : (numfailed++, "not ok"), numtests, desc); \ 127 132 if(!(__pred)) printf("\t(%s:%d)", __FILE__, __LINE__); printf("%c", '\n'); } while(0) 128 133 … … 131 136 { 132 137 int numfailed=0; 138 const char *home; 139 char *s, *path; 140 struct passwd *pw; 133 141 134 142 printf("# BEGIN testing owl_util\n"); … … 225 233 g_string_free(g, true); 226 234 235 236 s = owl_util_baseclass("barnowl"); 237 FAIL_UNLESS("baseclass barnowl", !strcmp("barnowl", s)); 238 g_free(s); 239 s = owl_util_baseclass("unbarnowl"); 240 FAIL_UNLESS("baseclass unbarnowl", !strcmp("barnowl", s)); 241 g_free(s); 242 s = owl_util_baseclass("unununbarnowl.d.d"); 243 FAIL_UNLESS("baseclass unununbarnowl.d.d", !strcmp("barnowl", s)); 244 g_free(s); 245 s = owl_util_baseclass("ununun.d.d"); 246 FAIL_UNLESS("baseclass ununun.d.d", !strcmp("", s)); 247 g_free(s); 248 s = owl_util_baseclass("d.d.d.d"); 249 FAIL_UNLESS("baseclass d.d.d.d", !strcmp("d", s)); 250 g_free(s); 251 s = owl_util_baseclass("n.d.d.d"); 252 FAIL_UNLESS("baseclass n.d.d.d", !strcmp("n", s)); 253 g_free(s); 254 s = owl_util_baseclass("ununun."); 255 FAIL_UNLESS("baseclass ununun.", !strcmp(".", s)); 256 g_free(s); 257 s = owl_util_baseclass("unununu"); 258 FAIL_UNLESS("baseclass unununu", !strcmp("u", s)); 259 g_free(s); 260 261 262 s = owl_util_makepath("foo/bar"); 263 FAIL_UNLESS("makepath foo/bar", !strcmp("foo/bar", s)); 264 g_free(s); 265 s = owl_util_makepath("//foo///bar"); 266 FAIL_UNLESS("makepath //foo///bar", !strcmp("/foo/bar", s)); 267 g_free(s); 268 s = owl_util_makepath("foo/~//bar/"); 269 FAIL_UNLESS("makepath foo/~//bar/", !strcmp("foo/~/bar/", s)); 270 g_free(s); 271 s = owl_util_makepath("~thisuserhadreallybetternotexist/foobar/"); 272 FAIL_UNLESS("makepath ~thisuserhadreallybetternotexist/foobar/", 273 !strcmp("~thisuserhadreallybetternotexist/foobar/", s)); 274 g_free(s); 275 276 errno = 0; 277 pw = getpwuid(getuid()); 278 if (pw) { 279 home = pw->pw_dir; 280 } else { 281 /* Just make some noise so we notice. */ 282 home = "<WHAT>"; 283 fprintf(stderr, "getpwuid: %s", errno ? strerror(errno) : "No such user"); 284 } 285 s = owl_util_makepath("~"); 286 FAIL_UNLESS("makepath ~", !strcmp(home, s)); 287 g_free(s); 288 289 path = g_strconcat(home, "/foo/bar/baz", NULL); 290 s = owl_util_makepath("~///foo/bar//baz"); 291 FAIL_UNLESS("makepath ~///foo/bar//baz", !strcmp(path, s)); 292 g_free(s); 293 g_free(path); 294 295 errno = 0; 296 pw = getpwnam("root"); 297 if (pw) { 298 home = pw->pw_dir; 299 } else { 300 /* Just make some noise so we notice. */ 301 home = "<WHAT>"; 302 fprintf(stderr, "getpwnam: %s", errno ? strerror(errno) : "No such user"); 303 } 304 305 s = owl_util_makepath("~root"); 306 FAIL_UNLESS("makepath ~root", !strcmp(home, s)); 307 g_free(s); 308 309 path = g_strconcat(home, "/foo/bar/baz", NULL); 310 s = owl_util_makepath("~root///foo/bar//baz"); 311 FAIL_UNLESS("makepath ~root///foo/bar//baz", !strcmp(path, s)); 312 g_free(s); 313 g_free(path); 314 227 315 /* if (numfailed) printf("*** WARNING: failures encountered with owl_util\n"); */ 228 316 printf("# END testing owl_util (%d failures)\n", numfailed); … … 276 364 int owl_variable_regtest(void) { 277 365 owl_vardict vd; 366 owl_variable *var; 278 367 int numfailed=0; 279 368 char *value; … … 283 372 FAIL_UNLESS("setup", 0==owl_variable_dict_setup(&vd)); 284 373 285 FAIL_UNLESS("get bool", 0==owl_variable_get_bool(&vd,"rxping")); 286 FAIL_UNLESS("get bool (no such)", -1==owl_variable_get_bool(&vd,"mumble")); 374 FAIL_UNLESS("get bool var", NULL != (var = owl_variable_get_var(&vd, "rxping"))); 375 FAIL_UNLESS("get bool", 0 == owl_variable_get_bool(var)); 376 FAIL_UNLESS("get bool (no such)", NULL == owl_variable_get_var(&vd, "mumble")); 287 377 FAIL_UNLESS("get bool as string", 288 !strcmp((value = owl_variable_get_tostring( &vd,"rxping")), "off"));378 !strcmp((value = owl_variable_get_tostring(var)), "off")); 289 379 g_free(value); 290 FAIL_UNLESS("set bool 1", 0==owl_variable_set_bool_on(&vd,"rxping")); 291 FAIL_UNLESS("get bool 2", 1==owl_variable_get_bool(&vd,"rxping")); 292 FAIL_UNLESS("set bool 3", 0==owl_variable_set_fromstring(&vd,"rxping","off",0,0)); 293 FAIL_UNLESS("get bool 4", 0==owl_variable_get_bool(&vd,"rxping")); 294 FAIL_UNLESS("set bool 5", -1==owl_variable_set_fromstring(&vd,"rxping","xxx",0,0)); 295 FAIL_UNLESS("get bool 6", 0==owl_variable_get_bool(&vd,"rxping")); 296 297 298 FAIL_UNLESS("get string", 0==strcmp("~/zlog/people", owl_variable_get_string(&vd,"logpath"))); 299 FAIL_UNLESS("set string 7", 0==owl_variable_set_string(&vd,"logpath","whee")); 300 FAIL_UNLESS("get string", 0==strcmp("whee", owl_variable_get_string(&vd,"logpath"))); 301 302 FAIL_UNLESS("get int", 8==owl_variable_get_int(&vd,"typewinsize")); 303 FAIL_UNLESS("get int (no such)", -1==owl_variable_get_int(&vd,"mmble")); 380 FAIL_UNLESS("set bool 1", 0 == owl_variable_set_bool_on(var)); 381 FAIL_UNLESS("get bool 2", 1 == owl_variable_get_bool(var)); 382 FAIL_UNLESS("set bool 3", 0 == owl_variable_set_fromstring(var, "off", 0)); 383 FAIL_UNLESS("get bool 4", 0 == owl_variable_get_bool(var)); 384 FAIL_UNLESS("set bool 5", -1 == owl_variable_set_fromstring(var, "xxx", 0)); 385 FAIL_UNLESS("get bool 6", 0 == owl_variable_get_bool(var)); 386 387 388 FAIL_UNLESS("get string var", NULL != (var = owl_variable_get_var(&vd, "logpath"))); 389 FAIL_UNLESS("get string", 0 == strcmp("~/zlog/people", owl_variable_get_string(var))); 390 FAIL_UNLESS("set string 7", 0 == owl_variable_set_string(var, "whee")); 391 FAIL_UNLESS("get string", !strcmp("whee", owl_variable_get_string(var))); 392 393 FAIL_UNLESS("get int var", NULL != (var = owl_variable_get_var(&vd, "typewinsize"))); 394 FAIL_UNLESS("get int", 8 == owl_variable_get_int(var)); 395 FAIL_UNLESS("get int (no such)", NULL == owl_variable_get_var(&vd, "mumble")); 304 396 FAIL_UNLESS("get int as string", 305 !strcmp((value = owl_variable_get_tostring( &vd,"typewinsize")), "8"));397 !strcmp((value = owl_variable_get_tostring(var)), "8")); 306 398 g_free(value); 307 FAIL_UNLESS("set int 1", 0 ==owl_variable_set_int(&vd,"typewinsize",12));308 FAIL_UNLESS("get int 2", 12 ==owl_variable_get_int(&vd,"typewinsize"));309 FAIL_UNLESS("set int 1b", -1 ==owl_variable_set_int(&vd,"typewinsize",-3));310 FAIL_UNLESS("get int 2b", 12 ==owl_variable_get_int(&vd,"typewinsize"));311 FAIL_UNLESS("set int 3", 0 ==owl_variable_set_fromstring(&vd,"typewinsize","9",0,0));312 FAIL_UNLESS("get int 4", 9 ==owl_variable_get_int(&vd,"typewinsize"));313 FAIL_UNLESS("set int 5", -1 ==owl_variable_set_fromstring(&vd,"typewinsize","xxx",0,0));314 FAIL_UNLESS("set int 6", -1 ==owl_variable_set_fromstring(&vd,"typewinsize","",0,0));315 FAIL_UNLESS("get int 7", 9 ==owl_variable_get_int(&vd,"typewinsize"));399 FAIL_UNLESS("set int 1", 0 == owl_variable_set_int(var, 12)); 400 FAIL_UNLESS("get int 2", 12 == owl_variable_get_int(var)); 401 FAIL_UNLESS("set int 1b", -1 == owl_variable_set_int(var, -3)); 402 FAIL_UNLESS("get int 2b", 12 == owl_variable_get_int(var)); 403 FAIL_UNLESS("set int 3", 0 == owl_variable_set_fromstring(var, "9", 0)); 404 FAIL_UNLESS("get int 4", 9 == owl_variable_get_int(var)); 405 FAIL_UNLESS("set int 5", -1 == owl_variable_set_fromstring(var, "xxx", 0)); 406 FAIL_UNLESS("set int 6", -1 == owl_variable_set_fromstring(var, "", 0)); 407 FAIL_UNLESS("get int 7", 9 == owl_variable_get_int(var)); 316 408 317 409 owl_variable_dict_newvar_string(&vd, "stringvar", "", "", "testval"); 318 FAIL_UNLESS("get new string var", NULL != (v = owl_variable_get(&vd, "stringvar", OWL_VARIABLE_STRING))); 319 FAIL_UNLESS("get new string val", !strcmp("testval", owl_variable_get_string(&vd, "stringvar"))); 320 owl_variable_set_string(&vd, "stringvar", "new val"); 321 FAIL_UNLESS("update string val", !strcmp("new val", owl_variable_get_string(&vd, "stringvar"))); 410 FAIL_UNLESS("get new string var", NULL != (var = owl_variable_get_var(&vd, "stringvar"))); 411 FAIL_UNLESS("get new string var", NULL != (v = owl_variable_get(var))); 412 FAIL_UNLESS("get new string val", !strcmp("testval", owl_variable_get_string(var))); 413 owl_variable_set_string(var, "new val"); 414 FAIL_UNLESS("update string val", !strcmp("new val", owl_variable_get_string(var))); 322 415 323 416 owl_variable_dict_newvar_int(&vd, "intvar", "", "", 47); 324 FAIL_UNLESS("get new int var", NULL != (v = owl_variable_get(&vd, "intvar", OWL_VARIABLE_INT))); 325 FAIL_UNLESS("get new int val", 47 == owl_variable_get_int(&vd, "intvar")); 326 owl_variable_set_int(&vd, "intvar", 17); 327 FAIL_UNLESS("update bool val", 17 == owl_variable_get_int(&vd, "intvar")); 417 FAIL_UNLESS("get new int var", NULL != (var = owl_variable_get_var(&vd, "intvar"))); 418 FAIL_UNLESS("get new int var", NULL != (v = owl_variable_get(var))); 419 FAIL_UNLESS("get new int val", 47 == owl_variable_get_int(var)); 420 owl_variable_set_int(var, 17); 421 FAIL_UNLESS("update int val", 17 == owl_variable_get_int(var)); 328 422 329 423 owl_variable_dict_newvar_bool(&vd, "boolvar", "", "", 1); 330 FAIL_UNLESS("get new bool var", NULL != (v = owl_variable_get(&vd, "boolvar", OWL_VARIABLE_BOOL))); 331 FAIL_UNLESS("get new bool val", owl_variable_get_bool(&vd, "boolvar")); 332 owl_variable_set_bool_off(&vd, "boolvar"); 333 FAIL_UNLESS("update string val", !owl_variable_get_bool(&vd, "boolvar")); 424 FAIL_UNLESS("get new bool var", NULL != (var = owl_variable_get_var(&vd, "boolvar"))); 425 FAIL_UNLESS("get new bool var", NULL != (v = owl_variable_get(var))); 426 FAIL_UNLESS("get new bool val", owl_variable_get_bool(var)); 427 owl_variable_set_bool_off(var); 428 FAIL_UNLESS("update bool val", !owl_variable_get_bool(var)); 429 430 owl_variable_dict_newvar_string(&vd, "nullstringvar", "", "", NULL); 431 FAIL_UNLESS("get new string (NULL) var", NULL != (var = owl_variable_get_var(&vd, "nullstringvar"))); 432 FAIL_UNLESS("get string (NULL)", NULL == (value = owl_variable_get_tostring(var))); 433 g_free(value); 434 var = owl_variable_get_var(&vd, "zsigproc"); 435 FAIL_UNLESS("get string (NULL) 2", NULL == (value = owl_variable_get_tostring(var))); 436 g_free(value); 334 437 335 438 owl_variable_dict_cleanup(&vd); -
util.c
r3cdd6d2 rc0c48d14 37 37 CALLER_OWN char *owl_util_makepath(const char *in) 38 38 { 39 int i, j, x; 40 char *out, user[MAXPATHLEN]; 41 struct passwd *pw; 42 43 out=g_new(char, MAXPATHLEN+1); 44 out[0]='\0'; 45 j=strlen(in); 46 x=0; 47 for (i=0; i<j; i++) { 48 if (in[i]=='~') { 49 if ( (i==(j-1)) || /* last character */ 50 (in[i+1]=='/') ) { /* ~/ */ 51 /* use my homedir */ 52 pw=getpwuid(getuid()); 53 if (!pw) { 54 out[x]=in[i]; 55 } else { 56 out[x]='\0'; 57 strcat(out, pw->pw_dir); 58 x+=strlen(pw->pw_dir); 59 } 60 } else { 61 /* another user homedir */ 62 int a, b; 63 b=0; 64 for (a=i+1; i<j; a++) { 65 if (in[a]==' ' || in[a]=='/') { 66 break; 67 } else { 68 user[b]=in[a]; 69 i++; 70 b++; 71 } 72 } 73 user[b]='\0'; 74 pw=getpwnam(user); 75 if (!pw) { 76 out[x]=in[i]; 77 } else { 78 out[x]='\0'; 79 strcat(out, pw->pw_dir); 80 x+=strlen(pw->pw_dir); 81 } 82 } 83 } else if (in[i]=='/') { 84 /* check for a double / */ 85 if (i<(j-1) && (in[i+1]=='/')) { 86 /* do nothing */ 87 } else { 88 out[x]=in[i]; 89 x++; 90 } 39 char *out; 40 int i, j; 41 if (in[0] == '~') { 42 /* Attempt tilde-expansion of the first component. Get the 43 tilde-prefix, which goes up to the next slash. */ 44 struct passwd *pw; 45 const char *end = strchr(in + 1, '/'); 46 if (end == NULL) 47 end = in + strlen(in); 48 49 if (end == in + 1) { 50 /* My home directory. */ 51 pw = getpwuid(getuid()); 91 52 } else { 92 out[x]=in[i]; 93 x++; 94 } 95 } 96 out[x]='\0'; 97 return(out); 53 /* Someone else's home directory. */ 54 char *user = g_strndup(in + 1, end - (in + 1)); 55 pw = getpwnam(user); 56 g_free(user); 57 } 58 59 /* Patch together a new path. Replace the ~ and tilde-prefix with 60 the homedir. */ 61 if (pw) { 62 out = g_strconcat(pw->pw_dir, end, NULL); 63 } else { 64 out = g_strdup(in); 65 } 66 } else { 67 out = g_strdup(in); 68 } 69 70 /* And a quick pass to remove duplicate slashes. */ 71 for (i = j = 0; out[i] != '\0'; i++) { 72 if (out[i] != '/' || i == 0 || out[i-1] != '/') 73 out[j++] = out[i]; 74 } 75 out[j] = '\0'; 76 return out; 98 77 } 99 78 … … 221 200 /* 222 201 * Appends 'tmpl' to 'buf', replacing any instances of '%q' with arguments from 223 * the varargs provided, quoting them to be safe for placing in a barnowl202 * the varargs provided, quoting them to be safe for placing in a BarnOwl 224 203 * command line. 225 204 */ -
variable.c
rce68f23 ra16d7e5 70 70 71 71 OWLVAR_BOOL( "startuplogin" /* %OwlVarStub */, 1, 72 "send a login message when owl starts", "" ),72 "send a login message when BarnOwl starts", "" ), 73 73 74 74 OWLVAR_BOOL( "shutdownlogout" /* %OwlVarStub */, 1, 75 "send a logout message when owl exits", "" ),75 "send a logout message when BarnOwl exits", "" ), 76 76 77 77 OWLVAR_BOOL( "rxping" /* %OwlVarStub */, 0, … … 137 137 OWLVAR_BOOL_FULL( "pseudologins" /* %OwlVarStub */, 0, 138 138 "Enable zephyr pseudo logins", 139 "When this is enabled, Owl will periodically check the zephyr\n"139 "When this is enabled, BarnOwl will periodically check the zephyr\n" 140 140 "location of users in your .anyone file. If a user is present\n" 141 141 "but sent no login message, or a user is not present that sent no\n" … … 145 145 OWLVAR_BOOL( "ignorelogins" /* %OwlVarStub */, 0, 146 146 "Enable printing of login notifications", 147 "When this is enabled, Owl will print login and logout notifications\n"148 "for AIM, zephyr, or other protocols. If disabled Owl will not print\n"147 "When this is enabled, BarnOwl will print login and logout notifications\n" 148 "for AIM, zephyr, or other protocols. If disabled BarnOwl will not print\n" 149 149 "login or logout notifications.\n"), 150 150 … … 160 160 OWLVAR_BOOL( "loglogins" /* %OwlVarStub */, 0, 161 161 "Enable logging of login notifications", 162 "When this is enabled, Owl will loginlogin and logout notifications\n"162 "When this is enabled, BarnOwl will log login and logout notifications\n" 163 163 "for AIM, zephyr, or other protocols. If disabled Owl will not print\n" 164 164 "login or logout notifications.\n"), … … 201 201 OWLVAR_PATH( "newmsgproc" /* %OwlVarStub:newmsgproc */, NULL, 202 202 "name of a program to run when new messages are present", 203 "The named program will be run when owl receives new\n"203 "The named program will be run when BarnOwl receives new\n" 204 204 "messages. It will not be run again until the first\n" 205 205 "instance exits"), … … 229 229 "string to append to the end of the sepbar", 230 230 "The sepbar is the bar separating the top and bottom\n" 231 "of the owl screen. Any string specified here will\n"231 "of the BarnOwl screen. Any string specified here will\n" 232 232 "be displayed on the right of the sepbar\n"), 233 233 … … 265 265 266 266 OWLVAR_STRING( "alert_action" /* %OwlVarStub */, "nop", 267 " owl command to execute for alert actions",267 "BarnOwl command to execute for alert actions", 268 268 "" ), 269 269 … … 276 276 "Styles may be created with the 'style' command.\n" 277 277 "Some built-in styles include:\n" 278 " default - the default owl formatting\n"278 " default - the default BarnOwl formatting\n" 279 279 " oneline - one line per-message\n" 280 280 " perl - legacy perl interface\n" … … 333 333 "cursor moves between messages being displayed.\n" 334 334 "The following modes are supported:\n\n" 335 " normal - This is the owl default. Scrolling happens\n"335 " normal - This is the BarnOwl default. Scrolling happens\n" 336 336 " when it needs to, and an attempt is made to\n" 337 337 " keep the current message roughly near\n" … … 662 662 } 663 663 664 void owl_variable_dict_newvar_string(owl_vardict * vd, const char *name, const char *summ, const char * desc, const char * initval) { 665 owl_variable *old = owl_variable_get_var(vd, name, OWL_VARIABLE_STRING); 666 if(old) { 664 void owl_variable_dict_newvar_string(owl_vardict *vd, const char *name, const char *summ, const char *desc, const char *initval) 665 { 666 owl_variable *old = owl_variable_get_var(vd, name); 667 if (old && owl_variable_get_type(old) == OWL_VARIABLE_STRING) { 667 668 owl_variable_update(old, summ, desc); 668 669 g_free(old->pval_default); … … 671 672 owl_variable * var = owl_variable_newvar(name, summ, desc); 672 673 var->type = OWL_VARIABLE_STRING; 674 var->validsettings = "<string>"; 673 675 var->pval_default = g_strdup(initval); 674 676 var->set_fn = owl_variable_string_set_default; … … 682 684 } 683 685 684 void owl_variable_dict_newvar_int(owl_vardict * vd, const char *name, const char *summ, const char * desc, int initval) { 685 owl_variable *old = owl_variable_get_var(vd, name, OWL_VARIABLE_INT); 686 if(old) { 686 void owl_variable_dict_newvar_int(owl_vardict *vd, const char *name, const char *summ, const char *desc, int initval) 687 { 688 owl_variable *old = owl_variable_get_var(vd, name); 689 if (old && owl_variable_get_type(old) == OWL_VARIABLE_INT) { 687 690 owl_variable_update(old, summ, desc); 688 691 old->ival_default = initval; … … 690 693 owl_variable * var = owl_variable_newvar(name, summ, desc); 691 694 var->type = OWL_VARIABLE_INT; 695 var->validsettings = "<int>"; 692 696 var->ival_default = initval; 693 697 var->validate_fn = owl_variable_int_validate_default; … … 703 707 } 704 708 705 void owl_variable_dict_newvar_bool(owl_vardict * vd, const char *name, const char *summ, const char * desc, int initval) { 706 owl_variable *old = owl_variable_get_var(vd, name, OWL_VARIABLE_BOOL); 707 if(old) { 709 void owl_variable_dict_newvar_bool(owl_vardict *vd, const char *name, const char *summ, const char *desc, bool initval) 710 { 711 owl_variable *old = owl_variable_get_var(vd, name); 712 if (old && owl_variable_get_type(old) == OWL_VARIABLE_BOOL) { 708 713 owl_variable_update(old, summ, desc); 709 714 old->ival_default = initval; … … 711 716 owl_variable * var = owl_variable_newvar(name, summ, desc); 712 717 var->type = OWL_VARIABLE_BOOL; 718 var->validsettings = "on,off"; 713 719 var->ival_default = initval; 714 720 var->validate_fn = owl_variable_bool_validate_default; … … 750 756 751 757 758 const char *owl_variable_get_name(const owl_variable *v) 759 { 760 return v->name; 761 } 762 752 763 const char *owl_variable_get_description(const owl_variable *v) { 753 764 return v->description; … … 759 770 760 771 const char *owl_variable_get_validsettings(const owl_variable *v) { 761 if (v->validsettings) { 762 return v->validsettings; 763 } else { 764 return ""; 765 } 772 return v->validsettings; 773 } 774 775 int owl_variable_get_type(const owl_variable *v) 776 { 777 return v->type; 766 778 } 767 779 … … 769 781 770 782 /* returns 0 on success, prints a status msg if msg is true */ 771 int owl_variable_set_fromstring(owl_vardict *d, const char *name, const char *value, int msg, int requirebool) { 772 owl_variable *v; 783 int owl_variable_set_fromstring(owl_variable *v, const char *value, int msg) { 773 784 char *tostring; 774 if (!name) return(-1); 775 v = owl_dict_find_element(d, name); 776 if (v == NULL) { 777 if (msg) owl_function_error("Unknown variable %s", name); 785 if (!v->set_fromstring_fn) { 786 if (msg) owl_function_error("Variable %s is read-only", owl_variable_get_name(v)); 787 return -1; 788 } 789 if (0 != v->set_fromstring_fn(v, value)) { 790 if (msg) owl_function_error("Unable to set %s (must be %s)", owl_variable_get_name(v), 791 owl_variable_get_validsettings(v)); 778 792 return -1; 779 793 } 780 if (!v->set_fromstring_fn) { 781 if (msg) owl_function_error("Variable %s is read-only", name); 782 return -1; 783 } 784 if (requirebool && v->type!=OWL_VARIABLE_BOOL) { 785 if (msg) owl_function_error("Variable %s is not a boolean", name); 786 return -1; 787 } 788 if (0 != v->set_fromstring_fn(v, value)) { 789 if (msg) owl_function_error("Unable to set %s (must be %s)", name, 790 owl_variable_get_validsettings(v)); 791 return -1; 792 } 793 if (msg && v->get_tostring_fn) { 794 if (msg) { 794 795 tostring = v->get_tostring_fn(v, v->get_fn(v)); 795 owl_function_makemsg("%s = '%s'", name, tostring); 796 if (tostring) 797 owl_function_makemsg("%s = '%s'", owl_variable_get_name(v), tostring); 798 else 799 owl_function_makemsg("%s = <null>", owl_variable_get_name(v)); 796 800 g_free(tostring); 797 801 } … … 799 803 } 800 804 801 int owl_variable_set_string(owl_vardict *d, const char *name, const char *newval) { 802 owl_variable *v; 803 if (!name) return(-1); 804 v = owl_dict_find_element(d, name); 805 if (v == NULL || !v->set_fn) return(-1); 806 if (v->type!=OWL_VARIABLE_STRING) return(-1); 805 int owl_variable_set_string(owl_variable *v, const char *newval) 806 { 807 if (v->type != OWL_VARIABLE_STRING) return -1; 807 808 return v->set_fn(v, newval); 808 809 } 809 810 810 int owl_variable_set_int(owl_vardict *d, const char *name, int newval) { 811 owl_variable *v; 812 if (!name) return(-1); 813 v = owl_dict_find_element(d, name); 814 if (v == NULL || !v->set_fn) return(-1); 815 if (v->type!=OWL_VARIABLE_INT && v->type!=OWL_VARIABLE_BOOL) return(-1); 811 int owl_variable_set_int(owl_variable *v, int newval) 812 { 813 if (v->type != OWL_VARIABLE_INT && v->type != OWL_VARIABLE_BOOL) return -1; 816 814 return v->set_fn(v, &newval); 817 815 } 818 816 819 int owl_variable_set_bool_on(owl_var dict *d, const char *name) {820 return owl_variable_set_int(d,name,1); 821 } 822 823 int owl_variable_set_bool_off(owl_vardict *d, const char *name) { 824 return owl_variable_set_int(d,name,0); 825 } 826 827 CALLER_OWN char *owl_variable_get_tostring(const owl_vardict *d, const char *name) 828 { 829 owl_variable *v; 830 if (!name) return NULL; 831 v = owl_dict_find_element(d, name); 832 if (v == NULL || !v->get_tostring_fn) return NULL; 817 int owl_variable_set_bool_on(owl_variable *v) 818 { 819 if (v->type != OWL_VARIABLE_BOOL) return -1; 820 return owl_variable_set_int(v, true); 821 } 822 823 int owl_variable_set_bool_off(owl_variable *v) 824 { 825 if (v->type != OWL_VARIABLE_BOOL) return -1; 826 return owl_variable_set_int(v, false); 827 } 828 829 CALLER_OWN char *owl_variable_get_tostring(const owl_variable *v) 830 { 833 831 return v->get_tostring_fn(v, v->get_fn(v)); 834 832 } 835 833 836 CALLER_OWN char *owl_variable_get_default_tostring(const owl_vardict *d, const char *name) 837 { 838 owl_variable *v; 839 if (!name) return NULL; 840 v = owl_dict_find_element(d, name); 841 if (v == NULL || !v->get_tostring_fn) return NULL; 834 CALLER_OWN char *owl_variable_get_default_tostring(const owl_variable *v) 835 { 842 836 if (v->type == OWL_VARIABLE_INT || v->type == OWL_VARIABLE_BOOL) { 843 837 return v->get_tostring_fn(v, &(v->ival_default)); … … 847 841 } 848 842 849 owl_variable *owl_variable_get_var(const owl_vardict *d, const char *name, int require_type) { 850 owl_variable *v; 851 if (!name) return(NULL); 852 v = owl_dict_find_element(d, name); 853 if (v == NULL || !v->get_fn || v->type != require_type) return(NULL); 854 return v; 843 owl_variable *owl_variable_get_var(const owl_vardict *d, const char *name) 844 { 845 return owl_dict_find_element(d, name); 855 846 } 856 847 857 848 /* returns a reference */ 858 const void *owl_variable_get(const owl_vardict *d, const char *name, int require_type) { 859 owl_variable *v = owl_variable_get_var(d, name, require_type); 860 if(v == NULL) return NULL; 849 const void *owl_variable_get(const owl_variable *v) 850 { 861 851 return v->get_fn(v); 862 852 } 863 853 854 const char *owl_variable_get_string(const owl_variable *v) 855 { 856 if (owl_variable_get_type(v) != OWL_VARIABLE_STRING) { 857 owl_function_error("Variable '%s' is not a string.", owl_variable_get_name(v)); 858 return NULL; 859 } 860 return owl_variable_get(v); 861 } 862 864 863 /* returns a reference */ 865 const char *owl_variable_get_string(const owl_vardict *d, const char *name) { 866 return owl_variable_get(d,name, OWL_VARIABLE_STRING); 867 } 868 869 /* returns a reference */ 870 const void *owl_variable_get_other(const owl_vardict *d, const char *name) { 871 return owl_variable_get(d,name, OWL_VARIABLE_OTHER); 872 } 873 874 int owl_variable_get_int(const owl_vardict *d, const char *name) { 875 const int *pi; 876 pi = owl_variable_get(d,name,OWL_VARIABLE_INT); 877 if (!pi) return(-1); 878 return(*pi); 879 } 880 881 int owl_variable_get_bool(const owl_vardict *d, const char *name) { 882 const int *pi; 883 pi = owl_variable_get(d,name,OWL_VARIABLE_BOOL); 884 if (!pi) return(-1); 885 return(*pi); 886 } 887 888 void owl_variable_describe(const owl_vardict *d, const char *name, owl_fmtext *fm) { 864 const void *owl_variable_get_other(const owl_variable *v) 865 { 866 if (owl_variable_get_type(v) != OWL_VARIABLE_OTHER) { 867 owl_function_error("Variable '%s' is not type other.", owl_variable_get_name(v)); 868 return NULL; 869 } 870 return owl_variable_get(v); 871 } 872 873 int owl_variable_get_int(const owl_variable *v) 874 { 875 if (owl_variable_get_type(v) != OWL_VARIABLE_INT) { 876 owl_function_error("Variable '%s' is an int.", owl_variable_get_name(v)); 877 return -1; 878 } 879 const int *pi = owl_variable_get(v); 880 if (!pi) return -1; 881 return *pi; 882 } 883 884 int owl_variable_get_bool(const owl_variable *v) 885 { 886 if (owl_variable_get_type(v) != OWL_VARIABLE_BOOL) { 887 owl_function_error("Variable '%s' is a boolean.", owl_variable_get_name(v)); 888 return -1; 889 } 890 const int *pi = owl_variable_get(v); 891 if (!pi) return -1; 892 return *pi; 893 } 894 895 void owl_variable_describe(const owl_variable *v, owl_fmtext *fm) 896 { 897 char *tostring = owl_variable_get_default_tostring(v); 889 898 char *default_buf; 890 owl_variable *v; 891 892 if (!name 893 || (v = owl_dict_find_element(d, name)) == NULL 894 || !v->get_fn) { 895 owl_fmtext_appendf_normal(fm, " No such variable '%s'\n", name); 896 return; 897 } 898 if (v->type == OWL_VARIABLE_INT || v->type == OWL_VARIABLE_BOOL) { 899 default_buf = v->get_tostring_fn(v, &(v->ival_default)); 900 } else { 901 default_buf = v->get_tostring_fn(v, v->pval_default); 902 } 903 owl_fmtext_appendf_normal(fm, OWL_TABSTR "%-20s - %s (default: '%s')\n", 904 v->name, 905 owl_variable_get_summary(v), default_buf); 899 900 if (tostring) 901 default_buf = g_strdup_printf("'%s'", tostring); 902 else 903 default_buf = g_strdup("<null>"); 904 owl_fmtext_appendf_normal(fm, OWL_TABSTR "%-20s - %s (default: %s)\n", 905 owl_variable_get_name(v), 906 owl_variable_get_summary(v), default_buf); 906 907 g_free(default_buf); 907 } 908 909 void owl_variable_get_help(const owl_vardict *d, const char *name, owl_fmtext *fm) { 908 g_free(tostring); 909 } 910 911 void owl_variable_get_help(const owl_variable *v, owl_fmtext *fm) { 910 912 char *tostring; 911 owl_variable *v;912 913 if (!name914 || (v = owl_dict_find_element(d, name)) == NULL915 || !v->get_fn) {916 owl_fmtext_append_normal(fm, "No such variable...\n");917 return;918 }919 913 920 914 owl_fmtext_append_bold(fm, "OWL VARIABLE\n\n"); 921 915 owl_fmtext_append_normal(fm, OWL_TABSTR); 922 owl_fmtext_append_normal(fm, name);916 owl_fmtext_append_normal(fm, owl_variable_get_name(v)); 923 917 owl_fmtext_append_normal(fm, " - "); 924 owl_fmtext_append_normal(fm, v->summary);918 owl_fmtext_append_normal(fm, owl_variable_get_summary(v)); 925 919 owl_fmtext_append_normal(fm, "\n\n"); 926 920 927 921 owl_fmtext_append_normal(fm, "Current: "); 928 tostring = owl_variable_get_tostring( d, name);929 owl_fmtext_append_normal(fm, tostring);922 tostring = owl_variable_get_tostring(v); 923 owl_fmtext_append_normal(fm, (tostring ? tostring : "<null>")); 930 924 g_free(tostring); 931 925 owl_fmtext_append_normal(fm, "\n\n"); 932 926 933 927 934 if (v->type == OWL_VARIABLE_INT || v->type == OWL_VARIABLE_BOOL) { 935 tostring = v->get_tostring_fn(v, &(v->ival_default)); 936 } else { 937 tostring = v->get_tostring_fn(v, v->pval_default); 938 } 928 tostring = owl_variable_get_default_tostring(v); 939 929 owl_fmtext_append_normal(fm, "Default: "); 940 owl_fmtext_append_normal(fm, tostring);930 owl_fmtext_append_normal(fm, (tostring ? tostring : "<null>")); 941 931 owl_fmtext_append_normal(fm, "\n\n"); 942 932 … … 998 988 { 999 989 if (val == NULL) { 1000 return g_strdup("<null>");990 return NULL; 1001 991 } else if (*(const int*)val == 0) { 1002 992 return g_strdup("off"); … … 1034 1024 { 1035 1025 if (val == NULL) { 1036 return g_strdup("<null>");1026 return NULL; 1037 1027 } else { 1038 1028 return g_strdup_printf("%d", *(const int*)val); … … 1078 1068 1079 1069 if (val == NULL) { 1080 return g_strdup("<null>");1070 return NULL; 1081 1071 } 1082 1072 enums = g_strsplit_set(v->validsettings, ",", 0); … … 1114 1104 CALLER_OWN char *owl_variable_string_get_tostring_default(const owl_variable *v, const void *val) 1115 1105 { 1116 if (val == NULL) { 1117 return g_strdup("<null>"); 1118 } else { 1119 return g_strdup((const char*)val); 1120 } 1121 } 1122 1106 return g_strdup((const char*)val); 1107 } 1108
Note: See TracChangeset
for help on using the changeset viewer.