3 # Create cdb file from flat alias file. DPC: 15/10/98.
4 # Args: source (may be relative or absolute)
5 # target (may be relative or absolute. Default = source)
6 # Generates: target.cdb
9 # Little Perl script to convert flat file into CDB file. Two advantages over
10 # cdbmake-12 awk script that is distributed with CDB:
11 # 1) Handles 'dpc22:dpc22@hermes' as well as 'dpc22 dpc22@hermes'
12 # 2) Perl works with arbitrary length strings: awk chokes at 1,024 chars
14 # Cambridge: hermes/src/admin/mkcdb,v 1.9 2005/02/15 18:14:12 fanf2 Exp
18 BEGIN { pop @INC if $INC[-1] eq '.' };
22 my $CDB = '/opt/cdb/bin/cdbmake';
25 $prog =~ s|(.*/)?([^/]+)|$2|;
30 $source = shift(@ARGV);
32 } elsif (@ARGV == 2) {
33 $source = shift(@ARGV);
34 $target = shift(@ARGV);
36 die("$prog: usage: <source> [<target>]\n");
38 # trust the invoker ?!
44 open(SOURCE, "< ${source}")
45 or die("$prog: open < $source: $!\n");
47 open(PIPE, "| $CDB $target.cdb $target.tmp")
48 or die("$prog: open | $CDB $target: $!\n");
53 printf PIPE ("+%d,%d:%s->%s\n", length($key), length($val), $key, $val);
58 if ($line =~ /^([^\s:]+)\s*:\s*(.*)$/s) { # key : values
62 if ($line =~ /^(\S+)\s+(.*)$/s) { # key: values
66 if ($line =~ /^(\S+)$/s) { # key (empty value)
70 warn "$prog: unrecognized item: $line";
75 next if /^#/ or /^\s*$/;
77 if (length($1) == 0) {
78 add_line($data) if defined $data;
84 add_line($data) if defined $data;
88 or die("$prog: close < $source: $!\n");
90 or die($! ? "$prog: close | $CDB $target: $!\n"
91 : "$prog: close | $CDB $target: exited $?\n");