File: parsedic.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 (28 lines) | stat: -rw-r--r-- 688 bytes parent folder | download | duplicates (6)
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
"""
Parse a DCMTK dict file and produce a flat file.
"""

import sys
import string
import re

r = re.compile(r'\(([^,]*),"([^"]*)",([^,]*)\)[ \t]*(..)[ \t]*([^ \t]*)[ \t]*(.*)')
s = r'(\1,00\3)\n\5\n\5\n\4\n\6\n\2\n'

for filename in sys.argv[1:]:
  f = open(filename)
  for line in f.readlines():
    l = line.strip()
    if line[0] == '(':
      g = re.sub(r,r'\1',l)
      e = re.sub(r,r'\3',l)
      if len(g) > 4:
        g0 = int(g[0:4],16)
        g1 = int(g[7:11],16)
        tail = re.sub(r,s[3:],l)
        for g in range(g0,g1+1,2):
          sys.stdout.write("(%04.4x" % (g,) + tail)
      elif len(e) > 4:
        continue
      else:
        sys.stdout.write(re.sub(r,s,l))