Skip to content
Snippets Groups Projects
Commit b1ecd9b6 authored by rswindell's avatar rswindell
Browse files

Return to the sbbs v2 behavior of printfile() behavior (sort-of): When

P_OPENCLOSE mode flag is *not* specified, do not malloc()/read() the entire
file and then display. Instead, print one line at a time (so long as that
line is <= 1MB in length), calling putmsg() for each line.

This should allow the viewing of massive text files in SBBS again without
alloc/swap issues.

I left the calls to utf8_normalize_str() in here, but I'm not so sure about
them now. putmsg() will convert UTF-8 to CP437 through print_utf8_as_cp437(),
and that only lacks a couple of conversions that utf8_normalize_str() does
(e.g. ellipsis to "..."), so that might be a good candidate to remove in
the future.
parent 3c4224c6
No related branches found
No related tags found
No related merge requests found
......@@ -39,6 +39,10 @@
#include "sbbs.h"
#include "utf8.h"
#ifndef PRINTFILE_MAX_LINE_LEN
#define PRINTFILE_MAX_LINE_LEN (1024*1024)
#endif
/****************************************************************************/
/* Prints a file remotely and locally, interpreting ^A sequences, checks */
/* for pauses, aborts and ANSI. 'str' is the path of the file to print */
......@@ -97,22 +101,43 @@ bool sbbs_t::printfile(const char* fname, long mode, long org_cols)
errormsg(WHERE,ERR_CHK,fpath,length);
return false;
}
if((buf=(char*)malloc(length+1L))==NULL) {
if(mode&P_OPENCLOSE) {
if((buf=(char*)malloc(length+1L))==NULL) {
fclose(stream);
errormsg(WHERE,ERR_ALLOC,fpath,length+1L);
return false;
}
l=lread(file,buf,length);
fclose(stream);
if(l!=length)
errormsg(WHERE,ERR_READ,fpath,length);
else {
buf[l]=0;
if((mode&P_UTF8) && !term_supports(UTF8))
utf8_normalize_str(buf);
putmsg(buf,mode,org_cols);
}
free(buf);
} else { // Line-at-a-time mode
if(length > PRINTFILE_MAX_LINE_LEN)
length = PRINTFILE_MAX_LINE_LEN;
if((buf=(char*)malloc(length+1L))==NULL) {
fclose(stream);
errormsg(WHERE,ERR_ALLOC,fpath,length+1L);
return false;
}
while(!feof(stream) && !msgabort()) {
if(fgets(buf, length-1, stream) == NULL)
break;
buf[length] = 0;
if((mode&P_UTF8) && !term_supports(UTF8))
utf8_normalize_str(buf);
putmsg(buf, mode, org_cols);
}
free(buf);
fclose(stream);
errormsg(WHERE,ERR_ALLOC,fpath,length+1L);
return false;
}
l=lread(file,buf,length);
fclose(stream);
if(l!=length)
errormsg(WHERE,ERR_READ,fpath,length);
else {
buf[l]=0;
if((mode&P_UTF8) && !term_supports(UTF8))
utf8_normalize_str(buf);
putmsg(buf,mode,org_cols);
}
free(buf);
if((mode&P_NOABORT || rip) && online==ON_REMOTE) {
SYNC;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment