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_
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(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)
38 originalLine
= line
.strip()
39 # strip the '#define' off the front
41 line
= line
[idx1
: len(line
)].strip()
46 sidName
= line
[0:idx1
].strip()
47 line
= line
[idx1
:len(line
)].strip()
48 # strip any trailing comments
49 idx1
= line
.find("//")
51 line
= line
[0:idx1
].strip()
52 idx1
= line
.find("/*")
54 line
= line
[0:idx1
].strip()
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):
66 # ignore the multiline macros
67 if (sidTextValue
.find("\\") != -1):
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
)
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
]
81 sidValueNum
= extractSidValue(sidTextValue
)
82 sidNameToValue
[sidName
] = sidValueNum
84 sidNamesToIgnore
.add(sidName
)
87 sidValueToName
= dict()
88 for sidName
in sidNameToValue
:
89 if sidName
in sidNamesToIgnore
:
91 if sidName
[0:4] != "SID_":
93 sidValue
= sidNameToValue
[sidName
]
94 if sidValueToName
.has_key(sidValue
):
95 print("conflict:\n\t", sidNameToOriginalLine
[sidName
], "\n\t", sidNameToOriginalLine
[sidValueToName
[sidValue
]])
97 sidValueToName
[sidValue
] = sidName