Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 6871123591698337ee06efa6a871ef7b > files > 22

cfengine3-base-3.0.2-1mdv2010.0.i586.rpm

######################################################################
#
# File editing - back reference
#
######################################################################


body common control

{
version => "1.2.3";
bundlesequence  => { "testbundle"  };
}

########################################################

bundle agent testbundle

{
files:

  # The back reference in a path only applies to the last link
  # of the pathname, so the (tmp) gets ignored

  "/home/mark/(tmp)/(cf3)_(.*)"
       create    => "true",
       edit_line => myedit("second $(match.2)");


  # but ...

#  "/home/mark/(tmp)/cf3_test"
#       create    => "true",
#       edit_line => myedit("second $(match.1)");


}

########################################################

bundle edit_line myedit(parameter)
  {
  vars:

   "edit_variable" string => "private edit variable is $(parameter)"; 

  insert_lines:

     "$(edit_variable)";
  
  replace_patterns:

  # replace shell comments with C comments

   "#(.*)"

      replace_with => C_comment,
     select_region => MySection("New section");

  }

########################################
# Bodies
########################################

body replace_with C_comment

{
replace_value => "/* $(match.1) */"; # backreference 0
occurrences => "all";  # first, last all
}

########################################################

body select_region MySection(x)

{
select_start => "\[$(x)\]";
select_end => "\[.*\]";
}