X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=lib-sys%2Ffilter.c;h=f2d6086f9c071108045d9e3b305c9e0a26088039;hp=193b2adea99cd5cc9faccede5cb5f96da0a57a7b;hb=bb8c11821cc88fef9da474587cc42e0f7554cf28;hpb=96e4b6de291b2195b26289fb03536acd101c6650 diff --git a/lib-sys/filter.c b/lib-sys/filter.c index 193b2ad..f2d6086 100644 --- a/lib-sys/filter.c +++ b/lib-sys/filter.c @@ -7,14 +7,8 @@ * please see the file GPL in the top level source directory. */ -#if HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include -#include -#include +#include +#include #include "mutt_signal.h" #include "unix.h" @@ -31,7 +25,7 @@ mutt_create_filter_fd (const char *cmd, FILE ** in, FILE ** out, FILE ** err, if (in) { *in = 0; if (pipe (pin) == -1) - return (-1); + return -1; } if (out) { @@ -41,7 +35,7 @@ mutt_create_filter_fd (const char *cmd, FILE ** in, FILE ** out, FILE ** err, close (pin[0]); close (pin[1]); } - return (-1); + return -1; } } @@ -56,7 +50,7 @@ mutt_create_filter_fd (const char *cmd, FILE ** in, FILE ** out, FILE ** err, close (pout[0]); close (pout[1]); } - return (-1); + return -1; } } @@ -116,7 +110,7 @@ mutt_create_filter_fd (const char *cmd, FILE ** in, FILE ** out, FILE ** err, close (perr[1]); } - return (-1); + return -1; } if (out) { @@ -134,12 +128,12 @@ mutt_create_filter_fd (const char *cmd, FILE ** in, FILE ** out, FILE ** err, *err = fdopen (perr[0], "r"); } - return (thepid); + return thepid; } pid_t mutt_create_filter (const char *s, FILE ** in, FILE ** out, FILE ** err) { - return (mutt_create_filter_fd (s, in, out, err, -1, -1, -1)); + return mutt_create_filter_fd (s, in, out, err, -1, -1, -1); } int mutt_wait_filter (pid_t pid) @@ -152,3 +146,31 @@ int mutt_wait_filter (pid_t pid) return rc; } + +/* This function allows the user to specify a command to read stdout from in + place of a normal file. If the last character in the string is a pipe (|), + then we assume it is a commmand to run instead of a normal file. */ +FILE *mutt_open_read (const char *path, pid_t * thepid) +{ + int len = m_strlen(path); + FILE *f; + + if (path[len - 1] == '|') { + char *s = m_strdup(path); + + /* read from a pipe */ + + s[len - 1] = 0; + mutt_endwin (NULL); + *thepid = mutt_create_filter (s, NULL, &f, NULL); + p_delete(&s); + } else { + f = fopen (path, "r"); + if (!f) + return NULL; + *thepid = -1; + } + + return f; +} +