mtimeout.1: Use correct dash for number ranges.
[misc] / cdb-list.in
CommitLineData
b2ffb9b7 1#! @PYTHON@
329f8eb8 2### -*-python-*-
bba986ae
MW
3
4from cdb import cdbmake
329f8eb8 5from re import compile as r_compile, sub as r_sub
bba986ae
MW
6from sys import argv, stdin, stderr, exit
7
8ego = r_sub(r'^.*[/\\]', '', argv[0])
9def die(msg, prefix = True):
841e5aca 10 if prefix: msg ='%s: %s' % (ego, msg)
bba986ae
MW
11 print >>stderr, msg
12 exit(1)
13
14def files(args):
15 if len(args) == 0:
16 yield stdin
17 else:
18 for a in args:
19 if a == '-':
841e5aca 20 yield stdin
bba986ae 21 else:
841e5aca 22 yield open(a, 'r')
bba986ae
MW
23
24if len(argv) < 2:
25 die('usage: %s CDB [INPUT ...]' % ego, False)
26
27rx_comment = r_compile(r'^\s*(\#|$)')
28rx_shave = r_compile(r'\s*(.*\S|)\s*$')
29
30cdb = cdbmake(argv[1], argv[1] + '.new')
31for f in files(argv[2:]):
32 for line in f:
33 if len(line) and line[-1] == '\n': line = line[:-1]
34 if rx_comment.match(line):
35 continue
36 line = rx_shave.sub(r'\1', line)
37 cdb.add(line, '')
38cdb.finish()