From 89e00ddbac20edb60fa0539d4d6fa871f122842c Mon Sep 17 00:00:00 2001 From: Robert Dickenson Date: Wed, 16 Oct 2002 01:45:49 +0000 Subject: [PATCH] Added some support for the MODE command. svn path=/trunk/; revision=3632 --- rosapps/cmdutils/mode/.cvsignore | 16 ++ rosapps/cmdutils/mode/makefile | 20 ++ rosapps/cmdutils/mode/mode.c | 332 +++++++++++++++++++++++++++++++ rosapps/cmdutils/mode/mode.rc | 45 +++++ 4 files changed, 413 insertions(+) create mode 100644 rosapps/cmdutils/mode/.cvsignore create mode 100644 rosapps/cmdutils/mode/makefile create mode 100644 rosapps/cmdutils/mode/mode.c create mode 100644 rosapps/cmdutils/mode/mode.rc diff --git a/rosapps/cmdutils/mode/.cvsignore b/rosapps/cmdutils/mode/.cvsignore new file mode 100644 index 00000000000..b8b4afb7e30 --- /dev/null +++ b/rosapps/cmdutils/mode/.cvsignore @@ -0,0 +1,16 @@ +*.sys +*.exe +*.dll +*.cpl +*.a +*.o +*.d +*.coff +*.dsp +*.dsw +*.aps +*.ncb +*.opt +*.sym +*.plg +*.bak diff --git a/rosapps/cmdutils/mode/makefile b/rosapps/cmdutils/mode/makefile new file mode 100644 index 00000000000..ef19da52f77 --- /dev/null +++ b/rosapps/cmdutils/mode/makefile @@ -0,0 +1,20 @@ + +PATH_TO_TOP=../../../reactos + +TARGET_TYPE = program + +TARGET_APPTYPE = console + +TARGET_NAME = mode + +TARGET_SDKLIBS = ntdll.a + +TARGET_OBJECTS = $(TARGET_NAME).o + +#TARGET_GCCLIBS = iberty + +include $(PATH_TO_TOP)/rules.mak + +include $(TOOLS_PATH)/helper.mk + +# EOF diff --git a/rosapps/cmdutils/mode/mode.c b/rosapps/cmdutils/mode/mode.c new file mode 100644 index 00000000000..aa6b3560900 --- /dev/null +++ b/rosapps/cmdutils/mode/mode.c @@ -0,0 +1,332 @@ +/* + * ReactOS mode console command + * + * mode.c + * + * Copyright (C) 2002 Robert Dickenson + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include +#include + +#define MAX_PORTNAME_LEN 20 +#define MAX_COMPORT_NUM 10 + +#define NUM_ELEMENTS(a) (sizeof(a)/sizeof(a[0])) +#define ASSERT(a) + +const char* usage_strings[] = { + "Device Status: MODE [device] [/STATUS]", + "Select code page: MODE CON[:] CP SELECT=yyy", + "Code page status: MODE CON[:] CP [/STATUS]", + "Display mode: MODE CON[:] [COLS=c] [LINES=n]", + "Typematic rate: MODE CON[:] [RATE=r DELAY=d]", + "Redirect printing: MODE LPTn[:]=COMm[:]", + "Serial port: MODE COMm[:] [BAUD=b] [PARITY=p] [DATA=d] [STOP=s]\n" \ + " [to=on|off] [xon=on|off] [odsr=on|off]\n" \ + " [octs=on|off] [dtr=on|off|hs]\n" \ + " [rts=on|off|hs|tg] [idsr=on|off]", +}; + +const char* parity_strings[] = { + _T("None"), + _T("Odd"), + _T("Even"), + _T("Mark"), + _T("Space") +}; + +const char* stopbit_strings[] = { _T("1"), _T("1.5"), _T("2") }; + + +int Usage() +{ + int i; + + printf("\nConfigures system devices.\n\n"); + for (i = 0; i < sizeof(usage_strings)/sizeof(usage_strings[0]); i++) { + printf("%s\n", usage_strings[i]); + } + printf("\n"); + return 0; +} + +int ShowParrallelStatus(int nPortNum) +{ + TCHAR buffer[250]; + + printf("\nStatus for device LPT%d:\n", nPortNum); + printf("-----------------------\n"); + + if (QueryDosDevice("LPT1", buffer, sizeof(buffer)/sizeof(TCHAR))) { + printf(" %s.\n", buffer); + } else { + //printf(" Printer output is not being rerouted.\n"); + } + printf(" Printer output is not being rerouted.\n"); +/* +DWORD QueryDosDevice( + LPCTSTR lpDeviceName, // MS-DOS device name string + LPTSTR lpTargetPath, // query results buffer + DWORD ucchMax // maximum size of buffer +); + */ + return 0; +} + +int ShowConsoleStatus() +{ + DWORD dwKbdDelay; + DWORD dwKbdSpeed; + CONSOLE_SCREEN_BUFFER_INFO ConsoleScreenBufferInfo; + HANDLE hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE); + + printf("\nStatus for device CON:\n"); + printf("-----------------------\n"); + if (GetConsoleScreenBufferInfo(hConsoleOutput, &ConsoleScreenBufferInfo)) { + printf(" Lines: %d\n", ConsoleScreenBufferInfo.dwSize.Y); + printf(" Columns: %d\n", ConsoleScreenBufferInfo.dwSize.X); + } + if (SystemParametersInfo(SPI_GETKEYBOARDDELAY, 0, &dwKbdDelay, 0)) { + printf(" Keyboard delay: %d\n", dwKbdDelay); + } + if (SystemParametersInfo(SPI_GETKEYBOARDSPEED, 0, &dwKbdSpeed, 0)) { + printf(" Keyboard rate: %d\n", dwKbdSpeed); + } + printf(" Code page: %d\n", GetConsoleOutputCP()); + return 0; +} + +static +BOOL GetComData(int nPortNum, LPDCB pDCB, LPCOMMTIMEOUTS pCommTimeouts) +{ + HANDLE hPort; + TCHAR szPortName[MAX_PORTNAME_LEN]; + + ASSERT(pDCB); + ASSERT(pCommTimeouts); + + sprintf(szPortName, _T("COM%d"), nPortNum); + hPort = CreateFile(szPortName, + GENERIC_READ|GENERIC_WRITE, + 0, // exclusive + NULL, // sec attr + OPEN_EXISTING, + 0, // no attributes + NULL); // no template + + if (hPort == (HANDLE)-1) { + printf("Illegal device name - %s\n", szPortName); + return FALSE; + } + if (!GetCommState(hPort, pDCB)) { + printf("Failed to get the status for device COM%d:\n", nPortNum); + CloseHandle(hPort); + return FALSE; + } + if (!GetCommTimeouts(hPort, pCommTimeouts)) { + printf("Failed to get Timeout status for device COM%d:\n", nPortNum); + CloseHandle(hPort); + return FALSE; + } + CloseHandle(hPort); + return TRUE; +} + +int ShowSerialStatus(int nPortNum) +{ + HANDLE hPort; + DCB dcb; + COMMTIMEOUTS CommTimeouts; + TCHAR szPortName[MAX_PORTNAME_LEN]; + + sprintf(szPortName, _T("COM%d"), nPortNum); + hPort = CreateFile(szPortName, + GENERIC_READ|GENERIC_WRITE, + 0, // exclusive + NULL, // sec attr + OPEN_EXISTING, + 0, // no attributes + NULL); // no template + + if (hPort == (HANDLE)-1) { + //printf("Illegal device name - %s\n", szPortName); + return 1; + } + dcb.DCBlength = sizeof(dcb); + if (!GetCommState(hPort, &dcb)) { + printf("Failed to get the status for device COM%d:\n", nPortNum); + CloseHandle(hPort); + return 1; + } + if (!GetCommTimeouts(hPort, &CommTimeouts)) { + printf("Failed to get Timeout status for device COM%d:\n", nPortNum); + CloseHandle(hPort); + return 1; + } + CloseHandle(hPort); + + if (dcb.Parity > NUM_ELEMENTS(parity_strings)) { + printf("ERROR: Invalid value for Parity Bits %d:\n", dcb.Parity); + dcb.Parity = 0; + } + if (dcb.StopBits > NUM_ELEMENTS(stopbit_strings)) { + printf("ERROR: Invalid value for Stop Bits %d:\n", dcb.StopBits); + dcb.StopBits = 0; + } + printf("\nStatus for device COM%d:\n", nPortNum); + printf("-----------------------\n"); + printf(" Baud: %d\n", dcb.BaudRate); + printf(" Parity: %s\n", parity_strings[dcb.Parity]); + printf(" Data Bits: %d\n", dcb.ByteSize); + printf(" Stop Bits: %s\n", stopbit_strings[dcb.StopBits]); + printf(" Timeout: %s\n", CommTimeouts.ReadIntervalTimeout ? "ON" : "OFF"); + printf(" XON/XOFF: %s\n", dcb.fOutX ? "ON" : "OFF"); + printf(" CTS handshaking: %s\n", dcb.fOutxCtsFlow ? "ON" : "OFF"); + printf(" DSR handshaking: %s\n", dcb.fOutxDsrFlow ? "ON" : "OFF"); + printf(" DSR sensitivity: %s\n", dcb.fDsrSensitivity ? "ON" : "OFF"); + printf(" DTR circuit: %s\n", dcb.fDtrControl ? "ON" : "OFF"); + printf(" RTS circuit: %s\n", dcb.fRtsControl ? "ON" : "OFF"); + return 0; +} + +int SetParrallelState(int nPortNum) +{ + return 0; +} + +int SetConsoleState() +{ + return 0; +} + +static +int GetComParameterData(const char* param) +{ + if (strstr(param, "off")) { + return 0; + } else if (strstr(param, "on")) { + return 1; + } else if (strstr(param, "hs")) { + return 2; + } else if (strstr(param, "tg")) { + return 3; + } + return -1; +} + +int SetSerialState(int nPortNum, int args, char *argv[]) +{ + int Baud = 1200; +// int Parity = None; + int DataBits = 7; + int StopBits = 1; + BOOL bTimeout = FALSE; + BOOL bXonXoff = FALSE; + BOOL bCTShandshaking = FALSE; + BOOL bDSRhandshaking = FALSE; + BOOL bDSRsensitivity = FALSE; + BOOL bDTRcircuit = TRUE; + BOOL bRTScircuit = TRUE; + + int arg; + + DCB dcb; + COMMTIMEOUTS CommTimeouts; + int value; + char* ptr; + + if (GetComData(nPortNum, &dcb, &CommTimeouts)) { + for (arg = 0; arg < args; arg++) { + ptr = argv[arg]; + printf("Parsing arg %d - %s\n", arg, ptr); + + if (strstr(ptr, "BAUD=")) { + } else if (strstr(ptr, "PARITY=")) { + } else if (strstr(ptr, "DATA=")) { + } else if (strstr(ptr, "STOP=")) { + } else if (strstr(ptr, "to=")) { + value = GetComParameterData(ptr); + } else if (strstr(ptr, "xon=")) { + value = GetComParameterData(ptr); + } else if (strstr(ptr, "odsr=")) { + value = GetComParameterData(ptr); + } else if (strstr(ptr, "octs=")) { + value = GetComParameterData(ptr); + } else if (strstr(ptr, "dtr=")) { + value = GetComParameterData(ptr); + } else if (strstr(ptr, "rts=")) { + value = GetComParameterData(ptr); + } else if (strstr(ptr, "idsr=")) { + value = GetComParameterData(ptr); + } else { + } + } + } +/* + "Serial port: MODE COMm[:] [BAUD=b] [PARITY=p] [DATA=d] [STOP=s]\n" \ + " [to=on|off] [xon=on|off] [odsr=on|off]\n" \ + " [octs=on|off] [dtr=on|off|hs]\n" \ + " [rts=on|off|hs|tg] [idsr=on|off]", + + */ + return 0; +} + +int find_portnum(const char* cmdverb) +{ + int portnum = -1; + + if ((char)*(cmdverb + 3) >= '0' && (char)*(cmdverb + 3) <= '9') { + portnum = ((char)*(cmdverb + 3)) - '0'; + if ((char)*(cmdverb + 4) >= '0' && (char)*(cmdverb + 4) <= '9') { + portnum *= 10; + portnum += ((char)*(cmdverb + 4)) - '0'; + } + } + return portnum; +} + +int main(int argc, char *argv[]) +{ + int nPortNum; + + if (argc > 1) { + if (strstr(argv[1], "/?")) { + return Usage(); + } else if (strstr(argv[1], "LPT")) { + nPortNum = find_portnum(argv[1]); + if (nPortNum != -1) + return ShowParrallelStatus(nPortNum); + } else if (strstr(argv[1], "CON")) { + return ShowConsoleStatus(); + } else if (strstr(argv[1], "COM")) { + nPortNum = find_portnum(argv[1]); + if (nPortNum != -1) + return ShowSerialStatus(nPortNum); + } + printf("Invalid parameter - %s\n", argv[1]); + return 1; + } else { + ShowParrallelStatus(1); + for (nPortNum = 0; nPortNum < MAX_COMPORT_NUM; nPortNum++) { + ShowSerialStatus(nPortNum + 1); + } + ShowConsoleStatus(); + } + return 0; +} diff --git a/rosapps/cmdutils/mode/mode.rc b/rosapps/cmdutils/mode/mode.rc new file mode 100644 index 00000000000..3a2bd29a729 --- /dev/null +++ b/rosapps/cmdutils/mode/mode.rc @@ -0,0 +1,45 @@ +#include +#include + +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US + +VS_VERSION_INFO VERSIONINFO + FILEVERSION RES_UINT_FV_MAJOR,RES_UINT_FV_MINOR,RES_UINT_FV_REVISION,RES_UINT_FV_BUILD + PRODUCTVERSION RES_UINT_PV_MAJOR,RES_UINT_PV_MINOR,RES_UINT_PV_REVISION,RES_UINT_PV_BUILD + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x40004L + FILETYPE 0x2L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "Comments", "Absolutely no warranties whatsoever - Use at your own risk\0" + VALUE "CompanyName", RES_STR_COMPANY_NAME + VALUE "FileDescription", "ReactOS mode utility\0" + VALUE "FileVersion", RES_STR_FILE_VERSION + VALUE "InternalName", "mode\0" + VALUE "LegalCopyright", RES_STR_LEGAL_COPYRIGHT + VALUE "OriginalCopyright", RES_STR_LEGAL_COPYRIGHT + VALUE "Copyright", "Copyright © 2002 Robert Dickenson\0" + VALUE "Maintainer", "Robert Dickenson (robd@users.sourceforge.net)\0" + VALUE "LegalTrademarks", "\0" + VALUE "PrivateBuild", "\0" + VALUE "OriginalFilename", "mode.exe\0" + VALUE "ProductName", RES_STR_PRODUCT_NAME + VALUE "ProductVersion", RES_STR_PRODUCT_VERSION + VALUE "SpecialBuild", "Non-versioned Development Beta Release\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END +