Berkeley specific header
[unix-history] / usr / src / usr.bin / more / ch.c
index 6760531..ee926e4 100644 (file)
@@ -3,15 +3,13 @@
  * Copyright (c) 1988 Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1988 Regents of the University of California.
  * All rights reserved.
  *
- * This code is derived from software contributed to Berkeley by
- * Mark Nudleman.
- * 
  * Redistribution and use in source and binary forms are permitted
  * provided that the above copyright notice and this paragraph are
  * duplicated in all such forms and that any documentation,
  * advertising materials, and other materials related to such
  * distribution and use acknowledge that the software was developed
  * Redistribution and use in source and binary forms are permitted
  * provided that the above copyright notice and this paragraph are
  * duplicated in all such forms and that any documentation,
  * advertising materials, and other materials related to such
  * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
+ * by Mark Nudleman and the University of California, Berkeley.  The
+ * name of Mark Nudleman or the
  * University may not be used to endorse or promote products derived
  * from this software without specific prior written permission.
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  * University may not be used to endorse or promote products derived
  * from this software without specific prior written permission.
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
@@ -20,7 +18,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)ch.c       5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)ch.c       5.5 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -63,9 +61,6 @@ extern int ispipe;
 extern int autobuf;
 extern int cbufs;
 extern int sigs;
 extern int autobuf;
 extern int cbufs;
 extern int sigs;
-#if LOGFILE
-extern int logfile;
-#endif
 
 /*
  * Current position in file.
 
 /*
  * Current position in file.
@@ -158,7 +153,7 @@ fch_get()
                        quit();
                }
        } else
                        quit();
                }
        } else
-               lseek(file, pos, 0);
+               (void)lseek(file, pos, L_SET);
 
        /*
         * Read the block.
 
        /*
         * Read the block.
@@ -176,14 +171,6 @@ fch_get()
        if (ispipe)
                last_piped_pos += n;
 
        if (ispipe)
                last_piped_pos += n;
 
-#if LOGFILE
-       /*
-        * If we have a log file, write the new data to it.
-        */
-       if (logfile >= 0 && n > 0)
-               write(logfile, &bp->data[bp->datasize], n);
-#endif
-
        bp->datasize += n;
 
        /*
        bp->datasize += n;
 
        /*
@@ -235,58 +222,6 @@ fch_get()
        return (bp->data[ch_offset]);
 }
 
        return (bp->data[ch_offset]);
 }
 
-#if LOGFILE
-/*
- * Close the logfile.
- * If we haven't read all of standard input into it, do that now.
- */
-       public void
-end_logfile()
-{
-       static int tried = 0;
-
-       if (logfile < 0)
-               return;
-       if (!tried && ch_fsize == NULL_POSITION)
-       {
-               tried = 1;
-               ierror("finishing logfile");
-               while (ch_forw_get() != EOI)
-                       if (sigs)
-                               break;
-       }
-       close(logfile);
-       logfile = -1;
-}
-
-/*
- * Start a log file AFTER less has already been running.
- * Invoked from the - command; see toggle_option().
- * Write all the existing buffered data to the log file.
- */
-       public void
-sync_logfile()
-{
-       register struct buf *bp;
-       register int n;
-       long block;
-       long last_block;
-
-       last_block = (last_piped_pos + BUFSIZ - 1) / BUFSIZ;
-       for (block = 0;  block <= last_block;  block++)
-               for (bp = buf_head;  bp != END_OF_CHAIN;  bp = bp->next)
-                       if (bp->block == block)
-                       {
-                               n = bp->datasize;
-                               if (bp->data[n-1] == EOI)
-                                       n--;
-                               write(logfile, bp->data, n);
-                               break;
-                       }
-}
-
-#endif
-
 /*
  * Determine if a specific block is currently in one of the buffers.
  */
 /*
  * Determine if a specific block is currently in one of the buffers.
  */
@@ -382,7 +317,7 @@ ch_length()
 {
        if (ispipe)
                return (ch_fsize);
 {
        if (ispipe)
                return (ch_fsize);
-       return ((POSITION)(lseek(file, (offset_t)0, 2)));
+       return ((POSITION)(lseek(file, (off_t)0, L_XTND)));
 }
 
 /*
 }
 
 /*
@@ -452,7 +387,7 @@ ch_init(want_nbufs, keep)
                 * If we don't have ANY, then quit.
                 * Otherwise, just report the error and return.
                 */
                 * If we don't have ANY, then quit.
                 * Otherwise, just report the error and return.
                 */
-               sprintf(message, "cannot allocate %d buffers",
+               (void)sprintf(message, "cannot allocate %d buffers",
                        want_nbufs - nbufs);
                error(message);
                if (nbufs == 0)
                        want_nbufs - nbufs);
                error(message);
                if (nbufs == 0)
@@ -489,7 +424,7 @@ ch_addbuf(nnew)
         * We don't have enough buffers.  
         * Allocate some new ones.
         */
         * We don't have enough buffers.  
         * Allocate some new ones.
         */
-       newbufs = (struct buf *) calloc(nnew, sizeof(struct buf));
+       newbufs = (struct buf *) calloc((u_int)nnew, sizeof(struct buf));
        if (newbufs == NULL)
                return (1);
 
        if (newbufs == NULL)
                return (1);