File: dump-poolitems-values.py

package info (click to toggle)
libreoffice 4%3A26.2.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 3,838,464 kB
  • sloc: cpp: 4,398,766; xml: 499,253; java: 254,438; python: 81,885; ansic: 33,826; perl: 30,297; javascript: 19,722; sh: 12,042; makefile: 10,848; cs: 8,865; yacc: 8,549; objc: 2,131; lex: 1,385; asm: 1,231; awk: 996; pascal: 914; csh: 20; sed: 5
file content (98 lines) | stat: -rwxr-xr-x 3,193 bytes parent folder | download | duplicates (8)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/python


# Produce a dump of name->constant of the poolitem values, to make interpreting things in the debugger easier
#

import subprocess

macroNameToValue = dict()
macroNameToOriginalLine = dict()


def extractMacroValue(macroValue):
    if isinstance(macroValue, int):
        return macroValue
    elif macroValue.isdigit():
        return int(macroValue)
    elif macroValue[0:2] == "0x":
        return int(macroValue, 16)
    elif macroValue.find("+") != -1:
        tokens = macroValue.split("+")
        tokens1 = tokens[0].strip()
        tokens2 = tokens[1].strip()
        return extractMacroValue(tokens1) + extractMacroValue(tokens2)
    elif macroValue.find("-") != -1:
        tokens = macroValue.split("-")
        tokens1 = tokens[0].strip()
        tokens2 = tokens[1].strip()
        return extractMacroValue(tokens1) - extractMacroValue(tokens2)
    rv = extractMacroValue(macroNameToValue[macroValue])
    macroNameToValue[macroValue] = rv
    return rv


a = subprocess.Popen("cpp -E -dD -Iinclude/ include/editeng/eeitem.hxx", stdout=subprocess.PIPE, shell=True)

with a.stdout as txt:
    for line in txt:
        line = line.strip()
        originalLine = line
        if not line.startswith("#define "):
            continue
        # strip the '#define' off the front
        idx1 = line.find(" ")
        line = line[idx1:len(line)].strip()
        # extract the name
        idx1 = line.find(" ")
        if (idx1 == -1):
            continue
        macroName = line[0:idx1].strip()
        line = line[idx1:len(line)].strip()
        # ignore internal stuff
        if macroName.startswith("_"):
            continue
        # strip any trailing comments
        idx1 = line.find("//")
        if (idx1 != -1):
            line = line[0:idx1].strip()
        idx1 = line.find("/*")
        if (idx1 != -1):
            line = line[0:idx1].strip()
        if len(line) == 0:
            continue
        # strip brackets
        if line[0] == "(":
            line = line[1:]
        if line[len(line)-1] == ")":
            line = line[0:len(line)-1]
        macroValue = line.strip()
        # ignore macros that #define strings, not interested in those
        if (macroValue.find("\"") != -1):
            continue
        # ignore the multiline macros
        if (macroValue.find("\\") != -1):
            continue
        # check for redefinitions
        if macroNameToValue.has_key(macroName):
            print("Redefinition:\n\t",  macroNameToOriginalLine[macroName], "\n\t", originalLine)
        else:
            macroNameToValue[macroName] = macroValue
            macroNameToOriginalLine[macroName] = originalLine

# decode the constants into their numeric values recursively
macroValueToName = dict()
for macroName in macroNameToValue:
    macroValue = macroNameToValue[macroName]
    try:
        macroValue = extractMacroValue(macroName)
        macroValueToName[macroValue] = macroName
    except KeyError:
        print("warning: could not decode macro ", macroName)

for macroValue in sorted(macroValueToName):
    macroName = macroValueToName[macroValue]
    print(repr(macroNameToValue[macroName]).rjust(5), " ", macroName)