I want to insert some text to my c++ file after certain line ( pattern ). The following is my file structure.
38 #include "stdlib.h"
39 #include "string.h"
40 #include "malloc.h"
41
...
324 void DMProcMon::threadManagerMonitorThread(DMProcMon* dmProcMon)
325 {
...
338 while (dmState == DVProcMon::Active &&
339 DmManService::getDCMRestartingFlag() == 0){
340 try{
342 setupTimerVerification(dmProcMon);
343 setupSignalVerification(dmProcMon);
344
....
360 }
I want to add code coverage macros using gcov. So basically what I need to achieve is
Add below text after all the #include statements.
45 #ifdef GCOV 46 extern "C" 47 void _gcov_flush(); 48 #endif
Add the below text after the while statement in the threadManagerMonitorThread function
#ifdef GCOV _gcov_flush(); #endif
So final code will loos like as below.
38 #include "stdlib.h"
39 #include "string.h"
40 #include "malloc.h"
41
45 #ifdef GCOV
46 _gcov_flush();
47 #endif
...
324 void DMProcMon::threadManagerMonitorThread(DMProcMon* dmProcMon)
325 {
...
338 while (dmState == DVProcMon::Active &&
339 DmManService::getDCMRestartingFlag() == 0){
340 try{
342 #ifdef GCOV
343 _gcov_flush();
344 #endif
346 setupTimerVerification(dmProcMon);
347 setupSignalVerification(dmProcMon);
348
....
360 }
What is the best way to do this. I would like to do this with either bash or pythyon.
Thanks ~S