reuse AllowedLinkProtocolFromDocument in writer
[LibreOffice.git] / bin / dump-poolitems-values.py
blobc2c5f357e9fae32d84247529cf818b5575ff40a2
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
8 import sys
10 macroNameToValue = dict()
11 macroNameToOriginalLine = dict()
14 def extractMacroValue(macroValue):
15 if isinstance(macroValue, int):
16 return macroValue
17 elif macroValue.isdigit():
18 return int(macroValue)
19 elif macroValue[0:2] == "0x":
20 return int(macroValue, 16)
21 elif macroValue.find("+") != -1:
22 tokens = macroValue.split("+")
23 tokens1 = tokens[0].strip()
24 tokens2 = tokens[1].strip()
25 return extractMacroValue(tokens1) + extractMacroValue(tokens2)
26 elif macroValue.find("-") != -1:
27 tokens = macroValue.split("-")
28 tokens1 = tokens[0].strip()
29 tokens2 = tokens[1].strip()
30 return extractMacroValue(tokens1) - extractMacroValue(tokens2)
31 rv = extractMacroValue(macroNameToValue[macroValue])
32 macroNameToValue[macroValue] = rv
33 return rv
36 a = subprocess.Popen("cpp -E -dD -Iinclude/ include/editeng/eeitem.hxx", stdout=subprocess.PIPE, shell=True)
38 with a.stdout as txt:
39 for line in txt:
40 line = line.strip()
41 originalLine = line
42 if not line.startswith("#define "): 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): continue
49 macroName = line[0 : idx1].strip()
50 line = line[idx1 : len(line)].strip()
51 # ignore internal stuff
52 if macroName.startswith("_"): continue
53 # strip any trailing comments
54 idx1 = line.find("//")
55 if (idx1 != -1):
56 line = line[0 : idx1].strip()
57 idx1 = line.find("/*")
58 if (idx1 != -1):
59 line = line[0 : idx1].strip()
60 if len(line) == 0: continue
61 # strip brackets
62 if line[0] == "(": line = line[1:]
63 if line[len(line)-1] == ")": line = line[0:len(line)-1]
64 macroValue = line.strip()
65 # ignore macros that #define strings, not interested in those
66 if (macroValue.find("\"") != -1): continue
67 # ignore the multiline macros
68 if (macroValue.find("\\") != -1): continue
69 # check for redefinitions
70 if macroNameToValue.has_key(macroName):
71 print "Redefinition:\n\t", macroNameToOriginalLine[macroName], "\n\t" , originalLine
72 else:
73 macroNameToValue[macroName] = macroValue
74 macroNameToOriginalLine[macroName] = originalLine
76 # decode the constants into their numeric values recursively
77 macroValueToName = dict()
78 for macroName in macroNameToValue:
79 macroValue = macroNameToValue[macroName]
80 try:
81 macroValue = extractMacroValue(macroName)
82 macroValueToName[macroValue] = macroName
83 except KeyError:
84 print "warning: could not decode macro ", macroName
86 for macroValue in sorted(macroValueToName):
87 macroName = macroValueToName[macroValue]
88 print repr(macroNameToValue[macroName]).rjust(5), " ", macroName