Skip to content

Commit 068bbf7

Browse files
committed
tvdemo: Unicode support and arbitrary line length
1 parent 7aa31b1 commit 068bbf7

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

examples/tvdemo/fileview.cpp

+9-10
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,9 @@ void TFileViewer::draw()
6767

6868
if( delta.y + i < fileLines->getCount() )
6969
{
70-
char s[maxLineLength+1];
7170
p = (char *)( fileLines->at(delta.y+i) );
72-
if( p == 0 || strlen(p) < delta.x )
73-
s[0] = EOS;
74-
else
75-
strnzcpy( s, p+delta.x, maxLineLength+1 );
76-
b.moveStr( 0, s, c );
71+
if( p )
72+
b.moveStr( 0, p, c, (short)size.x, delta.x );
7773
}
7874
writeBuf( 0, i, (short)size.x, 1, b );
7975
}
@@ -103,7 +99,8 @@ void TFileViewer::readFile( const char *fName )
10399
}
104100
else
105101
{
106-
char line[maxLineLength+1];
102+
char *line = (char *) malloc(maxLineLength);
103+
size_t lineSize = maxLineLength;
107104
char c;
108105
while( !lowMemory() &&
109106
!fileToView.eof() &&
@@ -113,17 +110,19 @@ void TFileViewer::readFile( const char *fName )
113110
int i = 0;
114111
while ( !fileToView.eof() && c != '\n' && c != '\r' ) // read a whole line
115112
{
116-
if ( i < maxLineLength )
117-
line[i++] = c;
113+
if (i == lineSize)
114+
line = (char *) realloc(line, (lineSize *= 2));
115+
line[i++] = c;
118116
fileToView.get( c );
119117
}
120118
line[i] = '\0';
121119
if ( c == '\r' && fileToView.peek() == '\n')
122120
fileToView.get( c ); // grab trailing newline on CRLF
123-
limit.x = max( limit.x, strlen( line ) );
121+
limit.x = max( limit.x, strwidth( line ) );
124122
fileLines->insert( newStr( line ) );
125123
}
126124
isValid = True;
125+
::free(line);
127126
}
128127
limit.y = fileLines->getCount();
129128
}

include/tvision/drawbuf.h

-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@
2222
#if defined( Uses_TDrawBuffer ) && !defined( __TDrawBuffer )
2323
#define __TDrawBuffer
2424

25-
#ifndef __BORLANDC__
26-
#include <string_view>
27-
#endif
28-
2925
class TDrawBuffer
3026
{
3127

0 commit comments

Comments
 (0)