42#define MAX_PORTNAME_LEN 20
58#define MAX_BUFFER_SIZE 4096
68 szMsgBuffer[
i] =
L'-';
116 swprintf(szPortName,
L"LPT%d", nPortNum);
117 swprintf(szTargetPath,
L"COM%d", nPortNum);
164 DWORD dwKbdDelay, dwKbdSpeed;
212 pcsbi->dwSize.X * pcsbi->dwSize.Y,
215 pcsbi->dwSize.X * pcsbi->dwSize.Y,
246 Width = pcsbi->srWindow.Right - pcsbi->srWindow.Left + 1;
247 Height = pcsbi->srWindow.Bottom - pcsbi->srWindow.Top + 1;
262 ConRect.
Left = ConRect.
Top = 0;
325 if (!argStr)
goto invalid_parameter;
329 while (*argStr ==
L' ') argStr++;
330 if (!*argStr)
goto Quit;
331 if (*argStr++ !=
L',')
goto invalid_parameter;
332 while (*argStr ==
L' ') argStr++;
336 if (!argStr)
goto invalid_parameter;
340 while (*argStr ==
L' ') argStr++;
341 if (*argStr)
goto invalid_parameter;
363 DWORD dwKbdDelay, dwKbdSpeed;
384 while (argStr && *argStr)
386 while (*argStr ==
L' ') argStr++;
389 if (!kbdMode &&
_wcsnicmp(argStr,
L"COLS=", 5) == 0)
395 if (!argStr)
goto invalid_parameter;
398 else if (!kbdMode &&
_wcsnicmp(argStr,
L"LINES=", 6) == 0)
404 if (!argStr)
goto invalid_parameter;
407 else if (!dispMode &&
_wcsnicmp(argStr,
L"RATE=", 5) == 0)
412 if (!argStr)
goto invalid_parameter;
414 else if (!dispMode &&
_wcsnicmp(argStr,
L"DELAY=", 6) == 0)
419 if (!argStr)
goto invalid_parameter;
456 UINT uOldCodePage, uNewCodePage;
458 if ( (
_wcsnicmp(argStr,
L"SELECT=", 7) == 0 && (argStr += 7)) ||
459 (
_wcsnicmp(argStr,
L"SEL=", 4) == 0 && (argStr += 4)) )
462 if (!argStr)
goto invalid_parameter;
465 while (*argStr ==
L' ') argStr++;
466 if (*argStr)
goto invalid_parameter;
475 uNewCodePage =
value;
531 swprintf(szPortName,
L"COM%d", nPortNum);
577 static const LPCWSTR parity_strings[] =
585 static const LPCWSTR control_strings[] = {
L"OFF",
L"ON",
L"HANDSHAKE",
L"TOGGLE" };
586 static const LPCWSTR stopbit_strings[] = {
L"1",
L"1.5",
L"2" };
596 if (dcb.Parity >=
ARRAYSIZE(parity_strings))
601 if (dcb.StopBits >=
ARRAYSIZE(stopbit_strings))
607 swprintf(szPortName,
L"COM%d", nPortNum);
621 control_strings[dcb.fOutX ? 1 : 0]);
623 control_strings[dcb.fOutxCtsFlow ? 1 : 0]);
625 control_strings[dcb.fOutxDsrFlow ? 1 : 0]);
627 control_strings[dcb.fDsrSensitivity ? 1 : 0]);
672 if (!argStr)
return NULL;
681 case 11:
case 15:
case 30:
case 60:
686 case 12:
case 24:
case 48:
case 96:
736 if (!argStr)
return NULL;
739 if (*ByteSize < 5 || *ByteSize > 8)
757 else if (*argStr ==
L'2')
786 if (!argStr)
return FALSE;
793 while (*argStr ==
L' ') argStr++;
794 if (!*argStr)
goto Quit;
795 if (*argStr++ !=
L',')
return FALSE;
796 while (*argStr ==
L' ') argStr++;
797 if (!*argStr)
goto Quit;
805 if (!argStr)
return FALSE;
808 while (*argStr ==
L' ') argStr++;
809 if (!*argStr)
goto Quit;
810 if (*argStr++ !=
L',')
return FALSE;
811 while (*argStr ==
L' ') argStr++;
812 if (!*argStr)
goto Quit;
820 if (!argStr)
return FALSE;
823 while (*argStr ==
L' ') argStr++;
824 if (!*argStr)
goto Quit;
825 if (*argStr++ !=
L',')
return FALSE;
826 while (*argStr ==
L' ') argStr++;
827 if (!*argStr)
goto Quit;
836 if (!argStr)
return FALSE;
840 while (*argStr ==
L' ') argStr++;
841 if (!*argStr)
goto Quit;
842 if (*argStr++ !=
L',')
return FALSE;
843 while (*argStr ==
L' ') argStr++;
844 if (!*argStr)
goto Quit;
852 pDCB->fOutxCtsFlow =
FALSE;
853 pDCB->fOutxDsrFlow =
FALSE;
861 pDCB->fOutxCtsFlow =
FALSE;
862 pDCB->fOutxDsrFlow =
FALSE;
870 pDCB->fOutxCtsFlow =
TRUE;
871 pDCB->fOutxDsrFlow =
TRUE;
880 if (*argStr) argStr++;
883 while (*argStr ==
L' ') argStr++;
884 if (*argStr)
return FALSE;
889 if (pDCB->BaudRate == 110)
914 while (argStr && *argStr)
916 while (*argStr ==
L' ') argStr++;
923 if (!argStr)
return FALSE;
925 else if (
_wcsnicmp(argStr,
L"PARITY=", 7) == 0)
929 if (!argStr)
return FALSE;
935 if (!argStr)
return FALSE;
942 if (!argStr)
return FALSE;
948 if (!argStr)
return FALSE;
951 pCommTimeouts->ReadTotalTimeoutConstant = 0;
952 pCommTimeouts->WriteTotalTimeoutConstant = 0;
956 pCommTimeouts->ReadTotalTimeoutConstant = 60000;
957 pCommTimeouts->WriteTotalTimeoutConstant = 60000;
967 if (!argStr)
return FALSE;
982 if (!argStr)
return FALSE;
984 pDCB->fOutxDsrFlow =
value;
992 if (!argStr)
return FALSE;
994 pDCB->fOutxCtsFlow =
value;
1002 if (!argStr)
return FALSE;
1004 pDCB->fDtrControl =
value;
1012 if (!argStr)
return FALSE;
1014 pDCB->fRtsControl =
value;
1018 else if (
_wcsnicmp(argStr,
L"IDSR=", 5) == 0)
1022 if (!argStr)
return FALSE;
1024 pDCB->fDsrSensitivity =
value;
1037 if (baud && pDCB->BaudRate == 110)
1088 *PortNum =
wcstol(argStr, &endptr, 10);
1089 if (endptr == argStr)
1146 if (!argStr || *argStr || nPortNum == -1)
1159 if (!argStr || *argStr || nPortNum == -1)
1239 while (*argStr ==
L' ') argStr++;
1250 while (*argStr !=
L' ') argStr++;
1252 while (*argStr ==
L' ') argStr++;
1256 goto invalid_parameter;
1263 if (!argStr || nPortNum == -1)
1264 goto invalid_parameter;
1266 if (*argStr ==
L':') argStr++;
1267 while (*argStr ==
L' ') argStr++;
1269 if (!*argStr ||
_wcsnicmp(argStr,
L"/STA", 4) == 0)
1272 ConPuts(
StdErr,
L"ERROR: LPT port redirection is not implemented!\n");
1279 if (!argStr || nPortNum == -1)
1280 goto invalid_parameter;
1282 if (*argStr ==
L':') argStr++;
1283 while (*argStr ==
L' ') argStr++;
1285 if (!*argStr ||
_wcsnicmp(argStr,
L"/STA", 4) == 0)
1295 if (*argStr ==
L':') argStr++;
1296 while (*argStr ==
L' ') argStr++;
1298 if (!*argStr ||
_wcsnicmp(argStr,
L"/STA", 4) == 0)
1302 else if ( (
_wcsnicmp(argStr,
L"CP", 2) == 0 && (argStr += 2)) ||
1303 (
_wcsnicmp(argStr,
L"CODEPAGE", 8) == 0 && (argStr += 8)) )
1305 while (*argStr ==
L' ') argStr++;
1307 if (!*argStr ||
_wcsnicmp(argStr,
L"/STA", 4) == 0)
void ConPuts(FILE *fp, LPCWSTR psz)
#define ConInitStdStreams()
void ConPrintf(FILE *fp, LPCWSTR psz,...)
void ConResPrintf(FILE *fp, UINT nID,...)
void ConResPuts(FILE *fp, UINT nID)
#define IDS_COM_STATUS_BAUD
#define IDS_ERROR_INVALID_PARAMETER
#define IDS_CONSOLE_KBD_DELAY
#define IDS_QUERY_DOSDEV_FOUND
#define IDS_QUERY_PRINTER_FOUND
#define IDS_COM_STATUS_XON_XOFF
#define IDS_COM_STATUS_PARITY
#define IDS_CONSOLE_STATUS_COLS
#define IDS_PRINTER_OUTPUT_REROUTED_SERIAL
#define IDS_ERROR_ILLEGAL_DEVICE_NAME
#define IDS_CONSOLE_CODEPAGE
#define IDS_CONSOLE_KBD_RATE
#define IDS_ERROR_QUERY_DEVICES_FORM
#define IDS_ERROR_INVALID_PARITY_BITS
#define IDS_COM_STATUS_STOP_BITS
#define IDS_DEVICE_STATUS_HEADER
#define IDS_COM_STATUS_DSR_HANDSHAKING
#define IDS_ERROR_TIMEOUT_GET_DEVICE
#define IDS_COM_STATUS_DTR_CIRCUIT
#define IDS_ERROR_TIMEOUT_SET_DEVICE
#define IDS_CONSOLE_STATUS_LINES
#define IDS_ERROR_DEVICE_NOT_AVAILABLE
#define IDS_ERROR_INVALID_STOP_BITS
#define IDS_ERROR_STATUS_SET_DEVICE
#define IDS_COM_STATUS_DSR_SENSITIVITY
#define IDS_ERROR_SCREEN_LINES_COL
#define IDS_PRINTER_OUTPUT_NOT_REROUTED
#define IDS_COM_STATUS_TIMEOUT
#define IDS_COM_STATUS_CTS_HANDSHAKING
#define IDS_ERROR_INVALID_CODEPAGE
#define IDS_ERROR_STATUS_GET_DEVICE
#define IDS_COM_STATUS_RTS_CIRCUIT
#define IDS_COM_STATUS_DATA_BITS
BOOL WINAPI SetConsoleOutputCP(IN UINT wCodepage)
BOOL WINAPI SetConsoleCursorPosition(IN HANDLE hConsoleOutput, IN COORD dwCursorPosition)
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
BOOL WINAPI FillConsoleOutputAttribute(IN HANDLE hConsoleOutput, IN WORD wAttribute, IN DWORD nLength, IN COORD dwWriteCoord, OUT LPDWORD lpNumberOfAttrsWritten)
BOOL WINAPI GetConsoleScreenBufferInfo(IN HANDLE hConsoleOutput, OUT PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo)
#define ERROR_INSUFFICIENT_BUFFER
#define INVALID_HANDLE_VALUE
#define HeapFree(x, y, z)
#define ERROR_ACCESS_DENIED
BOOL WINAPI SetConsoleWindowInfo(HANDLE hConsoleOutput, BOOL bAbsolute, CONST SMALL_RECT *lpConsoleWindow)
UINT WINAPI DECLSPEC_HOTPATCH GetConsoleOutputCP(VOID)
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleScreenBufferSize(HANDLE hConsoleOutput, COORD dwSize)
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleCP(UINT wCodePageID)
UINT WINAPI DECLSPEC_HOTPATCH GetConsoleCP(VOID)
BOOL WINAPI DECLSPEC_HOTPATCH FillConsoleOutputCharacterW(IN HANDLE hConsoleOutput, IN WCHAR cCharacter, IN DWORD nLength, IN COORD dwWriteCoord, OUT LPDWORD lpNumberOfCharsWritten)
BOOL WINAPI DefineDosDeviceW(DWORD dwFlags, LPCWSTR lpDeviceName, LPCWSTR lpTargetPath)
DWORD WINAPI QueryDosDeviceW(LPCWSTR lpDeviceName, LPWSTR lpTargetPath, DWORD ucchMax)
BOOL WINAPI SetCommTimeouts(HANDLE hComm, LPCOMMTIMEOUTS lptimeouts)
BOOL WINAPI SetCommState(HANDLE handle, LPDCB lpdcb)
BOOL WINAPI GetCommState(HANDLE handle, LPDCB lpdcb)
BOOL WINAPI GetCommTimeouts(HANDLE hComm, LPCOMMTIMEOUTS lptimeouts)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
_Check_return_ _CRTIMP int __cdecl swscanf(_In_z_ const wchar_t *_Src, _In_z_ _Scanf_format_string_ const wchar_t *_Format,...)
_Check_return_ long __cdecl wcstol(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
_CONST_RETURN wchar_t *__cdecl wcsstr(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_SubStr)
int SetParallelState(INT nPortNum)
int SetSerialState(INT nPortNum, IN PCWSTR ArgStr)
static PCWSTR ParseModes(PCWSTR argStr, PBYTE Mode)
static PCWSTR ParseBaudRate(PCWSTR argStr, PDWORD BaudRate)
VOID __cdecl UnderlinedResPrintf(IN PCON_STREAM Stream, IN UINT uID,...)
static BOOL SerialPortQuery(INT nPortNum, LPDCB pDCB, LPCOMMTIMEOUTS pCommTimeouts, BOOL bWrite)
static VOID ClearScreen(IN HANDLE hConOut, IN PCONSOLE_SCREEN_BUFFER_INFO pcsbi)
static BOOL BuildNewCommDCB(OUT LPDCB pDCB, OUT LPCOMMTIMEOUTS pCommTimeouts, IN PCWSTR ArgStr)
int ShowConsoleCPStatus(VOID)
int SetConsoleCPState(IN PCWSTR ArgStr)
static PCWSTR FindPortNum(PCWSTR argStr, PINT PortNum)
int SetConsoleStateOld(IN PCWSTR ArgStr)
static BOOL BuildOldCommDCB(OUT LPDCB pDCB, IN PCWSTR ArgStr)
int ShowSerialStatus(INT nPortNum)
static PCWSTR ParseByteSize(PCWSTR argStr, PBYTE ByteSize)
int SetConsoleState(IN PCWSTR ArgStr)
static PCWSTR ParseStopBits(PCWSTR argStr, PBYTE StopBits)
int ShowParallelStatus(INT nPortNum)
static PCWSTR ParseNumber(PCWSTR argStr, PDWORD Number)
int EnumerateDevices(VOID)
static PCWSTR ParseParity(PCWSTR argStr, PBYTE Parity)
static BOOL ResizeTextConsole(IN HANDLE hConOut, IN OUT PCONSOLE_SCREEN_BUFFER_INFO pcsbi, IN COORD Resolution)
int ShowConsoleStatus(VOID)
#define show_status(counter, text)
_In_opt_ PENTER_STATE_SYSTEM_HANDLER _In_opt_ PVOID _In_ LONG _In_opt_ LONG volatile * Number
INT ConResPrintfV(IN PCON_STREAM Stream, IN UINT uID, IN va_list args)
INT ConStreamWrite(IN PCON_STREAM Stream, IN PCTCH szStr, IN DWORD len)
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
#define ConStdStreamsSetCacheCodePage(InputCodePage, OutputCodePage)
LANGID ConSetThreadUILanguage(IN LANGID LangId OPTIONAL)
DWORD WriteTotalTimeoutConstant
DWORD ReadTotalTimeoutConstant
_In_ HFONT _Out_ PUINT _Out_ PUINT Width
_In_ HFONT _Out_ PUINT Height
#define STD_OUTPUT_HANDLE
#define RTS_CONTROL_ENABLE
#define DTR_CONTROL_HANDSHAKE
DWORD WINAPI GetLastError(void)
#define RTS_CONTROL_HANDSHAKE
#define DTR_CONTROL_ENABLE
#define DDD_REMOVE_DEFINITION
#define SPI_SETKEYBOARDSPEED
#define SPIF_UPDATEINIFILE
#define SPI_GETKEYBOARDSPEED
BOOL WINAPI SystemParametersInfoW(_In_ UINT uiAction, _In_ UINT uiParam, _Inout_opt_ PVOID pvParam, _In_ UINT fWinIni)
#define SPI_GETKEYBOARDDELAY
#define SPI_SETKEYBOARDDELAY
_IRQL_requires_same_ _In_ CLONG ByteSize