#include "windows.h"
#include "screen.h"
static int
ScreenEmChars(SCREEN *pScr, char *c, int len)
{
int insert;
int ocount;
int attrib;
int extra;
int nchars;
char *acurrent;
char *current;
char *start;
SCREENLINE *pScrLine;
if (len <= 0)
return(0);
if (pScr->x != pScr->width - 1)
pScr->bWrapPending = FALSE;
else {
if (pScr->bWrapPending) {
pScr->x = 0;
pScr->bWrapPending = FALSE;
ScreenIndex(pScr);
}
}
pScrLine = GetScreenLineFromY(pScr, pScr->y);
if (pScrLine == NULL)
return(0);
current = &pScrLine->text[pScr->x];
acurrent = &pScrLine->attrib[pScr->x];
start = current;
ocount = pScr->x;
extra = 0;
attrib = pScr->attrib;
insert = pScr->IRM;
for (nchars = 0; nchars < len && *c >= 32; nchars++) {
if (insert)
ScreenInsChar(pScr, 1);
*current = *c;
*acurrent = (char) attrib;
c++;
if (pScr->x < pScr->width - 1) {
acurrent++;
current++;
pScr->x++;
}
else {
extra = 1;
if (pScr->DECAWM) {
pScr->bWrapPending = TRUE;
nchars++;
break;
}
}
}
ScreenDraw(pScr, ocount, pScr->y, pScr->attrib,
pScr->x - ocount + extra, start);
return(nchars);
}
void
ScreenEm(LPSTR c, int len, SCREEN *pScr)
{
int escflg;
RECT rc;
unsigned int ic;
char stat[20];
int i;
int nchars;
if (pScr->screen_bottom != pScr->buffer_bottom) {
ScreenUnscroll(pScr);
InvalidateRect(pScr->hWnd, NULL, TRUE);
SetScrollPos(pScr->hWnd, SB_VERT, pScr->numlines, TRUE);
}
ScreenCursorOff(pScr);
escflg = pScr->escflg;
#ifdef UM
if (pScr->localprint && len > 0) {
pcount = send_localprint(c, len);
len -= pcount;
c += pcount;
}
#endif
while (len > 0) {
while((*c < 32) && (escflg == 0) && (len > 0)) {
switch(*c) {
case 0x1b:
escflg++;
break;
case -1:
escflg = 6;
break;
#ifdef CISB
case 0x05:
bp_ENQ();
break;
#endif
case 0x07:
ScreenBell(pScr);
break;
case 0x08:
ScreenBackspace(pScr);
break;
case 0x09:
ScreenTab(pScr);
break;
case 0x0a:
case 0x0b:
case 0x0c:
ScreenIndex(pScr);
break;
case 0x0d:
ScreenCarriageFeed(pScr);
break;
#if 0
case 0x0e:
if (pScr->G1)
pScr->attrib = VSgraph(pScr->attrib);
else
pScr->attrib = VSnotgraph(pScr->attrib);
pScr->charset = 1;
break;
case 0x0f:
if(pScr->G0)
pScr->attrib = VSgraph(pScr->attrib);
else
pScr->attrib = VSnotgraph(pScr->attrib);
pScr->charset = 0;
break;
#endif
#ifdef CISB
case 0x10:
bp_DLE(c, len);
len = 0;
break;
#endif
#if 0
case 0x11:
case 0x13:
case 0x18:
case 0x1a:
break;
#endif
}
c++;
len--;
}
if (escflg == 0) {
nchars = ScreenEmChars(pScr, c, len);
c += nchars;
len -= nchars;
}
while ((len > 0) && (escflg == 1)) {
switch(*c) {
case 0x08:
ScreenBackspace(pScr);
break;
case '[':
ScreenApClear(pScr);
escflg = 2;
break;
case '#':
escflg = 3;
break;
case '(':
escflg = 4;
break;
case ')':
escflg = 5;
break;
case '>':
pScr->DECPAM = 0;
escflg = 0;
break;
case '=':
pScr->DECPAM = 1;
escflg = 0;
break;
case '7':
ScreenSaveCursor(pScr);
escflg = 0;
break;
case '8':
ScreenRestoreCursor(pScr);
escflg = 0;
break;
#if 0
case 'c':
ScreenReset(pScr);
escflg = 0;
break;
#endif
case 'D':
ScreenIndex(pScr);
escflg = 0;
break;
case 'E':
pScr->x = 0;
ScreenIndex(pScr);
escflg = 0;
break;
case 'H':
pScr->tabs[pScr->x] = 'x';
escflg = 0;
break;
#ifdef CISB
case 'I':
bp_ESC_I();
break;
#endif
case 'M':
ScreenRevIndex(pScr);
escflg = 0;
break;
case 'Z':
escflg = 0;
break;
default:
ScreenEmChars(pScr, "\033", 1);
ScreenEmChars(pScr, c, 1);
escflg = 0;
break;
}
c++;
len--;
}
while((escflg == 2) && (len > 0)) {
switch(*c) {
case 0x08:
ScreenBackspace(pScr);
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
if (pScr->parms[pScr->parmptr] < 0)
pScr->parms[pScr->parmptr] = 0;
pScr->parms[pScr->parmptr] *= 10;
pScr->parms[pScr->parmptr] += *c - '0';
break;
case '?':
pScr->parms[pScr->parmptr++] = -2;
break;
case ';':
pScr->parmptr++;
break;
case 'A':
pScr->bWrapPending = FALSE;
rc.left = pScr->x * pScr->cxChar;
rc.right = (pScr->x + 1) * pScr->cxChar;
rc.top = pScr->cyChar * pScr->y;
rc.bottom = pScr->cyChar * (pScr->y + 1);
InvalidateRect(pScr->hWnd, &rc, TRUE);
if (pScr->parms[0] < 1)
pScr->y--;
else
pScr->y -= pScr->parms[0];
if(pScr->y < pScr->top)
pScr->y = pScr->top;
ScreenRange(pScr);
escflg = 0;
SendMessage(pScr->hWnd, WM_PAINT, 0, 0);
break;
case 'B':
pScr->bWrapPending = FALSE;
rc.left = pScr->x * pScr->cxChar;
rc.right = (pScr->x + 1) * pScr->cxChar;
rc.top = pScr->cyChar * pScr->y;
rc.bottom = pScr->cyChar * (pScr->y + 1);
InvalidateRect(pScr->hWnd, &rc, TRUE);
if (pScr->parms[0] < 1)
pScr->y++;
else
pScr->y += pScr->parms[0];
if (pScr->y > pScr->bottom)
pScr->y = pScr->bottom;
ScreenRange(pScr);
escflg = 0;
SendMessage(pScr->hWnd, WM_PAINT, 0, 0);
break;
case 'C':
pScr->bWrapPending = FALSE;
rc.left = pScr->x * pScr->cxChar;
rc.right = (pScr->x + 1) * pScr->cxChar;
rc.top = pScr->cyChar * pScr->y;
rc.bottom = pScr->cyChar * (pScr->y +1);
InvalidateRect(pScr->hWnd, &rc, TRUE);
if(pScr->parms[0] < 1)
pScr->x++;
else
pScr->x += pScr->parms[0];
ScreenRange(pScr);
if (pScr->x > pScr->width)
pScr->x = pScr->width;
escflg = 0;
SendMessage(pScr->hWnd, WM_PAINT, 0, 0);
break;
case 'D':
pScr->bWrapPending = FALSE;
rc.left = pScr->x * pScr->cxChar;
rc.right = (pScr->x + 1) * pScr->cxChar;
rc.top = pScr->cyChar * pScr->y;
rc.bottom = pScr->cyChar * (pScr->y + 1);
InvalidateRect(pScr->hWnd, &rc, TRUE);
if(pScr->parms[0] < 1)
pScr->x--;
else
pScr->x -= pScr->parms[0];
ScreenRange(pScr);
escflg = 0;
SendMessage(pScr->hWnd, WM_PAINT, 0, 0);
break;
case 'f':
case 'H':
pScr->bWrapPending = FALSE;
rc.left = pScr->x * pScr->cxChar;
rc.right = (pScr->x + 1) * pScr->cxChar;
rc.top = pScr->cyChar * pScr->y;
rc.bottom = pScr->cyChar * (pScr->y + 1);
InvalidateRect(pScr->hWnd, &rc, TRUE);
pScr->x = pScr->parms[1] - 1;
pScr->y = pScr->parms[0] - 1;
ScreenRange(pScr);
escflg = 0;
SendMessage(pScr->hWnd, WM_PAINT, 0, 0);
break;
case 'J':
switch(pScr->parms[0]) {
case -1:
case 0:
ScreenEraseToEndOfScreen(pScr);
break;
case 1:
#if 0
ScreenEraseToPosition(pScr);
#endif
break;
case 2:
ScreenEraseScreen(pScr);
break;
default:
break;
}
escflg = 0;
break;
case 'K':
switch(pScr->parms[0]) {
case -1:
case 0:
ScreenEraseToEOL(pScr);
break;
case 1:
ScreenEraseToBOL(pScr);
break;
case 2:
ScreenEraseLine(pScr, -1);
break;
default:
break;
}
escflg = 0;
break;
case 'L':
if (pScr->parms[0] < 1)
pScr->parms[0] = 1;
ScreenInsLines(pScr, pScr->parms[0], -1);
escflg = 0;
break;
case 'M':
if (pScr->parms[0] < 1)
pScr->parms[0] = 1;
ScreenDelLines(pScr, pScr->parms[0], -1);
escflg = 0;
break;
case 'P':
if (pScr->parms[0] < 1)
pScr->parms[0] = 1;
ScreenDelChars(pScr, pScr->parms[0]);
escflg = 0;
break;
#if 0
case 'R':
break;
#endif
#if 0
case 'c':
ScreenSendIdent();
escflg = 0;
break;
#endif
case 'g':
if (pScr->parms[0] == 3)
ScreenTabClear(pScr);
else
if (pScr->parms[0] <= 0)
pScr->tabs[pScr->x] = ' ';
escflg = 0;
break;
case 'h':
ScreenSetOption(pScr,1);
escflg = 0;
break;
case 'i':
#if 0
if(pScr->parms[pScr->parmptr] == 5)
pScr->localprint = 1;
else if (pScr->parms[pScr->parmptr] == 4)
pScr->localprint = 0;
#endif
escflg = 0;
break;
case 'l':
ScreenSetOption(pScr,0);
escflg = 0;
break;
case 'm':
{
int temp = 0;
while (temp <= pScr->parmptr) {
if (pScr->parms[temp] < 1)
pScr->attrib &= 128;
else
pScr->attrib |= 1 << (pScr->parms[temp] - 1);
temp++;
}
}
escflg = 0;
break;
case 'n':
switch (pScr->parms[0]) {
#if 0
case 0:
case 3:
#endif
case 5:
case 6:
wsprintf(stat, "\033[%d;%dR", pScr->y + 1, pScr->x + 1);
for (i = 0; stat[i]; i++)
SendMessage(pScr->hwndTel, WM_MYSCREENCHAR,
stat[i], (LPARAM) pScr);
break;
}
escflg = 0;
break;
case 'q':
escflg = 0;
break;
case 'r':
if (pScr->parms[0] < 0)
pScr->top = 0;
else
pScr->top = pScr->parms[0] - 1;
if (pScr->parms[1] < 0)
pScr->bottom = pScr->height - 1;
else
pScr->bottom = pScr->parms[1] - 1;
if (pScr->top < 0)
pScr->top = 0;
if (pScr->top > pScr->height-1)
pScr->top = pScr->height-1;
if (pScr->bottom < 1)
pScr->bottom = pScr->height;
if (pScr->bottom >= pScr->height)
pScr->bottom = pScr->height - 1;
if (pScr->top >= pScr->bottom) {
if (pScr->bottom >= 1)
pScr->top = pScr->bottom - 1;
else
pScr->bottom = pScr->top + 1;
}
pScr->x = 0;
pScr->y = 0;
#if 0
if (pScr->DECORG)
pScr->y = pScr->top;
#endif
escflg = 0;
break;
#if 0
case 'x':
case 'y':
break;
#endif
default:
escflg = 0;
break;
}
c++;
len--;
#if 0
if (pScr->localprint && (len > 0)) {
pcount = send_localprint(c, len);
len -= pcount;
c += pcount;
}
#endif
}
while ((escflg == 3) && (len > 0)) {
switch (*c) {
case 0x08:
ScreenBackspace(pScr);
break;
#if 0
case '3':
case '4':
case '5':
case '6':
break;
#endif
case '8':
ScreenAlign(pScr);
escflg = 0;
break;
default:
escflg = 0;
break;
}
c++;
len--;
}
while ((escflg == 4) && (len > 0)) {
switch (*c) {
case 0x08:
ScreenBackspace(pScr);
break;
#if 0
case 'A':
case 'B':
case '1':
pScr->G0 = 0;
if (!pScr->charset)
pScr->attrib = ScreenNotGraph(pScr->attrib);
escflg = 0;
break;
case '0':
case '2':
pScr->G0 = 1;
if(!pScr->charset)
pScr->attrib = ScreenGraph(pScr->attrib);
escflg = 0;
break;
#endif
default:
escflg = 0;
break;
}
c++;
len--;
}
while((escflg == 5) && (len > 0)) {
switch (*c) {
case 0x08:
ScreenBackspace(pScr);
break;
#if 0
case 'A':
case 'B':
case '1':
pScr->G1 = 0;
if (pScr->charset)
pScr->attrib = ScreenNotGraph(pScr->attrib);
escflg = 0;
break;
case '0':
case '2':
pScr->G1 = 1;
if(pScr->charset)
pScr->attrib = ScreenGraph(pScr->attrib);
escflg = 0;
break;
#endif
default:
escflg = 0;
break;
}
c++;
len--;
}
while ((escflg >= 6) && (escflg <= 10) && (len > 0)) {
ic = (unsigned char) *c;
switch (escflg) {
case 6:
if (ic == 255)
escflg = 0;
else if (ic == 250)
escflg = 7;
else
escflg = 9;
break;
case 7:
if (ic == 255)
escflg = 8;
break;
case 8:
if (ic == 255)
escflg = 7;
else if (ic == 240)
escflg = 0;
break;
case 9:
escflg = 0;
break;
}
c++;
len--;
}
if (escflg > 2 && escflg < 6 && len > 0) {
escflg = 0;
c++;
len--;
}
}
pScr->escflg = escflg;
ScreenCursorOn(pScr);
}