mirror of
https://github.com/reactos/reactos.git
synced 2025-02-23 00:45:24 +00:00
[MODE] Improve few points in the MODE command. Adapted from a patch by Katayama Hirofumi MZ. CORE-12894
This commit is contained in:
parent
bf3589a280
commit
22bf169288
1 changed files with 78 additions and 41 deletions
|
@ -46,7 +46,7 @@
|
||||||
|
|
||||||
/*** For fixes, see also network/net/main.c ***/
|
/*** For fixes, see also network/net/main.c ***/
|
||||||
// VOID PrintPadding(...)
|
// VOID PrintPadding(...)
|
||||||
INT
|
VOID
|
||||||
__cdecl
|
__cdecl
|
||||||
UnderlinedResPrintf(
|
UnderlinedResPrintf(
|
||||||
IN PCON_STREAM Stream,
|
IN PCON_STREAM Stream,
|
||||||
|
@ -69,50 +69,76 @@ UnderlinedResPrintf(
|
||||||
szMsgBuffer[i] = L'-';
|
szMsgBuffer[i] = L'-';
|
||||||
szMsgBuffer[Len] = UNICODE_NULL;
|
szMsgBuffer[Len] = UNICODE_NULL;
|
||||||
|
|
||||||
// FIXME: Use ConStreamWrite instead.
|
ConStreamWrite(Stream, szMsgBuffer, Len);
|
||||||
ConPuts(Stream, szMsgBuffer);
|
|
||||||
|
|
||||||
return Len;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int QueryDevices(VOID)
|
int QueryDevices(VOID)
|
||||||
{
|
{
|
||||||
WCHAR buffer[20240];
|
PWSTR Buffer, ptr;
|
||||||
WCHAR* ptr = buffer;
|
DWORD dwLen = MAX_PATH;
|
||||||
|
|
||||||
*ptr = L'\0';
|
/* Pre-allocate a buffer for QueryDosDeviceW() */
|
||||||
// FIXME: Dynamically allocate 'buffer' in a loop.
|
Buffer = HeapAlloc(GetProcessHeap(), 0, dwLen * sizeof(WCHAR));
|
||||||
if (QueryDosDeviceW(NULL, buffer, ARRAYSIZE(buffer)))
|
if (Buffer == NULL)
|
||||||
{
|
{
|
||||||
while (*ptr != L'\0')
|
/* We failed, bail out */
|
||||||
|
wprintf(L"ERROR: Not enough memory\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
*Buffer = UNICODE_NULL;
|
||||||
|
if (QueryDosDeviceW(NULL, Buffer, dwLen))
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
|
||||||
{
|
{
|
||||||
if (wcsstr(ptr, L"COM"))
|
/* We failed, bail out */
|
||||||
{
|
wprintf(L"ERROR: QueryDosDeviceW(...) failed: 0x%lx\n", GetLastError());
|
||||||
ConResPrintf(StdOut, IDS_QUERY_SERIAL_FOUND, ptr);
|
HeapFree(GetProcessHeap(), 0, Buffer);
|
||||||
}
|
return 0;
|
||||||
else if (wcsstr(ptr, L"PRN"))
|
}
|
||||||
{
|
|
||||||
ConResPrintf(StdOut, IDS_QUERY_PRINTER_FOUND, ptr);
|
/* The buffer was too small, try to re-allocate it */
|
||||||
}
|
dwLen *= 2;
|
||||||
else if (wcsstr(ptr, L"LPT"))
|
ptr = HeapReAlloc(GetProcessHeap(), 0, Buffer, dwLen * sizeof(WCHAR));
|
||||||
{
|
if (ptr == NULL)
|
||||||
ConResPrintf(StdOut, IDS_QUERY_PARALLEL_FOUND, ptr);
|
{
|
||||||
}
|
/* We failed, bail out */
|
||||||
else if (wcsstr(ptr, L"AUX") || wcsstr(ptr, L"NUL"))
|
wprintf(L"ERROR: Not enough memory\n");
|
||||||
{
|
HeapFree(GetProcessHeap(), 0, Buffer);
|
||||||
ConResPrintf(StdOut, IDS_QUERY_DOSDEV_FOUND, ptr);
|
return 0;
|
||||||
}
|
}
|
||||||
else
|
Buffer = ptr;
|
||||||
{
|
}
|
||||||
// ConResPrintf(StdOut, IDS_QUERY_MISC_FOUND, ptr);
|
|
||||||
}
|
for (ptr = Buffer; *ptr != UNICODE_NULL; ptr += wcslen(ptr) + 1)
|
||||||
ptr += (wcslen(ptr) + 1);
|
{
|
||||||
|
if (wcsstr(ptr, L"COM"))
|
||||||
|
{
|
||||||
|
ConResPrintf(StdOut, IDS_QUERY_SERIAL_FOUND, ptr);
|
||||||
|
}
|
||||||
|
else if (wcsstr(ptr, L"PRN"))
|
||||||
|
{
|
||||||
|
ConResPrintf(StdOut, IDS_QUERY_PRINTER_FOUND, ptr);
|
||||||
|
}
|
||||||
|
else if (wcsstr(ptr, L"LPT"))
|
||||||
|
{
|
||||||
|
ConResPrintf(StdOut, IDS_QUERY_PARALLEL_FOUND, ptr);
|
||||||
|
}
|
||||||
|
else if (wcsstr(ptr, L"AUX") || wcsstr(ptr, L"NUL"))
|
||||||
|
{
|
||||||
|
ConResPrintf(StdOut, IDS_QUERY_DOSDEV_FOUND, ptr);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// ConResPrintf(StdOut, IDS_QUERY_MISC_FOUND, ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
/* Free the buffer and return success */
|
||||||
wprintf(L"ERROR: QueryDosDeviceW(...) failed: 0x%lx\n", GetLastError());
|
HeapFree(GetProcessHeap(), 0, Buffer);
|
||||||
}
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +155,7 @@ int ShowParallelStatus(INT nPortNum)
|
||||||
|
|
||||||
if (QueryDosDeviceW(szPortName, buffer, ARRAYSIZE(buffer)))
|
if (QueryDosDeviceW(szPortName, buffer, ARRAYSIZE(buffer)))
|
||||||
{
|
{
|
||||||
WCHAR* ptr = wcsrchr(buffer, L'\\');
|
PWSTR ptr = wcsrchr(buffer, L'\\');
|
||||||
if (ptr != NULL)
|
if (ptr != NULL)
|
||||||
{
|
{
|
||||||
if (_wcsicmp(szPortName, ++ptr) == 0)
|
if (_wcsicmp(szPortName, ++ptr) == 0)
|
||||||
|
@ -1131,7 +1157,7 @@ int wmain(int argc, WCHAR* argv[])
|
||||||
*/
|
*/
|
||||||
ArgStrSize = 0;
|
ArgStrSize = 0;
|
||||||
|
|
||||||
/* Compute space needed for the new string, and allocate it */
|
/* Compute the space needed for the new string, and allocate it */
|
||||||
for (arg = 1; arg < argc; arg++)
|
for (arg = 1; arg < argc; arg++)
|
||||||
{
|
{
|
||||||
ArgStrSize += wcslen(argv[arg]) + 1; // 1 for space
|
ArgStrSize += wcslen(argv[arg]) + 1; // 1 for space
|
||||||
|
@ -1166,8 +1192,15 @@ int wmain(int argc, WCHAR* argv[])
|
||||||
}
|
}
|
||||||
else if (_wcsnicmp(argStr, L"/STA", 4) == 0)
|
else if (_wcsnicmp(argStr, L"/STA", 4) == 0)
|
||||||
{
|
{
|
||||||
// FIXME: Check if there are other "parameters" after the status,
|
/* Skip this parameter */
|
||||||
// in which case this is invalid.
|
while (*argStr != L' ') argStr++;
|
||||||
|
/* Skip any delimiter */
|
||||||
|
while (*argStr == L' ') argStr++;
|
||||||
|
|
||||||
|
/* The presence of any other parameter is invalid */
|
||||||
|
if (*argStr)
|
||||||
|
goto invalid_parameter;
|
||||||
|
|
||||||
goto show_status;
|
goto show_status;
|
||||||
}
|
}
|
||||||
else if (_wcsnicmp(argStr, L"LPT", 3) == 0)
|
else if (_wcsnicmp(argStr, L"LPT", 3) == 0)
|
||||||
|
@ -1179,7 +1212,11 @@ int wmain(int argc, WCHAR* argv[])
|
||||||
if (*argStr == L':') argStr++;
|
if (*argStr == L':') argStr++;
|
||||||
while (*argStr == L' ') argStr++;
|
while (*argStr == L' ') argStr++;
|
||||||
|
|
||||||
ret = ShowParallelStatus(nPortNum);
|
if (!*argStr || _wcsnicmp(argStr, L"/STA", 4) == 0)
|
||||||
|
ret = ShowParallelStatus(nPortNum);
|
||||||
|
else
|
||||||
|
wprintf(L"ERROR: LPT port redirection is not implemented!\n");
|
||||||
|
// TODO: Implement setting LPT port redirection using SetParallelState().
|
||||||
goto Quit;
|
goto Quit;
|
||||||
}
|
}
|
||||||
else if (_wcsnicmp(argStr, L"COM", 3) == 0)
|
else if (_wcsnicmp(argStr, L"COM", 3) == 0)
|
||||||
|
|
Loading…
Reference in a new issue