1#!/usr/bin/env python
2
3import re,sys
4
5pats = [
6 [ r"^\s*#\s*include\s+", r"__InClUdE__ " ],
7 [ r"^\s*#\s*ifdef (XEN_HAVE.*)\s+", r"__IfDeF__ \1" ],
8 [ r"^\s*#\s*else /\* (XEN_HAVE.*) \*/\s+", r"__ElSe__" ],
9 [ r"^\s*#\s*endif /\* (XEN_HAVE.*) \*/\s+", r"__EnDif__" ],
10 [ r"^\s*#\s*define\s+([A-Z_]*_GUEST_HANDLE)", r"#define HIDE_\1" ],
11 [ r"^\s*#\s*define\s+([a-z_]*_guest_handle)", r"#define hide_\1" ],
12 [ r"XEN_GUEST_HANDLE(_[0-9A-Fa-f]+)?", r"COMPAT_HANDLE" ],
13];
14
15xlatf = open('xlat.lst', 'r')
16for line in xlatf.readlines():
17    match = re.subn(r"^\s*\?\s+(\w*)\s.*", r"\1", line.rstrip())
18    if match[1]:
19        pats.append([ r"(struct|union)\s+(%s|xen_%s)\s+(\w)" % (match[0], match[0]),
20                      r"\1 @KeeP@\2 \3" ])
21xlatf.close()
22
23for pat in pats:
24    pat[0] = re.compile(pat[0])
25
26for line in sys.stdin.readlines():
27    for pat in pats:
28        line = re.sub(pat[0], pat[1], line)
29    print line.rstrip()
30