sh - Easiest way to check for include -



sh - Easiest way to check for include -

i check cpp files contain

#include <stdafx.h>

since not want thing fail, when e.g. comments in front end of include, prefer way of checking, honors actual c++ syntax. can done (in cross-platform way (using cygwin sh on windows))?

cpp, c preprocessor gnu compiler collection, has -m flag lists files c file depends on, i.e. headers includes. run cpp on files, filter out stdafx.h. don't utilize cygwin, believe should work:

find . -type f -name "*.cpp" -exec sh -c "echo {} && cpp -m {} | grep -c stdafx.h" \;

this finds every file name ends cpp, executes shell in turn echoes file name we're looking at. runs through cpp, grepping cpp's output header we're looking , counting lines. output should (looking stdio.h in git source tree):

./diff.c 0 ./gettext.c 1 ./gpg-interface.c 0 ./hashmap.c 0 ./hex.c 0 ./environment.c 0 ./remote-testsvn.c 0 ./server-info.c 0 ./compat/fopen.c 1 ./compat/basename.c 1 ./compat/strtoimax.c 1 ./compat/hstrerror.c 1 ./compat/pread.c 1 ./compat/gmtime.c 1 ./compat/setenv.c 1

of course, if want check single file, don't need whole find invocation, can "cpp -m myfile.cpp | grep -c stdafx.h" give either 0 if it's not in there or 1 if is.

sh

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -