diff --git a/src/include/config.h b/src/include/config.h index a5904c8..e9f334b 100644 --- a/src/include/config.h +++ b/src/include/config.h @@ -5,5 +5,8 @@ #define AUTOESCAPE_CHAR '\\' #define NOMINIFY_CHAR '&' #define SEPARATOR_CHAR ',' +#define SHELL_CHAR '$' + +#define ALLOW_SHELL #define MAX_INCLUDE_DEPTH 10 diff --git a/src/parse.c b/src/parse.c index b93935e..8dd949c 100644 --- a/src/parse.c +++ b/src/parse.c @@ -1,3 +1,9 @@ +#include + +#ifdef ALLOW_SHELL +#define _POSIX_C_SOURCE 2 +#endif + #include #include #include @@ -6,8 +12,6 @@ #include #include -#include - struct var { struct string *var; struct string *value; @@ -128,6 +132,26 @@ autoescapeend: fputc(data->data[i], out); } break; +#ifdef ALLOW_SHELL + case SHELL_CHAR: { + FILE *process; + long start; + start = ++i; + while (data->data[i] != ESCAPE_CHAR) + ++i; + data->data[i] = '\0'; + process = popen(data->data + start, "r"); + for (;;) { + int c; + c = fgetc(process); + if (c == EOF) + break; + mputc(&s, c, out); + } + pclose(process); + break; + } +#endif } } else @@ -165,6 +189,7 @@ static int expandfile(struct expandfile *ret, char *filename, int level) { goto error; break; case VAR_CHAR: case AUTOESCAPE_CHAR: case NOMINIFY_CHAR: + case SHELL_CHAR: if (appendchar(ret->data, ESCAPE_CHAR)) goto error; for (;;) {