|
|
1.1 ! root 1: /* scan.c - display a one-line "scan" listing */ ! 2: ! 3: #include "../h/mh.h" ! 4: #include "../h/formatsbr.h" ! 5: #include "../h/scansbr.h" ! 6: #include "../zotnet/tws.h" ! 7: #include <errno.h> ! 8: #include <stdio.h> ! 9: ! 10: /* */ ! 11: ! 12: static struct swit switches[] = { ! 13: #define CLRSW 0 ! 14: "clear", 0, ! 15: #define NCLRSW 1 ! 16: "noclear", 0, ! 17: ! 18: #define FORMSW 2 ! 19: "form formatfile", 0, ! 20: #define FMTSW 3 ! 21: "format string", 5, ! 22: ! 23: #define HEADSW 4 ! 24: "header", 0, ! 25: #define NHEADSW 5 ! 26: "noheader", 0, ! 27: ! 28: #define WIDSW 6 ! 29: "width columns", 0, ! 30: ! 31: #define REVSW 7 ! 32: "reverse", 0, ! 33: #define NREVSW 8 ! 34: "noreverse", 0, ! 35: ! 36: #define FILESW 9 ! 37: "file file", 4, ! 38: ! 39: #define HELPSW 10 ! 40: "help", 4, ! 41: ! 42: NULL, NULL ! 43: }; ! 44: ! 45: /* */ ! 46: ! 47: extern int errno; ! 48: extern struct msgs *fmt_current_folder; ! 49: ! 50: ! 51: void clear_screen(); ! 52: ! 53: /* */ ! 54: ! 55: /* ARGSUSED */ ! 56: ! 57: main(argc, argv) ! 58: int argc; ! 59: char *argv[]; ! 60: { ! 61: int clearflag = 0, hdrflag = 0, width = 0, msgp = 0, ! 62: ontty, state, msgnum; ! 63: register int revflag = 0, firstlim, lastlim, incr; ! 64: char *cp, *maildir, *file = NULL, *folder = NULL, ! 65: *form = NULL, *format = NULL, buf[100], ! 66: **ap, **argp, *nfs, *arguments[MAXARGS], *msgs[MAXARGS]; ! 67: struct msgs *mp; ! 68: FILE *in; ! 69: ! 70: invo_name = r1bindex(argv[0], '/'); ! 71: if ((cp = m_find(invo_name)) != NULL) { ! 72: ap = brkstring(cp = getcpy(cp), " ", "\n"); ! 73: ap = copyip(ap, arguments); ! 74: } else ! 75: ap = arguments; ! 76: (void) copyip(argv + 1, ap); ! 77: argp = arguments; ! 78: ! 79: /* */ ! 80: ! 81: while (cp = *argp++) { ! 82: if (*cp == '-') ! 83: switch (smatch(++cp, switches)) { ! 84: ! 85: case AMBIGSW: ! 86: ambigsw(cp, switches); ! 87: done(1); ! 88: case UNKWNSW: ! 89: adios(NULLCP, "-%s unknown", cp); ! 90: case HELPSW: ! 91: (void) sprintf(buf, ! 92: "%s [+folder] [msgs] [switches]", ! 93: invo_name); ! 94: help(buf, switches); ! 95: done(1); ! 96: ! 97: case CLRSW: ! 98: clearflag++; ! 99: continue; ! 100: case NCLRSW: ! 101: clearflag = 0; ! 102: continue; ! 103: ! 104: case FORMSW: ! 105: if (!(form = *argp++) || *form == '-') ! 106: adios(NULLCP, ! 107: "missing argument to %s", argp[-2]); ! 108: format = NULL; ! 109: continue; ! 110: case FMTSW: ! 111: if (!(format = *argp++) || *format == '-') ! 112: adios(NULLCP, ! 113: "missing argument to %s", argp[-2]); ! 114: form = NULL; ! 115: continue; ! 116: ! 117: case HEADSW: ! 118: hdrflag++; ! 119: continue; ! 120: case NHEADSW: ! 121: hdrflag = 0; ! 122: continue; ! 123: ! 124: case WIDSW: ! 125: if (!(cp = *argp++) || *cp == '-') ! 126: adios(NULLCP, ! 127: "missing argument to %s", argp[-2]); ! 128: width = atoi(cp); ! 129: continue; ! 130: case REVSW: ! 131: revflag++; ! 132: continue; ! 133: case NREVSW: ! 134: revflag = 0; ! 135: continue; ! 136: case FILESW: ! 137: if (!(cp = *argp++) || *cp == '-') ! 138: adios(NULLCP, ! 139: "missing argument to %s", argp[-2]); ! 140: file = path(cp, TFILE); ! 141: continue; ! 142: } ! 143: if (*cp == '+' || *cp == '@') { ! 144: if (folder) ! 145: adios(NULLCP, "only one folder at a time!"); ! 146: else ! 147: folder = path(cp + 1, ! 148: *cp == '+' ? TFOLDER : TSUBCWF); ! 149: } else ! 150: msgs[msgp++] = cp; ! 151: } ! 152: ! 153: ! 154: if (!m_find("path")) ! 155: free(path("./", TFOLDER)); ! 156: if (!msgp) ! 157: msgs[msgp++] = "all"; ! 158: if (!folder) ! 159: folder = m_getfolder(); ! 160: maildir = m_maildir(folder); ! 161: ! 162: if (chdir(maildir) == NOTOK) ! 163: adios(maildir, "unable to change directory to"); ! 164: if (!(mp = m_gmsg(folder))) ! 165: adios(NULLCP, "unable to read folder %s", folder); ! 166: if (mp->hghmsg == 0) ! 167: adios(NULLCP, "no messages in %s", folder); ! 168: ! 169: for (msgnum = 0; msgnum < msgp; msgnum++) ! 170: if (!m_convert(mp, msgs[msgnum])) ! 171: done(1); ! 172: m_setseq(mp); ! 173: ! 174: m_replace(pfolder, folder); ! 175: m_sync(mp); ! 176: m_update(); ! 177: ! 178: nfs = new_fs(form, format, FORMAT); ! 179: ! 180: ontty = isatty(fileno(stdout)); ! 181: ! 182: if (file) { ! 183: /* we've been asked to scan a maildrop file */ ! 184: in = fopen(file, "r"); ! 185: if (in == NULL) ! 186: adios(NULLCP, "can't open %s (%d)", file, errno); ! 187: ! 188: m_unknown(in); ! 189: for (msgnum = 1;; ++msgnum) { ! 190: state = scan(in, msgnum, -1, nfs, width, ! 191: 0, hdrflag, 0L, 1, 0); ! 192: if (state != SCNMSG && state != SCNENC) ! 193: break; ! 194: } ! 195: fclose(in); ! 196: done(0); ! 197: } else ! 198: fmt_current_folder = mp; ! 199: ! 200: #ifdef BERK ! 201: if (revflag) { ! 202: firstlim = mp->hghsel; ! 203: lastlim = mp->lowsel; ! 204: incr = -1; ! 205: } else { ! 206: firstlim = mp->lowsel; ! 207: lastlim = mp->hghsel; ! 208: incr = 1; ! 209: } ! 210: ! 211: for (msgnum = firstlim; ! 212: (revflag ? msgnum >= lastlim : msgnum <= lastlim); ! 213: msgnum += incr) ! 214: #else ! 215: for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) ! 216: #endif ! 217: if (mp->msgstats[msgnum] & SELECTED) { ! 218: if ((in = fopen(cp = m_name(msgnum), "r")) == NULL) { ! 219: if (errno != EACCES) ! 220: admonish(cp, "unable to open message"); ! 221: else ! 222: printf("%*d unreadable\n", ! 223: DMAXFOLDER, msgnum); ! 224: free(cp); ! 225: continue; ! 226: } ! 227: if (hdrflag) ! 228: printf("Folder %-32s%s\n\n", ! 229: folder, dtimenow()); ! 230: switch (state = scan(in, msgnum, 0, nfs, width, ! 231: msgnum == mp->curmsg, hdrflag, 0L, 1, 0)) { ! 232: case SCNMSG: ! 233: case SCNENC: ! 234: case SCNERR: ! 235: break; ! 236: ! 237: default: ! 238: adios(NULLCP, "scan() botch (%d)", state); ! 239: ! 240: case SCNEOF: ! 241: printf("%*d empty\n", DMAXFOLDER, msgnum); ! 242: break; ! 243: } ! 244: hdrflag = 0; ! 245: (void) fclose(in); ! 246: if (ontty) ! 247: (void) fflush(stdout); ! 248: } ! 249: m_sync(mp); ! 250: ! 251: /* */ ! 252: ! 253: if (clearflag) ! 254: clear_screen(); ! 255: ! 256: done(0); ! 257: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.