Changeset f1e629d
- Timestamp:
- Jul 6, 2003, 6:42:06 PM (21 years ago)
- 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
- Files:
-
- 3 added
- 1 deleted
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
ChangeLog
r6873455 rf1e629d 1 1 $Id$ 2 3 2.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 2 37 3 38 2.0.8-pre-1 -
Makefile.in
rbd3f232 rf1e629d 20 20 BASE_SRCS=list.c message.c mainwin.c popwin.c zephyr.c messagelist.c \ 21 21 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 \ 23 23 regex.c history.c view.c dict.c variable.c filterelement.c pair.c \ 24 24 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 26 26 OWL_SRC = owl.c 27 27 TESTER_SRC = tester.c … … 29 29 BASE_OBJS = $(BASE_SRCS:.c=.o) 30 30 31 GEN_C = varstubs.c perlglue.c 31 GEN_C = varstubs.c perlglue.c perlwrap.c 32 32 GEN_H = owl_prototypes.h 33 33 GEN_O = $(GEN_C:.c=.o) … … 61 61 varstubs.c: variable.c stubgen.pl 62 62 perl stubgen.pl > varstubs.c 63 64 perlwrap.c: perlwrap.pm encapsulate.pl 65 perl encapsulate.pl perlwrap.pm owl_perlwrap_codebuff > perlwrap.c 63 66 64 67 # Only move owl_prototypes.h into place if the new one is different -
cmd.c
r1c7a4e0 rf1e629d 96 96 if (!templ->name) return(-1); 97 97 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); 102 102 return(0); 103 103 } -
commands.c
r6873455 rf1e629d 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"), 103 111 104 112 OWLCMD_ARGS("zwrite", owl_command_zwrite, OWL_CTX_INTERACTIVE, … … 567 575 "show subscriptions\n" 568 576 "show zpunts\n" 577 "show styles\n" 569 578 "show colors\n" 570 579 "show terminal\n" … … 583 592 "Show commands will list the names of all keymaps.\n" 584 593 "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" 585 596 "Show variables will list the names of all variables.\n\n" 586 597 "SEE ALSO: filter, view, alias, bindkey, help\n"), … … 1413 1424 1414 1425 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>"); 1416 1427 return NULL; 1417 1428 } … … 1430 1441 return NULL; 1431 1442 } 1443 1444 char *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 1432 1464 1433 1465 void owl_command_quit() … … 1864 1896 } else if (!strcmp(argv[1], "colors")) { 1865 1897 owl_function_show_colors(); 1898 } else if (!strcmp(argv[1], "styles")) { 1899 owl_function_show_styles(); 1866 1900 } else if (!strcmp(argv[1], "subs") || !strcmp(argv[1], "subscriptions")) { 1867 1901 owl_function_getsubs(); … … 2115 2149 if (argc==2) { 2116 2150 owl_global_set_buffercommand(&g, buff); 2117 owl_function_start_password(" Password: ");2151 owl_function_start_password("AIM Password: "); 2118 2152 return(NULL); 2119 2153 } -
examples/owlconf.erik
r039213e rf1e629d 1 1 ### The owlconf config file -*- perl -*- 2 2 ### $Id$ 3 3 ### 4 4 ### !!!!!WARNING!!!!! !!!!!WARNING!!!!! !!!!!WARNING!!!!! !!!!!WARNING!!!!! 5 5 ### This is an example file intended to demonstrate how to use … … 9 9 ### Don't blame me if anything in here ends up vaporizing your dog. 10 10 ### !!!!!WARNING!!!!! !!!!!WARNING!!!!! !!!!!WARNING!!!!! !!!!!WARNING!!!!! 11 11 ### 12 12 ### 13 13 ### This file is interpreted by the perl interpreter. … … 24 24 ### owl::startup() run when owl first starts 25 25 ### 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 29 27 ### owl::receive_msg() run when a message is received, and after 30 28 ### it has been added to the message list 31 29 ### 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 ### 38 33 ### 39 34 … … 46 41 my @sepbartokens = (); 47 42 43 # Map for mail messages from msg id to pop msg id 44 my %mail_id_map = (); 45 46 # (originally from jdaniel) 47 sub 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 57 sub 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 67 sub zlocatesender { 68 my $m = owl::getcurmsg(); 69 if ($m->{"type"} eq "zephyr") { 70 my $sender = $m->{"sender"}; 71 owl::command("zlocate $sender"); 72 } 73 } 48 74 49 75 # adds a sepbartoken and also updates the appendtosepbar variable … … 63 89 } 64 90 91 my $loopctr=0; 92 65 93 # trims a sepbartoken from the list also updates the appendtosepbar variable 66 94 sub 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)); 68 96 } 69 97 … … 73 101 if ($restoreview) { 74 102 owl::command("view $restoreview"); 75 76 } else { 77 78 103 $restoreview = undef; 104 } else { 105 $restoreview = $curview; 106 owl::command("smartnarrow"); 79 107 } 80 108 } … … 91 119 } else { 92 120 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... 127 sub 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; 94 135 } 95 136 } 96 137 97 138 sub 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"); 100 143 owl::command("set -q startuplogin off"); 101 144 owl::command("set -q shutdownlogout off"); 102 145 #owl::command("set personalbell on"); 146 owl::command("set -q _burningears on"); 103 147 owl::command("set -q rxping on"); 104 148 owl::command("set -q typewinsize 5"); 105 if ($ENV{"DISPLAY"} eq ":0 ") {149 if ($ENV{"DISPLAY"} eq ":0.0") { 106 150 owl::command("set -q webbrowser galeon"); 107 151 } 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"); 111 157 112 158 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 123 190 owl::command("bindkey recv M-k command ( smartnarrow ; delete view )"); 124 191 owl::command("bindkey recv M-l command ( expunge ; view all )"); 125 192 owl::command("bindkey recv M-K command ( smartnarrow ; delete view ; expunge ; view all )"); 126 193 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(); 141 204 } 142 205 … … 145 208 } 146 209 210 211 # run when a message is received, and after 212 # it has been added to the message list. 213 sub 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 252 sub indent4 { 253 my ($b) = @_; 254 $b=~s/^/ /g; 255 $b=~s/\n/\n /g; 256 return $b; 257 } 258 147 259 # 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") { 260 sub 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) { 158 275 $out="\@bold(LOGIN)"; 159 } elsif ( uc($owl::opcode) eq "USER_LOGOUT") {276 } elsif ($m->is_logout) { 160 277 $out="\@bold(LOGOUT)"; 161 278 } else { 162 279 $out="\@bold(UNKNOWN)"; 163 280 } 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 } 165 285 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) { 167 306 $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 345 sub format_msg_debug { 346 my ($m) = @_; 347 return "\@bold(-------------MESSAGE-------------)\n".($m->serialize).".\n"; 348 } 349 350 sub 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 359 sub 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 "; } 171 415 return($out."\n"); 172 416 } 173 417 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 195 446 196 447 # make personal messages bold 197 if (uc($owl::class) eq "MESSAGE" && 198 uc($owl::instance) eq "PERSONAL") { 448 if ($m->is_personal) { 199 449 $out="\@bold{".$out."}"; 200 450 } 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 454 sub 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 78 78 } 79 79 80 void 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 94 char *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 } 80 108 81 109 char *owl_function_cmd_describe(void *name) … … 741 769 742 770 /* execute the commands in shutdown */ 743 ret = owl_ config_execute("owl::shutdown();");771 ret = owl_perlconfig_execute("owl::shutdown();"); 744 772 if (ret) owl_free(ret); 745 773 … … 2051 2079 buff = skiptokens(buff, 1); 2052 2080 2053 perlout = owl_ config_execute(buff);2081 perlout = owl_perlconfig_execute(buff); 2054 2082 if (perlout) { 2055 2083 if (type==1) { -
global.c
ra352335c rf1e629d 53 53 owl_list_create(&(g->puntlist)); 54 54 owl_list_create(&(g->messagequeue)); 55 owl_ list_create(&(g->stylelist));55 owl_dict_create(&(g->styledict)); 56 56 g->curmsg_vert_offset=0; 57 57 g->resizepending=0; … … 390 390 _owl_global_setup_windows(g); 391 391 392 /* in case any styles rely on the current width */ 393 owl_messagelist_invalidate_formats(owl_global_get_msglist(g)); 394 392 395 /* refresh stuff */ 393 396 g->needrefresh=1; … … 774 777 owl_style *owl_global_get_style_by_name(owl_global *g, char *name) 775 778 { 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. */ 784 int owl_global_get_style_names(owl_global *g, owl_list *l) { 785 return owl_dict_get_keys(&(g->styledict), l); 787 786 } 788 787 789 788 void owl_global_add_style(owl_global *g, owl_style *s) 790 789 { 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); 792 792 } 793 793 -
message.c
r9ceee9d rf1e629d 574 574 } 575 575 576 char *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 599 char *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 612 char *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 622 char *owl_message_get_header(owl_message *m) { 623 return owl_message_get_attribute_value(m, "adminheader"); 624 } 625 576 626 /* return 1 if the message contains "string", 0 otherwise. This is 577 627 * case insensitive because the functions it uses are … … 798 848 owl_fmtext_free(&(m->fmtext)); 799 849 } 850 851 -
owl.c
ra352335c rf1e629d 33 33 int newmsgs, zpendcount, nexttimediff; 34 34 struct sigaction sigact; 35 char *configfile, *tty, *perlout, * *argvsave, buff[LINE], startupmsg[LINE];35 char *configfile, *tty, *perlout, *perlerr, **argvsave, buff[LINE], startupmsg[LINE]; 36 36 owl_filter *f; 37 37 owl_style *s; … … 152 152 /* setup the built-in styles */ 153 153 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"); 155 156 owl_global_add_style(&g, s); 156 157 157 158 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."); 159 161 owl_global_add_style(&g, s); 160 162 161 163 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"); 163 166 owl_global_add_style(&g, s); 164 167 … … 224 227 /* read the config file */ 225 228 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) { 228 231 endwin(); 229 printf("\nError parsing configfile\n");232 fprintf(stderr, "\nError parsing configfile: %s\n", perlerr); 230 233 exit(1); 231 234 } … … 235 238 owl_function_debugmsg("Found perl formatting"); 236 239 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"); 238 243 owl_global_add_style(&g, s); 239 244 owl_global_set_default_style(&g, "perl"); 240 245 } 241 246 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 242 257 /* execute the startup function in the configfile */ 243 perlout = owl_ config_execute("owl::startup();");258 perlout = owl_perlconfig_execute("owl::startup();"); 244 259 if (perlout) owl_free(perlout); 245 260 owl_function_debugmsg("-- Owl Startup --"); … … 273 288 } 274 289 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))); 287 292 288 293 /* welcome message */ 289 294 strcpy(startupmsg, "-------------------------------------------------------------------------\n"); 290 sprintf(buff, "Welcome to Owl version %s. Press 'h' for on 295 sprintf(buff, "Welcome to Owl version %s. Press 'h' for on-line help. \n", OWL_VERSION_STRING); 291 296 strcat(startupmsg, buff); 292 297 strcat(startupmsg, " \n"); … … 395 400 396 401 /* 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); 398 403 399 404 /* add it to any necessary views; right now there's only the current view */ -
owl.h
r6873455 rf1e629d 21 21 static const char owl_h_fileIdent[] = "$Id$"; 22 22 23 #define OWL_VERSION 2.0.8-pre- 124 #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" 25 25 26 26 #define OWL_DEBUG 0 … … 274 274 typedef struct _owl_style { 275 275 char *name; 276 char *description; 276 277 int type; 277 278 char *perlfuncname; … … 451 452 owl_buddylist buddylist; /* list of logged in AIM buddies */ 452 453 owl_list messagequeue; /* for queueing up aim and other messages */ 453 owl_ list stylelist; /* global listof available styles */454 owl_dict styledict; /* global dictionary of available styles */ 454 455 char *response; /* response to the last question asked */ 455 456 int havezephyr; -
perlglue.xs
r1fd0b25 rf1e629d 1 1 static const char fileIdent[] = "$Id$"; 2 2 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> 6 7 7 8 /* 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 *); 9 extern char *owl_function_command(char *cmd); 10 extern void owl_free(void *x); 11 extern SV *owl_perlconfig_curmessage2hashref(); 10 12 extern int owl_zwrite_create_and_send_from_line(char *, char *); 11 13 extern char *owl_function_ztext_stylestrip(char *); 14 extern void g; 15 extern int owl_global_get_cols(void*); 12 16 13 17 MODULE = owl PACKAGE = owl … … 26 30 if (rv) owl_free(rv); 27 31 32 SV * 33 getcurmsg() 34 CODE: 35 ST(0) = owl_perlconfig_curmessage2hashref(); 36 37 int 38 getnumcols() 39 CODE: 40 RETVAL = owl_global_get_cols(&g); 41 OUTPUT: 42 RETVAL 43 44 char * 45 zephyr_getrealm() 46 CODE: 47 RETVAL = ZGetRealm(); 48 OUTPUT: 49 RETVAL 50 51 char * 52 zephyr_getsender() 53 CODE: 54 RETVAL = ZGetSender(); 55 OUTPUT: 56 RETVAL 57 28 58 void 29 send_zwrite(cmd,msg)59 zephyr_zwrite(cmd,msg) 30 60 char *cmd 31 61 char *msg -
style.c
ref56a67 rf1e629d 3 3 static const char fileIdent[] = "$Id$"; 4 4 5 void owl_style_create_internal(owl_style *s, char *name, void (*formatfunc) (owl_fmtext *fm, owl_message *m) )5 void owl_style_create_internal(owl_style *s, char *name, void (*formatfunc) (owl_fmtext *fm, owl_message *m), char *description) 6 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 } 9 14 s->perlfuncname=NULL; 10 15 s->formatfunc=formatfunc; 11 16 } 12 17 13 void owl_style_create_perl(owl_style *s, char *name, char *perlfuncname )18 void owl_style_create_perl(owl_style *s, char *name, char *perlfuncname, char *description) 14 19 { 15 20 s->type=OWL_STYLE_TYPE_PERL; 16 21 s->name=owl_strdup(name); 17 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 } 18 29 s->formatfunc=NULL; 19 30 } … … 30 41 } 31 42 43 char *owl_style_get_description(owl_style *s) 44 { 45 return(s->description); 46 } 47 32 48 /* Use style 's' to format message 'm' into fmtext 'fm'. 33 49 * 'fm' should already be be initialzed … … 41 57 42 58 /* run the perl function */ 43 body=owl_ config_getmsg(m, s->perlfuncname);59 body=owl_perlconfig_getmsg(m, 1, s->perlfuncname); 44 60 45 61 /* indent */ … … 55 71 } 56 72 73 int 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 57 87 void owl_style_free(owl_style *s) 58 88 { 59 89 if (s->name) owl_free(s->name); 90 if (s->description) owl_free(s->description); 60 91 if (s->type==OWL_STYLE_TYPE_PERL && s->perlfuncname) { 61 92 owl_free(s->perlfuncname); -
util.c
r3ba3af0 rf1e629d 283 283 char *owl_util_minutes_to_timestr(int in) 284 284 { 285 int days, minutes,hours;285 int days, hours; 286 286 long run; 287 287 char *out; -
variable.c
r09489b89 rf1e629d 204 204 OWLVAR_STRING( "default_style" /* %OwlVarStub */, "default", 205 205 "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 209 216 210 217 OWLVAR_INT( "edit:maxfillcols" /* %OwlVarStub:edit_maxfillcols */, 70, … … 356 363 owl_zephyr_set_locationinfo(owl_global_get_hostname(&g), newval); 357 364 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);377 365 } 378 366 -
view.c
ref56a67 rf1e629d 67 67 { 68 68 return(v->style); 69 } 70 71 char *owl_view_get_style_name(owl_view *v) { 72 return(owl_style_get_name(v->style)); 69 73 } 70 74 -
zephyr.c
re6449bc rf1e629d 731 731 #endif 732 732 733 734 733 /* returns a buffer of subscriptions or an error message. 735 734 * Caller must free the return.
Note: See TracChangeset
for help on using the changeset viewer.