Skip to content

Commit

Permalink
Make -b argument be in units of 1K.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwsw committed Dec 31, 2001
1 parent 0c6cda1 commit b6393f4
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 42 deletions.
2 changes: 1 addition & 1 deletion NEWS.VER
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

* Default LESSCHARSET for MS-DOS versions is now "dos".

* Improved performance in reading very large files.
* Improved performance in reading very large pipes.

* Eliminated some dependencies on file offets being 32 bits.

Expand Down
37 changes: 13 additions & 24 deletions ch.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ struct filestate {

static struct filestate *thisfile;
static int ch_ungotchar = -1;
static int maxbufs = -1;

extern int autobuf;
extern int sigs;
extern int cbufs;
extern int secure;
extern constant char helpdata[];
extern constant int size_helpdata;
Expand Down Expand Up @@ -162,7 +162,7 @@ fch_get()
* 2. We haven't allocated the max buffers for this file yet.
*/
if ((autobuf && !(ch_flags & CH_CANSEEK)) ||
(cbufs == -1 || ch_nbufs < cbufs))
(maxbufs < 0 || ch_nbufs < maxbufs))
if (ch_addbuf())
/*
* Allocation failed: turn off autobuf.
Expand Down Expand Up @@ -561,32 +561,21 @@ ch_back_get()
}

/*
* Allocate buffers.
* Caller wants us to have a total of at least want_nbufs buffers.
* Set max amount of buffer space.
* bufspace is in units of 1024 bytes. -1 mean no limit.
*/
public int
ch_nbuf(want_nbufs)
int want_nbufs;
public void
ch_setbufspace(bufspace)
int bufspace;
{
PARG parg;

while (ch_nbufs < want_nbufs)
if (bufspace < 0)
maxbufs = -1;
else
{
if (ch_addbuf())
{
/*
* Cannot allocate enough buffers.
* If we don't have ANY, then quit.
* Otherwise, just report the error and return.
*/
parg.p_int = want_nbufs - ch_nbufs;
error("Cannot allocate %d buffers", &parg);
if (ch_nbufs == 0)
quit(QUIT_ERROR);
break;
}
maxbufs = ((bufspace * 1024) + LBUFSIZE-1) / LBUFSIZE;
if (maxbufs < 1)
maxbufs = 1;
}
return (ch_nbufs);
}

/*
Expand Down
19 changes: 12 additions & 7 deletions less.nro.VER
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ less \- opposite of more
.br
.B "less [-[+]aBcCdeEfFgGiIJmMnNqQrRsSuUVwWX]"
.br
.B " [-b \fIbufs\fP] [-h \fIlines\fP] [-j \fIline\fP] [-k \fIkeyfile\fP]"
.B " [-b \fIspace\fP] [-h \fIlines\fP] [-j \fIline\fP] [-k \fIkeyfile\fP]"
.br
.B " [-{oO} \fIlogfile\fP] [-p \fIpattern\fP] [-P \fIprompt\fP] [-t \fItag\fP]"
.br
Expand Down Expand Up @@ -452,19 +452,24 @@ thus skipping all lines displayed on the screen.
By default, searches start at the second line on the screen
(or after the last found line; see the -j option).
.IP "-b\fIn\fP or --buffers=\fIn\fP"
Specifies the number of buffers
Specifies the amount of buffer space
.I less
will use for each file.
Buffers are 1K, and by default 10 buffers are used for each file
(except if the file is a pipe; see the -B option).
The number \fIn\fP specifies a different number of buffers to use.
will use for each file, in units of kilobytes (1024 bytes).
By default 64K of buffer space is used for each file
(unless the file is a pipe; see the -B option).
The -b option specifies instead that \fIn\fP kilobytes of
buffer space should be used for each file.
If \fIn\FP is -1, buffer space is unlimited; that is,
the entire file is read into memory.
.IP "-B or --auto-buffers"
By default, when data is read from a pipe,
buffers are allocated automatically as needed.
If a large amount of data is read from the pipe, this can cause
a large amount of memory to be allocated.
The -B option disables this automatic allocation of buffers for pipes,
so that only the number of buffers specified by the -b option are used.
so that only 64K
(or the amount of space specified by the -b option).
is used for the pipe.
Warning: use of -B can result in erroneous display, since only the
most recently viewed part of the file is kept in memory;
any earlier data is lost.
Expand Down
10 changes: 5 additions & 5 deletions optfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "option.h"

extern int nbufs;
extern int cbufs;
extern int bufspace;
extern int pr_type;
extern int plusoption;
extern int swindow;
Expand Down Expand Up @@ -316,14 +316,14 @@ opt_b(type, s)
{
switch (type)
{
case INIT:
case TOGGLE:
case QUERY:
/*
* Allocate the new number of buffers.
* Set the new number of buffers.
*/
cbufs = ch_nbuf(cbufs);
ch_setbufspace(bufspace);
break;
case INIT:
case QUERY:
break;
}
}
Expand Down
8 changes: 4 additions & 4 deletions opttbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public int back_scroll; /* Repaint screen on backwards movement */
public int forw_scroll; /* Repaint screen on forward movement */
public int caseless; /* Do "caseless" searches */
public int linenums; /* Use line numbers */
public int cbufs; /* Current number of buffers */
public int autobuf; /* Automatically allocate buffers as needed */
public int bufspace; /* Max buffer space per file (K) */
public int ctldisp; /* Send control chars to screen untranslated */
public int force_open; /* Open the file even if not regular file */
public int swindow; /* Size of scrolling window */
Expand Down Expand Up @@ -128,9 +128,9 @@ static struct option option[] =
},

{ 'b', &b_optname,
NUMBER, 10, &cbufs, opt_b,
"Buffers: ",
"%d buffers",
NUMBER, 64, &bufspace, opt_b,
"Max buffer space per file (K): ",
"Max buffer space per file: %dK",
NULL
},
{ 'B', &B__optname,
Expand Down
3 changes: 2 additions & 1 deletion version.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,8 @@ v370 12/23/01 Fix tags error messages.
-----------------------------------------------------------------
v371 12/26/01 Fix new_file bug; use popen in Windows version;
fix some compiler warnings.
v372 12/29/01 Make -b be in units of 1K.
*/

char version[] = "371";
char version[] = "372";

0 comments on commit b6393f4

Please sign in to comment.