0

I am a newbie to creating scripts. I am working in a C language based software project. One of the problems is that there are a lot of unused #define constant definitions in the project and I have created a windows script to find the unused #defines as given below:

rem /*Extract all the lines with #defines to log.txt */
findstr "#define" *.h >log.txt

rem /*Extract all the 'tokens' from log.txt to log2.txt */
FOR /F "tokens=2 delims= " %%G IN (log.txt) DO @echo %%G >>log2.txt

rem /*Search through the *.c files in the folder to see if the */
rem /*tokens from log2.txt are used. If not, print them to log5.txt  */
for /F %%i in (log2.txt) do (
findstr /M /C:%%i *.c
If ERRORLEVEL 1 echo %%i >>log5.txt )

The problem with the above script is that it does not check whether the pre-processor constant is actually used in a source code line or in a Comment line (/* */). Please can someone help? Also, I appreciate any suggestions to simplify the script or point out any drawbacks.

henrycarteruk
  • 12,708
  • 2
  • 36
  • 40
  • That's not the only problem. It also doesn't check if a `#define`-ed identifier is used in any of the header files that are (recursively) `#include`-ed by the `.c` files you are examining. – Mike Kinghan Dec 02 '16 at 19:59
  • Yes, you are correct !! – AGLakshmanan Dec 08 '16 at 08:21
  • ...and the header files that get `#include-ed` are only determined by the `-D` and `-I` options that are passed to the compiler *when you compile the code*. – Mike Kinghan Dec 08 '16 at 10:38

0 Answers0