X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=uip%2Fmhlsbr.c;h=927d8454d462e961d224082800058db36094f562;hp=7bce5da2d74d6e029ed6295ebcbf5ab574d3e782;hb=5b792c4424571f05bc2008e3109797d18d7d00d1;hpb=8e5be81f784682822f5e868c1bf3c8624682bd23 diff --git a/uip/mhlsbr.c b/uip/mhlsbr.c index 7bce5da..927d845 100644 --- a/uip/mhlsbr.c +++ b/uip/mhlsbr.c @@ -304,106 +304,118 @@ mhl(int argc, char **argv) while ((cp = *argp++)) { if (*cp == '-') { switch (smatch(++cp, mhlswitches)) { - case AMBIGSW: - ambigsw(cp, mhlswitches); - done(1); - case UNKWNSW: - adios(NULL, "-%s unknown\n", cp); - - case HELPSW: - snprintf(buf, sizeof(buf), "%s [switches] [files ...]", invo_name); - print_help(buf, mhlswitches, 1); - done(1); - case VERSIONSW: - print_version(invo_name); - done(1); - - case BELLSW: - bellflg = 1; - continue; - case NBELLSW: - bellflg = -1; - continue; + case AMBIGSW: + ambigsw(cp, mhlswitches); + done(1); + case UNKWNSW: + adios(NULL, "-%s unknown\n", cp); + + case HELPSW: + snprintf(buf, sizeof(buf), "%s [switches] [files ...]", invo_name); + print_help(buf, mhlswitches, 1); + done(1); + case VERSIONSW: + print_version(invo_name); + done(1); + + case BELLSW: + bellflg = 1; + continue; + case NBELLSW: + bellflg = -1; + continue; - case CLRSW: - clearflg = 1; - continue; - case NCLRSW: - clearflg = -1; - continue; + case CLRSW: + clearflg = 1; + continue; + case NCLRSW: + clearflg = -1; + continue; - case FOLDSW: - if (!(folder = *argp++) || - *folder == '-') - adios(NULL, "missing argument to %s", argp[-2]); - continue; - case FORMSW: - if (!(form = *argp++) || *form == '-') - adios(NULL, "missing argument to %s", argp[-2]); - continue; + case FOLDSW: + if (!(folder = *argp++) || *folder == '-') + adios(NULL, "missing argument to %s", + argp[-2]); + continue; + case FORMSW: + if (!(form = *argp++) || *form == '-') + adios(NULL, "missing argument to %s", + argp[-2]); + continue; - case SLEEPSW: - if (!(cp = *argp++) || *cp == '-') - adios(NULL, "missing argument to %s", argp[-2]); - sleepsw = atoi(cp); /* ZERO ok! */ - continue; + case SLEEPSW: + if (!(cp = *argp++) || *cp == '-') + adios(NULL, "missing argument to %s", + argp[-2]); + sleepsw = atoi(cp); /* ZERO ok! */ + continue; - case PROGSW: - if (!(moreproc = *argp++) || *moreproc == '-') - adios(NULL, "missing argument to %s", argp[-2]); - continue; - case NPROGSW: - nomore++; - continue; + case PROGSW: + if (!(moreproc = *argp++) || *moreproc == '-') + adios(NULL, "missing argument to %s", + argp[-2]); + continue; + case NPROGSW: + nomore++; + continue; - case LENSW: - if (!(cp = *argp++) || *cp == '-') - adios(NULL, "missing argument to %s", argp[-2]); - if ((length = atoi(cp)) < 1) - adios(NULL, "bad argument %s %s", argp[-2], cp); - continue; - case WIDTHSW: - if (!(cp = *argp++) || *cp == '-') - adios(NULL, "missing argument to %s", argp[-2]); - if ((width = atoi(cp)) < 1) - adios(NULL, "bad argument %s %s", argp[-2], cp); - continue; + case LENSW: + if (!(cp = *argp++) || *cp == '-') + adios(NULL, "missing argument to %s", + argp[-2]); + if ((length = atoi(cp)) < 1) + adios(NULL, "bad argument %s %s", + argp[-2], cp); + continue; + case WIDTHSW: + if (!(cp = *argp++) || *cp == '-') + adios(NULL, "missing argument to %s", + argp[-2]); + if ((width = atoi(cp)) < 1) + adios(NULL, "bad argument %s %s", + 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 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: - forwflg++; - clearflg = -1;/* XXX */ - continue; + case FORW2SW: + forwall++; /* fall */ + case FORW1SW: + forwflg++; + clearflg = -1;/* XXX */ + continue; - case BITSTUFFSW: - dashstuff = 1; /* trinary logic */ - continue; - case NBITSTUFFSW: - dashstuff = -1; /* trinary logic */ - continue; + case BITSTUFFSW: + dashstuff = 1; /* trinary logic */ + continue; + case NBITSTUFFSW: + dashstuff = -1; /* trinary logic */ + continue; - case NBODYSW: - dobody = 0; - continue; + case NBODYSW: + dobody = 0; + continue; } } files[vecp++] = cp; @@ -535,69 +547,64 @@ mhl_format(char *file, int length, int width) parptr = bp; strncpy(name, parse(), sizeof(name)); switch(*parptr) { - case '\0': - case ',': - case '=': + case '\0': + case ',': + case '=': + /* + ** Split this list of fields to ignore, and copy + ** it to the end of the current "ignores" list. + */ + if (!mh_strcasecmp(name, "ignores")) { + char **tmparray, **p; + int n = 0; + + /* split the fields */ + tmparray = brkstring(getcpy(++parptr), ",", + NULL); + + /* count number of fields split */ + p = tmparray; + while (*p++) + n++; + /* - ** Split this list of fields to ignore, - ** and copy it to the end of the current - ** "ignores" list. + ** copy pointers to split fields + ** to ignores array */ - if (!mh_strcasecmp(name, "ignores")) { - char **tmparray, **p; - int n = 0; - - /* split the fields */ - tmparray = brkstring(getcpy(++parptr), - ",", NULL); - - /* count number of fields split */ - p = tmparray; - while (*p++) - n++; - - /* - ** copy pointers to split fields - ** to ignores array - */ - ip = copyip(tmparray, ip, - MAXARGS - num_ignores); - num_ignores += n; - continue; - } - parptr = bp; - while (*parptr) { - if (evalvar(&global)) - adios(NULL, "format file syntax error: %s", bp); - if (*parptr) - parptr++; - } + ip = copyip(tmparray, ip, + MAXARGS - num_ignores); + num_ignores += n; continue; - - case ':': - c1 = add_queue(&fmthd, &fmttl, name, NULL, - INIT); - while (*parptr == ':' || *parptr == ',') { + } + parptr = bp; + while (*parptr) { + if (evalvar(&global)) + adios(NULL, "format file syntax error: %s", bp); + if (*parptr) parptr++; - if (evalvar(c1)) - adios(NULL, "format file syntax error: %s", bp); - } - if (!c1->c_nfs && global.c_nfs) { - if (c1->c_flags & DATEFMT) { - if (global.c_flags & DATEFMT) - c1->c_nfs = getcpy(global.c_nfs); - } - else - if (c1->c_flags & ADDRFMT) { - if (global.c_flags & ADDRFMT) - c1->c_nfs = getcpy(global.c_nfs); - } + } + continue; + + case ':': + c1 = add_queue(&fmthd, &fmttl, name, NULL, INIT); + while (*parptr == ':' || *parptr == ',') { + parptr++; + if (evalvar(c1)) + adios(NULL, "format file syntax error: %s", bp); + } + if (!c1->c_nfs && global.c_nfs) { + if ((c1->c_flags & DATEFMT) && + (global.c_flags & DATEFMT)) { + c1->c_nfs = getcpy(global.c_nfs); + } else if ((c1->c_flags & ADDRFMT) && + (global.c_flags & ADDRFMT)) { + c1->c_nfs = getcpy(global.c_nfs); } - continue; + } + continue; - default: - adios(NULL, "format file syntax error: %s", - bp); + default: + adios(NULL, "format file syntax error: %s", bp); } } fclose(fp); @@ -620,12 +627,12 @@ out: } switch (bellflg) { /* command line may override format file */ - case 1: - global.c_flags |= BELL; - break; - case -1: - global.c_flags &= ~BELL; - break; + case 1: + global.c_flags |= BELL; + break; + case -1: + global.c_flags &= ~BELL; + break; } if (length) @@ -780,39 +787,38 @@ process(char *folder, char *fname, int ofilen, int ofilec) struct mcomp *c1; switch (setjmp(env)) { - case OK: - if (fname) { - fp = mhl_action ? (*mhl_action) (fname) : - fopen(fname, "r"); - if (fp == NULL) { - advise(fname, "unable to open"); - exitstat++; - return; - } - } else { - fname = "(stdin)"; - fp = stdin; + case OK: + if (fname) { + fp = mhl_action ? (*mhl_action) (fname) : + fopen(fname, "r"); + if (fp == NULL) { + advise(fname, "unable to open"); + exitstat++; + return; } - cp = folder ? concat(folder, ":", fname, NULL) : - getcpy(fname); - if (ontty != PITTY) - SIGNAL(SIGINT, intrser); - mhlfile(fp, cp, ofilen, ofilec); /* FALL THROUGH! */ + } else { + fname = "(stdin)"; + fp = stdin; + } + cp = folder ? concat(folder, ":", fname, NULL) : getcpy(fname); + if (ontty != PITTY) + SIGNAL(SIGINT, intrser); + mhlfile(fp, cp, ofilen, ofilec); /* FALL THROUGH! */ - default: - if (ontty != PITTY) - SIGNAL(SIGINT, SIG_IGN); - if (mhl_action == NULL && fp != stdin) - fclose(fp); - free(cp); - if (holder.c_text) { - free(holder.c_text); - holder.c_text = NULL; - } - free_queue(&msghd, &msgtl); - for (c1 = fmthd; c1; c1 = c1->c_next) - c1->c_flags &= ~HDROUTPUT; - break; + default: + if (ontty != PITTY) + SIGNAL(SIGINT, SIG_IGN); + if (mhl_action == NULL && fp != stdin) + fclose(fp); + free(cp); + if (holder.c_text) { + free(holder.c_text); + holder.c_text = NULL; + } + free_queue(&msghd, &msgtl); + for (c1 = fmthd; c1; c1 = c1->c_next) + c1->c_flags &= ~HDROUTPUT; + break; } } @@ -838,135 +844,136 @@ mhlfile(FILE *fp, char *mname, int ofilen, int ofilec) } } else { switch (ontty) { - case PITTY: - if (ofilec > 1) { - if (ofilen > 1) { - if ((global.c_flags & CLEARSCR)) - clear_screen(); - else - printf("\n\n\n"); - } - printf(">>> %s\n\n", mname); - } - break; - - case ISTTY: - strncpy(buf, "\n", sizeof(buf)); - if (ofilec > 1) { - if (SOprintf("Press to list \"%s\"...", mname)) { - if (ofilen > 1) - printf("\n\n\n"); - printf("Press to list \"%s\"...", mname); - } - fflush(stdout); - buf[0] = 0; - read(fileno(stdout), buf, sizeof(buf)); - } - if (strchr(buf, '\n')) { + case PITTY: + if (ofilec > 1) { + if (ofilen > 1) { if ((global.c_flags & CLEARSCR)) clear_screen(); + else + printf("\n\n\n"); } - else - printf("\n"); - break; + printf(">>> %s\n\n", mname); + } + break; - default: - if (ofilec > 1) { - if (ofilen > 1) { + case ISTTY: + strncpy(buf, "\n", sizeof(buf)); + if (ofilec > 1) { + if (SOprintf("Press to list \"%s\"...", mname)) { + if (ofilen > 1) printf("\n\n\n"); - if (clearflg > 0) - clear_screen(); - } - printf(">>> %s\n\n", mname); + printf("Press to list \"%s\"...", mname); } - break; + fflush(stdout); + buf[0] = 0; + read(fileno(stdout), buf, sizeof(buf)); + } + if (strchr(buf, '\n')) { + if ((global.c_flags & CLEARSCR)) + clear_screen(); + } else + printf("\n"); + break; + + default: + if (ofilec > 1) { + if (ofilen > 1) { + printf("\n\n\n"); + if (clearflg > 0) + clear_screen(); + } + printf(">>> %s\n\n", mname); + } + break; } } for (state = FLD;;) { switch (state = m_getfld(state, name, buf, sizeof(buf), fp)) { - case FLD: - case FLDPLUS: - for (ip = ignores; *ip; ip++) - if (!mh_strcasecmp(name, *ip)) { - while (state == FLDPLUS) - state = m_getfld(state, name, buf, sizeof(buf), fp); - break; - } - if (*ip) - continue; - - for (c2 = fmthd; c2; c2 = c2->c_next) - if (!mh_strcasecmp(c2->c_name, name)) - break; - c1 = NULL; - if (!((c3 = c2 ? c2 : &global)->c_flags & SPLIT)) - for (c1 = msghd; c1; c1 = c1->c_next) - if (!mh_strcasecmp(c1->c_name, c3->c_name)) { - c1->c_text = mcomp_add (c1->c_flags, buf, c1->c_text); - break; - } - if (c1 == NULL) - c1 = add_queue(&msghd, &msgtl, name, buf, 0); - while (state == FLDPLUS) { - state = m_getfld(state, name, buf, sizeof(buf), fp); - c1->c_text = add(buf, c1->c_text); + case FLD: + case FLDPLUS: + for (ip = ignores; *ip; ip++) + if (!mh_strcasecmp(name, *ip)) { + while (state == FLDPLUS) + state = m_getfld(state, name, buf, sizeof(buf), fp); + break; } - if (c2 == NULL) - c1->c_flags |= EXTRA; + if (*ip) continue; - case BODY: - case FILEEOF: - row = column = 0; - for (c1 = fmthd; c1; c1 = c1->c_next) { - if (c1->c_flags & CLEARTEXT) { - putcomp(c1, c1, ONECOMP); - continue; - } - if (!mh_strcasecmp(c1->c_name, "messagename")) { - holder.c_text = concat("(Message ", mname, ")\n", - NULL); - putcomp(c1, &holder, ONECOMP); - free(holder.c_text); - holder.c_text = NULL; - continue; - } - if (!mh_strcasecmp(c1->c_name, "extras")) { - for (c2 = msghd; c2; c2 = c2->c_next) - if (c2->c_flags & EXTRA) - putcomp(c1, c2, TWOCOMP); - continue; - } - if (dobody && !mh_strcasecmp(c1->c_name, "body")) { - holder.c_text = mh_xmalloc(sizeof(buf)); - strncpy(holder.c_text, buf, sizeof(buf)); - while (state == BODY) { - putcomp(c1, &holder, BODYCOMP); - state = m_getfld(state, name, holder.c_text, sizeof(buf), fp); - } - free(holder.c_text); - holder.c_text = NULL; - continue; + for (c2 = fmthd; c2; c2 = c2->c_next) + if (!mh_strcasecmp(c2->c_name, name)) + break; + c1 = NULL; + if (!((c3 = c2 ? c2 : &global)->c_flags & SPLIT)) + for (c1 = msghd; c1; c1 = c1->c_next) + if (!mh_strcasecmp(c1->c_name, + c3->c_name)) { + c1->c_text = mcomp_add(c1->c_flags, buf, c1->c_text); + break; } + if (c1 == NULL) + c1 = add_queue(&msghd, &msgtl, name, buf, 0); + while (state == FLDPLUS) { + state = m_getfld(state, name, buf, + sizeof(buf), fp); + c1->c_text = add(buf, c1->c_text); + } + if (c2 == NULL) + c1->c_flags |= EXTRA; + continue; + + case BODY: + case FILEEOF: + row = column = 0; + for (c1 = fmthd; c1; c1 = c1->c_next) { + if (c1->c_flags & CLEARTEXT) { + putcomp(c1, c1, ONECOMP); + continue; + } + if (!mh_strcasecmp(c1->c_name, "messagename")) { + holder.c_text = concat("(Message ", + mname, ")\n", NULL); + putcomp(c1, &holder, ONECOMP); + free(holder.c_text); + holder.c_text = NULL; + continue; + } + if (!mh_strcasecmp(c1->c_name, "extras")) { for (c2 = msghd; c2; c2 = c2->c_next) - if (!mh_strcasecmp(c2->c_name, c1->c_name)) { - putcomp(c1, c2, ONECOMP); - if (!(c1->c_flags & SPLIT)) - break; - } + if (c2->c_flags & EXTRA) + putcomp(c1, c2, TWOCOMP); + continue; } - return; + if (dobody && !mh_strcasecmp(c1->c_name, "body")) { + holder.c_text = mh_xmalloc(sizeof(buf)); + strncpy(holder.c_text, buf, sizeof(buf)); + while (state == BODY) { + putcomp(c1, &holder, BODYCOMP); + state = m_getfld(state, name, holder.c_text, sizeof(buf), fp); + } + free(holder.c_text); + holder.c_text = NULL; + continue; + } + for (c2 = msghd; c2; c2 = c2->c_next) + if (!mh_strcasecmp(c2->c_name, + c1->c_name)) { + putcomp(c1, c2, ONECOMP); + if (!(c1->c_flags & SPLIT)) + break; + } + } + return; - case LENERR: - case FMTERR: - advise(NULL, "format error in message %s", - mname); - exitstat++; - return; + case LENERR: + case FMTERR: + advise(NULL, "format error in message %s", mname); + exitstat++; + return; - default: - adios(NULL, "getfld() returned %d", state); + default: + adios(NULL, "getfld() returned %d", state); } } } @@ -1332,53 +1339,53 @@ putch(char ch) return; switch (ch) { - case '\n': - if (llim > 0) - llim--; - column = 0; - row++; - if (ontty != ISTTY || row != global.c_length) - break; - if (global.c_flags & BELL) - putchar('\007'); - fflush(stdout); - buf[0] = 0; - read(fileno(stdout), buf, sizeof(buf)); - if (strchr(buf, '\n')) { - if (global.c_flags & CLEARSCR) - clear_screen(); - row = 0; - } else { - putchar('\n'); - row = global.c_length / 3; - } - return; - - case '\t': - column |= 07; - column++; - break; - - case '\b': - column--; - break; - - case '\r': - column = 0; + case '\n': + if (llim > 0) + llim--; + column = 0; + row++; + if (ontty != ISTTY || row != global.c_length) break; + if (global.c_flags & BELL) + putchar('\007'); + fflush(stdout); + buf[0] = 0; + read(fileno(stdout), buf, sizeof(buf)); + if (strchr(buf, '\n')) { + if (global.c_flags & CLEARSCR) + clear_screen(); + row = 0; + } else { + putchar('\n'); + row = global.c_length / 3; + } + return; - default: - /* - ** If we are forwarding this message, and the first - ** column contains a dash, then add a dash and a space. - */ - if (column == 0 && forwflg && (dashstuff >= 0) && ch == '-') { - putchar('-'); - putchar(' '); - } - if (ch >= ' ') - column++; - break; + case '\t': + column |= 07; + column++; + break; + + case '\b': + column--; + break; + + case '\r': + column = 0; + break; + + default: + /* + ** If we are forwarding this message, and the first + ** column contains a dash, then add a dash and a space. + */ + if (column == 0 && forwflg && (dashstuff >= 0) && ch == '-') { + putchar('-'); + putchar(' '); + } + if (ch >= ' ') + column++; + break; } if (column >= wid) { @@ -1439,44 +1446,44 @@ mhlsbr(int argc, char **argv, FILE *(*action)()) struct mcomp *c1; switch (setjmp(mhlenv)) { - case OK: - cp = invo_name; - sleepsw = 0; /* XXX */ - bellflg = clearflg = forwflg = forwall = exitstat = 0; - digest = NULL; - ontty = NOTTY; - mhl_action = action; - - /* - ** If signal is at default action, then start ignoring - ** it, else let it set to its current action. - */ - if ((istat = SIGNAL(SIGINT, SIG_IGN)) != SIG_DFL) - SIGNAL(SIGINT, istat); - if ((qstat = SIGNAL(SIGQUIT, SIG_IGN)) != SIG_DFL) - SIGNAL(SIGQUIT, qstat); - pstat = SIGNAL(SIGPIPE, pipeser); - mhl(argc, argv); /* FALL THROUGH! */ + case OK: + cp = invo_name; + sleepsw = 0; /* XXX */ + bellflg = clearflg = forwflg = forwall = exitstat = 0; + digest = NULL; + ontty = NOTTY; + mhl_action = action; - default: + /* + ** If signal is at default action, then start ignoring + ** it, else let it set to its current action. + */ + if ((istat = SIGNAL(SIGINT, SIG_IGN)) != SIG_DFL) SIGNAL(SIGINT, istat); + if ((qstat = SIGNAL(SIGQUIT, SIG_IGN)) != SIG_DFL) SIGNAL(SIGQUIT, qstat); - SIGNAL(SIGPIPE, SIG_IGN); /* - ** should probably change to block - ** instead - */ - if (ontty == PITTY) - m_pclose(); - SIGNAL(SIGPIPE, pstat); - invo_name = cp; - if (holder.c_text) { - free(holder.c_text); - holder.c_text = NULL; - } - free_queue(&msghd, &msgtl); - for (c1 = fmthd; c1; c1 = c1->c_next) - c1->c_flags &= ~HDROUTPUT; - return exitstat; + pstat = SIGNAL(SIGPIPE, pipeser); + mhl(argc, argv); /* FALL THROUGH! */ + + default: + SIGNAL(SIGINT, istat); + SIGNAL(SIGQUIT, qstat); + SIGNAL(SIGPIPE, SIG_IGN); /* + ** should probably change to block + ** instead + */ + if (ontty == PITTY) + m_pclose(); + SIGNAL(SIGPIPE, pstat); + invo_name = cp; + if (holder.c_text) { + free(holder.c_text); + holder.c_text = NULL; + } + free_queue(&msghd, &msgtl); + for (c1 = fmthd; c1; c1 = c1->c_next) + c1->c_flags &= ~HDROUTPUT; + return exitstat; } } @@ -1521,29 +1528,29 @@ m_popen(char *name) adios("pipe", "unable to"); switch (m_pid = vfork()) { - case NOTOK: - adios("fork", "unable to"); - - case OK: - SIGNAL(SIGINT, SIG_DFL); - SIGNAL(SIGQUIT, SIG_DFL); + case NOTOK: + adios("fork", "unable to"); - 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); + case OK: + SIGNAL(SIGINT, SIG_DFL); + SIGNAL(SIGQUIT, SIG_DFL); - default: + close(pd[1]); + if (pd[0] != fileno(stdin)) { + dup2(pd[0], fileno(stdin)); close(pd[0]); - if (pd[1] != fileno(stdout)) { - dup2(pd[1], fileno(stdout)); - close(pd[1]); - } + } + 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]); + } } }