X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb/blobdiff_plain/83d31c09c02f5935aa3ce9d093f07d0d14d6f8d4..3a732227d8d63271b7171482ce36218d04f586cc:/utils/split-pieces diff --git a/utils/split-pieces b/utils/split-pieces index 11ecd8a9..a5b62945 100755 --- a/utils/split-pieces +++ b/utils/split-pieces @@ -47,15 +47,15 @@ class BaseQfConvert (object): print ";; piece widths = %r" % seq return cls(p, seq) def hack(me, n): - if 2*n >= me.p: n -= p + if me.SIGNEDP and 2*n >= me.p: n -= me.p nn = [] wds = cycle(me.wdseq) while n: wd = wds.next() lim = 1 << wd; m = lim - 1 d = n&m; n >>= wd - if d >= lim/2: d -= lim; n += 1 - nn.append(str(d)) + if me.SIGNEDP and d >= lim/2: d -= lim; n += 1 + nn.append(me.fmt(d)) return nn def unhack(me, nn): a = o = 0 @@ -65,13 +65,17 @@ class BaseQfConvert (object): if a < 0: a += me.p return a +class SignedQfConvert (BaseQfConvert): + SIGNEDP = True + def fmt(me, n): return str(n) + R_split = RX.compile(r',\s*|\s+') def spliteval(arg): return map(eval, R_split.split(arg.strip())) convmap = { 'scaf': ScafConvert, 'unscaf': ScafConvert, - 'qf': BaseQfConvert, - 'unqf': BaseQfConvert } + 'qf': SignedQfConvert, + 'unqf': SignedQfConvert } op = getarg() cvt = convmap[op].parse() if op.startswith('un'): prepare, conv, format = spliteval, cvt.unhack, str