and even less very old hacks.
[apps/madmutt.git] / filter.c
index 056fbdd..530f16f 100644 (file)
--- a/filter.c
+++ b/filter.c
@@ -1,20 +1,15 @@
 /*
+ * Copyright notice from original mutt:
  * Copyright (C) 1996-2000 Michael R. Elkins.
- * 
- *     This program is free software; you can redistribute it and/or modify
- *     it under the terms of the GNU General Public License as published by
- *     the Free Software Foundation; either version 2 of the License, or
- *     (at your option) any later version.
- * 
- *     This program is distributed in the hope that it will be useful,
- *     but WITHOUT ANY WARRANTY; without even the implied warranty of
- *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *     GNU General Public License for more details.
- * 
- *     You should have received a copy of the GNU General Public License
- *     along with this program; if not, write to the Free Software
- *     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
- */ 
+ *
+ * This file is part of mutt-ng, see http://www.muttng.org/.
+ * It's licensed under the GNU General Public License,
+ * please see the file GPL in the top level source directory.
+ */
+
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include "mutt.h"
 
  * to the specified handles.
  */
 pid_t
-mutt_create_filter_fd (const char *cmd, FILE **in, FILE **out, FILE **err,
-                      int fdin, int fdout, int fderr)
+mutt_create_filter_fd (const char *cmd, FILE ** in, FILE ** out, FILE ** err,
+                       int fdin, int fdout, int fderr)
 {
   int pin[2], pout[2], perr[2], thepid;
 
-  if (in)
-  {
+  if (in) {
     *in = 0;
     if (pipe (pin) == -1)
       return (-1);
   }
 
-  if (out)
-  {
+  if (out) {
     *out = 0;
-    if (pipe (pout) == -1)
-    {
-      if (in)
-      {
-       close (pin[0]);
-       close (pin[1]);
+    if (pipe (pout) == -1) {
+      if (in) {
+        close (pin[0]);
+        close (pin[1]);
       }
       return (-1);
     }
   }
 
-  if (err)
-  {
+  if (err) {
     *err = 0;
-    if (pipe (perr) == -1)
-    {
-      if (in)
-      {
-       close (pin[0]);
-       close (pin[1]);
+    if (pipe (perr) == -1) {
+      if (in) {
+        close (pin[0]);
+        close (pin[1]);
       }
-      if (out)
-      {
-       close (pout[0]);
-       close (pout[1]);
+      if (out) {
+        close (pout[0]);
+        close (pout[1]);
       }
       return (-1);
     }
@@ -73,67 +60,56 @@ mutt_create_filter_fd (const char *cmd, FILE **in, FILE **out, FILE **err,
 
   mutt_block_signals_system ();
 
-  if ((thepid = fork ()) == 0)
-  {
+  if ((thepid = fork ()) == 0) {
     mutt_unblock_signals_system (0);
 
-    if (in)
-    {
+    if (in) {
       close (pin[1]);
       dup2 (pin[0], 0);
       close (pin[0]);
     }
-    else if (fdin != -1)
-    {
+    else if (fdin != -1) {
       dup2 (fdin, 0);
       close (fdin);
     }
 
-    if (out)
-    {
+    if (out) {
       close (pout[0]);
       dup2 (pout[1], 1);
       close (pout[1]);
     }
-    else if (fdout != -1)
-    {
+    else if (fdout != -1) {
       dup2 (fdout, 1);
       close (fdout);
     }
 
-    if (err)
-    {
+    if (err) {
       close (perr[0]);
       dup2 (perr[1], 2);
       close (perr[1]);
     }
-    else if (fderr != -1)
-    {
+    else if (fderr != -1) {
       dup2 (fderr, 2);
       close (fderr);
     }
 
-    execl (EXECSHELL, "sh", "-c", cmd, NULL);
+    execl ("/bin/sh", "sh", "-c", cmd, NULL);
     _exit (127);
   }
-  else if (thepid == -1)
-  {
+  else if (thepid == -1) {
     mutt_unblock_signals_system (1);
 
-    if (in)
-    {
+    if (in) {
       close (pin[0]);
       close (pin[1]);
     }
-    
-    if (out)
-    {
+
+    if (out) {
       close (pout[0]);
       close (pout[1]);
     }
 
-    if (err)
-    {
+    if (err) {
       close (perr[0]);
       close (perr[1]);
     }
@@ -141,20 +117,17 @@ mutt_create_filter_fd (const char *cmd, FILE **in, FILE **out, FILE **err,
     return (-1);
   }
 
-  if (out)
-  {
+  if (out) {
     close (pout[1]);
     *out = fdopen (pout[0], "r");
   }
 
-  if (in)
-  {
+  if (in) {
     close (pin[0]);
     *in = fdopen (pin[1], "w");
   }
 
-  if (err)
-  {
+  if (err) {
     close (perr[1]);
     *err = fdopen (perr[0], "r");
   }
@@ -162,7 +135,7 @@ mutt_create_filter_fd (const char *cmd, FILE **in, FILE **out, FILE **err,
   return (thepid);
 }
 
-pid_t mutt_create_filter (const char *s, FILE **in, FILE **out, FILE **err)
+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));
 }
@@ -170,10 +143,10 @@ pid_t mutt_create_filter (const char *s, FILE **in, FILE **out, FILE **err)
 int mutt_wait_filter (pid_t pid)
 {
   int rc;
-  
+
   waitpid (pid, &rc, 0);
   mutt_unblock_signals_system (1);
   rc = WIFEXITED (rc) ? WEXITSTATUS (rc) : -1;
-  
+
   return rc;
 }