X-Git-Url: https://git.distorted.org.uk/~mdw/misc/blobdiff_plain/841e5aca814309f2ca144d84681a48060537c2a1..b2ffb9b761c57c643a13316b7a15a715644a16ad:/cdb-assign?ds=sidebyside diff --git a/cdb-assign b/cdb-assign deleted file mode 100755 index 18051b1..0000000 --- a/cdb-assign +++ /dev/null @@ -1,40 +0,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()