2 # SPDX-License-Identifier: GPL-2.0-only
4 # Create cdb file from flat alias file. DPC: 15/10/98.
5 # Args: source (may be relative or absolute)
6 # target (may be relative or absolute. Default = source)
7 # Generates: target.cdb
10 # Little Perl script to convert flat file into CDB file. Two advantages over
11 # cdbmake-12 awk script that is distributed with CDB:
12 # 1) Handles 'dpc22:dpc22@hermes' as well as 'dpc22 dpc22@hermes'
13 # 2) Perl works with arbitrary length strings: awk chokes at 1,024 chars
15 # Cambridge: hermes/src/admin/mkcdb,v 1.9 2005/02/15 18:14:12 fanf2 Exp
19 BEGIN { pop @INC if $INC[-1] eq '.' };
23 my $CDB = '/opt/cdb/bin/cdbmake';
26 $prog =~ s|(.*/)?([^/]+)|$2|;
31 $source = shift(@ARGV);
33 } elsif (@ARGV == 2) {
34 $source = shift(@ARGV);
35 $target = shift(@ARGV);
37 die("$prog: usage: <source> [<target>]\n");
39 # trust the invoker ?!
45 open(SOURCE, "< ${source}")
46 or die("$prog: open < $source: $!\n");
48 open(PIPE, "| $CDB $target.cdb $target.tmp")
49 or die("$prog: open | $CDB $target: $!\n");
54 printf PIPE ("+%d,%d:%s->%s\n", length($key), length($val), $key, $val);
59 if ($line =~ /^([^\s:]+)\s*:\s*(.*)$/s) { # key : values
63 if ($line =~ /^(\S+)\s+(.*)$/s) { # key: values
67 if ($line =~ /^(\S+)$/s) { # key (empty value)
71 warn "$prog: unrecognized item: $line";
76 next if /^#/ or /^\s*$/;
78 if (length($1) == 0) {
79 add_line($data) if defined $data;
85 add_line($data) if defined $data;
89 or die("$prog: close < $source: $!\n");
91 or die($! ? "$prog: close | $CDB $target: $!\n"
92 : "$prog: close | $CDB $target: exited $?\n");