I am trying to write one regexp to match C preprocessor commands in C program. I wonder if you can give me some suggestions?
Thank you so much in advance.
That would be
grep '^[[:blank:]]*#'
Note that this will only grep the first line of a multi line preprocessor directive (continued with backslash newline).
# or %: token following a newline, to just before the next newline. Whether the inside of the directive is well-formed is another matter. The other shortcoming of this approach is that it doesn't allow a comment before the #, but seriously who cares.May be this: (not too exact though)
\s*#\s*(define|error|import|undef|elif|if|include|using|else|ifdef|line|endif|ifndef|pragma)\s*\S*
You can use cpp and pass the option -dM to list out all defined macros.
cpp -dM test.c
awk. This didn't change recently.