43 #define MAX_PORTNAME_LEN 20 59 #define MAX_BUFFER_SIZE 4096 69 szMsgBuffer[
i] =
L'-';
117 swprintf(szPortName,
L"LPT%d", nPortNum);
118 swprintf(szTargetPath,
L"COM%d", nPortNum);
165 DWORD dwKbdDelay, dwKbdSpeed;
213 pcsbi->dwSize.X * pcsbi->dwSize.Y,
216 pcsbi->dwSize.X * pcsbi->dwSize.Y,
247 Width = pcsbi->srWindow.
Right - pcsbi->srWindow.Left + 1;
248 Height = pcsbi->srWindow.Bottom - pcsbi->srWindow.Top + 1;
263 ConRect.
Left = ConRect.
Top = 0;
294 ConRect.
Right = ConRect.
Left + Width - 1;
295 ConRect.
Bottom =
max(pcsbi->dwCursorPosition.Y, Height - 1);
296 ConRect.
Top = ConRect.
Bottom - Height + 1;
326 if (!argStr)
goto invalid_parameter;
330 while (*argStr ==
L' ') argStr++;
331 if (!*argStr)
goto Quit;
332 if (*argStr++ !=
L',')
goto invalid_parameter;
333 while (*argStr ==
L' ') argStr++;
337 if (!argStr)
goto invalid_parameter;
341 while (*argStr ==
L' ') argStr++;
342 if (*argStr)
goto invalid_parameter;
364 DWORD dwKbdDelay, dwKbdSpeed;
385 while (argStr && *argStr)
387 while (*argStr ==
L' ') argStr++;
390 if (!kbdMode &&
_wcsnicmp(argStr,
L"COLS=", 5) == 0)
396 if (!argStr)
goto invalid_parameter;
399 else if (!kbdMode &&
_wcsnicmp(argStr,
L"LINES=", 6) == 0)
405 if (!argStr)
goto invalid_parameter;
408 else if (!dispMode &&
_wcsnicmp(argStr,
L"RATE=", 5) == 0)
413 if (!argStr)
goto invalid_parameter;
415 else if (!dispMode &&
_wcsnicmp(argStr,
L"DELAY=", 6) == 0)
420 if (!argStr)
goto invalid_parameter;
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;
498 swprintf(szPortName,
L"COM%d", nPortNum);
544 static const LPCWSTR parity_strings[] =
552 static const LPCWSTR control_strings[] = {
L"OFF",
L"ON",
L"HANDSHAKE",
L"TOGGLE" };
553 static const LPCWSTR stopbit_strings[] = {
L"1",
L"1.5",
L"2" };
563 if (dcb.Parity >=
ARRAYSIZE(parity_strings))
568 if (dcb.StopBits >=
ARRAYSIZE(stopbit_strings))
574 swprintf(szPortName,
L"COM%d", nPortNum);
588 control_strings[dcb.fOutX ? 1 : 0]);
590 control_strings[dcb.fOutxCtsFlow ? 1 : 0]);
592 control_strings[dcb.fOutxDsrFlow ? 1 : 0]);
594 control_strings[dcb.fDsrSensitivity ? 1 : 0]);
639 if (!argStr)
return NULL;
648 case 11:
case 15:
case 30:
case 60:
653 case 12:
case 24:
case 48:
case 96:
703 if (!argStr)
return NULL;
706 if (*ByteSize < 5 || *ByteSize > 8)
724 else if (*argStr ==
L'2')
753 if (!argStr)
return FALSE;
760 while (*argStr ==
L' ') argStr++;
761 if (!*argStr)
goto Quit;
762 if (*argStr++ !=
L',')
return FALSE;
763 while (*argStr ==
L' ') argStr++;
764 if (!*argStr)
goto Quit;
772 if (!argStr)
return FALSE;
775 while (*argStr ==
L' ') argStr++;
776 if (!*argStr)
goto Quit;
777 if (*argStr++ !=
L',')
return FALSE;
778 while (*argStr ==
L' ') argStr++;
779 if (!*argStr)
goto Quit;
787 if (!argStr)
return FALSE;
790 while (*argStr ==
L' ') argStr++;
791 if (!*argStr)
goto Quit;
792 if (*argStr++ !=
L',')
return FALSE;
793 while (*argStr ==
L' ') argStr++;
794 if (!*argStr)
goto Quit;
803 if (!argStr)
return FALSE;
807 while (*argStr ==
L' ') argStr++;
808 if (!*argStr)
goto Quit;
809 if (*argStr++ !=
L',')
return FALSE;
810 while (*argStr ==
L' ') argStr++;
811 if (!*argStr)
goto Quit;
819 pDCB->fOutxCtsFlow =
FALSE;
820 pDCB->fOutxDsrFlow =
FALSE;
828 pDCB->fOutxCtsFlow =
FALSE;
829 pDCB->fOutxDsrFlow =
FALSE;
837 pDCB->fOutxCtsFlow =
TRUE;
838 pDCB->fOutxDsrFlow =
TRUE;
847 if (*argStr) argStr++;
850 while (*argStr ==
L' ') argStr++;
851 if (*argStr)
return FALSE;
856 if (pDCB->BaudRate == 110)
881 while (argStr && *argStr)
883 while (*argStr ==
L' ') argStr++;
890 if (!argStr)
return FALSE;
892 else if (
_wcsnicmp(argStr,
L"PARITY=", 7) == 0)
896 if (!argStr)
return FALSE;
902 if (!argStr)
return FALSE;
909 if (!argStr)
return FALSE;
915 if (!argStr)
return FALSE;
918 pCommTimeouts->ReadTotalTimeoutConstant = 0;
919 pCommTimeouts->WriteTotalTimeoutConstant = 0;
923 pCommTimeouts->ReadTotalTimeoutConstant = 60000;
924 pCommTimeouts->WriteTotalTimeoutConstant = 60000;
934 if (!argStr)
return FALSE;
949 if (!argStr)
return FALSE;
951 pDCB->fOutxDsrFlow =
value;
959 if (!argStr)
return FALSE;
961 pDCB->fOutxCtsFlow =
value;
969 if (!argStr)
return FALSE;
971 pDCB->fDtrControl =
value;
979 if (!argStr)
return FALSE;
981 pDCB->fRtsControl =
value;
989 if (!argStr)
return FALSE;
991 pDCB->fDsrSensitivity =
value;
1004 if (baud && pDCB->BaudRate == 110)
1055 *PortNum =
wcstol(argStr, &endptr, 10);
1056 if (endptr == argStr)
1113 if (!argStr || *argStr || nPortNum == -1)
1126 if (!argStr || *argStr || nPortNum == -1)
1206 while (*argStr ==
L' ') argStr++;
1217 while (*argStr !=
L' ') argStr++;
1219 while (*argStr ==
L' ') argStr++;
1223 goto invalid_parameter;
1230 if (!argStr || nPortNum == -1)
1231 goto invalid_parameter;
1233 if (*argStr ==
L':') argStr++;
1234 while (*argStr ==
L' ') argStr++;
1236 if (!*argStr ||
_wcsnicmp(argStr,
L"/STA", 4) == 0)
1239 ConPuts(
StdErr,
L"ERROR: LPT port redirection is not implemented!\n");
1246 if (!argStr || nPortNum == -1)
1247 goto invalid_parameter;
1249 if (*argStr ==
L':') argStr++;
1250 while (*argStr ==
L' ') argStr++;
1252 if (!*argStr ||
_wcsnicmp(argStr,
L"/STA", 4) == 0)
1262 if (*argStr ==
L':') argStr++;
1263 while (*argStr ==
L' ') argStr++;
1265 if (!*argStr ||
_wcsnicmp(argStr,
L"/STA", 4) == 0)
1269 else if ( (
_wcsnicmp(argStr,
L"CP", 2) == 0 && (argStr += 2)) ||
1270 (
_wcsnicmp(argStr,
L"CODEPAGE", 8) == 0 && (argStr += 8)) )
1272 while (*argStr ==
L' ') argStr++;
1274 if (!*argStr ||
_wcsnicmp(argStr,
L"/STA", 4) == 0)
#define IDS_ERROR_TIMEOUT_GET_DEVICE
#define IDS_QUERY_PRINTER_FOUND
static PCWSTR ParseByteSize(PCWSTR argStr, PBYTE ByteSize)
BOOL WINAPI SetConsoleOutputCP(IN UINT wCodepage)
#define IDS_PRINTER_OUTPUT_REROUTED_SERIAL
#define IDS_ERROR_DEVICE_NOT_AVAILABLE
BOOL WINAPI FillConsoleOutputAttribute(IN HANDLE hConsoleOutput, IN WORD wAttribute, IN DWORD nLength, IN COORD dwWriteCoord, OUT LPDWORD lpNumberOfAttrsWritten)
#define SPI_GETKEYBOARDSPEED
#define IDS_CONSOLE_CODEPAGE
INT ConResPrintfV(IN PCON_STREAM Stream, IN UINT uID, IN va_list args)
BOOL WINAPI SetCommState(HANDLE handle, LPDCB lpdcb)
#define RTS_CONTROL_ENABLE
BOOL WINAPI SetCommTimeouts(HANDLE hComm, LPCOMMTIMEOUTS lptimeouts)
#define IDS_COM_STATUS_DTR_CIRCUIT
_CONST_RETURN wchar_t *__cdecl wcsstr(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_SubStr)
#define DDD_REMOVE_DEFINITION
static PCWSTR ParseModes(PCWSTR argStr, PBYTE Mode)
#define RTS_CONTROL_HANDSHAKE
#define IDS_ERROR_INVALID_STOP_BITS
#define IDS_CONSOLE_KBD_RATE
_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 INVALID_HANDLE_VALUE
DWORD WINAPI GetLastError(VOID)
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
#define IDS_COM_STATUS_DSR_SENSITIVITY
_Check_return_ long __cdecl wcstol(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
int SetConsoleCPState(IN PCWSTR ArgStr)
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleScreenBufferSize(HANDLE hConsoleOutput, COORD dwSize)
#define IDS_COM_STATUS_XON_XOFF
#define SPI_SETKEYBOARDDELAY
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
#define IDS_COM_STATUS_RTS_CIRCUIT
#define IDS_ERROR_INVALID_PARAMETER
#define ConInitStdStreams()
int ShowConsoleCPStatus(VOID)
#define ERROR_ACCESS_DENIED
VOID __cdecl UnderlinedResPrintf(IN PCON_STREAM Stream, IN UINT uID,...)
#define DTR_CONTROL_ENABLE
#define IDS_PRINTER_OUTPUT_NOT_REROUTED
static PCWSTR ParseNumber(PCWSTR argStr, PDWORD Number)
#define IDS_CONSOLE_STATUS_LINES
int SetConsoleStateOld(IN PCWSTR ArgStr)
#define IDS_COM_STATUS_CTS_HANDSHAKING
INT __cdecl ConPrintf(IN PCON_STREAM Stream, IN LPWSTR szStr,...)
UINT WINAPI DECLSPEC_HOTPATCH GetConsoleOutputCP(VOID)
INT ConStreamWrite(IN PCON_STREAM Stream, IN PTCHAR szStr, IN DWORD len)
static BOOL ResizeTextConsole(IN HANDLE hConOut, IN OUT PCONSOLE_SCREEN_BUFFER_INFO pcsbi, IN COORD Resolution)
BOOL WINAPI SetConsoleCursorPosition(IN HANDLE hConsoleOutput, IN COORD dwCursorPosition)
static VOID ClearScreen(IN HANDLE hConOut, IN PCONSOLE_SCREEN_BUFFER_INFO pcsbi)
DWORD WINAPI QueryDosDeviceW(LPCWSTR lpDeviceName, LPWSTR lpTargetPath, DWORD ucchMax)
#define IDS_COM_STATUS_DATA_BITS
_Check_return_ _CRTIMP _CONST_RETURN wchar_t *__cdecl wcsrchr(_In_z_ const wchar_t *_Str, _In_ wchar_t _Ch)
int ShowSerialStatus(INT nPortNum)
BOOL WINAPI GetCommState(HANDLE handle, LPDCB lpdcb)
BOOL WINAPI GetCommTimeouts(HANDLE hComm, LPCOMMTIMEOUTS lptimeouts)
int EnumerateDevices(VOID)
BOOL WINAPI GetConsoleScreenBufferInfo(IN HANDLE hConsoleOutput, OUT PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo)
INT __cdecl ConResPrintf(IN PCON_STREAM Stream, IN UINT uID,...)
#define IDS_DEVICE_STATUS_HEADER
#define IDS_CONSOLE_KBD_DELAY
BOOL WINAPI SystemParametersInfoW(_In_ UINT, _In_ UINT, _Inout_opt_ PVOID, _In_ UINT)
#define SPI_GETKEYBOARDDELAY
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
#define IDS_COM_STATUS_STOP_BITS
#define SPI_SETKEYBOARDSPEED
#define IDS_COM_STATUS_DSR_HANDSHAKING
#define IDS_ERROR_TIMEOUT_SET_DEVICE
#define swprintf(buf, format,...)
static BOOL SerialPortQuery(INT nPortNum, LPDCB pDCB, LPCOMMTIMEOUTS pCommTimeouts, BOOL bWrite)
#define IDS_ERROR_STATUS_GET_DEVICE
DWORD ReadTotalTimeoutConstant
int ShowConsoleStatus(VOID)
INT ConResPuts(IN PCON_STREAM Stream, IN UINT uID)
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define IDS_QUERY_DOSDEV_FOUND
#define STD_OUTPUT_HANDLE
#define IDS_ERROR_ILLEGAL_DEVICE_NAME
#define IDS_ERROR_STATUS_SET_DEVICE
GLsizei const GLfloat * value
_In_opt_ PENTER_STATE_SYSTEM_HANDLER _In_opt_ PVOID _In_ LONG _In_opt_ LONG volatile * Number
int wmain(int argc, WCHAR *argv[])
BOOL WINAPI DefineDosDeviceW(DWORD dwFlags, LPCWSTR lpDeviceName, LPCWSTR lpTargetPath)
static PCWSTR FindPortNum(PCWSTR argStr, PINT PortNum)
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleCP(UINT wCodePageID)
#define SPIF_UPDATEINIFILE
int SetConsoleState(IN PCWSTR ArgStr)
#define IDS_COM_STATUS_TIMEOUT
#define IDS_COM_STATUS_PARITY
int SetParallelState(INT nPortNum)
#define DTR_CONTROL_HANDSHAKE
static PCWSTR ParseBaudRate(PCWSTR argStr, PDWORD BaudRate)
INT ConPuts(IN PCON_STREAM Stream, IN LPWSTR szStr)
static PCWSTR ParseStopBits(PCWSTR argStr, PBYTE StopBits)
static BOOL BuildOldCommDCB(OUT LPDCB pDCB, IN PCWSTR ArgStr)
static PCWSTR ParseParity(PCWSTR argStr, PBYTE Parity)
#define IDS_COM_STATUS_BAUD
#define IDS_ERROR_INVALID_PARITY_BITS
BOOL WINAPI SetConsoleWindowInfo(HANDLE hConsoleOutput, BOOL bAbsolute, CONST SMALL_RECT *lpConsoleWindow)
#define show_status(counter, text)
IN BOOLEAN OUT PSTR Buffer
DWORD WriteTotalTimeoutConstant
int SetSerialState(INT nPortNum, IN PCWSTR ArgStr)
#define IDS_CONSOLE_STATUS_COLS
_IRQL_requires_same_ _In_ CLONG ByteSize
_Check_return_ _CRTIMP int __cdecl swscanf(_In_z_ const wchar_t *_Src, _In_z_ _Scanf_format_string_ const wchar_t *_Format,...)
#define IDS_ERROR_SCREEN_LINES_COL
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define HeapFree(x, y, z)
_Inout_opt_ PUNICODE_STRING _Inout_opt_ PUNICODE_STRING Stream
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define IDS_ERROR_QUERY_DEVICES_FORM
static BOOL BuildNewCommDCB(OUT LPDCB pDCB, OUT LPCOMMTIMEOUTS pCommTimeouts, IN PCWSTR ArgStr)
BOOL WINAPI DECLSPEC_HOTPATCH FillConsoleOutputCharacterW(IN HANDLE hConsoleOutput, IN WCHAR cCharacter, IN DWORD nLength, IN COORD dwWriteCoord, OUT LPDWORD lpNumberOfCharsWritten)
int ShowParallelStatus(INT nPortNum)
#define ERROR_INSUFFICIENT_BUFFER