Wednesday, 15 January 2014

grep - Find include guard typos in C++ with gnu coreutils -



grep - Find include guard typos in C++ with gnu coreutils -

below typo c++ include guard. both should read _myfile_h_.

#ifndef _myfile_h_ #define _myflie_h_

how suggest searching bunch of header files typo using gnu coreutils (e.g. grep, awk)?

you utilize awk:

{ if ($1 == "#ifndef") { was_ifdef = 1; def = $2 } else if ($1 == "#define" && was_ifdef) { if ($2 != def) printf("mismatch in %s: expected %s found %s\n", filename, def, $2); } else was_ifdef = 0; }

there may more clever ways this, (to me) quite clear , easy.

note: show "false positives" if file contains

#ifndef foo_defined typedef int foo; #define foo_defined #endif

c++ grep include-guards gnu-coreutils

No comments:

Post a Comment