#!/usr/bin/perl # # Given a C #define, surround it with # #ifndef foo # #define foo # #endif for (<>) { if (/^#(\s*)define(\s+)([A-Za-z0-9_]*)/) { print "#$1ifndef$2$3\n"; print; print "#endif\n"; } }