Created tohypyen.py to clean up all DW_* entries
[dwarf-doc.git] / dwarf5 / tools / tohyphen.py
1 # Copyright 2012 DWARF Debugging Information Format Committee
2 #
3 # Convert DW_ and DW\_ names to DW\-\_ 
4 #
5
6 import sys
7 import fileio
8
9 def convertToHyphen(s):
10   out = []
11   for c in s:
12     if c == "_":
13       out += ["\\"]
14       out += ["-"]
15       out += ["\\"]
16     out += [c]  
17   os = ''.join(out)
18   return os
19
20 def transfunc(linetoks):
21   if len(linetoks) < 1:
22     return linetoks
23   outtoks = []
24   for t in linetoks:
25     stdname= ''.join(t._std)
26     if stdname.startswith("DW_") != 0:
27       xs = convertToHyphen(stdname)
28       x = fileio.dwtoken()
29       x.insertid(xs)
30       x.finishUpId()
31       outtoks += [x]
32     else:
33       outtoks += [t]
34     # End of for loop.
35   return outtoks
36
37 def read_args():
38   cur = 1
39   filelist = []
40   while  len(sys.argv) > cur:
41     v = sys.argv[cur]
42     filelist += [v]
43     cur = int(cur) + 1
44
45   dwf = fileio.readFilelist(filelist)
46   dwf.dwtransformline(transfunc)
47   dwf.dwwrite()
48
49 if __name__ == '__main__':
50   read_args()
51   
52
53