1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
#!/usr/bin/python
# Search for unused constants in .hrc files.
#
# Note that sometimes these constants are calculated, so some careful checking of the output is necessary.
#
# Takes about 4 hours to run this on a fast machine with an SSD
#
import subprocess
import sys
exclusionSet = set([
# List of RID constants where we compute a value using a base before calling one of the RESSTR methods
# Found with: git grep -P 'RID_\w+\s*\+' -- :/ ':!*.hrc' ':!*.src' ':!*.java' ':!*.py' ':!*.xba'
"RID_SVXSTR_KEY_",
"RID_SVXITEMS_SHADOW_",
"RID_SVXITEMS_BREAK_",
"RID_SVXITEMS_FRMDIR_",
"RID_SVXITEMS_COLOR",
"RID_SVXITEMS_HORJUST_",
"RID_SVXITEMS_VERJUST_",
"RID_SVXITEMS_JUSTMETHOD_",
"RID_SVXITEMS_ADJUST_",
"RID_SVXITEMS_WEIGHT_",
"RID_SVXITEMS_UL_",
"RID_SVXITEMS_OL_",
"RID_SVXITEMS_STRIKEOUT_",
"RID_SVXITEMS_CASEMAP_",
"RID_SVXITEMS_ESCAPEMENT_",
"RID_SVXITEMS_EMPHASIS_",
"RID_SVXITEMS_RELIEF_",
"RID_SVXITEMS_FRMDIR_",
"RID_UPDATE_BUBBLE_TEXT_",
"RID_UPDATE_BUBBLE_T_TEXT_",
"RID_SVXSTR_TBLAFMT_",
"RID_BMP_CONTENT_",
"RID_DROPMODE_",
"RID_BMP_LEVEL",
"RID_SVXSTR_BULLET_DESCRIPTION",
"RID_SVXSTR_SINGLENUM_DESCRIPTION",
"RID_SVXSTR_OUTLINENUM_DESCRIPTION",
"RID_SVXSTR_RULER_",
"RID_GALLERYSTR_THEME_",
"RID_SVXITEMS_ORI_",
"RID_SVXITEMS_PAGE_NUM_",
"RID_SVXSTR_BULLET_DESCRIPTION",
"RID_SVXSTR_SINGLENUM_DESCRIPTION",
"RID_SVXSTR_OUTLINENUM_DESCRIPTION",
# doing some weird stuff in svx/source/unodraw/unoprov.cxx involving mapping of UNO api names to translated names and back again
"RID_SVXSTR_GRDT",
"RID_SVXSTR_HATCH",
"RID_SVXSTR_BMP",
"RID_SVXSTR_DASH",
"RID_SVXSTR_LEND",
"RID_SVXSTR_TRASNGR",
# other places doing calculations
"RID_SVXSTR_DEPTH",
"RID_SUBSETSTR_",
"ANALYSIS_"
])
def in_exclusion_set( a ):
for f in exclusionSet:
if a.startswith(f):
return True;
return False;
a = subprocess.Popen("git grep -hP '^#define\s+\w+\s+' -- *.hrc | sort -u", stdout=subprocess.PIPE, shell=True)
with a.stdout as txt:
for line in txt:
idx1 = line.find("#define ")
idx2 = line.find(" ", idx1 + 9)
idName = line[idx1+8 : idx2]
# the various _START and _END constants are normally unused outside of the .hrc and .src files, and that's fine
if idName.endswith("_START"): continue
if idName.endswith("_BEGIN"): continue
if idName.endswith("_END"): continue
if idName.startswith("RID_"):
if idName == "RID_GROUPS_SFXOFFSET": continue
if idName == "RID_SVX_FIRSTFREE": continue
if in_exclusion_set(idName): continue
# search for the constant
b = subprocess.Popen(["git", "grep", "-wl", idName], stdout=subprocess.PIPE)
found_reason_to_exclude = False
with b.stdout as txt2:
for line2 in txt2:
line2 = line2.strip() # otherwise the comparisons below will not work
# check if we found one in actual code
if not line2.endswith(".hrc") and not line2.endswith(".src"): found_reason_to_exclude = True
if idName.startswith("RID_"):
# check that the constant is not being used as an identifier by entries in .src files
if line2.endswith(".src") and line2.find("Identifier = ") != -1: found_reason_to_exclude = True
# check that the constant is not being used by the property controller extension or reportdesigner inspection,
# which use macros to declare constants, hiding them from a search
if line2.find("extensions/source/propctrlr") != -1: found_reason_to_exclude = True
if line2.find("reportdesign/source/ui/inspection/inspection.src") != -1: found_reason_to_exclude = True
if idName.startswith("HID_"):
# check that the constant is not being used as an identifier by entries in .src files
if line2.endswith(".src") and line2.find("HelpId = ") != -1: found_reason_to_exclude = True
if not found_reason_to_exclude:
sys.stdout.write(idName + '\n')
# otherwise the previous line of output will be incorrectly mixed into the below git output, because of buffering
sys.stdout.flush()
# search again, so we log the location and filename of stuff we want to remove
subprocess.call(["git", "grep", "-wn", idName])
|