diff --git a/rosapps/cmd/cmd.h b/rosapps/cmd/cmd.h index 38e9bcc37f6..3ade9917a9e 100644 --- a/rosapps/cmd/cmd.h +++ b/rosapps/cmd/cmd.h @@ -30,7 +30,7 @@ #include -#define CMD_VER "0.1 pre 5" +#define CMD_VER "0.1 pre 6" #ifdef _MSC_VER #define SHELLVER "Version " CMD_VER " [" __DATE__ ", msc]" @@ -259,6 +259,8 @@ extern TCHAR cDecimalSeparator; extern INT nNumberGroups; VOID InitLocale (VOID); +VOID PrintDate (VOID); +VOID PrintTime (VOID); /* Prototypes for MISC.C */ @@ -277,6 +279,10 @@ BOOL FileGetString (HANDLE, LPTSTR, INT); INT cmd_move (LPTSTR, LPTSTR); +/* Prototypes for MSGBOX.C */ +INT CommandMsgbox (LPTSTR, LPTSTR); + + /* Prototypes from PATH.C */ INT cmd_path (LPTSTR, LPTSTR); @@ -311,6 +317,10 @@ INT cmd_start (LPTSTR, LPTSTR); INT cmd_time (LPTSTR, LPTSTR); +/* Prototypes for TIMER.C */ +INT CommandTimer (LPTSTR cmd, LPTSTR param); + + /* Prototypes for TITLE.C */ INT cmd_title (LPTSTR, LPTSTR); diff --git a/rosapps/cmd/cmdtable.c b/rosapps/cmd/cmdtable.c index d0f7d3a53c5..6a8c85d2949 100644 --- a/rosapps/cmd/cmdtable.c +++ b/rosapps/cmd/cmdtable.c @@ -131,6 +131,11 @@ COMMAND cmds[] = {_T("move"), 0, cmd_move}, #endif + +#ifdef INCLUDE_CMD_MSGBOX + {_T("msgbox"), 0, CommandMsgbox}, +#endif + #ifdef INCLUDE_CMD_PATH {_T("path"), 0, cmd_path}, #endif @@ -182,6 +187,10 @@ COMMAND cmds[] = {_T("time"), 0, cmd_time}, #endif +#ifdef INCLUDE_CMD_TIMER + {_T("timer"), 0, CommandTimer}, +#endif + #ifdef INCLUDE_CMD_TITLE {_T("title"), 0, cmd_title}, #endif diff --git a/rosapps/cmd/config.h b/rosapps/cmd/config.h index 0f7808bc8bd..169ef770e68 100644 --- a/rosapps/cmd/config.h +++ b/rosapps/cmd/config.h @@ -72,6 +72,9 @@ #define INCLUDE_CMD_LABEL #define INCLUDE_CMD_MKDIR #define INCLUDE_CMD_MOVE +#ifndef __REACTOS__ +#define INCLUDE_CMD_MSGBOX +#endif #define INCLUDE_CMD_PATH #define INCLUDE_CMD_PROMPT #define INCLUDE_CMD_RMDIR @@ -79,6 +82,7 @@ #define INCLUDE_CMD_SET #define INCLUDE_CMD_START #define INCLUDE_CMD_TIME +#define INCLUDE_CMD_TIMER #define INCLUDE_CMD_TITLE #define INCLUDE_CMD_TYPE #define INCLUDE_CMD_VER diff --git a/rosapps/cmd/console.c b/rosapps/cmd/console.c index 68919e06cea..62f80a64922 100644 --- a/rosapps/cmd/console.c +++ b/rosapps/cmd/console.c @@ -19,11 +19,13 @@ #include "cmd.h" +#define OUTPUT_BUFFER_SIZE 4096 + #ifdef _DEBUG VOID DebugPrintf (LPTSTR szFormat, ...) { - TCHAR szOut[512]; + TCHAR szOut[OUTPUT_BUFFER_SIZE]; va_list arg_ptr; DWORD dwWritten; @@ -135,7 +137,7 @@ VOID ConOutPuts (LPTSTR szText) VOID ConOutPrintf (LPTSTR szFormat, ...) { DWORD dwWritten; - TCHAR szOut[256]; + TCHAR szOut[OUTPUT_BUFFER_SIZE]; va_list arg_ptr; va_start (arg_ptr, szFormat); @@ -169,7 +171,7 @@ VOID ConErrPuts (LPTSTR szText) VOID ConErrPrintf (LPTSTR szFormat, ...) { DWORD dwWritten; - TCHAR szOut[4096]; + TCHAR szOut[OUTPUT_BUFFER_SIZE]; va_list arg_ptr; va_start (arg_ptr, szFormat); diff --git a/rosapps/cmd/date.c b/rosapps/cmd/date.c index 24b271dd0df..ec65045a9fd 100644 --- a/rosapps/cmd/date.c +++ b/rosapps/cmd/date.c @@ -47,42 +47,6 @@ static WORD awMonths[2][13] = }; -static VOID -PrintDate (VOID) -{ -#ifdef __REACTOS__ - SYSTEMTIME st; - - GetLocalTime (&st); - - switch (nDateFormat) - { - case 0: /* mmddyy */ - default: - ConOutPrintf (_T("Current date is: %s %02d%c%02d%c%04d\n"), - aszDayNames[st.wDayOfWeek], st.wMonth, cDateSeparator, st.wDay, cDateSeparator, st.wYear); - break; - - case 1: /* ddmmyy */ - ConOutPrintf (_T("Current date is: %s %02d%c%02d%c%04d\n"), - aszDayNames[st.wDayOfWeek], st.wDay, cDateSeparator, st.wMonth, cDateSeparator, st.wYear); - break; - - case 2: /* yymmdd */ - ConOutPrintf (_T("Current date is: %s %04d%c%02d%c%02d\n"), - aszDayNames[st.wDayOfWeek], st.wYear, cDateSeparator, st.wMonth, cDateSeparator, st.wDay); - break; - } -#else - TCHAR szDate[32]; - - GetDateFormat (LOCALE_USER_DEFAULT, DATE_SHORTDATE, NULL, NULL, - szDate, sizeof (szDate)); - ConOutPrintf (_T("Current date is: %s\n"), szDate); -#endif -} - - static VOID PrintDateString (VOID) { @@ -90,17 +54,17 @@ PrintDateString (VOID) { case 0: /* mmddyy */ default: - ConOutPrintf (_T("Enter new date (mm%cdd%cyyyy): "), + ConOutPrintf (_T("\nEnter new date (mm%cdd%cyyyy): "), cDateSeparator, cDateSeparator); break; case 1: /* ddmmyy */ - ConOutPrintf (_T("Enter new date (dd%cmm%cyyyy): "), + ConOutPrintf (_T("\nEnter new date (dd%cmm%cyyyy): "), cDateSeparator, cDateSeparator); break; case 2: /* yymmdd */ - ConOutPrintf (_T("Enter new date (yyyy%cmm%cdd): "), + ConOutPrintf (_T("\nEnter new date (yyyy%cmm%cdd): "), cDateSeparator, cDateSeparator); break; } diff --git a/rosapps/cmd/files.txt b/rosapps/cmd/files.txt index d7eb1e2fba8..1d26cab0a3f 100644 --- a/rosapps/cmd/files.txt +++ b/rosapps/cmd/files.txt @@ -42,6 +42,7 @@ internal.c Internal commands (DIR, RD, etc) label.c Implements label command locale.c Locale handling code misc.c Misc. Functions +msgbox.c Implements msgbox command move.c Implements move command path.c Implements path command pause.c Implements pause command @@ -51,6 +52,7 @@ ren.c Implements rename command set.c Implements set command shift.c Implements shift command time.c Implements time command +timer.c Implements timer command type.c Implements type command ver.c Implements ver command where.c Code to search path for executables diff --git a/rosapps/cmd/history.txt b/rosapps/cmd/history.txt index 310a754806b..b1ae41e109a 100644 --- a/rosapps/cmd/history.txt +++ b/rosapps/cmd/history.txt @@ -344,7 +344,7 @@ o Added CHCP command. o Fixed keyboard input bug. o Rewrote DEL and MOVE commands. -19-Aug-1999 ReactOS CMD version 0.1 pre 5 (Eric Kohl ) +29-Aug-1999 ReactOS CMD version 0.1 pre 6 (Eric Kohl ) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ o Cleaned up DIR command. o Searching for executables in the right order. @@ -352,3 +352,6 @@ o Fixed some little but nasty bugs. o Added TITLE command. Thanks to Emanuele Aliberti! o Added "/Q", "/W" and "/Z" options to DEL command. o Added CHOICE command. +o Added TIMER command. +o Added MSGBOX command (not available under ReactOS). + diff --git a/rosapps/cmd/locale.c b/rosapps/cmd/locale.c index d7c2cdc3e59..2751719b642 100644 --- a/rosapps/cmd/locale.c +++ b/rosapps/cmd/locale.c @@ -114,3 +114,71 @@ VOID InitLocale (VOID) _tcscpy (aszDayNames[i], names[i]); #endif } + + +VOID PrintDate (VOID) +{ +#ifdef __REACTOS__ + SYSTEMTIME st; + + GetLocalTime (&st); + + switch (nDateFormat) + { + case 0: /* mmddyy */ + default: + ConOutPrintf (_T("%s %02d%c%02d%c%04d"), + aszDayNames[st.wDayOfWeek], st.wMonth, cDateSeparator, st.wDay, cDateSeparator, st.wYear); + break; + + case 1: /* ddmmyy */ + ConOutPrintf (_T("%s %02d%c%02d%c%04d"), + aszDayNames[st.wDayOfWeek], st.wDay, cDateSeparator, st.wMonth, cDateSeparator, st.wYear); + break; + + case 2: /* yymmdd */ + ConOutPrintf (_T("%s %04d%c%02d%c%02d"), + aszDayNames[st.wDayOfWeek], st.wYear, cDateSeparator, st.wMonth, cDateSeparator, st.wDay); + break; + } +#else + TCHAR szDate[32]; + + GetDateFormat (LOCALE_USER_DEFAULT, DATE_SHORTDATE, NULL, NULL, + szDate, sizeof (szDate)); + ConOutPrintf (_T("%s"), szDate); +#endif +} + + +VOID PrintTime (VOID) +{ +#ifdef __REACTOS__ + SYSTEMTIME st; + + GetLocalTime (&st); + + switch (nTimeFormat) + { + case 0: /* 12 hour format */ + default: + ConOutPrintf (_T("Current time is %2d%c%02d%c%02d%c%02d%c\n"), + (st.wHour == 0 ? 12 : (st.wHour <= 12 ? st.wHour : st.wHour - 12)), + cTimeSeparator, st.wMinute, cTimeSeparator, st.wSecond, cDecimalSeparator, + st.wMilliseconds / 10, (st.wHour <= 11 ? 'a' : 'p')); + break; + + case 1: /* 24 hour format */ + ConOutPrintf (_T("Current time is %2d%c%02d%c%02d%c%02d\n"), + st.wHour, cTimeSeparator, st.wMinute, cTimeSeparator, + st.wSecond, cDecimalSeparator, st.wMilliseconds / 10); + break; + } +#else + TCHAR szTime[32]; + + GetTimeFormat (LOCALE_USER_DEFAULT, 0, NULL, NULL, + szTime, sizeof (szTime)); + ConOutPrintf (_T("Current time is: %s\n"), szTime); +#endif +} diff --git a/rosapps/cmd/makefile b/rosapps/cmd/makefile index 688cbafa41b..e9dfee04fab 100644 --- a/rosapps/cmd/makefile +++ b/rosapps/cmd/makefile @@ -7,9 +7,9 @@ all: cmd.exe OBJECTS = cmd.o attrib.o alias.o batch.o beep.o call.o chcp.o choice.o \ cls.o cmdinput.o cmdtable.o color.o console.o copy.o date.o del.o \ dir.o dirstack.o echo.o error.o filecomp.o for.o goto.o history.o \ - if.o internal.o label.o locale.o misc.o move.o path.o pause.o \ - prompt.o redir.o ren.o set.o shift.o start.o time.o title.o \ - type.o ver.o verify.o vol.o where.o + if.o internal.o label.o locale.o misc.o move.o msgbox.o path.o \ + pause.o prompt.o redir.o ren.o set.o shift.o start.o time.o \ + timer.o title.o type.o ver.o verify.o vol.o where.o CLEAN_FILES = *.o cmd.exe cmd.sym diff --git a/rosapps/cmd/msgbox.c b/rosapps/cmd/msgbox.c new file mode 100644 index 00000000000..2703ae65253 --- /dev/null +++ b/rosapps/cmd/msgbox.c @@ -0,0 +1,256 @@ +/* + * MSGBOX.C - msgbox internal command. + * + * clone from 4nt msgbox command + * + * 25 Aug 1999 + * started - Dr.F + */ + +#include "config.h" + +#ifdef INCLUDE_CMD_MSGBOX +#include +#include +#include +#include +#include "cmd.h" +//#include + +//#include + + +#define U_TYPE_INIT 0 + +//undefine it to allow to omit arguments +//that will be replaced by default ones +#define _SYNTAX_CHECK + +INT CommandMsgbox (LPTSTR cmd, LPTSTR param) +{ + + //used to parse command line + LPTSTR tmp; + + +#if 0 + //command line parsing stuff + LPTSTR *p; + INT argc; + INT i; +#endif + + //used to find window title (used as messagebox title) + //and to find window handle to pass to MessageBox + HWND hWnd; + TCHAR buff[2048]; + + //these are MessabeBox() parameters + LPTSTR title, prompt=""; + UINT uType=U_TYPE_INIT; + + + + + + //set default title to window title + GetConsoleTitle(buff,2048); + title = buff; + + + + + + if (_tcsncmp (param, _T("/?"), 2) == 0) + { + ConOutPuts(_T( + "display a message box and return user responce\n" +"\n" + "MSGBOX type [\"title\"] prompt\n" +"\n" + "type button displayed\n" + " possible values are: OK, OKCANCEL,\n" + " YESNO, YESNOCANCEL\n" + "title title of message box\n" + "prompt text displayed by the message box\n" +"\n" +"\n" + "ERRORLEVEL is set according the button pressed:\n" +"\n" + "YES : 10 | NO : 11\n" + "OK : 10 | CANCEL : 12\n" + )); + return 0; + } + + + + //yes here things are quite massed up :) + + + //skip spaces + while(_istspace(*param)) + param++; + + + + //serch for messagebox type (ok, okcancel, ...) + if (_tcsnicmp(param, _T("ok "),3 ) == 0) + { + uType |= MB_ICONEXCLAMATION | MB_OK; + param+=3; + } + else if (_tcsnicmp(param, _T("okcancel "),9 ) == 0) + { + uType |= MB_ICONQUESTION | MB_OKCANCEL; + param+=9; + } + else if (_tcsnicmp(param, _T("yesno "),6 ) == 0) + { + uType |= MB_ICONQUESTION | MB_YESNO; + param+=6; + } + else if (_tcsnicmp(param, _T("yesnocancel "), 12 ) == 0) + { + uType |= MB_ICONQUESTION | MB_YESNOCANCEL; + param+=12; + } + else{ +#ifdef _SYNTAX_CHECK + error_req_param_missing (); + return 1; +#else + uType |= MB_ICONEXCLAMATION | MB_OK; +#endif + } + + + //skip spaces + while(_istspace(*param)) + param++; + +#ifdef _SYNTAX_CHECK + //if reache end of string + //it is an error becuase we do not yet have prompt + if ( *param == 0) + { + error_req_param_missing (); + return 1; + } +#endif + + //serche for "title" + tmp = param; + + if(*param == '"') + { + tmp = _tcschr(param+1,'"'); + if (tmp) + { + *tmp = 0; + title = param+1; + tmp++; + param = tmp; + } + } + + + + //skip spaces + while(_istspace(*param)) + param++; +#ifdef _SYNTAX_CHECK + //get prompt + if ( *param == 0) + { + error_req_param_missing (); + return 1; + } +#endif + + prompt = param; + + + +#if 0 + p=split(param,&argc); + + for(i=0;i + */ + +#include "config.h" + +#ifdef INCLUDE_CMD_TIMER +#include "cmd.h" + +#include +#include +#include +#include + + +#define NCS_NOT_SPECIFIED -1 +#define NCS_ON 1 +#define NCS_OFF 0 + + + +//print timer status +#define PS ConOutPrintf("Timer %d is %s: ",clk_n,cS?"ON":"OFF"); \ + PrintTime() + +//print timer value +#define PT(format) PrintElapsedTime(GetTickCount()-cT,format) + + +//current timer Time (at wich started to count) +#define cT clksT[clk_n] + +//current timer status +#define cS clksS[clk_n] + + +static VOID +PrintElapsedTime (DWORD time,INT format) +{ + + DWORD h,m,s,ms; + +#ifdef _DEBUG + DebugPrintf("PrintTime(%d,%d)",time,format); +#endif + + switch (format) + { + case 0: + ConOutPrintf("Elapsed %d msecs\n",time); + break; + + case 1: + ms = time % 1000; + time /= 1000; + s = time % 60; + time /=60; + m = time % 60; + h = time / 60; + ConOutPrintf("Elapsed %02d%c%02d%c%02d%c%02d\n", + h,cTimeSeparator, + m,cTimeSeparator, + s,cDecimalSeparator,ms/10); + break; + } +} + + +INT CommandTimer (LPTSTR cmd, LPTSTR param) +{ + //here are kept all timers + static DWORD clksT[10]; + + //timers status + //set all the clocks off by default + static BOOL clksS[10]={FALSE,FALSE,FALSE,FALSE, + FALSE,FALSE,FALSE,FALSE,FALSE,FALSE}; + + //TRUE if /S in command line + BOOL bS = FALSE; + + //avoid to set clk_n more than once + BOOL bCanNSet = TRUE; + + INT NewClkStatus = NCS_NOT_SPECIFIED; + + //the clock number specified on the command line + //1 by default + INT clk_n=1; + + // output format + INT iFormat=1; + + + // command line parsing variables + INT argc; + LPTSTR *p; + + INT i; + + if (_tcsncmp (param, _T("/?"), 2) == 0) + { + ConOutPrintf(_T( + "allow the use of ten stopwaches.\n" + "\n" + "TIMER [ON|OFF] [/S] [/n] [/Fn]\n" + "\n" + " ON set stopwach ON\n" + " OFF set stopwach OFF\n" + " /S Split time. Return stopwach split\n" + " time without changing its value\n" + " /n Specifiy the stopwach number.\n" + " Stopwaches avaliable are 0 to 10\n" + " If it is not specified default is 1\n" + " /Fn Format for output\n" + " n can be:\n" + " 0 milliseconds\n" + " 1 hh%cmm%css%cdd\n" + "\n"), + cTimeSeparator,cTimeSeparator,cDecimalSeparator); + + ConOutPrintf(_T( + "if none of ON, OFF or /S is specified the command\n" + "will toggle stopwach state\n" + "\n")); + return 0; + } + + + p = split (param,&argc); + +//read options + for (i = 0; i < argc; i++) + { + //set timer on + if (!(_tcsicmp(&p[i][0],"on")) && NewClkStatus == NCS_NOT_SPECIFIED) + { + NewClkStatus = NCS_ON; + continue; + } + + //set timer off + if (!(_tcsicmp(&p[i][0],"off")) && NewClkStatus == NCS_NOT_SPECIFIED) + { + NewClkStatus = NCS_OFF; + continue; + } + + //other options + if (p[i][0] == _T('/')) + { + + //set timer number + if (_istdigit(p[i][1]) && bCanNSet) + { + clk_n = p[i][1] - _T('0'); + bCanNSet = FALSE; + continue; + } + + //set s(plit) option + if (_totupper(p[i][1]) == _T('S')) + { + bS = TRUE; + continue; + } + + //specify format + if(_totupper(p[i][1]) == _T('F')) + { + iFormat = p[i][2] - _T('0'); + continue; + + } + } + } + + + //do stuff (start/stop/read timer) + if(NewClkStatus == NCS_ON) + { + cT=GetTickCount(); + cS=TRUE; + PS; + freep(p); + return 0; + } + + if(bS) + { + if(cS) + { + PS; + PrintElapsedTime(GetTickCount()-cT, iFormat); + freep(p); + return 0; + } + + cT=GetTickCount(); + cS=TRUE; + PS; + freep(p); + return 0; + } + + if(NewClkStatus == NCS_NOT_SPECIFIED) + { + if(cS){ + cS=FALSE; + PS; + PrintElapsedTime(GetTickCount()-cT, iFormat); + freep(p); + return 0; + } + + cT=GetTickCount(); + cS=TRUE; + PS; + freep(p); + return 0; + } + + + if(NewClkStatus == NCS_OFF) + { + if(cS) + { + cS=FALSE; + PS; + PrintElapsedTime(GetTickCount()-cT, iFormat); + freep(p); + return 0; + } + PS; + freep(p); + return 0; + } + + freep(p); + return 0; +} + +#endif /* INCLUDE_CMD_TIMER */ +