Skip to content

Commit

Permalink
tvdemo: Unicode support and arbitrary line length
Browse files Browse the repository at this point in the history
  • Loading branch information
magiblot committed Aug 8, 2020
1 parent 7aa31b1 commit 068bbf7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
19 changes: 9 additions & 10 deletions examples/tvdemo/fileview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,9 @@ void TFileViewer::draw()

if( delta.y + i < fileLines->getCount() )
{
char s[maxLineLength+1];
p = (char *)( fileLines->at(delta.y+i) );
if( p == 0 || strlen(p) < delta.x )
s[0] = EOS;
else
strnzcpy( s, p+delta.x, maxLineLength+1 );
b.moveStr( 0, s, c );
if( p )
b.moveStr( 0, p, c, (short)size.x, delta.x );
}
writeBuf( 0, i, (short)size.x, 1, b );
}
Expand Down Expand Up @@ -103,7 +99,8 @@ void TFileViewer::readFile( const char *fName )
}
else
{
char line[maxLineLength+1];
char *line = (char *) malloc(maxLineLength);
size_t lineSize = maxLineLength;
char c;
while( !lowMemory() &&
!fileToView.eof() &&
Expand All @@ -113,17 +110,19 @@ void TFileViewer::readFile( const char *fName )
int i = 0;
while ( !fileToView.eof() && c != '\n' && c != '\r' ) // read a whole line
{
if ( i < maxLineLength )
line[i++] = c;
if (i == lineSize)
line = (char *) realloc(line, (lineSize *= 2));
line[i++] = c;
fileToView.get( c );
}
line[i] = '\0';
if ( c == '\r' && fileToView.peek() == '\n')
fileToView.get( c ); // grab trailing newline on CRLF
limit.x = max( limit.x, strlen( line ) );
limit.x = max( limit.x, strwidth( line ) );
fileLines->insert( newStr( line ) );
}
isValid = True;
::free(line);
}
limit.y = fileLines->getCount();
}
Expand Down
4 changes: 0 additions & 4 deletions include/tvision/drawbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@
#if defined( Uses_TDrawBuffer ) && !defined( __TDrawBuffer )
#define __TDrawBuffer

#ifndef __BORLANDC__
#include <string_view>
#endif

class TDrawBuffer
{

Expand Down

0 comments on commit 068bbf7

Please sign in to comment.