From 73180c876d11ed4c142b2de2e34a986629edc78d Mon Sep 17 00:00:00 2001 From: bagajjal Date: Tue, 7 Feb 2017 12:21:01 -0800 Subject: [PATCH] Cleaned up shell-host and terminal related code --- contrib/win32/win32compat/ansiprsr.c | 1212 ++++++------- contrib/win32/win32compat/console.c | 2297 +++++++++++------------- contrib/win32/win32compat/shell-host.c | 75 +- contrib/win32/win32compat/termio.c | 21 +- contrib/win32/win32compat/tncon.c | 9 +- contrib/win32/win32compat/tnnet.c | 3 +- 6 files changed, 1701 insertions(+), 1916 deletions(-) diff --git a/contrib/win32/win32compat/ansiprsr.c b/contrib/win32/win32compat/ansiprsr.c index 2e5beb20b..9f9bf03b7 100644 --- a/contrib/win32/win32compat/ansiprsr.c +++ b/contrib/win32/win32compat/ansiprsr.c @@ -4,7 +4,7 @@ * Copyright (c) 2015 Microsoft Corp. * All rights reserved * - * Microsoft openssh win32 port + * ANSI Parser to run on Win32 based operating systems * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,18 +27,11 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/* ansiprsr.c - * - * ANSI Parser to run on Win32 based operating systems. - * - */ #include #include #include #include - - #include #include "ansiprsr.h" @@ -48,305 +41,283 @@ #define TS_IS 0 #define TS_SEND 1 -// items used from other modules +/* items used from other modules */ TelParams Parameters; extern int ScreenX; extern int ScreenY; extern int ScrollTop; extern int ScrollBottom; - extern BOOL bAnsiParsing; -// end of imports from outside module - -bool gbVTAppMode = false; - -// private message for port printing to -unsigned char VT_ST[] = { 0x1b, '/', '\0' }; - -static int AutoWrap = 1; - -BOOL bAtEOLN = FALSE; - +bool gbVTAppMode = false; +/* private message for port printing to */ +unsigned char VT_ST[] = { 0x1b, '/', '\0' }; +static int AutoWrap = 1; +BOOL bAtEOLN = FALSE; static int term_mode = TERM_ANSI; -// ParseANSI globals - these need to be here, because sometimes blocks are sent -// in mid ANSI sequence -int iParam[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +/* + * ParseANSI globals - these need to be here, because sometimes blocks are sent + * in mid ANSI sequence +*/ +int iParam[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int iCurrentParam = 0; int bDelimiter = 0; -int bMode = 0; -int fcompletion = 1; +int bMode = 0; +int fcompletion = 1; int bExtMode = 0; -int bCS0 = 0; +int bCS0 = 0; int bCS1 = 0; -int bBkMode = 0; -int bCharMode = 0; +int bBkMode = 0; +int bCharMode = 0; int ReportedX = 0; int ReportedY = 0; - -BOOL fShiftOut = FALSE; -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 -#define MODE_COL132 0x0004 -#define MODE_SMOOTHSCROLL 0x0008 -#define MODE_REVERSESCREEN 0x0010 -#define MODE_ORIGINREL 0x0020 -#define MODE_WRAPAROUND 0x0040 -#define MODE_AUTOREPEAT 0x0080 -#define MODE_APPMODE 0x0100 -#define MODE_LNM 0x0200 -#define MODE_IRM_INSERT 0x0400 - int VTMode = 0; +BOOL fShiftOut = FALSE; +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 -#define MODE_COL132 0x0004 +#define MODE_COL132 0x0004 #define MODE_SMOOTHSCROLL 0x0008 #define MODE_REVERSESCREEN 0x0010 #define MODE_ORIGINREL 0x0020 #define MODE_WRAPAROUND 0x0040 #define MODE_AUTOREPEAT 0x0080 #define MODE_APPMODE 0x0100 -#define MODE_LNM 0x0200 +#define MODE_LNM 0x0200 +#define MODE_IRM_INSERT 0x0400 -char *GetTerminalId() +#define MODE_CURSORAPP 0x0001 +#define MODE_ANSIVT52 0x0002 +#define MODE_COL132 0x0004 +#define MODE_SMOOTHSCROLL 0x0008 +#define MODE_REVERSESCREEN 0x0010 +#define MODE_ORIGINREL 0x0020 +#define MODE_WRAPAROUND 0x0040 +#define MODE_AUTOREPEAT 0x0080 +#define MODE_APPMODE 0x0100 +#define MODE_LNM 0x0200 + +char * +GetTerminalId() { return TERMINAL_ID; } -char * GetStatusReport() +char * +GetStatusReport() { return STATUS_REPORT; } -char * GetCursorPositionReport() +char * +GetCursorPositionReport() { - DWORD wr = 0; - DWORD out = 0; + DWORD wr = 0; + DWORD out = 0; - out = _snprintf_s(cursor_report, sizeof(cursor_report), _TRUNCATE, - CURSOR_REPORT_FORMAT_STRING, ConGetCursorY() + 1, ConGetCursorX() + 1); + out = _snprintf_s(cursor_report, sizeof(cursor_report), _TRUNCATE, + CURSOR_REPORT_FORMAT_STRING, ConGetCursorY() + 1, ConGetCursorX() + 1); + if (out > 0) { + return cursor_report; + } - if (out > 0) { - return cursor_report; - } - - return NULL; + return NULL; } -void BufConvertToG2(char * pszBuffer, int length) +void +BufConvertToG2(char * pszBuffer, int length) { - int i; - - for (i=0;i= (ConWindowSizeY()-1)) - { - ConScrollDown(ScrollTop,ScrollBottom); - ConMoveCursorPosition(-ConGetCursorX(),0); + if (ConGetCursorY() >= (ConWindowSizeY() - 1)) { + ConScrollDown(ScrollTop, ScrollBottom); + ConMoveCursorPosition(-ConGetCursorX(), 0); } else - ConMoveCursorPosition(-ConGetCursorX(),1); + ConMoveCursorPosition(-ConGetCursorX(), 1); + bAtEOLN = FALSE; } -unsigned char* ParseBuffer(unsigned char* pszBuffer, unsigned char* pszBufferEnd, unsigned char **respbuf, size_t *resplen) +unsigned char* +ParseBuffer(unsigned char* pszBuffer, unsigned char* pszBufferEnd, unsigned char **respbuf, size_t *resplen) { int CurrentX; int CurrentY; int bufLen, cmpLen, i; - if (!fcompletion) - { - if (pszBuffer < pszBufferEnd - 1) - { - unsigned char * pszCurrent = pszBuffer+1; + if (!fcompletion) { + if (pszBuffer < pszBufferEnd - 1) { + unsigned char * pszCurrent = pszBuffer + 1; unsigned char * pszNewCurrent = pszCurrent; if (term_mode == TERM_ANSI && bAnsiParsing) - { pszNewCurrent = ParseANSI(pszCurrent, pszBufferEnd, respbuf, resplen); - } - if (pszCurrent == pszNewCurrent) // Pointer didn't move inside Parse function - { - pszNewCurrent += ConWriteString( (char *)pszCurrent, 1); + /* Pointer didn't move inside Parse function */ + if (pszCurrent == pszNewCurrent) { + pszNewCurrent += ConWriteString((char *)pszCurrent, 1); return pszNewCurrent; } + if (pszNewCurrent > pszCurrent) pszBuffer = pszNewCurrent; } } - // This is handling special characters including locating the ESC which starts a - // terminal control sequence. - switch ((unsigned char) (*pszBuffer)) + /* Handle special characters including locating the ESC which starts a terminal control seq */ + switch ((unsigned char)(*pszBuffer)) { - case 0: - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: - case 11: - pszBuffer++; - break; + case 0: /* FALLTHROUGH */ + case 1: /* FALLTHROUGH */ + case 2: /* FALLTHROUGH */ + case 3: /* FALLTHROUGH */ + case 4: /* FALLTHROUGH */ + case 5: /* FALLTHROUGH */ + case 6: /* FALLTHROUGH */ + case 11: /* FALLTHROUGH */ + pszBuffer++; + break; - case 7: - Beep(1000, 400); - 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); - } + 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; + } + bAtEOLN = FALSE; + break; - case 9: - { - if (bAtEOLN) GoToNextLine(); - int i, MoveRight = 8 - (ConGetCursorX() % 8); + case 9: + { + if (bAtEOLN) GoToNextLine(); + int i, MoveRight = 8 - (ConGetCursorX() % 8); - for ( i = 0; i < MoveRight; i++ ) - ConWriteString( " ", 1 ); - pszBuffer++; - AutoWrap = 1; - bAtEOLN = FALSE; + for (i = 0; i < MoveRight; i++) + ConWriteString(" ", 1); + pszBuffer++; + AutoWrap = 1; + bAtEOLN = FALSE; + } + break; + + case 10: + pszBuffer++; + AutoWrap = 1; + bAtEOLN = FALSE; + break; + + case 12: + pszBuffer++; + ConSetCursorPosition(0, 0); + ConClearScreen(); + AutoWrap = 1; + bAtEOLN = FALSE; + break; + + case 13: + pszBuffer++; + AutoWrap = 1; + GoToNextLine(); + 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, respbuf, resplen); } - break; - case 10: - pszBuffer++; - AutoWrap = 1; - bAtEOLN = FALSE; - break; - - case 12: - pszBuffer++; - ConSetCursorPosition(0, 0); - ConClearScreen(); - AutoWrap = 1; - bAtEOLN = FALSE; - break; + if (pszNewCurrent > pszCurrent) + pszBuffer = pszNewCurrent; + } + break; - case 13: - pszBuffer++; - AutoWrap = 1; - GoToNextLine(); - break; + default: + { + if (bAtEOLN) GoToNextLine(); - case 14: - pszBuffer++; - fShiftOut = TRUE; - break; + unsigned char* pszCurrent = pszBuffer; + CurrentX = ConGetCursorX(); + int nCharCount = 0; - 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, respbuf, resplen); - } - } - if (pszNewCurrent > pszCurrent) - pszBuffer = pszNewCurrent; + while ((pszCurrent < pszBufferEnd) && (*pszCurrent != (unsigned char)27) + && (*pszCurrent > (unsigned char)15) && (*pszCurrent != (unsigned char)255) + && (CurrentX++ < ScreenX)) { + if (*pszCurrent > 127) { + unsigned char nLead = *pszCurrent; + nCharCount++; + if ((nLead & 128) == 128) + pszCurrent++; + if ((nLead & 192) == 192) + pszCurrent++; + if ((nLead & 224) == 224) + pszCurrent++; + if ((nLead & 240) == 240) + pszCurrent++; } - break; + else + pszCurrent++; + } - default: - { - if (bAtEOLN) GoToNextLine(); + if (fShiftOut) + memset(pszBuffer, '|', pszCurrent - pszBuffer); - unsigned char* pszCurrent = pszBuffer; - CurrentX = ConGetCursorX(); - int nCharCount = 0; + pszBuffer += ConWriteString((char *)pszBuffer, (int)(pszCurrent - pszBuffer)); - while ((pszCurrent < pszBufferEnd) && (*pszCurrent != (unsigned char)27) - && (*pszCurrent > (unsigned char)15) && (*pszCurrent != (unsigned char)255) - && (CurrentX++ < ScreenX)) { - if (*pszCurrent > 127) { - unsigned char nLead = *pszCurrent; - nCharCount++; - if ((nLead & 128) == 128) { - pszCurrent++; - } - if ((nLead & 192) == 192) { - pszCurrent++; - } - if ((nLead & 224) == 224) { - pszCurrent++; - } - if ((nLead & 240) == 240) { - pszCurrent++; - } - } - else - 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; @@ -354,71 +325,71 @@ unsigned char * GetNextChar(unsigned char *pszBuffer, unsigned char *pszBufferEn return pszBuffer; } -void ConSetExtendedMode(int iFunction, BOOL bEnable) +void +ConSetExtendedMode(int iFunction, BOOL bEnable) { - switch(iFunction) - { - case 1: - if (bEnable){ - VTMode |= MODE_CURSORAPP; - gbVTAppMode = true; - }else{ - VTMode &= ~MODE_CURSORAPP; - gbVTAppMode = false; - } - break; - case 2: - if (!bEnable) - VTMode |= MODE_ANSIVT52; - break; - case 3: - if (bEnable) - VTMode |= MODE_COL132; - else - VTMode &= ~MODE_COL132; - break; - case 4: - if (bEnable) - VTMode |= MODE_SMOOTHSCROLL; - else - VTMode &= ~MODE_SMOOTHSCROLL; - break; - case 5: - if (bEnable) - VTMode |= MODE_REVERSESCREEN; - else - VTMode &= ~MODE_REVERSESCREEN; - break; - case 6: - if (bEnable) - VTMode |= MODE_ORIGINREL; - else - VTMode &= ~MODE_ORIGINREL; - break; - case 7: - if (bEnable) - VTMode |= MODE_WRAPAROUND; - else - VTMode &= ~MODE_WRAPAROUND; - break; - case 8: - if (bEnable) - VTMode |= MODE_AUTOREPEAT; - else - VTMode &= ~MODE_AUTOREPEAT; - break; - case 20: // LNM Mode CSI 20h - if (bEnable){ - VTMode |= MODE_LNM; - Parameters.nReceiveCRLF = ENUM_CRLF; - }else{ - VTMode &= ~MODE_LNM; - Parameters.nReceiveCRLF = ENUM_LF; - } - break; - case 25: - ConDisplayCursor(bEnable); - break; + switch (iFunction) { + case 1: + if (bEnable) { + VTMode |= MODE_CURSORAPP; + gbVTAppMode = true; + } else { + VTMode &= ~MODE_CURSORAPP; + gbVTAppMode = false; + } + break; + case 2: + if (!bEnable) + VTMode |= MODE_ANSIVT52; + break; + case 3: + if (bEnable) + VTMode |= MODE_COL132; + else + VTMode &= ~MODE_COL132; + break; + case 4: + if (bEnable) + VTMode |= MODE_SMOOTHSCROLL; + else + VTMode &= ~MODE_SMOOTHSCROLL; + break; + case 5: + if (bEnable) + VTMode |= MODE_REVERSESCREEN; + else + VTMode &= ~MODE_REVERSESCREEN; + break; + case 6: + if (bEnable) + VTMode |= MODE_ORIGINREL; + else + VTMode &= ~MODE_ORIGINREL; + break; + case 7: + if (bEnable) + VTMode |= MODE_WRAPAROUND; + else + VTMode &= ~MODE_WRAPAROUND; + break; + case 8: + if (bEnable) + VTMode |= MODE_AUTOREPEAT; + else + VTMode &= ~MODE_AUTOREPEAT; + break; + case 20: /* LNM Mode CSI 20h */ + if (bEnable) { + VTMode |= MODE_LNM; + Parameters.nReceiveCRLF = ENUM_CRLF; + } else { + VTMode &= ~MODE_LNM; + Parameters.nReceiveCRLF = ENUM_LF; + } + break; + case 25: + ConDisplayCursor(bEnable); + break; } } @@ -434,440 +405,354 @@ 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 **respbuf, size_t *resplen) +unsigned char * +ParseANSI(unsigned char * pszBuffer, unsigned char * pszBufferEnd, unsigned char **respbuf, size_t *resplen) { - const int nParam = 10; // Maximum number of parameters - + const int nParam = 10; /* Maximum number of parameters */ static int SavedX = 0; static int SavedY = 0; + unsigned char * pszCurrent = pszBuffer; - unsigned char * pszCurrent = pszBuffer; + if (pszCurrent == NULL || pszBufferEnd == NULL) + return NULL; - if (pszCurrent == NULL || pszBufferEnd == NULL) - return NULL; + fcompletion = 0; + do { + switch ((unsigned char)*pszCurrent) { + case ';': /* Delimiter */ + bDelimiter = TRUE; + break; + /* Modifiers */ + case '?': /* Extended Mode */ + bMode |= MODE_EXT; + break; + case '(': + bMode |= MODE_CS0; + break; + case ')': + bMode |= MODE_CS1; + break; + case '*': + bMode |= MODE_CS2; + break; + case '+': + bMode |= MODE_CS3; + break; + case '[': + bMode |= MODE_BRK; + break; + case '#': + bMode |= MODE_CHAR; + break; - fcompletion = 0; - do - { - switch ((unsigned char) *pszCurrent) - { -// Delimiter - case ';': - bDelimiter = TRUE; - break; -// Modifiers - case '?': // Extended Mode - bMode |= MODE_EXT; - break; - case '(': - bMode |= MODE_CS0; - break; - case ')': - bMode |= MODE_CS1; - break; - case '*': - bMode |= MODE_CS2; - break; - case '+': - bMode |= MODE_CS3; - break; - case '[': - bMode |= MODE_BRK; - break; - case '#': - bMode |= MODE_CHAR; - break; + /* Termination Options */ + case 0: + fcompletion = 1; + break; -// Termination Options - case 0: - fcompletion = 1; - break; + case '}': + fcompletion = 1; + break; - case '}': - fcompletion = 1; - break; + case '<': /* Character set */ + fcompletion = 1; + break; - case '<': // Character set - fcompletion = 1; - break; + case '\\': + fcompletion = 1; + break; - case '\\': - fcompletion = 1; - break; + case '~': + fcompletion = 1; + break; - case '~': - fcompletion = 1; - break; + case '^': /* Private message */ + /* while not stop */ + while (pszCurrent && pszCurrent < pszBufferEnd && + _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 '^': // Private message - while (pszCurrent && pszCurrent < pszBufferEnd && - _strnicmp((const char *)pszCurrent, (const char *)VT_ST, strlen((const char *)VT_ST) ) ) // while not stop - { - if (pszCurrent && pszCurrent < pszBufferEnd && - _strnicmp((const char *)pszCurrent, (const char *)VT_ST, strlen((const char *)VT_ST) ) ) - pszCurrent++; + case 'A': /* Character Set change or Cursor Up */ + if (bMode & MODE_BRK) { /* Cursor UP */ + if (iParam[0] == 0) + iParam[0] = 1; + ConMoveCursorPosition(0, -iParam[0]); + } + fcompletion = 1; + break; + + case 'B': /* Character set change or Cursor down */ + if (bMode & MODE_BRK) { /* Cursor DOWN */ + if (iParam[0] == 0) + iParam[0] = 1; + ConMoveCursorPosition(0, iParam[0]); + } + fcompletion = 1; + break; + + case 'C': /* Character Set change or Cursor right */ + if (bMode & MODE_BRK) { /* Cursor right */ + if (iParam[0] == 0) + iParam[0] = 1; + ConMoveCursorPosition(iParam[0], 0); + } + fcompletion = 1; + break; + + case 'D': + if (bMode & MODE_BRK) { /* Cursor left */ + if (iParam[0] == 0) + iParam[0] = 1; + ConMoveCursorPosition(-iParam[0], 0); + } else if (bMode == 0) { /* Index */ + ConScrollDown(ScrollTop, ScrollBottom); + } + fcompletion = 1; + bAtEOLN = FALSE; + break; + + case '=': /* Application mode */ + VTMode |= MODE_APPMODE; + fcompletion = 1; + break; + + case '>': /* Numeric mode */ + VTMode &= ~MODE_APPMODE; + fcompletion = 1; + break; + + case '%': /* Character set definitions */ + fcompletion = 1; + break; + + case 'h': + if (bMode & MODE_EXT) { + if (iParam[0] == 4 && iParam[1] == 7) { + ConSaveScreen(); } - pszCurrent += strlen((const char *)VT_ST) - 1; - fcompletion = 1; - break; - - case 'A': // Character Set change or Cursor Up - if (bMode & MODE_CHAR) - { - } - else if (bMode & MODE_BRK) - { - // Cursor UP - if (iParam[0] == 0) - iParam[0] = 1; - ConMoveCursorPosition(0, -iParam[0]); - } - fcompletion = 1; - break; - - case 'B': // Character set change or Cursor down - if (bMode & MODE_CHAR) - { - // Character Set - } - else if (bMode & MODE_BRK) - { - // Cursor DOWN - if (iParam[0] == 0) - iParam[0] = 1; - ConMoveCursorPosition(0, iParam[0]); - } - fcompletion = 1; - break; - - case 'C': // Character Set change or Cursor right - if (bMode & MODE_CHAR) - { - // Character Set - } - else if (bMode & MODE_BRK) - { - // Cursor right - if (iParam[0] == 0) - iParam[0] = 1; - ConMoveCursorPosition(iParam[0], 0); - - } - fcompletion = 1; - break; - - case 'D': // Cursor left - if (bMode & MODE_BRK) - { - // Cursor left - if (iParam[0] == 0) - iParam[0] = 1; - ConMoveCursorPosition(-iParam[0], 0); - } - else if (bMode == 0) - { - // Index - ConScrollDown(ScrollTop,ScrollBottom); - } - fcompletion = 1; - bAtEOLN = FALSE; - break; - - case '=': // Application mode - VTMode |= MODE_APPMODE; - fcompletion = 1; - break; - - case '>': // Numeric mode - VTMode &= ~MODE_APPMODE; - fcompletion = 1; - break; - - case '%': // Character set definitions - fcompletion = 1; - break; - - case 'h': - if (bMode & MODE_EXT) - { - if (iParam[0] == 4 && iParam[1] == 7) { - ConSaveScreen(); - } - } - case 'l': // ^[?25h - if (bMode & MODE_EXT) - { - if (iParam[0] == 4 && iParam[1] == 7) { - ConRestoreScreen(); - } - else - { - if (iParam[0] == 4) { - VTMode |= MODE_IRM_INSERT; - } - int i; - for (i = 0; i < iCurrentParam; i++) - ConSetExtendedMode(iParam[i], *pszCurrent == 'h' ? 1 : 0); - } - } - else if (bMode & MODE_BRK) - { - // Possible set Line feed (option 20) - if (iParam[0] == 20) - ConSetExtendedMode(iParam[0], *pszCurrent=='h' ? 1 : 0); - if (iParam[0] == 4){ - VTMode &= ~MODE_IRM_INSERT; - } - } - fcompletion = 1; - break; - - case 'L': - if (iParam[0]) - { + } + case 'l': /* ^[?25h */ + if (bMode & MODE_EXT) { + if (iParam[0] == 4 && iParam[1] == 7) + ConRestoreScreen(); + else { + if (iParam[0] == 4) + VTMode |= MODE_IRM_INSERT; int i; - for (i=0; i 0) ? iParam[1] - 1 : 0, (iParam[0] > 0) ? iParam[0] - 1 : 0); - } - else if (bMode == 0) - { - //Set tab - } - fcompletion = 1; - bAtEOLN = FALSE; - break; + case 'L': + if (iParam[0]) { + int i; + for (i = 0; i < iParam[0]; i++) + ConScrollUp(ConGetCursorY() - 1, ScrollTop + ConWindowSizeY() - 2); + } else { + if (ConGetCursorY() <= ScrollTop + ConWindowSizeY() - 2) + ConScrollUp(ConGetCursorY() - 1, ScrollTop + ConWindowSizeY() - 2); + } + fcompletion = 1; + bAtEOLN = FALSE; + break; - case 'M': - if (iParam[0]) - { - int i ; - for (i=0; i 0) ? iParam[1] - 1 : 0, (iParam[0] > 0) ? iParam[0] - 1 : 0); + + fcompletion = 1; + bAtEOLN = FALSE; + break; - case 'E': - case 'G': - case 'g': - fcompletion = 1; - break; + case 'M': + if (iParam[0]) { + int i; + for (i = 0; i < iParam[0]; i++) + ConScrollUp(ConGetCursorY(), ScrollTop - ConGetCursorY()); + } else { + if (ConGetCursorY() <= ScrollTop + ConWindowSizeY() - 2) + ConScrollUp(ConGetCursorY(), ScrollTop - ConGetCursorY()); + } + fcompletion = 1; + bAtEOLN = FALSE; + break; - case 'i': // ANSI or VTXXX Print - if ( iParam[0] == 5 ) - { - } - else if ( iParam[0] == 4 ) - InPrintMode = FALSE; - fcompletion = 1; - break; + case 'E': + case 'G': + case 'g': + fcompletion = 1; + break; - case 'K': - if (bMode & MODE_BRK) - { - switch (iParam[0]) - { - case 0: - ConClearEOLine(); - break; - case 1: - ConClearBOLine(); - break; - case 2: - ConClearLine(); - break; - } - } - else if (bMode == 0) - { - bMode |= MODE_K; - } + case 'i': /* ANSI or VTXXX Print */ + if (iParam[0] == 4) + InPrintMode = FALSE; + fcompletion = 1; + break; - fcompletion = 1; - break; - - case 'J': - switch (iParam[0]) + case 'K': + if (bMode & MODE_BRK) { + switch (iParam[0]) { - case 0: - ConClearEOScreen(); + case 0: + ConClearEOLine(); break; - case 1: - ConClearBOScreen(); + case 1: + ConClearBOLine(); break; - case 2: - ConClearScreen(); + case 2: + ConClearLine(); break; } - fcompletion = 1; - break; + } else if (bMode == 0) + bMode |= MODE_K; - case 'n': - if (iCurrentParam == 1) - { - if (iParam[0] == 5) - { - char * szStatus = GetStatusReport(); - if (respbuf != NULL) - { - *respbuf = szStatus; - if (resplen != NULL) - { - *resplen = strlen(szStatus); - } - } + fcompletion = 1; + break; + + case 'J': + switch (iParam[0]) { + case 0: + ConClearEOScreen(); + break; + case 1: + ConClearBOScreen(); + break; + case 2: + ConClearScreen(); + break; + } + fcompletion = 1; + break; + + case 'n': + if (iCurrentParam == 1) { + if (iParam[0] == 5) { + char * szStatus = GetStatusReport(); + if (respbuf != NULL) { + *respbuf = szStatus; + if (resplen != NULL) + *resplen = strlen(szStatus); } - else if ( iParam[0] == 6 ) - { - char * szStatus = GetCursorPositionReport(); - if (respbuf != NULL) - { - *respbuf = szStatus; - if (resplen != NULL) - { - *resplen = strlen(szStatus); - } - } + } else if (iParam[0] == 6) { + char * szStatus = GetCursorPositionReport(); + if (respbuf != NULL) { + *respbuf = szStatus; + if (resplen != NULL) + *resplen = strlen(szStatus); } } - fcompletion = 1; - break; + } + fcompletion = 1; + break; - case 'c': - if (bMode == (MODE_BRK & MODE_EXT)) - { - // What is your response? + case 'c': + if (bMode == MODE_BRK) { + char* szTerminalId = GetTerminalId(); + if (szTerminalId) { + if (respbuf != NULL) { + *respbuf = szTerminalId; + if (resplen != NULL) + *resplen = strlen(szTerminalId); + } } - else if (bMode == MODE_BRK) - { - char* szTerminalId = GetTerminalId(); - if (szTerminalId) { - if (respbuf != NULL) - { - *respbuf = szTerminalId; - if (resplen != NULL) - { - *resplen = strlen(szTerminalId); - } - } - } - } - fcompletion = 1; - break; + } + fcompletion = 1; + break; - case 'y': - case 'q': - fcompletion = 1; - break; + case 'y': + case 'q': + fcompletion = 1; + break; - case 'Z': // Identify - This is really a VT52 command - { - char* szTerminalId = GetTerminalId(); - if (szTerminalId) { - *respbuf = szTerminalId; - if (resplen != NULL) - { - *resplen = strlen(szTerminalId); - } - } - } - fcompletion = 1; - break; + case 'Z': /* Identify - This is really a VT52 command */ + { + char* szTerminalId = GetTerminalId(); + if (szTerminalId) { + *respbuf = szTerminalId; + if (resplen != NULL) + *resplen = strlen(szTerminalId); + } + } + fcompletion = 1; + break; - case 'P': - ConDeleteChars(iParam[0]); - fcompletion = 1; - break; + case 'P': + ConDeleteChars(iParam[0]); + fcompletion = 1; + break; default: - - // pszHead should point to digit now. Otherwise we got a bad escape - // sequence, so we just get out of here! - if(*pszCurrent) { - if (!isdigit(*pszCurrent)) - { + /* pszHead should point to digit now. Otherwise we got a bad escape + * sequence, so we just get out of here! + */ + if (*pszCurrent) { + if (!isdigit(*pszCurrent)) { pszCurrent = pszBuffer; return pszCurrent; } iParam[iCurrentParam] = strtoul((const char *)pszCurrent, (char **)&pszCurrent, 10); - pszCurrent--; - if (iCurrentParam < nParam) iCurrentParam++; - // Check for digit completion + /* Check for digit completion */ if (bMode & DIGI_MASK) fcompletion = 1; - - if (bMode == 0) - { - switch(iParam[0]) - { - case 7: - SavedX = ConGetCursorX(); - SavedY = ConGetCursorY(); - break; - case 8: - ConSetCursorPosition(SavedX, SavedY); - break; + + if (bMode == 0) { + switch (iParam[0]) { + case 7: + SavedX = ConGetCursorX(); + SavedY = ConGetCursorY(); + break; + case 8: + ConSetCursorPosition(SavedX, SavedY); + break; } fcompletion = 1; } - } - else { - pszCurrent = pszBuffer; - return pszCurrent; - } - + } else { + pszCurrent = pszBuffer; + return pszCurrent; + } break; } - } while ((++pszCurrent < pszBufferEnd) && !fcompletion); + } while ((++pszCurrent < pszBufferEnd) && !fcompletion); - if (fcompletion) - { + if (fcompletion) { memset(iParam, '\0', sizeof(iParam)); iCurrentParam = 0; bDelimiter = 0; @@ -878,7 +763,6 @@ unsigned char * ParseANSI(unsigned char * pszBuffer, unsigned char * pszBufferEn bBkMode = 0; bCharMode = 0; return pszCurrent; - } - else + } else return pszBuffer; } diff --git a/contrib/win32/win32compat/console.c b/contrib/win32/win32compat/console.c index c1b18ff2a..eb6b717d7 100644 --- a/contrib/win32/win32compat/console.c +++ b/contrib/win32/win32compat/console.c @@ -4,7 +4,9 @@ * Copyright (c) 2015 Microsoft Corp. * All rights reserved * - * Microsoft openssh win32 port + * Common library for Windows Console Screen IO. + * Contains Windows console related definition so that emulation code can draw + * on Windows console screen surface. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,21 +29,15 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/* console.c - * - * Common library for Windows Console Screen IO. - * Contains Windows console related definition so that emulation code can draw - * on Windows console screen surface. - * - */ #include #include #include #include -#include "console.h" #include +#include "console.h" + #ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING #define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x4 #endif @@ -56,1552 +52,1421 @@ int ScrollTop; int ScrollBottom; int LastCursorX; int LastCursorY; - BOOL bAnsiParsing = FALSE; - char *pSavedScreen = NULL; -static COORD ZeroCoord = {0,0}; -COORD SavedScreenSize = {0,0}; -COORD SavedScreenCursor = {0, 0 }; -SMALL_RECT SavedViewRect = {0,0,0,0}; +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; -}SCREEN_RECORD,*PSCREEN_RECORD; +typedef struct _SCREEN_RECORD { + PCHAR_INFO pScreenBuf; + COORD ScreenSize; + COORD ScreenCursor; + SMALL_RECT srWindowRect; +}SCREEN_RECORD, *PSCREEN_RECORD; PSCREEN_RECORD pSavedScreenRec = NULL; int in_raw_mode = 0; -/* ************************************************************ */ -/* Function: ConInit */ -/* Used to Initialize the Console for output */ -/* ************************************************************ */ -int ConInit( DWORD OutputHandle, BOOL fSmartInit ) +/* Used to Initialize the Console for output */ +int +ConInit(DWORD OutputHandle, BOOL fSmartInit) { - OSVERSIONINFO os; - DWORD dwAttributes = 0; - DWORD dwRet = 0; - BOOL bRet = FALSE; - CONSOLE_SCREEN_BUFFER_INFO csbi; - static bool bFirstConInit = true; + OSVERSIONINFO os; + DWORD dwAttributes = 0; + DWORD dwRet = 0; + BOOL bRet = FALSE; + 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 on OutputHandle failed with %d\n", dwRet); - return dwRet; - } + hOutputConsole = GetStdHandle(OutputHandle); + if (hOutputConsole == INVALID_HANDLE_VALUE) { + dwRet = GetLastError(); + printf("GetStdHandle on OutputHandle failed with %d\n", dwRet); + return dwRet; + } - if (!GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &dwSavedAttributes)) { - dwRet = GetLastError(); - printf("GetConsoleMode on STD_INPUT_HANDLE failed with %d\n", dwRet); - return dwRet; - } + if (!GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &dwSavedAttributes)) { + dwRet = GetLastError(); + printf("GetConsoleMode on STD_INPUT_HANDLE failed with %d\n", dwRet); + return dwRet; + } - dwAttributes = dwSavedAttributes; - dwAttributes &= ~(ENABLE_LINE_INPUT | - ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_MOUSE_INPUT); - dwAttributes |= ENABLE_WINDOW_INPUT; + dwAttributes = dwSavedAttributes; + dwAttributes &= ~(ENABLE_LINE_INPUT | + ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_MOUSE_INPUT); + dwAttributes |= ENABLE_WINDOW_INPUT; - if (!SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), dwAttributes)) { // Windows NT - dwRet = GetLastError(); - printf("SetConsoleMode on STD_INPUT_HANDLE failed with %d\n", dwRet); - return dwRet; - } + if (!SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), dwAttributes)) { /* Windows NT */ + dwRet = GetLastError(); + printf("SetConsoleMode on STD_INPUT_HANDLE failed with %d\n", dwRet); + return dwRet; + } - if (!GetConsoleMode(hOutputConsole, &dwAttributes)) { - dwRet = GetLastError(); - printf("GetConsoleMode on hOutputConsole failed with %d\n", dwRet); - return dwRet; - } + if (!GetConsoleMode(hOutputConsole, &dwAttributes)) { + dwRet = GetLastError(); + printf("GetConsoleMode on hOutputConsole failed with %d\n", dwRet); + return dwRet; + } - dwAttributes |= (DWORD)ENABLE_VIRTUAL_TERMINAL_PROCESSING; + dwAttributes |= (DWORD)ENABLE_VIRTUAL_TERMINAL_PROCESSING; - if (!SetConsoleMode(hOutputConsole, dwAttributes)) { // Windows NT - bAnsiParsing = TRUE; - } + if (!SetConsoleMode(hOutputConsole, dwAttributes)) /* Windows NT */ + bAnsiParsing = TRUE; - ConSetScreenX(); - ConSetScreenY(); - ScrollTop = 0; - ScrollBottom = ConWindowSizeY(); + ConSetScreenX(); + ConSetScreenY(); + ScrollTop = 0; + ScrollBottom = ConWindowSizeY(); - if (GetConsoleScreenBufferInfo(hOutputConsole, &csbi)) - SavedViewRect = csbi.srWindow; + if (GetConsoleScreenBufferInfo(hOutputConsole, &csbi)) + SavedViewRect = csbi.srWindow; in_raw_mode = 1; - return 0; + return 0; } - -/* ************************************************************ */ -/* Function: ConUnInit */ -/* Used to Uninitialize the Console */ -/* ************************************************************ */ -int ConUnInit( void ) +/* Used to Uninitialize the Console */ +int +ConUnInit(void) { - CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo; - + CONSOLE_SCREEN_BUFFER_INFO consoleInfo; in_raw_mode = 0; - if ( hOutputConsole == NULL ) - return 0; + if (hOutputConsole == NULL) + return 0; - if (!GetConsoleScreenBufferInfo(hOutputConsole, &ConsoleInfo)) - return 0; + if (!GetConsoleScreenBufferInfo(hOutputConsole, &consoleInfo)) + return 0; - SetConsoleMode(hOutputConsole, dwSavedAttributes); + SetConsoleMode(hOutputConsole, dwSavedAttributes); - return 0; + return 0; } -/* ************************************************************ */ -/* Function: ConUnInit */ -/* Used to Uninitialize the Console */ -/* ************************************************************ */ -int ConUnInitWithRestore( void ) +/* Used to Uninitialize the Console */ +int +ConUnInitWithRestore(void) { - DWORD dwWritten; - COORD Coord ; - CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo; + DWORD dwWritten; + COORD Coord; + CONSOLE_SCREEN_BUFFER_INFO consoleInfo; - if ( hOutputConsole == NULL ) - return 0; + if (hOutputConsole == NULL) + return 0; - if (!GetConsoleScreenBufferInfo(hOutputConsole, &ConsoleInfo)) - return 0; + if (!GetConsoleScreenBufferInfo(hOutputConsole, &consoleInfo)) + return 0; - SetConsoleMode(hOutputConsole, dwSavedAttributes); - - Coord = ConsoleInfo.dwCursorPosition; - Coord.X = 0; - - DWORD dwNumChar = (ConsoleInfo.dwSize.Y - ConsoleInfo.dwCursorPosition.Y) * - ConsoleInfo.dwSize.X; - - FillConsoleOutputCharacter(hOutputConsole, ' ', dwNumChar, - Coord, &dwWritten); - FillConsoleOutputAttribute(hOutputConsole, wStartingAttributes, dwNumChar, - Coord, &dwWritten); - - SetConsoleTextAttribute(hOutputConsole, wStartingAttributes); - - return 0; + SetConsoleMode(hOutputConsole, dwSavedAttributes); + Coord = consoleInfo.dwCursorPosition; + Coord.X = 0; + DWORD dwNumChar = (consoleInfo.dwSize.Y - consoleInfo.dwCursorPosition.Y) * consoleInfo.dwSize.X; + FillConsoleOutputCharacter(hOutputConsole, ' ', dwNumChar, Coord, &dwWritten); + FillConsoleOutputAttribute(hOutputConsole, wStartingAttributes, dwNumChar, Coord, &dwWritten); + SetConsoleTextAttribute(hOutputConsole, wStartingAttributes); + return 0; } -BOOL ConSetScreenRect( int xSize, int ySize ) +BOOL +ConSetScreenRect(int xSize, int ySize) { - BOOL bSuccess = TRUE; + BOOL bSuccess = TRUE; + CONSOLE_SCREEN_BUFFER_INFO csbi; /* hold current console buffer info */ + SMALL_RECT srWindowRect; /* hold the new console size */ + COORD coordScreen; - CONSOLE_SCREEN_BUFFER_INFO csbi; /* hold current console buffer info */ - SMALL_RECT srWindowRect; /* hold the new console size */ - COORD coordScreen; + bSuccess = GetConsoleScreenBufferInfo(hOutputConsole, &csbi); + if (!bSuccess) + return bSuccess; - bSuccess = GetConsoleScreenBufferInfo(hOutputConsole, &csbi); - if (!bSuccess) { - return bSuccess; - } + /* get the largest size we can size the console window to */ + coordScreen = GetLargestConsoleWindowSize(hOutputConsole); - /* get the largest size we can size the console window to */ - coordScreen = GetLargestConsoleWindowSize(hOutputConsole); + /* 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 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); - } + /* define the new console buffer size */ + coordScreen.X = max(csbi.dwSize.X, xSize); + coordScreen.Y = max(csbi.dwSize.Y, ySize); - if (bSuccess) - ConSaveViewRect(); + /* 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 ) +BOOL +ConSetScreenSize(int xSize, int ySize) { - BOOL bSuccess = TRUE; + BOOL bSuccess = TRUE; + CONSOLE_SCREEN_BUFFER_INFO csbi; /* hold current console buffer info */ + SMALL_RECT srWindowRect; /* hold the new console size */ + COORD coordScreen; - CONSOLE_SCREEN_BUFFER_INFO csbi; /* hold current console buffer info */ - SMALL_RECT srWindowRect; /* hold the new console size */ - COORD coordScreen; + bSuccess = GetConsoleScreenBufferInfo(hOutputConsole, &csbi); + if (!bSuccess) + return bSuccess; - bSuccess = GetConsoleScreenBufferInfo(hOutputConsole, &csbi); - if (!bSuccess) { - return bSuccess; - } + /* get the largest size we can size the console window to */ + coordScreen = GetLargestConsoleWindowSize(hOutputConsole); - /* get the largest size we can size the console window to */ - coordScreen = GetLargestConsoleWindowSize(hOutputConsole); + /* 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 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); - } - } + /* define the new console buffer size */ + coordScreen.X = xSize; + coordScreen.Y = ySize; - /* 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 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: ConSetAttributes */ -/* Used to set the Color of the console and other attributes */ -/* ************************************************************ */ -void ConSetAttribute(int *iParam, int iParamCount) +/* Used to set the Color of the console and other attributes */ +void +ConSetAttribute(int *iParam, int iParamCount) { - static int iAttr = 0; - int i = 0; - BOOL bRet = TRUE; + static int iAttr = 0; + int i = 0; + BOOL bRet = TRUE; - if (iParamCount < 1) - { - iAttr |= FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; + if (iParamCount < 1) { + iAttr |= FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; + iAttr = iAttr & ~BACKGROUND_INTENSITY; + iAttr = iAttr & ~FOREGROUND_INTENSITY; + iAttr = iAttr & ~COMMON_LVB_UNDERSCORE; + iAttr = iAttr & ~COMMON_LVB_REVERSE_VIDEO; - iAttr = iAttr & ~BACKGROUND_INTENSITY; - iAttr = iAttr & ~FOREGROUND_INTENSITY; - iAttr = iAttr & ~COMMON_LVB_UNDERSCORE; - iAttr = iAttr & ~COMMON_LVB_REVERSE_VIDEO; + SetConsoleTextAttribute(hOutputConsole, (WORD)iAttr); + } else { + for (i = 0; i < iParamCount; i++) { + switch (iParam[i]) { + case ANSI_ATTR_RESET: + iAttr |= FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; + iAttr = iAttr & ~BACKGROUND_RED; + iAttr = iAttr & ~BACKGROUND_BLUE; + iAttr = iAttr & ~BACKGROUND_GREEN; + iAttr = iAttr & ~BACKGROUND_INTENSITY; + iAttr = iAttr & ~FOREGROUND_INTENSITY; + iAttr = iAttr & ~COMMON_LVB_UNDERSCORE; + iAttr = iAttr & ~COMMON_LVB_REVERSE_VIDEO; + break; + case ANSI_BRIGHT: + iAttr |= FOREGROUND_INTENSITY; + break; + case ANSI_DIM: + break; + case ANSI_NOUNDERSCORE: + iAttr = iAttr & ~COMMON_LVB_UNDERSCORE; + break; + case ANSI_UNDERSCORE: + iAttr |= COMMON_LVB_UNDERSCORE; + break; + case ANSI_BLINK: + break; + case ANSI_REVERSE: + iAttr |= COMMON_LVB_REVERSE_VIDEO; + break; + case ANSI_HIDDEN: + break; + case ANSI_NOREVERSE: + iAttr = iAttr & ~COMMON_LVB_REVERSE_VIDEO; + break; + case ANSI_DEFAULT_FOREGROUND: + /* White */ + iAttr |= FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; + break; + case ANSI_FOREGROUND_BLACK: + iAttr = iAttr & ~FOREGROUND_RED; + iAttr = iAttr & ~FOREGROUND_BLUE; + iAttr = iAttr & ~FOREGROUND_GREEN; + iAttr |= 0; + break; + case ANSI_FOREGROUND_RED: + iAttr = iAttr & ~FOREGROUND_GREEN; + iAttr = iAttr & ~FOREGROUND_BLUE; + iAttr |= FOREGROUND_RED; + break; + case ANSI_FOREGROUND_GREEN: + iAttr = iAttr & ~FOREGROUND_BLUE; + iAttr = iAttr & ~FOREGROUND_RED; + iAttr |= FOREGROUND_GREEN; + break; + case ANSI_FOREGROUND_YELLOW: + iAttr = iAttr & ~FOREGROUND_BLUE; + iAttr |= FOREGROUND_RED | FOREGROUND_GREEN; + break; + case ANSI_FOREGROUND_BLUE: + iAttr = iAttr & ~FOREGROUND_GREEN; + iAttr = iAttr & ~FOREGROUND_RED; + iAttr |= FOREGROUND_BLUE; + break; + case ANSI_FOREGROUND_MAGENTA: + iAttr = iAttr & ~FOREGROUND_GREEN; + iAttr |= FOREGROUND_BLUE | FOREGROUND_RED; + break; + case ANSI_FOREGROUND_CYAN: + iAttr = iAttr & ~FOREGROUND_RED; + iAttr |= FOREGROUND_BLUE | FOREGROUND_GREEN; + break; + case ANSI_FOREGROUND_WHITE: + iAttr |= FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN; + break; + case ANSI_DEFAULT_BACKGROUND: + /* Black */ + iAttr = iAttr & ~BACKGROUND_RED; + iAttr = iAttr & ~BACKGROUND_BLUE; + iAttr = iAttr & ~BACKGROUND_GREEN; + iAttr |= 0; + break; + case ANSI_BACKGROUND_BLACK: + iAttr = iAttr & ~BACKGROUND_RED; + iAttr = iAttr & ~BACKGROUND_BLUE; + iAttr = iAttr & ~BACKGROUND_GREEN; + iAttr |= 0; + break; + case ANSI_BACKGROUND_RED: + iAttr = iAttr & ~BACKGROUND_GREEN; + iAttr = iAttr & ~BACKGROUND_BLUE; + iAttr |= BACKGROUND_RED; + break; + case ANSI_BACKGROUND_GREEN: + iAttr = iAttr & ~BACKGROUND_RED; + iAttr = iAttr & ~BACKGROUND_BLUE; + iAttr |= BACKGROUND_GREEN; + break; + case ANSI_BACKGROUND_YELLOW: + iAttr = iAttr & ~BACKGROUND_BLUE; + iAttr |= BACKGROUND_RED | BACKGROUND_GREEN; + break; + case ANSI_BACKGROUND_BLUE: + iAttr = iAttr & ~BACKGROUND_GREEN; + iAttr = iAttr & ~BACKGROUND_RED; + iAttr |= BACKGROUND_BLUE; + break; + case ANSI_BACKGROUND_MAGENTA: + iAttr = iAttr & ~BACKGROUND_GREEN; + iAttr |= BACKGROUND_BLUE | BACKGROUND_RED; + break; + case ANSI_BACKGROUND_CYAN: + iAttr = iAttr & ~BACKGROUND_RED; + iAttr |= BACKGROUND_BLUE | BACKGROUND_GREEN; + break; + case ANSI_BACKGROUND_WHITE: + iAttr |= BACKGROUND_BLUE | BACKGROUND_RED | BACKGROUND_GREEN; + break; + case ANSI_BACKGROUND_BRIGHT: + iAttr |= BACKGROUND_INTENSITY; + break; + default: + continue; + } + } - SetConsoleTextAttribute(hOutputConsole, (WORD)iAttr); - } - else - { - for (i=0;i ScrollBottom-1) - { - ConScrollDown( ScrollTop, ScrollBottom ); - ConSetCursorPosition( 0, ScrollBottom ); - } - else - ConSetCursorPosition( 0, Y ); - break; - - default: - - fOkay = (BOOL)WriteConsole( hOutputConsole, &ch, 1, (LPDWORD)&Result, 0 ); - - if ( X >= ScreenX-1 ) // last coord - { - if (Y >= ScrollBottom-1) // last coord - { - ConScrollDown(ScrollTop,ScrollBottom); - ConMoveCursorPosition(-ConGetCursorX(),0); - } - else - { - ConMoveCursorPosition(-ConGetCursorX(),1); - } - } - break; - } - - return fOkay; + return Result; } - -BOOL ConWriteCharW(WCHAR ch) +BOOL +ConWriteChar(CHAR ch) { - int X, Y, Result; - BOOL fOkay = TRUE; + int X, Y, Result; + BOOL fOkay = TRUE; - Y = ConGetCursorY(); - X = ConGetCursorX(); + Y = ConGetCursorY(); + X = ConGetCursorX(); - switch ( ch ) - { - case 0x8: // BackSpace - if ( X == 0 ) - { - ConSetCursorPosition( ScreenX - 1, --Y ); - WriteConsole( hOutputConsole, " ", 1, (LPDWORD)&Result, 0 ); - ConSetCursorPosition( ScreenX - 1, Y ); - } - else - { - ConSetCursorPosition( X - 1, Y ); - WriteConsole( hOutputConsole, " ", 1, (LPDWORD)&Result, 0 ); - ConSetCursorPosition( X - 1, Y ); - } + switch (ch) { + case 0x8: /* BackSpace */ + if (X == 0) { + ConSetCursorPosition(ScreenX - 1, --Y); + WriteConsole(hOutputConsole, " ", 1, (LPDWORD)&Result, 0); + ConSetCursorPosition(ScreenX - 1, Y); + } else { + ConSetCursorPosition(X - 1, Y); + WriteConsole(hOutputConsole, " ", 1, (LPDWORD)&Result, 0); + ConSetCursorPosition(X - 1, Y); + } - break; - case L'\r': - ConSetCursorPosition( 0, Y ); - break; + break; + case '\r': + ConSetCursorPosition(0, Y); - case L'\n': - Y++; - if ( Y > ScrollBottom-1) - { - ConScrollDown( ScrollTop, ScrollBottom ); - ConSetCursorPosition( 0, ScrollBottom ); - } - else - ConSetCursorPosition( 0, Y ); - break; + break; + case '\n': + Y++; + if (Y > ScrollBottom - 1) { + ConScrollDown(ScrollTop, ScrollBottom); + ConSetCursorPosition(0, ScrollBottom); + } else + ConSetCursorPosition(0, Y); + break; + default: + fOkay = (BOOL)WriteConsole(hOutputConsole, &ch, 1, (LPDWORD)&Result, 0); - default: - fOkay = (BOOL)WriteConsoleW( hOutputConsole, &ch, 1, (LPDWORD)&Result, 0 ); + /* last coord */ + if (X >= ScreenX - 1) { + if (Y >= ScrollBottom - 1) { /* last coord */ + ConScrollDown(ScrollTop, ScrollBottom); + ConMoveCursorPosition(-ConGetCursorX(), 0); + } else + ConMoveCursorPosition(-ConGetCursorX(), 1); + } + break; + } - if ( X >= ScreenX-1 ) // last coord - { - if (Y >= ScrollBottom-1) // last coord - { - ConScrollDown(ScrollTop,ScrollBottom); - ConMoveCursorPosition(-ConGetCursorX(),0); - } - else - { - ConMoveCursorPosition(-ConGetCursorX(),1); - } - } - break; - } + return fOkay; +} - return fOkay; +BOOL +ConWriteCharW(WCHAR ch) +{ + int X, Y, Result; + BOOL fOkay = TRUE; + + Y = ConGetCursorY(); + X = ConGetCursorX(); + + switch (ch) { + case 0x8: /* BackSpace */ + if (X == 0) { + ConSetCursorPosition(ScreenX - 1, --Y); + WriteConsole(hOutputConsole, " ", 1, (LPDWORD)&Result, 0); + ConSetCursorPosition(ScreenX - 1, Y); + } else { + ConSetCursorPosition(X - 1, Y); + WriteConsole(hOutputConsole, " ", 1, (LPDWORD)&Result, 0); + ConSetCursorPosition(X - 1, Y); + } + break; + case L'\r': + ConSetCursorPosition(0, Y); + break; + + case L'\n': + Y++; + if (Y > ScrollBottom - 1) { + ConScrollDown(ScrollTop, ScrollBottom); + ConSetCursorPosition(0, ScrollBottom); + } + else + ConSetCursorPosition(0, Y); + break; + + default: + fOkay = (BOOL)WriteConsoleW(hOutputConsole, &ch, 1, (LPDWORD)&Result, 0); + + if (X >= ScreenX - 1) { /* last coord */ + if (Y >= ScrollBottom - 1) { /* last coord */ + ConScrollDown(ScrollTop, ScrollBottom); + ConMoveCursorPosition(-ConGetCursorX(), 0); + } else + ConMoveCursorPosition(-ConGetCursorX(), 1); + } + break; + } + return fOkay; } /* Special Function for handling TABS and other bad control chars */ -int ConWriteConsole( char *pData, int NumChars ) +int +ConWriteConsole(char *pData, int NumChars) { - int X, CurrentY, CurrentX, Result; + int X, CurrentY, CurrentX, Result; - for( X = 0; (X < NumChars) && (pData[X] != '\0') ; X++ ) - { - switch (pData[X]) - { + for (X = 0; (X < NumChars) && (pData[X] != '\0'); X++) { + switch (pData[X]) { + case 0: /* FALLTHROUGH */ + case 1: /* FALLTHROUGH */ + case 2: /* FALLTHROUGH */ + case 3: /* FALLTHROUGH */ + case 4: /* FALLTHROUGH */ + case 5: /* FALLTHROUGH */ + case 6: /* FALLTHROUGH */ + case 11: /* FALLTHROUGH */ + break; - case 0: - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: - case 11: - break; + case 7: + Beep(1000, 400); + break; - case 7: - Beep( 1000, 400); - break; + case 8: + ConMoveCursorPosition(-1, 0); + WriteConsole(hOutputConsole, " ", 1, (LPDWORD)&Result, 0); + ConMoveCursorPosition(-1, 0); + break; - case 8: - ConMoveCursorPosition( -1, 0 ); - WriteConsole(hOutputConsole, " ", 1, (LPDWORD)&Result, 0); - ConMoveCursorPosition( -1, 0 ); - break; + case 9: + { + int i, MoveRight = TAB_LENGTH - (ConGetCursorX() % TAB_LENGTH); - case 9: - { - int i, MoveRight = TAB_LENGTH - (ConGetCursorX() % TAB_LENGTH); + for (i = 0; i < MoveRight; i++) + WriteConsole(hOutputConsole, " ", 1, (LPDWORD)&Result, 0); + } + break; - for ( i = 0; i < MoveRight; i++ ) - WriteConsole(hOutputConsole, " ", 1, (LPDWORD)&Result, 0); - } - break; + case 10: + CurrentY = ConGetCursorY() + 1; + if (CurrentY >= ScrollBottom) { + ConScrollDown(ScrollTop, ScrollBottom); + ConMoveCursorPosition(-ConGetCursorX(), 0); + } else + ConMoveCursorPosition(0, 1); + break; - case 10: - CurrentY = ConGetCursorY()+1; - if (CurrentY >= ScrollBottom) - { - ConScrollDown(ScrollTop,ScrollBottom); - ConMoveCursorPosition(-ConGetCursorX(),0); - } - else - { - ConMoveCursorPosition(0,1); - } - break; - - case 12: - ConClearScreen(); - ConSetCursorPosition(0, 0); - break; + case 12: + ConClearScreen(); + ConSetCursorPosition(0, 0); + break; - case 13: - ConMoveCursorPosition(-ConGetCursorX(),0); - break; + case 13: + ConMoveCursorPosition(-ConGetCursorX(), 0); + break; - case 14: - break; + case 14: /* FALLTHROUGH */ + case 15: + break; - case 15: - break; + default: + { + CurrentY = ConGetCursorY(); + CurrentX = ConGetCursorX(); - default: - { + WriteConsole(hOutputConsole, &pData[X], 1, (LPDWORD)&Result, 0); - CurrentY = ConGetCursorY(); - CurrentX = ConGetCursorX(); + if (CurrentX >= ScreenX - 1) { /* last coord */ + if (CurrentY >= ScrollBottom - 1) { /* last coord */ + ConScrollDown(ScrollTop, ScrollBottom); + ConMoveCursorPosition(-ConGetCursorX(), 0); + } else + ConMoveCursorPosition(-ConGetCursorX(), 1); + } + } + } + } - WriteConsole(hOutputConsole, &pData[X], 1, (LPDWORD)&Result, 0); - - if ( CurrentX >= ScreenX-1) // last coord - { - if (CurrentY >= ScrollBottom-1) // last coord - { - ConScrollDown(ScrollTop,ScrollBottom); - ConMoveCursorPosition(-ConGetCursorX(),0); - } - else - { - ConMoveCursorPosition(-ConGetCursorX(),1); - } - } - } - } - } - - return X; + return X; } -PCHAR ConWriteLine(char* pData) +PCHAR +ConWriteLine(char* pData) { - PCHAR pCurrent, pNext, pTab; - DWORD Result; - size_t distance, tabCount, pos; - size_t tabLength, charCount; + PCHAR pCurrent, pNext, pTab; + DWORD Result; + size_t distance, tabCount, pos; + size_t tabLength, charCount; - pCurrent = pData; + pCurrent = pData; + pNext = strchr(pCurrent, '\r'); + if (pNext != NULL) { + distance = pNext - pCurrent; - pNext = strchr( pCurrent, '\r' ); - if ( pNext != NULL ) - { - distance = pNext - pCurrent; + if (distance > (size_t)ScreenX) + distance = (size_t)ScreenX; - if ( distance > (size_t)ScreenX ) - distance = (size_t)ScreenX; + pos = 0; + tabCount = 0; + pTab = strchr(pCurrent, TAB_CHAR); + if ((pTab != NULL) && (pTab < pNext)) { + /* Tab exists in string So we use our WriteString */ + while ((pTab != NULL) && (pTab < pNext) && (pos < (size_t)ScreenX)) { + tabCount++; + charCount = (pTab - pCurrent) - 1; /* Ignore actual TAB since we add 8 for it */ + pos = charCount + (tabCount * TAB_LENGTH); + pTab++; /* increment past last tab */ + pTab = strchr(pTab, TAB_CHAR); + } - pos = 0; - tabCount = 0; - pTab = strchr( pCurrent, TAB_CHAR ); - if ( (pTab != NULL) && (pTab < pNext) ) - { - // Tab exists in string - // So we use our WriteString - while ( (pTab != NULL) && (pTab < pNext) && (pos < (size_t)ScreenX) ) - { - tabCount++; - charCount = (pTab - pCurrent) - 1; // Ignore actual TAB since we add 8 for it - pos = charCount + (tabCount * TAB_LENGTH); - pTab++; // increment past last tab - pTab = strchr( pTab, TAB_CHAR ); - } + tabLength = (tabCount * TAB_LENGTH); - tabLength = (tabCount * TAB_LENGTH); + distance = ConWriteConsole(pCurrent, (int)distance); /* Special routine for handling TABS */ -// if ( pos >= ScreenX ) - distance = ConWriteConsole( pCurrent, (int)distance );// Special routine for handling TABS + } else + WriteConsole(hOutputConsole, pCurrent, (DWORD)distance, &Result, 0); - } - else - WriteConsole( hOutputConsole,pCurrent, (DWORD)distance, &Result, 0 ); + ConSetCursorPosition(0, ConGetCursorY() + 1); - ConSetCursorPosition( 0, ConGetCursorY() + 1 ); + pCurrent += (distance + 2); /* Add one to always skip last char printed */ + } else { + distance = strlen(pCurrent); + if (distance > (size_t)ScreenX) + distance = (size_t)ScreenX; + WriteConsole(hOutputConsole, pCurrent, (DWORD)distance, &Result, 0); + pCurrent += distance; + } - pCurrent+= (distance + 2); // Add one to always skip last char printed - } - else - { - distance = strlen( pCurrent ); - if ( distance > (size_t)ScreenX ) - distance = (size_t)ScreenX; - WriteConsole( hOutputConsole, pCurrent, (DWORD)distance, &Result, 0 ); - pCurrent += distance; - } - - return pCurrent; + return pCurrent; } -PCHAR ConDisplayData(char* pData, int NumLines) +PCHAR +ConDisplayData(char* pData, int NumLines) { - PCHAR pCurrent, pNext, pTab; - DWORD Result; - size_t Y, distance, pos, add; - int linecnt = 0; + PCHAR pCurrent, pNext, pTab; + DWORD Result; + size_t Y, distance, pos, add; + int linecnt = 0; - pCurrent = pData; + pCurrent = pData; + for (; (pCurrent) && ((Y = (size_t)ConGetCursorY()) <= (size_t)ScrollBottom) && (*pCurrent != '\0'); ) { + pNext = strchr(pCurrent, '\n'); + if (pNext != NULL) { + --pNext; + if (*pNext != '\r') { + pNext++; + add = 1; + } + else + add = 2; + distance = pNext - pCurrent; - for ( ;(pCurrent) && - ((Y = (size_t)ConGetCursorY()) <= (size_t)ScrollBottom) && - (*pCurrent != '\0'); ) - { - pNext = strchr( pCurrent, '\n' ); - if ( pNext != NULL ) - { - --pNext; - if ( *pNext != '\r' ) - { - pNext++; - add = 1; - } - else - add = 2; - distance = pNext - pCurrent; - - if ( distance > 0 && linecnt < NumLines) - { - pos = 0; - pTab = strchr( pCurrent, TAB_CHAR ); - if ( (distance > (size_t)ScreenX) || ((pTab != NULL) && (pTab < pNext)) ) - { - ConWriteConsole( pCurrent, (int)distance ); // Special routine for handling TABS - } - else - { - WriteConsole( hOutputConsole, pCurrent, (DWORD)distance, &Result, 0 ); - } - } - ConMoveCursorPosition(-ConGetCursorX(),1); - pCurrent += (distance + add); // Add one to always skip last char printed - linecnt++; - } - else - { - distance = strlen( pCurrent ); - if ( distance > (size_t)ScreenX ) - distance = ScreenX; - if (linecnt < NumLines) - WriteConsole( hOutputConsole, pCurrent, (DWORD)distance, &Result, 0 ); - return pCurrent + distance; - } - } - return pCurrent; + if (distance > 0 && linecnt < NumLines) { + pos = 0; + pTab = strchr(pCurrent, TAB_CHAR); + if ((distance > (size_t)ScreenX) || ((pTab != NULL) && (pTab < pNext))) + ConWriteConsole(pCurrent, (int)distance); /* Special routine for handling TABS */ + else + WriteConsole(hOutputConsole, pCurrent, (DWORD)distance, &Result, 0); + } + ConMoveCursorPosition(-ConGetCursorX(), 1); + pCurrent += (distance + add); /* Add one to always skip last char printed */ + linecnt++; + } else { + distance = strlen(pCurrent); + if (distance > (size_t)ScreenX) + distance = ScreenX; + if (linecnt < NumLines) + WriteConsole(hOutputConsole, pCurrent, (DWORD)distance, &Result, 0); + return pCurrent + distance; + } + } + return pCurrent; } -int Con_printf( const char *Format, ... ) +int +Con_printf(const char *Format, ...) { - va_list va_data; - int len; - char Temp[4096]; + va_list va_data; + int len; + char temp[4096]; - memset( Temp, '\0', sizeof( Temp ) ); + memset(temp, '\0', sizeof(temp)); + va_start(va_data, Format); + len = vsnprintf(temp, sizeof(temp), Format, va_data); + ConWriteConsole(temp, len); + va_end(va_data); - va_start( va_data, Format ); - - len = vsnprintf( Temp, sizeof(Temp), Format, va_data ); - - ConWriteConsole(Temp, len); - - va_end( va_data ); - - return len; + return len; } -BOOL ConDisplayCursor( BOOL bVisible ) +BOOL +ConDisplayCursor(BOOL bVisible) { - CONSOLE_CURSOR_INFO ConsoleCursorInfo; + CONSOLE_CURSOR_INFO ConsoleCursorInfo; - if (GetConsoleCursorInfo(hOutputConsole, &ConsoleCursorInfo)) { + if (GetConsoleCursorInfo(hOutputConsole, &ConsoleCursorInfo)) { + ConsoleCursorInfo.bVisible = bVisible; + return SetConsoleCursorInfo(hOutputConsole, &ConsoleCursorInfo); + } - ConsoleCursorInfo.bVisible = bVisible; - - return SetConsoleCursorInfo(hOutputConsole, &ConsoleCursorInfo); - } - - return FALSE; + return FALSE; } -void ConClearScreen(void) +void +ConClearScreen(void) { - DWORD dwWritten; - COORD Coord ; - CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo; - SMALL_RECT srcWindow; + DWORD dwWritten; + COORD Coord; + CONSOLE_SCREEN_BUFFER_INFO consoleInfo; + SMALL_RECT srcWindow; - if (!GetConsoleScreenBufferInfo(hOutputConsole, &ConsoleInfo)) - return; + if (!GetConsoleScreenBufferInfo(hOutputConsole, &consoleInfo)) + return; - Coord.X = 0; - Coord.Y = 0; + Coord.X = 0; + Coord.Y = 0; - DWORD dwNumChar = (ConsoleInfo.srWindow.Bottom + 1) * - (ConsoleInfo.srWindow.Right + 1); - - FillConsoleOutputCharacter(hOutputConsole, ' ', - dwNumChar, - Coord, &dwWritten); - FillConsoleOutputAttribute(hOutputConsole, ConsoleInfo.wAttributes, - dwNumChar, - Coord, &dwWritten); - - srcWindow = ConsoleInfo.srWindow; - - ConSetCursorPosition(0, 0); + DWORD dwNumChar = (consoleInfo.srWindow.Bottom + 1) * (consoleInfo.srWindow.Right + 1); + FillConsoleOutputCharacter(hOutputConsole, ' ', dwNumChar, Coord, &dwWritten); + FillConsoleOutputAttribute(hOutputConsole, consoleInfo.wAttributes, dwNumChar, Coord, &dwWritten); + srcWindow = consoleInfo.srWindow; + ConSetCursorPosition(0, 0); } -void ConClearScrollRegion() +void +ConClearScrollRegion() { - DWORD dwWritten; - COORD Coord ; - CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo; - if (!GetConsoleScreenBufferInfo(hOutputConsole, &ConsoleInfo)) - return; + DWORD dwWritten; + COORD Coord; + CONSOLE_SCREEN_BUFFER_INFO consoleInfo; + if (!GetConsoleScreenBufferInfo(hOutputConsole, &consoleInfo)) + return; - Coord.X = 0; - Coord.Y = ScrollTop+ConsoleInfo.srWindow.Top; - FillConsoleOutputCharacter(hOutputConsole, ' ', (DWORD)ConsoleInfo.dwSize.X * (DWORD)ScrollBottom, - Coord, &dwWritten); + Coord.X = 0; + Coord.Y = ScrollTop + consoleInfo.srWindow.Top; + FillConsoleOutputCharacter(hOutputConsole, ' ', (DWORD)consoleInfo.dwSize.X * (DWORD)ScrollBottom, + Coord, &dwWritten); - FillConsoleOutputAttribute(hOutputConsole, ConsoleInfo.wAttributes, - (DWORD)ConsoleInfo.dwSize.X * (DWORD)ScrollBottom, - Coord, &dwWritten); + FillConsoleOutputAttribute(hOutputConsole, consoleInfo.wAttributes, + (DWORD)consoleInfo.dwSize.X * (DWORD)ScrollBottom, Coord, &dwWritten); - ConSetCursorPosition( 0, ScrollTop ); + ConSetCursorPosition(0, ScrollTop); } -void ConClearEOScreen() +void +ConClearEOScreen() { - DWORD dwWritten; - COORD Coord ; - CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo; + DWORD dwWritten; + COORD Coord; + CONSOLE_SCREEN_BUFFER_INFO consoleInfo; - if (!GetConsoleScreenBufferInfo(hOutputConsole, &ConsoleInfo)) - return; + if (!GetConsoleScreenBufferInfo(hOutputConsole, &consoleInfo)) + return; - Coord.X = 0; - Coord.Y = (short)(ConGetCursorY() + 1) + ConsoleInfo.srWindow.Top; - FillConsoleOutputCharacter(hOutputConsole, ' ', - (DWORD)(ConsoleInfo.dwSize.X)* - (DWORD)(ConsoleInfo.srWindow.Bottom - Coord.Y + 1), - Coord, &dwWritten); - FillConsoleOutputAttribute(hOutputConsole, ConsoleInfo.wAttributes, - (DWORD)(ConsoleInfo.dwSize.X)* - (DWORD)(ConsoleInfo.srWindow.Bottom - Coord.Y + 1), - Coord, &dwWritten); + Coord.X = 0; + Coord.Y = (short)(ConGetCursorY() + 1) + consoleInfo.srWindow.Top; + FillConsoleOutputCharacter(hOutputConsole, ' ', + (DWORD)(consoleInfo.dwSize.X)* + (DWORD)(consoleInfo.srWindow.Bottom - Coord.Y + 1), + Coord, &dwWritten); + FillConsoleOutputAttribute(hOutputConsole, consoleInfo.wAttributes, + (DWORD)(consoleInfo.dwSize.X)* + (DWORD)(consoleInfo.srWindow.Bottom - Coord.Y + 1), + Coord, &dwWritten); - ConClearEOLine(); + ConClearEOLine(); } -void ConClearBOScreen() +void +ConClearBOScreen() { - DWORD dwWritten; - COORD Coord; - CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo; - if (!GetConsoleScreenBufferInfo(hOutputConsole, &ConsoleInfo)) - return; + DWORD dwWritten; + COORD Coord; + CONSOLE_SCREEN_BUFFER_INFO consoleInfo; + if (!GetConsoleScreenBufferInfo(hOutputConsole, &consoleInfo)) + return; - Coord.X = 0; - Coord.Y = 0; - FillConsoleOutputCharacter(hOutputConsole, ' ', - (DWORD)(ConsoleInfo.dwSize.X)* - (DWORD)(ConsoleInfo.dwSize.Y - ConGetCursorY() - 1), - Coord, &dwWritten); - FillConsoleOutputAttribute(hOutputConsole, ConsoleInfo.wAttributes, - (DWORD)(ConsoleInfo.dwSize.X)* - (DWORD)(ConsoleInfo.dwSize.Y - ConGetCursorY() - 1), - Coord, &dwWritten); + Coord.X = 0; + Coord.Y = 0; + FillConsoleOutputCharacter(hOutputConsole, ' ', + (DWORD)(consoleInfo.dwSize.X)* + (DWORD)(consoleInfo.dwSize.Y - ConGetCursorY() - 1), + Coord, &dwWritten); + FillConsoleOutputAttribute(hOutputConsole, consoleInfo.wAttributes, + (DWORD)(consoleInfo.dwSize.X)* + (DWORD)(consoleInfo.dwSize.Y - ConGetCursorY() - 1), + Coord, &dwWritten); - ConClearBOLine(); + ConClearBOLine(); } -void ConClearLine() +void +ConClearLine() { - DWORD dwWritten; - COORD Coord; - CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo; - if (!GetConsoleScreenBufferInfo(hOutputConsole, &ConsoleInfo)) - return; + DWORD dwWritten; + COORD Coord; + CONSOLE_SCREEN_BUFFER_INFO consoleInfo; + if (!GetConsoleScreenBufferInfo(hOutputConsole, &consoleInfo)) + return; - Coord.X = 0; - Coord.Y = ConGetCursorY(); - - FillConsoleOutputAttribute(hOutputConsole, ConsoleInfo.wAttributes, ScreenX, - Coord, &dwWritten); - FillConsoleOutputCharacter(hOutputConsole, ' ',ScreenX, - Coord, &dwWritten); + Coord.X = 0; + Coord.Y = ConGetCursorY(); + FillConsoleOutputAttribute(hOutputConsole, consoleInfo.wAttributes, ScreenX, Coord, &dwWritten); + FillConsoleOutputCharacter(hOutputConsole, ' ', ScreenX, Coord, &dwWritten); } -void ConClearEOLine() +void +ConClearEOLine() { - DWORD dwWritten; - COORD Coord; - CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo; + DWORD dwWritten; + COORD Coord; + CONSOLE_SCREEN_BUFFER_INFO consoleInfo; - if (!GetConsoleScreenBufferInfo(hOutputConsole, &ConsoleInfo)) - return;; + if (!GetConsoleScreenBufferInfo(hOutputConsole, &consoleInfo)) + return;; - Coord.X = ConGetCursorX()+ConsoleInfo.srWindow.Left; - Coord.Y = ConGetCursorY()+ConsoleInfo.srWindow.Top; + Coord.X = ConGetCursorX() + consoleInfo.srWindow.Left; + Coord.Y = ConGetCursorY() + consoleInfo.srWindow.Top; - FillConsoleOutputCharacter(hOutputConsole, ' ', - (DWORD)(ScreenX - ConGetCursorX()), - Coord, &dwWritten); - FillConsoleOutputAttribute(hOutputConsole, ConsoleInfo.wAttributes, - (DWORD)(ScreenX - ConGetCursorX()), - Coord, &dwWritten); + FillConsoleOutputCharacter(hOutputConsole, ' ', + (DWORD)(ScreenX - ConGetCursorX()), + Coord, &dwWritten); + FillConsoleOutputAttribute(hOutputConsole, consoleInfo.wAttributes, + (DWORD)(ScreenX - ConGetCursorX()), + Coord, &dwWritten); } -void ConClearNFromCursorRight(int n) +void +ConClearNFromCursorRight(int n) { - DWORD dwWritten; - COORD Coord; - CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo; - if (!GetConsoleScreenBufferInfo(hOutputConsole, &ConsoleInfo)) - return; + DWORD dwWritten; + COORD Coord; + CONSOLE_SCREEN_BUFFER_INFO consoleInfo; + if (!GetConsoleScreenBufferInfo(hOutputConsole, &consoleInfo)) + return; - - Coord.X = ConGetCursorX()+ConsoleInfo.srWindow.Left; - Coord.Y = ConGetCursorY()+ConsoleInfo.srWindow.Top; - FillConsoleOutputCharacter(hOutputConsole, ' ', - (DWORD)n, - Coord, &dwWritten); - FillConsoleOutputAttribute(hOutputConsole, ConsoleInfo.wAttributes, - (DWORD)n, - Coord, &dwWritten); + Coord.X = ConGetCursorX() + consoleInfo.srWindow.Left; + Coord.Y = ConGetCursorY() + consoleInfo.srWindow.Top; + FillConsoleOutputCharacter(hOutputConsole, ' ', (DWORD)n, Coord, &dwWritten); + FillConsoleOutputAttribute(hOutputConsole, consoleInfo.wAttributes, (DWORD)n, Coord, &dwWritten); } -void ConClearNFromCursorLeft(int n) +void +ConClearNFromCursorLeft(int n) { - DWORD dwWritten; - COORD Coord; - CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo; + DWORD dwWritten; + COORD Coord; + CONSOLE_SCREEN_BUFFER_INFO consoleInfo; - if (!GetConsoleScreenBufferInfo(hOutputConsole, &ConsoleInfo)) - return; + if (!GetConsoleScreenBufferInfo(hOutputConsole, &consoleInfo)) + return; - Coord.X = ConGetCursorX()+ConsoleInfo.srWindow.Left-n; - Coord.Y = ConGetCursorY()+ConsoleInfo.srWindow.Top; - FillConsoleOutputCharacter(hOutputConsole, ' ', - (DWORD)n, - Coord, &dwWritten); - FillConsoleOutputAttribute(hOutputConsole, ConsoleInfo.wAttributes, - (DWORD)n, - Coord, &dwWritten); + Coord.X = ConGetCursorX() + consoleInfo.srWindow.Left - n; + Coord.Y = ConGetCursorY() + consoleInfo.srWindow.Top; + FillConsoleOutputCharacter(hOutputConsole, ' ', (DWORD)n, Coord, &dwWritten); + FillConsoleOutputAttribute(hOutputConsole, consoleInfo.wAttributes, (DWORD)n, Coord, &dwWritten); } -void ConScrollDownEntireBuffer() +void +ConScrollDownEntireBuffer() { - CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo; + CONSOLE_SCREEN_BUFFER_INFO consoleInfo; - if (!GetConsoleScreenBufferInfo(hOutputConsole, &ConsoleInfo)) - return; - ConScrollDown(0, ConsoleInfo.dwSize.Y - 1); - return; + if (!GetConsoleScreenBufferInfo(hOutputConsole, &consoleInfo)) + return; + ConScrollDown(0, consoleInfo.dwSize.Y - 1); + return; } -void ConScrollUpEntireBuffer() +void +ConScrollUpEntireBuffer() { - CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo; + CONSOLE_SCREEN_BUFFER_INFO consoleInfo; - if (!GetConsoleScreenBufferInfo(hOutputConsole, &ConsoleInfo)) - return; - ConScrollUp(0, ConsoleInfo.dwSize.Y - 1); - return; + if (!GetConsoleScreenBufferInfo(hOutputConsole, &consoleInfo)) + return; + ConScrollUp(0, consoleInfo.dwSize.Y - 1); + return; } -void ConScrollUp(int topline,int botline) +void +ConScrollUp(int topline, int botline) { - SMALL_RECT ScrollRect; - SMALL_RECT ClipRect; - COORD destination; - CHAR_INFO Fill; - CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo; + SMALL_RECT ScrollRect; + SMALL_RECT ClipRect; + COORD destination; + CHAR_INFO Fill; + CONSOLE_SCREEN_BUFFER_INFO consoleInfo; - if (!GetConsoleScreenBufferInfo(hOutputConsole, &ConsoleInfo)) - return; + if (!GetConsoleScreenBufferInfo(hOutputConsole, &consoleInfo)) + return; - if ((botline - topline) == ConsoleInfo.dwSize.Y-1) // scrolling whole buffer - { - ScrollRect.Top = topline; - ScrollRect.Bottom = botline; - } - else - { - ScrollRect.Top = topline + ConsoleInfo.srWindow.Top; - ScrollRect.Bottom = botline + ConsoleInfo.srWindow.Top; - } - ScrollRect.Left = 0; - ScrollRect.Right = ConScreenSizeX() -1; + if ((botline - topline) == consoleInfo.dwSize.Y - 1) { /* scrolling whole buffer */ + ScrollRect.Top = topline; + ScrollRect.Bottom = botline; + } else { + ScrollRect.Top = topline + consoleInfo.srWindow.Top; + ScrollRect.Bottom = botline + consoleInfo.srWindow.Top; + } - ClipRect.Top = ScrollRect.Top; - ClipRect.Bottom = ScrollRect.Bottom; - ClipRect.Left = ScrollRect.Left; - ClipRect.Right = ScrollRect.Right; + ScrollRect.Left = 0; + ScrollRect.Right = ConScreenSizeX() - 1; - destination.X = 0; - destination.Y = ScrollRect.Top+1; + ClipRect.Top = ScrollRect.Top; + ClipRect.Bottom = ScrollRect.Bottom; + ClipRect.Left = ScrollRect.Left; + ClipRect.Right = ScrollRect.Right; - Fill.Attributes = ConsoleInfo.wAttributes; - Fill.Char.AsciiChar = ' '; + destination.X = 0; + destination.Y = ScrollRect.Top + 1; - BOOL bRet = ScrollConsoleScreenBuffer( hOutputConsole, - &ScrollRect, - &ClipRect, - destination, - &Fill - ); + Fill.Attributes = consoleInfo.wAttributes; + Fill.Char.AsciiChar = ' '; + + BOOL bRet = ScrollConsoleScreenBuffer(hOutputConsole, + &ScrollRect, + &ClipRect, + destination, + &Fill + ); } -void ConScrollDown(int topline, int botline) +void +ConScrollDown(int topline, int botline) { - SMALL_RECT ScrollRect; - SMALL_RECT ClipRect; - COORD destination; - CHAR_INFO Fill; - CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo; + SMALL_RECT ScrollRect; + SMALL_RECT ClipRect; + COORD destination; + CHAR_INFO Fill; + CONSOLE_SCREEN_BUFFER_INFO consoleInfo; - if (!GetConsoleScreenBufferInfo(hOutputConsole, &ConsoleInfo)) - return; + if (!GetConsoleScreenBufferInfo(hOutputConsole, &consoleInfo)) + return; - if ((botline - topline) == ConsoleInfo.dwSize.Y - 1) // scrolling whole buffer - { - ScrollRect.Top = topline; - ScrollRect.Bottom = botline; - } - else - { - ScrollRect.Top = topline + ConsoleInfo.srWindow.Top + 1; - ScrollRect.Bottom = botline + ConsoleInfo.srWindow.Top; - } + if ((botline - topline) == consoleInfo.dwSize.Y - 1) { /* scrolling whole buffer */ + ScrollRect.Top = topline; + ScrollRect.Bottom = botline; + } else { + ScrollRect.Top = topline + consoleInfo.srWindow.Top + 1; + ScrollRect.Bottom = botline + consoleInfo.srWindow.Top; + } - ScrollRect.Left = 0; - ScrollRect.Right = ConScreenSizeX() - 1; + ScrollRect.Left = 0; + ScrollRect.Right = ConScreenSizeX() - 1; - ClipRect.Top = ScrollRect.Top; - ClipRect.Bottom = ScrollRect.Bottom; - ClipRect.Left = ScrollRect.Left; - ClipRect.Right = ScrollRect.Right; + ClipRect.Top = ScrollRect.Top; + ClipRect.Bottom = ScrollRect.Bottom; + ClipRect.Left = ScrollRect.Left; + ClipRect.Right = ScrollRect.Right; - destination.X = 0; - destination.Y = ScrollRect.Top - 1; + destination.X = 0; + destination.Y = ScrollRect.Top - 1; - Fill.Attributes = ConsoleInfo.wAttributes; - Fill.Char.AsciiChar = ' '; + Fill.Attributes = consoleInfo.wAttributes; + Fill.Char.AsciiChar = ' '; - BOOL bRet = ScrollConsoleScreenBuffer( hOutputConsole, - &ScrollRect, - NULL, - destination, - &Fill - ); + BOOL bRet = ScrollConsoleScreenBuffer(hOutputConsole, + &ScrollRect, + NULL, + destination, + &Fill + ); } -void ConClearBOLine() +void +ConClearBOLine() { - DWORD dwWritten; - COORD Coord ; - CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo; + DWORD dwWritten; + COORD Coord; + CONSOLE_SCREEN_BUFFER_INFO consoleInfo; - if (!GetConsoleScreenBufferInfo(hOutputConsole, &ConsoleInfo)) - return; + if (!GetConsoleScreenBufferInfo(hOutputConsole, &consoleInfo)) + return; - Coord.X = 0; - Coord.Y = (short)(ConGetCursorY()); - FillConsoleOutputAttribute(hOutputConsole, ConsoleInfo.wAttributes, - (DWORD)(ConGetCursorX()), - Coord, &dwWritten); - FillConsoleOutputCharacter(hOutputConsole, ' ', - (DWORD)(ConGetCursorX()), - Coord, &dwWritten); + Coord.X = 0; + Coord.Y = (short)(ConGetCursorY()); + FillConsoleOutputAttribute(hOutputConsole, consoleInfo.wAttributes, + (DWORD)(ConGetCursorX()), + Coord, &dwWritten); + FillConsoleOutputCharacter(hOutputConsole, ' ', + (DWORD)(ConGetCursorX()), + Coord, &dwWritten); } -void ConSetCursorPosition(int x, int y) +void +ConSetCursorPosition(int x, int y) { - CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo; - COORD Coord; - int rc; + CONSOLE_SCREEN_BUFFER_INFO consoleInfo; + COORD Coord; + int rc; - if (!GetConsoleScreenBufferInfo(hOutputConsole, &ConsoleInfo)) - return; + if (!GetConsoleScreenBufferInfo(hOutputConsole, &consoleInfo)) + return; - Coord.X = (short)(x); - Coord.Y = (short)(y); + Coord.X = (short)(x); + Coord.Y = (short)(y); - if ((y > ConsoleInfo.dwSize.Y - 1) && y > LastCursorY) { - for(int n = LastCursorY; n < y; n++) - GoToNextLine(); - } + if ((y > consoleInfo.dwSize.Y - 1) && y > LastCursorY) { + for (int n = LastCursorY; n < y; n++) + GoToNextLine(); + } - if (y >= ConsoleInfo.dwSize.Y) { - Coord.Y = ConsoleInfo.dwSize.Y - 1; - } + if (y >= consoleInfo.dwSize.Y) { + Coord.Y = consoleInfo.dwSize.Y - 1; + } - if (!SetConsoleCursorPosition(hOutputConsole, Coord)) - rc = GetLastError(); + if (!SetConsoleCursorPosition(hOutputConsole, Coord)) + rc = GetLastError(); - LastCursorX = x; - LastCursorY = y; + LastCursorX = x; + LastCursorY = y; } -BOOL ConChangeCursor( CONSOLE_CURSOR_INFO *pCursorInfo ) +BOOL +ConChangeCursor(CONSOLE_CURSOR_INFO *pCursorInfo) { - return SetConsoleCursorInfo( hOutputConsole, pCursorInfo ); + return SetConsoleCursorInfo(hOutputConsole, pCursorInfo); } -int ConGetCursorX() +int +ConGetCursorX() { - CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo; + CONSOLE_SCREEN_BUFFER_INFO consoleInfo; - if (!GetConsoleScreenBufferInfo(hOutputConsole, &ConsoleInfo)) - return 0; + if (!GetConsoleScreenBufferInfo(hOutputConsole, &consoleInfo)) + return 0; - return ConsoleInfo.dwCursorPosition.X; + return consoleInfo.dwCursorPosition.X; } -int ConGetCursorY() +int +ConGetCursorY() { - CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo; + CONSOLE_SCREEN_BUFFER_INFO consoleInfo; - if (!GetConsoleScreenBufferInfo(hOutputConsole, &ConsoleInfo)) - { - return 0; - } + if (!GetConsoleScreenBufferInfo(hOutputConsole, &consoleInfo)) + return 0; - return (ConsoleInfo.dwCursorPosition.Y - ConsoleInfo.srWindow.Top); + return (consoleInfo.dwCursorPosition.Y - consoleInfo.srWindow.Top); } -int ConGetCursorInBufferY() +int +ConGetCursorInBufferY() { - CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo; + CONSOLE_SCREEN_BUFFER_INFO consoleInfo; - if (!GetConsoleScreenBufferInfo(hOutputConsole, &ConsoleInfo)) - { - return 0; - } + if (!GetConsoleScreenBufferInfo(hOutputConsole, &consoleInfo)) + return 0; - return (ConsoleInfo.dwCursorPosition.Y); + return (consoleInfo.dwCursorPosition.Y); } -void ConMoveCursorPosition(int x, int y) +void +ConMoveCursorPosition(int x, int y) { - CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo; - COORD Coord; + CONSOLE_SCREEN_BUFFER_INFO consoleInfo; + COORD Coord; - if (!GetConsoleScreenBufferInfo(hOutputConsole, &ConsoleInfo)) - return; + if (!GetConsoleScreenBufferInfo(hOutputConsole, &consoleInfo)) + return; - Coord.X = (short)(ConsoleInfo.dwCursorPosition.X + x); - Coord.Y = (short)(ConsoleInfo.dwCursorPosition.Y + y); + Coord.X = (short)(consoleInfo.dwCursorPosition.X + x); + Coord.Y = (short)(consoleInfo.dwCursorPosition.Y + y); - SetConsoleCursorPosition(hOutputConsole, Coord); + SetConsoleCursorPosition(hOutputConsole, Coord); } -void ConGetRelativeCursorPosition(int *x, int *y) +void +ConGetRelativeCursorPosition(int *x, int *y) { - CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo; + CONSOLE_SCREEN_BUFFER_INFO consoleInfo; - if (!GetConsoleScreenBufferInfo(hOutputConsole, &ConsoleInfo)) - return; + if (!GetConsoleScreenBufferInfo(hOutputConsole, &consoleInfo)) + return; - *x -= ConsoleInfo.srWindow.Left; - *y -= ConsoleInfo.srWindow.Top; + *x -= consoleInfo.srWindow.Left; + *y -= consoleInfo.srWindow.Top; } -void ConDeleteChars(int n) +void +ConDeleteChars(int n) { - CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo; - COORD Coord; - CHAR_INFO chiBuffer[256]; // 1 row, 256 characters - SMALL_RECT sr; - COORD Temp; - int result; + CONSOLE_SCREEN_BUFFER_INFO consoleInfo; + COORD coord; + CHAR_INFO chiBuffer[256]; // 1 row, 256 characters + SMALL_RECT sr; + COORD temp; + int result; - if (!GetConsoleScreenBufferInfo(hOutputConsole, &ConsoleInfo)) - return; + if (!GetConsoleScreenBufferInfo(hOutputConsole, &consoleInfo)) + return; - Coord.X = (short)(ConsoleInfo.dwCursorPosition.X); - Coord.Y = (short)(ConsoleInfo.dwCursorPosition.Y); + coord.X = (short)(consoleInfo.dwCursorPosition.X); + coord.Y = (short)(consoleInfo.dwCursorPosition.Y); - sr.Left = Coord.X + n; - sr.Top = Coord.Y; - sr.Bottom = Coord.Y; - sr.Right = ConsoleInfo.srWindow.Right; + sr.Left = coord.X + n; + sr.Top = coord.Y; + sr.Bottom = coord.Y; + sr.Right = consoleInfo.srWindow.Right; - Temp.X = 256; - Temp.Y = 1; - result = ReadConsoleOutput( hOutputConsole, // handle of a console screen buffer - (PCHAR_INFO)chiBuffer, // address of buffer that receives data - Temp, // column-row size of destination buffer - ZeroCoord, // upper-left cell to write to - &sr // address of rectangle to read from - ); - ConClearEOLine(); + temp.X = 256; + temp.Y = 1; + result = ReadConsoleOutput(hOutputConsole, /* console screen buffer handle */ + (PCHAR_INFO)chiBuffer, /* address of buffer that receives data */ + temp, /* column-row size of destination buffer */ + ZeroCoord, /* upper-left cell to write to */ + &sr /* address of rectangle to read from */ + ); + ConClearEOLine(); - sr.Left = Coord.X; - Temp.X = 256; - Temp.Y = 1; + sr.Left = coord.X; + temp.X = 256; + temp.Y = 1; - sr.Right -= n; - result = WriteConsoleOutput(hOutputConsole,(PCHAR_INFO)chiBuffer,Temp, ZeroCoord, &sr); + sr.Right -= n; + result = WriteConsoleOutput(hOutputConsole, (PCHAR_INFO)chiBuffer, temp, ZeroCoord, &sr); } -SCREEN_HANDLE ConSaveScreenHandle( SCREEN_HANDLE hScreen ) +SCREEN_HANDLE +ConSaveScreenHandle(SCREEN_HANDLE hScreen) { - CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo; + CONSOLE_SCREEN_BUFFER_INFO consoleInfo; + PSCREEN_RECORD pScreenRec = (PSCREEN_RECORD)hScreen; + int result, width, height; - PSCREEN_RECORD pScreenRec = (PSCREEN_RECORD)hScreen; + if (hOutputConsole == NULL) + return NULL; - int result, width,height; + if (!GetConsoleScreenBufferInfo(hOutputConsole, &consoleInfo)) + return (NULL); - if ( hOutputConsole == NULL ) - return NULL; + if (pScreenRec == NULL) { + pScreenRec = (PSCREEN_RECORD)malloc(sizeof(SCREEN_RECORD)); + pScreenRec->pScreenBuf = NULL; + } - if (!GetConsoleScreenBufferInfo(hOutputConsole, &ConsoleInfo)) - return (NULL); + pScreenRec->srWindowRect = consoleInfo.srWindow; + width = consoleInfo.srWindow.Right - consoleInfo.srWindow.Left + 1; + height = consoleInfo.srWindow.Bottom - consoleInfo.srWindow.Top + 1; + pScreenRec->ScreenSize.X = width; + pScreenRec->ScreenSize.Y = height; + pScreenRec->ScreenCursor.X = consoleInfo.dwCursorPosition.X - consoleInfo.srWindow.Left; + pScreenRec->ScreenCursor.Y = consoleInfo.dwCursorPosition.Y - consoleInfo.srWindow.Top; - if (pScreenRec == NULL){ - pScreenRec = (PSCREEN_RECORD)malloc(sizeof(SCREEN_RECORD)); - pScreenRec->pScreenBuf = NULL; - } - - pScreenRec->srWindowRect = ConsoleInfo.srWindow; - width = ConsoleInfo.srWindow.Right - ConsoleInfo.srWindow.Left + 1; - height = ConsoleInfo.srWindow.Bottom - ConsoleInfo.srWindow.Top + 1; - pScreenRec->ScreenSize.X = width; - pScreenRec->ScreenSize.Y = height; - pScreenRec->ScreenCursor.X = ConsoleInfo.dwCursorPosition.X-ConsoleInfo.srWindow.Left; - pScreenRec->ScreenCursor.Y = ConsoleInfo.dwCursorPosition.Y-ConsoleInfo.srWindow.Top; + if (pScreenRec->pScreenBuf == NULL) + pScreenRec->pScreenBuf = (PCHAR_INFO)malloc(sizeof(CHAR_INFO) * width * height); - if (pScreenRec->pScreenBuf == NULL){ - pScreenRec->pScreenBuf = (PCHAR_INFO)malloc( sizeof(CHAR_INFO) * width * height ); - } + if (!pScreenRec->pScreenBuf) { + if (pScreenRec != (PSCREEN_RECORD)hScreen) + free(pScreenRec); + + return NULL; + } - if ( !pScreenRec->pScreenBuf ) - { - if ( pScreenRec != (PSCREEN_RECORD)hScreen ) { - free(pScreenRec); - } - return NULL; - } + result = ReadConsoleOutput(hOutputConsole, /* console screen buffer handle */ + (PCHAR_INFO)(pScreenRec->pScreenBuf),/* address of buffer that receives data */ + pScreenRec->ScreenSize, /* column-row size of destination buffer */ + ZeroCoord, /* upper-left cell to write to */ + &consoleInfo.srWindow /* address of rectangle to read from */ + ); - result = ReadConsoleOutput( hOutputConsole, // handle of a console screen buffer - (PCHAR_INFO)(pScreenRec->pScreenBuf), // address of buffer that receives data - pScreenRec->ScreenSize, // column-row size of destination buffer - ZeroCoord, // upper-left cell to write to - &ConsoleInfo.srWindow // address of rectangle to read from - ); - - return((SCREEN_HANDLE)pScreenRec); + return((SCREEN_HANDLE)pScreenRec); } - -BOOL ConRestoreScreenHandle( SCREEN_HANDLE hScreen ) +BOOL +ConRestoreScreenHandle(SCREEN_HANDLE hScreen) { - BOOL fOkay = FALSE; - CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo; - COORD beginOfScreen = { 0, 0 }; - PCHAR_INFO pSavedCharInfo; - DWORD dwWritten; - PSCREEN_RECORD pScreenRec = (PSCREEN_RECORD)hScreen; - int width, height; + BOOL fOkay = FALSE; + CONSOLE_SCREEN_BUFFER_INFO consoleInfo; + COORD beginOfScreen = { 0, 0 }; + PCHAR_INFO pSavedCharInfo; + DWORD dwWritten; + PSCREEN_RECORD pScreenRec = (PSCREEN_RECORD)hScreen; + int width, height; - if ( hOutputConsole == NULL ) - return FALSE; + if (hOutputConsole == NULL) + return FALSE; - if (!GetConsoleScreenBufferInfo(hOutputConsole, &ConsoleInfo)) - return (FALSE); + if (!GetConsoleScreenBufferInfo(hOutputConsole, &consoleInfo)) + return (FALSE); - width = ConsoleInfo.srWindow.Right - ConsoleInfo.srWindow.Left + 1; - height = ConsoleInfo.srWindow.Bottom - ConsoleInfo.srWindow.Top + 1; - - beginOfScreen.X = ConsoleInfo.srWindow.Left; - beginOfScreen.Y = ConsoleInfo.srWindow.Top; - FillConsoleOutputCharacter(hOutputConsole, ' ', (DWORD)width*height, - beginOfScreen, &dwWritten); + width = consoleInfo.srWindow.Right - consoleInfo.srWindow.Left + 1; + height = consoleInfo.srWindow.Bottom - consoleInfo.srWindow.Top + 1; - pSavedCharInfo = (PCHAR_INFO)(pScreenRec->pScreenBuf); - SetConsoleTextAttribute(hOutputConsole, pSavedCharInfo->Attributes); + beginOfScreen.X = consoleInfo.srWindow.Left; + beginOfScreen.Y = consoleInfo.srWindow.Top; + FillConsoleOutputCharacter(hOutputConsole, ' ', (DWORD)width*height, beginOfScreen, &dwWritten); - FillConsoleOutputAttribute(hOutputConsole, pSavedCharInfo->Attributes, - (DWORD)width*height, - beginOfScreen, &dwWritten); + pSavedCharInfo = (PCHAR_INFO)(pScreenRec->pScreenBuf); + SetConsoleTextAttribute(hOutputConsole, pSavedCharInfo->Attributes); - fOkay = WriteConsoleOutput( hOutputConsole, // handle to a console screen buffer - (PCHAR_INFO)(pScreenRec->pScreenBuf), // pointer to buffer with data to write - pScreenRec->ScreenSize, // column-row size of source buffer - ZeroCoord, // upper-left cell to write from - &ConsoleInfo.srWindow // pointer to rectangle to write to - ); + FillConsoleOutputAttribute(hOutputConsole, pSavedCharInfo->Attributes, + (DWORD)width*height, + beginOfScreen, &dwWritten); - SetConsoleWindowInfo(hOutputConsole,TRUE,&pScreenRec->srWindowRect); - - ConSetCursorPosition( pScreenRec->ScreenCursor.X, pScreenRec->ScreenCursor.Y ); - - return fOkay; + fOkay = WriteConsoleOutput(hOutputConsole, /* handle to a console screen buffer */ + (PCHAR_INFO)(pScreenRec->pScreenBuf), /* pointer to buffer with data to write */ + pScreenRec->ScreenSize, /* column-row size of source buffer */ + ZeroCoord, /* upper-left cell to write from */ + &consoleInfo.srWindow /* pointer to rectangle to write to */ + ); + + SetConsoleWindowInfo(hOutputConsole, TRUE, &pScreenRec->srWindowRect); + ConSetCursorPosition(pScreenRec->ScreenCursor.X, pScreenRec->ScreenCursor.Y); + + return fOkay; } -BOOL ConRestoreScreenColors( ) +BOOL +ConRestoreScreenColors() { - SCREEN_HANDLE hScreen = pSavedScreenRec; - BOOL fOkay = FALSE; - CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo; - COORD beginOfScreen = { 0, 0 }; - PCHAR_INFO pSavedCharInfo; - DWORD dwWritten; - PSCREEN_RECORD pScreenRec = (PSCREEN_RECORD)hScreen; + SCREEN_HANDLE hScreen = pSavedScreenRec; + BOOL fOkay = FALSE; + CONSOLE_SCREEN_BUFFER_INFO consoleInfo; + COORD beginOfScreen = { 0, 0 }; + PCHAR_INFO pSavedCharInfo; + DWORD dwWritten; + PSCREEN_RECORD pScreenRec = (PSCREEN_RECORD)hScreen; - if ( hOutputConsole == NULL ) - return FALSE; + if (hOutputConsole == NULL) + return FALSE; - if ( pSavedScreen == NULL ) - return FALSE; + if (pSavedScreen == NULL) + return FALSE; - if (!GetConsoleScreenBufferInfo(hOutputConsole, &ConsoleInfo)) - return (FALSE); + if (!GetConsoleScreenBufferInfo(hOutputConsole, &consoleInfo)) + return (FALSE); - beginOfScreen.X = ConsoleInfo.srWindow.Left; - beginOfScreen.Y = ConsoleInfo.srWindow.Top; + beginOfScreen.X = consoleInfo.srWindow.Left; + beginOfScreen.Y = consoleInfo.srWindow.Top; - FillConsoleOutputCharacter(hOutputConsole, ' ', - (DWORD)pScreenRec->ScreenSize.X*pScreenRec->ScreenSize.Y, - beginOfScreen, &dwWritten); + FillConsoleOutputCharacter(hOutputConsole, ' ', + (DWORD)pScreenRec->ScreenSize.X*pScreenRec->ScreenSize.Y, + beginOfScreen, &dwWritten); - pSavedCharInfo = (PCHAR_INFO)(pScreenRec->pScreenBuf); - SetConsoleTextAttribute(hOutputConsole, pSavedCharInfo->Attributes); + pSavedCharInfo = (PCHAR_INFO)(pScreenRec->pScreenBuf); + SetConsoleTextAttribute(hOutputConsole, pSavedCharInfo->Attributes); - FillConsoleOutputAttribute(hOutputConsole, pSavedCharInfo->Attributes, - (DWORD)pScreenRec->ScreenSize.X*pScreenRec->ScreenSize.Y, - beginOfScreen, &dwWritten); + FillConsoleOutputAttribute(hOutputConsole, pSavedCharInfo->Attributes, + (DWORD)pScreenRec->ScreenSize.X*pScreenRec->ScreenSize.Y, + beginOfScreen, &dwWritten); - return fOkay; + return fOkay; } -void ConDeleteScreenHandle( SCREEN_HANDLE hScreen ) +void +ConDeleteScreenHandle(SCREEN_HANDLE hScreen) { - PSCREEN_RECORD pScreenRec = (PSCREEN_RECORD)hScreen; - - free(pScreenRec->pScreenBuf); - free(pScreenRec); + PSCREEN_RECORD pScreenRec = (PSCREEN_RECORD)hScreen; + free(pScreenRec->pScreenBuf); + free(pScreenRec); } -/* ************************************************************ */ -/* Function: ConRestoreScreen */ -/* Restores Previous Saved screen info and buffer */ -/* ************************************************************ */ -BOOL ConRestoreScreen( void ) +/* Restores Previous Saved screen info and buffer */ +BOOL +ConRestoreScreen(void) { - return ConRestoreScreenHandle(pSavedScreenRec); + return ConRestoreScreenHandle(pSavedScreenRec); } -void ConRestoreViewRect( void ) +/* Saves current screen info and buffer */ +BOOL +ConSaveScreen(void) { - //SetConsoleWindowInfo(hOutputConsole,TRUE,&SavedViewRect); + pSavedScreenRec = (PSCREEN_RECORD)ConSaveScreenHandle(pSavedScreenRec); + return TRUE; } -/* ************************************************************ */ -/* Function: ConSaveScreen */ -/* Saves current screen info and buffer */ -/* ************************************************************ */ -BOOL ConSaveScreen( void ) +void +ConSaveViewRect(void) { - pSavedScreenRec = (PSCREEN_RECORD)ConSaveScreenHandle(pSavedScreenRec); - return TRUE; + CONSOLE_SCREEN_BUFFER_INFO csbi; + + if (!GetConsoleScreenBufferInfo(hOutputConsole, &csbi)) + return; + + SavedViewRect = csbi.srWindow; } -void ConSaveViewRect( void ) +BOOL +ConIsRedirected(HANDLE hInput) { - CONSOLE_SCREEN_BUFFER_INFO csbi; - - if (!GetConsoleScreenBufferInfo(hOutputConsole, &csbi)) - return; - - SavedViewRect = csbi.srWindow; - + DWORD dwMode; + return !GetConsoleMode(hInput, &dwMode); } -BOOL ConIsRedirected(HANDLE hInput) +HANDLE +GetConsoleOutputHandle() { - DWORD dwMode; + SECURITY_ATTRIBUTES sa; - return !GetConsoleMode(hInput, &dwMode); + sa.nLength = sizeof(SECURITY_ATTRIBUTES); + sa.lpSecurityDescriptor = NULL; + sa.bInheritHandle = TRUE; + + HANDLE hTemp = GetStdHandle(STD_OUTPUT_HANDLE); + + if (ConIsRedirected(hTemp)) + hTemp = CreateFile(TEXT("CONOUT$"), GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_WRITE | FILE_SHARE_READ, + &sa, OPEN_EXISTING, 0, NULL); + + return hTemp; } -HANDLE GetConsoleOutputHandle() +HANDLE +GetConsoleInputHandle() { - SECURITY_ATTRIBUTES sa; + SECURITY_ATTRIBUTES sa; - sa.nLength = sizeof(SECURITY_ATTRIBUTES); - sa.lpSecurityDescriptor = NULL; - sa.bInheritHandle = TRUE; + sa.nLength = sizeof(SECURITY_ATTRIBUTES); + sa.lpSecurityDescriptor = NULL; + sa.bInheritHandle = TRUE; - HANDLE hTemp = GetStdHandle(STD_OUTPUT_HANDLE); + HANDLE hTemp = GetStdHandle(STD_INPUT_HANDLE); - if (ConIsRedirected(hTemp)) - { - hTemp = CreateFile(TEXT("CONOUT$"), GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_WRITE | FILE_SHARE_READ, - &sa, OPEN_EXISTING, 0, NULL); - } + if (ConIsRedirected(hTemp)) + hTemp = CreateFile(TEXT("CONIN$"), GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_WRITE | FILE_SHARE_READ, + &sa, OPEN_EXISTING, 0, NULL); - return hTemp; + return hTemp; } -HANDLE GetConsoleInputHandle() +void +ConSaveWindowsState(void) { - SECURITY_ATTRIBUTES sa; + CONSOLE_SCREEN_BUFFER_INFOEX csbiex; + csbiex.cbSize = sizeof(CONSOLE_SCREEN_BUFFER_INFOEX); - sa.nLength = sizeof(SECURITY_ATTRIBUTES); - sa.lpSecurityDescriptor = NULL; - sa.bInheritHandle = TRUE; + if (!GetConsoleScreenBufferInfoEx(hOutputConsole, &csbiex)) + return; - HANDLE hTemp = GetStdHandle(STD_INPUT_HANDLE); - - if (ConIsRedirected(hTemp)) - { - hTemp = CreateFile(TEXT("CONIN$"), GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_WRITE | FILE_SHARE_READ, - &sa, OPEN_EXISTING, 0, NULL); - } - - return hTemp; -} - -void ConSaveWindowsState(void) -{ - CONSOLE_SCREEN_BUFFER_INFOEX csbiex; - csbiex.cbSize = sizeof(CONSOLE_SCREEN_BUFFER_INFOEX); - - if (!GetConsoleScreenBufferInfoEx(hOutputConsole, &csbiex)) - return; - - SavedWindowState = csbiex; + SavedWindowState = csbiex; } diff --git a/contrib/win32/win32compat/shell-host.c b/contrib/win32/win32compat/shell-host.c index cd4de126a..37f422565 100644 --- a/contrib/win32/win32compat/shell-host.c +++ b/contrib/win32/win32compat/shell-host.c @@ -207,7 +207,8 @@ SendKeyStroke(HANDLE hInput, int keyStroke, char character) } void -ProcessIncomingKeys(char * ansikey) { +ProcessIncomingKeys(char * ansikey) +{ int nKey = 0; int index = ARRAYSIZE(keys); @@ -228,7 +229,8 @@ ProcessIncomingKeys(char * ansikey) { * VT output routines */ void -SendLF(HANDLE hInput) { +SendLF(HANDLE hInput) +{ DWORD wr = 0; if (bUseAnsiEmulation) @@ -236,7 +238,8 @@ SendLF(HANDLE hInput) { } void -SendClearScreen(HANDLE hInput) { +SendClearScreen(HANDLE hInput) +{ DWORD wr = 0; if (bUseAnsiEmulation) @@ -244,7 +247,8 @@ SendClearScreen(HANDLE hInput) { } void -SendClearScreenFromCursor(HANDLE hInput) { +SendClearScreenFromCursor(HANDLE hInput) +{ DWORD wr = 0; if (bUseAnsiEmulation) @@ -252,7 +256,8 @@ SendClearScreenFromCursor(HANDLE hInput) { } void -SendHideCursor(HANDLE hInput) { +SendHideCursor(HANDLE hInput) +{ DWORD wr = 0; if (bUseAnsiEmulation) @@ -260,7 +265,8 @@ SendHideCursor(HANDLE hInput) { } void -SendShowCursor(HANDLE hInput) { +SendShowCursor(HANDLE hInput) +{ DWORD wr = 0; if (bUseAnsiEmulation) @@ -268,7 +274,8 @@ SendShowCursor(HANDLE hInput) { } void -SendCursorPositionRequest(HANDLE hInput) { +SendCursorPositionRequest(HANDLE hInput) +{ DWORD wr = 0; if (bUseAnsiEmulation) @@ -276,7 +283,8 @@ SendCursorPositionRequest(HANDLE hInput) { } void -SendSetCursor(HANDLE hInput, int X, int Y) { +SendSetCursor(HANDLE hInput, int X, int Y) +{ DWORD wr = 0; DWORD out = 0; char formatted_output[255]; @@ -287,7 +295,8 @@ SendSetCursor(HANDLE hInput, int X, int Y) { } void -SendVerticalScroll(HANDLE hInput, int lines) { +SendVerticalScroll(HANDLE hInput, int lines) +{ DWORD wr = 0; DWORD out = 0; char formatted_output[255]; @@ -303,7 +312,8 @@ SendVerticalScroll(HANDLE hInput, int lines) { } void -SendHorizontalScroll(HANDLE hInput, int cells) { +SendHorizontalScroll(HANDLE hInput, int cells) +{ DWORD wr = 0; DWORD out = 0; char formatted_output[255]; @@ -315,7 +325,8 @@ SendHorizontalScroll(HANDLE hInput, int cells) { } void -SendCharacter(HANDLE hInput, WORD attributes, wchar_t character) { +SendCharacter(HANDLE hInput, WORD attributes, wchar_t character) +{ DWORD wr = 0; DWORD out = 0; DWORD current = 0; @@ -403,7 +414,8 @@ SendCharacter(HANDLE hInput, WORD attributes, wchar_t character) { } void -SendBuffer(HANDLE hInput, CHAR_INFO *buffer, DWORD bufferSize) { +SendBuffer(HANDLE hInput, CHAR_INFO *buffer, DWORD bufferSize) +{ if (bufferSize <= 0) return; @@ -412,14 +424,16 @@ SendBuffer(HANDLE hInput, CHAR_INFO *buffer, DWORD bufferSize) { } void -CalculateAndSetCursor(HANDLE hInput, UINT aboveTopLine, UINT viewPortHeight, UINT x, UINT y) { +CalculateAndSetCursor(HANDLE hInput, UINT aboveTopLine, UINT viewPortHeight, UINT x, UINT y) +{ SendSetCursor(pipe_out, x + 1, y + 1); currentLine = y; } void -SizeWindow(HANDLE hInput) { +SizeWindow(HANDLE hInput) +{ SMALL_RECT srWindowRect; COORD coordScreen; BOOL bSuccess = FALSE; @@ -472,7 +486,8 @@ SizeWindow(HANDLE hInput) { } DWORD WINAPI -MonitorChild(_In_ LPVOID lpParameter) { +MonitorChild(_In_ LPVOID lpParameter) +{ WaitForSingleObject(child, INFINITE); GetExitCodeProcess(child, &child_exit_code); PostThreadMessage(hostThreadId, WM_APPEXIT, 0, 0); @@ -480,7 +495,8 @@ MonitorChild(_In_ LPVOID lpParameter) { } DWORD -ProcessEvent(void *p) { +ProcessEvent(void *p) +{ char f[255]; wchar_t chUpdate; WORD wAttributes; @@ -689,7 +705,8 @@ ProcessEvent(void *p) { } DWORD WINAPI -ProcessEventQueue(LPVOID p) { +ProcessEventQueue(LPVOID p) +{ static SHORT lastX = 0; static SHORT lastY = 0; @@ -747,7 +764,8 @@ ProcessEventQueue(LPVOID p) { } void -QueueEvent(DWORD event, HWND hwnd, LONG idObject, LONG idChild) { +QueueEvent(DWORD event, HWND hwnd, LONG idObject, LONG idChild) +{ consoleEvent* current = NULL; EnterCriticalSection(&criticalSection); @@ -786,7 +804,8 @@ QueueEvent(DWORD event, HWND hwnd, LONG idObject, LONG idChild) { } DWORD WINAPI -ProcessPipes(LPVOID p) { +ProcessPipes(LPVOID p) +{ BOOL ret; DWORD dwStatus; @@ -838,12 +857,14 @@ ConsoleEventProc(HWINEVENTHOOK hWinEventHook, LONG idObject, LONG idChild, DWORD dwEventThread, - DWORD dwmsEventTime) { + DWORD dwmsEventTime) +{ QueueEvent(event, hwnd, idObject, idChild); } DWORD -ProcessMessages(void* p) { +ProcessMessages(void* p) +{ BOOL ret; DWORD dwMode; DWORD dwStatus; @@ -895,7 +916,8 @@ cleanup: } int -start_with_pty(int ac, wchar_t **av) { +start_with_pty(int ac, wchar_t **av) +{ STARTUPINFO si; PROCESS_INFORMATION pi; wchar_t cmd[MAX_CMD_LEN]; @@ -1015,7 +1037,8 @@ HANDLE child_pipe_read; HANDLE child_pipe_write; DWORD WINAPI -MonitorChild_nopty( _In_ LPVOID lpParameter) { +MonitorChild_nopty( _In_ LPVOID lpParameter) +{ WaitForSingleObject(child, INFINITE); GetExitCodeProcess(child, &child_exit_code); CloseHandle(pipe_in); @@ -1023,7 +1046,8 @@ MonitorChild_nopty( _In_ LPVOID lpParameter) { } int -start_withno_pty(int ac, wchar_t **av) { +start_withno_pty(int ac, wchar_t **av) +{ STARTUPINFO si; PROCESS_INFORMATION pi; wchar_t cmd[MAX_CMD_LEN]; @@ -1157,7 +1181,8 @@ cleanup: } int -wmain(int ac, wchar_t **av) { +wmain(int ac, wchar_t **av) +{ /* create job to hold all child processes */ HANDLE job = CreateJobObject(NULL, NULL); JOBOBJECT_EXTENDED_LIMIT_INFORMATION job_info; diff --git a/contrib/win32/win32compat/termio.c b/contrib/win32/win32compat/termio.c index 4708fdc2a..967b20e97 100644 --- a/contrib/win32/win32compat/termio.c +++ b/contrib/win32/win32compat/termio.c @@ -53,7 +53,8 @@ static struct io_status read_status, write_status; /* APC that gets queued on main thread when a sync Read completes on worker thread */ static VOID CALLBACK -ReadAPCProc(_In_ ULONG_PTR dwParam) { +ReadAPCProc(_In_ ULONG_PTR dwParam) +{ struct w32_io* pio = (struct w32_io*)dwParam; debug3("TermRead CB - io:%p, bytes: %d, pending: %d, error: %d", pio, read_status.transferred, pio->read_details.pending, read_status.error); @@ -68,7 +69,8 @@ ReadAPCProc(_In_ ULONG_PTR dwParam) { /* Read worker thread */ static DWORD WINAPI -ReadConsoleThread(_In_ LPVOID lpParameter) { +ReadConsoleThread(_In_ LPVOID lpParameter) +{ int nBytesReturned = 0; struct w32_io* pio = (struct w32_io*)lpParameter; @@ -91,7 +93,8 @@ ReadConsoleThread(_In_ LPVOID lpParameter) { /* Initiates read on tty */ int -termio_initiate_read(struct w32_io* pio) { +termio_initiate_read(struct w32_io* pio) +{ HANDLE read_thread; debug3("TermRead initiate io:%p", pio); @@ -118,7 +121,8 @@ termio_initiate_read(struct w32_io* pio) { /* APC that gets queued on main thread when a sync Write completes on worker thread */ static VOID CALLBACK -WriteAPCProc(_In_ ULONG_PTR dwParam) { +WriteAPCProc(_In_ ULONG_PTR dwParam) +{ struct w32_io* pio = (struct w32_io*)dwParam; debug3("TermWrite CB - io:%p, bytes: %d, pending: %d, error: %d", pio, write_status.transferred, pio->write_details.pending, write_status.error); @@ -134,7 +138,8 @@ WriteAPCProc(_In_ ULONG_PTR dwParam) { /* Write worker thread */ static DWORD WINAPI -WriteThread(_In_ LPVOID lpParameter) { +WriteThread(_In_ LPVOID lpParameter) +{ struct w32_io* pio = (struct w32_io*)lpParameter; char *respbuf = NULL; size_t resplen = 0; @@ -166,7 +171,8 @@ WriteThread(_In_ LPVOID lpParameter) { /* Initiates write on tty */ int -termio_initiate_write(struct w32_io* pio, DWORD num_bytes) { +termio_initiate_write(struct w32_io* pio, DWORD num_bytes) +{ HANDLE write_thread; debug3("TermWrite initiate io:%p", pio); memset(&write_status, 0, sizeof(write_status)); @@ -185,7 +191,8 @@ termio_initiate_write(struct w32_io* pio, DWORD num_bytes) { /* tty close */ int -termio_close(struct w32_io* pio) { +termio_close(struct w32_io* pio) +{ debug2("termio_close - pio:%p", pio); HANDLE h; CancelIoEx(WINHANDLE(pio), NULL); diff --git a/contrib/win32/win32compat/tncon.c b/contrib/win32/win32compat/tncon.c index 3dac83f61..6d6d81e31 100644 --- a/contrib/win32/win32compat/tncon.c +++ b/contrib/win32/win32compat/tncon.c @@ -79,7 +79,8 @@ void queue_terminal_window_change_event(); * a global buffer setup by ReadConsoleForTermEmul(). */ int -NetWriteString2(SOCKET sock, char* source, size_t len, int options) { +NetWriteString2(SOCKET sock, char* source, size_t len, int options) +{ while (len > 0) { if (glob_outlen >= glob_space) return glob_outlen; @@ -91,7 +92,8 @@ NetWriteString2(SOCKET sock, char* source, size_t len, int options) { } BOOL -DataAvailable(HANDLE h) { +DataAvailable(HANDLE h) +{ DWORD dwRet = WaitForSingleObject(h, INFINITE); if (dwRet == WAIT_OBJECT_0) return TRUE; @@ -101,7 +103,8 @@ DataAvailable(HANDLE h) { } int -ReadConsoleForTermEmul(HANDLE hInput, char *destin, int destinlen) { +ReadConsoleForTermEmul(HANDLE hInput, char *destin, int destinlen) +{ HANDLE hHandle[] = { hInput, NULL }; DWORD nHandle = 1; DWORD dwInput = 0; diff --git a/contrib/win32/win32compat/tnnet.c b/contrib/win32/win32compat/tnnet.c index 11955d061..9763010e0 100644 --- a/contrib/win32/win32compat/tnnet.c +++ b/contrib/win32/win32compat/tnnet.c @@ -45,7 +45,8 @@ * are hardcoded in the server and will be transformed to Windows Console commands. */ size_t -telProcessNetwork(char *buf, size_t len, unsigned char **respbuf, size_t *resplen) { +telProcessNetwork(char *buf, size_t len, unsigned char **respbuf, size_t *resplen) +{ unsigned char szBuffer[dwBuffer + 8]; unsigned char* pszNewHead = NULL; unsigned char* pszHead = NULL;