document distributed with 4.3BSD
[unix-history] / usr / src / usr.bin / mail / fio.c
index 80fe866..c195eab 100644 (file)
@@ -1,6 +1,12 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)fio.c      2.17 (Berkeley) %G%";
-#endif
+static char *sccsid = "@(#)fio.c       5.3 (Berkeley) %G%";
+#endif not lint
 
 #include "rcv.h"
 #include <sys/stat.h>
 
 #include "rcv.h"
 #include <sys/stat.h>
@@ -40,19 +46,7 @@ setptr(ibuf)
        maybe = 1;
        flag = MUSED|MNEW;
        for (;;) {
        maybe = 1;
        flag = MUSED|MNEW;
        for (;;) {
-               cp = linebuf;
-               c = getc(ibuf);
-               while (c != EOF && c != '\n') {
-                       if (cp - linebuf >= LINESIZE - 1) {
-                               ungetc(c, ibuf);
-                               *cp = 0;
-                               break;
-                       }
-                       *cp++ = c;
-                       c = getc(ibuf);
-               }
-               *cp = 0;
-               if (cp == linebuf && c == EOF) {
+               if (fgets(linebuf, LINESIZE, ibuf) == NULL) {
                        this.m_flag = flag;
                        flag = MUSED|MNEW;
                        this.m_offset = offsetof(offset);
                        this.m_flag = flag;
                        flag = MUSED|MNEW;
                        this.m_offset = offsetof(offset);
@@ -68,10 +62,11 @@ setptr(ibuf)
                        close(mestmp);
                        return;
                }
                        close(mestmp);
                        return;
                }
-               count = cp - linebuf + 1;
-               for (cp = linebuf; *cp;)
-                       putc(*cp++, otf);
-               putc('\n', otf);
+               count = strlen(linebuf);
+               fputs(linebuf, otf);
+               cp = linebuf + (count - 1);
+               if (*cp == '\n')
+                       *cp = 0;
                if (ferror(otf)) {
                        perror("/tmp");
                        exit(1);
                if (ferror(otf)) {
                        perror("/tmp");
                        exit(1);
@@ -94,14 +89,10 @@ setptr(ibuf)
                }
                if (linebuf[0] == 0)
                        inhead = 0;
                }
                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 (inhead && (cp = index(linebuf, ':'))) {
+                       *cp = 0;
+                       if (icequal(linebuf, "status")) {
+                               ++cp;
                                if (index(cp, 'R'))
                                        flag |= MREAD;
                                if (index(cp, 'O'))
                                if (index(cp, 'R'))
                                        flag |= MREAD;
                                if (index(cp, 'O'))
@@ -138,38 +129,6 @@ putline(obuf, linebuf)
        return(c+1);
 }
 
        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
 /*
  * Read up a line from the specified input into the line
  * buffer.  Return the number of characters read.  Do not
@@ -180,23 +139,15 @@ readline(ibuf, linebuf)
        FILE *ibuf;
        char *linebuf;
 {
        FILE *ibuf;
        char *linebuf;
 {
-       register char *cp;
-       register int c;
+       register int n;
 
 
-       do {
-               clearerr(ibuf);
-               c = getc(ibuf);
-               for (cp = linebuf; c != '\n' && c != EOF; c = getc(ibuf)) {
-                       if (c == 0)
-                               continue;
-                       if (cp - linebuf < LINESIZE-2)
-                               *cp++ = c;
-               }
-       } while (ferror(ibuf) && ibuf == stdin);
-       *cp = 0;
-       if (c == EOF && cp == linebuf)
+       clearerr(ibuf);
+       if (fgets(linebuf, LINESIZE, ibuf) == NULL)
                return(0);
                return(0);
-       return(cp - linebuf + 1);
+       n = strlen(linebuf);
+       if (n >= 1 && linebuf[n-1] == '\n')
+               linebuf[n-1] = '\0';
+       return(n);
 }
 
 /*
 }
 
 /*
@@ -395,7 +346,7 @@ done:
 }
 
 static int sigdepth = 0;               /* depth of holdsigs() */
 }
 
 static int sigdepth = 0;               /* depth of holdsigs() */
-static int sigmask = 0;
+static int omask = 0;
 /*
  * Hold signals SIGHUP - SIGQUIT.
  */
 /*
  * Hold signals SIGHUP - SIGQUIT.
  */
@@ -404,7 +355,7 @@ holdsigs()
        register int i;
 
        if (sigdepth++ == 0)
        register int i;
 
        if (sigdepth++ == 0)
-               sigmask = sigblock(mask(SIGHUP)|mask(SIGINT)|mask(SIGQUIT));
+               omask = sigblock(sigmask(SIGHUP)|sigmask(SIGINT)|sigmask(SIGQUIT));
 }
 
 /*
 }
 
 /*
@@ -415,7 +366,7 @@ relsesigs()
        register int i;
 
        if (--sigdepth == 0)
        register int i;
 
        if (--sigdepth == 0)
-               sigsetmask(sigmask);
+               sigsetmask(omask);
 }
 
 /*
 }
 
 /*