[kw-pm] how to *delete* all "#if 0" content from a source tree
Robert P. J. Day
rpjday at mindspring.com
Sun Mar 18 09:15:59 PDT 2007
On Sun, 18 Mar 2007, fishbot wrote:
> I've used Text::Balanced (which is core, incidentally, though I
> forget the as-of) at $work to great effect, though understanding the
> API can be a challenge, particularly if you want to do more than
> basic things.
>
> Adding to the trickiness here is that you actually want to track all
> the #if * ... #endif blocks, but you are only interested in the ones
> starting with #if 0. That is, you have to track all the nestings,
> then prune that list. And the interesting #if 0s might be nested in
> uninteresting #ifs, or vice-versa.
>
> Also, modern compilers let you have whitespace before the '#' and
> between the '#' and the 'if' and 'endif'. Plus #endif can be for
> #ifs or #ifdefs, etc.
and on top of that, it's possible to have:
#if 0
... blah blah ...
#else
... woof woof ...
#endif
and the simplification should leave "woof woof" in the file. yes, it
gets ugly in a hurry, doesn't it?
> So, it's not a trivial challenge. In theory, Text::Balanced
> extract_tagged/get_extract_tagged, but damned if I can get it to
> work at all.
>
> I rolled my own, I've tested it... just prints the before and after
> right now, but making it replace files, recurse directories is just
> a SMOP.
>
> Code review/opinions welcome. It's just a Sunday morning
> coffee-hack, so it doesn't handle extreme cases. It's sloppy with
> what it accepts as #ifs. Sort of cool is that if you decide you
> want to expunge #ifdef DEBUG etc. as well, it's just a matter of
> altering is_interesting().
ok, i'll check this when i get a chance. thanks.
rday
More information about the kw-pm
mailing list