Changeset 864ed35


Ignore:
Timestamp:
Apr 29, 2008, 1:21:13 AM (16 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
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
Message:
Initial step of moving styles from the current mishmash of different
options to a unified object interface.
No backwards-compatibility support yet.
Files:
1 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • Makefile.in

    rd5ebf3a r864ed35  
    2525     regex.c history.c view.c dict.c variable.c filterelement.c pair.c \
    2626     keypress.c keymap.c keybinding.c cmd.c context.c zcrypt.c \
    27      aim.c buddy.c buddylist.c timer.c style.c stylefunc.c errqueue.c \
     27     aim.c buddy.c buddylist.c timer.c style.c errqueue.c \
    2828     zbuddylist.c muxevents.c popexec.c obarray.c select.c
    2929OWL_SRC = owl.c
  • commands.c

    rd768834 r864ed35  
    101101              "Use 'show keymaps' to see the existing keymaps.\n"
    102102              "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"),
    111103
    112104  OWLCMD_ARGS("zwrite", owl_command_zwrite, OWL_CTX_INTERACTIVE,
     
    16751667  return NULL;
    16761668}
    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 
    16981669
    16991670void owl_command_quit()
  • owl.c

    rc0c4449c r864ed35  
    265265  }
    266266
    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 
    274267  /* setup the default filters */
    275268  /* the personal filter will need to change again when AIM chat's are
  • perlglue.xs

    r9c7a701 r864ed35  
    256256
    257257void
    258 _create_style(name, function, description)
     258_create_style(name, object)
    259259     char *name
    260      char *function
    261      char *description
     260     SV  *object
    262261     PREINIT:
    263262                /* This is to allow us to bootstrap the default style before the
     
    267266        {
    268267                s = owl_malloc(sizeof(owl_style));
    269                 owl_style_create_perl(s, name, function, description);
     268                owl_style_create_perl(s, name, object);
    270269                owl_global_add_style(&g, s);
    271270        }
  • perlwrap.pm

    r9815e2e r864ed35  
    702702        if(*BarnOwl::format_msg{CODE}) {
    703703            # 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");
    708708        }
    709709    }
     
    763763sub format_message($)
    764764{
     765    my $self = shift;
    765766    my $m = shift;
    766767
    767768    if ( $m->is_loginout) {
    768         return format_login($m);
     769        return $self->format_login($m);
    769770    } elsif($m->is_ping && $m->is_personal) {
    770         return ( "\@b(PING) from \@b(" . $m->pretty_sender . ")\n" );
     771        return $self->format_ping($m);
    771772    } elsif($m->is_admin) {
    772         return "\@bold(OWL ADMIN)\n" . indentBody($m);
     773        return $self->format_admin($m);
    773774    } else {
    774         return format_chat($m);
     775        return $self->format_chat($m);
    775776    }
    776777}
    777778
    778 BarnOwl::_create_style("default", "BarnOwl::Style::Default::format_message", "Default style");
     779sub description {"Default style";}
     780
     781BarnOwl::_create_style("default", "BarnOwl::Style::Default");
    779782
    780783################################################################################
     
    787790
    788791sub format_login($) {
     792    my $self = shift;
    789793    my $m = shift;
    790794    return sprintf(
     
    798802}
    799803
     804sub format_ping {
     805    my $self = shift;
     806    my $m = shift;
     807    return "\@b(PING) from \@b(" . $m->pretty_sender . ")\n";
     808}
     809
     810sub format_admin {
     811    my $self = shift;
     812    my $m = shift;
     813    return "\@bold(OWL ADMIN)\n" . indentBody($m);
     814}
     815
    800816sub format_chat($) {
     817    my $self = shift;
    801818    my $m = shift;
    802819    my $header;
     
    846863}
    847864
     865package BarnOwl::Style::Basic;
     866
     867our @ISA=qw(BarnOwl::Style::Default);
     868
     869sub description {"Compatability alias for the default style";}
     870
     871BarnOwl::_create_style("basic", "BarnOwl::Style::Basic");
     872
    848873package BarnOwl::Style::OneLine;
    849874################################################################################
     
    852877use constant BASE_FORMAT => '%s %-13.13s %-11.11s %-12.12s ';
    853878sub format_message($) {
     879  my $self = shift;
    854880  my $m = shift;
    855881
    856 #  if ( $m->is_zephyr ) {
    857 #    return format_zephyr($m);
    858 #  }
    859882  if ( $m->is_loginout ) {
    860     return format_login($m);
     883    return $self->format_login($m);
    861884  }
    862885  elsif ( $m->is_ping) {
    863     return format_ping($m);
     886    return $self->format_ping($m);
    864887  }
    865888  elsif ( $m->is_admin || $m->is_loopback) {
    866     return format_local($m);
     889    return $self->format_local($m);
    867890  }
    868891  else {
    869     return format_chat($m);
     892    return $self->format_chat($m);
    870893  }
    871894}
    872895
    873 BarnOwl::_create_style("oneline", "BarnOwl::Style::OneLine::format_message", "Formats for one-line-per-message");
     896sub description {"Formats for one-line-per-message"}
     897
     898BarnOwl::_create_style("oneline", "BarnOwl::Style::OneLine");
    874899
    875900################################################################################
    876901
    877902sub format_login($) {
     903  my $self = shift;
    878904  my $m = shift;
    879905  return sprintf(
     
    898924sub format_chat($)
    899925{
     926  my $self = shift;
    900927  my $m = shift;
    901928  my $dir = lc($m->{direction});
     
    938965sub format_local($)
    939966{
     967  my $self = shift;
    940968  my $m = shift;
    941969  my $type = uc($m->{type});
  • style.c

    r5a9f6fe r864ed35  
     1#define OWL_PERL
    12#include "owl.h"
    23
    34static const char fileIdent[] = "$Id$";
    45
    5 void owl_style_create_internal(owl_style *s, char *name, void (*formatfunc) (owl_fmtext *fm, owl_message *m), char *description)
     6void owl_style_create_perl(owl_style *s, char *name, SV *obj)
    67{
    7   s->type=OWL_STYLE_TYPE_INTERNAL;
    88  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);
    3010}
    3111
     
    4323char *owl_style_get_description(owl_style *s)
    4424{
    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  }
    4638}
    4739
     
    5143void owl_style_get_formattext(owl_style *s, owl_fmtext *fm, owl_message *m)
    5244{
    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;
    5847
    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                       );
    7458
    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>";
    8063  }
     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);
    8180}
    8281
    8382int 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)) {
    9384    return -1;
    9485  }
     86  return 0;
    9587}
    9688
     
    9890{
    9991  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);
    10493}
Note: See TracChangeset for help on using the changeset viewer.