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.