Well, Graham got me thinking about this and I think I've managed to write a
Perl script which will grab the phone numbers and display them for you
without ever requiring that emacs be started OR having a separate
bbdb-phones file sitting about.  Just think how much fun I had trying to
write a regexp that will match lisp objects.  (There still is one small
problem with the regexp for the network address matching stuff in the
"other" field if there are more than just notes.)

I've tested this on a variety of my bbdb entries and it seems to work
nicely.  I've set it up to display the person's name plus their phone and
location on a single line.  If they have more than one phone entry, each
gets its own line.

I call the perl script "phone.perl", so it can be run by doing:

grep -i NAME ~/.bbdb | ~/bin/phone.perl

Or this can be stuck into a shell script:

-------
#!/bin/sh
grep -i -h $1 $HOME/.bbdb | $HOME/bin/phone.perl
-------

Here is the actual code:

---------- phone.perl --------
#!/usr/local/bin/perl

#Author: Jack Vinson:  [EMAIL PROTECTED]
#Date: Tue Jun 28 1994

#Jack's attempt at parsing lisp objects via regexps in order to extract 
# interesting info.  In this case, I'm grabbing all the entries of the 
# .bbdb file and displaying name and phone number if they exist.

#This can be fairly easily extended to display addresses as well.

#NOTE:  The variable $nets will be filled improperly if the database 
# entry has notes AND user-defined fields.

while (<>) {
    ($first, $last, $aliases, $company, $phones, $addresses, $nets, $other) = 
/^\[(nil|\"[^\"]*\") (nil|\"[^\"]*\") (nil|\(\".*\"\)) (nil|\"[^\"]*\") (nil|\(.*\)) 
(nil|\(.*\)) (nil|\(\".*\"\)) (nil|.*) nil\]$/;
    if ($first !~ /^nil$/) {
        ($temp1, $first, $temp2) = split(/\"/,$first,3);
    }
    if ($last !~ /^nil$/) {
        ($temp1, $last, $temp2) = split(/\"/,$last,3);
    }
    if ($phones =~ /^nil$/) {
        print "There are no phone numbers available for $first $last.\n";
    }
    else {
        @phentries = split(/\]/,$phones);
        $phentries = @phentries;
        if ($phentries > 2) { print "$first $last:\n"; }
        else { print "$first $last:"; }
        foreach $entry (@phentries) {
            if ($entry !~ /\)$/) {
                ($temp1, $loc, $num) = split(/\"/,$entry);
                if ($num =~ / 0$/) { $num = substr($num,0,13); }
                print "\t$loc: $num\n";
            }
        }
        print "\n";
    }
}
---------------- phone.perl -------

Have fun!


Jack Vinson                   The Purple Puddle Eater and Captain Jack
[EMAIL PROTECTED]    WWW: "http://www.cis.upenn.edu/~vinson/home.html"
"Skin ain't got no tailored pockets."   - Eat _Sell_Me_a_God_

Reply via email to