aboutsummaryrefslogtreecommitdiffstats
path: root/com32/rosh
diff options
context:
space:
mode:
authorGene Cumm <gene.cumm@gmail.com>2010-07-02 17:40:39 -0400
committerGene Cumm <gene.cumm@gmail.com>2010-07-07 09:59:21 -0400
commitee4411236c606483e29ef26ed6d6d8b4d927a49e (patch)
tree7aa7ca62121effacfff4771bb3fb0b8740157d3a /com32/rosh
parent8f38bdc111eca5eb0683b8f385d5aa155f8f9e5a (diff)
downloadsyslinux-ee4411236c606483e29ef26ed6d6d8b4d927a49e.tar.gz
syslinux-ee4411236c606483e29ef26ed6d6d8b4d927a49e.tar.xz
syslinux-ee4411236c606483e29ef26ed6d6d8b4d927a49e.zip
rosh: move scrbuf to more's main function; malloc and free oversize buffer.
Diffstat (limited to 'com32/rosh')
-rw-r--r--com32/rosh/rosh.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/com32/rosh/rosh.c b/com32/rosh/rosh.c
index 594c8008..7ee30fd9 100644
--- a/com32/rosh/rosh.c
+++ b/com32/rosh/rosh.c
@@ -775,12 +775,11 @@ void rosh_dir(const char *cmdstr)
/* Page through a buffer string
* buf Buffer to page through
*/
-void rosh_more_buf(char *buf, int buflen, int rows, int cols)
+void rosh_more_buf(char *buf, int buflen, int rows, int cols, char *scrbuf)
{
char *bufp, *bufeol, *bufeol2; /* Pointer to current and next
end-of-line position in buffer */
int bufpos, bufcnt; /* current position, count characters */
- char scrbuf[ROSH_SBUF_SZ];
int inc;
int i, numln; /* Index, Number of lines */
int elpl; /* Extra lines per line read */
@@ -800,13 +799,15 @@ void rosh_more_buf(char *buf, int buflen, int rows, int cols)
i = numln;
} else {
elpl = ((bufeol2 - bufeol - 1) / cols);
+ if (elpl < 0)
+ elpl = 0;
i += elpl;
ROSH_DEBUG2(" %d/%d ", elpl, i+1);
/* If this will not push too much, use it */
/* but if it's the first line, use it */
/* //HERE: We should probably snip the line off */
if ((i < numln) || ((i == elpl) && (i >= numln)))
- bufeol = bufeol2 + 1;
+ bufeol = bufeol2 + 1;
}
}
ROSH_DEBUG2("\n");
@@ -836,7 +837,7 @@ void rosh_more_buf(char *buf, int buflen, int rows, int cols)
/* Page through a single file using the open file stream
* fd File Descriptor
*/
-void rosh_more_fd(int fd, int rows, int cols)
+void rosh_more_fd(int fd, int rows, int cols, char *scrbuf)
{
struct stat fdstat;
int status;
@@ -858,7 +859,7 @@ void rosh_more_fd(int fd, int rows, int cols)
((int)fdstat.st_size - bufpos), f);
}
fclose(f);
- rosh_more_buf(buf, bufpos, rows, cols);
+ rosh_more_buf(buf, bufpos, rows, cols, scrbuf);
}
} else {
}
@@ -875,6 +876,7 @@ void rosh_more(const char *cmdstr)
char filestr[ROSH_PATH_SZ];
int cmdpos;
int rows, cols;
+ char *scrbuf;
ROSH_DEBUG("CMD: '%s'\n", cmdstr);
/* Initialization */
@@ -890,6 +892,9 @@ void rosh_more(const char *cmdstr)
cols = 75;
}
ROSH_DEBUG("\tUSE ROWS='%d'\tCOLS='%d'\n", rows, cols);
+ scrbuf = calloc(rows, cols + 1);
+ if (!scrbuf)
+ return;
/* skip the first word */
cmdpos = rosh_parse_sp_1(filestr, cmdstr, cmdpos);
@@ -902,7 +907,7 @@ void rosh_more(const char *cmdstr)
printf("--File = '%s'\n", filestr);
fd = open(filestr, O_RDONLY);
if (fd != -1) {
- rosh_more_fd(fd, rows, cols);
+ rosh_more_fd(fd, rows, cols, scrbuf);
close(fd);
} else {
rosh_error(errno, "more", filestr);
@@ -912,6 +917,7 @@ void rosh_more(const char *cmdstr)
}
rosh_console_std();
}
+ free(scrbuf);
} /* rosh_more */
/* Page a file with rewind