document distributed with 4.1BSD
[unix-history] / usr / src / usr.bin / ex / ex_io.c
index 9c681bb..fdfdba5 100644 (file)
@@ -1,5 +1,13 @@
-/* Copyright (c) 1981 Regents of the University of California */
-static char *sccsid = "@(#)ex_io.c     7.7     %G%";
+/*
+ * 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
+static char *sccsid = "@(#)ex_io.c     7.11 (Berkeley) %G%";
+#endif not lint
+
 #include "ex.h"
 #include "ex_argv.h"
 #include "ex_temp.h"
 #include "ex.h"
 #include "ex_argv.h"
 #include "ex_temp.h"
@@ -413,10 +421,18 @@ rop(c)
 rop2()
 {
        line *first, *last, *a;
 rop2()
 {
        line *first, *last, *a;
+       struct stat statb;
 
        deletenone();
        clrstats();
        first = addr2 + 1;
 
        deletenone();
        clrstats();
        first = addr2 + 1;
+       if (fstat(io, &statb) < 0)
+               bsize = LBSIZE;
+       else {
+               bsize = statb.st_blksize;
+               if (bsize <= 0)
+                       bsize = LBSIZE;
+       }
        ignore(append(getfile, addr2));
        last = dot;
        /*
        ignore(append(getfile, addr2));
        last = dot;
        /*
@@ -631,7 +647,7 @@ getfile()
        fp = nextip;
        do {
                if (--ninbuf < 0) {
        fp = nextip;
        do {
                if (--ninbuf < 0) {
-                       ninbuf = read(io, genbuf, LBSIZE) - 1;
+                       ninbuf = read(io, genbuf, bsize) - 1;
                        if (ninbuf < 0) {
                                if (lp != linebuf) {
                                        lp++;
                        if (ninbuf < 0) {
                                if (lp != linebuf) {
                                        lp++;
@@ -641,13 +657,14 @@ getfile()
                                return (EOF);
                        }
 #ifdef CRYPT
                                return (EOF);
                        }
 #ifdef CRYPT
-                       fp = genbuf;
-                       while(fp < &genbuf[ninbuf]) {
-                               if (*fp++ & 0200) {
-                                       if (kflag)
+                       if (kflag) {
+                               fp = genbuf;
+                               while(fp < &genbuf[ninbuf]) {
+                                       if (*fp++ & 0200) {
                                                crblock(perm, genbuf, ninbuf+1,
                                                crblock(perm, genbuf, ninbuf+1,
-cntch);
-                                       break;
+       cntch);
+                                               break;
+                                       }
                                }
                        }
 #endif
                                }
                        }
 #endif
@@ -685,13 +702,21 @@ int isfilter;
        line *a1;
        register char *fp, *lp;
        register int nib;
        line *a1;
        register char *fp, *lp;
        register int nib;
+       struct stat statb;
 
        a1 = addr1;
        clrstats();
        cntln = addr2 - a1 + 1;
        if (cntln == 0)
                return;
 
        a1 = addr1;
        clrstats();
        cntln = addr2 - a1 + 1;
        if (cntln == 0)
                return;
-       nib = BUFSIZ;
+       if (fstat(io, &statb) < 0)
+               bsize = LBSIZE;
+       else {
+               bsize = statb.st_blksize;
+               if (bsize <= 0)
+                       bsize = LBSIZE;
+       }
+       nib = bsize;
        fp = genbuf;
        do {
                getline(*a1++);
        fp = genbuf;
        do {
                getline(*a1++);
@@ -707,7 +732,7 @@ int isfilter;
                                        wrerror();
                                }
                                cntch += nib;
                                        wrerror();
                                }
                                cntch += nib;
-                               nib = BUFSIZ - 1;
+                               nib = bsize - 1;
                                fp = genbuf;
                        }
                        if ((*fp++ = *lp++) == 0) {
                                fp = genbuf;
                        }
                        if ((*fp++ = *lp++) == 0) {