I am trying to parse C++ headers to delete any #ifdef inside a enum. i needed this because a headerParser module I am using has this bug of skipping any enum with #ifdef in it.
I have a shell script which collects the file and prepares it. then one python script is called to generate final output. The python file is generic, so I need to do the "#ifdef" block cleaning inside shell script only.
the text section looks like:
typedef enum fixedsample
{
element 1,
element 2,
element 3,
#ifdef XYZ
element 4,
element 5,
#endif
} FIXEDNAME;
I do not need the elements inside ifdef, so need to delete this. Also the enum name "fixedsample" and "FIXEDNAME" is true for any file, no variation will be there.
Can awk be used for this purpose? Any help is highly appriciated.
EDIT: "typedef enum ConstantName" and "}CONSTANT;" will be present in all files. so the #ifdef needs to be searched inside that block only. No other #ifdef will be removed.
awk
script that will work with your example input, but without seeing the rest of the header file it is impossible to tell if it will work under all conditions. What should happen with the#ifdef
in other places? Is the#ifdef
always written in exactly the same style? (indentation, different whitespace orif defined(XYZ)
...) Is theenum
always declared in combination withtypedef
? Istypedef enum somename
always in one single line? Please edit your question to add more details. You might be able to use the preprocessor remove the#ifdef
block.