Cleaned up.
committer: mfx <mfx> 968681755 +0000
This commit is contained in:
+42
-33
@@ -188,99 +188,108 @@ static int set_fg(FILE *f, int fg)
|
|||||||
static void print0(FILE *f, const char *ss)
|
static void print0(FILE *f, const char *ss)
|
||||||
{
|
{
|
||||||
int cx, cy;
|
int cx, cy;
|
||||||
int c_cx, c_cy;
|
int old_cx = 0, old_cy = 0;
|
||||||
const int sx = screen->getCols(screen);
|
const int sx = screen->getCols(screen);
|
||||||
const int sy = screen->getRows(screen);
|
const int sy = screen->getRows(screen);
|
||||||
int pass;
|
int pass;
|
||||||
|
|
||||||
// Note:
|
// Note:
|
||||||
// We use 2 passes to avoid unnecessary system calls because
|
// We use 2 passes to avoid unnecessary system calls because
|
||||||
// scrollScreen() under Win32 is *extremely* slow.
|
// scrollUp() under Win32 is *extremely* slow.
|
||||||
UNUSED(f);
|
UNUSED(f);
|
||||||
screen->getCursor(screen,&cx,&cy);
|
|
||||||
c_cx = cx; c_cy = cy;
|
screen->getCursor(screen,&old_cx,&old_cy);
|
||||||
|
cx = old_cx; cy = old_cy;
|
||||||
|
|
||||||
for (pass = 0; pass < 2; pass++)
|
for (pass = 0; pass < 2; pass++)
|
||||||
{
|
{
|
||||||
const char *s = ss;
|
const char *s = ss;
|
||||||
// char buffer for pass == 1
|
// char buffer for pass 2
|
||||||
char p[256+1];
|
char p[256+1];
|
||||||
int pi = 0, px = -1, py = -1;
|
int pi = 0, px = 0, py = 0;
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
|
// walk over whitespace
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
if (*s == '\n')
|
if (*s == '\n')
|
||||||
{
|
{
|
||||||
c_cy++;
|
cx = 0;
|
||||||
c_cx = 0;
|
cy++;
|
||||||
}
|
}
|
||||||
else if (*s == '\r')
|
else if (*s == '\r')
|
||||||
{
|
{
|
||||||
c_cx = 0;
|
cx = 0;
|
||||||
if (pass > 0 && c_cy < sy)
|
if (pass > 0 && cy < sy)
|
||||||
screen->clearLine(screen,c_cy);
|
screen->clearLine(screen,cy);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
s++;
|
s++;
|
||||||
}
|
}
|
||||||
if (c_cx >= sx)
|
// adjust cursor
|
||||||
|
if (cx >= sx)
|
||||||
{
|
{
|
||||||
c_cy++;
|
cx = 0;
|
||||||
c_cx = 0;
|
cy++;
|
||||||
}
|
}
|
||||||
if (pass > 0)
|
if (pass > 0)
|
||||||
{
|
{
|
||||||
if (pi > 0 && (*s == 0 || py != c_cy))
|
// check if we should print something
|
||||||
|
if (pi > 0 && (*s == 0 || py != cy))
|
||||||
{
|
{
|
||||||
p[pi] = 0;
|
p[pi] = 0;
|
||||||
screen->putString(screen,p,px,py);
|
screen->putString(screen,p,px,py);
|
||||||
pi = 0;
|
pi = 0;
|
||||||
}
|
}
|
||||||
if (c_cy >= sy)
|
// check if we should scroll even more (this can happen
|
||||||
|
// if the string is longer than sy lines)
|
||||||
|
if (cy >= sy)
|
||||||
{
|
{
|
||||||
int scroll_y = c_cy - sy + 1;
|
int scroll_y = cy - sy + 1;
|
||||||
screen->scrollUp(screen,scroll_y);
|
screen->scrollUp(screen,scroll_y);
|
||||||
c_cy -= scroll_y;
|
cy -= scroll_y;
|
||||||
if (c_cy < 0)
|
if (cy < 0)
|
||||||
c_cy = 0;
|
cy = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// done ?
|
||||||
if (*s == 0)
|
if (*s == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (pass > 0)
|
if (pass > 0)
|
||||||
{
|
{
|
||||||
|
// store current char
|
||||||
if (pi == 0)
|
if (pi == 0)
|
||||||
{
|
{
|
||||||
px = c_cx;
|
px = cx;
|
||||||
py = c_cy;
|
py = cy;
|
||||||
}
|
}
|
||||||
p[pi++] = *s;
|
p[pi++] = *s;
|
||||||
}
|
}
|
||||||
c_cx++;
|
// advance
|
||||||
|
cx++;
|
||||||
s++;
|
s++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pass == 0)
|
if (pass == 0)
|
||||||
{
|
{
|
||||||
c_cx = cx;
|
// end of pass 1 - scroll up, restore cursor
|
||||||
if (c_cy >= sy)
|
if (cy >= sy)
|
||||||
{
|
{
|
||||||
int scroll_y = c_cy - sy + 1;
|
int scroll_y = cy - sy + 1;
|
||||||
screen->scrollUp(screen,scroll_y);
|
screen->scrollUp(screen,scroll_y);
|
||||||
c_cy = cy - scroll_y;
|
cy = old_cy - scroll_y;
|
||||||
if (c_cy < 0)
|
if (cy < 0)
|
||||||
c_cy = 0;
|
cy = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
c_cy = cy;
|
cy = old_cy;
|
||||||
|
cx = old_cx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
screen->setCursor(screen,c_cx,c_cy);
|
screen->setCursor(screen,cx,cy);
|
||||||
screen->refresh(screen);
|
screen->refresh(screen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user