2

I want to parse and get the list of definitions(#define) in c header file.

I know there are many python modules but I couldn't find parse pre-processors like "#if", "#undef".

If header file is as below:

#define ABC
#define DEF
#define CONDITION
#ifdef CONDITION
#undef DEF
#define HIJ
#endif

I want to get the list as below:

ABC, CONDITION, HIJ  // no DEF

Do you have any idea for this?

ChangUZ
  • 5,380
  • 10
  • 46
  • 64

1 Answers1

1

I found out (but not using python).

echo | g++ -dM -E my_header.h | sort > out.txt

including my_path

echo | g++ -dM -E -I"my_path" my_header.h | sort > out.txt

ChangUZ
  • 5,380
  • 10
  • 46
  • 64