| 1 | #! @PYTHON@ |
| 2 | ### -*-python-*- |
| 3 | |
| 4 | from cdb import cdbmake |
| 5 | from re import sub as r_sub |
| 6 | from sys import argv, stdin, stderr, exit |
| 7 | |
| 8 | ego = r_sub(r'^.*[/\\]', '', argv[0]) |
| 9 | def die(msg, prefix = True): |
| 10 | if prefix: msg ='%s: %s' % (ego, msg) |
| 11 | print >>stderr, msg |
| 12 | exit(1) |
| 13 | |
| 14 | def files(args): |
| 15 | if len(args) == 0: |
| 16 | yield stdin |
| 17 | else: |
| 18 | for a in args: |
| 19 | if a == '-': |
| 20 | yield stdin |
| 21 | else: |
| 22 | yield open(a, 'r') |
| 23 | |
| 24 | if len(argv) < 2: |
| 25 | die('usage: %s CDB [INPUT ...]' % ego, False) |
| 26 | |
| 27 | cdb = cdbmake(argv[1], argv[1] + '.new') |
| 28 | for f in files(argv[2:]): |
| 29 | for line in f: |
| 30 | if len(line) and line[-1] == '\n': line = line[:-1] |
| 31 | k, v = line.split(':', 1) |
| 32 | cdb.add(k, v) |
| 33 | cdb.finish() |