Register
It is currently Wed Nov 26, 2014 6:39 am

Need help writing AWK program that replace macro in my c++


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Sat Jun 14, 2014 9:36 am   

Joined: Sat Jun 14, 2014 9:19 am
Posts: 1
I’m have very big project in VS2010 C++ and we have a Macros in the code that I would like to get rid of
I want to write a program that go on all the files in a directory and sub-directory of the project and replace the macro to the desirable code.

I installed Cygwin and want to run a gawk.exe script the will do the job.
Is there anyone who can help me ?
10X

Code:
#define ABC_BEGIN_NAMESPACE            namespace ABC  {
#define ABC_BEGIN_NAMESPACE_1(___ns)      namespace ABC  { namespace ___ns  {
#define ABC_BEGIN_NAMESPACE_2(___ns1,___ns2)   namespace ABC  { namespace ___ns1 { namespace ___ns2 {
#define ABC_BEGIN_NAMESPACE_3(___ns1,___ns2,___ns3)   namespace ABC  { namespace ___ns1 { namespace ___ns2 { namespace ___ns3 {
#define ABC_BEGIN_NAMESPACE_4(___ns1,___ns2,___ns3,___ns4) namespace ABC  { namespace ___ns1 { namespace ___ns2 { namespace ___ns3 { namespace ___ns4 {
#define ABC_BEGIN_NAMESPACE_5(___ns1,___ns2,___ns3,___ns4,___ns5)   namespace ABC  { namespace ___ns1 { namespace ___ns2 { namespace ___ns3 { namespace ___ns4 { namespace ___ns5 {

#define ABC_END_NAMESPACE                                 }
#define ABC_END_NAMESPACE_1                                 }}
#define ABC_END_NAMESPACE_2                                 }}}
#define ABC_END_NAMESPACE_3                                 }}}}
#define ABC_END_NAMESPACE_4                                 }}}}}
#define ABC_END_NAMESPACE_5                                 }}}}}}


fileA.h
Code:
ABC_BEGIN_NAMESPACE
   class A {
   public:
      int m_a;
   };
ABC_END_NAMESPACE;

fileB.h
Code:
ABC_BEGIN_NAMESPACE_1(QWE)
class B {
public:
   A m_a;
   int m_b;
};
ABC_END_NAMESPACE_1;

After running the program should look like this

fileA.h
Code:
namespace ABC  {
   class A {
   public:
      int m_a;
   };
}};


fileB.h
Code:
namespace ABC  { namespace QWE {
class B {
public:
   A m_a;
   int m_b;
};
}};



Top
 Profile  
 PostPosted: Tue Oct 21, 2014 8:53 am   

Joined: Mon Oct 20, 2014 9:53 am
Posts: 16
Code:
# ATTENTION: this "sed" command does in place editing.
#   The original file is modified with no way back.
#   brave folks try without backup. unrecommended.
sed -rnis 's/^ABC_BEGIN_NAMESPACE$/namespace ABC {/;
           s/^ABC_BEGIN_NAMESPACE_.+\((.+)\)$/namespace ABC { namespace \1 {/;
           s/^ABC_END_NAMESPACE;/\}\};/;
           s/^ABC_END_NAMESPACE_[[:digit:]]+;/\}\};/;
           p
           '  file1 file2 *


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP