2006-02-16 23:23:37 +00:00
|
|
|
/*
|
|
|
|
* TIMER.C - timer internal command.
|
|
|
|
*
|
|
|
|
* clone from 4nt timer command
|
|
|
|
*
|
|
|
|
* 20 Aug 1999
|
|
|
|
* started - Paolo Pantaleo <paolopan@freemail.it>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <precomp.h>
|
|
|
|
|
|
|
|
#ifdef INCLUDE_CMD_TIMER
|
|
|
|
|
|
|
|
|
|
|
|
#define NCS_NOT_SPECIFIED -1
|
|
|
|
#define NCS_ON 1
|
|
|
|
#define NCS_OFF 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//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;
|
|
|
|
|
2008-05-15 20:02:05 +00:00
|
|
|
TRACE ("PrintElapsedTime(%d,%d)",time,format);
|
2006-02-16 23:23:37 +00:00
|
|
|
|
|
|
|
switch (format)
|
|
|
|
{
|
|
|
|
case 0:
|
2008-07-26 22:49:49 +00:00
|
|
|
ConOutResPrintf(STRING_TIMER_HELP1, time);
|
2006-02-16 23:23:37 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
ms = time % 1000;
|
|
|
|
time /= 1000;
|
|
|
|
s = time % 60;
|
|
|
|
time /=60;
|
|
|
|
m = time % 60;
|
|
|
|
h = time / 60;
|
2008-07-26 22:49:49 +00:00
|
|
|
ConOutResPrintf(STRING_TIMER_HELP2,
|
|
|
|
h, cTimeSeparator,
|
|
|
|
m, cTimeSeparator,
|
|
|
|
s, cDecimalSeparator, ms/10);
|
2006-02-16 23:23:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-25 23:22:03 +00:00
|
|
|
INT CommandTimer (LPTSTR param)
|
2006-02-16 23:23:37 +00:00
|
|
|
{
|
|
|
|
// all timers are kept
|
|
|
|
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)
|
|
|
|
{
|
2008-07-26 22:49:49 +00:00
|
|
|
ConOutResPrintf(STRING_TIMER_HELP3, cTimeSeparator, cTimeSeparator, cDecimalSeparator);
|
2006-02-16 23:23:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nErrorLevel = 0;
|
|
|
|
|
|
|
|
p = split (param, &argc, FALSE);
|
|
|
|
|
|
|
|
//read options
|
|
|
|
for (i = 0; i < argc; i++)
|
|
|
|
{
|
|
|
|
//set timer on
|
|
|
|
if (!(_tcsicmp(&p[i][0],_T("on"))) && NewClkStatus == NCS_NOT_SPECIFIED)
|
|
|
|
{
|
|
|
|
NewClkStatus = NCS_ON;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//set timer off
|
|
|
|
if (!(_tcsicmp(&p[i][0],_T("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;
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2008-07-26 22:49:49 +00:00
|
|
|
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
|
2009-03-16 00:44:08 +00:00
|
|
|
ConOutPuts(GetTimeString());
|
2006-02-16 23:23:37 +00:00
|
|
|
freep(p);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(bS)
|
|
|
|
{
|
|
|
|
if(cS)
|
2007-10-19 23:21:45 +00:00
|
|
|
{
|
2008-07-26 22:49:49 +00:00
|
|
|
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
|
2009-03-16 00:44:08 +00:00
|
|
|
ConOutPuts(GetTimeString());
|
2006-02-16 23:23:37 +00:00
|
|
|
PrintElapsedTime(GetTickCount()-cT, iFormat);
|
|
|
|
freep(p);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cT=GetTickCount();
|
|
|
|
cS=TRUE;
|
2008-07-26 22:49:49 +00:00
|
|
|
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
|
2009-03-16 00:44:08 +00:00
|
|
|
ConOutPuts(GetTimeString());
|
2006-02-16 23:23:37 +00:00
|
|
|
freep(p);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NewClkStatus == NCS_NOT_SPECIFIED)
|
|
|
|
{
|
|
|
|
if (cS)
|
|
|
|
{
|
|
|
|
cS=FALSE;
|
2008-07-26 22:49:49 +00:00
|
|
|
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
|
2009-03-16 00:44:08 +00:00
|
|
|
ConOutPuts(GetTimeString());
|
2006-02-16 23:23:37 +00:00
|
|
|
PrintElapsedTime(GetTickCount()-cT, iFormat);
|
|
|
|
freep(p);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cT=GetTickCount();
|
|
|
|
cS=TRUE;
|
2008-07-26 22:49:49 +00:00
|
|
|
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
|
2009-03-16 00:44:08 +00:00
|
|
|
ConOutPuts(GetTimeString());
|
2006-02-16 23:23:37 +00:00
|
|
|
freep(p);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (NewClkStatus == NCS_OFF)
|
|
|
|
{
|
|
|
|
if (cS)
|
|
|
|
{
|
|
|
|
cS=FALSE;
|
2008-07-26 22:49:49 +00:00
|
|
|
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
|
2009-03-16 00:44:08 +00:00
|
|
|
ConOutPuts(GetTimeString());
|
2006-02-16 23:23:37 +00:00
|
|
|
PrintElapsedTime(GetTickCount()-cT, iFormat);
|
|
|
|
freep(p);
|
|
|
|
return 0;
|
|
|
|
}
|
2008-07-26 22:49:49 +00:00
|
|
|
ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
|
2009-03-16 00:44:08 +00:00
|
|
|
ConOutPuts(GetTimeString());
|
2006-02-16 23:23:37 +00:00
|
|
|
freep(p);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
freep(p);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* INCLUDE_CMD_TIMER */
|