File: update_include.py

package info (click to toggle)
z3 4.13.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 33,364 kB
  • sloc: cpp: 501,803; python: 16,788; cs: 10,567; java: 9,687; ml: 3,282; ansic: 2,531; sh: 162; javascript: 37; makefile: 32
file content (69 lines) | stat: -rw-r--r-- 1,855 bytes parent folder | download | duplicates (3)
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
68
69
# Copyright (c) 2017 Microsoft Corporation

import os
import re

is_include = re.compile("#include \"(.*)\"")
is_include2 = re.compile("#include\"(.*)\"")


def fix_include(file, paths):
    tmp = "%s.tmp" % file
    ins = open(file)
    ous = open(tmp,'w')
    line = ins.readline()
    found = False
    while line:
        m = is_include.search(line)
        if m and m.group(1) in paths:
            ous.write("#include \"")
            ous.write(paths[m.group(1)])
            ous.write("\"\n")
            found = True
            line = ins.readline()
            continue
        m = is_include2.search(line)
        if m and m.group(1) in paths:
            ous.write("#include \"")
            ous.write(paths[m.group(1)])
            ous.write("\"\n")
            found = True
            line = ins.readline()
            continue
        ous.write(line)            
        line = ins.readline()
    ins.close()
    ous.close()
    if found:
        print(file)
        os.system("move %s %s" % (tmp, file))
    else:
        os.system("del %s" % tmp)

def find_paths(dir):
    paths = {}
    for root, dirs, files in os.walk(dir):
        root1 = root.replace("\\","/")[4:]
        for f in files:
            if f.endswith('.h') or f.endswith('.hpp') or f.endswith('.cpp'):
                path = "%s/%s" % (root1, f)
                paths[f] = path
            if f.endswith('.pyg'):
                f = f.replace("pyg","hpp")
                path = "%s/%s" % (root1, f)
                paths[f] = path
    return paths

paths = find_paths('src')

def fixup(dir):
    for root, dirs, files in os.walk(dir):
        for f in files:
            if f == "z3.h":
                continue
            if f.endswith('.h') or f.endswith('.cpp'):
                path = "%s\\%s" % (root, f)
                fix_include(path, paths)


fixup('src')