X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/77a2ce8a960e7d7f6186b6d66be11f05b05fad8b..953c713aa6415dcfe9d8faf75fb64a21db680f97:/usr/src/usr.bin/mail/fio.c diff --git a/usr/src/usr.bin/mail/fio.c b/usr/src/usr.bin/mail/fio.c index 7a4e7df7d8..96f27344bb 100644 --- a/usr/src/usr.bin/mail/fio.c +++ b/usr/src/usr.bin/mail/fio.c @@ -10,7 +10,7 @@ * File I/O. */ -static char *SccsId = "@(#)fio.c 1.1 %G%"; +static char *SccsId = "@(#)fio.c 1.8 %G%"; /* * Set up the input pointers while copying the mail file into @@ -20,10 +20,13 @@ static char *SccsId = "@(#)fio.c 1.1 %G%"; setptr(ibuf) FILE *ibuf; { + register int c; + register char *cp, *cp2; register int count, s, l; off_t offset; char linebuf[LINESIZE]; - int maybe, mestmp, flag; + char wbuf[LINESIZE]; + int maybe, mestmp, flag, inhead; struct message this; extern char tempSet[]; @@ -34,12 +37,23 @@ setptr(ibuf) s = 0; l = 0; maybe = 1; - flag = MUSED; - if (value("hold") != NOSTR) - flag = MPRESERVE|MUSED; + flag = MUSED|MNEW; for (;;) { - if ((count = readline(ibuf, linebuf)) == 0) { + cp = linebuf; + c = getc(ibuf); + while (c != EOF && c != '\n') { + if (cp - linebuf >= BUFSIZ - 1) { + ungetc(c, ibuf); + *cp = 0; + break; + } + *cp++ = c; + c = getc(ibuf); + } + *cp = 0; + if (cp == linebuf && c == EOF) { this.m_flag = flag; + flag = MUSED|MNEW; this.m_offset = offsetof(offset); this.m_block = blockof(offset); this.m_size = s; @@ -53,13 +67,19 @@ setptr(ibuf) close(mestmp); return; } - if (putline(otf, linebuf) < 0) { + count = cp - linebuf + 1; + for (cp = linebuf; *cp;) + putc(*cp++, otf); + putc('\n', otf); + if (ferror(otf)) { perror("/tmp"); exit(1); } - if (maybe && ishead(linebuf)) { + if (maybe && linebuf[0] == 'F' && ishead(linebuf)) { msgCount++; this.m_flag = flag; + flag = MUSED|MNEW; + inhead = 1; this.m_block = blockof(offset); this.m_offset = offsetof(offset); this.m_size = s; @@ -71,6 +91,23 @@ setptr(ibuf) exit(1); } } + if (linebuf[0] == 0) + inhead = 0; + if (inhead && index(linebuf, ':')) { + cp = linebuf; + cp2 = wbuf; + while (isalpha(*cp)) + *cp2++ = *cp++; + *cp2 = 0; + if (icequal(wbuf, "status")) { + cp = index(linebuf, ':'); + if (index(cp, 'R')) + flag |= MREAD; + if (index(cp, 'O')) + flag &= ~MNEW; + inhead = 0; + } + } offset += count; s += count; l++; @@ -100,6 +137,38 @@ putline(obuf, linebuf) return(c+1); } +/* + * Quickly read a line from the specified input into the line + * buffer; return characters read. + */ + +freadline(ibuf, linebuf) + register FILE *ibuf; + register char *linebuf; +{ + register int c; + register char *cp; + + c = getc(ibuf); + cp = linebuf; + while (c != '\n' && c != EOF) { + if (c == 0) { + c = getc(ibuf); + continue; + } + if (cp - linebuf >= BUFSIZ-1) { + *cp = 0; + return(cp - linebuf + 1); + } + *cp++ = c; + c = getc(ibuf); + } + if (c == EOF && cp == linebuf) + return(0); + *cp = 0; + return(cp - linebuf + 1); +} + /* * Read up a line from the specified input into the line * buffer. Return the number of characters read. Do not @@ -167,6 +236,8 @@ makemessage(f) printf("Insufficient memory for %d messages\n", msgCount); exit(1); } + if (message != (struct message *) 0) + cfree((char *) message); message = (struct message *) mp; dot = message; lseek(f, 0L, 0); @@ -175,6 +246,7 @@ makemessage(f) for (m = &message[0]; m < &message[msgCount]; m++) { m->m_size = (m+1)->m_size; m->m_lines = (m+1)->m_lines; + m->m_flag = (m+1)->m_flag; } message[msgCount].m_size = 0; message[msgCount].m_lines = 0; @@ -223,11 +295,18 @@ edstop() register struct message *mp; FILE *obuf; - for (mp = &message[0], gotcha = 0; mp < &message[msgCount]; mp++) - if (mp->m_flag & (MODIFY|MDELETED)) { + if (readonly) + return; + for (mp = &message[0], gotcha = 0; mp < &message[msgCount]; mp++) { + if (mp->m_flag & MNEW) { + mp->m_flag &= ~MNEW; + mp->m_flag |= MSTATUS; + } + if (mp->m_flag & (MODIFY|MDELETED|MSTATUS)) { gotcha++; break; } + } if (!gotcha) return; printf("\"%s\" ", editfile);