Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#/usr/bin/bash
# Add ifndef/define/endif to headers which use pragma once. I used
# it to edit some C++ project which wouldn't compile because the
# compiler didn't understand pragma once. SunCC, I'm looking at you!
~/bin/ack -l 'pragma once' | while read file; do
f="${file//\//_}"
f="${f//./_}"
f="$(echo "$f" | tr '[:lower:]' '[:upper:]')"
gsed -i "/#pragma once/ {
a#ifndef $f
a#define $f
}; \$a#endif /* $f */" $file
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment