1999-09-12 18:23:31 +00:00
|
|
|
/*
|
1999-08-29 22:31:43 +00:00
|
|
|
* TIMER.C - timer internal command.
|
|
|
|
*
|
|
|
|
* clone from 4nt timer command
|
|
|
|
*
|
|
|
|
* 20 Aug 1999
|
1999-10-03 22:20:33 +00:00
|
|
|
* started - Paolo Pantaleo <paolopan@freemail.it>
|
1999-08-29 22:31:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#ifdef INCLUDE_CMD_TIMER
|
|
|
|
#include "cmd.h"
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <tchar.h>
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
|
|
|
|
#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;
|
1999-09-12 18:23:31 +00:00
|
|
|
ConOutPrintf("Elapsed %02d%c%02d%c%02d%c%02d\n",
|
|
|
|
h,cTimeSeparator,
|
|
|
|
m,cTimeSeparator,
|
|
|
|
s,cDecimalSeparator,ms/10);
|
|
|
|
break;
|
1999-08-29 22:31:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
INT CommandTimer (LPTSTR cmd, LPTSTR param)
|
|
|
|
{
|
1999-09-12 18:23:31 +00:00
|
|
|
// all timers are kept
|
1999-08-29 22:31:43 +00:00
|
|
|
static DWORD clksT[10];
|
|
|
|
|
1999-09-12 18:23:31 +00:00
|
|
|
// timers status
|
|
|
|
// set all the clocks off by default
|
1999-08-29 22:31:43 +00:00
|
|
|
static BOOL clksS[10]={FALSE,FALSE,FALSE,FALSE,
|
|
|
|
FALSE,FALSE,FALSE,FALSE,FALSE,FALSE};
|
|
|
|
|
1999-09-12 18:23:31 +00:00
|
|
|
// TRUE if /S in command line
|
1999-08-29 22:31:43 +00:00
|
|
|
BOOL bS = FALSE;
|
|
|
|
|
1999-09-12 18:23:31 +00:00
|
|
|
// avoid to set clk_n more than once
|
1999-08-29 22:31:43 +00:00
|
|
|
BOOL bCanNSet = TRUE;
|
|
|
|
|
|
|
|
INT NewClkStatus = NCS_NOT_SPECIFIED;
|
|
|
|
|
1999-09-12 18:23:31 +00:00
|
|
|
// the clock number specified on the command line
|
|
|
|
// 1 by default
|
1999-08-29 22:31:43 +00:00
|
|
|
INT clk_n=1;
|
|
|
|
|
1999-09-12 18:23:31 +00:00
|
|
|
// output format
|
1999-08-29 22:31:43 +00:00
|
|
|
INT iFormat=1;
|
|
|
|
|
|
|
|
|
|
|
|
// command line parsing variables
|
|
|
|
INT argc;
|
|
|
|
LPTSTR *p;
|
|
|
|
|
|
|
|
INT i;
|
|
|
|
|
|
|
|
if (_tcsncmp (param, _T("/?"), 2) == 0)
|
|
|
|
{
|
1999-09-12 18:23:31 +00:00
|
|
|
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"));
|
1999-08-29 22:31:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-12 18:23:31 +00:00
|
|
|
p = split (param,&argc);
|
1999-08-29 22:31:43 +00:00
|
|
|
|
1999-09-12 18:23:31 +00:00
|
|
|
//read options
|
|
|
|
for (i = 0; i < argc; i++)
|
1999-08-29 22:31:43 +00:00
|
|
|
{
|
|
|
|
//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;
|
|
|
|
}
|
|
|
|
|
1999-09-12 18:23:31 +00:00
|
|
|
// other options
|
1999-08-29 22:31:43 +00:00
|
|
|
if (p[i][0] == _T('/'))
|
|
|
|
{
|
|
|
|
|
1999-09-12 18:23:31 +00:00
|
|
|
// set timer number
|
1999-08-29 22:31:43 +00:00
|
|
|
if (_istdigit(p[i][1]) && bCanNSet)
|
|
|
|
{
|
|
|
|
clk_n = p[i][1] - _T('0');
|
|
|
|
bCanNSet = FALSE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
1999-09-12 18:23:31 +00:00
|
|
|
// set s(plit) option
|
1999-08-29 22:31:43 +00:00
|
|
|
if (_totupper(p[i][1]) == _T('S'))
|
|
|
|
{
|
|
|
|
bS = TRUE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
1999-09-12 18:23:31 +00:00
|
|
|
// specify format
|
1999-08-29 22:31:43 +00:00
|
|
|
if(_totupper(p[i][1]) == _T('F'))
|
|
|
|
{
|
|
|
|
iFormat = p[i][2] - _T('0');
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-09-12 18:23:31 +00:00
|
|
|
// do stuff (start/stop/read timer)
|
1999-08-29 22:31:43 +00:00
|
|
|
if(NewClkStatus == NCS_ON)
|
|
|
|
{
|
|
|
|
cT=GetTickCount();
|
|
|
|
cS=TRUE;
|
|
|
|
PS;
|
1999-09-12 18:23:31 +00:00
|
|
|
freep(p);
|
1999-08-29 22:31:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(bS)
|
|
|
|
{
|
|
|
|
if(cS)
|
|
|
|
{
|
|
|
|
PS;
|
1999-09-12 18:23:31 +00:00
|
|
|
PrintElapsedTime(GetTickCount()-cT, iFormat);
|
|
|
|
freep(p);
|
1999-08-29 22:31:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1999-09-12 18:23:31 +00:00
|
|
|
|
1999-08-29 22:31:43 +00:00
|
|
|
cT=GetTickCount();
|
|
|
|
cS=TRUE;
|
|
|
|
PS;
|
1999-09-12 18:23:31 +00:00
|
|
|
freep(p);
|
|
|
|
return 0;
|
1999-08-29 22:31:43 +00:00
|
|
|
}
|
|
|
|
|
1999-09-12 18:23:31 +00:00
|
|
|
if(NewClkStatus == NCS_NOT_SPECIFIED)
|
1999-08-29 22:31:43 +00:00
|
|
|
{
|
|
|
|
if(cS){
|
|
|
|
cS=FALSE;
|
|
|
|
PS;
|
1999-09-12 18:23:31 +00:00
|
|
|
PrintElapsedTime(GetTickCount()-cT, iFormat);
|
|
|
|
freep(p);
|
1999-08-29 22:31:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cT=GetTickCount();
|
|
|
|
cS=TRUE;
|
|
|
|
PS;
|
1999-09-12 18:23:31 +00:00
|
|
|
freep(p);
|
1999-08-29 22:31:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-12 18:23:31 +00:00
|
|
|
if(NewClkStatus == NCS_OFF)
|
1999-08-29 22:31:43 +00:00
|
|
|
{
|
|
|
|
if(cS)
|
|
|
|
{
|
|
|
|
cS=FALSE;
|
|
|
|
PS;
|
1999-09-12 18:23:31 +00:00
|
|
|
PrintElapsedTime(GetTickCount()-cT, iFormat);
|
|
|
|
freep(p);
|
1999-08-29 22:31:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1999-09-12 18:23:31 +00:00
|
|
|
PS;
|
|
|
|
freep(p);
|
1999-08-29 22:31:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
freep(p);
|
1999-09-12 18:23:31 +00:00
|
|
|
return 0;
|
1999-08-29 22:31:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* INCLUDE_CMD_TIMER */
|