mirror of
https://github.com/reactos/reactos.git
synced 2025-08-03 18:35:41 +00:00
Minor updates and fixes.
svn path=/trunk/; revision=674
This commit is contained in:
parent
1241612f69
commit
56e30e8907
5 changed files with 185 additions and 102 deletions
|
@ -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,10 +28,62 @@
|
||||||
#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"
|
||||||
|
@ -98,11 +157,9 @@ CommandChoice (LPTSTR cmd, LPTSTR param)
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
@ -153,7 +210,7 @@ CommandChoice (LPTSTR cmd, LPTSTR param)
|
||||||
|
|
||||||
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,32 +245,8 @@ CommandChoice (LPTSTR cmd, LPTSTR param)
|
||||||
|
|
||||||
ConInFlush ();
|
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)
|
while (TRUE)
|
||||||
{
|
{
|
||||||
ConInKey (&ir);
|
ConInKey (&ir);
|
||||||
|
@ -240,6 +272,57 @@ CommandChoice (LPTSTR cmd, LPTSTR param)
|
||||||
}
|
}
|
||||||
|
|
||||||
freep (arg);
|
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
|
#ifdef DEBUG
|
||||||
DebugPrintf (_T("ErrorLevel: %d\n"), nErrorLevel);
|
DebugPrintf (_T("ErrorLevel: %d\n"), nErrorLevel);
|
||||||
|
|
|
@ -302,9 +302,8 @@ BOOL FileGetString (HANDLE hFile, LPTSTR lpBuffer, INT nBufferLength)
|
||||||
*/
|
*/
|
||||||
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));
|
||||||
|
@ -312,10 +311,14 @@ HWND GetConsoleWindow(VOID)
|
||||||
_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);
|
||||||
|
|
||||||
|
while(!(h = FindWindow (0, temp)))
|
||||||
|
;
|
||||||
|
|
||||||
SetConsoleTitle (original);
|
SetConsoleTitle (original);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
{
|
{
|
||||||
|
|
|
@ -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,36 +28,28 @@
|
||||||
#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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,28 +57,32 @@ INT CommandWindow (LPTSTR cmd, LPTSTR param)
|
||||||
|
|
||||||
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++;
|
||||||
|
|
||||||
|
@ -113,18 +110,17 @@ INT CommandWindow (LPTSTR cmd, LPTSTR param)
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue