File: bbdb-areacode-split.pl

package info (click to toggle)
xemacs21-packages 2009.02.17.dfsg.1-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 116,928 kB
  • ctags: 88,975
  • sloc: lisp: 1,232,060; ansic: 16,570; java: 13,514; xml: 6,477; sh: 4,611; makefile: 4,036; asm: 3,007; perl: 839; cpp: 500; ruby: 257; csh: 96; haskell: 93; awk: 49; python: 47
file content (62 lines) | stat: -rwxr-xr-x 1,539 bytes parent folder | download | duplicates (20)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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__