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 arbitary 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
21 my $CDB = '/opt/cdb/bin/cdbmake';
24 $prog =~ s|(.*/)?([^/]+)|$2|;
29 $source = shift(@ARGV);
31 } elsif (@ARGV == 2) {
32 $source = shift(@ARGV);
33 $target = shift(@ARGV);
35 die("$prog: usage: <source> [<target>]\n");
37 # trust the invoker ?!
43 open(SOURCE, "< ${source}")
44 or die("$prog: open < $source: $!\n");
46 open(PIPE, "| $CDB $target.cdb $target.tmp")
47 or die("$prog: open | $CDB $target: $!\n");
52 printf PIPE ("+%d,%d:%s->%s\n", length($key), length($val), $key, $val);
57 if ($line =~ /^([^\s:]+)\s*:\s*(.*)$/s) { # key : values
61 if ($line =~ /^(\S+)\s+(.*)$/s) { # key: values
65 if ($line =~ /^(\S+)$/s) { # key (empty value)
69 warn "$prog: unrecognized item: $line";
74 next if /^#/ or /^\s*$/;
76 if (length($1) == 0) {
77 add_line($data) if defined $data;
83 add_line($data) if defined $data;
87 or die("$prog: close < $source: $!\n");
89 or die($! ? "$prog: close | $CDB $target: $!\n"
90 : "$prog: close | $CDB $target: exited $?\n");