Changeset 864ed35
- Timestamp:
- Apr 29, 2008, 1:21:13 AM (16 years ago)
- Branches:
- master, barnowl_perlaim, debian, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- b67ab6b
- Parents:
- 120291c
- Files:
-
- 1 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
Makefile.in
rd5ebf3a r864ed35 25 25 regex.c history.c view.c dict.c variable.c filterelement.c pair.c \ 26 26 keypress.c keymap.c keybinding.c cmd.c context.c zcrypt.c \ 27 aim.c buddy.c buddylist.c timer.c style.c stylefunc.cerrqueue.c \27 aim.c buddy.c buddylist.c timer.c style.c errqueue.c \ 28 28 zbuddylist.c muxevents.c popexec.c obarray.c select.c 29 29 OWL_SRC = owl.c -
commands.c
rd768834 r864ed35 101 101 "Use 'show keymaps' to see the existing keymaps.\n" 102 102 "Key sequences may be things like M-C-t or NPAGE.\n"), 103 104 OWLCMD_ARGS("style", owl_command_style, OWL_CTX_ANY,105 "creates a new style",106 "style <name> perl <function_name>",107 "Creates a new style for formatting messages.\n"108 "A style named <name> will be created that will\n"109 "format messages using the perl function <function_name>.\n\n"110 "SEE ALSO: show styles, view -s, filter -s\n"),111 103 112 104 OWLCMD_ARGS("zwrite", owl_command_zwrite, OWL_CTX_INTERACTIVE, … … 1675 1667 return NULL; 1676 1668 } 1677 1678 char *owl_command_style(int argc, char **argv, char *buff) {1679 owl_style *s;1680 1681 /* Usage: style <name> perl <function> */1682 if (argc != 4 || strcmp(argv[2], "perl")) {1683 owl_function_makemsg("Usage: style <name> perl <function>");1684 return NULL;1685 }1686 if (!owl_perlconfig_is_function(argv[3])) {1687 owl_function_makemsg("Unable to create style '%s': no perl function '%s'",1688 argv[1], argv[3]);1689 return NULL;1690 }1691 s=owl_malloc(sizeof(owl_style));1692 owl_style_create_perl(s, argv[1], argv[3], NULL);1693 owl_global_add_style(&g, s);1694 1695 return NULL;1696 }1697 1698 1669 1699 1670 void owl_command_quit() -
owl.c
rc0c4449c r864ed35 265 265 } 266 266 267 /* setup the built-in styles */268 owl_function_debugmsg("startup: creating built-in styles");269 270 s=owl_malloc(sizeof(owl_style));271 owl_style_create_internal(s, "basic", &owl_stylefunc_basic, "Basic message formatting.");272 owl_global_add_style(&g, s);273 274 267 /* setup the default filters */ 275 268 /* the personal filter will need to change again when AIM chat's are -
perlglue.xs
r9c7a701 r864ed35 256 256 257 257 void 258 _create_style(name, function, description)258 _create_style(name, object) 259 259 char *name 260 char *function 261 char *description 260 SV *object 262 261 PREINIT: 263 262 /* This is to allow us to bootstrap the default style before the … … 267 266 { 268 267 s = owl_malloc(sizeof(owl_style)); 269 owl_style_create_perl(s, name, function, description);268 owl_style_create_perl(s, name, object); 270 269 owl_global_add_style(&g, s); 271 270 } -
perlwrap.pm
r9815e2e r864ed35 702 702 if(*BarnOwl::format_msg{CODE}) { 703 703 # if the config defines a legacy formatting function, add 'perl' as a style 704 BarnOwl::_create_style("perl", "BarnOwl::_format_msg_legacy_wrap",705 "User-defined perl style that calls BarnOwl::format_msg"706 . " with legacy global variable support");707 BarnOwl::set("-q default_style perl");704 # BarnOwl::_create_style("perl", "BarnOwl::_format_msg_legacy_wrap", 705 # "User-defined perl style that calls BarnOwl::format_msg" 706 # . " with legacy global variable support"); 707 # BarnOwl::set("-q default_style perl"); 708 708 } 709 709 } … … 763 763 sub format_message($) 764 764 { 765 my $self = shift; 765 766 my $m = shift; 766 767 767 768 if ( $m->is_loginout) { 768 return format_login($m);769 return $self->format_login($m); 769 770 } elsif($m->is_ping && $m->is_personal) { 770 return ( "\@b(PING) from \@b(" . $m->pretty_sender . ")\n");771 return $self->format_ping($m); 771 772 } elsif($m->is_admin) { 772 return "\@bold(OWL ADMIN)\n" . indentBody($m);773 return $self->format_admin($m); 773 774 } else { 774 return format_chat($m);775 return $self->format_chat($m); 775 776 } 776 777 } 777 778 778 BarnOwl::_create_style("default", "BarnOwl::Style::Default::format_message", "Default style"); 779 sub description {"Default style";} 780 781 BarnOwl::_create_style("default", "BarnOwl::Style::Default"); 779 782 780 783 ################################################################################ … … 787 790 788 791 sub format_login($) { 792 my $self = shift; 789 793 my $m = shift; 790 794 return sprintf( … … 798 802 } 799 803 804 sub format_ping { 805 my $self = shift; 806 my $m = shift; 807 return "\@b(PING) from \@b(" . $m->pretty_sender . ")\n"; 808 } 809 810 sub format_admin { 811 my $self = shift; 812 my $m = shift; 813 return "\@bold(OWL ADMIN)\n" . indentBody($m); 814 } 815 800 816 sub format_chat($) { 817 my $self = shift; 801 818 my $m = shift; 802 819 my $header; … … 846 863 } 847 864 865 package BarnOwl::Style::Basic; 866 867 our @ISA=qw(BarnOwl::Style::Default); 868 869 sub description {"Compatability alias for the default style";} 870 871 BarnOwl::_create_style("basic", "BarnOwl::Style::Basic"); 872 848 873 package BarnOwl::Style::OneLine; 849 874 ################################################################################ … … 852 877 use constant BASE_FORMAT => '%s %-13.13s %-11.11s %-12.12s '; 853 878 sub format_message($) { 879 my $self = shift; 854 880 my $m = shift; 855 881 856 # if ( $m->is_zephyr ) {857 # return format_zephyr($m);858 # }859 882 if ( $m->is_loginout ) { 860 return format_login($m);883 return $self->format_login($m); 861 884 } 862 885 elsif ( $m->is_ping) { 863 return format_ping($m);886 return $self->format_ping($m); 864 887 } 865 888 elsif ( $m->is_admin || $m->is_loopback) { 866 return format_local($m);889 return $self->format_local($m); 867 890 } 868 891 else { 869 return format_chat($m);892 return $self->format_chat($m); 870 893 } 871 894 } 872 895 873 BarnOwl::_create_style("oneline", "BarnOwl::Style::OneLine::format_message", "Formats for one-line-per-message"); 896 sub description {"Formats for one-line-per-message"} 897 898 BarnOwl::_create_style("oneline", "BarnOwl::Style::OneLine"); 874 899 875 900 ################################################################################ 876 901 877 902 sub format_login($) { 903 my $self = shift; 878 904 my $m = shift; 879 905 return sprintf( … … 898 924 sub format_chat($) 899 925 { 926 my $self = shift; 900 927 my $m = shift; 901 928 my $dir = lc($m->{direction}); … … 938 965 sub format_local($) 939 966 { 967 my $self = shift; 940 968 my $m = shift; 941 969 my $type = uc($m->{type}); -
style.c
r5a9f6fe r864ed35 1 #define OWL_PERL 1 2 #include "owl.h" 2 3 3 4 static const char fileIdent[] = "$Id$"; 4 5 5 void owl_style_create_ internal(owl_style *s, char *name, void (*formatfunc) (owl_fmtext *fm, owl_message *m), char *description)6 void owl_style_create_perl(owl_style *s, char *name, SV *obj) 6 7 { 7 s->type=OWL_STYLE_TYPE_INTERNAL;8 8 s->name=owl_strdup(name); 9 if (description) { 10 s->description=owl_strdup(description); 11 } else { 12 s->description=owl_sprintf("Owl internal style %s", name); 13 } 14 s->perlfuncname=NULL; 15 s->formatfunc=formatfunc; 16 } 17 18 void owl_style_create_perl(owl_style *s, char *name, char *perlfuncname, char *description) 19 { 20 s->type=OWL_STYLE_TYPE_PERL; 21 s->name=owl_strdup(name); 22 s->perlfuncname=owl_strdup(perlfuncname); 23 if (description) { 24 s->description=owl_strdup(description); 25 } else { 26 s->description=owl_sprintf("User-defined perl style that calls %s", 27 perlfuncname); 28 } 29 s->formatfunc=NULL; 9 s->perlobj = SvREFCNT_inc(obj); 30 10 } 31 11 … … 43 23 char *owl_style_get_description(owl_style *s) 44 24 { 45 return(s->description); 25 SV *sv = NULL; 26 OWL_PERL_CALL_METHOD(s->perlobj, 27 "description", 28 /* no args */, 29 "Error in style_get_description: %s", 30 0, 31 sv = SvREFCNT_inc(POPs); 32 ); 33 if(sv) { 34 return SvPV_nolen(sv_2mortal(sv)); 35 } else { 36 return "[error getting description]"; 37 } 46 38 } 47 39 … … 51 43 void owl_style_get_formattext(owl_style *s, owl_fmtext *fm, owl_message *m) 52 44 { 53 if (s->type==OWL_STYLE_TYPE_INTERNAL) { 54 (* s->formatfunc)(fm, m); 55 } else if (s->type==OWL_STYLE_TYPE_PERL) { 56 char *body, *indent; 57 int curlen; 45 char *body, *indent; 46 int curlen; 58 47 59 /* run the perl function */ 60 body=owl_perlconfig_getmsg(m, 1, s->perlfuncname); 61 if (!strcmp(body, "")) { 62 owl_free(body); 63 body=owl_strdup("<unformatted message>"); 64 } 65 66 /* indent and ensure ends with a newline */ 67 indent=owl_malloc(strlen(body)+(owl_text_num_lines(body))*OWL_TAB+10); 68 owl_text_indent(indent, body, OWL_TAB); 69 curlen = strlen(indent); 70 if (curlen==0 || indent[curlen-1] != '\n') { 71 indent[curlen] = '\n'; 72 indent[curlen+1] = '\0'; 73 } 48 SV *sv = NULL; 49 50 /* Call the perl object */ 51 OWL_PERL_CALL_METHOD(s->perlobj, 52 "format_message", 53 XPUSHs(owl_perlconfig_message2hashref(m));, 54 "Error in format_message: %s", 55 0, 56 sv = SvREFCNT_inc(POPs); 57 ); 74 58 75 /* fmtext_append. This needs to change */ 76 owl_fmtext_append_ztext(fm, indent); 77 78 owl_free(indent); 79 owl_free(body); 59 if(sv) { 60 body = SvPV_nolen(sv); 61 } else { 62 body = "<unformatted message>"; 80 63 } 64 65 /* indent and ensure ends with a newline */ 66 indent=owl_malloc(strlen(body)+(owl_text_num_lines(body))*OWL_TAB+10); 67 owl_text_indent(indent, body, OWL_TAB); 68 curlen = strlen(indent); 69 if (curlen==0 || indent[curlen-1] != '\n') { 70 indent[curlen] = '\n'; 71 indent[curlen+1] = '\0'; 72 } 73 74 /* fmtext_append. This needs to change */ 75 owl_fmtext_append_ztext(fm, indent); 76 77 owl_free(indent); 78 if(sv) 79 SvREFCNT_dec(body); 81 80 } 82 81 83 82 int owl_style_validate(owl_style *s) { 84 if (!s) { 85 return -1; 86 } else if (s->type==OWL_STYLE_TYPE_INTERNAL) { 87 return 0; 88 } else if (s->type==OWL_STYLE_TYPE_PERL 89 && s->perlfuncname 90 && owl_perlconfig_is_function(s->perlfuncname)) { 91 return 0; 92 } else { 83 if (!s || !s->perlobj || !SvOK(s->perlobj)) { 93 84 return -1; 94 85 } 86 return 0; 95 87 } 96 88 … … 98 90 { 99 91 if (s->name) owl_free(s->name); 100 if (s->description) owl_free(s->description); 101 if (s->type==OWL_STYLE_TYPE_PERL && s->perlfuncname) { 102 owl_free(s->perlfuncname); 103 } 92 SvREFCNT_dec(s->perlobj); 104 93 }
Note: See TracChangeset
for help on using the changeset viewer.