]> diplodocus.org Git - nmh/blobdiff - uip/mhlsbr.c
eliminate use of fgets() in mhparse.c
[nmh] / uip / mhlsbr.c
index 6a1c3db7878ef0e2121c1bc25c8c30fda167e073..e9d4de8eb8f0cc7854733235663c9d700afecd05 100644 (file)
@@ -332,7 +332,6 @@ static void pipeser (int);
 static void quitser (int);
 static void mhladios (char *, char *, ...);
 static void mhldone (int);
 static void quitser (int);
 static void mhladios (char *, char *, ...);
 static void mhldone (int);
-static void m_popen (char *);
 static void filterbody (struct mcomp *, char *, int, int, FILE *,
                         m_getfld_state_t);
 static void compile_formatfield(struct mcomp *);
 static void filterbody (struct mcomp *, char *, int, int, FILE *,
                         m_getfld_state_t);
 static void compile_formatfield(struct mcomp *);
@@ -349,11 +348,9 @@ mhl (int argc, char **argv)
     char buf[BUFSIZ], *files[MAXARGS];
     char **argp, **arguments;
 
     char buf[BUFSIZ], *files[MAXARGS];
     char **argp, **arguments;
 
+    /* Need this if called from main() of show(1). */
     invo_name = r1bindex (argv[0], '/');
 
     invo_name = r1bindex (argv[0], '/');
 
-    /* read user profile/context */
-    context_read();
-
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
 
@@ -484,7 +481,7 @@ mhl (int argc, char **argv)
                SIGNAL2 (SIGQUIT, quitser);
            }
            SIGNAL2 (SIGPIPE, pipeser);
                SIGNAL2 (SIGQUIT, quitser);
            }
            SIGNAL2 (SIGPIPE, pipeser);
-           m_popen (moreproc);
+           m_popen (moreproc, mhl_action != NULL);
            ontty = PITTY;
        } else {
            SIGNAL (SIGINT, SIG_IGN);
            ontty = PITTY;
        } else {
            SIGNAL (SIGINT, SIG_IGN);
@@ -1646,74 +1643,6 @@ mhldone (int status)
 }
 
 
 }
 
 
-static int m_pid = NOTOK;
-static  int sd = NOTOK;
-
-static void
-m_popen (char *name)
-{
-    int pd[2];
-    char *file;
-    char **arglist;
-
-    if (mhl_action && (sd = dup (fileno (stdout))) == NOTOK)
-       adios ("standard output", "unable to dup()");
-
-    if (pipe (pd) == NOTOK)
-       adios ("pipe", "unable to");
-
-    switch (m_pid = fork()) {
-       case NOTOK: 
-           adios ("fork", "unable to");
-
-       case OK: 
-           SIGNAL (SIGINT, SIG_DFL);
-           SIGNAL (SIGQUIT, SIG_DFL);
-
-           close (pd[1]);
-           if (pd[0] != fileno (stdin)) {
-               dup2 (pd[0], fileno (stdin));
-               close (pd[0]);
-           }
-           arglist = argsplit(name, &file, NULL);
-           execvp (file, arglist);
-           fprintf (stderr, "unable to exec ");
-           perror (name);
-           _exit (-1);
-
-       default: 
-           close (pd[0]);
-           if (pd[1] != fileno (stdout)) {
-               dup2 (pd[1], fileno (stdout));
-               close (pd[1]);
-           }
-    }
-}
-
-
-void
-m_pclose (void)
-{
-    if (m_pid == NOTOK)
-       return;
-
-    if (sd != NOTOK) {
-       fflush (stdout);
-       if (dup2 (sd, fileno (stdout)) == NOTOK)
-           adios ("standard output", "unable to dup2()");
-
-       clearerr (stdout);
-       close (sd);
-       sd = NOTOK;
-    }
-    else
-       fclose (stdout);
-
-    pidwait (m_pid, OK);
-    m_pid = NOTOK;
-}
-
-
 /*
  * Compile a format string used by the formatfield option and save it
  * for later.
 /*
  * Compile a format string used by the formatfield option and save it
  * for later.