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:
*
* 12-Aug-1999 (Eric Kohl)
* Started.
* 12 Aug 1999 (Eric Kohl)
* started.
*
* 01 Sep 1999 (Eric Kohl)
* Fixed help text.
*
* 26 Sep 1999 (Paolo Pantaleo)
* Fixed timeout.
*/
#include "config.h"
@ -25,10 +28,62 @@
#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
IsKeyInString (LPTSTR lpString, TCHAR cKey, BOOL bCaseSensitive)
{
LPTSTR p = lpString;
LPTCH p = lpString;
INT val = 0;
while (*p)
@ -69,6 +124,10 @@ CommandChoice (LPTSTR cmd, LPTSTR param)
INT i;
INT val;
INT GCret;
TCHAR Ch;
DWORD amount,clk;
if (_tcsncmp (param, _T("/?"), 2) == 0)
{
ConOutPuts (_T("Waits for the user to choose one of a set of choices.\n"
@ -98,11 +157,9 @@ CommandChoice (LPTSTR cmd, LPTSTR param)
lpText = p;
break;
}
np = _tcschr (p, _T(' '));
if (!np)
break;
p = np + 1;
}
@ -123,7 +180,7 @@ CommandChoice (LPTSTR cmd, LPTSTR param)
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);
return 1;
}
@ -153,7 +210,7 @@ CommandChoice (LPTSTR cmd, LPTSTR param)
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);
return 1;
}
@ -164,8 +221,7 @@ CommandChoice (LPTSTR cmd, LPTSTR param)
}
else if (arg[i][0] == _T('/'))
{
ConErrPrintf (_T("Invalid switch on command line. Expected format:\n"
" CHOICE [/C[:]choices][/N][/S][/T[:]c,nn][text]\n"));
ConErrPrintf (_T("Illegal Option: %s"), arg[i]);
freep (arg);
return 1;
}
@ -181,7 +237,7 @@ CommandChoice (LPTSTR cmd, LPTSTR param)
{
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("]?"));
@ -189,32 +245,8 @@ CommandChoice (LPTSTR cmd, LPTSTR param)
ConInFlush ();
if (bTimeout)
if(!bTimeout)
{
if (WaitForSingleObject (GetStdHandle(STD_INPUT_HANDLE),
nTimeout * 1000) == WAIT_TIMEOUT)
{
val = IsKeyInString (lpOptions,
cDefault,
bCaseSensitive);
if (val >= 0)
{
ConOutPrintf (_T("%c\n"), lpOptions[val]);
nErrorLevel = val + 1;
freep (arg);
#ifdef DEBUG
DebugPrintf (_T("ErrorLevel: %d\n"), nErrorLevel);
#endif /* DEBUG */
return 0;
}
}
}
while (TRUE)
{
ConInKey (&ir);
@ -240,6 +272,57 @@ CommandChoice (LPTSTR cmd, LPTSTR param)
}
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
DebugPrintf(_T("exiting waiting loop after %d msecs\n"),
GetTickCount () - clk);
#endif /* DEBUG */
val = IsKeyInString (lpOptions, cDefault, bCaseSensitive);
ConOutPrintf (_T("%c\n"), lpOptions[val]);
nErrorLevel = val + 1;
freep (arg);
#ifdef DEBUG
DebugPrintf (_T("ErrorLevel: %d\n"), nErrorLevel);

View file

@ -302,9 +302,8 @@ BOOL FileGetString (HANDLE hFile, LPTSTR lpBuffer, INT nBufferLength)
*/
HWND GetConsoleWindow (VOID)
{
TCHAR original[256]; /* stores original title*/
TCHAR temp[256]; /* stores temp title*/
TCHAR original[256];
TCHAR temp[256];
HWND h=0;
GetConsoleTitle (original, sizeof(original));
@ -312,10 +311,14 @@ HWND GetConsoleWindow(VOID)
_tcscpy (temp, original);
_tcscat (temp, _T("-xxx "));
if((h = FindWindow("tty",temp)) == NULL )
if (FindWindow (0, temp) == NULL )
{
SetConsoleTitle (temp);
h=FindWindow("tty",temp);
Sleep (0);
while(!(h = FindWindow (0, temp)))
;
SetConsoleTitle (original);
}

View file

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

View file

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