2 * TIMER.C - timer internal command.
4 * clone from 4nt timer command
7 * started - Paolo Pantaleo <paolopan@freemail.it>
12 #ifdef INCLUDE_CMD_TIMER
15 #define NCS_NOT_SPECIFIED -1
22 #define PS ConOutPrintf(_T("Timer %d is %s: "),clk_n,cS?_T("ON"):_T("OFF")); \
26 #define PT(format) PrintElapsedTime(GetTickCount()-cT,format)
29 //current timer Time (at wich started to count)
30 #define cT clksT[clk_n]
32 //current timer status
33 #define cS clksS[clk_n]
37 PrintElapsedTime (DWORD time
,INT format
)
43 DebugPrintf(_T("PrintTime(%d,%d)"),time
,format
);
49 ConOutPrintf(_T("Elapsed %d msecs\n"),time
);
59 ConOutPrintf(_T("Elapsed %02d%c%02d%c%02d%c%02d\n"),
62 s
,cDecimalSeparator
,ms
/10);
68 INT
CommandTimer (LPTSTR cmd
, LPTSTR param
)
70 // all timers are kept
71 static DWORD clksT
[10];
74 // set all the clocks off by default
75 static BOOL clksS
[10]={FALSE
,FALSE
,FALSE
,FALSE
,
76 FALSE
,FALSE
,FALSE
,FALSE
,FALSE
,FALSE
};
78 // TRUE if /S in command line
81 // avoid to set clk_n more than once
84 INT NewClkStatus
= NCS_NOT_SPECIFIED
;
86 // the clock number specified on the command line
94 // command line parsing variables
100 if (_tcsncmp (param
, _T("/?"), 2) == 0)
103 "allow the use of ten stopwaches.\n"
105 "TIMER [ON|OFF] [/S] [/n] [/Fn]\n"
107 " ON set stopwach ON\n"
108 " OFF set stopwach OFF\n"
109 " /S Split time. Return stopwach split\n"
110 " time without changing its value\n"
111 " /n Specifiy the stopwach number.\n"
112 " Stopwaches avaliable are 0 to 10\n"
113 " If it is not specified default is 1\n"
114 " /Fn Format for output\n"
117 " 1 hh%cmm%css%cdd\n"
119 cTimeSeparator
,cTimeSeparator
,cDecimalSeparator
);
122 "if none of ON, OFF or /S is specified the command\n"
123 "will toggle stopwach state\n"
129 p
= split (param
, &argc
, FALSE
);
132 for (i
= 0; i
< argc
; i
++)
135 if (!(_tcsicmp(&p
[i
][0],_T("on"))) && NewClkStatus
== NCS_NOT_SPECIFIED
)
137 NewClkStatus
= NCS_ON
;
142 if (!(_tcsicmp(&p
[i
][0],_T("off"))) && NewClkStatus
== NCS_NOT_SPECIFIED
)
144 NewClkStatus
= NCS_OFF
;
149 if (p
[i
][0] == _T('/'))
153 if (_istdigit(p
[i
][1]) && bCanNSet
)
155 clk_n
= p
[i
][1] - _T('0');
160 // set s(plit) option
161 if (_totupper(p
[i
][1]) == _T('S'))
168 if(_totupper(p
[i
][1]) == _T('F'))
170 iFormat
= p
[i
][2] - _T('0');
176 // do stuff (start/stop/read timer)
177 if(NewClkStatus
== NCS_ON
)
191 PrintElapsedTime(GetTickCount()-cT
, iFormat
);
203 if(NewClkStatus
== NCS_NOT_SPECIFIED
)
208 PrintElapsedTime(GetTickCount()-cT
, iFormat
);
221 if(NewClkStatus
== NCS_OFF
)
227 PrintElapsedTime(GetTickCount()-cT
, iFormat
);
240 #endif /* INCLUDE_CMD_TIMER */