Q:

Easiest way to check for include

I would like to check for cpp files to contain
#include <stdafx.h>

Since I do not want this thing to fail, when e.g. comments are in front of the include, I would prefer a way of checking, that honors the actual c++ syntax.
Can this be easily done (in a cross-platform way (using cygwin sh on Windows))?

A:

cpp, the C preprocessor from the GNU compiler collection, has an -M flag that lists the files a C file depends on, i.e. the headers it includes. You could run cpp on all your files, then filter out stdafx.h. I don't personally use Cygwin, but I believe something like this should work:
find . -type f -name "*.cpp" -exec sh -c "echo {} && cpp -M {} | grep -c stdafx.h" \;

This finds every file with a name that ends with cpp, then executes a shell that in turn echoes the file name we're looking at. It then runs it through cpp, finally grepping cpp's output for the header we're looking for and counting the lines. The output should look something like this (looking for stdio.h in the 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 you only want to check a single file, you don't need the whole find invocation, you can just do "cpp -M myfile.cpp | grep -c stdafx.h" which will give you either a 0 if it's not in there or a 1 if it is.

