tdf#162340: handle target column scale in setObjectWithInfo
[LibreOffice.git] / bin / find-duplicated-sids.py
blob96b9aa4402ed7837a044dd01b5a627065cde5db6
1 #!/usr/bin/python
4 # Scan .hrc files for conflicting SID constants
6 # This is not as easy as it sounds because some of the constants depend on other
7 # constants whose names do not start with SID_
10 import subprocess
12 sidNameToValue = dict()
13 sidNameToOriginalLine = dict()
16 def extractSidValue(sidValue):
17 if isinstance(sidValue, int):
18 return sidValue
19 if sidValue.isdigit():
20 return int(sidValue)
21 if sidValue[0:2] == "0x":
22 return int(sidValue, 16)
23 if sidValue.find("+") != -1:
24 tokens = sidValue.split("+")
25 tokens1 = tokens[0].strip()
26 tokens2 = tokens[1].strip()
27 return extractSidValue(tokens1) + extractSidValue(tokens2)
28 rv = extractSidValue(sidNameToValue[sidValue])
29 sidNameToValue[sidValue] = rv
30 return rv
33 #a = subprocess.Popen(r"git grep -P '#define\s+(SID_|SC_|DETECTIVE_|DRAWTEXTBAR_|DRAW_BAR_|RID_|OBJBAR_FORMAT_|TAB_POPUP_|DATA_MENU_|EXTRA_MENU_|FORMAT_MENU_|INSERT_MENU_|VIEW_MENU_|EDIT_MENU_|FILE_MENU_|SC_FUNCTION_|RC_)'", stdout=subprocess.PIPE, shell=True)
34 a = subprocess.Popen(r"git grep -Pn '#define\s+(\S+)' -- *.hrc", stdout=subprocess.PIPE, shell=True)
36 with a.stdout as txt:
37 for line in txt:
38 originalLine = line.strip()
39 # strip the '#define' off the front
40 idx1 = line.find(" ")
41 line = line[idx1 : len(line)].strip()
42 # extract the name
43 idx1 = line.find(" ")
44 if (idx1 == -1):
45 continue
46 sidName = line[0:idx1].strip()
47 line = line[idx1:len(line)].strip()
48 # strip any trailing comments
49 idx1 = line.find("//")
50 if (idx1 != -1):
51 line = line[0:idx1].strip()
52 idx1 = line.find("/*")
53 if (idx1 != -1):
54 line = line[0:idx1].strip()
55 if len(line) == 0:
56 continue
57 # strip brackets
58 if line[0] == "(":
59 line = line[1:]
60 if line[len(line)-1] == ")":
61 line = line[0:len(line)-1]
62 sidTextValue = line.strip()
63 # ignore the #define strings
64 if (sidTextValue.find("\"") != -1):
65 continue
66 # ignore the multiline macros
67 if (sidTextValue.find("\\") != -1):
68 continue
69 # check for redefinitions
70 if sidName[0:4] == "SID_" and sidNameToValue.has_key(sidName):
71 print("Redefinition:\n\t", sidNameToOriginalLine[sidName], "\n\t" , originalLine)
72 else:
73 sidNameToValue[sidName] = sidTextValue
74 sidNameToOriginalLine[sidName] = originalLine
76 # decode the constants into their numeric values recursively
77 sidNamesToIgnore = set()
78 for sidName in sidNameToValue:
79 sidTextValue = sidNameToValue[sidName]
80 try:
81 sidValueNum = extractSidValue(sidTextValue)
82 sidNameToValue[sidName] = sidValueNum
83 except KeyError:
84 sidNamesToIgnore.add(sidName)
86 # check for conflicts
87 sidValueToName = dict()
88 for sidName in sidNameToValue:
89 if sidName in sidNamesToIgnore:
90 continue
91 if sidName[0:4] != "SID_":
92 continue
93 sidValue = sidNameToValue[sidName]
94 if sidValueToName.has_key(sidValue):
95 print("conflict:\n\t", sidNameToOriginalLine[sidName], "\n\t", sidNameToOriginalLine[sidValueToName[sidValue]])
96 else:
97 sidValueToName[sidValue] = sidName