Cleaned up shell-host and terminal related code
This commit is contained in:
parent
ce03c08333
commit
73180c876d
|
@ -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 <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include "ansiprsr.h"
|
||||
|
@ -48,31 +41,26 @@
|
|||
#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
|
||||
/* 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
|
||||
/*
|
||||
* 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;
|
||||
|
@ -85,11 +73,11 @@ int bBkMode = 0;
|
|||
int bCharMode = 0;
|
||||
int ReportedX = 0;
|
||||
int ReportedY = 0;
|
||||
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];
|
||||
|
||||
|
@ -105,8 +93,6 @@ char cursor_report[255];
|
|||
#define MODE_LNM 0x0200
|
||||
#define MODE_IRM_INSERT 0x0400
|
||||
|
||||
int VTMode = 0;
|
||||
|
||||
#define MODE_CURSORAPP 0x0001
|
||||
#define MODE_ANSIVT52 0x0002
|
||||
#define MODE_COL132 0x0004
|
||||
|
@ -118,24 +104,26 @@ int VTMode = 0;
|
|||
#define MODE_APPMODE 0x0100
|
||||
#define MODE_LNM 0x0200
|
||||
|
||||
char *GetTerminalId()
|
||||
char *
|
||||
GetTerminalId()
|
||||
{
|
||||
return TERMINAL_ID;
|
||||
}
|
||||
|
||||
char * GetStatusReport()
|
||||
char *
|
||||
GetStatusReport()
|
||||
{
|
||||
return STATUS_REPORT;
|
||||
}
|
||||
|
||||
char * GetCursorPositionReport()
|
||||
char *
|
||||
GetCursorPositionReport()
|
||||
{
|
||||
DWORD wr = 0;
|
||||
DWORD out = 0;
|
||||
|
||||
out = _snprintf_s(cursor_report, sizeof(cursor_report), _TRUNCATE,
|
||||
CURSOR_REPORT_FORMAT_STRING, ConGetCursorY() + 1, ConGetCursorX() + 1);
|
||||
|
||||
if (out > 0) {
|
||||
return cursor_report;
|
||||
}
|
||||
|
@ -143,68 +131,65 @@ char * GetCursorPositionReport()
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void BufConvertToG2(char * pszBuffer, int length)
|
||||
void
|
||||
BufConvertToG2(char * pszBuffer, int length)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < length; i++)
|
||||
pszBuffer[i] = '|';
|
||||
//*(pszBuffer+i) += 20;
|
||||
}
|
||||
|
||||
|
||||
void GoToNextLine()
|
||||
{
|
||||
if (ConGetCursorY() >= (ConWindowSizeY()-1))
|
||||
void
|
||||
GoToNextLine()
|
||||
{
|
||||
if (ConGetCursorY() >= (ConWindowSizeY() - 1)) {
|
||||
ConScrollDown(ScrollTop, ScrollBottom);
|
||||
ConMoveCursorPosition(-ConGetCursorX(), 0);
|
||||
}
|
||||
else
|
||||
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)
|
||||
{
|
||||
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
|
||||
{
|
||||
/* 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.
|
||||
/* 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:
|
||||
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;
|
||||
|
||||
|
@ -215,16 +200,12 @@ unsigned char* ParseBuffer(unsigned char* pszBuffer, unsigned char* pszBufferEnd
|
|||
|
||||
case 8:
|
||||
pszBuffer++;
|
||||
if (!bAtEOLN)
|
||||
{
|
||||
if (!bAtEOLN) {
|
||||
CurrentX = ConGetCursorX();
|
||||
if (CurrentX == 0)
|
||||
{
|
||||
if (CurrentX == 0) {
|
||||
ConMoveCursorPosition(ScreenX - 1, -1);
|
||||
ConWriteString(" ", 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
ConClearNFromCursorLeft(1);
|
||||
ConMoveCursorPosition(-1, 0);
|
||||
}
|
||||
|
@ -276,23 +257,18 @@ unsigned char* ParseBuffer(unsigned char* pszBuffer, unsigned char* pszBufferEnd
|
|||
break;
|
||||
|
||||
case 27:
|
||||
if (pszBuffer < pszBufferEnd -1)
|
||||
{
|
||||
if (pszBuffer < pszBufferEnd - 1) {
|
||||
unsigned char * pszCurrent = pszBuffer + 1;
|
||||
unsigned char * pszNewCurrent = pszCurrent;
|
||||
|
||||
if (*pszCurrent == 27)
|
||||
{
|
||||
if (*pszCurrent == 27) {
|
||||
pszNewCurrent += ConWriteString((char *)pszCurrent, 1);
|
||||
return pszBuffer + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if (term_mode == TERM_ANSI)
|
||||
{
|
||||
pszNewCurrent = ParseANSI(pszCurrent, pszBufferEnd, respbuf, resplen);
|
||||
}
|
||||
}
|
||||
|
||||
if (pszNewCurrent > pszCurrent)
|
||||
pszBuffer = pszNewCurrent;
|
||||
}
|
||||
|
@ -312,19 +288,15 @@ unsigned char* ParseBuffer(unsigned char* pszBuffer, unsigned char* pszBufferEnd
|
|||
if (*pszCurrent > 127) {
|
||||
unsigned char nLead = *pszCurrent;
|
||||
nCharCount++;
|
||||
if ((nLead & 128) == 128) {
|
||||
if ((nLead & 128) == 128)
|
||||
pszCurrent++;
|
||||
}
|
||||
if ((nLead & 192) == 192) {
|
||||
if ((nLead & 192) == 192)
|
||||
pszCurrent++;
|
||||
}
|
||||
if ((nLead & 224) == 224) {
|
||||
if ((nLead & 224) == 224)
|
||||
pszCurrent++;
|
||||
}
|
||||
if ((nLead & 240) == 240) {
|
||||
if ((nLead & 240) == 240)
|
||||
pszCurrent++;
|
||||
}
|
||||
}
|
||||
else
|
||||
pszCurrent++;
|
||||
}
|
||||
|
@ -335,9 +307,7 @@ unsigned char* ParseBuffer(unsigned char* pszBuffer, unsigned char* pszBufferEnd
|
|||
pszBuffer += ConWriteString((char *)pszBuffer, (int)(pszCurrent - pszBuffer));
|
||||
|
||||
if ((CurrentX >= ScreenX) && AutoWrap && !(VTMode & MODE_CURSORAPP))
|
||||
{
|
||||
bAtEOLN = TRUE;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -346,7 +316,8 @@ unsigned char* ParseBuffer(unsigned char* pszBuffer, unsigned char* pszBufferEnd
|
|||
}
|
||||
|
||||
|
||||
unsigned char * GetNextChar(unsigned char *pszBuffer, unsigned char *pszBufferEnd)
|
||||
unsigned char *
|
||||
GetNextChar(unsigned char *pszBuffer, unsigned char *pszBufferEnd)
|
||||
{
|
||||
if (++pszBuffer > pszBufferEnd)
|
||||
return NULL;
|
||||
|
@ -354,10 +325,10 @@ unsigned char * GetNextChar(unsigned char *pszBuffer, unsigned char *pszBufferEn
|
|||
return pszBuffer;
|
||||
}
|
||||
|
||||
void ConSetExtendedMode(int iFunction, BOOL bEnable)
|
||||
{
|
||||
switch(iFunction)
|
||||
void
|
||||
ConSetExtendedMode(int iFunction, BOOL bEnable)
|
||||
{
|
||||
switch (iFunction) {
|
||||
case 1:
|
||||
if (bEnable) {
|
||||
VTMode |= MODE_CURSORAPP;
|
||||
|
@ -407,7 +378,7 @@ void ConSetExtendedMode(int iFunction, BOOL bEnable)
|
|||
else
|
||||
VTMode &= ~MODE_AUTOREPEAT;
|
||||
break;
|
||||
case 20: // LNM Mode CSI 20h
|
||||
case 20: /* LNM Mode CSI 20h */
|
||||
if (bEnable) {
|
||||
VTMode |= MODE_LNM;
|
||||
Parameters.nReceiveCRLF = ENUM_CRLF;
|
||||
|
@ -434,29 +405,25 @@ void ConSetExtendedMode(int iFunction, BOOL bEnable)
|
|||
|
||||
#define DIGI_MASK (MODE_CS0 | MODE_CS1 | MODE_CS2 | MODE_CS3 | MODE_CHAR)
|
||||
|
||||
unsigned char * ParseANSI(unsigned char * pszBuffer, unsigned char * pszBufferEnd, unsigned char **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;
|
||||
|
||||
if (pszCurrent == NULL || pszBufferEnd == NULL)
|
||||
return NULL;
|
||||
|
||||
fcompletion = 0;
|
||||
do
|
||||
{
|
||||
switch ((unsigned char) *pszCurrent)
|
||||
{
|
||||
// Delimiter
|
||||
case ';':
|
||||
do {
|
||||
switch ((unsigned char)*pszCurrent) {
|
||||
case ';': /* Delimiter */
|
||||
bDelimiter = TRUE;
|
||||
break;
|
||||
// Modifiers
|
||||
case '?': // Extended Mode
|
||||
/* Modifiers */
|
||||
case '?': /* Extended Mode */
|
||||
bMode |= MODE_EXT;
|
||||
break;
|
||||
case '(':
|
||||
|
@ -478,7 +445,7 @@ unsigned char * ParseANSI(unsigned char * pszBuffer, unsigned char * pszBufferEn
|
|||
bMode |= MODE_CHAR;
|
||||
break;
|
||||
|
||||
// Termination Options
|
||||
/* Termination Options */
|
||||
case 0:
|
||||
fcompletion = 1;
|
||||
break;
|
||||
|
@ -487,7 +454,7 @@ unsigned char * ParseANSI(unsigned char * pszBuffer, unsigned char * pszBufferEn
|
|||
fcompletion = 1;
|
||||
break;
|
||||
|
||||
case '<': // Character set
|
||||
case '<': /* Character set */
|
||||
fcompletion = 1;
|
||||
break;
|
||||
|
||||
|
@ -499,10 +466,10 @@ unsigned char * ParseANSI(unsigned char * pszBuffer, unsigned char * pszBufferEn
|
|||
fcompletion = 1;
|
||||
break;
|
||||
|
||||
case '^': // Private message
|
||||
case '^': /* Private message */
|
||||
/* while not stop */
|
||||
while (pszCurrent && pszCurrent < pszBufferEnd &&
|
||||
_strnicmp((const char *)pszCurrent, (const char *)VT_ST, strlen((const char *)VT_ST) ) ) // while not stop
|
||||
{
|
||||
_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++;
|
||||
|
@ -511,13 +478,8 @@ unsigned char * ParseANSI(unsigned char * pszBuffer, unsigned char * pszBufferEn
|
|||
fcompletion = 1;
|
||||
break;
|
||||
|
||||
case 'A': // Character Set change or Cursor Up
|
||||
if (bMode & MODE_CHAR)
|
||||
{
|
||||
}
|
||||
else if (bMode & MODE_BRK)
|
||||
{
|
||||
// Cursor UP
|
||||
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]);
|
||||
|
@ -525,14 +487,8 @@ unsigned char * ParseANSI(unsigned char * pszBuffer, unsigned char * pszBufferEn
|
|||
fcompletion = 1;
|
||||
break;
|
||||
|
||||
case 'B': // Character set change or Cursor down
|
||||
if (bMode & MODE_CHAR)
|
||||
{
|
||||
// Character Set
|
||||
}
|
||||
else if (bMode & MODE_BRK)
|
||||
{
|
||||
// Cursor DOWN
|
||||
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]);
|
||||
|
@ -540,107 +496,82 @@ unsigned char * ParseANSI(unsigned char * pszBuffer, unsigned char * pszBufferEn
|
|||
fcompletion = 1;
|
||||
break;
|
||||
|
||||
case 'C': // Character Set change or Cursor right
|
||||
if (bMode & MODE_CHAR)
|
||||
{
|
||||
// Character Set
|
||||
}
|
||||
else if (bMode & MODE_BRK)
|
||||
{
|
||||
// Cursor right
|
||||
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': // Cursor left
|
||||
if (bMode & MODE_BRK)
|
||||
{
|
||||
// Cursor left
|
||||
case 'D':
|
||||
if (bMode & MODE_BRK) { /* Cursor left */
|
||||
if (iParam[0] == 0)
|
||||
iParam[0] = 1;
|
||||
ConMoveCursorPosition(-iParam[0], 0);
|
||||
}
|
||||
else if (bMode == 0)
|
||||
{
|
||||
// Index
|
||||
} else if (bMode == 0) { /* Index */
|
||||
ConScrollDown(ScrollTop, ScrollBottom);
|
||||
}
|
||||
fcompletion = 1;
|
||||
bAtEOLN = FALSE;
|
||||
break;
|
||||
|
||||
case '=': // Application mode
|
||||
case '=': /* Application mode */
|
||||
VTMode |= MODE_APPMODE;
|
||||
fcompletion = 1;
|
||||
break;
|
||||
|
||||
case '>': // Numeric mode
|
||||
case '>': /* Numeric mode */
|
||||
VTMode &= ~MODE_APPMODE;
|
||||
fcompletion = 1;
|
||||
break;
|
||||
|
||||
case '%': // Character set definitions
|
||||
case '%': /* Character set definitions */
|
||||
fcompletion = 1;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
if (bMode & MODE_EXT)
|
||||
{
|
||||
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) {
|
||||
case 'l': /* ^[?25h */
|
||||
if (bMode & MODE_EXT) {
|
||||
if (iParam[0] == 4 && iParam[1] == 7)
|
||||
ConRestoreScreen();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (iParam[0] == 4) {
|
||||
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)
|
||||
} 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){
|
||||
if (iParam[0] == 4)
|
||||
VTMode &= ~MODE_IRM_INSERT;
|
||||
}
|
||||
}
|
||||
fcompletion = 1;
|
||||
break;
|
||||
|
||||
case 'L':
|
||||
if (iParam[0])
|
||||
{
|
||||
if (iParam[0]) {
|
||||
int i;
|
||||
for (i = 0; i < iParam[0]; i++)
|
||||
ConScrollUp(ConGetCursorY() - 1, ScrollTop + ConWindowSizeY() - 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if (ConGetCursorY() <= ScrollTop + ConWindowSizeY() - 2)
|
||||
{
|
||||
ConScrollUp(ConGetCursorY() - 1, ScrollTop + ConWindowSizeY() - 2);
|
||||
}
|
||||
}
|
||||
fcompletion = 1;
|
||||
bAtEOLN = FALSE;
|
||||
break;
|
||||
|
||||
case 'N':
|
||||
case 'N': /* FALLTHROUGH */
|
||||
case 'O':
|
||||
fcompletion = 1;
|
||||
break;
|
||||
|
@ -658,31 +589,21 @@ unsigned char * ParseANSI(unsigned char * pszBuffer, unsigned char * pszBufferEn
|
|||
case 'H':
|
||||
case 'f':
|
||||
if (bMode & MODE_BRK)
|
||||
{
|
||||
ConSetCursorPosition((iParam[1] > 0) ? iParam[1] - 1 : 0, (iParam[0] > 0) ? iParam[0] - 1 : 0);
|
||||
}
|
||||
else if (bMode == 0)
|
||||
{
|
||||
//Set tab
|
||||
}
|
||||
|
||||
fcompletion = 1;
|
||||
bAtEOLN = FALSE;
|
||||
break;
|
||||
|
||||
case 'M':
|
||||
if (iParam[0])
|
||||
{
|
||||
if (iParam[0]) {
|
||||
int i;
|
||||
for (i = 0; i < iParam[0]; i++)
|
||||
ConScrollUp(ConGetCursorY(), ScrollTop - ConGetCursorY());
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if (ConGetCursorY() <= ScrollTop + ConWindowSizeY() - 2)
|
||||
{
|
||||
ConScrollUp(ConGetCursorY(), ScrollTop - ConGetCursorY());
|
||||
}
|
||||
}
|
||||
fcompletion = 1;
|
||||
bAtEOLN = FALSE;
|
||||
break;
|
||||
|
@ -693,18 +614,14 @@ unsigned char * ParseANSI(unsigned char * pszBuffer, unsigned char * pszBufferEn
|
|||
fcompletion = 1;
|
||||
break;
|
||||
|
||||
case 'i': // ANSI or VTXXX Print
|
||||
if ( iParam[0] == 5 )
|
||||
{
|
||||
}
|
||||
else if ( iParam[0] == 4 )
|
||||
case 'i': /* ANSI or VTXXX Print */
|
||||
if (iParam[0] == 4)
|
||||
InPrintMode = FALSE;
|
||||
fcompletion = 1;
|
||||
break;
|
||||
|
||||
case 'K':
|
||||
if (bMode & MODE_BRK)
|
||||
{
|
||||
if (bMode & MODE_BRK) {
|
||||
switch (iParam[0])
|
||||
{
|
||||
case 0:
|
||||
|
@ -717,18 +634,14 @@ unsigned char * ParseANSI(unsigned char * pszBuffer, unsigned char * pszBufferEn
|
|||
ConClearLine();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (bMode == 0)
|
||||
{
|
||||
} else if (bMode == 0)
|
||||
bMode |= MODE_K;
|
||||
}
|
||||
|
||||
fcompletion = 1;
|
||||
break;
|
||||
|
||||
case 'J':
|
||||
switch (iParam[0])
|
||||
{
|
||||
switch (iParam[0]) {
|
||||
case 0:
|
||||
ConClearEOScreen();
|
||||
break;
|
||||
|
@ -743,53 +656,35 @@ unsigned char * ParseANSI(unsigned char * pszBuffer, unsigned char * pszBufferEn
|
|||
break;
|
||||
|
||||
case 'n':
|
||||
if (iCurrentParam == 1)
|
||||
{
|
||||
if (iParam[0] == 5)
|
||||
{
|
||||
if (iCurrentParam == 1) {
|
||||
if (iParam[0] == 5) {
|
||||
char * szStatus = GetStatusReport();
|
||||
if (respbuf != NULL)
|
||||
{
|
||||
if (respbuf != NULL) {
|
||||
*respbuf = szStatus;
|
||||
if (resplen != NULL)
|
||||
{
|
||||
*resplen = strlen(szStatus);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( iParam[0] == 6 )
|
||||
{
|
||||
} else if (iParam[0] == 6) {
|
||||
char * szStatus = GetCursorPositionReport();
|
||||
if (respbuf != NULL)
|
||||
{
|
||||
if (respbuf != NULL) {
|
||||
*respbuf = szStatus;
|
||||
if (resplen != NULL)
|
||||
{
|
||||
*resplen = strlen(szStatus);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fcompletion = 1;
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
if (bMode == (MODE_BRK & MODE_EXT))
|
||||
{
|
||||
// What is your response?
|
||||
}
|
||||
else if (bMode == MODE_BRK)
|
||||
{
|
||||
if (bMode == MODE_BRK) {
|
||||
char* szTerminalId = GetTerminalId();
|
||||
if (szTerminalId) {
|
||||
if (respbuf != NULL)
|
||||
{
|
||||
if (respbuf != NULL) {
|
||||
*respbuf = szTerminalId;
|
||||
if (resplen != NULL)
|
||||
{
|
||||
*resplen = strlen(szTerminalId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fcompletion = 1;
|
||||
|
@ -800,15 +695,13 @@ unsigned char * ParseANSI(unsigned char * pszBuffer, unsigned char * pszBufferEn
|
|||
fcompletion = 1;
|
||||
break;
|
||||
|
||||
case 'Z': // Identify - This is really a VT52 command
|
||||
case 'Z': /* Identify - This is really a VT52 command */
|
||||
{
|
||||
char* szTerminalId = GetTerminalId();
|
||||
if (szTerminalId) {
|
||||
*respbuf = szTerminalId;
|
||||
if (resplen != NULL)
|
||||
{
|
||||
*resplen = strlen(szTerminalId);
|
||||
}
|
||||
}
|
||||
}
|
||||
fcompletion = 1;
|
||||
|
@ -820,31 +713,26 @@ unsigned char * ParseANSI(unsigned char * pszBuffer, unsigned char * pszBufferEn
|
|||
break;
|
||||
|
||||
default:
|
||||
|
||||
// pszHead should point to digit now. Otherwise we got a bad escape
|
||||
// sequence, so we just get out of here!
|
||||
/* 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))
|
||||
{
|
||||
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])
|
||||
{
|
||||
if (bMode == 0) {
|
||||
switch (iParam[0]) {
|
||||
case 7:
|
||||
SavedX = ConGetCursorX();
|
||||
SavedY = ConGetCursorY();
|
||||
|
@ -855,19 +743,16 @@ unsigned char * ParseANSI(unsigned char * pszBuffer, unsigned char * pszBufferEn
|
|||
}
|
||||
fcompletion = 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
pszCurrent = pszBuffer;
|
||||
return pszCurrent;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
} 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;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue