1 | #! /bin/sh /usr/share/dpatch/dpatch-run |
---|
2 | # Subject: Wrap moreproc around as much MIME content as possible |
---|
3 | # Origin: http://debathena.mit.edu/trac/changeset/13008 |
---|
4 | # Forwarded: no |
---|
5 | # Author: Daniel Winship <danw@mit.edu> |
---|
6 | # Reviewed-by: Evan Broder <broder@mit.edu> |
---|
7 | |
---|
8 | @DPATCH@ |
---|
9 | |
---|
10 | --- a/uip/mhshowsbr.c.orig 2003-09-30 12:58:43.000000000 -0400 |
---|
11 | +++ b/uip/mhshowsbr.c 2010-06-25 20:43:59.000000000 -0400 |
---|
12 | @@ -47,7 +47,7 @@ |
---|
13 | int nomore = 0; |
---|
14 | char *formsw = NULL; |
---|
15 | |
---|
16 | -pid_t xpid = 0; |
---|
17 | +pid_t xpid = 0, m_pid = 0; |
---|
18 | |
---|
19 | static sigjmp_buf intrenv; |
---|
20 | |
---|
21 | @@ -90,6 +90,8 @@ |
---|
22 | static int show_partial (CT, int, int); |
---|
23 | static int show_external (CT, int, int); |
---|
24 | static RETSIGTYPE intrser (int); |
---|
25 | +static void m_popen (char *); |
---|
26 | +static void m_pclose (void); |
---|
27 | |
---|
28 | |
---|
29 | /* |
---|
30 | @@ -143,6 +145,9 @@ |
---|
31 | * the viewer (e.g., lynx) are going to be accessible */ |
---|
32 | umask (ct->c_umask & ~(0100)); |
---|
33 | |
---|
34 | + if (!nomore && isatty (fileno (stdout))) |
---|
35 | + m_popen (progsw ? progsw : moreproc); |
---|
36 | + |
---|
37 | /* |
---|
38 | * If you have a format file, then display |
---|
39 | * the message headers. |
---|
40 | @@ -170,6 +175,8 @@ |
---|
41 | sigaddset (&set, SIGTERM); |
---|
42 | SIGPROCMASK (SIG_BLOCK, &set, &oset); |
---|
43 | |
---|
44 | + m_pclose (); |
---|
45 | + |
---|
46 | while (wait (&status) != NOTOK) { |
---|
47 | #ifdef WAITINT |
---|
48 | pidcheck (status); |
---|
49 | @@ -203,18 +210,8 @@ |
---|
50 | vec[vecp++] = "-form"; |
---|
51 | vec[vecp++] = form; |
---|
52 | vec[vecp++] = "-nobody"; |
---|
53 | + vec[vecp++] = "-nomoreproc"; |
---|
54 | vec[vecp++] = ct->c_file; |
---|
55 | - |
---|
56 | - /* |
---|
57 | - * If we've specified -(no)moreproc, |
---|
58 | - * then just pass that along. |
---|
59 | - */ |
---|
60 | - if (nomore) { |
---|
61 | - vec[vecp++] = "-nomoreproc"; |
---|
62 | - } else if (progsw) { |
---|
63 | - vec[vecp++] = "-moreproc"; |
---|
64 | - vec[vecp++] = progsw; |
---|
65 | - } |
---|
66 | vec[vecp] = NULL; |
---|
67 | |
---|
68 | fflush (stdout); |
---|
69 | @@ -546,6 +543,9 @@ |
---|
70 | xpid = 0; |
---|
71 | } |
---|
72 | |
---|
73 | + if (xstdin && m_pid) |
---|
74 | + m_pclose (); |
---|
75 | + |
---|
76 | if (xlist) { |
---|
77 | char prompt[BUFSIZ]; |
---|
78 | |
---|
79 | @@ -647,8 +647,7 @@ |
---|
80 | * if it is not a text part of a multipart/alternative |
---|
81 | */ |
---|
82 | if (!alternate || ct->c_subtype == TEXT_PLAIN) { |
---|
83 | - snprintf (buffer, sizeof(buffer), "%%p%s '%%F'", progsw ? progsw : |
---|
84 | - moreproc && *moreproc ? moreproc : "more"); |
---|
85 | + snprintf (buffer, sizeof(buffer), "%%ecat '%%f'"); |
---|
86 | cp = (ct->c_showproc = add (buffer, NULL)); |
---|
87 | return show_content_aux (ct, serial, alternate, cp, NULL); |
---|
88 | } |
---|
89 | @@ -1121,3 +1120,65 @@ |
---|
90 | putchar ('\n'); |
---|
91 | siglongjmp (intrenv, DONE); |
---|
92 | } |
---|
93 | + |
---|
94 | +static int sd = NOTOK; |
---|
95 | + |
---|
96 | +static void |
---|
97 | +m_popen (char *name) |
---|
98 | +{ |
---|
99 | + int pd[2]; |
---|
100 | + |
---|
101 | + if ((sd = dup (fileno (stdout))) == NOTOK) |
---|
102 | + adios ("standard output", "unable to dup()"); |
---|
103 | + |
---|
104 | + if (pipe (pd) == NOTOK) |
---|
105 | + adios ("pipe", "unable to"); |
---|
106 | + |
---|
107 | + switch (m_pid = vfork ()) { |
---|
108 | + case NOTOK: |
---|
109 | + adios ("fork", "unable to"); |
---|
110 | + |
---|
111 | + case OK: |
---|
112 | + SIGNAL (SIGINT, SIG_DFL); |
---|
113 | + SIGNAL (SIGQUIT, SIG_DFL); |
---|
114 | + |
---|
115 | + close (pd[1]); |
---|
116 | + if (pd[0] != fileno (stdin)) { |
---|
117 | + dup2 (pd[0], fileno (stdin)); |
---|
118 | + close (pd[0]); |
---|
119 | + } |
---|
120 | + execlp (name, r1bindex (name, '/'), NULL); |
---|
121 | + fprintf (stderr, "unable to exec "); |
---|
122 | + perror (name); |
---|
123 | + _exit (-1); |
---|
124 | + |
---|
125 | + default: |
---|
126 | + close (pd[0]); |
---|
127 | + if (pd[1] != fileno (stdout)) { |
---|
128 | + dup2 (pd[1], fileno (stdout)); |
---|
129 | + close (pd[1]); |
---|
130 | + } |
---|
131 | + } |
---|
132 | +} |
---|
133 | + |
---|
134 | + |
---|
135 | +void |
---|
136 | +m_pclose (void) |
---|
137 | +{ |
---|
138 | + if (!m_pid) |
---|
139 | + return; |
---|
140 | + |
---|
141 | + if (sd != NOTOK) { |
---|
142 | + if (dup2 (sd, fileno (stdout)) == NOTOK) |
---|
143 | + adios ("standard output", "unable to dup2()"); |
---|
144 | + |
---|
145 | + clearerr (stdout); |
---|
146 | + close (sd); |
---|
147 | + sd = NOTOK; |
---|
148 | + } |
---|
149 | + else |
---|
150 | + fclose (stdout); |
---|
151 | + |
---|
152 | + pidwait (m_pid, OK); |
---|
153 | + m_pid = 0; |
---|
154 | +} |
---|