Instantiate the amended code multiple times by successively binding
values to a variable
This instantiates the depending code snippet as often as their are tokens. For each of these instantiations the meta-variable ${NAME}
is bound to the corresponding token TOKENx
. See the description of regVar
how these tokens can be manipulated.
If :INDEX
is also present, the meta-variable ${INDEX}
is bound to the number of the current instance, instance counts starting at 0
.
Example
typdef enum coucou {
#pragma CMOD amend foreach COUCOU = ka ke ki kuku
${COUCOU},
#pragma CMOD amend done
} coucou;
Will generate four copies of the depending source where the appearance of the string ${COUCOU}
will be replaced by the each of the words in the list, that is
The following declares an array of names of these enumeration constants.
char const*coucouNames[] = {
#pragma CMOD amend foreach COUCOU:I = ka ke ki kuku
[${I}] = #${COUCOU},
#pragma CMOD amend done
}
is expanded to
Note that the #
in #${COUCOU}
forces it to be replaced by a string containing the value and that ${I}
is replaced by the position of the token in the list.
Coding and configuration
The following code is needed to enable the sh-module framework.SRC="$_" . "${0%%/${0##*/}}/import.sh"
Imports
The following sh
-modules are imported: