File: make_vm.py

package info (click to toggle)
vtk-dicom 0.8.17-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,032 kB
  • sloc: cpp: 113,806; python: 2,041; makefile: 43; tcl: 10
file content (67 lines) | stat: -rw-r--r-- 1,525 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""
Generate the enum code for the VM header file.
"""

def getmin(k):
    if ((k & 0x8000) != 0):
        return (k & 0x7fff)
    else:
        return (k >> 8)

def getmax(k):
    if ((k & 0x8000) != 0):
        return (k & 0x7fff)
    elif ((k & 0x80) == 0):
        return (k & 0xff)
    else:
        return -1;

def getstep(k):
    if ((k & 0x8000) != 0):
        return 1
    elif ((k & 0x80) == 0):
        return 1
    else:
        return ((-k) & 0xff)

def printm(k):
    n = getmin(k)
    m = getmax(k)
    s = getstep(k)
    a = 'M'
    a += str(n)
    if (m > n or m < 0):
        a += 'T'
        if (s > 1):
            a += str(s)
        if (m > 0):
            a += str(m)
        else:
            a += 'N'
    return a

if __name__ == '__main__':
    import sys

    if len(sys.argv) > 1:
        nlist = []
        for i in sys.argv[1:]:
            nlist.append(int(i, 16))
    else:
        nlist = [0x0000, 0x00FF, 0x7F7F, 0x8080, 0x80FF,
                 0x8100, 0x8200, 0x8300, 0x8400, 0x8800]
        nrange = list(range(0,33)) + [63, 64, 99, 100]
        for i in nrange:
            mrange = list(range(i,33)) + [63, 64, 99, 100, 0xff]
            for j in mrange:
                if j < i:
                    continue
                nlist.append((i << 8) | j)
                if j == 0xff and i > 1:
                    nlist.append((i << 8) | (j - i + 1))

    nlist.sort()
    for i in nlist:
        m = printm(i)
        if len(m) <= 9:
            print('    %-9.9s = 0x%4.4X,' % (m, i))