So I’ve got giant code base that needs to have a namespace added to it. Instead of doing this manually, I thought of using grep, xargs & sed to add the namespace to all source files…
But my skills are not up to par.
Ideally
namespace foo
{
Would be added after all the includes, and ‘}’ added after the #endif in the .h files.
For the .cpp files, adding ‘using namespace foo’ after all the includes would be sufficient.
I’ve been messing around with sed, but haven’t gotten very far.
Any help would be appreciated. Thanks!
This is not an easy task. Things that make it problematic include
language "C" { C-stuff }namespace Foo {and the closing ‘}’ can be tough.language C.templatedeclaration, if any, and of course doxygen comments and the like.Good luck! A script will take a bit more than a half an hour to write. It will take far less time than rewriting all your code. I suggest that you use something a tad more powerful than sed. Perl, python, and ruby are three good choices.