Changeset b6c067a
- Timestamp:
- Feb 16, 2007, 1:37:44 AM (18 years ago)
- Branches:
- master, barnowl_perlaim, debian, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- 6e6ded7
- Parents:
- 3f21b8e
- git-author:
- Nelson Elhage <nelhage@mit.edu> (02/15/07 23:16:22)
- git-committer:
- Nelson Elhage <nelhage@mit.edu> (02/16/07 01:37:44)
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
owl.c
r687c674 rb6c067a 227 227 } 228 228 229 /* Initialize perl */ 230 owl_function_debugmsg("startup: processing config file"); 231 owl_context_set_readconfig(owl_global_get_context(&g)); 232 perlerr=owl_perlconfig_initperl(configfile); 233 if (perlerr) { 234 endwin(); 235 owl_function_error("Internal perl error: %s\n", perlerr); 236 fprintf(stderr, "Internal perl error: %s\n", perlerr); 237 fflush(stderr); 238 printf("Internal perl error: %s\n", perlerr); 239 fflush(stdout); 240 exit(1); 241 } 242 229 243 /* setup the built-in styles */ 230 244 owl_function_debugmsg("startup: creating built-in styles"); 231 s=owl_malloc(sizeof(owl_style));232 owl_style_create_internal(s, "default", &owl_stylefunc_default, "Default message formatting");233 owl_global_add_style(&g, s);234 245 235 246 s=owl_malloc(sizeof(owl_style)); … … 304 315 owl_function_debugmsg("startup: doing AIM initialization"); 305 316 owl_aim_init(); 306 307 /* read the config file */308 owl_function_debugmsg("startup: processing config file");309 owl_context_set_readconfig(owl_global_get_context(&g));310 perlerr=owl_perlconfig_readconfig(configfile);311 if (perlerr) {312 endwin();313 owl_function_error("Error parsing configfile: %s\n", perlerr);314 fprintf(stderr, "\nError parsing configfile: %s\n", perlerr);315 fflush(stderr);316 printf("\nError parsing configfile: %s\n", perlerr);317 fflush(stdout);318 exit(1);319 }320 317 321 318 /* if the config defines a formatting function, add 'perl' as a style */ -
perlconfig.c
r8fba2ee rb6c067a 270 270 271 271 272 char *owl_perlconfig_ readconfig(char * file)272 char *owl_perlconfig_initperl(char * file) 273 273 { 274 274 int ret; … … 276 276 char *err; 277 277 char *args[4] = {"", "-e", "0;", NULL}; 278 279 278 280 279 /* create and initialize interpreter */ -
perlglue.xs
r0ff2528 rb6c067a 246 246 owl_function_error("%s", text); 247 247 } 248 249 void 250 _create_style(name, function, description) 251 char *name 252 char *function 253 char *description 254 PREINIT: 255 /* This is to allow us to bootstrap the default style before the 256 command architecture has been initialized */ 257 owl_style *s; 258 CODE: 259 { 260 s = owl_malloc(sizeof(owl_style)); 261 owl_style_create_perl(s, name, function, description); 262 owl_global_add_style(&g, s); 263 } -
perlwrap.pm
r16138b0 rb6c067a 5 5 ##################################################################### 6 6 ##################################################################### 7 # XXX NOTE: This file is sourced before almost any barnowl 8 # 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 7 12 8 13 use strict; … … 293 298 ##################################################################### 294 299 ################################################################################ 295 package owl;300 package BarnOwl; 296 301 297 302 ################################################################################ … … 326 331 BarnOwl::mainloop_hook() if *BarnOwl::mainloop_hook{CODE}; 327 332 } 328 333 329 334 @BarnOwl::Hooks::onMainLoop = (); 330 335 @BarnOwl::Hooks::onStartSubs = (); … … 335 340 undef $@; 336 341 do $BarnOwl::configfile; 337 owl::error("Error reloading $BarnOwl::configfile: $@") if $@;342 BarnOwl::error("Error reloading $BarnOwl::configfile: $@") if $@; 338 343 } 339 344 BarnOwl::reload_hook(@_); 340 package owl;345 package BarnOwl; 341 346 } 342 347 … … 372 377 } 373 378 379 sub _load_owlconf { 380 # Only do this the first time 381 return if $BarnOwl::reload; 382 # load the config file 383 if ( -r $BarnOwl::configfile ) { 384 undef $@; 385 do $BarnOwl::configfile; 386 die $@ if $@; 387 } 388 } 389 390 push @BarnOwl::Hooks::onStartSubs, \&_load_owlconf; 391 374 392 package BarnOwl::Hooks; 375 393 … … 453 471 return runHook_accumulate(\@onGetBuddyList); 454 472 } 473 474 ################################################################################ 475 # Built-in perl styles 476 ################################################################################ 477 package BarnOwl::Style::Default; 478 ################################################################################ 479 # Branching point for various formatting functions in this style. 480 ################################################################################ 481 sub format_message($) 482 { 483 my $m = shift; 484 485 if ( $m->is_zephyr ) { 486 return format_zephyr($m); 487 } 488 elsif ( $m->is_admin ) { 489 return "\@bold(OWL ADMIN)\n" . indentBody($m); 490 } 491 elsif ( $m->is_aim ) { 492 return format_aim($m); 493 } 494 elsif ( lc( $m->type ) eq 'loopback' ) { 495 return format_loopback($m); 496 } 497 else { 498 return "Unexpected message type."; 499 } 500 } 501 502 BarnOwl::_create_style("default", "BarnOwl::Style::Default::format_message", "Default style"); 503 504 ################################################################################ 505 sub format_zephyr($) 506 { 507 my $m = shift; 508 509 # Extract time from message 510 my ($time) = $m->time =~ /(\d\d:\d\d)/; 511 512 # Deal with PING messages, assuming owl's rxping variable is true. 513 if ( $m->is_ping && $m->recipient ne "" ) { 514 return ( "\@b(PING) from \@b(" . $m->pretty_sender . ")\n" ); 515 } 516 517 # Deal with login/logout messages 518 elsif ( $m->is_loginout ) { 519 return sprintf( 520 '@b<%s%s> for @b(%s) at %s %s %s', 521 uc( $m->login ), 522 523 # This is a hack, owl does not export "pseudo"-ness 524 ( $m->zsig ) ? "" : " (PSEUDO)", 525 $m->pretty_sender, 526 lc( $m->host ), 527 $m->login_tty, 528 $time 529 ); 530 } 531 532 # Deal with outbound zephyrs (personal, we don't see outbound non-personal) 533 elsif ( lc( $m->direction ) eq 'out' ) { 534 my $user = $m->recipient; 535 $user =~ s/\@ATHENA[.]MIT[.]EDU$//; 536 537 my $zsig = $m->zsig; 538 $zsig =~ s/\n.*$//s; 539 540 return sprintf( "Zephyr sent to %s %s (Zsig: %s)\n%s", 541 $user, $time, $zsig, indentBody($m) ); 542 } 543 544 # Deal with everything else 545 else { 546 my $zsig = $m->zsig; 547 $zsig =~ s/\n.*$//s; 548 549 my $msg = sprintf( 550 "%s / %s / \@b<%s>%s %s (%s)\n%s", 551 $m->class, $m->instance, $m->pretty_sender, 552 ( $m->opcode ? " [@{[$m->opcode]}]" : "" ), 553 $time, $zsig, indentBody($m) 554 ); 555 return BarnOwl::Style::boldify($msg) if ( $m->is_private ); 556 return $msg; 557 } 558 } 559 560 561 sub format_aim($) 562 { 563 my $m = shift; 564 565 # Extract time from message 566 my ($time) = $m->time =~ /(\d\d:\d\d)/; 567 568 # Deal with login/logout messages 569 if ( $m->is_loginout ) { 570 return 571 sprintf( "\@b(AIM %s) for %s %s", 572 uc( $m->login ), 573 $m->sender, 574 $time ); 575 } 576 elsif ( lc( $m->direction ) eq 'out' ) { 577 return sprintf( "AIM sent to %s %s\n%s", 578 $m->recipient, 579 $time, 580 indentBody($m) ); 581 } 582 else { 583 return sprintf( "\@b(AIM from %s) %s\n%s", 584 $m->sender, 585 $time, 586 BarnOwl::Style::boldify( indentBody($m) ) ); 587 } 588 } 589 590 591 sub format_loopback($) 592 { 593 my $m = shift; 594 595 # Extract time from message 596 my ($time) = $m->time =~ /(\d\d:\d\d)/; 597 598 return sprintf( "loopback from: %s to: %s %s\n%s", 599 $m->sender, $m->recipient, $time, indentBody($m) ); 600 } 601 602 603 sub indentBody($) 604 { 605 my $m = shift; 606 607 my $body = $m->body; 608 # replace newline followed by anything with 609 # newline plus four spaces and that thing. 610 $body =~ s/\n(.)/\n $1/g; 611 612 return " ".$body; 613 } 614 615 616 package BarnOwl::Style; 617 618 # This takes a zephyr to be displayed and modifies it to be displayed 619 # entirely in bold. 620 sub boldify($) 621 { 622 local $_ = shift; 623 if ( !(/\)/) ) { 624 return '@b(' . $_ . ')'; 625 } elsif ( !(/\>/) ) { 626 return '@b<' . $_ . '>'; 627 } elsif ( !(/\}/) ) { 628 return '@b{' . $_ . '}'; 629 } elsif ( !(/\]/) ) { 630 return '@b[' . $_ . ']'; 631 } else { 632 my $txt = "\@b($_"; 633 $txt =~ s/\)/\)\@b\[\)\]\@b\(/g; 634 return $txt . ')'; 635 } 636 } 637 455 638 456 639 # switch to package main when we're done … … 468 651 } 469 652 470 # load the config file471 if (-r $BarnOwl::configfile) {472 undef $@;473 do $BarnOwl::configfile;474 die $@ if $@;475 }476 477 653 1;
Note: See TracChangeset
for help on using the changeset viewer.