Changeset f1e629d


Ignore:
Timestamp:
Jul 6, 2003, 6:42:06 PM (21 years ago)
Author:
Erik Nygren <nygren@mit.edu>
Branches:
master, barnowl_perlaim, debian, owl, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
5d9c664
Parents:
675ce49
Message:
	New API for perl message formatting functions.
	        Legacy variables are still supported for owl::format_msg
		and owl::receive_msg, but these functions are now also
		passed an owl::Message object which contains methods
		for accessing the contents of the message.  See perlwrap.pm
		(and docs TBD) for the available methods.
		*** WARNING:  The exact API for owl::Message has
		*** not yet stabilized.
	Added "style" command for creating new styles.
	        Usage:  style <name> perl <function_name>
	Added support for "show styles".  Changed global style table
	        from list to dictionary.
	Changed AIM password prompt from "Password:" to "AIM Password:".
	Messages are reformatted after a window resize to allow styles
	        to take into account the width of the window.
	When perl throws an error, the message is put in the msgwin
	        if possible.
	Added perl functions for:
	        owl::getcurmsg() -- returns an owl::Message object for
		                    the active message
		                    in the current view.
	        owl::getnumcols() -- returns the column width of the window
		owl::zephyr_getrealm() -- returns the zephyr realm
	        owl::zephyr_getsender() -- returns the zephyr sender
	Made owl::COMMAND("foo"); be syntactic sugar for
	        owl::command("COMMAND foo");
		*** Is this a good or bad idea?
		*** This feature may be taken out before release.
	Added perlwrap.pm to contain perl code to be compiled into
	        the binary.  This is transformed into perlwrap.c by
		encapsulate.pl.
	Renamed readconfig.c to perlconfig.c and changed variables accordingly.
	Minor bugfixes in cmd.c and commands.c
Files:
3 added
1 deleted
16 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r6873455 rf1e629d  
    11$Id$
     2
     32.0.8-pre-2
     4        New API for perl message formatting functions. 
     5                Legacy variables are still supported for owl::format_msg
     6                and owl::receive_msg, but these functions are now also
     7                passed an owl::Message object which contains methods
     8                for accessing the contents of the message.  See perlwrap.pm
     9                (and docs TBD) for the available methods.
     10                *** WARNING:  The exact API for owl::Message has
     11                *** not yet stabilized.
     12        Added "style" command for creating new styles.
     13                Usage:  style <name> perl <function_name>
     14        Added support for "show styles".  Changed global style table
     15                from list to dictionary.
     16        Changed AIM password prompt from "Password:" to "AIM Password:".
     17        Messages are reformatted after a window resize to allow styles
     18                to take into account the width of the window.
     19        When perl throws an error, the message is put in the msgwin
     20                if possible.
     21        Added perl functions for:       
     22                owl::getcurmsg() -- returns an owl::Message object for
     23                                    the active message
     24                                    in the current view.
     25                owl::getnumcols() -- returns the column width of the window
     26                owl::zephyr_getrealm() -- returns the zephyr realm
     27                owl::zephyr_getsender() -- returns the zephyr sender
     28        Made owl::COMMAND("foo"); be syntactic sugar for
     29                owl::command("COMMAND foo");
     30                *** Is this a good or bad idea?
     31                *** This feature may be taken out before release.
     32        Added perlwrap.pm to contain perl code to be compiled into
     33                the binary.  This is transformed into perlwrap.c by
     34                encapsulate.pl.
     35        Renamed readconfig.c to perlconfig.c and changed variables accordingly.
     36        Minor bugfixes in cmd.c and commands.c
    237
    3382.0.8-pre-1
  • Makefile.in

    rbd3f232 rf1e629d  
    2020BASE_SRCS=list.c message.c mainwin.c popwin.c zephyr.c messagelist.c \
    2121     commands.c global.c text.c fmtext.c editwin.c util.c logging.c \
    22      readconfig.c keys.c functions.c zwrite.c viewwin.c help.c filter.c \
     22     perlconfig.c keys.c functions.c zwrite.c viewwin.c help.c filter.c \
    2323     regex.c history.c view.c dict.c variable.c filterelement.c pair.c \
    2424     keypress.c keymap.c keybinding.c cmd.c context.c zcrypt.c \
    25      aim.c buddylist.c timer.c style.c stylefunc.c
     25     aim.c buddylist.c timer.c style.c stylefunc.c 
    2626OWL_SRC = owl.c
    2727TESTER_SRC = tester.c
     
    2929BASE_OBJS = $(BASE_SRCS:.c=.o)
    3030
    31 GEN_C = varstubs.c perlglue.c
     31GEN_C = varstubs.c perlglue.c perlwrap.c
    3232GEN_H = owl_prototypes.h
    3333GEN_O = $(GEN_C:.c=.o)
     
    6161varstubs.c: variable.c stubgen.pl
    6262        perl stubgen.pl > varstubs.c
     63
     64perlwrap.c: perlwrap.pm encapsulate.pl
     65        perl encapsulate.pl perlwrap.pm owl_perlwrap_codebuff > perlwrap.c
    6366
    6467# Only move owl_prototypes.h into place if the new one is different
  • cmd.c

    r1c7a4e0 rf1e629d  
    9696  if (!templ->name) return(-1);
    9797  cmd->name = owl_strdup(templ->name);
    98   if (cmd->summary)     cmd->summary     = owl_strdup(templ->summary);
    99   if (cmd->usage)       cmd->usage       = owl_strdup(templ->usage);
    100   if (cmd->description) cmd->description = owl_strdup(templ->description);
    101   if (cmd->cmd_aliased_to) cmd->cmd_aliased_to = owl_strdup(templ->cmd_aliased_to);
     98  if (templ->summary)     cmd->summary     = owl_strdup(templ->summary);
     99  if (templ->usage)       cmd->usage       = owl_strdup(templ->usage);
     100  if (templ->description) cmd->description = owl_strdup(templ->description);
     101  if (templ->cmd_aliased_to) cmd->cmd_aliased_to = owl_strdup(templ->cmd_aliased_to);
    102102  return(0);
    103103}
  • commands.c

    r6873455 rf1e629d  
    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"),
    103111
    104112  OWLCMD_ARGS("zwrite", owl_command_zwrite, OWL_CTX_INTERACTIVE,
     
    567575              "show subscriptions\n"
    568576              "show zpunts\n"
     577              "show styles\n"
    569578              "show colors\n"
    570579              "show terminal\n"
     
    583592              "Show commands will list the names of all keymaps.\n"
    584593              "Show command <command> will provide information about a command.\n\n"
     594              "Show styles will list the names of all styles available\n"
     595              "for formatting messages.\n\n"
    585596              "Show variables will list the names of all variables.\n\n"
    586597              "SEE ALSO: filter, view, alias, bindkey, help\n"),
     
    14131424
    14141425  if (argc < 5 || strcmp(argv[3], "command")) {
    1415     owl_function_makemsg("Usage: bindkey <keymap> <binding> command <cmd>", argv[3], argc);
     1426    owl_function_makemsg("Usage: bindkey <keymap> <binding> command <cmd>");
    14161427    return NULL;
    14171428  }
     
    14301441  return NULL;
    14311442}
     1443
     1444char *owl_command_style(int argc, char **argv, char *buff) {
     1445  owl_style *s;
     1446
     1447  /* Usage: style <name> perl <function> */
     1448  if (argc != 4 || strcmp(argv[2], "perl")) {
     1449    owl_function_makemsg("Usage: style <name> perl <function>");
     1450    return NULL;
     1451  }
     1452  if (!owl_perlconfig_is_function(argv[3])) {
     1453    owl_function_makemsg("Unable to create style '%s': no perl function '%s'",
     1454                         argv[1], argv[3]);
     1455    return NULL;
     1456  }
     1457  s=owl_malloc(sizeof(owl_style));
     1458  owl_style_create_perl(s, argv[1], argv[3], NULL);
     1459  owl_global_add_style(&g, s);
     1460
     1461  return NULL;
     1462}
     1463
    14321464
    14331465void owl_command_quit()
     
    18641896  } else if (!strcmp(argv[1], "colors")) {
    18651897    owl_function_show_colors();
     1898  } else if (!strcmp(argv[1], "styles")) {
     1899    owl_function_show_styles();
    18661900  } else if (!strcmp(argv[1], "subs") || !strcmp(argv[1], "subscriptions")) {
    18671901    owl_function_getsubs();
     
    21152149  if (argc==2) {
    21162150    owl_global_set_buffercommand(&g, buff);
    2117     owl_function_start_password("Password: ");
     2151    owl_function_start_password("AIM Password: ");
    21182152    return(NULL);
    21192153  }
  • examples/owlconf.erik

    r039213e rf1e629d  
    11### The owlconf config file   -*- perl -*- 
    22###  $Id$
    3 
     3###
    44### !!!!!WARNING!!!!! !!!!!WARNING!!!!! !!!!!WARNING!!!!! !!!!!WARNING!!!!!
    55### This is an example file intended to demonstrate how to use
     
    99### Don't blame me if anything in here ends up vaporizing your dog.
    1010### !!!!!WARNING!!!!! !!!!!WARNING!!!!! !!!!!WARNING!!!!! !!!!!WARNING!!!!!
    11 
     11###
    1212###
    1313### This file is interpreted by the perl interpreter.
     
    2424###     owl::startup()     run when owl first starts
    2525###     owl::shutdown()    run when owl exits
    26 ###     owl::format_msg()  run when a new message arrives, the return
    27 ###                           value is used to display the message on the
    28 ###                           screen
     26###     owl::format_msg()  formats messages that are passed to it
    2927###     owl::receive_msg() run when a message is received, and after
    3028###                        it has been added to the message list
    3129###
    32 ###
    33 ### The following variables will be set each time a message is recevied:
    34 ###
    35 ###     $owl::class, $owl::instance, $owl::recipient,
    36 ###     $owl::sender, $owl::opcode, $owl::zsig,
    37 ###     $owl::msg, $owl::time, $owl::host, @owl::fields, $owl::id
     30### The format_msg and receive_msg functions are passed owl::Message objects.
     31### The message attributes may be dereferenced with $m->attribute
     32###
    3833###   
    3934
     
    4641my @sepbartokens = ();
    4742
     43# Map for mail messages from msg id to pop msg id
     44my %mail_id_map = ();
     45
     46# (originally from jdaniel)
     47sub mail_add_message ($) {
     48    my ($m) = @_;
     49    my $from = `from -t`;
     50    # example value:
     51    # You have 188 messages (667593 bytes) on PO11.MIT.EDU.
     52    my ($msg_num) = $from =~ m/(\d+)/;
     53    $mail_id_map{$m->id} = $msg_num;
     54}
     55
     56
     57sub mail_pop_curmsg () {
     58    my $m = owl::getcurmsg();
     59    if (!$m->is_mail || !defined $mail_id_map{$m->id}) {
     60        &owl::command("pop-message");
     61    } else {
     62        &owl::command(sprintf 'pexec pop -request c -request "retr %d" -request q',
     63                      $mail_id_map{$m->id});
     64    }
     65}
     66
     67sub zlocatesender {
     68    my $m = owl::getcurmsg();
     69    if ($m->{"type"} eq "zephyr") {
     70        my $sender = $m->{"sender"};
     71        owl::command("zlocate $sender");
     72    }
     73}
    4874
    4975# adds a sepbartoken and also updates the appendtosepbar variable
     
    6389}
    6490
     91my $loopctr=0;
     92
    6593# trims a sepbartoken from the list also updates the appendtosepbar variable
    6694sub sepbartokens_set {
    67     owl::command(sprintf "set -q appendtosepbar \"%s\"", (join " ", @sepbartokens));
     95    owl::command(sprintf "set -q appendtosepbar \"%s %s %s\"", (scalar localtime), (join " ", @sepbartokens));
    6896}
    6997
     
    73101    if ($restoreview) {
    74102        owl::command("view $restoreview");
    75         $restoreview = undef;
    76     } else {
    77         $restoreview = $curview;
    78         owl::command("smartnarrow");
     103        $restoreview = undef;
     104    } else {
     105        $restoreview = $curview;
     106        owl::command("smartnarrow");
    79107    }
    80108}
     
    91119    } else {
    92120        owl::command("filter $smartfilt -c green");
    93         $lastcolored = $smartfilt;
     121        $lastcolored = $smartfilt;
     122    }
     123}
     124
     125# Load in things which don't belong in an owlconf
     126# that people might use as an example...
     127sub personal_startup {
     128    my $personalconf = $ENV{"HOME"}."/.owl/personalconf";
     129    if (-f $personalconf) {
     130        my $b = "";
     131        open INB, $personalconf;
     132        for (<INB>) { $b .= $_; }
     133        close INB;
     134        eval $b;
    94135    }
    95136}
    96137
    97138sub owl::startup {
    98     owl::command("set -q logging off");
    99     owl::command("set -q zsigproc /home/nygren/bin/owlzsigs");
     139    owl::command("set -q logging on");
     140    owl::command("set -q logpath ~/.zlog/owl/personal");
     141    owl::command("set -q classlogpath ~/.zlog/owl/class");
     142    owl::command("set -q logging on");
    100143    owl::command("set -q startuplogin off");
    101144    owl::command("set -q shutdownlogout off");
    102145    #owl::command("set personalbell on");
     146    owl::command("set -q _burningears on");
    103147    owl::command("set -q rxping on");
    104148    owl::command("set -q typewinsize 5");
    105     if ($ENV{"DISPLAY"} eq ":0") {
     149    if ($ENV{"DISPLAY"} eq ":0.0") {
    106150      owl::command("set -q webbrowser galeon");
    107151    }
    108     owl::command("filter me recipient ".$ENV{"USER"});
    109     owl::command("filter help class help");
    110     owl::command("filter quiet not ( class ^greed|geek|help|login$ or instance white-magic )");   
     152    owl::command("filter me recipient %me% or ( sender %me% and class message and instance personal ) or class mail or type aim");
     153    owl::command("filter owl instance ^owl.*");
     154
     155    owl::command(q(alias finger pperl $x=owl::getcurmsg()->hostname; `finger \@$x`;));
     156    owl::command("bindkey recv f command finger");
    111157
    112158    owl::command("alias z zwrite");
    113     owl::command("alias zc zwrite -c");
    114 
    115     # Send zephyrs with "C-c C-c". 
    116     # Note that this will cause "C-c" to not work...
    117     owl::command("bindkey editmulti \"C-c C-c\" command editmulti:done");
    118 
    119     # Make "d" ignore current movement direction
    120     owl::command("bindkey recv d command ( delete --no-move ; next --skip-deleted )");
    121 
    122     # Useful keys for reading and deleting by class/instance
     159    owl::command("alias zw zwrite");
     160    owl::command("alias v view");
     161
     162    owl::command("alias popmail perl mail_pop_curmsg();");
     163
     164    # toggle between a view and a smartnarrow with TAB
     165    owl::command("alias swapview perl swapview();");
     166    owl::command("bindkey recv C-i command swapview");
     167
     168    # color the current thread
     169    owl::command("alias colorthread perl colorthread();");
     170    owl::command("bindkey recv M-c command colorthread");
     171
     172    # zlocate current sender
     173    owl::command("bindkey recv L command perl zlocatesender();");
     174
     175    # Declare styles
     176    &owl::command("style vt     perl format_msg_vt");
     177    &owl::command("style brief  perl format_msg_brief");
     178    &owl::command("style custom perl format_msg_custom");
     179    &owl::command("style debug  perl format_msg_debug");
     180    &owl::command("set -q default_style custom");
     181
     182    # Change to different view styles
     183    owl::command("bindkey recv \"C-s v\" command view -s vt");
     184    owl::command("bindkey recv \"C-s c\" command view -s custom");
     185    owl::command("bindkey recv \"C-s b\" command view -s brief");
     186    owl::command("bindkey recv \"C-s d\" command view -s debug");
     187    owl::command("bindkey recv \"C-s o\" command view -s standard");
     188
     189    # For fast-reading of zephyrs
    123190    owl::command("bindkey recv M-k command ( smartnarrow ; delete view )");
    124191    owl::command("bindkey recv M-l command ( expunge ; view all )");
    125192    owl::command("bindkey recv M-K command ( smartnarrow ; delete view ; expunge ; view all )");
    126193
    127     # Toggle between a view and a smartnarrow with TAB.
    128     # Note that you probably want to use something other than TAB as
    129     # it will have another binding in a future version of owl.
    130     owl::command("alias swapview perl swapview();");
    131     owl::command("bindkey recv C-i command swapview");
    132 
    133     # color the current thread
    134     owl::command("alias colorthread perl colorthread();");
    135     owl::command("bindkey recv M-c command colorthread");
    136 
    137     # Make 'M-s' insert a <scritchscritchscritch> sequence with a random
    138     # number of scritches.
    139     owl::command(q(bindkey edit M-s command perl owl::command("edit:insert-text <".("scritch"x int(1+rand(5))).">")));
    140 
     194    # Support for scroll mice
     195    &owl::command("bindkey recv \"M-[ A\" command recv:prev");
     196    &owl::command("bindkey recv \"M-[ B\" command recv:next");
     197
     198    # This overrides the default "M" keybinding
     199    owl::command("bindkey recv M command popmail");
     200
     201    sepbartokens_add("...");
     202
     203    personal_startup();
    141204}
    142205
     
    145208}
    146209
     210
     211# run when a message is received, and after
     212# it has been added to the message list.
     213sub owl::receive_msg {
     214    my ($m) = @_;
     215    my ($out, $tmp);
     216
     217    if ($m->is_admin && !$m->is_outgoing) {
     218        $m->delete();
     219        return 1;
     220    }
     221
     222    return 0 if (!$m->is_zephyr && !$m->is_aim);
     223
     224    my $sender = $m->pretty_sender;
     225
     226    if ($m->is_ping) {
     227        sepbartokens_add(".$sender");
     228        $m->delete();
     229    } elsif ($m->is_loginout) {
     230        $m->delete();
     231        if ($m->is_login) {
     232            sepbartokens_add(">$sender");
     233            sepbartokens_trim("<$sender");
     234        } elsif ($m->is_logout) {
     235            sepbartokens_add("<$sender");
     236            sepbartokens_trim(">$sender");
     237        }
     238    } elsif ($m->is_mail) {
     239        mail_add_message($m);
     240        $m->delete();
     241        sepbartokens_add("M");
     242    }
     243
     244    if ($m->is_personal) {
     245        sepbartokens_trim(".$sender");
     246        sepbartokens_add(":$sender");
     247    }
     248
     249    return 1;
     250}
     251
     252sub indent4 {
     253    my ($b) = @_;
     254    $b=~s/^/    /g;
     255    $b=~s/\n/\n    /g;   
     256    return $b;
     257}
     258
    147259# run to format a message
    148 sub owl::format_msg {
    149     my $out, $tmp;
    150 
    151     $owl::sender=~s/\@ATHENA\.MIT\.EDU$//;
    152     $owl::sender=~s/\@local-realm$//;
    153 
    154     if (uc($owl::opcode) eq "PING") {
    155         return("\@bold(PING) from \@bold($owl::sender)\n");
    156     } elsif (uc($owl::class) eq "LOGIN") {
    157         if (uc($owl::opcode) eq "USER_LOGIN") {
     260sub format_msg_custom {
     261    my ($m) = @_;
     262    my ($out, $tmp);
     263
     264    if ($m->is_admin) {
     265        $out = "\@bold([owl admin]) ".$m->header."\n";
     266        $out.=indent4($m->body);
     267        return $out."\n";
     268    }
     269
     270    my $sender=$m->pretty_sender;
     271
     272    if (($m->is_aim or $m->is_zephyr) && $m->is_loginout) {
     273
     274        if ($m->is_login) {
    158275            $out="\@bold(LOGIN)";
    159         } elsif (uc($owl::opcode) eq "USER_LOGOUT") {
     276        } elsif ($m->is_logout) {
    160277            $out="\@bold(LOGOUT)";
    161278        } else {
    162279            $out="\@bold(UNKNOWN)";
    163280        }
    164         $out.=" for \@bold($owl::sender) at $fields[0] on $fields[2]\n";
     281        $out.=" for \@bold($sender) on ".$m->type;
     282        if ($m->is_zephyr) {
     283            $out.=" at ".($m->login_host)." on ".($m->login_tty)."\n";
     284        }
    165285        return($out);
    166     } elsif (uc($owl::class) eq "MAIL" and uc($owl::instance) eq "INBOX") {
     286    }
     287
     288    if (!$m->is_zephyr && !$m->is_aim) {
     289        return "Unknown message type: ".$m->type."\n";
     290    }
     291
     292    if ($m->is_outgoing) {
     293        my $target = $m->recipient;
     294        if ($m->is_zephyr) {
     295            $target = $m->zwriteline;
     296            $target =~ s/^zwrite //;
     297        }
     298        $out = sprintf "\@bold([outgoing %s to %s]) / %s\n", $m->type, $target, $m->time;
     299        $out.=indent4($m->body);
     300        return $out;
     301    }
     302
     303    if ($m->is_zephyr && $m->is_ping) {
     304        return("\@bold(PING) from \@bold($sender)\n");
     305    } elsif ($m->is_zephyr && $m->is_mail) {
    167306        $out = "\@bold(MAIL) ";
    168         if ($owl::msg =~ /^From:\s+(.+)\s*$/m) { $out .= "From $1 "; }
    169         if ($owl::msg =~ /^To:\s+(.+)\s*$/m) { $out .= "To $1 "; }
    170         if ($owl::msg =~ /^Subject:\s+(.+)\s*$/m) { $out .= "Subject $1 "; }
     307        if ($m->body =~ /^From:\s+(.+)\s*$/m) { $out .= "From $1 "; }
     308        if ($m->body =~ /^To:\s+(.+)\s*$/m) { $out .= "To $1 "; }
     309        if ($m->body =~ /^Subject:\s+(.+)\s*$/m) { $out .= "Subject $1 "; }
     310        return($out);
     311    }
     312
     313    if ($m->is_zephyr) {
     314        $out = sprintf "[mit,%s,%s] / %s / %s", lc($m->class),
     315        lc($m->instance), $m->time, lc($m->host);
     316        if ($m->opcode ne "") {$out.=" op:".$m->opcode;}
     317        $out.="\n";
     318        $out.= "  \@bold($sender)> ";
     319        if ($m->zsig ne "") {
     320            my $zsig = $m->zsig;
     321            $zsig =~ s/(\n.*)+$/ [...]/;
     322            if (length($zsig)+5+length($sender) > 70) {
     323                $out.="# ...";
     324            } else {
     325                $out.="# $zsig";
     326            }
     327        }
     328        $out.="\n";             
     329    } else {
     330        $out = sprintf "[%s] / %s\n", lc($m->type), $m->time;
     331        $out.= "  \@bold($sender)> ";
     332        $out.="\n";             
     333    }
     334
     335    $out.=indent4($m->body);
     336
     337    # make personal messages bold
     338    if ($m->is_personal) {
     339        $out="\@bold{".$out."}";
     340    }
     341
     342    return($out."\n");
     343}
     344
     345sub format_msg_debug {
     346    my ($m) = @_;
     347    return "\@bold(-------------MESSAGE-------------)\n".($m->serialize).".\n";
     348}
     349
     350sub format_msg_brief {
     351    my ($m) = @_;
     352    my $out = format_msg_vt($m);
     353    $out =~ s/\n/ /g;
     354    $out =~ s/                        / /g;
     355    return($out."\n");
     356}
     357
     358
     359sub format_msg_vt {
     360    my ($m) = @_;
     361    my ($out, $tmp);
     362
     363    if ($m->is_admin) {
     364        $out = sprintf "%-29s \@i(%s)", "\@bold(OWL ADMIN)", $m->header;
     365        $tmp=$m->body;
     366        $tmp=~s/^/                       /g;
     367        $tmp=~s/\n/\n                       /g;
     368        $out.="\n".$tmp;
     369        return $out;
     370    }
     371
     372    my $sender=$m->pretty_sender;
     373
     374    if ($m->is_outgoing) {
     375        my $target = $m->recipient;
     376        if ($m->is_zephyr) {
     377            $target = $m->zwriteline;
     378            $target =~ s/^zwrite //;
     379        }
     380        $out = sprintf "%-15s %-13s", "\@bold(OUTGOING)", "to $target via ".$m->type.": ";
     381        my $pagewidth = owl::getnumcols()-6;
     382        $out .= fill_text($m->body, $pagewidth, 22, 1);
     383        return $out;
     384    }
     385
     386    if (!$m->is_zephyr && !$m->is_aim) {
     387        return "Unknown message type: ".$m->type."\n";
     388    }
     389
     390    if ($m->is_zephyr && $m->is_ping) {
     391        return (sprintf "%-15s %-13s\n", "\@bold(PING)", $sender);
     392    } elsif ($m->is_loginout) {
     393        my $state;
     394        if ($m->is_login) {
     395            $state="\@bold(LOGIN)";
     396        } elsif ($m->is_logout) {
     397            $state="\@bold(LOGOUT)";
     398        } else {
     399            $state="\@bold(UNKNOWN)";
     400        }
     401        my $out = sprintf "%-15s %-13s ", $state, $sender;
     402        if ($m->is_zephyr) {
     403            $out .= sprintf "via %s on %s at %s", $m->type, $m->login_host, $m->login_tty;
     404        } else {
     405            $out .= sprintf "via %s", $m->type;
     406        }
     407        return "$out\n";
     408               
     409    } elsif ($m->is_zephyr && $m->is_mail) {
     410        my $body = $m->body;
     411        $out = sprintf "%-15s %-13s ", "\@bold(MAIL)", "";
     412        if ($body =~ /^From:\s+(.+)\s*$/m) { $out .= "From $1 "; }
     413        if ($body =~ /^To:\s+(.+)\s*$/m) { $out .= "To $1 "; }
     414        if ($body =~ /^Subject:\s+(.+)\s*$/m) { $out .= "Subject $1 "; }
    171415        return($out."\n");
    172416    }
    173417
    174     $out = sprintf "[mit,%s,%s] / %s / %s", lc($owl::class),
    175                    lc($owl::instance), $owl::time, lc($owl::host);
    176     if ($owl::opcode ne "") {$out.=" op:$owl::opcode";}
    177     $out.="\n";
    178     $out.= "  \@bold($owl::sender)> ";
    179     if ($owl::zsig ne "") {
    180         my $zsig = $owl::zsig;
    181         $zsig =~ s/(\n.*)+$/ [...]/;
    182         if (length($zsig)+5+length($owl::sender) > 70) {
    183             $out.="# ...";
    184         } else {
    185             $out.="# $zsig";
    186         }
    187     }
    188     $out.="\n";         
    189 
    190     # indent it
    191     $tmp=$owl::msg;
    192     $tmp=~s/^/    /g;
    193     $tmp=~s/\n/\n    /g;
    194     $out.=$tmp;
     418    my $channel = "";
     419    my $body = $m->body;
     420   
     421    if ($m->is_zephyr) {
     422        my $inst = $m->instance;
     423        $channel = $m->class;
     424        if (lc($m->class) ne "message" and lc($m->instance) eq "personal") {
     425            $inst = "";
     426        }
     427        $channel .= "[".$inst."]";
     428        $channel = substr($channel,0,13);
     429    } else {
     430        $channel = "[".$m->type."]";
     431    }
     432
     433    $header = sprintf "%-8s %-13s ", lc($sender), lc($channel);
     434
     435    if ($body =~ /=/) {
     436        # indent it
     437        $out.=$header."\n".indent4($body);
     438    } else {
     439        # fill it
     440        my $pagewidth = owl::getnumcols()-6;
     441        $out .= $header;
     442        $out .= fill_text($body, $pagewidth, 22, 1);
     443    }
     444
     445    # note: no zsig added in this version
    195446
    196447    # make personal messages bold
    197     if (uc($owl::class) eq "MESSAGE" &&
    198         uc($owl::instance) eq "PERSONAL") {
     448    if ($m->is_personal) {
    199449        $out="\@bold{".$out."}";
    200450    }
    201 
    202     return($out."\n");
    203 }
    204 
    205 # run when a message is received, and after
    206 # it has been added to the message list.
    207 sub owl::receive_msg() {
    208     my $out, $tmp;
    209 
    210     $owl::sender=~s/\@ATHENA\.MIT\.EDU$//;
    211     $owl::sender=~s/\@local-realm$//;
    212 
    213     if (uc($owl::opcode) eq "PING") {
    214         sepbartokens_add(".$owl::sender");
    215         owl::command("delete -id $owl::id");
    216     } elsif (uc($owl::class) eq "LOGIN") {
    217         owl::command("delete -id $owl::id");
    218         if (uc($owl::opcode) eq "USER_LOGIN") {
    219             sepbartokens_add(">$owl::sender");
    220             sepbartokens_trim("<$owl::sender");
    221         } elsif (uc($owl::opcode) eq "USER_LOGOUT") {
    222             sepbartokens_add("<$owl::sender");
    223             sepbartokens_trim(">$owl::sender");
    224         }
    225     } elsif (uc($owl::class) eq "MAIL") {
    226         owl::command("delete -id $owl::id");
    227         sepbartokens_add("M");
    228     }
    229 
    230 
    231     # make personal messages bold
    232     if (uc($owl::class) eq "MESSAGE" &&
    233         uc($owl::instance) eq "PERSONAL") {
    234         sepbartokens_trim(".$owl::sender");
    235         sepbartokens_add(":$owl::sender");
    236     }
    237 
    238     return 1;
    239 }
     451    return($out);
     452}
     453
     454sub fill_text {
     455    my ($in, $width, $indent, $unindent_first) = @_;
     456    $indent = 0 if (@_ < 3);
     457    my $unindent = $indent if ($unindent_first);
     458    my @words = split " ", $in;
     459    my $out = "";
     460    my $outline = "";
     461    if (!$unindent_first) {
     462        my $outline = " "x$indent;
     463    }
     464    for my $w (@words) {
     465        if (($outline ne "")
     466            && (length($outline)+length($w) > $width-$unindent)) {
     467            $out .= $outline."\n";
     468            $outline = " "x$indent;
     469            $unindent = 0;
     470        }
     471        if ($outline =~ /.*\.$/) {
     472            $outline .= "  ";
     473        } elsif ($outline ne "") {
     474            $outline .= " ";
     475        }
     476        $outline .= $w;
     477    }
     478    $out .= $outline . "\n";   
     479}
  • functions.c

    ra352335c rf1e629d  
    7878}
    7979
     80void owl_function_show_styles() {
     81  owl_list l;
     82  owl_fmtext fm;
     83
     84  owl_fmtext_init_null(&fm);
     85  owl_fmtext_append_bold(&fm, "Styles:\n");
     86  owl_global_get_style_names(&g, &l);
     87  owl_fmtext_append_list(&fm, &l, "\n", owl_function_style_describe);
     88  owl_fmtext_append_normal(&fm, "\n");
     89  owl_function_popless_fmtext(&fm);
     90  owl_list_free_all(&l, owl_free);
     91  owl_fmtext_free(&fm);
     92}
     93
     94char *owl_function_style_describe(void *name) {
     95  char *desc, *s;
     96  owl_style *style;
     97  style = owl_global_get_style_by_name(&g, name);
     98  if (style) {
     99    desc = owl_style_get_description(style);
     100  } else {
     101    desc = "???";
     102  }
     103  s = owl_sprintf("%-20s - %s%s", name,
     104                  0==owl_style_validate(style)?"":"[INVALID] ",
     105                  desc);
     106  return s;
     107}
    80108
    81109char *owl_function_cmd_describe(void *name)
     
    741769
    742770  /* execute the commands in shutdown */
    743   ret = owl_config_execute("owl::shutdown();");
     771  ret = owl_perlconfig_execute("owl::shutdown();");
    744772  if (ret) owl_free(ret);
    745773
     
    20512079  buff = skiptokens(buff, 1);
    20522080
    2053   perlout = owl_config_execute(buff);
     2081  perlout = owl_perlconfig_execute(buff);
    20542082  if (perlout) {
    20552083    if (type==1) {
  • global.c

    ra352335c rf1e629d  
    5353  owl_list_create(&(g->puntlist));
    5454  owl_list_create(&(g->messagequeue));
    55   owl_list_create(&(g->stylelist));
     55  owl_dict_create(&(g->styledict));
    5656  g->curmsg_vert_offset=0;
    5757  g->resizepending=0;
     
    390390  _owl_global_setup_windows(g);
    391391
     392  /* in case any styles rely on the current width */
     393  owl_messagelist_invalidate_formats(owl_global_get_msglist(g));
     394
    392395  /* refresh stuff */
    393396  g->needrefresh=1;
     
    774777owl_style *owl_global_get_style_by_name(owl_global *g, char *name)
    775778{
    776   int i, j;
    777   owl_style *s;
    778  
    779   j=owl_list_get_size(&(g->stylelist));
    780   for (i=0; i<j; i++) {
    781     s=owl_list_get_element(&(g->stylelist), i);
    782     if (owl_style_matches_name(s, name)) {
    783       return(s);
    784     }
    785   }
    786   return(NULL);
     779  return owl_dict_find_element(&(g->styledict), name);
     780}
     781
     782/* creates a list and fills it in with keys.  duplicates the keys,
     783 * so they will need to be freed by the caller. */
     784int owl_global_get_style_names(owl_global *g, owl_list *l) {
     785  return owl_dict_get_keys(&(g->styledict), l);
    787786}
    788787
    789788void owl_global_add_style(owl_global *g, owl_style *s)
    790789{
    791   owl_list_append_element(&(g->stylelist), s);
     790  owl_dict_insert_element(&(g->styledict), owl_style_get_name(s),
     791                          s, (void(*)(void*))owl_style_free);
    792792}
    793793
  • message.c

    r9ceee9d rf1e629d  
    574574}
    575575
     576char *owl_message_get_type(owl_message *m) {
     577  switch (m->type) {
     578  case OWL_MESSAGE_TYPE_ADMIN:
     579    return("admin");
     580  case OWL_MESSAGE_TYPE_ZEPHYR:
     581    return("zephyr");
     582  case OWL_MESSAGE_TYPE_GENERIC:
     583    return("generic");
     584  case OWL_MESSAGE_TYPE_AIM:
     585    return("aim");
     586  case OWL_MESSAGE_TYPE_JABBER:
     587    return("jabber");
     588  case OWL_MESSAGE_TYPE_ICQ:
     589    return("icq");
     590  case OWL_MESSAGE_TYPE_YAHOO:
     591    return("yahoo");
     592  case OWL_MESSAGE_TYPE_MSN:
     593    return("msn");
     594  default:
     595    return("unknown");
     596  }
     597}
     598
     599char *owl_message_get_direction(owl_message *m) {
     600  switch (m->direction) {
     601  case OWL_MESSAGE_DIRECTION_IN:
     602    return("in");
     603  case OWL_MESSAGE_DIRECTION_OUT:
     604    return("out");
     605  case OWL_MESSAGE_DIRECTION_NONE:
     606    return("none");
     607  default:
     608    return("unknown");
     609  }
     610}
     611
     612char *owl_message_get_login(owl_message *m) {
     613  if (owl_message_is_login(m)) {
     614    return "login";
     615  } else if (owl_message_is_logout(m)) {
     616    return "logout";
     617  } else {
     618    return "none";
     619  }
     620}
     621
     622char *owl_message_get_header(owl_message *m) {
     623  return owl_message_get_attribute_value(m, "adminheader");
     624}
     625
    576626/* return 1 if the message contains "string", 0 otherwise.  This is
    577627 * case insensitive because the functions it uses are
     
    798848  owl_fmtext_free(&(m->fmtext));
    799849}
     850
     851
  • owl.c

    ra352335c rf1e629d  
    3333  int newmsgs, zpendcount, nexttimediff;
    3434  struct sigaction sigact;
    35   char *configfile, *tty, *perlout, **argvsave, buff[LINE], startupmsg[LINE];
     35  char *configfile, *tty, *perlout, *perlerr, **argvsave, buff[LINE], startupmsg[LINE];
    3636  owl_filter *f;
    3737  owl_style *s;
     
    152152  /* setup the built-in styles */
    153153  s=owl_malloc(sizeof(owl_style));
    154   owl_style_create_internal(s, "default", &owl_stylefunc_default);
     154  owl_style_create_internal(s, "default", &owl_stylefunc_default,
     155                            "Default message formatting");
    155156  owl_global_add_style(&g, s);
    156157
    157158  s=owl_malloc(sizeof(owl_style));
    158   owl_style_create_internal(s, "basic", &owl_stylefunc_basic);
     159  owl_style_create_internal(s, "basic", &owl_stylefunc_basic,
     160                            "Basic message formatting.");
    159161  owl_global_add_style(&g, s);
    160162
    161163  s=owl_malloc(sizeof(owl_style));
    162   owl_style_create_internal(s, "oneline", &owl_stylefunc_oneline);
     164  owl_style_create_internal(s, "oneline", &owl_stylefunc_oneline,
     165                            "Formats for one-line-per-message");
    163166  owl_global_add_style(&g, s);
    164167
     
    224227  /* read the config file */
    225228  owl_context_set_readconfig(owl_global_get_context(&g));
    226   ret=owl_readconfig(configfile);
    227   if (ret) {
     229  perlerr=owl_perlconfig_readconfig(configfile);
     230  if (perlerr) {
    228231    endwin();
    229     printf("\nError parsing configfile\n");
     232    fprintf(stderr, "\nError parsing configfile: %s\n", perlerr);
    230233    exit(1);
    231234  }
     
    235238    owl_function_debugmsg("Found perl formatting");
    236239    s=owl_malloc(sizeof(owl_style));
    237     owl_style_create_perl(s, "perl", "owl::format_msg");
     240    owl_style_create_perl(s, "perl", "owl::_format_msg_legacy_wrap",
     241                          "User-defined perl style that calls owl::format_msg"
     242                          "with legacy global variable support");
    238243    owl_global_add_style(&g, s);
    239244    owl_global_set_default_style(&g, "perl");
    240245  }
    241246
     247  /* set the startup and default style, based on userclue and presence of a
     248   * formatting function */
     249  if (owl_global_is_config_format(&g)) {
     250    owl_global_set_default_style(&g, "perl");
     251  } else if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) {
     252    owl_global_set_default_style(&g, "default");
     253  } else {
     254    owl_global_set_default_style(&g, "basic");
     255  }
     256
    242257  /* execute the startup function in the configfile */
    243   perlout = owl_config_execute("owl::startup();");
     258  perlout = owl_perlconfig_execute("owl::startup();");
    244259  if (perlout) owl_free(perlout);
    245260  owl_function_debugmsg("-- Owl Startup --");
     
    273288  }
    274289
    275   /* set the startup and default style, based on userclue and presence of a
    276    * formatting function */
    277   if (owl_global_is_config_format(&g)) {
    278     owl_view_set_style(owl_global_get_current_view(&g), owl_global_get_style_by_name(&g, "perl"));
    279     owl_global_set_default_style(&g, "perl");
    280   } else if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) {
    281     owl_view_set_style(owl_global_get_current_view(&g), owl_global_get_style_by_name(&g, "default"));
    282     owl_global_set_default_style(&g, "default");
    283   } else {
    284     owl_view_set_style(owl_global_get_current_view(&g), owl_global_get_style_by_name(&g, "basic"));
    285     owl_global_set_default_style(&g, "basic");
    286   }
     290  owl_view_set_style(owl_global_get_current_view(&g),
     291                     owl_global_get_style_by_name(&g, owl_global_get_default_style(&g)));   
    287292
    288293  /* welcome message */
    289294  strcpy(startupmsg, "-------------------------------------------------------------------------\n");
    290   sprintf(buff,      "Welcome to Owl version %s.  Press 'h' for on line help. \n", OWL_VERSION_STRING);
     295  sprintf(buff,      "Welcome to Owl version %s.  Press 'h' for on-line help. \n", OWL_VERSION_STRING);
    291296  strcat(startupmsg, buff);
    292297  strcat(startupmsg, "                                                                         \n");
     
    395400
    396401      /* let the config know the new message has been received */
    397       owl_config_getmsg(m, "owl::receive_msg();");
     402      owl_perlconfig_getmsg(m, 0, NULL);
    398403
    399404      /* add it to any necessary views; right now there's only the current view */
  • owl.h

    r6873455 rf1e629d  
    2121static const char owl_h_fileIdent[] = "$Id$";
    2222
    23 #define OWL_VERSION         2.0.8-pre-1
    24 #define OWL_VERSION_STRING "2.0.8-pre-1"
     23#define OWL_VERSION         2.0.8-pre-2
     24#define OWL_VERSION_STRING "2.0.8-pre-2"
    2525
    2626#define OWL_DEBUG 0
     
    274274typedef struct _owl_style {
    275275  char *name;
     276  char *description;
    276277  int type;
    277278  char *perlfuncname;
     
    451452  owl_buddylist buddylist;  /* list of logged in AIM buddies */
    452453  owl_list messagequeue;    /* for queueing up aim and other messages */
    453   owl_list stylelist;       /* global list of available styles */
     454  owl_dict styledict;       /* global dictionary of available styles */
    454455  char *response;           /* response to the last question asked */
    455456  int havezephyr;
  • perlglue.xs

    r1fd0b25 rf1e629d  
    11static const char fileIdent[] = "$Id$";
    22
    3 #include "EXTERN.h"
    4 #include "perl.h"
    5 #include "XSUB.h"
     3#include <zephyr/zephyr.h>
     4#include <EXTERN.h>
     5#include <perl.h>
     6#include <XSUB.h>
    67
    78/* Yeah, we should just include owl.h, but curses and perl don't play nice. */
    8 extern char *owl_function_command(char *);
    9 extern void owl_free(void *);
     9extern char *owl_function_command(char *cmd);
     10extern void owl_free(void *x);
     11extern SV *owl_perlconfig_curmessage2hashref();
    1012extern int owl_zwrite_create_and_send_from_line(char *, char *);
    1113extern char *owl_function_ztext_stylestrip(char *);
     14extern void g;
     15extern int owl_global_get_cols(void*);
    1216
    1317MODULE = owl            PACKAGE = owl           
     
    2630                if (rv) owl_free(rv);
    2731
     32SV *
     33getcurmsg()
     34        CODE:
     35                ST(0) = owl_perlconfig_curmessage2hashref();
     36
     37int
     38getnumcols()
     39        CODE:
     40                RETVAL = owl_global_get_cols(&g);
     41        OUTPUT:
     42                RETVAL
     43
     44char *
     45zephyr_getrealm()
     46        CODE:
     47                RETVAL = ZGetRealm();
     48        OUTPUT:
     49                RETVAL
     50
     51char *
     52zephyr_getsender()
     53        CODE:
     54                RETVAL = ZGetSender();
     55        OUTPUT:
     56                RETVAL
     57
    2858void
    29 send_zwrite(cmd,msg)
     59zephyr_zwrite(cmd,msg)
    3060        char *cmd
    3161        char *msg
  • style.c

    ref56a67 rf1e629d  
    33static const char fileIdent[] = "$Id$";
    44
    5 void owl_style_create_internal(owl_style *s, char *name, void (*formatfunc) (owl_fmtext *fm, owl_message *m))
     5void owl_style_create_internal(owl_style *s, char *name, void (*formatfunc) (owl_fmtext *fm, owl_message *m), char *description)
    66{
    77  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  }
    914  s->perlfuncname=NULL;
    1015  s->formatfunc=formatfunc;
    1116}
    1217
    13 void owl_style_create_perl(owl_style *s, char *name, char *perlfuncname)
     18void owl_style_create_perl(owl_style *s, char *name, char *perlfuncname, char *description)
    1419{
    1520  s->type=OWL_STYLE_TYPE_PERL;
    1621  s->name=owl_strdup(name);
    1722  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  }
    1829  s->formatfunc=NULL;
    1930}
     
    3041}
    3142
     43char *owl_style_get_description(owl_style *s)
     44{
     45  return(s->description);
     46}
     47
    3248/* Use style 's' to format message 'm' into fmtext 'fm'.
    3349 * 'fm' should already be be initialzed
     
    4157
    4258    /* run the perl function */
    43     body=owl_config_getmsg(m, s->perlfuncname);
     59    body=owl_perlconfig_getmsg(m, 1, s->perlfuncname);
    4460   
    4561    /* indent */
     
    5571}
    5672
     73int owl_style_validate(owl_style *s) {
     74  if (!s) {
     75    return -1;
     76  } else if (s->type==OWL_STYLE_TYPE_INTERNAL) {
     77    return 0;
     78  } else if (s->type==OWL_STYLE_TYPE_PERL
     79             && s->perlfuncname
     80             && owl_perlconfig_is_function(s->perlfuncname)) {
     81    return 0;
     82  } else {
     83    return -1;
     84  }
     85}
     86
    5787void owl_style_free(owl_style *s)
    5888{
    5989  if (s->name) owl_free(s->name);
     90  if (s->description) owl_free(s->description);
    6091  if (s->type==OWL_STYLE_TYPE_PERL && s->perlfuncname) {
    6192    owl_free(s->perlfuncname);
  • util.c

    r3ba3af0 rf1e629d  
    283283char *owl_util_minutes_to_timestr(int in)
    284284{
    285   int days, minutes, hours;
     285  int days, hours;
    286286  long run;
    287287  char *out;
  • variable.c

    r09489b89 rf1e629d  
    204204  OWLVAR_STRING( "default_style" /* %OwlVarStub */, "default",
    205205                 "name of the default formatting style",
    206                  "This sets the default message formatting style. Possbile\n"
    207                  "values include 'default' 'basic' 'oneline' and if\n"
    208                  "available, 'perl'\n" ),
     206                 "This sets the default message formatting style.\n"
     207                 "Styles may be created with the 'style' command.\n"
     208                 "Some built-in styles include:\n"
     209                 "   default  - the default owl formatting\n"
     210                 "   basic    - simple formatting\n"
     211                 "   oneline  - one line per-message\n"
     212                 "   perl     - legacy perl interface\n"
     213                 "\nSEE ALSO: style, show styles, view -s <style>\n"
     214                 ),
     215
    209216
    210217  OWLVAR_INT(    "edit:maxfillcols" /* %OwlVarStub:edit_maxfillcols */, 70,
     
    356363  owl_zephyr_set_locationinfo(owl_global_get_hostname(&g), newval);
    357364  return(owl_variable_string_set_default(v, newval));
    358 }
    359 
    360 int owl_variable_style_set(owl_variable *v, void *newval) {
    361   /* Invalidate all message formats first */
    362   int ret;
    363   owl_style *s;
    364 
    365   s=owl_global_get_style_by_name(&g, newval);
    366   if (!s) {
    367     /* this message won't get seen, we'll need to deal with that later */
    368     owl_function_makemsg("No style named '%s' exists.", newval);
    369     return(0);
    370   }
    371  
    372   owl_messagelist_invalidate_formats(owl_global_get_msglist(&g));
    373   ret=owl_variable_string_set_default(v, newval);
    374   owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS);
    375   owl_mainwin_redisplay(owl_global_get_mainwin(&g));
    376   return(ret);
    377365}
    378366
  • view.c

    ref56a67 rf1e629d  
    6767{
    6868  return(v->style);
     69}
     70
     71char *owl_view_get_style_name(owl_view *v) {
     72  return(owl_style_get_name(v->style));
    6973}
    7074
  • zephyr.c

    re6449bc rf1e629d  
    731731#endif
    732732
    733 
    734733/* returns a buffer of subscriptions or an error message.
    735734 * Caller must free the return.
Note: See TracChangeset for help on using the changeset viewer.