Next: tokmatch, Previous: str_varscan, Up: Strings
interpolates environmental variables into a string
#include <suplib/str.h>char *str_interp( const char *text, int keep_undef, const char **ustart, const char **uend, int *error );
const char *text
- the text to be interpolated into
int keep_undef
- if true, undefined variables are left in the text. if false, they are removed
const char **ustart
- if not NULL, set to the start of the undefined variable name
const char **uend
- if not NULL, set to the end of the undefined variable name
int *error
- error code
This routine scans a string for embedded environmental variables and returns a pointer to a copy of the string with the interpolated values. The user is responsible for freeing the new string.
The input string is scanned left to right for substrings of the
form ${VAR}
or $VAR
. VAR
must begin with an
alphabet character or the ‘_’ character. The remaining
characters must be alphabetic, numeric, or the ‘_’ character.
Upon success a pointer to the interpolated string is returned and
*error
is set to 0
. The user is responsible for
freeing the memory pointed to by the returned string.
If keep_undef
was set and there was an undefined variable,
then *errp
is set to EFAULT
and *ustart
and
*uend
point at the first and last characters in the variable
name. If multiple variables are undefined, they will point to the
first undefined variable name.
Upon error, NULL
is returned and *errp
is set to one
of the following
EDOM There was an unbalanced ‘
{’. *ustart is set
*uend
is
undefined.
ENOMEM
Diab Jerius