3 # Search for unused constants in header files.
5 # Note that sometimes these constants are calculated, so some careful checking of the output is necessary.
7 # Takes about 4 hours to run this on a fast machine with an SSD
15 # List of RID constants where we compute a value using a base before calling one of the RESSTR methods
16 # Found with: git grep -P 'RID_\w+\s*\+' -- :/ ':!*.hrc' ':!*.src' ':!*.java' ':!*.py' ':!*.xba'
18 "RID_UPDATE_BUBBLE_TEXT_",
19 "RID_UPDATE_BUBBLE_T_TEXT_",
20 "RID_SVXSTR_TBLAFMT_",
24 "RID_SVXSTR_BULLET_DESCRIPTION",
25 "RID_SVXSTR_SINGLENUM_DESCRIPTION",
26 "RID_SVXSTR_OUTLINENUM_DESCRIPTION",
28 "RID_GALLERYSTR_THEME_",
29 "RID_SVXSTR_BULLET_DESCRIPTION",
30 "RID_SVXSTR_SINGLENUM_DESCRIPTION",
31 "RID_SVXSTR_OUTLINENUM_DESCRIPTION",
32 # doing some weird stuff in svx/source/unodraw/unoprov.cxx involving mapping of UNO api names to translated names and back again
39 # other places doing calculations
56 "STR_AUTH_FIELD_ADDRESS_",
75 "PRICING_DEFFUNCNAME_",
81 "STR_ItemValFITTOSIZE",
82 "STR_ItemValMEASURE_",
83 "STR_ItemValMEASURETEXT_",
84 "STR_ItemValTEXTANI_",
85 "STR_ItemValTEXTHADJ",
86 "STR_ItemValTEXTVADJ",
87 "RID_SVXITEMS_VERJUST",
89 "RID_SVXITEMS_JUSTMETHOD",
90 "RID_SVXITEMS_HORJUST",
95 def in_exclusion_set( a
):
96 for f
in exclusionSet
:
101 # find defines, excluding the externals folder
102 a
= subprocess
.Popen("git grep -hP '^#define\\s+\\w\\w\\w\\w+\\s*' -- \"[!e][!x][!t]*\" | sort -u", stdout
=subprocess
.PIPE
, shell
=True)
104 name_re
= re
.compile(r
"#define\s+(\w+)")
105 with a
.stdout
as txt
:
107 idName
= name_re
.match(line
).group(1)
108 if idName
.startswith("INCLUDED_"): continue
109 # the various _START and _END constants are normally unused outside of the .hrc and .src files, and that's fine
110 if idName
.endswith("_START"): continue
111 if idName
.endswith("_BEGIN"): continue
112 if idName
.endswith("_END"): continue
113 if idName
== "RID_SVX_FIRSTFREE": continue
114 if idName
== "": continue
115 if idName
.startswith("__com"): continue # these are the include/header macros for the UNO stuff
116 if in_exclusion_set(idName
): continue
117 # search for the constant
118 b
= subprocess
.Popen(["git", "grep", "-w", idName
], stdout
=subprocess
.PIPE
)
119 found_reason_to_exclude
= False
120 with b
.stdout
as txt2
:
123 line2
= line2
.strip() # otherwise the comparisons below will not work
124 # ignore if/undef magic, does not indicate an actual use (most of the time)
125 if "ifdef" in line2
: continue
126 if "undef" in line2
: continue
127 # ignore commented out code
128 if line2
.startswith("//"): continue
129 if line2
.startswith("/*"): continue
130 # check if we found one in actual code
131 if idName
.startswith("SID_"):
132 if not ".hrc:" in line2
and not ".src:" in line2
and not ".sdi:" in line2
: found_reason_to_exclude
= True
134 if not ".hrc:" in line2
and not ".src:" in line2
: found_reason_to_exclude
= True
135 if idName
.startswith("RID_"):
136 # is the constant being used as an identifier by entries in .src files?
137 if ".src:" in line2
and "Identifier = " in line2
: found_reason_to_exclude
= True
138 # is the constant being used by the property controller extension or reportdesigner inspection,
139 # which use macros to declare constants, hiding them from a search
140 if "extensions/source/propctrlr" in line2
: found_reason_to_exclude
= True
141 if "reportdesign/source/ui/inspection/inspection.src" in line2
: found_reason_to_exclude
= True
142 if idName
.startswith("HID_"):
143 # is the constant being used as an identifier by entries in .src files
144 if ".src:" in line2
and "HelpId = " in line2
: found_reason_to_exclude
= True
145 # is it being used as a constant in an ItemList in .src files?
146 if ".src:" in line2
and (";> ;" in line2
or "; >;" in line2
): found_reason_to_exclude
= True
147 # these are used in calculations in other .hrc files
148 if "sw/inc/rcid.hrc:" in line2
: found_reason_to_exclude
= True
150 if "sw/source/uibase/inc/ribbar.hrc:" in line2
and "ST_" in idName
: found_reason_to_exclude
= True
151 if "sw/source/uibase/inc/ribbar.hrc:" in line2
and "STR_IMGBTN_" in idName
: found_reason_to_exclude
= True
152 if "sw/source/core/undo/undo.hrc:" in line2
: found_reason_to_exclude
= True
153 if "sw/inc/poolfmt.hrc:" in line2
: found_reason_to_exclude
= True
154 # used via a macro that hides them from search
155 if "dbaccess/" in line2
and idName
.startswith("PROPERTY_ID_"): found_reason_to_exclude
= True
156 if "reportdesign/" in line2
and idName
.startswith("HID_RPT_PROP_"): found_reason_to_exclude
= True
157 if "reportdesign/" in line2
and idName
.startswith("RID_STR_"): found_reason_to_exclude
= True
158 if "forms/" in line2
and idName
.startswith("PROPERTY_"): found_reason_to_exclude
= True
159 if "svx/source/tbxctrls/extrusioncontrols.hrc:" in line2
and idName
.startswith("DIRECTION_"): found_reason_to_exclude
= True
160 if "svx/source/tbxctrls/extrusioncontrols.hrc:" in line2
and idName
.startswith("FROM_"): found_reason_to_exclude
= True
161 # if we see more than a few lines then it's probably one of the BASE/START/BEGIN things
163 if cnt
> 2: found_reason_to_exclude
= True
164 if not found_reason_to_exclude
:
166 # otherwise the previous line of output will be incorrectly mixed into the below git output, because of buffering
168 # search again, so we log the location and filename of stuff we want to remove
169 subprocess
.call(["git", "grep", "-wn", idName
])