summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorMatt Simmons <simmonmt@acm.org>1997-10-06 00:55:25 +0000
committerMatt Simmons <simmonmt@acm.org>1997-10-06 00:55:25 +0000
commitdbf027caad002695361f8a16f6a87eafef9639fa (patch)
tree774d4ff2d682478f1c87c1481779caccff11b7ed /utils
parentb5987e01dcb658a505a59c721ffff141cd2190eb (diff)
Initial revision
Diffstat (limited to 'utils')
-rw-r--r--utils/bbdb-213-310.el57
-rw-r--r--utils/bbdb-415-510.el87
-rwxr-xr-xutils/bbdb-areacode-split.pl62
-rwxr-xr-xutils/bbdb-cid.pl516
-rwxr-xr-xutils/bbdb-srv.pl45
-rw-r--r--utils/bbdb-to-netscape.el213
-rwxr-xr-xutils/bbdb-unlazy-lock.pl19
7 files changed, 999 insertions, 0 deletions
diff --git a/utils/bbdb-213-310.el b/utils/bbdb-213-310.el
new file mode 100644
index 0000000..5a791a5
--- /dev/null
+++ b/utils/bbdb-213-310.el
@@ -0,0 +1,57 @@
+;;; -*- Mode:Emacs-Lisp -*-
+
+;;; The 213 area code (in LA) has been split into 213 and 310. This code
+;;; will map over your Insidious Big Brother Database and convert the area
+;;; codes when approriate. It then displays the records which it has changed.
+;;;
+;;; This is derived from a list posted by Paul Eggert <eggert@twinsun.com>
+;;; on 3 Mar 92 18:24:04 GMT.
+
+(require 'bbdb)
+
+(defconst bbdb-310-exchanges
+ '(201 202 203 204 205 206 207 208 209 210 212 214 215 216 217 218 219 220
+ 246 247 270 271 273 274 275 276 277 278 279 280 281 282 284 285 286 287
+ 288 289 297 301 302 305 306 312 313 314 315 316 317 318 319 320 322 323
+ 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 348 350 352
+ 354 355 363 364 370 371 372 373 374 375 376 377 378 379 390 391 392 393
+ 394 395 396 397 398 399 401 402 403 404 406 407 408 409 410 412 414 416
+ 417 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435
+ 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
+ 454 455 456 457 458 459 470 471 472 473 474 475 476 477 478 479 490 491
+ 492 493 494 495 496 497 498 499 501 502 510 512 513 514 515 516 517 518
+ 519 521 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
+ 540 541 542 543 544 545 546 547 548 549 550 551 552 553 556 557 558 559
+ 568 570 571 572 573 574 575 576 577 578 590 591 592 593 594 595 596 597
+ 598 599 601 602 603 604 605 606 607 608 609 615 616 618 630 631 632 633
+ 634 635 637 638 639 640 641 642 643 644 645 646 647 648 649 652 657 659
+ 670 671 672 673 674 675 676 677 679 690 691 692 693 694 695 696 697 698
+ 699 708 715 719 761 762 763 764 767 768 769 781 782 783 784 785 787 788
+ 791 792 793 794 795 796 797 798 799 800 801 802 803 804 806 807 809 812
+ 813 814 815 816 819 820 821 822 823 824 825 826 827 828 829 830 831 832
+ 833 834 835 836 837 838 839 840 841 842 843 854 855 858 859 860 861 862
+ 863 864 865 866 867 868 869 885 886 898 899 902 903 904 905 906 907 908
+ 914 915 916 917 918 920 921 922 923 924 925 926 927 928 929 940 941 942
+ 943 944 945 946 947 948 949 967 970 973 978 980 981 982 983 984 985 986
+ 987 988 989)
+ "Those exchanges which have moved from the 213 area code to the new 310.")
+
+(defun bbdb-convert-213-to-310 ()
+ "Convert phone numbers in the BBDB which are in the 213 area code to the
+newly-created 310 area code if appropriate."
+ (let ((records (bbdb-records))
+ phones frobbed change-p)
+ (while records
+ (setq phones (bbdb-record-phones (car records))
+ change-p nil)
+ (while phones
+ (if (and (= (bbdb-phone-area (car phones)) 213)
+ (memq (bbdb-phone-exchange (car phones)) bbdb-310-exchanges))
+ (setq change-p (bbdb-phone-set-area (car phones) 310)))
+ (setq phones (cdr phones)))
+ (if change-p
+ (progn
+ (setq frobbed (cons (car records) frobbed))
+ (bbdb-change-record (car records) nil)))
+ (setq records (cdr records)))
+ (bbdb-display-records frobbed)))
diff --git a/utils/bbdb-415-510.el b/utils/bbdb-415-510.el
new file mode 100644
index 0000000..2870151
--- /dev/null
+++ b/utils/bbdb-415-510.el
@@ -0,0 +1,87 @@
+;;; -*- Mode:Emacs-Lisp -*-
+
+;;; The San Francisco Bay Area, which was formerly area code 415, has been
+;;; split into two area codes: 415 for the west side of the bay, and 510
+;;; for the east side. This code will map over your Insidious Big Brother
+;;; Database and convert the area codes when approriate. It then displays
+;;; the records which it has changed.
+
+(require 'bbdb)
+
+(defconst bbdb-415-exchanges
+ '(206 219 221 227 239 241 243 244 252 255 257 258 259 266 267 282 285 289
+ 291 292 296 306 307 312 321 322 323 324 325 326 327 328 329 330 331 332
+ 333 334 335 336 337 338 340 341 342 343 344 345 346 347 348 349 354 355
+ 358 359 361 362 363 364 365 366 367 368 369 371 375 377 378 381 382 383
+ 386 387 388 389 391 392 393 394 395 396 397 398 399 403 404 406 421 424
+ 431 432 433 434 435 441 442 445 449 453 454 456 457 459 461 464 465 466
+ 467 468 469 472 473 474 476 477 478 479 485 488 491 492 493 494 495 496
+ 497 499 502 506 507 508 512 513 541 542 543 544 545 546 550 552 553 554
+ 556 557 558 561 563 564 565 566 567 570 571 572 573 574 576 578 579 583
+ 584 585 586 587 588 589 591 592 593 594 595 597 599 604 610 616 617 621
+ 622 626 627 637 641 647 648 661 662 663 664 665 666 668 669 673 677 681
+ 688 691 692 694 695 696 697 701 703 705 715 721 723 725 726 728 731 737
+ 738 739 742 744 747 749 750 751 752 753 755 756 759 761 764 765 768 771
+ 772 773 774 775 776 777 780 781 788 789 804 806 807 813 821 822 824 826
+ 851 852 853 854 855 856 857 858 859 861 863 864 868 871 872 873 875 876
+ 877 878 879 882 883 885 892 894 896 897 898 903 904 905 912 917 921 922
+ 923 924 925 926 927 928 929 931 940 941 948 949 951 952 953 954 955 956
+ 957 960 961 962 964 965 966 967 968 969 972 973 974 978 979 981 982 983
+ 984 985 986 989 991 992 993 994 995 997 998)
+ "Those exchanges which are still in the 415 area code.")
+
+(defconst bbdb-510-exchanges
+ '(204 208 210 215 222 223 224 226 228 229 231 232 233 234 235 236 237 238
+ 245 246 248 251 253 254 256 261 262 263 268 271 272 273 275 276 277 278
+ 283 284 287 293 294 295 297 302 308 313 317 339 351 352 356 357 370 372
+ 373 374 376 420 422 423 425 426 427 428 429 430 436 437 438 439 443 444
+ 446 447 448 451 452 455 458 460 462 463 471 475 481 482 483 484 486 487
+ 489 490 498 515 516 521 522 523 524 525 526 527 528 529 530 531 532 533
+ 534 535 536 537 538 539 540 547 548 549 551 559 562 568 569 577 581 582
+ 596 598 601 602 603 606 609 613 614 618 620 623 624 625 631 632 633 634
+ 635 636 638 639 642 643 644 645 646 649 651 652 653 654 655 656 657 658
+ 659 667 670 671 672 674 675 676 678 680 682 683 684 685 686 687 689 704
+ 706 708 709 713 716 717 718 724 727 729 732 733 734 735 736 741 743 745
+ 746 748 754 757 758 762 763 769 778 779 782 783 784 785 786 787 790 791
+ 792 793 794 795 796 797 798 799 801 803 810 814 815 819 820 823 825 827
+ 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 845 846
+ 847 848 849 862 865 866 867 869 874 881 884 886 887 888 889 891 893 895
+ 901 910 930 932 933 934 935 937 938 939 942 943 944 945 946 947 975 977
+ 987)
+ "Those exchanges which have moved from the 415 area code to the new 510.")
+
+
+(defsubst bbdb-convert-415-to-510-internal (phone)
+ (cond ((memq (bbdb-phone-exchange phone) bbdb-510-exchanges)
+ (if (= (bbdb-phone-area phone) 510)
+ nil
+ (bbdb-phone-set-area phone 510)))
+ ((memq (bbdb-phone-exchange phone) bbdb-415-exchanges)
+ (if (= (bbdb-phone-area phone) 415)
+ nil
+ (bbdb-phone-set-area phone 415)))
+ (t (error "Exchange %03d is not in the 415 or 510 area codes: %s"
+ (bbdb-phone-exchange phone)
+ (bbdb-phone-string phone)))))
+
+
+(defun bbdb-convert-415-to-510 ()
+ "Convert phone numbers in the BBDB which are in the 415 area code to the
+newly-created 510 area code if appropriate."
+ (let ((records (bbdb-records))
+ phones frobbed change-p)
+ (while records
+ (setq phones (bbdb-record-phones (car records))
+ change-p nil)
+ (while phones
+ (if (memq (bbdb-phone-area (car phones)) '(415 510))
+ (setq change-p
+ (or (bbdb-convert-415-to-510-internal (car phones))
+ change-p)))
+ (setq phones (cdr phones)))
+ (if change-p
+ (progn
+ (setq frobbed (cons (car records) frobbed))
+ (bbdb-change-record (car records) nil)))
+ (setq records (cdr records)))
+ (bbdb-display-records frobbed)))
diff --git a/utils/bbdb-areacode-split.pl b/utils/bbdb-areacode-split.pl
new file mode 100755
index 0000000..b77e65f
--- /dev/null
+++ b/utils/bbdb-areacode-split.pl
@@ -0,0 +1,62 @@
+#!/usr/bin/perl
+#
+# Looks for phone numbers in your .bbdb with a particular area code
+# and one of a set of exchanges and changes the area code. The old
+# and new area codes are specified on the command line, as is the
+# location of a file that contains the exchanges that are being
+# changed. (The format of that file is very loose. Every three digit
+# sequence will be used.)
+#
+# Seth Golub <seth@cs.wustl.edu>
+# 15 Aug 1997
+
+sub Usage
+{
+ $0 =~ s@.*/@@;
+ die "Usage: \n $0 <old-code> <new-code> <exchanges-file> [bbdb]\n";
+}
+
+$old_area_code = shift || Usage();
+$new_area_code = shift || Usage();
+$exchange_list_file = shift || Usage();
+
+$bbdb_file = $ENV{'BBDB'} || shift || $ENV{'HOME'} . '/.bbdb';
+$bbdb_dir = `dirname $bbdb_file`; chomp $bbdb_dir;
+$tmp_file = "$bbdb_dir/bbdb.new-$$";
+
+open( LIST, "<$exchange_list_file" )
+ || die "Failed to open $exchange_list_file\n";
+
+while (<LIST>)
+{
+ while ( /(\d\d\d)/g )
+ {
+ push( @exchanges, $1 );
+ }
+}
+
+close( LIST );
+
+$exchanges = join( '|', @exchanges );
+
+open( BBDB_IN, "<$bbdb_file" ) || die "Failed to open $bbdb_file\n";
+open( BBDB_OUT, ">$tmp_file" ) || die "Failed to open $tmp_file\n";
+
+while (<BBDB_IN>)
+{
+ next unless /^\[/;
+ s/(\[\".*?\") $old_area_code (($exchanges) \d+ \d+\])/$1 $new_area_code $2/og;
+} continue {
+ print BBDB_OUT;
+}
+
+close( BBDB_IN );
+close( BBDB_OUT );
+
+unlink( "$bbdb_file.bak" );
+rename( $bbdb_file, "$bbdb_file.bak" );
+rename( $tmp_file, $bbdb_file );
+
+print STDERR "Old bbdb moved to $bbdb_file.bak\n";
+
+__END__
diff --git a/utils/bbdb-cid.pl b/utils/bbdb-cid.pl
new file mode 100755
index 0000000..3bc4cde
--- /dev/null
+++ b/utils/bbdb-cid.pl
@@ -0,0 +1,516 @@
+#!/usr/local/bin/perl5 -w
+#
+# Caller-ID-logger, by jwz (19-Jan-97)
+# Modified: 24-Apr-97
+#
+# Opens the modem and waits for it to print caller-ID data. When it does,
+# it logs it to a file, parses it, and pops up a window using "xmessage".
+# If the number is present in your .bbdb file, it shows the name (or company)
+# associated with it.
+#
+# Todo:
+# My caller ID service (in San Francisco) only ever sends numbers, not names,
+# so I've never seen a "name" line come in; I assume that it would send both
+# a name and a number, so it would be nice to present both (with error
+# checking against BBDB) but the code as currently structured only handles
+# one-line-per-call. It should realize that consecutive lines with the same
+# timestamp are the same call.
+#
+# Modems other than ZyXELs have different caller-ID formats, and this doesn't
+# deal with those.
+
+##############################################################################
+#
+# Some variables you might want to set...
+
+
+# Set this to the device that your modem is attached to.
+#
+$modem_device = "/dev/ttyd1";
+
+# This is your .bbdb file. (Set it to null if you don't want to do BBDB
+# lookups at all, but why would you want to go and do a thing like that?)
+#
+$bbdb_file = "$ENV{HOME}/.bbdb";
+
+# A shell command to use to cause emacs to pop up the BBDB buffer
+# (bbdb-srv.pl is a good choice, so it defaults to the value of the
+# shell environment variable $NS_MSG_DISPLAY_HOOK.)
+#
+$bbdb_cmd = $ENV{NS_MSG_DISPLAY_HOOK};
+
+# If you want the $bbdb_cmd to be run on a different host, set it here.
+#
+$bbdb_host = "gimp";
+
+# If you want each call to be logged to a file as well, name it here.
+#
+$logfile = "/usr/spool/fax/log/cid-log";
+
+# For verbosity...
+$debug = 0;
+
+# How to pop up a dialog box.
+#
+$xmessage_cmd = "xmessage";
+@xmessage_args = ("-display", ":0",
+ "-name", "Caller ID",
+ # roughly centered on my screen; YMMV.
+ "-geometry", "+400+400",
+ "-xrm", "*Font: -*-new cent*-bold-r-normal-*-240-*",
+ "-xrm", "*Foreground: black",
+ "-xrm", "*Background: lightgreen",
+ # no buttons on the window: dismiss it by clicking in it.
+ "-button", "",
+ "-xrm", "*form.Translations: #override <BtnDown>: exit(0)",
+ "-xrm", "*Command.Font: -*-new cent*-bold-r-normal-*-120-*",
+ "-xrm", "*Command.horizDistance: 130"
+ );
+
+# Uh, let's turn off the screensaver before popping up the window.
+#
+$pre_dialog_cmd = "xscreensaver-command -deactivate";
+
+
+# commands (and their expected responses) used to initialize the modem.
+#
+@modem_init = ( "AT", "OK", # ping
+ "ATZ", "OK", # reset
+ "ATE0", "OK", # don't echo commands
+ "ATM0", "OK", # turn off speaker
+ "ATN0", "OK", # turn off ringer
+ "ATS40.2=1", "OK", # turn on caller ID
+ );
+
+
+# for diagnostics: if the modem ever asynchronously prints something that
+# doesn't match this, we issue a warning.
+#
+$expected_responses = "^CALLER NUMBER" . "|" .
+ "^REASON FOR NO CALLER " . "|" .
+ "^RING" . "|" .
+ "^TIME: [-0-9: ]+\$";
+
+
+##############################################################################
+#
+# Talking to the serial port...
+#
+#
+
+if ( $ debug ) {
+ use diagnostics;
+}
+
+
+sub open_modem {
+ use IPC::Open2;
+
+ # Close the terminal streams before forking `cu', because otherwise
+ # it fucks around with the stty settings.
+ #
+ open(SAVEIN, "<&STDIN") || die("can't dup stdin");
+ open(SAVEOUT, ">&STDOUT") || die("can't dup stdout");
+ open(SAVEERR, ">&STDERR") || die("can't dup stderr");
+ close(STDIN);
+ close(STDOUT);
+ close(STDERR);
+
+ my $cu_pid = open2( \*MODEM_IN, \*MODEM_OUT,
+ "cu -l$modem_device -s2400 2>&1");
+
+ # Now that cu has been launched, we can restore them.
+ #
+ open(STDIN, "<&SAVEIN") || die("can't restore stdin");
+ open(STDOUT, ">&SAVEOUT") || die("can't restore stdout");
+ open(STDERR, ">&SAVEERR") || die("can't restore stderr");
+ close(SAVEIN);
+ close(SAVEOUT);
+ close(SAVEERR);
+
+ # The following doesn't seem to work and I don't know why...
+ #
+ # Set up a signal handler to try and kill off the cu process
+ # when we exit, instead of waiting ~30 seconds for it to notice
+ # that the pipe is gone...
+ #
+# $SIG{INT} = sub { my $signame = shift;
+# if ( $debug) {
+# print STDERR "sending $signame to $cu_pid\n";
+# }
+# print MODEM_OUT "\r\n~.\r\n";
+# close MODEM_OUT;
+# close MODEM_IN;
+# kill ($signame, $cu_pid);
+# exit (1);
+# };
+
+ $_ = <MODEM_IN>;
+ chop;
+ if ( !m/^Connected/ ) {
+ print STDERR "$0: cu printed `$_' instead of `Connected'\n";
+ }
+}
+
+sub read_line {
+ $_ = <MODEM_IN>;
+ $_ || die("got eof on modem");
+ s/[\r\n]+$//;
+ if ( $_ eq "" ) {
+ $_ = <MODEM_IN>;
+ $_ || die("got eof on modem");
+ s/[\r\n]+$//;
+ }
+ return $_;
+}
+
+sub command {
+ my ( $command, $expected_response) = @_;
+
+ if ( $debug ) {
+ print STDERR "sending: $command\n";
+ }
+
+ print MODEM_OUT "$command\r\n";
+ my $line = read_line();
+
+ if ( $line eq $command ) {
+ if ( $debug ) {
+ print STDERR " got echo: reading next line too...\n";
+ }
+ $line = read_line();
+ }
+
+ if ( $line ne $expected_response ) {
+ print STDERR " got: $line ; expected: $expected_response\n";
+ } elsif ( $debug ) {
+ print STDERR " got: $line\n";
+ }
+}
+
+sub init_modem {
+ open_modem;
+
+ my $len = $#modem_init + 1;
+ my $i;
+ for ($i = 0; $i < $len; $i += 2) {
+ command($modem_init[$i], $modem_init[$i+1]);
+ }
+}
+
+sub handle_async_line {
+ local ( $_ ) = @_;
+
+ if (!m/$expected_responses/) {
+ print STDERR "modem turd: $_\n";
+
+ } elsif (m/CALLER/) {
+ if ( $debug ) {
+ print STDERR "caller: $_\n";
+ }
+ handle_cid_line($_);
+
+ } elsif ( $debug ) {
+ if ( $_ eq '' ) {
+ print STDERR "ignored: blank line\n";
+ } else {
+ print STDERR "ignored: $_\n";
+ }
+ }
+}
+
+
+##############################################################################
+#
+# Parsing BBDB and CID data...
+#
+
+sub find_bbdb_record {
+ my ( $area, $exchange, $suffix ) = @_;
+
+ if ( ! $bbdb_file ) {
+ return undef;
+ }
+
+ # strip off leading 0's, to match the way it's stored in .bbdb.
+ $area =~ s/^0+(.)/$1/;
+ $exchange =~ s/^0+(.)/$1/;
+ $suffix =~ s/^0+(.)/$1/;
+
+ my $bbdb_rec = undef;
+ my $pat = "\\[\"[^\"]+\" $area $exchange $suffix (nil|[0-9]+)\\]";
+
+ open(BBDB, "<$bbdb_file") || die("error opening $bbdb_file: $!\n");
+
+ while (<BBDB>) {
+ if ( m/$pat/ ) {
+ $bbdb_rec = $_;
+ last;
+ }
+ }
+ close(BBDB);
+ return $bbdb_rec;
+}
+
+
+# note: global (kludge!)
+$pretty_number = 0;
+
+sub make_message_string {
+ my ( $number, $date, $fn, $ln, $co, $error ) = @_;
+ my $msg;
+
+ my $line_prefix = " ";
+ my $line_suffix = " ";
+
+ # First print the date (reformatted.)
+ #
+ $_ = $date;
+ my ( $dotw, $mon, $day, $hr, $min, $sec, $year ) =
+ m/^([^ ]+) +([^ ]+) +([^ ]+) +([^:]+):([^:]+):([^:]+) +([^ ]+) *$/;
+ $year =~ s/^..(..)/$1/;
+ $day =~ s/^0//;
+ $hr =~ s/^0//;
+ if ($hr < 12) {
+ $ampm = "am";
+ } else {
+ $ampm = "pm";
+ if ($hr > 12) { $hr -= 12 };
+ }
+ $date = "$hr:$min$ampm, $day-$mon-$year ($dotw)";
+ $msg = $line_prefix . $date . $line_suffix;
+
+ # Next print the caller name, company, or error message.
+ #
+ if ( $error ) {
+ $msg .= "\n" . $line_prefix . $error . $line_suffix;
+ } elsif ( $co && !$fn && !$ln ) {
+ $msg .= "\n" . $line_prefix . $co . $line_suffix;
+ } elsif ( $fn || $ln ) {
+ $msg .= "\n" . $line_prefix . "$fn $ln" . $line_suffix;
+ }
+
+ # Next print the phone number (formatted nicely.)
+ #
+ if ( $number ) {
+ my $area = 0;
+ my $exchange = 0;
+ my $suffix = 0;
+ $_ = $number;
+ ( $area, $exchange, $suffix ) =
+ m/^([0-9][0-9][0-9])([0-9][0-9][0-9])([0-9][0-9][0-9][0-9]+)/;
+
+ # note: global (kludge!)
+ $pretty_number = "($area) $exchange-$suffix";
+ $msg .= "\n" . $line_prefix . $pretty_number . $line_suffix;
+ }
+
+ return $msg;
+}
+
+use POSIX;
+sub reaper {
+ $SIG{CHLD} = \&reaper; # loathe sysV
+ my $signame = shift;
+ if ( $debug >= 2 ) {
+ printf STDERR " (got SIG$signame...)\n";
+ }
+ my $child;
+ while ( ( $child = waitpid(-1,WNOHANG) ),
+ $child > 0 ) {
+ if ( $debug >= 2 ) {
+ printf STDERR " (pid $child exited with $?)\n";
+ }
+ }
+}
+
+sub fork_and_exec {
+ my @cmd_list = @_;
+
+ $SIG{CHLD} = \&reaper;
+
+ if ( $debug >= 2 ) {
+ $_ = $cmd_list[0];
+ s/ .*//;
+ print STDERR "forking for " . $_ . " at " . (localtime) . ".\n";
+ }
+
+ my $pid;
+ if ($pid = fork()) {
+ # parent
+ } elsif (!defined $pid) {
+ print STDERR "$0: fork failed: $!\n";
+ } else {
+ # child
+
+ if ( $debug ) {
+ $_ = $cmd_list[0];
+ s/ .*//;
+ print STDERR "exec'ing " . $_ . " at " . (localtime) .
+ " in pid $$.\n";
+ }
+ close(STDIN);
+ close(STDOUT);
+ close(STDERR);
+ exec @cmd_list;
+ }
+}
+
+
+sub fork_and_exec_for_bbdb {
+ my @cmd_list = @_;
+ my $number = shift @cmd_list;
+
+ $SIG{CHLD} = \&reaper;
+
+ if ( $debug >= 2 ) {
+ $_ = $cmd_list[0];
+ s/ .*//;
+ print STDERR "forking for " . $_ . " at " . (localtime) . ".\n";
+ }
+
+ my $pid;
+ if ($pid = fork()) {
+ # parent
+ } elsif (!defined $pid) {
+ print STDERR "$0: fork failed: $!\n";
+ exit (1);
+ } else {
+ # child
+
+ if ( $debug ) {
+ $_ = $cmd_list[0];
+ s/ .*//;
+ print STDERR "exec'ing " . $_ . " at " . (localtime) .
+ " in pid $$.\n";
+ }
+ if ( system @cmd_list ) {
+ my $cmd = "gnudoit -q '(bbdb-srv-add-phone \"$pretty_number\")'";
+ if ( $bbdb_host ) {
+ $cmd =~ s/([()\"])/\\$1/g;
+ $cmd = "rsh $bbdb_host $cmd";
+ }
+ exec $cmd;
+ }
+ exit (0);
+ }
+}
+
+
+sub pop_up_dialog {
+ my ( $msg, $buttonp, $number ) = @_;
+
+ fork_and_exec $pre_dialog_cmd;
+
+ if ( ! $buttonp ) {
+ fork_and_exec $xmessage_cmd, @xmessage_args, "\n$msg\n\n";
+ } else {
+ my @args = ( @xmessage_args, "-button", "Add To BBDB" );
+ fork_and_exec_for_bbdb $number, $xmessage_cmd, @args, "\n$msg\n\n";
+ }
+}
+
+sub pop_up_bbdb_buffer {
+ my ( $caller ) = @_;
+ if ( $bbdb_cmd ) {
+ my $cmd = $bbdb_cmd;
+ if ( $bbdb_host ) {
+ $cmd = "rsh $bbdb_host $cmd";
+ }
+ $caller =~ s/\\/\\\\/g;
+ $caller =~ s/\"/\\\\\"/g;
+ `echo "Path:\nFrom: \\\"$caller\\\" <>" | $cmd >&- 2>&- &`;
+ }
+}
+
+
+sub handle_cid_line {
+ my($line) = @_;
+
+ my $date = localtime;
+
+ # Log the call...
+ #
+ if ( $logfile ) {
+ if (open(LOG, ">>$logfile")) {
+ print LOG "$date\t$line\r\n";
+ close LOG;
+ } else {
+ print STDERR "error opening $logfile: $!\n";
+ }
+ }
+
+ # Pull the phone number out of the message...
+ #
+ my $number = "";
+ my $error = "";
+
+ $_ = $line;
+ if ( m/^CALLER NUMBER/ ) {
+ ( $number ) = m/^[^:]+: *(.*) *$/;
+ } else {
+ $error = $line;
+ }
+
+ my $caller = undef;
+
+ my $fn = undef;
+ my $ln = undef;
+ my $co = undef;
+ my $buttonp = 0;
+
+ if ( !$number || $number eq "" ) {
+ $error =~ tr#A-Z#a-z#;
+ $error =~ s/^REASON FOR NO CALLER (NUMBER|NAME)/Caller unknown/i;
+
+ } else {
+ $_ = $number;
+
+ my $area = 0;
+ my $exchange = 0;
+ my $suffix = 0;
+ ( $area, $exchange, $suffix ) =
+ m/^([0-9][0-9][0-9])([0-9][0-9][0-9])([0-9][0-9][0-9][0-9]+)/;
+
+ my $bbdb_rec = find_bbdb_record($area, $exchange, $suffix);
+
+ if ( $bbdb_rec ) {
+ my $junk = 0;
+ $_ = $bbdb_rec;
+ # This will lose if names or aliases have double-quotes in them.
+ # No doubt there's some hairier regexp magic that handles that...
+ ( $fn, $ln ) = m/^[\[]\"([^\"]*)\" *\"([^\"]*)\"/;
+ ( $junk, $junk, $junk, $co ) =
+ m/^[[](nil|\"[^\"]*\") *(nil|\"[^\"]*\") (nil|[(][^)]*[)]) \"([^\"]*)\"/;
+
+ if ( $fn || $ln ) {
+ $caller = "$fn $ln";
+ }
+ } else {
+ $buttonp = 1;
+ }
+ }
+
+ my $msg = make_message_string($number, $date, $fn, $ln, $co, $error);
+ pop_up_dialog($msg, $buttonp, $pretty_number);
+
+ if ( $caller ) {
+ pop_up_bbdb_buffer($caller);
+ }
+}
+
+
+##############################################################################
+#
+# hey ho. let's go.
+#
+sub main {
+ init_modem();
+ while (1) {
+ handle_async_line(read_line());
+ }
+ exit (1);
+}
+
+main();
+
diff --git a/utils/bbdb-srv.pl b/utils/bbdb-srv.pl
new file mode 100755
index 0000000..70bd011
--- /dev/null
+++ b/utils/bbdb-srv.pl
@@ -0,0 +1,45 @@
+#!/usr/local/bin/perl
+
+# This script reads a block of message headers on stdin, and converts them
+# to an emacs-lisp string (quoting all dangerous characters) and then
+# uses the `gnudoit' program to cause a running Emacs process to invoke
+# the `bbdb-srv' function with that string.
+#
+# This has the effect of causing the running Emacs to display the BBDB
+# record corresponding to these headers.
+#
+# See the Emacs side of things in bbdb-srv.el for more info.
+#
+# A trivial application of this is the shell command:
+#
+# echo 'From: Jamie Zawinski <jwz@netscape.com>' | bbdb-srv.perl
+#
+# which will cause the corresponding record to be displayed.
+# A more interesting application of this is:
+#
+# setenv NS_MSG_DISPLAY_HOOK bbdb-srv.perl
+#
+# which will hook BBDB up to Mozilla (Unix Netscape Mail and Netscape News
+# versions 3.0b2 and later only.)
+#
+# -- Jamie Zawinski <jwz@netscape.com>, 25-apr-96
+
+# spawn in the background and return to the caller immediately.
+if (fork == 0) { exit 0; }
+
+$str="(bbdb-srv \"";
+while(<>)
+{
+ # quote most shell metacharacters with backslash.
+ s/([\\"`$#^!])/\\\1/g;
+ # but quote ' as \047
+ s/'/\\047/g;
+ # and just for kicks, turn newlines into \n
+# s/\n/\\n/g;
+
+ $str = $str.$_;
+}
+$str=$str."\")";
+
+exec "gnudoit", "-q", $str;
+exit 0;
diff --git a/utils/bbdb-to-netscape.el b/utils/bbdb-to-netscape.el
new file mode 100644
index 0000000..cf7d5a4
--- /dev/null
+++ b/utils/bbdb-to-netscape.el
@@ -0,0 +1,213 @@
+;;; -*- Mode:Emacs-Lisp -*-
+
+;;; This file is the part of the Insidious Big Brother Database (aka BBDB),
+;;; copyright (c) 1991, 1992, 1993, 1995 Jamie Zawinski <jwz@lucid.com>.
+;;; Converting a BBDB database to a Netscape Address Book.
+;;; last change21-feb-97.
+
+;;; The Insidious Big Brother Database is free software; you can redistribute
+;;; it and/or modify it under the terms of the GNU General Public License as
+;;; published by the Free Software Foundation; either version 2, or (at your
+;;; option) any later version.
+;;;
+;;; BBDB is distributed in the hope that it will be useful, but WITHOUT ANY
+;;; WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+;;; FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+;;; details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Emacs; see the file COPYING. If not, write to
+;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+
+;;; This file attempts to convert a BBDB database to a Netscape Address Book
+;;; file. It doesn't work very well. If you fix it, let me know. -- jwz
+
+(require 'bbdb)
+
+(defun bbdb-mozilla-insert-url (string)
+ (let ((p (point))
+ c)
+ (insert string)
+ (goto-char (prog1 p (setq p (point))))
+ (while (progn
+ (skip-chars-forward "-a-zA-Z0-9.@/_\r\n" p)
+ (< (point) p))
+ (setq c (following-char))
+ (delete-char 1)
+ (insert (format "%%%02X" c))
+ (setq p (+ 2 p)))
+ (goto-char p)))
+
+(defun bbdb-mozilla-insert-html (string)
+ (let ((p (point))
+ c)
+ (insert string)
+ (goto-char (prog1 p (setq p (point))))
+ (while (progn
+ (skip-chars-forward "^&<>" p)
+ (< (point) p))
+ (setq c (following-char))
+ (delete-char 1)
+ (cond ((= c ?&) (insert "&amp;") (setq p (+ p 4)))
+ ((= c ?<) (insert "&lt;") (setq p (+ p 3)))
+ (t (insert "&gt;") (setq p (+ p 3)))))
+ (goto-char p)))
+
+(defun bbdb-mozilla-emit-record (record aliases)
+ (let (addr)
+ (cond ((setq addr (car (bbdb-record-net record)))
+ (insert " <DT><A HREF=\"mailto:")
+ (bbdb-mozilla-insert-url addr)
+ (insert "\"")
+ (let ((nick nil))
+ (cond (nick
+ (insert " NICKNAME=\"")
+ (bbdb-mozilla-insert-html nick)
+ (insert "\"")))
+ (insert ">"))
+ (let ((name (or (bbdb-record-name record)
+ (bbdb-record-company record)
+ "")))
+ (bbdb-mozilla-insert-html name))
+ (insert "</A>\n")
+ (let ((notes nil))
+ (cond (notes
+ )))
+ t)
+ (t nil))))
+
+(defun bbdb-to-netscape ()
+ (let* ((target (cons bbdb-define-all-aliases-field
+ "^[a-z, ]+$"))
+ (records1 (bbdb-search (bbdb-records)
+ nil ; name
+ nil ; company
+ nil ;"netscape\\.com" ; net
+ target ; notes
+ ))
+ (records records1)
+ result record aliases match
+ (lists nil)
+ (single-aliases nil)
+ (count 0)
+ )
+ (message "%d" (length records1))
+ (while records
+ (setq record (car records))
+ (setq aliases (bbdb-record-getprop record bbdb-define-all-aliases-field))
+ (setq aliases (and aliases (bbdb-split aliases ",")))
+ (while aliases
+ (if (setq match (assoc (car aliases) result))
+ (nconc match (cons record nil))
+ (setq result (cons (list (car aliases) record) result)))
+ (setq aliases (cdr aliases)))
+ (setq records (cdr records)))
+ (while result
+ (let ((alias (downcase (car (car result))))
+ (expansion (cdr (car result))))
+ (cond
+ ((cdr expansion)
+ (setq lists (cons (cons alias expansion) lists)))
+ (expansion
+ (setq single-aliases (cons (cons (car expansion) alias)
+ single-aliases))))
+ (setq result (cdr result))))
+
+; (setq records (bbdb-records))
+ (setq records records1)
+ (set-buffer (get-buffer-create "*netscape-address-book*"))
+ (erase-buffer)
+ (insert "<!DOCTYPE NETSCAPE-Addressbook-file-1>\n"
+ "<!-- This is an automatically generated file.\n"
+ "It will be read and overwritten.\n"
+ "Do Not Edit! -->\n"
+ "<TITLE>" (user-full-name) "'s Address book</TITLE>\n"
+ "<H1>" (user-full-name) "'s Address book</H1>\n"
+ "\n"
+ "<DL><p>\n")
+ (while records
+ (setq record (car records))
+ (insert " <DT><A HREF=\"mailto:")
+ (let ((net (car (bbdb-record-net record))))
+ (if net (insert net))
+ (insert "\" ALIASID=\"")
+ (prin1 count (current-buffer))
+ (insert "\"")
+ (message "%d..." count)
+ (setq count (1+ count))
+ (cond ((setq match (cdr (assq record single-aliases)))
+ (insert " NICKNAME=\"")
+ (princ match (current-buffer))
+ (insert "\"")))
+ (insert ">")
+ (insert (or (bbdb-record-name record)
+ net
+ (bbdb-record-company record)
+ "")))
+
+ (insert "</A>\n")
+ (let ((phones (bbdb-record-phones record))
+ (addrs (bbdb-record-addresses record))
+ (aka (bbdb-record-aka record))
+ phone
+ )
+
+ (insert "<DD>")
+ (setq match nil)
+ (while phones
+ (setq phone (car phones))
+ (setq match t)
+ (insert (format " %14s: " (bbdb-phone-location phone)))
+ (insert (bbdb-phone-string phone) "\n<BR>")
+ (setq phones (cdr phones)))
+ (let (addr c s)
+ (while addrs
+ (setq addr (car addrs))
+ (setq match t)
+ (insert (format " %14s: " (bbdb-address-location addr)))
+ (if (= 0 (length (setq s (bbdb-address-street1 addr)))) nil
+ (indent-to 17) (insert s "\n<BR>"))
+ (if (= 0 (length (setq s (bbdb-address-street2 addr)))) nil
+ (indent-to 17) (insert s "\n<BR>"))
+ (if (= 0 (length (setq s (bbdb-address-street3 addr)))) nil
+ (indent-to 17) (insert s "\n<BR>"))
+ (indent-to 17)
+ (insert (setq c (bbdb-address-city addr)))
+ (setq s (bbdb-address-state addr))
+ (if (and (> (length c) 0) (> (length s) 0)) (insert ", "))
+ (insert s " ")
+ (insert (bbdb-address-zip-string addr) "\n<BR>")
+ (setq addrs (cdr addrs))))
+ (cond (aka
+ (setq match t)
+ (insert (format " %14s: %s\n<BR>" "AKA"
+ (mapconcat (function identity) aka ", ")))))
+ (let ((notes (bbdb-record-raw-notes record)))
+ (if (stringp notes)
+ (setq notes (list (cons 'notes notes))))
+ (while notes
+ (if (memq (car (car notes))
+ '(mail-alias password bbdb mail-name face mark-char aka))
+ nil
+ (setq match t)
+ (insert (format " %14s: " (car (car notes))))
+ (let ((p (point)))
+ (insert (cdr (car notes)))
+ (save-excursion
+ (save-restriction
+ (narrow-to-region p (1- (point)))
+ (goto-char (1+ p))
+ (while (search-forward "\n" nil t)
+ (forward-char -1)
+ (insert "<BR>")
+ (forward-char 1)
+ (insert (make-string 17 ?\ )))))
+ (insert "\n")))
+ (setq notes (cdr notes)))))
+
+ (or match (delete-char -4))
+
+ (setq records (cdr records))
+ )
+ (insert "</DL><p>\n")
+ ))
diff --git a/utils/bbdb-unlazy-lock.pl b/utils/bbdb-unlazy-lock.pl
new file mode 100755
index 0000000..69a5755
--- /dev/null
+++ b/utils/bbdb-unlazy-lock.pl
@@ -0,0 +1,19 @@
+#!/usr/local/bin/perl
+#
+# Author: Christopher Kline <ckline@media.mit.edu>
+#
+# $Id$
+#
+# $Log$
+# Revision 1.1 1997/10/06 00:56:14 simmonmt
+# Initial revision
+#
+#
+# Lazy-lock-mode has (had) a nasty habit of munging .bbdb files if you visited them
+# with it on. This script removes the lazy-lock mung
+#
+
+while( <STDIN> ) {
+ s/#\(("[^"]*")( \d+ \d+ (nil)*(\(lazy-lock t\))*)*\)/$1/gi;
+ print;
+}