-
-/* Copies from SRC to DST, calling INSERT_VARIABLE to handle each
- instance of $var or ${var} in SRC. $$ is replaced by $. */
-void
-fn_interp_vars (struct substring src,
- void (*insert_variable) (const char *var,
- struct string *dst, void *aux),
- void *aux, 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;
- char *var;
-
- 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);
-
- var = ss_xstrdup (var_name);
- insert_variable (var, &dst, aux);
- free (var);
- }
- }
-
- ds_swap (&dst, dst_);
- ds_destroy (&dst);
-}
-
-static void
-insert_env_var (const char *var, struct string *dst, void *aux UNUSED)
-{
- const char *value = fn_getenv (var);
- if (value != NULL)
- ds_put_cstr (dst, value);
-}
-
-/* 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. */