Ad-vic
Ad-vic

Reputation: 529

perl - need to add function arguments list in a template inside .c file

perl - need to add set of lines into a file

This was my original question.

I have slight variation in question now. I am trying for long time but unable to fix it.

pChainCtrl 
pChainName 
pDef 

pChainCtrl 
pArgs 

pChainCtrl
pChainCtrl 
name 
pChainTable

These are arguments of few functions,Need to add them to a function template inside .c file in front of "@param[in ]"

PART OF .C FILE

/**
********************************************************************************
 *  @fn ChainCtrlSetJpgSnapshotFile                                             
 *  @brief
 *  @param[in ]    //arguments needs to be added here                 
 *  @return
********************************************************************************
*/
eErrorT ChainCtrlSetJpgSnapshotFile(ChainCtrlT* pChainCtrl, RouteListItemT* pRoute, char * dst_chain, char *jpg_file_path)
{
  ............
}

/**
********************************************************************************
 *  @fn ChainCtrlSetBgFile                                                      
 *  @brief
 *  @param[in ]         //arguments needs to be added here
 *  @return
********************************************************************************
*/
eErrorT ChainCtrlSetBgFile(ChainCtrlT* pChainCtrl, RouteListItemT* pRoute, char * dst_chain, char *bg_file_path)
{
  ....
}
/**
********************************************************************************
 *  @fn ChainCtrlSetColorBar                                                    
 *  @brief
 *  @param[in ]    //arguments needs to be added here                       
 *  @return
********************************************************************************
*/
eErrorT ChainCtrlSetColorBar(ChainCtrlT* pChainCtrl, RouteListItemT* pRoute, char * dst_chain,Boolean bOnOff)
{
  ..........
}

I tried the code shared by user @mpapec

But it adds arguments only in the first function.

use strict;
use warnings;

open(my $FILE4, "<", "chaincontroller.c") or die $!;
my $tl = do { local $/; <$FILE4> };
$tl =~ s|\s+$||mg;

open (my $FILE3, "<", "functions2.txt") or die $!;
my @array1 = map [ split ],
  do { local $/ = ""; <$FILE3> };

for my $arg (@array1) {
  my $s = $tl;
  $s =~ s|(param.+)|"$1   ". join "\n                 ", @$arg |e;
  print $s;
}

Upvotes: 0

Views: 65

Answers (1)

mpapec
mpapec

Reputation: 50637

Try replacing for loop with,

$tl =~ s{(\@param.+)}{
  "$1   ". join "\n                 ", @{ shift @array1 };
}ge;
print $tl;

Upvotes: 1

Related Questions