chiark / gitweb /
cdb: Remove dependency on freecdb and libfile-cdb-perl.
authorMark Wooding <mdw@distorted.org.uk>
Thu, 2 Mar 2006 01:49:57 +0000 (01:49 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 2 Mar 2006 01:49:57 +0000 (01:49 +0000)
The C utilities are now built against tinycdb.  The Perl utilities have
been rewritten in Python and use python-cdb.

Makefile
cdb-assign
cdb-check-domain.c
cdb-list
cdb-map [changed mode: 0644->0755]
cdb-probe.c
debian/control
debian/rules

index 30921f5811908bf7014b93a6a53cb0619fc7389d..8d75d34b84835becef8342fc1a79d679684ead96 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -73,10 +73,10 @@ qmail-checkspam: qmail-checkspam.o
        $(LINK) -lspamc
 
 cdb-probe: cdb-probe.o
-       $(LINK) -lfreecdb
+       $(LINK) -lcdb
 
 cdb-check-domain: cdb-check-domain.o
-       $(LINK) -lfreecdb
+       $(LINK) -lcdb
 
 not: not.o
        $(LINK)
index e3184c2de62c2cf91aa4871d324f846d7a140e92..686d0f71b8cbfd2f81b3a9847f3926ee0d6ae61a 100755 (executable)
@@ -1,15 +1,40 @@
-#! /usr/bin/perl
-
-use CDB_File;
-
-@ARGV >= 1 or die "usage: $0 CDB [INPUT ...]\n";
-$f = shift;
-$c = CDB_File->new($f, "$f.new") or die "CDB_File->new: $!\n";
-while (<>) {
-  chomp;
-  next if m'^\s*(\#|$)';
-  m'^\s*([-\w]+)\s*=\s*(.*\S|)\s*$' or die "bad assignment `$_'\n";
-  $c->insert($1, $2);
-}
-$c->finish() or die "CDB_File->finish: $!\n";
-exit 0;
+#! /usr/bin/python
+
+from cdb import cdbmake
+from sre import compile as r_compile, sub as r_sub
+from sys import argv, stdin, stderr, exit
+
+ego = r_sub(r'^.*[/\\]', '', argv[0])
+def die(msg, prefix = True):
+  if prefix: msg ='%s: %s' % (ego, msg) 
+  print >>stderr, msg
+  exit(1)
+
+def files(args):
+  if len(args) == 0:
+    yield stdin
+  else:
+    for a in args:
+      if a == '-':
+        yield stdin
+      else:
+        yield open(a, 'r')
+
+if len(argv) < 2:
+  die('usage: %s CDB [INPUT ...]' % ego, False)
+
+rx_comment = r_compile(r'^\s*(\#|$)')
+rx_split = r_compile(r'^\s*([-\w]+)\s*=\s*(.*\S|)\s*$')
+
+cdb = cdbmake(argv[1], argv[1] + '.new')
+for f in files(argv[2:]):
+  for line in f:
+    if len(line) and line[-1] == '\n': line = line[:-1]
+    if rx_comment.match(line):
+      continue
+    m = rx_split.match(line)
+    if not m:
+      die("bad assignment: `%s'" % line)
+    k, v = m.groups([1, 2])
+    cdb.add(k, v)
+cdb.finish()
index bac648103b99c5ef5a2b473ecc928a3c7324b590..ac11000aba25e31e7c9497d92839bb5a378e7de6 100644 (file)
@@ -3,14 +3,14 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "freecdb.h"
+#include <cdb.h>
 
 const char *prog;
 
 static void check(const char *p)
 {
   int rc;
-  uint32_t l;
+  unsigned l;
 
   rc = cdb_seek(0, p, strlen(p), &l);
   if (rc < 0) {
index 368da625e6ffbdaab930e9763808b1d1a364ec2d..ee85a1483617b24632a96e0811a43a8c4e667fb9 100755 (executable)
--- a/cdb-list
+++ b/cdb-list
@@ -1,15 +1,37 @@
-#! /usr/bin/perl
-
-use CDB_File;
-
-@ARGV >= 1 or die "usage: $0 CDB [INPUT ...]\n";
-$f = shift;
-$c = CDB_File->new($f, "$f.new") or die "CDB_File->new: $!\n";
-while (<>) {
-  chomp;
-  next if m'^\s*(\#|$)';
-  m'^\s*(.*\S|)\s*$';
-  $c->insert($1, "");
-}
-$c->finish() or die "CDB_File->finish: $!\n";
-exit 0;
+#! /usr/bin/python
+
+from cdb import cdbmake
+from sre import compile as r_compile, sub as r_sub
+from sys import argv, stdin, stderr, exit
+
+ego = r_sub(r'^.*[/\\]', '', argv[0])
+def die(msg, prefix = True):
+  if prefix: msg ='%s: %s' % (ego, msg) 
+  print >>stderr, msg
+  exit(1)
+
+def files(args):
+  if len(args) == 0:
+    yield stdin
+  else:
+    for a in args:
+      if a == '-':
+        yield stdin
+      else:
+        yield open(a, 'r')
+
+if len(argv) < 2:
+  die('usage: %s CDB [INPUT ...]' % ego, False)
+
+rx_comment = r_compile(r'^\s*(\#|$)')
+rx_shave = r_compile(r'\s*(.*\S|)\s*$')
+
+cdb = cdbmake(argv[1], argv[1] + '.new')
+for f in files(argv[2:]):
+  for line in f:
+    if len(line) and line[-1] == '\n': line = line[:-1]
+    if rx_comment.match(line):
+      continue
+    line = rx_shave.sub(r'\1', line)
+    cdb.add(line, '')
+cdb.finish()
diff --git a/cdb-map b/cdb-map
old mode 100644 (file)
new mode 100755 (executable)
index 71cdde0..f230a42
--- a/cdb-map
+++ b/cdb-map
@@ -1,14 +1,32 @@
-#! /usr/bin/perl
-
-use CDB_File;
-
-@ARGV >= 1 or die "usage: $0 CDB [INPUT ...]\n";
-$f = shift;
-$c = CDB_File->new($f, "$f.new") or die "CDB_File->new: $!\n";
-while (<>) {
-  chomp;
-  m'^([^:]*):(.*)$' or die "bad assignment `$_'\n";
-  $c->insert($1, $2);
-}
-$c->finish() or die "CDB_File->finish: $!\n";
-exit 0;
+#! /usr/bin/python
+
+from cdb import cdbmake
+from sre import sub as r_sub
+from sys import argv, stdin, stderr, exit
+
+ego = r_sub(r'^.*[/\\]', '', argv[0])
+def die(msg, prefix = True):
+  if prefix: msg ='%s: %s' % (ego, msg) 
+  print >>stderr, msg
+  exit(1)
+
+def files(args):
+  if len(args) == 0:
+    yield stdin
+  else:
+    for a in args:
+      if a == '-':
+        yield stdin
+      else:
+        yield open(a, 'r')
+
+if len(argv) < 2:
+  die('usage: %s CDB [INPUT ...]' % ego, False)
+
+cdb = cdbmake(argv[1], argv[1] + '.new')
+for f in files(argv[2:]):
+  for line in f:
+    if len(line) and line[-1] == '\n': line = line[:-1]
+    k, v = line.split(':', 1)
+    cdb.add(k, v)
+cdb.finish()
index cb19a295f29a18c1e356f9a16f7eb6b794f8bbc7..ff2b7eac75985afb363a44c293605311f82376ba 100644 (file)
@@ -3,14 +3,14 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "freecdb.h"
+#include <cdb.h>
 
 const char *prog;
 
 static void check(const char *p)
 {
   int rc;
-  uint32_t l;
+  unsigned l;
 
   rc = cdb_seek(0, p, strlen(p), &l);
   if (rc < 0) {
index 638d863dad6730d1fa6ec02de211a47cd517cc77..5fbde5278cf4f4af82f34bc4d65ad327848e1d48 100644 (file)
@@ -2,7 +2,7 @@ Source: nsict-utils
 Section: utils
 Priority: extra
 Maintainer: Mark Wooding <mdw@distorted.org.uk>
-Build-Depends: freecdb, bash-builtins, debhelper (>= 4.0.2),
+Build-Depends: tinycdb, bash-builtins, debhelper (>= 4.0.2), python,
  catacomb-dev (>= 2.0.0), mlib-dev (>= 2.0.0), libspamc-dev
 Standards-Version: 3.1.1
 
@@ -22,7 +22,7 @@ Description: Options parser library for perl.
 Package: nsict-cdb
 Architecture: any
 Section: utils
-Depends: ${shlibs:Depends}, perl5, libcdb-file-perl
+Depends: ${shlibs:Depends}, ${python:Depends}, python-cdb
 Description: Simple utilities for messing with CDB files.
 
 Package: locking
index d987ec68900762dd9a456d1f69f8989005905700..80aed10d49e62246ea0478088367f07d3866310a 100755 (executable)
@@ -24,8 +24,9 @@ binary-indep:
        dh_testroot -i
        dh_compress -i
        dh_installdocs -i
-       dh_gencontrol -i
        dh_perl -i
+       dh_python -i
+       dh_gencontrol -i
        dh_fixperms -i
        dh_installdeb -i
        dh_md5sums -i
@@ -38,6 +39,7 @@ binary-arch:
        dh_installdocs -a
        dh_strip -a
        dh_shlibdeps -a
+       dh_python -a
        dh_gencontrol -a
        dh_fixperms -a
        dh_installdeb -a