lok: jsdialog: enable font name box after save
[LibreOffice.git] / bin / dump-poolitems-values.py
blobd7dcc920574ab2357329fb300007e77fdd2da9ff
1 #!/usr/bin/python
4 # Produce a dump of name->constant of the poolitem values, to make interpreting things in the debugger easier
7 import subprocess
9 macroNameToValue = dict()
10 macroNameToOriginalLine = dict()
13 def extractMacroValue(macroValue):
14 if isinstance(macroValue, int):
15 return macroValue
16 elif macroValue.isdigit():
17 return int(macroValue)
18 elif macroValue[0:2] == "0x":
19 return int(macroValue, 16)
20 elif macroValue.find("+") != -1:
21 tokens = macroValue.split("+")
22 tokens1 = tokens[0].strip()
23 tokens2 = tokens[1].strip()
24 return extractMacroValue(tokens1) + extractMacroValue(tokens2)
25 elif macroValue.find("-") != -1:
26 tokens = macroValue.split("-")
27 tokens1 = tokens[0].strip()
28 tokens2 = tokens[1].strip()
29 return extractMacroValue(tokens1) - extractMacroValue(tokens2)
30 rv = extractMacroValue(macroNameToValue[macroValue])
31 macroNameToValue[macroValue] = rv
32 return rv
35 a = subprocess.Popen("cpp -E -dD -Iinclude/ include/editeng/eeitem.hxx", stdout=subprocess.PIPE, shell=True)
37 with a.stdout as txt:
38 for line in txt:
39 line = line.strip()
40 originalLine = line
41 if not line.startswith("#define "):
42 continue
43 # strip the '#define' off the front
44 idx1 = line.find(" ")
45 line = line[idx1:len(line)].strip()
46 # extract the name
47 idx1 = line.find(" ")
48 if (idx1 == -1):
49 continue
50 macroName = line[0:idx1].strip()
51 line = line[idx1:len(line)].strip()
52 # ignore internal stuff
53 if macroName.startswith("_"):
54 continue
55 # strip any trailing comments
56 idx1 = line.find("//")
57 if (idx1 != -1):
58 line = line[0:idx1].strip()
59 idx1 = line.find("/*")
60 if (idx1 != -1):
61 line = line[0:idx1].strip()
62 if len(line) == 0:
63 continue
64 # strip brackets
65 if line[0] == "(":
66 line = line[1:]
67 if line[len(line)-1] == ")":
68 line = line[0:len(line)-1]
69 macroValue = line.strip()
70 # ignore macros that #define strings, not interested in those
71 if (macroValue.find("\"") != -1):
72 continue
73 # ignore the multiline macros
74 if (macroValue.find("\\") != -1):
75 continue
76 # check for redefinitions
77 if macroNameToValue.has_key(macroName):
78 print("Redefinition:\n\t", macroNameToOriginalLine[macroName], "\n\t", originalLine)
79 else:
80 macroNameToValue[macroName] = macroValue
81 macroNameToOriginalLine[macroName] = originalLine
83 # decode the constants into their numeric values recursively
84 macroValueToName = dict()
85 for macroName in macroNameToValue:
86 macroValue = macroNameToValue[macroName]
87 try:
88 macroValue = extractMacroValue(macroName)
89 macroValueToName[macroValue] = macroName
90 except KeyError:
91 print("warning: could not decode macro ", macroName)
93 for macroValue in sorted(macroValueToName):
94 macroName = macroValueToName[macroValue]
95 print(repr(macroNameToValue[macroName]).rjust(5), " ", macroName)