Minor updates and fixes.

svn path=/trunk/; revision=674
This commit is contained in:
Eric Kohl 1999-09-27 22:15:44 +00:00
parent 1241612f69
commit 56e30e8907
5 changed files with 185 additions and 102 deletions

View file

@ -4,11 +4,14 @@
* *
* History: * History:
* *
* 12-Aug-1999 (Eric Kohl) * 12 Aug 1999 (Eric Kohl)
* Started. * started.
* *
* 01 Sep 1999 (Eric Kohl) * 01 Sep 1999 (Eric Kohl)
* Fixed help text. * Fixed help text.
*
* 26 Sep 1999 (Paolo Pantaleo)
* Fixed timeout.
*/ */
#include "config.h" #include "config.h"
@ -25,11 +28,63 @@
#include "batch.h" #include "batch.h"
#define GC_TIMEOUT -1
#define GC_NOKEY 0 //an event occurred but it wasn't a key pressed
#define GC_KEYREAD 1 //a key has been read
static INT
GetCharacterTimeout (LPTCH ch, DWORD dwMilliseconds)
{
//--------------------------------------------
// Get a character from standard input but with a timeout.
// The function will wait a limited amount
// of time, then the function returns GC_TIMEOUT.
//
// dwMilliseconds is the timeout value, that can
// be set to INFINITE, so the function works like
// stdio.h's getchar()
HANDLE hInput;
DWORD dwRead;
INPUT_RECORD lpBuffer;
hInput = GetStdHandle (STD_INPUT_HANDLE);
#ifdef _DEBUG
if (hInput == INVALID_HANDLE_VALUE)
DebugPrintf ("Invalid input handle!!!\n");
#endif
//if the timeout experied return GC_TIMEOUT
if (WaitForSingleObject (hInput, dwMilliseconds) == WAIT_TIMEOUT)
return GC_TIMEOUT;
//otherwise get the event
ReadConsoleInput (hInput, &lpBuffer, 1, &dwRead);
//if the event is a key pressed
if ((lpBuffer.EventType == KEY_EVENT) &&
(lpBuffer.Event.KeyEvent.bKeyDown == TRUE))
{
//read the key
#ifdef _UNICODE
*ch = lpBuffer.Event.KeyEvent.uChar.UnicodeChar;
#else
*ch = lpBuffer.Event.KeyEvent.uChar.AsciiChar;
#endif
return GC_KEYREAD;
}
//else return no key
return GC_NOKEY;
}
static INT static INT
IsKeyInString (LPTSTR lpString, TCHAR cKey, BOOL bCaseSensitive) IsKeyInString (LPTSTR lpString, TCHAR cKey, BOOL bCaseSensitive)
{ {
LPTSTR p = lpString; LPTCH p = lpString;
INT val = 0; INT val = 0;
while (*p) while (*p)
{ {
@ -69,6 +124,10 @@ CommandChoice (LPTSTR cmd, LPTSTR param)
INT i; INT i;
INT val; INT val;
INT GCret;
TCHAR Ch;
DWORD amount,clk;
if (_tcsncmp (param, _T("/?"), 2) == 0) if (_tcsncmp (param, _T("/?"), 2) == 0)
{ {
ConOutPuts (_T("Waits for the user to choose one of a set of choices.\n" ConOutPuts (_T("Waits for the user to choose one of a set of choices.\n"
@ -96,13 +155,11 @@ CommandChoice (LPTSTR cmd, LPTSTR param)
if (*p != _T('/')) if (*p != _T('/'))
{ {
lpText = p; lpText = p;
break; break;
} }
np = _tcschr (p, _T(' ')); np = _tcschr (p, _T(' '));
if (!np) if (!np)
break; break;
p = np + 1; p = np + 1;
} }
@ -123,7 +180,7 @@ CommandChoice (LPTSTR cmd, LPTSTR param)
if (_tcslen (lpOptions) == 0) if (_tcslen (lpOptions) == 0)
{ {
ConErrPuts (_T("Invalid choise switch syntax. Expected format: /C[:]choices\n")); ConErrPuts (_T("Invalid option. Expected format: /C[:]options"));
freep (arg); freep (arg);
return 1; return 1;
} }
@ -143,17 +200,17 @@ CommandChoice (LPTSTR cmd, LPTSTR param)
if (arg[i][2] == _T(':')) if (arg[i][2] == _T(':'))
{ {
cDefault = arg[i][3]; cDefault = arg[i][3];
s = & arg[i][4]; s = &arg[i][4];
} }
else else
{ {
cDefault = arg[i][2]; cDefault = arg[i][2];
s = & arg[i][3]; s = &arg[i][3];
} }
if (*s != _T(',')) if (*s != _T(','))
{ {
ConErrPrintf (_T("Invalid timeout syntax. Expected format: /T[:]c,nn\n")); ConErrPuts (_T("Invalid option. Expected format: /T[:]c,nn"));
freep (arg); freep (arg);
return 1; return 1;
} }
@ -164,8 +221,7 @@ CommandChoice (LPTSTR cmd, LPTSTR param)
} }
else if (arg[i][0] == _T('/')) else if (arg[i][0] == _T('/'))
{ {
ConErrPrintf (_T("Invalid switch on command line. Expected format:\n" ConErrPrintf (_T("Illegal Option: %s"), arg[i]);
" CHOICE [/C[:]choices][/N][/S][/T[:]c,nn][text]\n"));
freep (arg); freep (arg);
return 1; return 1;
} }
@ -181,7 +237,7 @@ CommandChoice (LPTSTR cmd, LPTSTR param)
{ {
ConOutPrintf (_T("[%c"), lpOptions[0]); ConOutPrintf (_T("[%c"), lpOptions[0]);
for (i = 1; i < _tcslen (lpOptions); i++) for (i = 1; (unsigned)i < _tcslen (lpOptions); i++)
ConOutPrintf (_T(",%c"), lpOptions[i]); ConOutPrintf (_T(",%c"), lpOptions[i]);
ConOutPrintf (_T("]?")); ConOutPrintf (_T("]?"));
@ -189,13 +245,18 @@ CommandChoice (LPTSTR cmd, LPTSTR param)
ConInFlush (); ConInFlush ();
if (bTimeout) if(!bTimeout)
{ {
if (WaitForSingleObject (GetStdHandle(STD_INPUT_HANDLE), while (TRUE)
nTimeout * 1000) == WAIT_TIMEOUT)
{ {
ConInKey (&ir);
val = IsKeyInString (lpOptions, val = IsKeyInString (lpOptions,
cDefault, #ifdef _UNICODE
ir.Event.KeyEvent.uChar.UnicodeChar,
#else
ir.Event.KeyEvent.uChar.AsciiChar,
#endif /* _UNICODE */
bCaseSensitive); bCaseSensitive);
if (val >= 0) if (val >= 0)
@ -204,40 +265,62 @@ CommandChoice (LPTSTR cmd, LPTSTR param)
nErrorLevel = val + 1; nErrorLevel = val + 1;
freep (arg); break;
}
Beep (440, 50);
}
freep (arg);
return 0;
}
clk = GetTickCount ();
amount = nTimeout*1000;
loop:
GCret = GetCharacterTimeout (&Ch, amount - (GetTickCount () - clk));
switch (GCret)
{
case GC_TIMEOUT:
#ifdef DEBUG
DebugPrintf (_T("GC_TIMEOUT\n"));
DebugPrintf (_T("elapsed %d msecs\n"), GetTickCount () - clk);
#endif /* DEBUG */
break;
case GC_NOKEY:
#ifdef DEBUG
DebugPrintf(_T("GC_NOKEY\n"));
DebugPrintf(_T("elapsed %d msecs\n"), GetTickCount () - clk);
#endif /* DEBUG */
goto loop;
case GC_KEYREAD:
#ifdef DEBUG
DebugPrintf(_T("GC_KEYREAD\n"));
DebugPrintf(_T("elapsed %d msecs\n"), GetTickCount () - clk);
DebugPrintf(_T("read %c"), Ch);
#endif /* DEBUG */
if ((val=IsKeyInString(lpOptions,Ch,bCaseSensitive))==-1)
{
Beep (440, 50);
goto loop;
}
cDefault=Ch;
break;
}
#ifdef DEBUG #ifdef DEBUG
DebugPrintf (_T("ErrorLevel: %d\n"), nErrorLevel); DebugPrintf(_T("exiting waiting loop after %d msecs\n"),
GetTickCount () - clk);
#endif /* DEBUG */ #endif /* DEBUG */
return 0; val = IsKeyInString (lpOptions, cDefault, bCaseSensitive);
} ConOutPrintf (_T("%c\n"), lpOptions[val]);
}
}
while (TRUE) nErrorLevel = val + 1;
{
ConInKey (&ir);
val = IsKeyInString (lpOptions,
#ifdef _UNICODE
ir.Event.KeyEvent.uChar.UnicodeChar,
#else
ir.Event.KeyEvent.uChar.AsciiChar,
#endif /* _UNICODE */
bCaseSensitive);
if (val >= 0)
{
ConOutPrintf (_T("%c\n"), lpOptions[val]);
nErrorLevel = val + 1;
break;
}
Beep (440, 50);
}
freep (arg); freep (arg);

View file

@ -25,7 +25,7 @@
#ifdef _DEBUG #ifdef _DEBUG
VOID DebugPrintf (LPTSTR szFormat, ...) VOID DebugPrintf (LPTSTR szFormat, ...)
{ {
TCHAR szOut[OUTPUT_BUFFER_SIZE]; TCHAR szOut[OUTPUT_BUFFER_SIZE];
va_list arg_ptr; va_list arg_ptr;
DWORD dwWritten; DWORD dwWritten;
@ -57,7 +57,7 @@ VOID ConInDummy (VOID)
VOID ConInFlush (VOID) VOID ConInFlush (VOID)
{ {
FlushConsoleInputBuffer (GetStdHandle (STD_INPUT_HANDLE)); FlushConsoleInputBuffer (GetStdHandle (STD_INPUT_HANDLE));
} }

View file

@ -300,23 +300,26 @@ BOOL FileGetString (HANDLE hFile, LPTSTR lpBuffer, INT nBufferLength)
/* /*
* GetConsoleWindow - returns the handle to the current console window * GetConsoleWindow - returns the handle to the current console window
*/ */
HWND GetConsoleWindow(VOID) HWND GetConsoleWindow (VOID)
{ {
TCHAR original[256]; /* stores original title*/ TCHAR original[256];
TCHAR temp[256]; /* stores temp title*/ TCHAR temp[256];
HWND h=0; HWND h=0;
GetConsoleTitle(original,sizeof(original)); GetConsoleTitle (original, sizeof(original));
_tcscpy(temp,original); _tcscpy (temp, original);
_tcscat(temp,_T("-xxx ")); _tcscat (temp, _T("-xxx "));
if((h = FindWindow("tty",temp)) == NULL ) if (FindWindow (0, temp) == NULL )
{ {
SetConsoleTitle(temp); SetConsoleTitle (temp);
h=FindWindow("tty",temp); Sleep (0);
SetConsoleTitle(original);
while(!(h = FindWindow (0, temp)))
;
SetConsoleTitle (original);
} }
return h; return h;

View file

@ -128,7 +128,7 @@ INT cmd_ver (LPTSTR cmd, LPTSTR param)
"\n" "\n"
"ReactOS version written by:\n" "ReactOS version written by:\n"
" Eric Kohl Emanuele Aliberti\n" " Eric Kohl Emanuele Aliberti\n"
" Dr. Faustus\n")); " Paolo Pantaleo\n"));
} }
else else
{ {

View file

@ -1,14 +1,15 @@
/* /*
* WINDOW.C - internal command. * WINDOW.C - activate internal command.
* *
* clone from 4nt window command * clone from 4nt window command
* *
* 10 Sep 1999 * 10 Sep 1999
* started - Dr.F <dfaustus@freemail.it> * started - Paolo Pantaleo <dfaustus@freemail.it>
* *
* *
*/ */
#include "config.h" #include "config.h"
#ifdef INCLUDE_CMD_WINDOW #ifdef INCLUDE_CMD_WINDOW
@ -27,69 +28,65 @@
#define A_SIZE 0x10 #define A_SIZE 0x10
INT CommandWindow (LPTSTR cmd, LPTSTR param) INT CommandWindow (LPTSTR cmd, LPTSTR param)
{ {
LPTSTR *p; LPTSTR *p,p_tmp;
INT argc,i; INT argc,i;
INT iAction=0; INT iAction=0;
LPTSTR title=0; LPTSTR title=0;
HWND hWnd; HWND hWnd;
WINDOWPLACEMENT wp; WINDOWPLACEMENT wp;
RECT pos; RECT pos;
LPTSTR tmp; LPTSTR tmp;
if (_tcsncmp (param, _T("/?"), 2) == 0) if (_tcsncmp (param, _T("/?"), 2) == 0)
{ {
ConOutPuts(_T( ConOutPuts(_T("change console window aspect\n"
"change console window aspect\n"
"\n" "\n"
"WINDOW [/POS[=]left,top,width,heigth]\n" "WINDOW [/POS[=]left,top,width,heigth]\n"
" [MIN|MAX|RESTORE]\n" " [MIN|MAX|RESTORE]\n"
"\n" "\n"
"/POS specify window placement and dimensions\n" "/POS specify window placement and dimensions\n"
"MIN minimize the winodw\n" "MIN minimize the window\n"
"MAX maximize the winodw\n" "MAX maximize the window\n"
"RESTORE restore the window" "RESTORE restore the window"));
));
return 0; return 0;
} }
p=split(param,&argc); p=split(param,&argc);
for(i=0;i <argc;i++) for(i = 0; i < argc; i++)
{ {
if (_tcsicmp(p[i],_T("min"))==0) p_tmp=p[i];
if (*p_tmp == _T('/'))
p_tmp++;
if (_tcsicmp(p_tmp,_T("min"))==0)
{ {
iAction |=A_MIN; iAction |= A_MIN;
continue; continue;
} }
if (_tcsicmp(p[i],_T("max"))==0) if (_tcsicmp(p_tmp,_T("max"))==0)
{ {
iAction |=A_MAX; iAction |= A_MAX;
continue; continue;
} }
if (_tcsicmp(p[i],_T("restore"))==0) if (_tcsicmp(p_tmp,_T("restore"))==0)
{ {
iAction |=A_RESTORE; iAction |= A_RESTORE;
continue; continue;
} }
if (_tcsnicmp(p[i],_T("/pos"),4)==0) if (_tcsnicmp(p_tmp,_T("pos"),3)==0)
{ {
iAction |=A_POS; iAction |= A_POS;
tmp = p[i]+4; tmp = p_tmp+3;
if (*tmp == _T('=')) if (*tmp == _T('='))
tmp++; tmp++;
pos.left=_ttoi(tmp); pos.left= _ttoi(tmp);
if(!(tmp=_tcschr(tmp,_T(',')))) if(!(tmp=_tcschr(tmp,_T(','))))
{ {
error_invalid_parameter_format(p[i]); error_invalid_parameter_format(p[i]);
@ -97,7 +94,7 @@ INT CommandWindow (LPTSTR cmd, LPTSTR param)
return 1; return 1;
} }
pos.top=_ttoi(++tmp); pos.top = _ttoi (++tmp);
if(!(tmp=_tcschr(tmp,_T(',')))) if(!(tmp=_tcschr(tmp,_T(','))))
{ {
error_invalid_parameter_format(p[i]); error_invalid_parameter_format(p[i]);
@ -105,26 +102,25 @@ INT CommandWindow (LPTSTR cmd, LPTSTR param)
return 1; return 1;
} }
pos.right=_ttoi(++tmp)+pos.left; pos.right = _ttoi(++tmp)+pos.left;
if(!(tmp=_tcschr(tmp,_T(',')))) if(!(tmp=_tcschr(tmp,_T(','))))
{ {
error_invalid_parameter_format(p[i]); error_invalid_parameter_format(p[i]);
freep(p); freep(p);
return 1; return 1;
} }
pos.bottom=_ttoi(++tmp)+pos.top; pos.bottom = _ttoi(++tmp) + pos.top;
continue; continue;
} }
if (_tcsnicmp(p[i],_T("/size"),5)==0) if (_tcsnicmp(p_tmp,_T("size"),4)==0)
{ {
iAction |=A_SIZE; iAction |=A_SIZE;
continue; continue;
} }
#if 0 #if 0
if(*p[i] != _T('"')) if(*p_tmp != '"')
{ {
error_invalid_parameter_format(p[i]); error_invalid_parameter_format(p[i]);
@ -141,13 +137,13 @@ INT CommandWindow (LPTSTR cmd, LPTSTR param)
return 1; return 1;
} }
if (p[i][0] ==_T('"')) if (p_tmp[0] == _T('"'))
{ {
title = (p[i]+1); title = (p_tmp+1);
*_tcschr(p[i]+1,_T('"'))=0; *_tcschr(p_tmp+1,_T('"'))=0;
continue; continue;
} }
title = p[i]; title = p_tmp;
} }
if(title) if(title)
@ -175,6 +171,7 @@ INT CommandWindow (LPTSTR cmd, LPTSTR param)
wp.length=sizeof(WINDOWPLACEMENT); wp.length=sizeof(WINDOWPLACEMENT);
SetWindowPlacement(hWnd,&wp); SetWindowPlacement(hWnd,&wp);
freep(p);
return 0; return 0;
} }