Technical data

8. Documentation for Developers
The RegEx has (only) matched with “/bin/” (only this part of the line is contained in the
variable FGREP_MATCH_1). The first bracketed part in the expression only matches the first char
after the first “/”, this is why only “b” is contained in FGREP_MATCH_2. The second bracketed
part contains the rest after “b” up to the last “/”, hence “in” is noted in variable FGREP_MATCH_3.
The following second example demonstrates an usual use of fgrep taken from
check/base.ext. It will be tested if all tmpl:-references given in PF_FORWARD_x are really
present.
foreach n in pf_forward_n
do
set rule=pf_forward_%[n]
if (rule =~ "tmpl:([^[:space:]]+)")
then
foreach m in match_%
do
stat("$config_dir/etc/fwrules.tmpl/$m", tmplfile)
if(tmplfile_res == "OK")
then
add_to_opt "etc/fwrules.tmpl/$m"
else
stat("opt/etc/fwrules.tmpl/$m", tmplfile)
if(tmplfile_res == "OK")
then
add_to_opt "etc/fwrules.tmpl/$m"
else
fgrep("opt/etc/fwrules.tmpl/templates", "^$m[[:space:]]+")
if (fgrep_match_n == 0)
then
error "Can't find tmpl:$m for PF_FORWARD_${n}='$rule'!"
fi
fi
fi
done
fi
done
Both a filename value as well as a regular expression passed as a string constant are subject
to variable substitution (Page 300).
Splitting Parameters: split
Often variables can be assigned with several parameters, which then have to be split apart
again in the startup scripts. If it is desired to split these previously and perform tests on them
split can be used. The syntax is like this:
split (<String>, <Array>, <Separator>)
The string can be specified by a variable or directly as a constant. mkfli4l splits it where a
separator is found and generates an element of the array for each part. You may iterate over
these elements later on and perform tests. If nothing is found between two separators an array
element with an empty string as its value is created. The exception is ”: Here all spaces are
deleted and no empty variable is created.
307