Branch libreoffice-5-0-4
[LibreOffice.git] / bin / find-unused-defines.sh
blob6c07de4aeea52beddd9af776e7b683baf78fa01c
2 # This is a pretty brute-force approach. It takes several hours to run on a top-spec MacbookAir.
3 # It also produces some false positives, so it requires careful examination and testing of the results.
5 # Algorithm Summary:
6 # First we find all #defines,
7 # then we search for each of them in turn,
8 # and if we find only one instance of a #define, we print it out.
10 # Algorithm Detail:
11 # (1) find #defines, excluding the externals folder
12 # (2) extract just the constant name from the search results
13 # (3) trim blank lines
14 # (4) sort the results, mostly so I have an idea how far along the process is
15 # (5) for each result:
16 # (6) grep for the constant
17 # (7) use awk to to check if only one match for a given constant was found
18 # (8) if so, generate a sed command to remove the #define
20 git grep -P '^#define\s+\w+\s+\w' -- "[!e][!x][!t]*" \
21 | cut -s -d ' ' -f 2 \
22 | sed '/^$/d' \
23 | sort \
24 | xargs -Ixxx sh -c \
25 "git grep -w 'xxx' | awk -f bin/find-unused-defines.awk -v p1=xxx && echo \"xxx\" 1>&2"