Changes in / [3066d23:1cf32e7d]


Ignore:
Files:
59 added
44 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • BUGS

    r69d66aa7 r0337203  
    55* reply to resource names from ichat (foo's computer) fails badly [hartmans]
    66* viewuser doesn't work with AIM or Jabber
    7 * jmuc join'ing a MUC you're already in has weird behavior [nelhage]
  • Makefile.in

    ra956288 r702aee7  
    3131
    3232EXE = barnowl
     33PERL_MODULES = Jabber
     34MODULE_DIRS = $(PERL_MODULES:%=perl/modules/%)
    3335
    3436BASE_OBJS = $(BASE_SRCS:.c=.o)
     
    5759        ./tester reg
    5860
    59 clean: libfaimclean
     61clean: libfaimclean modules_clean
    6062        $(RM) $(EXE) tester *.o $(AUTOGEN) owl_prototypes.h.new
    6163
    6264distclean: clean libfaimdistclean
    6365        $(RM) config.cache config.log config.status  Makefile config.h TAGS *~ core
     66
     67.PHONY: $(MODULE_DIRS)
     68
     69modules: $(MODULE_DIRS)
     70modules_clean:
     71        for i in $(MODULE_DIRS); do \
     72                cd $$i; test ! -f Makefile || make clean; \
     73        done
     74
     75$(MODULE_DIRS): %: %/Makefile
     76        ( cd $@ && make $(notdir $@).par )
     77
     78$(MODULE_DIRS:=/Makefile): %/Makefile: %/Makefile.PL
     79        ( cd $(dir $@) && perl -I../../lib Makefile.PL )
    6480
    6581proto: owl_prototypes.h
     
    104120        (cd libfaim; $(MAKE) distclean)
    105121
    106 all: $(EXE)
     122all: $(EXE) $(MODULE_DIRS)
    107123
    108124install: all installdirs
    109125        ${INSTALL_PROGRAM} $(EXE) ${DESTDIR}${bindir}/$(EXE)
    110126        ${INSTALL_DATA} doc/owl.1 ${DESTDIR}${mandir}/man1/barnowl.1
    111         tar -C perl -c . | tar -C ${DESTDIR}${datadir} -x
     127        ${INSTALL} -d ${DESTDIR}${datadir}/lib
     128        ${INSTALL} -d ${DESTDIR}${datadir}/modules
     129        tar -C perl/lib --exclude .svn -c . | tar -C ${DESTDIR}${datadir}/lib -x
     130        for i in $(PERL_MODULES); do \
     131                ${INSTALL_DATA} perl/modules/$$i/$$i.par ${DESTDIR}${datadir}/modules/$$i.par; \
     132        done
    112133
    113134installdirs: mkinstalldirs
  • fmtext.c

    r801b7ac ra387d12e  
    99{
    1010  f->textlen=0;
    11   f->textbuff=owl_strdup("");
     11  f->bufflen=5;
     12  f->textbuff=owl_malloc(5);
    1213  f->fmbuff=owl_malloc(5);
    1314  f->fgcolorbuff=owl_malloc(5);
    1415  f->bgcolorbuff=owl_malloc(5);
     16  f->textbuff[0]=0;
    1517  f->fmbuff[0]=OWL_FMTEXT_ATTR_NONE;
    1618  f->fgcolorbuff[0]=OWL_COLOR_DEFAULT;
     
    1820}
    1921
     22/* Clear the data from an fmtext, but don't deallocate memory. This
     23   fmtext can then be appended to again. */
     24void owl_fmtext_clear(owl_fmtext *f)
     25{
     26    f->textlen = 0;
     27    f->textbuff[0] = 0;
     28    f->fmbuff[0]=OWL_FMTEXT_ATTR_NONE;
     29    f->fgcolorbuff[0]=OWL_COLOR_DEFAULT;
     30    f->bgcolorbuff[0]=OWL_COLOR_DEFAULT;
     31}
     32
    2033/* Internal function.  Set the attribute 'attr' from index 'first' to
    2134 * index 'last'
     
    5972}
    6073
     74void _owl_fmtext_realloc(owl_fmtext *f, int newlen) /*noproto*/
     75{
     76    if(newlen + 1 > f->bufflen) {
     77      f->textbuff=owl_realloc(f->textbuff, newlen+1);
     78      f->fmbuff=owl_realloc(f->fmbuff, newlen+1);
     79      f->fgcolorbuff=owl_realloc(f->fgcolorbuff, newlen+1);
     80      f->bgcolorbuff=owl_realloc(f->bgcolorbuff, newlen+1);
     81      f->bufflen = newlen+1;
     82  }
     83}
     84
    6185/* append text to the end of 'f' with attribute 'attr' and color
    6286 * 'color'
     
    6589{
    6690  int newlen;
    67 
    6891  newlen=strlen(f->textbuff)+strlen(text);
    69   f->textbuff=owl_realloc(f->textbuff, newlen+2);
    70   f->fmbuff=owl_realloc(f->fmbuff, newlen+2);
    71   f->fgcolorbuff=owl_realloc(f->fgcolorbuff, newlen+2);
    72   f->bgcolorbuff=owl_realloc(f->bgcolorbuff, newlen+2);
    73 
     92  _owl_fmtext_realloc(f, newlen);
     93 
    7494  strcat(f->textbuff, text);
    7595  _owl_fmtext_set_attr(f, attr, f->textlen, newlen);
     
    154174
    155175  newlen=strlen(f->textbuff)+(stop-start+1);
    156   f->textbuff=owl_realloc(f->textbuff, newlen+1);
    157   f->fmbuff=owl_realloc(f->fmbuff, newlen+1);
    158   f->fgcolorbuff=owl_realloc(f->fgcolorbuff, newlen+1);
    159   f->bgcolorbuff=owl_realloc(f->bgcolorbuff, newlen+1);
     176  _owl_fmtext_realloc(f, newlen);
    160177
    161178  strncat(f->textbuff, in->textbuff+start, stop-start+1);
  • functions.c

    ra5fc448 r0337203  
    10351035
    10361036  /* execute the commands in shutdown */
    1037   ret = owl_perlconfig_execute("BarnOwl::Hooks::shutdown();");
     1037  ret = owl_perlconfig_execute("BarnOwl::Hooks::_shutdown();");
    10381038  if (ret) owl_free(ret);
    10391039
     
    33653365
    33663366  if(aim && zephyr) {
    3367       if(owl_perlconfig_is_function("BarnOwl::Hooks::get_blist")) {
    3368           char * perlblist = owl_perlconfig_execute("BarnOwl::Hooks::get_blist()");
     3367      if(owl_perlconfig_is_function("BarnOwl::Hooks::_get_blist")) {
     3368          char * perlblist = owl_perlconfig_execute("BarnOwl::Hooks::_get_blist()");
    33693369          if(perlblist) {
    33703370              owl_fmtext_append_ztext(&fm, perlblist);
  • global.c

    r8e401cae ra387d12e  
    108108
    109109  owl_obarray_init(&(g->obarray));
     110
     111  owl_message_init_fmtext_cache();
    110112}
    111113
  • message.c

    r963542b ra387d12e  
    1313static const char fileIdent[] = "$Id$";
    1414
     15static owl_fmtext_cache fmtext_cache[OWL_FMTEXT_CACHE_SIZE];
     16static owl_fmtext_cache * fmtext_cache_next = fmtext_cache;
     17
     18void owl_message_init_fmtext_cache ()
     19{
     20    int i;
     21    for(i = 0; i < OWL_FMTEXT_CACHE_SIZE; i++) {
     22        owl_fmtext_init_null(&(fmtext_cache[i].fmtext));
     23        fmtext_cache[i].message = NULL;
     24    }
     25}
     26
     27owl_fmtext_cache * owl_message_next_fmtext() /*noproto*/
     28{
     29    if(fmtext_cache_next->message != NULL) {
     30        owl_message_invalidate_format(fmtext_cache_next->message);
     31    }
     32    owl_fmtext_cache * f = fmtext_cache_next;
     33    fmtext_cache_next++;
     34    if(fmtext_cache_next - fmtext_cache == OWL_FMTEXT_CACHE_SIZE)
     35        fmtext_cache_next = fmtext_cache;
     36    return f;
     37}
     38
    1539void owl_message_init(owl_message *m)
    1640{
     
    1943  m->delete=0;
    2044  m->zwriteline=NULL;
    21   m->invalid_format=1;
    2245
    2346  owl_message_set_hostname(m, "");
     
    2952  m->timestr[strlen(m->timestr)-1]='\0';
    3053
    31   /* initialize the fmtext */
    32   owl_fmtext_init_null(&(m->fmtext));
     54  m->fmtext = NULL;
    3355}
    3456
     
    106128void owl_message_invalidate_format(owl_message *m)
    107129{
    108   m->invalid_format=1;
     130  if(m->fmtext) {
     131    m->fmtext->message = NULL;
     132    owl_fmtext_clear(&(m->fmtext->fmtext));
     133    m->fmtext=NULL;
     134  }
    109135}
    110136
     
    112138{
    113139  owl_message_format(m);
    114   return(&(m->fmtext));
     140  return(&(m->fmtext->fmtext));
    115141}
    116142
     
    120146  owl_view *v;
    121147
    122   if (m->invalid_format) {
     148  if (!m->fmtext) {
     149    m->fmtext = owl_message_next_fmtext();
     150    m->fmtext->message = m;
    123151    /* for now we assume there's just the one view and use that style */
    124152    v=owl_global_get_current_view(&g);
    125153    s=owl_view_get_style(v);
    126154
    127     owl_fmtext_free(&(m->fmtext));
    128     owl_fmtext_init_null(&(m->fmtext));
    129     owl_style_get_formattext(s, &(m->fmtext), m);
    130     m->invalid_format=0;
     155    owl_style_get_formattext(s, &(m->fmtext->fmtext), m);
    131156  }
    132157}
     
    392417char *owl_message_get_text(owl_message *m)
    393418{
    394   return(owl_fmtext_get_text(&(m->fmtext)));
     419  return(owl_fmtext_get_text(&(m->fmtext->fmtext)));
    395420}
    396421
     
    437462  if (m == NULL) return(0);
    438463  owl_message_format(m);
    439   return(owl_fmtext_num_lines(&(m->fmtext)));
     464  return(owl_fmtext_num_lines(&(m->fmtext->fmtext)));
    440465}
    441466
     
    504529  owl_fmtext_init_null(&b);
    505530 
    506   owl_fmtext_truncate_lines(&(m->fmtext), aline, bline-aline+1, &a);
     531  owl_fmtext_truncate_lines(&(m->fmtext->fmtext), aline, bline-aline+1, &a);
    507532  owl_fmtext_truncate_cols(&a, acol, bcol, &b);
    508533  if (fgcolor!=OWL_COLOR_DEFAULT) {
     
    698723  owl_message_format(m); /* is this necessary? */
    699724 
    700   return (owl_fmtext_search(&(m->fmtext), string));
     725  return (owl_fmtext_search(&(m->fmtext->fmtext), string));
    701726}
    702727
     
    9891014  owl_list_free_simple(&(m->attributes));
    9901015 
    991   owl_fmtext_free(&(m->fmtext));
    992 }
     1016  owl_message_invalidate_format(m);
     1017}
  • owl.c

    r2058d7a r72c210f  
    318318  /* execute the startup function in the configfile */
    319319  owl_function_debugmsg("startup: executing perl startup, if applicable");
    320   perlout = owl_perlconfig_execute("BarnOwl::Hooks::startup();");
     320  perlout = owl_perlconfig_execute("BarnOwl::Hooks::_startup();");
    321321  if (perlout) owl_free(perlout);
    322322
     
    397397
    398398  owl_function_debugmsg("startup: set style for the view: %s", owl_global_get_default_style(&g));
    399   owl_view_set_style(owl_global_get_current_view(&g),
    400                      owl_global_get_style_by_name(&g, owl_global_get_default_style(&g)));   
     399  s = owl_global_get_style_by_name(&g, owl_global_get_default_style(&g));
     400  if(s)
     401      owl_view_set_style(owl_global_get_current_view(&g), s);
     402  else
     403      owl_function_error("No such style: %s", owl_global_get_default_style(&g));
    401404
    402405  owl_function_debugmsg("startup: setting context interactive");
  • owl.h

    rd08162a ra387d12e  
    249249typedef struct _owl_fmtext {
    250250  int textlen;
     251  int bufflen;
    251252  char *textbuff;
    252253  char *fmbuff;
     
    329330} owl_pair;
    330331
     332struct _owl_fmtext_cache;
     333
    331334typedef struct _owl_message {
    332335  int id;
     
    335338  ZNotice_t notice;
    336339#endif
    337   owl_fmtext fmtext;              /* this is now only a CACHED copy */
    338   int invalid_format;             /* indicates whether fmtext needs to be regenerated */
     340  struct _owl_fmtext_cache * fmtext;
    339341  int delete;
    340342  char *hostname;
     
    344346  char *zwriteline;
    345347} owl_message;
     348
     349#define OWL_FMTEXT_CACHE_SIZE 1000
     350/* We cache the saved fmtexts for the last bunch of messages we
     351   rendered */
     352typedef struct _owl_fmtext_cache {
     353    owl_message * message;
     354    owl_fmtext fmtext;
     355} owl_fmtext_cache;
    346356
    347357typedef struct _owl_style {
  • perlconfig.c

    r1cc95709 r0337203  
    422422  } else {
    423423    char *ptr = NULL;
    424     if (owl_perlconfig_is_function("BarnOwl::Hooks::receive_msg")) {
     424    if (owl_perlconfig_is_function("BarnOwl::Hooks::_receive_msg")) {
    425425      ptr = owl_perlconfig_call_with_message(subname?subname
    426426                                       :"BarnOwl::_receive_msg_legacy_wrap", m);
     
    506506void owl_perlconfig_mainloop()
    507507{
    508   if (!owl_perlconfig_is_function("BarnOwl::Hooks::mainloop_hook"))
     508  if (!owl_perlconfig_is_function("BarnOwl::Hooks::_mainloop_hook"))
    509509    return;
    510510  dSP ;
    511511  PUSHMARK(SP) ;
    512   call_pv("BarnOwl::Hooks::mainloop_hook", G_DISCARD|G_EVAL);
     512  call_pv("BarnOwl::Hooks::_mainloop_hook", G_DISCARD|G_EVAL);
    513513  if(SvTRUE(ERRSV)) {
    514514    STRLEN n_a;
  • perlwrap.pm

    r37dd88c r18a99d2  
    77# XXX NOTE: This file is sourced before almost any barnowl
    88# architecture is loaded. This means, for example, that it cannot
    9 # execute any owl commands. Any code that needs to do so, should
    10 # create a function wrapping it and push it onto @onStartSubs
    11 
     9# execute any owl commands. Any code that needs to do so should live
     10# in BarnOwl::Hooks::_startup
    1211
    1312use strict;
     
    1514
    1615package BarnOwl;
    17 
    1816
    1917BEGIN {
     
    4442    my ($m) = @_;
    4543    $m->legacy_populate_global();
    46     return &BarnOwl::Hooks::receive_msg($m);
     44    return &BarnOwl::Hooks::_receive_msg($m);
    4745}
    4846
     
    204202
    205203sub smartfilter {
    206     die("smartfilter not supported for this message");
     204    die("smartfilter not supported for this message\n");
    207205}
    208206
     
    351349#####################################################################
    352350################################################################################
    353 package BarnOwl;
    354 
    355 ################################################################################
    356 # Mainloop hook
    357 ################################################################################
    358 
    359 our $shutdown;
    360 $shutdown = 0;
    361 our $reload;
    362 $reload = 0;
    363 
    364 #Run this on start and reload. Adds modules
    365 sub onStart
    366 {
    367     _load_owlconf();
    368     reload_init();
    369     loadModules();
    370 }
    371 ################################################################################
    372 # Reload Code, taken from /afs/sipb/user/jdaniel/project/owl/perl
    373 ################################################################################
    374 sub reload_hook (@)
    375 {
    376     BarnOwl::Hooks::startup();
    377     return 1;
    378 }
    379 
    380 sub reload
    381 {
    382     # Use $reload to tell modules that we're performing a reload.
    383   {
    384       local $reload = 1;
    385       BarnOwl::mainloop_hook() if *BarnOwl::mainloop_hook{CODE};
    386   }
    387 
    388   @BarnOwl::Hooks::onMainLoop = ();
    389   @BarnOwl::Hooks::onStartSubs = ();
    390 
    391   # Do reload
    392   package main;
    393   if (-r $BarnOwl::configfile) {
    394       undef $@;
    395       do $BarnOwl::configfile;
    396       BarnOwl::error("Error reloading $BarnOwl::configfile: $@") if $@;
    397   }
    398   BarnOwl::reload_hook(@_);
    399   package BarnOwl;
    400 }
    401 
    402 sub reload_init ()
    403 {
    404     BarnOwl::command('alias reload perl BarnOwl::reload()');
    405     BarnOwl::command('bindkey global "C-x C-r" command reload');
    406 }
    407 
    408 ################################################################################
    409 # Loads modules from ~/.owl/modules and owl's data directory
    410 ################################################################################
    411 
    412 sub loadModules () {
    413     my @modules;
    414     my $rv;
    415     foreach my $dir ( BarnOwl::get_data_dir() . "/modules",
    416                       $ENV{HOME} . "/.owl/modules" )
    417     {
    418         opendir( MODULES, $dir );
    419 
    420         # source ./modules/*.pl
    421         @modules = sort grep( /\.pl$/, readdir(MODULES) );
    422 
    423         foreach my $mod (@modules) {
    424             unless ($rv = do "$dir/$mod") {
    425                 BarnOwl::error("Couldn't load $dir/$mod:\n $@") if $@;
    426                 BarnOwl::error("Couldn't run $dir/$mod:\n $!") unless defined $rv;
    427             }
    428         }
    429         closedir(MODULES);
    430     }
    431 }
     351
     352package BarnOwl::Hook;
     353
     354sub new {
     355    my $class = shift;
     356    return bless [], $class;
     357}
     358
     359sub run {
     360    my $self = shift;
     361    my @args = @_;
     362    return map {$_->(@args)} @$self;
     363}
     364
     365sub add {
     366    my $self = shift;
     367    my $func = shift;
     368    die("Not a coderef!") unless ref($func) eq 'CODE';
     369    push @$self, $func;
     370}
     371
     372sub clear {
     373    my $self = shift;
     374    @$self = ();
     375}
     376
     377package BarnOwl::Hooks;
     378
     379use Exporter;
     380
     381our @EXPORT_OK = qw($startup $shutdown
     382                    $receiveMessage $mainLoop
     383                    $getBuddyList);
     384
     385our %EXPORT_TAGS = (all => [@EXPORT_OK]);
     386
     387our $startup = BarnOwl::Hook->new;
     388our $shutdown = BarnOwl::Hook->new;
     389our $receiveMessage = BarnOwl::Hook->new;
     390our $mainLoop = BarnOwl::Hook->new;
     391our $getBuddyList = BarnOwl::Hook->new;
     392
     393# Internal startup/shutdown routines called by the C code
    432394
    433395sub _load_owlconf {
    434     # Only do this the first time
    435     return if $BarnOwl::reload;
    436396    # load the config  file
    437397    if ( -r $BarnOwl::configfile ) {
     
    451411}
    452412
    453 package BarnOwl::Hooks;
    454 
    455 # Arrays of subrefs to be called at specific times.
    456 our @onStartSubs = ();
    457 our @onReceiveMsg = ();
    458 our @onMainLoop = ();
    459 our @onGetBuddyList = ();
    460 
    461 # Functions to call hook lists
    462 sub runHook($@)
    463 {
    464     my $hook = shift;
    465     my @args = @_;
    466     $_->(@args) for (@$hook);
    467 }
    468 
    469 sub runHook_accumulate($@)
    470 {
    471     my $hook = shift;
    472     my @args = @_;
    473     return join("\n", map {$_->(@args)} @$hook);
    474 }
    475 
    476 ################################################################################
    477 # Startup and Shutdown code
    478 ################################################################################
    479 sub startup
    480 {
    481     # Modern versions of owl provides a great place to have startup stuff.
    482     # Put things in ~/.owl/startup
    483 
    484     #So that the user's .owlconf can have startsubs, we don't clear
    485     #onStartSubs; reload does however
    486     @onReceiveMsg = ();
    487     @onMainLoop = ();
    488     @onGetBuddyList = ();
    489 
    490     BarnOwl::onStart();
    491 
    492     runHook(\@onStartSubs);
    493 
     413sub _startup {
     414    _load_owlconf();
     415
     416    if(eval {require BarnOwl::ModuleLoader}) {
     417        eval {
     418            BarnOwl::ModuleLoader->load_all;
     419        };
     420        BarnOwl::error("Error loading modules: $@") if $@;
     421    } else {
     422        BarnOwl::error("Can't load BarnOwl::ModuleLoader, loadable module support disabled:\n$@");
     423    }
     424   
     425    $startup->run(0);
    494426    BarnOwl::startup() if *BarnOwl::startup{CODE};
    495427}
    496428
    497 sub shutdown
    498 {
    499 # Modern versions of owl provides a great place to have shutdown stuff.
    500 # Put things in ~/.owl/shutdown
    501 
    502     # use $shutdown to tell modules that that's what we're doing.
    503     $BarnOwl::shutdown = 1;
     429sub _shutdown {
     430    $shutdown->run;
     431   
     432    BarnOwl::shutdown() if *BarnOwl::shutdown{CODE};
     433}
     434
     435sub _receive_msg {
     436    my $m = shift;
     437
     438    $receiveMessage->run($m);
     439   
     440    BarnOwl::receive_msg($m) if *BarnOwl::receive_msg{CODE};
     441}
     442
     443sub _mainloop_hook {
     444    $mainLoop->run;
    504445    BarnOwl::mainloop_hook() if *BarnOwl::mainloop_hook{CODE};
    505 
    506     BarnOwl::shutdown() if *BarnOwl::shutdown{CODE};
    507 }
    508 
    509 sub mainloop_hook
    510 {
    511     runHook(\@onMainLoop);
    512     BarnOwl::mainloop_hook() if *BarnOwl::mainloop_hook{CODE};
    513 }
    514 
    515 ################################################################################
    516 # Hooks into receive_msg()
    517 ################################################################################
    518 
    519 sub receive_msg
    520 {
    521     my $m = shift;
    522     runHook(\@onReceiveMsg, $m);
    523     BarnOwl::receive_msg($m) if *BarnOwl::receive_msg{CODE};
    524 }
    525 
    526 ################################################################################
    527 # Hooks into get_blist()
    528 ################################################################################
    529 
    530 sub get_blist
    531 {
    532     return runHook_accumulate(\@onGetBuddyList);
     446}
     447
     448sub _get_blist {
     449    return join("\n", $getBuddyList->run);
    533450}
    534451
     
    644561# switch to package main when we're done
    645562package main;
    646 # alias the hooks
    647 {
    648     no strict 'refs';
    649     foreach my $hook  qw (onStartSubs
    650                           onReceiveMsg
    651                           onMainLoop
    652                           onGetBuddyList ) {
    653         *{"main::".$hook} = \*{"BarnOwl::Hooks::".$hook};
    654         *{"owl::".$hook} = \*{"BarnOwl::Hooks::".$hook};
    655     }
    656 }
     563
     564# Shove a bunch of fake entries into @INC so modules can use or
     565# require them without choking
     566$::INC{$_} = 1 for (qw(BarnOwl.pm BarnOwl/Hooks.pm
     567                       BarnOwl/Message.pm BarnOwl/Style.pm));
    657568
    6585691;
     570
Note: See TracChangeset for help on using the changeset viewer.