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 constants whose names do not start with SID_
12 sidNameToValue
= dict()
13 sidNameToOriginalLine
= dict()
16 def extractSidValue(sidValue
):
17 if isinstance(sidValue
, int):
19 if sidValue
.isdigit():
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
33 #a = subprocess.Popen("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("git grep -Pn '#define\s+(\S+)' -- *.hrc", stdout
=subprocess
.PIPE
, shell
=True)
38 originalLine
= line
.strip()
39 # strip the '#define' off the front
41 line
= line
[idx1
: len(line
)].strip()
44 if (idx1
== -1): continue
45 sidName
= line
[0 : idx1
].strip()
46 line
= line
[idx1
: len(line
)].strip()
47 # strip any trailing comments
48 idx1
= line
.find("//")
50 line
= line
[0 : idx1
].strip()
51 idx1
= line
.find("/*")
53 line
= line
[0 : idx1
].strip()
54 if len(line
) == 0: continue
56 if line
[0] == "(": line
= line
[1:]
57 if line
[len(line
)-1] == ")": line
= line
[0:len(line
)-1]
58 sidTextValue
= line
.strip()
59 # ignore the #define strings
60 if (sidTextValue
.find("\"") != -1): continue
61 # ignore the multiline macros
62 if (sidTextValue
.find("\\") != -1): continue
63 # check for redefinitions
64 if sidName
[0:4] == "SID_" and sidNameToValue
.has_key(sidName
):
65 print "Redefinition:\n\t", sidNameToOriginalLine
[sidName
], "\n\t" , originalLine
67 sidNameToValue
[sidName
] = sidTextValue
68 sidNameToOriginalLine
[sidName
] = originalLine
70 # decode the constants into their numeric values recursively
71 sidNamesToIgnore
= set()
72 for sidName
in sidNameToValue
:
73 sidTextValue
= sidNameToValue
[sidName
]
75 sidValueNum
= extractSidValue(sidTextValue
)
76 sidNameToValue
[sidName
] = sidValueNum
78 sidNamesToIgnore
.add(sidName
)
81 sidValueToName
= dict()
82 for sidName
in sidNameToValue
:
83 if sidName
in sidNamesToIgnore
: continue
84 if sidName
[0:4] != "SID_": continue
85 sidValue
= sidNameToValue
[sidName
]
86 if sidValueToName
.has_key(sidValue
):
87 print "conflict:\n\t", sidNameToOriginalLine
[sidName
], "\n\t", sidNameToOriginalLine
[sidValueToName
[sidValue
]]
89 sidValueToName
[sidValue
] = sidName