no warnings in lib-sys anymore
[apps/madmutt.git] / lib-sys / filter.c
index 193b2ad..90d9af2 100644 (file)
@@ -7,14 +7,8 @@
  * please see the file GPL in the top level source directory.
  */
 
  * please see the file GPL in the top level source directory.
  */
 
-#if HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <unistd.h>
-#include <stdlib.h>
-#include <sys/wait.h>
-#include <stdio.h>
+#include <lib-lib/lib-lib.h>
+#include <lib-ui/curses.h>
 
 #include "mutt_signal.h"
 #include "unix.h"
 
 #include "mutt_signal.h"
 #include "unix.h"
@@ -152,3 +146,31 @@ int mutt_wait_filter (pid_t pid)
 
   return rc;
 }
 
   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);
+}
+