* Set development version to 2.3.29
[fvwm.git] / libs / envvar.h
blobebc963076578f949927dcc1b20a6b2dffd8c02c8
1 #ifndef FVWMLIB_ENVVAR_H
2 #define FVWMLIB_ENVVAR_H
4 /*-------------------------------------------------------------------------
6 * NAME envExpand
8 * FUNCTION Expand environment variables in a string.
10 * SYNOPSIS #include "envvar.h"
11 * int envExpand(char *s, int maxstrlen);
13 * INPUT s string to expand environment variables in.
14 * maxstrlen max length of string, including '\0'.
16 * OUTPUT s the string with environment variables expanded.
18 * RETURNS Number of changes done.
20 * NOTES A non-existing variable is substituted with the empty
21 * string.
24 int envExpand(char *s, int maxstrlen);
27 /*-------------------------------------------------------------------------
29 * NAME envDupExpand
31 * FUNCTION Expand environment variables into a new string.
33 * SYNOPSIS #include "envvar.h"
34 * char *envDupExpand(const char *s, int extra);
36 * INPUT s string to expand environment variables in.
37 * extra number of extra bytes to allocate in the
38 * string, in addition to the string contents
39 * and the terminating '\0'.
41 * RETURNS A dynamically allocated string with environment
42 * variables expanded.
43 * Use free() to deallocate the buffer when it is no
44 * longer needed.
45 * NULL is returned if there is not enough memory.
47 * NOTES A non-existing variable is substituted with the empty
48 * string.
51 char *envDupExpand(const char *s, int extra);
54 /*-------------------------------------------------------------------------
56 * NAME getFirstEnv
58 * FUNCTION Search for the first environment variable and return
59 * its contents and coordinates in the given string.
61 * INPUT s the string to scan.
62 * may include $ and { } that introduce variable.
64 * OUTPUT beg index in the string of matching $.
65 * end index in the string, first after matching var.
67 * RETURNS The variable contents; "" if env variable has legal name,
68 * but does not exist; or NULL if no env variables found.
69 * Returned constant string must not be deallocated.
71 * NOTE This function will only return `legal' variables. There
72 * may be $'s in the string that are not followed by what
73 * is considered a legal variable name introducer. Such
74 * occurrences are skipped.
75 * If nothing is found returns NULL and sets beg and end to 0.
77 * EXAMPLE getFirstEnv("echo $HOME/.fvwm2rc", &beg, &end)
78 * returns "/home/username" and beg=5, end=10.
81 const char* getFirstEnv(const char *s, int *beg, int *end);
84 #endif