diff --git a/channels.c b/channels.c index de6102b..8682bfb 100644 --- a/channels.c +++ b/channels.c @@ -2442,6 +2442,8 @@ channel_input_extended_data(int type, u_int32_t seq, void *ctxt) char *data; u_int data_len, tcode; Channel *c; + char *respbuf = NULL; + size_t resplen = 0; /* Get the channel number and verify it. */ id = packet_get_int(); @@ -2480,8 +2482,14 @@ channel_input_extended_data(int type, u_int32_t seq, void *ctxt) #ifndef WIN32_FIXME//N buffer_append(&c->extended, data, data_len); #else - if ( c->client_tty ) - telProcessNetwork ( data, data_len ); // run it by ANSI engine if it is the ssh client + if (c->client_tty) { + if (telProcessNetwork(data, data_len, &respbuf, &resplen) > 0) // run it by ANSI engine if it is the ssh client + buffer_append(&c->extended, data, data_len); + + if (respbuf != NULL) { + sshbuf_put(&c->input, respbuf, resplen); + } + } else buffer_append(&c->extended, data, data_len); #endif diff --git a/contrib/win32/openssh/Win32-OpenSSH.VC.db b/contrib/win32/openssh/Win32-OpenSSH.VC.db new file mode 100644 index 0000000..dd65f7d Binary files /dev/null and b/contrib/win32/openssh/Win32-OpenSSH.VC.db differ diff --git a/contrib/win32/win32compat/ansiprsr.c b/contrib/win32/win32compat/ansiprsr.c index 92f3553..0c39448 100644 --- a/contrib/win32/win32compat/ansiprsr.c +++ b/contrib/win32/win32compat/ansiprsr.c @@ -49,7 +49,6 @@ #define TS_SEND 1 // items used from other modules -int NetWriteString(char* pszString, size_t cbString); TelParams Parameters; extern int ScreenX; @@ -65,7 +64,6 @@ unsigned char VT_ST[] = { 0x1b, '/', '\0' }; static int AutoWrap = 1; -int marginTop, marginBottom; BOOL bAtEOLN = FALSE; static int term_mode; @@ -89,6 +87,7 @@ BOOL InPrintMode = FALSE; BOOL fPcMode = FALSE; char printErr[] = "Unable to Print: Printer not assigned. Press any key to continue..."; +char cursor_report[255]; #define MODE_CURSORAPP 0x0001 #define MODE_ANSIVT52 0x0002 @@ -117,12 +116,27 @@ int VTMode = 0; char *GetTerminalId() { - return "\033[?1;2c"; + return TERMINAL_ID; } char * GetStatusReport() { - return "\033[2;5R"; + return STATUS_REPORT; +} + +char * GetCursorPositionReport() +{ + DWORD wr = 0; + DWORD out = 0; + + out = _snprintf_s(cursor_report, sizeof(cursor_report), _TRUNCATE, + CURSOR_REPORT_FORMAT_STRING, ConGetCursorY() + 1, ConGetCursorX() + 1); + + if (out > 0) { + return cursor_report; + } + + return NULL; } void BufConvertToG2(char * pszBuffer, int length) @@ -147,202 +161,177 @@ void GoToNextLine() bAtEOLN = FALSE; } -unsigned char* ParseBuffer(unsigned char* pszBuffer, unsigned char* pszBufferEnd) +unsigned char* ParseBuffer(unsigned char* pszBuffer, unsigned char* pszBufferEnd, unsigned char **respbuf, size_t *resplen) { int CurrentX; int CurrentY; - int rc = 0, bufLen, cmpLen, i; + int bufLen, cmpLen, i; + if (!fcompletion) + { + if (pszBuffer < pszBufferEnd - 1) + { + unsigned char * pszCurrent = pszBuffer+1; + unsigned char * pszNewCurrent = pszCurrent; - if (!fcompletion) + if (term_mode == TERM_ANSI) { - if (pszBuffer < pszBufferEnd -1) - { - unsigned char * pszCurrent = pszBuffer+1; - unsigned char * pszNewCurrent = pszCurrent; + pszNewCurrent = ParseANSI(pszCurrent, pszBufferEnd, respbuf, resplen); + } + else if (term_mode == TERM_VT52) + { + pszNewCurrent = ParseVT52(pszCurrent, pszBufferEnd, respbuf, resplen); + } + if (pszCurrent == pszNewCurrent) // Pointer didn't move inside Parse function + { + pszNewCurrent += ConWriteString( (char *)pszCurrent, 1); + return pszBuffer + 1; + } + if (pszNewCurrent > pszCurrent) + pszBuffer = pszNewCurrent; + } + } + + // This is handling special characters including locating the ESC which starts a + // terminal control sequence. + switch ((unsigned char) (*pszBuffer)) + { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 11: + pszBuffer++; + break; + + case 7: + Beep(1000, 400); + pszBuffer++; + break; + + case 8: + pszBuffer++; + if (!bAtEOLN) + { + CurrentX = ConGetCursorX(); + if (CurrentX == 0) + { + ConMoveCursorPosition(ScreenX-1,-1); + ConWriteString(" ",1); + } + else + { + ConClearNFromCursorLeft(1); + ConMoveCursorPosition(-1, 0); + } + } + bAtEOLN = FALSE; + break; + + case 9: + { + if (bAtEOLN) GoToNextLine(); + int i, MoveRight = 8 - (ConGetCursorX() % 8); + + for ( i = 0; i < MoveRight; i++ ) + ConWriteString( " ", 1 ); + pszBuffer++; + AutoWrap = 1; + bAtEOLN = FALSE; + } + break; + + case 10: + pszBuffer++; + AutoWrap = 1; + bAtEOLN = TRUE; + break; + + case 12: + pszBuffer++; + ConSetCursorPosition(0, 0); + ConClearScreen(); + AutoWrap = 1; + bAtEOLN = FALSE; + break; + + case 13: + pszBuffer++; + AutoWrap = 1; + bAtEOLN = FALSE; + break; + + case 14: + pszBuffer++; + fShiftOut = TRUE; + break; + + case 15: + fShiftOut = FALSE; + pszBuffer++; + break; + + case 27: + if (pszBuffer < pszBufferEnd -1) + { + unsigned char * pszCurrent = pszBuffer + 1; + unsigned char * pszNewCurrent = pszCurrent; + + if (*pszCurrent == 27) + { + pszNewCurrent += ConWriteString( (char *)pszCurrent, 1); + return pszBuffer + 1; + } + else + { if (term_mode == TERM_ANSI) { - pszNewCurrent = ParseANSI(pszCurrent, pszBufferEnd); + pszNewCurrent = ParseANSI(pszCurrent, pszBufferEnd, respbuf, resplen); } else if (term_mode == TERM_VT52) { - pszNewCurrent = ParseVT52(pszCurrent, pszBufferEnd); + pszNewCurrent = ParseVT52(pszCurrent, pszBufferEnd, respbuf, resplen); } - if ( pszCurrent == pszNewCurrent ) // didn't move inside Parsefunction - { - pszNewCurrent += ConWriteString( (char *)pszCurrent, 1); - return pszBuffer + 1; - } - if (pszNewCurrent > pszCurrent ) - pszBuffer = pszNewCurrent; } + if (pszNewCurrent > pszCurrent) + pszBuffer = pszNewCurrent; } - switch ((unsigned char) (*pszBuffer)) - { - case 0: - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: - case 11: - pszBuffer++; - break; + break; - case 7: - Beep( 1000, 400); - pszBuffer++; - break; + default: + { + if (bAtEOLN) GoToNextLine(); - case 8: - pszBuffer++; - if (!bAtEOLN) - { - CurrentX = ConGetCursorX(); - if (CurrentX == 0) - { - ConMoveCursorPosition( ScreenX-1,-1); - ConWriteString(" ",1); - // ConMoveCursorPosition(-1,0); - } - else - { - ConClearNFromCursorLeft(1); - ConMoveCursorPosition( -1, 0 ); - } - } - bAtEOLN = FALSE; - - //ConWriteString( " ", 1 ); - //ConMoveCursorPosition( -1, 0 ); - break; + unsigned char* pszCurrent = pszBuffer; + CurrentX = ConGetCursorX(); - case 9: - { - if (bAtEOLN) GoToNextLine(); - int i, MoveRight = 8 - (ConGetCursorX() % 8); + while ((pszCurrent < pszBufferEnd) && (*pszCurrent != (unsigned char)27) + && (*pszCurrent > (unsigned char)15) && (*pszCurrent != (unsigned char)255) + && (CurrentX++ < ScreenX)) + pszCurrent++; - for ( i = 0; i < MoveRight; i++ ) - ConWriteString( " ", 1 ); - pszBuffer++; - AutoWrap = 1; - bAtEOLN = FALSE; - } - break; + if (fShiftOut) + memset(pszBuffer, '|', pszCurrent - pszBuffer); - case 10: + pszBuffer += ConWriteString((char *)pszBuffer, (int)(pszCurrent - pszBuffer)); - - pszBuffer++; - CurrentY = ConGetCursorY(); - - - if (CurrentY >= marginBottom ) - { - if (VTMode & MODE_APPMODE) - ConScrollDown(marginTop,marginBottom); - else - printf("\n"); - ConMoveCursorPosition(-ConGetCursorX(),0); - } - else - { - ConMoveCursorPosition(0,1); - } - if ( Parameters.nReceiveCRLF == ENUM_LF ) - ConMoveCursorPosition(-ConGetCursorX(),0); - AutoWrap = 1; - bAtEOLN = FALSE; - break; - - case 12: - pszBuffer++; - ConSetCursorPosition(0, 0); - ConClearScreen(); - AutoWrap = 1; - bAtEOLN = FALSE; - break; - - case 13: - pszBuffer++; - ConMoveCursorPosition(-ConGetCursorX(),0); - AutoWrap = 1; - bAtEOLN = FALSE; - break; - - case 14: - pszBuffer++; - fShiftOut = TRUE; - break; - - case 15: - fShiftOut = FALSE; - pszBuffer++; - break; - - case 27: - if (pszBuffer < pszBufferEnd -1) - { - unsigned char * pszCurrent = pszBuffer+1; - unsigned char * pszNewCurrent = pszCurrent; - - if ( *pszCurrent == 27 ) - { - pszNewCurrent += ConWriteString( (char *)pszCurrent, 1); - return pszBuffer + 1; - } - else - { - if (term_mode == TERM_ANSI) - { - pszNewCurrent = ParseANSI(pszCurrent, pszBufferEnd); - } - else if (term_mode == TERM_VT52) - { - pszNewCurrent = ParseVT52(pszCurrent, pszBufferEnd); - } - } - if (pszNewCurrent > pszCurrent ) - pszBuffer = pszNewCurrent; - } - break; - - default: - { - if (bAtEOLN) GoToNextLine(); - - unsigned char* pszCurrent = pszBuffer; - CurrentX = ConGetCursorX(); - - while ((pszCurrent < pszBufferEnd) && (*pszCurrent != (unsigned char)27) - && (*pszCurrent > (unsigned char)15) && (*pszCurrent != (unsigned char)255) - && (CurrentX++ < ScreenX )) - // (*pszCurrent != (char)15) && (*pszCurrent != (char)14) && - // (*pszCurrent != (char)12) && (*pszCurrent != (char)13) && (*pszCurrent != (char)8) && - // (*pszCurrent != (char)9)) - pszCurrent++; - - if (fShiftOut) - memset( pszBuffer, '|', pszCurrent-pszBuffer ); - - pszBuffer += ConWriteString((char *)pszBuffer, (int)(pszCurrent - pszBuffer)); - - if ((CurrentX >= ScreenX) && AutoWrap && !(VTMode & MODE_CURSORAPP) ) - { - bAtEOLN = TRUE; - } - - break; - } - } + if ((CurrentX >= ScreenX) && AutoWrap && !(VTMode & MODE_CURSORAPP)) + { + bAtEOLN = TRUE; + } + } + break; + } return pszBuffer; } -unsigned char * GetNextChar(unsigned char * pszBuffer, unsigned char *pszBufferEnd) +unsigned char * GetNextChar(unsigned char *pszBuffer, unsigned char *pszBufferEnd) { if (++pszBuffer > pszBufferEnd) return NULL; @@ -435,26 +424,25 @@ void ConSetExtendedMode(int iFunction, BOOL bEnable) #define DIGI_MASK (MODE_CS0 | MODE_CS1 | MODE_CS2 | MODE_CS3 | MODE_CHAR) -unsigned char * ParseANSI(unsigned char * pszBuffer, unsigned char * pszBufferEnd) +unsigned char * ParseANSI(unsigned char * pszBuffer, unsigned char * pszBufferEnd, unsigned char **respbuf, size_t *resplen) { - unsigned char * pszCurrent = pszBuffer; - const int nParam = 10; // Maximum number of parameters - int rc = 0; - static int SavedX = 0; - static int SavedY = 0; - SCREEN_HANDLE hScreen = NULL; - char anyKey[2] = " "; - WORD BytesRead; - char pszServerPort[10]; - int indx; - char jobName[40]; + const int nParam = 10; // Maximum number of parameters - fcompletion = 0; + static int SavedX = 0; + static int SavedY = 0; + + unsigned char * pszCurrent = pszBuffer; + + if (pszCurrent == NULL || pszBufferEnd == NULL) + return NULL; + + fcompletion = 0; do { switch ((unsigned char) *pszCurrent) { - case ';': // delimiter +// Delimiter + case ';': bDelimiter = TRUE; break; // Modifiers @@ -489,7 +477,7 @@ unsigned char * ParseANSI(unsigned char * pszBuffer, unsigned char * pszBufferEn fcompletion = 1; break; - case '<': // character set + case '<': // Character set fcompletion = 1; break; @@ -500,69 +488,63 @@ unsigned char * ParseANSI(unsigned char * pszBuffer, unsigned char * pszBufferEn case '~': fcompletion = 1; break; - case '^': // private message pszCurrent++; - while (_strnicmp((const char *)pszCurrent, (const char *)VT_ST, strlen((const char *)VT_ST) ) )// while not stop + + case '^': // Private message + while (pszCurrent && pszCurrent < pszBufferEnd && + _strnicmp((const char *)pszCurrent, (const char *)VT_ST, strlen((const char *)VT_ST) ) ) // while not stop { - if (_strnicmp((const char *)pszCurrent, (const char *)VT_ST, strlen((const char *)VT_ST) ) ) + if (pszCurrent && pszCurrent < pszBufferEnd && + _strnicmp((const char *)pszCurrent, (const char *)VT_ST, strlen((const char *)VT_ST) ) ) pszCurrent++; } pszCurrent += strlen((const char *)VT_ST) - 1; fcompletion = 1; break; - case 'A': // British Character Set or Cursor Up + case 'A': // Character Set change or Cursor Up if (bMode & MODE_CHAR) { - // Britsh Character Set } else if (bMode & MODE_BRK) { // Cursor UP - if (iCurrentParam < 1) - iParam[0] = 1; ConMoveCursorPosition(0, -iParam[0]); -// AutoWrap = 0; } fcompletion = 1; break; - case 'B': // US ASCII or Cursor down + + case 'B': // Character set change or Cursor down if (bMode & MODE_CHAR) { - // US ASCII Character Set + // Character Set } else if (bMode & MODE_BRK) { // Cursor DOWN - if (iCurrentParam < 1) - iParam[0] = 1; ConMoveCursorPosition(0, iParam[0]); -// AutoWrap = 0; } fcompletion = 1; break; - case 'C': // Finish Character Set or Cursor right + + case 'C': // Character Set change or Cursor right if (bMode & MODE_CHAR) { - // Britsh Character Set + // Character Set } else if (bMode & MODE_BRK) { // Cursor right - if (iCurrentParam < 1) - iParam[0] = 1; ConMoveCursorPosition(iParam[0], 0); -// AutoWrap = 0; - } + + } fcompletion = 1; break; - case 'D': // Cursor left + + case 'D': // Cursor left if (bMode & MODE_BRK) { // Cursor left - if (iCurrentParam < 1) - iParam[0] = 1; ConMoveCursorPosition(-iParam[0], 0); -// AutoWrap = 0; } else if (bMode == 0) { @@ -573,38 +555,36 @@ unsigned char * ParseANSI(unsigned char * pszBuffer, unsigned char * pszBufferEn bAtEOLN = FALSE; break; - - case '=': // application mode + case '=': // Application mode VTMode |= MODE_APPMODE; fcompletion = 1; break; - case '>': // numeric mode + + case '>': // Numeric mode VTMode &= ~MODE_APPMODE; fcompletion = 1; break; - case '%': // character set definitions - + case '%': // Character set definitions fcompletion = 1; break; + case 'h': case 'l': // ^[?25h if (bMode & MODE_EXT) { - if (iParam[0] == 4){ + if (iParam[0] == 4) { VTMode |= MODE_IRM_INSERT; } -// iParam[0] = atoi( (pszCurrent - iCurrentParam) ); int i; for ( i = 0; i < iCurrentParam; i++ ) - ConSetExtendedMode(iParam[i], *pszCurrent=='h'?1:0); + ConSetExtendedMode(iParam[i], *pszCurrent=='h' ? 1 : 0); } else if (bMode & MODE_BRK) { - // Possible set Line feed (option 20) // Possible set Line feed (option 20) if (iParam[0] == 20) - ConSetExtendedMode(iParam[0], *pszCurrent=='h'?1:0); + ConSetExtendedMode(iParam[0], *pszCurrent=='h' ? 1 : 0); if (iParam[0] == 4){ VTMode &= ~MODE_IRM_INSERT; } @@ -629,31 +609,25 @@ unsigned char * ParseANSI(unsigned char * pszBuffer, unsigned char * pszBufferEn fcompletion = 1; bAtEOLN = FALSE; break; + case 'N': case 'O': fcompletion =1; break; case 'm': - if (iCurrentParam < 1) - iParam[0] = 0; ConSetAttribute(iParam, iCurrentParam); fcompletion = 1; break; case 'r': - marginTop = (iParam[0] > 0) ? iParam[0] - 1 : 0; - marginBottom = (iParam[1] > 0) ? iParam[1] - 1 : 0; - fcompletion = 1; break; + case 'H': case 'f': if (bMode & MODE_BRK) { - if ((iParam[0]-1) > ConWindowSizeY()) - ConSetScreenRect(ConWindowSizeX(), iParam[0]-1); ConSetCursorPosition((iParam[1] > 0) ? iParam[1] - 1 : 0, (iParam[0] > 0) ? iParam[0] - 1 : 0); - //AutoWrap = 0; } else if (bMode == 0) { @@ -668,35 +642,37 @@ unsigned char * ParseANSI(unsigned char * pszBuffer, unsigned char * pszBufferEn { int i ; for (i=0; i': // Exit Alt Keypad mode case '1': // Graphics processor on case '2': // Graphics processor off pszCurrent++; break; + case '<': // Enter ANSI mode term_mode = TERM_ANSI; pszCurrent++; break; + default: pszCurrent++; + break; } return pszCurrent; diff --git a/contrib/win32/win32compat/ansiprsr.h b/contrib/win32/win32compat/ansiprsr.h index 8ce75aa..c1cbfc4 100644 --- a/contrib/win32/win32compat/ansiprsr.h +++ b/contrib/win32/win32compat/ansiprsr.h @@ -39,16 +39,15 @@ #define TERM_ANSI 0 #define TERM_VT52 1 -unsigned char * ParseBuffer(unsigned char* pszBuffer, unsigned char* pszBufferEnd); +unsigned char * ParseBuffer(unsigned char* pszBuffer, unsigned char* pszBufferEnd, unsigned char **respbuf, size_t *resplen); unsigned char * GetNextChar(unsigned char * pszBuffer, unsigned char *pszBufferEnd); -unsigned char * ParseANSI(unsigned char * pszBuffer, unsigned char * pszBufferEnd); -unsigned char * ParseVT52(unsigned char * pszBuffer, unsigned char * pszBufferEnd); +unsigned char * ParseANSI(unsigned char * pszBuffer, unsigned char * pszBufferEnd, unsigned char **respbuf, size_t *resplen); +unsigned char * ParseVT52(unsigned char * pszBuffer, unsigned char * pszBufferEnd, unsigned char **respbuf, size_t *resplen); #define true TRUE #define false FALSE #define bool BOOL -//typedef enum _crlftype { CRLF = 0, LF, CR } CRLFType; #define ENUM_CRLF 0 #define ENUM_LF 1 #define ENUM_CR 2 @@ -60,22 +59,22 @@ typedef struct _TelParams char *pInputFile; - char * szDebugInputFile; - BOOL fDebugWait; + char *szDebugInputFile; + BOOL fDebugWait; int timeOut; int fLocalEcho; int fTreatLFasCRLF; int fSendCROnly; int nReceiveCRLF; - //_crlftype nReceiveCRLF; - char sleepChar; - char menuChar; - SOCKET Socket; + char sleepChar; + char menuChar; + + SOCKET Socket; BOOL bVT100Mode; - char *pAltKey; + char *pAltKey; } TelParams; diff --git a/contrib/win32/win32compat/console.c b/contrib/win32/win32compat/console.c index 414b10b..bfe0f62 100644 --- a/contrib/win32/win32compat/console.c +++ b/contrib/win32/win32compat/console.c @@ -38,15 +38,17 @@ #include #include #include - #include - #include #include -HANDLE hConsole = NULL; -DWORD dwSavedAttributes = 0; +#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING +#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x4 +#endif +HANDLE hInputConsole = NULL; +HANDLE hOutputConsole = NULL; +DWORD dwSavedAttributes = 0; WORD wStartingAttributes = 0; int ScreenX; @@ -54,149 +56,72 @@ int ScreenY; int ScrollTop; int ScrollBottom; -char *pSavedScreen = NULL; -static COORD ZeroCoord = {0,0}; -COORD SavedScreenSize = {0,0}; -COORD SavedScreenCursor = {0, 0 }; -SMALL_RECT SavedViewRect = {0,0,0,0}; +char *pSavedScreen = NULL; +static COORD ZeroCoord = {0,0}; +COORD SavedScreenSize = {0,0}; +COORD SavedScreenCursor = {0, 0 }; +SMALL_RECT SavedViewRect = {0,0,0,0}; +CONSOLE_SCREEN_BUFFER_INFOEX SavedWindowState; typedef struct _SCREEN_RECORD{ PCHAR_INFO pScreenBuf; - COORD ScreenSize; - COORD ScreenCursor; - SMALL_RECT srWindowRect; + COORD ScreenSize; + COORD ScreenCursor; + SMALL_RECT srWindowRect; }SCREEN_RECORD,*PSCREEN_RECORD; -PSCREEN_RECORD pSavedScreenRec = NULL; - +PSCREEN_RECORD pSavedScreenRec = NULL; /* ************************************************************ */ /* Function: ConInit */ /* Used to Initialize the Console for output */ /* ************************************************************ */ -int ConInit( DWORD OutputHandle, bool fSmartInit ) +int ConInit( DWORD OutputHandle, BOOL fSmartInit ) { + OSVERSIONINFO os; + DWORD dwAttributes = 0; + DWORD dwRet = 0; + CONSOLE_SCREEN_BUFFER_INFO csbi; + static bool bFirstConInit = true; - OSVERSIONINFO os; - DWORD dwAttributes = 0; - CONSOLE_SCREEN_BUFFER_INFO csbi; - static bool bFirstConInit = true; + os.dwOSVersionInfoSize = sizeof( OSVERSIONINFO ); + GetVersionEx( &os ); - os.dwOSVersionInfoSize = sizeof( OSVERSIONINFO ); - GetVersionEx( &os ); + hOutputConsole = GetStdHandle(OutputHandle); + if (hOutputConsole == INVALID_HANDLE_VALUE) { + dwRet = GetLastError(); + printf("GetStdHandle failed with %d\n", dwRet); + return dwRet; + } - hConsole = GetStdHandle( OutputHandle ); - if (hConsole == INVALID_HANDLE_VALUE) - printf("GetStdHandle failed with %d\n",GetLastError()); + if (!GetConsoleMode(hOutputConsole, &dwSavedAttributes)) { + dwRet = GetLastError(); + printf("GetConsoleMode failed with %d\n", GetLastError()); + return dwRet; + } - if (!GetConsoleMode( hConsole, &dwSavedAttributes )) - printf("GetConsoleMode failed with %d\n",GetLastError()); + dwAttributes = dwSavedAttributes; - dwAttributes = dwSavedAttributes; + if ( os.dwPlatformId == VER_PLATFORM_WIN32_NT ) + { + dwAttributes = (DWORD)ENABLE_PROCESSED_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING; // PERFECT in NT + SetConsoleMode(hOutputConsole, dwAttributes); // Windows NT + } + else + { + dwAttributes = (DWORD)ENABLE_WRAP_AT_EOL_OUTPUT; // Doesn't always print last column & doesn't handle CRLF + SetConsoleMode(hOutputConsole, dwAttributes); // Windows 95 + } - if ( os.dwPlatformId == VER_PLATFORM_WIN32_NT ) - { -// dwAttributes = (DWORD)ENABLE_WRAP_AT_EOL_OUTPUT; // Causes screen scroll in Edit -// dwAttributes = (DWORD)(ENABLE_PROCESSED_OUTPUT & ~(ENABLE_WRAP_AT_EOL_OUTPUT)); -// dwAttributes = 0; // Causes wrong FONTS and doesn't handle CRLF - dwAttributes = (DWORD)ENABLE_PROCESSED_OUTPUT; // PERFECT in NT -// dwAttributes = (DWORD)ENABLE_PROCESSED_OUTPUT | (DWORD)ENABLE_WRAP_AT_EOL_OUTPUT; // PERFECT in NT - SetConsoleMode(hConsole, dwAttributes ); // Windows NT - } - else - { - dwAttributes = (DWORD)ENABLE_WRAP_AT_EOL_OUTPUT; // Doesn't always print last column & doesn't handle CRLF -// dwAttributes = (DWORD)(ENABLE_PROCESSED_OUTPUT & ~(ENABLE_WRAP_AT_EOL_OUTPUT)); -// dwAttributes = 0; // Causes wrong FONTS and doesn't handle CRLF -// dwAttributes = (DWORD)ENABLE_PROCESSED_OUTPUT; // Scrolls in Windows 95 - SetConsoleMode(hConsole, dwAttributes ); // Windows 95 - } + ConSetScreenX(); + ConSetScreenY(); + ScrollTop = 0; + ScrollBottom = ConWindowSizeY(); + if (GetConsoleScreenBufferInfo(hOutputConsole, &csbi)) + SavedViewRect = csbi.srWindow; - - - if (bFirstConInit && fSmartInit) - { - - if (GetConsoleScreenBufferInfo(hConsole, &csbi)) - { - SMALL_RECT sr; - - wStartingAttributes = csbi.wAttributes; - - int ydelta = csbi.srWindow.Bottom-csbi.srWindow.Top+1; - if (csbi.dwCursorPosition.Y+ydelta > csbi.dwSize.Y) - { - // not enough buffer to reposition window.. must scroll - SMALL_RECT ScrollRect; - SMALL_RECT ClipRect; - COORD destination; - CHAR_INFO Fill; - COORD newCursorPos; - - ScrollRect.Top = (csbi.dwCursorPosition.Y+ydelta - csbi.dwSize.Y); - ScrollRect.Bottom = csbi.dwCursorPosition.Y+1; - ScrollRect.Left = 0; - ScrollRect.Right = csbi.dwSize.X; - - ClipRect = ScrollRect; - ClipRect.Top = 0; - - destination.X = 0; - destination.Y = 0; - - Fill.Attributes = csbi.wAttributes; - Fill.Char.AsciiChar = ' '; - - - ScrollConsoleScreenBuffer( hConsole, - &ScrollRect, - &ClipRect, - destination, - &Fill - ); - - - - - newCursorPos.Y = csbi.dwSize.Y-ydelta; - - - newCursorPos.X = csbi.dwCursorPosition.X; - SetConsoleCursorPosition(hConsole,newCursorPos); - - sr = csbi.srWindow; - sr.Top = newCursorPos.Y; - sr.Bottom = csbi.dwSize.Y-1; - - - BOOL rc = SetConsoleWindowInfo(hConsole,TRUE,&sr); - - - }else{ - GetConsoleScreenBufferInfo(hConsole, &csbi); - - sr = csbi.srWindow; - sr.Top = csbi.dwCursorPosition.Y; - sr.Bottom = sr.Top+ydelta-1; - - - BOOL rc = SetConsoleWindowInfo(hConsole,TRUE,&sr); - } - - } - bFirstConInit = false; - } - - ConSetScreenX(); - ConSetScreenY(); - ScrollTop = 0; - ScrollBottom = ConWindowSizeY(); - - if (GetConsoleScreenBufferInfo(hConsole, &csbi)) - SavedViewRect = csbi.srWindow; - - return 0; + return 0; } @@ -206,20 +131,17 @@ int ConInit( DWORD OutputHandle, bool fSmartInit ) /* ************************************************************ */ int ConUnInit( void ) { - CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo; + CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo; - if ( hConsole == NULL ) - return 0; + if ( hOutputConsole == NULL ) + return 0; + if (!GetConsoleScreenBufferInfo(hOutputConsole, &ConsoleInfo)) + return 0; + SetConsoleMode(hOutputConsole, dwSavedAttributes); - if (!GetConsoleScreenBufferInfo(hConsole, &ConsoleInfo)) - return 0; - - SetConsoleMode(hConsole,dwSavedAttributes); - - - return 0; + return 0; } /* ************************************************************ */ @@ -228,331 +150,291 @@ int ConUnInit( void ) /* ************************************************************ */ int ConUnInitWithRestore( void ) { - DWORD dwWritten; - COORD Coord ; - CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo; + DWORD dwWritten; + COORD Coord ; + CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo; - if ( hConsole == NULL ) - return 0; + if ( hOutputConsole == NULL ) + return 0; + if (!GetConsoleScreenBufferInfo(hOutputConsole, &ConsoleInfo)) + return 0; + SetConsoleMode(hOutputConsole, dwSavedAttributes); - if (!GetConsoleScreenBufferInfo(hConsole, &ConsoleInfo)) - return 0; + Coord = ConsoleInfo.dwCursorPosition; + Coord.X = 0; - SetConsoleMode(hConsole,dwSavedAttributes); + DWORD dwNumChar = (ConsoleInfo.dwSize.Y - ConsoleInfo.dwCursorPosition.Y) * + ConsoleInfo.dwSize.X; - Coord = ConsoleInfo.dwCursorPosition; - Coord.X = 0; + FillConsoleOutputCharacter(hOutputConsole, ' ', dwNumChar, + Coord, &dwWritten); + FillConsoleOutputAttribute(hOutputConsole, wStartingAttributes, dwNumChar, + Coord, &dwWritten); - DWORD dwNumChar = (ConsoleInfo.dwSize.Y - ConsoleInfo.dwCursorPosition.Y) * - ConsoleInfo.dwSize.X; + SetConsoleTextAttribute(hOutputConsole, wStartingAttributes); - FillConsoleOutputCharacter(hConsole, ' ', - dwNumChar, - Coord, &dwWritten); - FillConsoleOutputAttribute(hConsole, wStartingAttributes, - dwNumChar, - Coord, &dwWritten); - - SetConsoleTextAttribute( hConsole, wStartingAttributes ); - - return 0; + return 0; } -// BLR - rewrite of ConSetScreenSize that doesn't alter buffer size - BOOL ConSetScreenRect( int xSize, int ySize ) { - CONSOLE_SCREEN_BUFFER_INFO csbi; /* hold current console buffer info */ - BOOL bSuccess = TRUE; - SMALL_RECT srWindowRect; /* hold the new console size */ - COORD coordScreen; + BOOL bSuccess = TRUE; - bSuccess = GetConsoleScreenBufferInfo(hConsole, &csbi); + CONSOLE_SCREEN_BUFFER_INFO csbi; /* hold current console buffer info */ + SMALL_RECT srWindowRect; /* hold the new console size */ + COORD coordScreen; - /* get the largest size we can size the console window to */ - coordScreen = GetLargestConsoleWindowSize(hConsole); + bSuccess = GetConsoleScreenBufferInfo(hOutputConsole, &csbi); + if (!bSuccess) { + return bSuccess; + } - /* define the new console window size and scroll position */ - srWindowRect.Top = csbi.srWindow.Top; - srWindowRect.Left = csbi.srWindow.Left; - srWindowRect.Right = xSize - 1 + srWindowRect.Left; - srWindowRect.Bottom = ySize - 1 + srWindowRect.Top; - - /* define the new console buffer size */ - coordScreen.X = max(csbi.dwSize.X, xSize); - coordScreen.Y = max(csbi.dwSize.Y, ySize); - - /* if the current buffer is larger than what we want, resize the */ - /* console window first, then the buffer */ - if (csbi.dwSize.X < coordScreen.X || - csbi.dwSize.Y < coordScreen.Y) - { - bSuccess = SetConsoleScreenBufferSize(hConsole, coordScreen); - if (bSuccess) - bSuccess = SetConsoleWindowInfo(hConsole, TRUE, &srWindowRect); - } - else - { - bSuccess = SetConsoleWindowInfo(hConsole, TRUE, &srWindowRect); - if (bSuccess) - bSuccess = SetConsoleScreenBufferSize(hConsole, coordScreen); - } + /* get the largest size we can size the console window to */ + coordScreen = GetLargestConsoleWindowSize(hOutputConsole); - if (bSuccess) - ConSaveViewRect(); + /* define the new console window size and scroll position */ + srWindowRect.Top = csbi.srWindow.Top; + srWindowRect.Left = csbi.srWindow.Left; + srWindowRect.Right = xSize - 1 + srWindowRect.Left; + srWindowRect.Bottom = ySize - 1 + srWindowRect.Top; + + /* define the new console buffer size */ + coordScreen.X = max(csbi.dwSize.X, xSize); + coordScreen.Y = max(csbi.dwSize.Y, ySize); + + /* if the current buffer is larger than what we want, resize the */ + /* console window first, then the buffer */ + if (csbi.dwSize.X < coordScreen.X || + csbi.dwSize.Y < coordScreen.Y) + { + bSuccess = SetConsoleScreenBufferSize(hOutputConsole, coordScreen); + if (bSuccess) + bSuccess = SetConsoleWindowInfo(hOutputConsole, TRUE, &srWindowRect); + } + else + { + bSuccess = SetConsoleWindowInfo(hOutputConsole, TRUE, &srWindowRect); + if (bSuccess) + bSuccess = SetConsoleScreenBufferSize(hOutputConsole, coordScreen); + } - /* if the current buffer *is* the size we want, don't do anything! */ - return bSuccess; + if (bSuccess) + ConSaveViewRect(); + + /* if the current buffer *is* the size we want, don't do anything! */ + return bSuccess; } BOOL ConSetScreenSize( int xSize, int ySize ) { - CONSOLE_SCREEN_BUFFER_INFO csbi; /* hold current console buffer info */ - BOOL bSuccess = TRUE; - SMALL_RECT srWindowRect; /* hold the new console size */ - COORD coordScreen; + BOOL bSuccess = TRUE; - bSuccess = GetConsoleScreenBufferInfo(hConsole, &csbi); + CONSOLE_SCREEN_BUFFER_INFO csbi; /* hold current console buffer info */ + SMALL_RECT srWindowRect; /* hold the new console size */ + COORD coordScreen; - /* get the largest size we can size the console window to */ - coordScreen = GetLargestConsoleWindowSize(hConsole); + bSuccess = GetConsoleScreenBufferInfo(hOutputConsole, &csbi); + if (!bSuccess) { + return bSuccess; + } - /* define the new console window size and scroll position */ - srWindowRect.Right = (SHORT) (min(xSize, coordScreen.X) - 1); - srWindowRect.Bottom = (SHORT) (min(ySize, coordScreen.Y) - 1); - srWindowRect.Left = srWindowRect.Top = (SHORT) 0; - - /* define the new console buffer size */ - coordScreen.X = xSize; - coordScreen.Y = ySize; - - /* if the current buffer is larger than what we want, resize the */ - /* console window first, then the buffer */ - if ((DWORD) csbi.dwSize.X * csbi.dwSize.Y > (DWORD) xSize * ySize) - { - bSuccess = SetConsoleWindowInfo(hConsole, TRUE, &srWindowRect); - if (bSuccess) - { - bSuccess = SetConsoleScreenBufferSize(hConsole, coordScreen); - } - } + /* get the largest size we can size the console window to */ + coordScreen = GetLargestConsoleWindowSize(hOutputConsole); - /* if the current buffer is smaller than what we want, resize the */ - /* buffer first, then the console window */ - if ((DWORD) csbi.dwSize.X * csbi.dwSize.Y < (DWORD) xSize * ySize) - { - bSuccess = SetConsoleScreenBufferSize(hConsole, coordScreen); - if (bSuccess) - bSuccess = SetConsoleWindowInfo(hConsole, TRUE, &srWindowRect); - } + /* define the new console window size and scroll position */ + srWindowRect.Right = (SHORT) (min(xSize, coordScreen.X) - 1); + srWindowRect.Bottom = (SHORT) (min(ySize, coordScreen.Y) - 1); + srWindowRect.Left = srWindowRect.Top = (SHORT) 0; + + /* define the new console buffer size */ + coordScreen.X = xSize; + coordScreen.Y = ySize; + + /* if the current buffer is larger than what we want, resize the */ + /* console window first, then the buffer */ + if ((DWORD) csbi.dwSize.X * csbi.dwSize.Y > (DWORD) xSize * ySize) + { + bSuccess = SetConsoleWindowInfo(hOutputConsole, TRUE, &srWindowRect); + if (bSuccess) + { + bSuccess = SetConsoleScreenBufferSize(hOutputConsole, coordScreen); + } + } - if (bSuccess) - ConSaveViewRect(); + /* if the current buffer is smaller than what we want, resize the */ + /* buffer first, then the console window */ + if ((DWORD) csbi.dwSize.X * csbi.dwSize.Y < (DWORD) xSize * ySize) + { + bSuccess = SetConsoleScreenBufferSize(hOutputConsole, coordScreen); + if (bSuccess) + bSuccess = SetConsoleWindowInfo(hOutputConsole, TRUE, &srWindowRect); + } - /* if the current buffer *is* the size we want, don't do anything! */ - return bSuccess; + if (bSuccess) + ConSaveViewRect(); + + /* if the current buffer *is* the size we want, don't do anything! */ + return bSuccess; } -/* ************************************************************ */ -/* Function: ConRedrawScreen */ -/* Redraws the saved screen */ -/* ************************************************************ */ -DWORD ConRedrawScreen( void ) -{ - PCHAR_INFO pInfo; - CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo; - int i; - - if ( pSavedScreen == NULL ) - return 1; - - if (!GetConsoleScreenBufferInfo(hConsole, &ConsoleInfo)) - return 1; - - pInfo = (PCHAR_INFO)pSavedScreen; - - for ( i = 0; i < (ConsoleInfo.dwSize.X * ConsoleInfo.dwSize.Y); i++ ) - { - pInfo++; - } - return 0; -} - -bool fFirstTime = true; /* ************************************************************ */ /* Function: ConSetAttributes */ /* Used to set the Color of the console and other attributes */ -/* 6/21/99 BLH commented out INTENSITY FLAGS for cyan, magenta, and yellow */ -/* it appears that they weren't commented out when the check for intensity - was added - since i'm not sure why we would explicitly state high - intensity for those colors /* ************************************************************ */ -void ConSetAttribute( int *iParam, int iParamCount ) +void ConSetAttribute(int *iParam, int iParamCount) { - int iAttr; - int i; + int iAttr = 0; + int i = 0; - iAttr = 0; - if (iParamCount < 1) - SetConsoleTextAttribute(hConsole,FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE); - else - { - for (i=0;i