X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=uip%2Fmhl.c;h=18d0176c5d5c078bc1925da70826957ffa67f202;hb=6d6b17fd2311daa48928e36bb131cda8fd1c91eb;hp=58c7d2b07bd2dd2c342f5af28680fb9cce920b96;hpb=3c7a396c28e665f8cc2e94f18e1a84b3e1d2efd4;p=mmh diff --git a/uip/mhl.c b/uip/mhl.c index 58c7d2b..18d0176 100644 --- a/uip/mhl.c +++ b/uip/mhl.c @@ -48,20 +48,14 @@ static struct swit mhlswitches[] = { #define SLEEPSW 2 { "sleep seconds", 0 }, #define VERSIONSW 3 - { "version", 0 }, + { "Version", 0 }, #define HELPSW 4 { "help", 0 }, #define FORW1SW 5 { "forward", -7 }, #define FORW2SW 6 { "forwall", -7 }, -#define DGSTSW 7 - { "digest list", -6 }, -#define VOLUMSW 8 - { "volume number", -6 }, -#define ISSUESW 9 - { "issue number", -5 }, -#define NBODYSW 10 +#define NBODYSW 7 { "nobody", -6 }, { NULL, 0 } }; @@ -165,17 +159,9 @@ static int forwall = 0; static int sleepsw = NOTOK; -static char *digest = NULL; -static int volume = 0; -static int issue = 0; - static int exitstat = 0; static int mhldebug = 0; -#define PITTY (-1) -#define NOTTY 0 -static int ontty = NOTTY; - static unsigned int column; static int lm; @@ -195,10 +181,6 @@ static char *ignores[MAXARGS]; static jmp_buf env; static jmp_buf mhlenv; -static char delim3[] = -"\n----------------------------------------------------------------------\n\n"; -static char delim4[] = "\n------------------------------\n\n"; - static FILE *(*mhl_action) () = (FILE *(*) ()) 0; @@ -230,13 +212,8 @@ static char *oneline(char *, long); static void putstr(char *); static void putch(char); static void intrser(int); -static void pipeser(int); -static void quitser(int); static void mhladios(char *, char *, ...); static void mhldone(int); -static void m_popen(char *); - -void m_pclose(void); int sc_width(void); /* from termsbr.c */ @@ -249,10 +226,7 @@ main(int argc, char **argv) char buf[BUFSIZ], *files[MAXARGS]; char **argp, **arguments; -#ifdef LOCALE setlocale(LC_ALL, ""); -#endif - invo_name = mhbasename(argv[0]); /* read user profile/context */ @@ -303,29 +277,6 @@ main(int argc, char **argv) argp[-2], cp); continue; - case DGSTSW: - if (!(digest = *argp++) || - *digest == '-') - adios(NULL, "missing argument to %s", - argp[-2]); - continue; - case ISSUESW: - if (!(cp = *argp++) || *cp == '-') - adios(NULL, "missing argument to %s", - argp[-2]); - if ((issue = atoi(cp)) < 1) - adios(NULL, "bad argument %s %s", - argp[-2], cp); - continue; - case VOLUMSW: - if (!(cp = *argp++) || *cp == '-') - adios(NULL, "missing argument to %s", - argp[-2]); - if ((volume = atoi(cp)) < 1) - adios(NULL, "bad argument %s %s", - argp[-2], cp); - continue; - case FORW2SW: forwall++; /* fall */ case FORW1SW: @@ -340,18 +291,6 @@ main(int argc, char **argv) files[vecp++] = cp; } - if (isatty(fileno(stdout))) { - if (mhl_action) { - SIGNAL(SIGINT, SIG_IGN); - SIGNAL2(SIGQUIT, quitser); - } - SIGNAL2(SIGPIPE, pipeser); - m_popen(defaultpager); - ontty = PITTY; - } else { - ontty = NOTTY; - } - mhl_format(form ? form : mhlformat, width); if (vecp == 0) { @@ -362,22 +301,7 @@ main(int argc, char **argv) } if (forwall) { - if (digest) { - printf("%s", delim4); - if (volume == 0) { - snprintf(buf, sizeof(buf), - "End of %s Digest\n", digest); - } else { - snprintf(buf, sizeof(buf), "End of %s Digest [Volume %d Issue %d]\n", digest, volume, issue); - } - i = strlen(buf); - for (cp = buf + i; i > 1; i--) - *cp++ = '*'; - *cp++ = '\n'; - *cp = 0; - printf("%s", buf); - } else - printf("\n------- End of Forwarded Message%s\n\n", + printf("\n------- End of Forwarded Message%s\n\n", vecp > 1 ? "s" : ""); } @@ -386,9 +310,6 @@ main(int argc, char **argv) adios("output", "error writing"); } - if (ontty == PITTY) - m_pclose(); - return exitstat; } @@ -677,13 +598,11 @@ process(char *fname, int ofilen, int ofilec) fname = "(stdin)"; fp = stdin; } - if (ontty != PITTY) - SIGNAL(SIGINT, intrser); + SIGNAL(SIGINT, intrser); mhlfile(fp, fname, ofilen, ofilec); /* FALL THROUGH! */ default: - if (ontty != PITTY) - SIGNAL(SIGINT, SIG_IGN); + SIGNAL(SIGINT, SIG_IGN); if (mhl_action == NULL && fp != stdin) fclose(fp); if (holder.c_text) { @@ -706,17 +625,12 @@ mhlfile(FILE *fp, char *mname, int ofilen, int ofilec) char **ip, name[NAMESZ], buf[BUFSIZ]; if (forwall) { - if (digest) - printf("%s", ofilen == 1 ? delim3 : delim4); - else { - printf("\n-------"); - if (ofilen == 1) - printf(" Forwarded Message%s", - ofilec > 1 ? "s" : ""); - else - printf(" Message %d", ofilen); - printf("\n\n"); - } + printf("\n-------"); + if (ofilen == 1) + printf(" Forwarded Message%s", ofilec > 1 ? "s" : ""); + else + printf(" Message %d", ofilen); + printf("\n\n"); } else if (ofilec > 1) { if (ofilen > 1) { printf("\n\n\n"); @@ -1219,22 +1133,6 @@ intrser(int i) } -static void -pipeser(int i) -{ - done(NOTOK); -} - - -static void -quitser(int i) -{ - putchar('\n'); - fflush(stdout); - done(NOTOK); -} - - #undef adios #undef done @@ -1259,68 +1157,3 @@ mhldone(int status) else done(exitstat); } - - -static int m_pid = NOTOK; -static int sd = NOTOK; - -static void -m_popen(char *name) -{ - int pd[2]; - - 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]); - } - execlp(name, mhbasename(name), NULL); - 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; -}