-
-/* Substitutes $variables in SRC, putting the result in DST,
- properly handling the case where SRC is a substring of DST.
- Variables are as defined by GETENV. Supports $var and ${var}
- syntaxes; $$ substitutes as $. */
-void
-fn_interp_vars (struct substring src, const char *(*getenv) (const char *),
- struct string *dst_)
-{
- struct string dst = DS_EMPTY_INITIALIZER;
- int c;
-
- while ((c = ss_get_char (&src)) != EOF)
- if (c != '$')
- ds_put_char (&dst, c);
- else
- {
- if (ss_match_char (&src, '$') || ss_is_empty (src))
- ds_put_char (&dst, '$');
- else
- {
- struct substring var_name;
- size_t start;
- const char *value;
-
- if (ss_match_char (&src, '('))
- ss_get_until (&src, ')', &var_name);
- else if (ss_match_char (&src, '{'))
- ss_get_until (&src, '}', &var_name);
- else
- ss_get_chars (&src, MAX (1, ss_span (src, ss_cstr (CC_ALNUM))),
- &var_name);
-
- start = ds_length (&dst);
- ds_put_substring (&dst, var_name);
- value = getenv (ds_cstr (&dst) + start);
- ds_truncate (&dst, start);
-
- ds_put_cstr (&dst, value);
- }
- }
-
- ds_swap (&dst, dst_);
- ds_destroy (&dst);
-}
-
-/* Searches for a configuration file with name NAME in the path
- given by PATH, which is environment-interpolated.
- Directories in PATH are delimited by ':'. Returns the
- malloc'd full name of the first file found, or NULL if none is
- found. */
+/* Searches for a configuration file with name NAME in the directories given in
+ PATH, which is terminated by a null pointer. Returns the full name of the
+ first file found, which the caller is responsible for freeing with free(),
+ or NULL if none is found. */