Ticket #636: debathena-nmh.patch

File debathena-nmh.patch, 3.1 KB (added by broder, 14 years ago)
  • uip/mhshowsbr.c

    old new  
    4747int nomore   = 0; 
    4848char *formsw = NULL; 
    4949 
    50 pid_t xpid = 0; 
     50pid_t xpid = 0, m_pid = 0; 
    5151 
    5252static sigjmp_buf intrenv; 
    5353 
     
    9090static int show_partial (CT, int, int); 
    9191static int show_external (CT, int, int); 
    9292static RETSIGTYPE intrser (int); 
     93static void m_popen (char *); 
     94static void m_pclose (void); 
    9395 
    9496 
    9597/* 
     
    143145     * the viewer (e.g., lynx) are going to be accessible */ 
    144146    umask (ct->c_umask & ~(0100)); 
    145147 
     148    if (!nomore && isatty (fileno (stdout))) 
     149        m_popen (progsw ? progsw : moreproc); 
     150 
    146151    /* 
    147152     * If you have a format file, then display 
    148153     * the message headers. 
     
    170175    sigaddset (&set, SIGTERM); 
    171176    SIGPROCMASK (SIG_BLOCK, &set, &oset); 
    172177 
     178    m_pclose (); 
     179 
    173180    while (wait (&status) != NOTOK) { 
    174181#ifdef WAITINT 
    175182        pidcheck (status); 
     
    203210    vec[vecp++] = "-form"; 
    204211    vec[vecp++] = form; 
    205212    vec[vecp++] = "-nobody"; 
     213    vec[vecp++] = "-nomoreproc"; 
    206214    vec[vecp++] = ct->c_file; 
    207  
    208     /* 
    209      * If we've specified -(no)moreproc, 
    210      * then just pass that along. 
    211      */ 
    212     if (nomore) { 
    213         vec[vecp++] = "-nomoreproc"; 
    214     } else if (progsw) { 
    215         vec[vecp++] = "-moreproc"; 
    216         vec[vecp++] = progsw; 
    217     } 
    218215    vec[vecp] = NULL; 
    219216 
    220217    fflush (stdout); 
     
    546543        xpid = 0; 
    547544    } 
    548545 
     546    if (xstdin && m_pid) 
     547        m_pclose (); 
     548 
    549549    if (xlist) { 
    550550        char prompt[BUFSIZ]; 
    551551 
     
    647647     * if it is not a text part of a multipart/alternative 
    648648     */ 
    649649    if (!alternate || ct->c_subtype == TEXT_PLAIN) { 
    650         snprintf (buffer, sizeof(buffer), "%%p%s '%%F'", progsw ? progsw : 
    651                 moreproc && *moreproc ? moreproc : "more"); 
     650        snprintf (buffer, sizeof(buffer), "%%ecat '%%f'"); 
    652651        cp = (ct->c_showproc = add (buffer, NULL)); 
    653652        return show_content_aux (ct, serial, alternate, cp, NULL); 
    654653    } 
     
    11211120    putchar ('\n'); 
    11221121    siglongjmp (intrenv, DONE); 
    11231122} 
     1123 
     1124static  int sd = NOTOK; 
     1125 
     1126static void 
     1127m_popen (char *name) 
     1128{ 
     1129    int pd[2]; 
     1130 
     1131    if ((sd = dup (fileno (stdout))) == NOTOK) 
     1132        adios ("standard output", "unable to dup()"); 
     1133 
     1134    if (pipe (pd) == NOTOK) 
     1135        adios ("pipe", "unable to"); 
     1136 
     1137    switch (m_pid = vfork ()) { 
     1138        case NOTOK:  
     1139            adios ("fork", "unable to"); 
     1140 
     1141        case OK:  
     1142            SIGNAL (SIGINT, SIG_DFL); 
     1143            SIGNAL (SIGQUIT, SIG_DFL); 
     1144 
     1145            close (pd[1]); 
     1146            if (pd[0] != fileno (stdin)) { 
     1147                dup2 (pd[0], fileno (stdin)); 
     1148                close (pd[0]); 
     1149            } 
     1150            execlp (name, r1bindex (name, '/'), NULL); 
     1151            fprintf (stderr, "unable to exec "); 
     1152            perror (name); 
     1153            _exit (-1); 
     1154 
     1155        default:  
     1156            close (pd[0]); 
     1157            if (pd[1] != fileno (stdout)) { 
     1158                dup2 (pd[1], fileno (stdout)); 
     1159                close (pd[1]); 
     1160            } 
     1161    } 
     1162} 
     1163 
     1164 
     1165void 
     1166m_pclose (void) 
     1167{ 
     1168    if (!m_pid) 
     1169        return; 
     1170 
     1171    if (sd != NOTOK) { 
     1172        if (dup2 (sd, fileno (stdout)) == NOTOK) 
     1173            adios ("standard output", "unable to dup2()"); 
     1174 
     1175        clearerr (stdout); 
     1176        close (sd); 
     1177        sd = NOTOK; 
     1178    } 
     1179    else 
     1180        fclose (stdout); 
     1181 
     1182    pidwait (m_pid, OK); 
     1183    m_pid = 0; 
     1184}