2 * TIMER.C - timer internal command.
4 * clone from 4nt timer command
7 * started - Dr.F <dfaustus@freemail.it>
12 #ifdef INCLUDE_CMD_TIMER
21 #define NCS_NOT_SPECIFIED -1
28 #define PS ConOutPrintf("Timer %d is %s: ",clk_n,cS?"ON":"OFF"); \
32 #define PT(format) PrintElapsedTime(GetTickCount()-cT,format)
35 //current timer Time (at wich started to count)
36 #define cT clksT[clk_n]
38 //current timer status
39 #define cS clksS[clk_n]
43 PrintElapsedTime (DWORD time
,INT format
)
49 DebugPrintf("PrintTime(%d,%d)",time
,format
);
55 ConOutPrintf("Elapsed %d msecs\n",time
);
65 ConOutPrintf("Elapsed %02d%c%02d%c%02d%c%02d\n",
68 s
,cDecimalSeparator
,ms
/10);
74 INT
CommandTimer (LPTSTR cmd
, LPTSTR param
)
76 // all timers are kept
77 static DWORD clksT
[10];
80 // set all the clocks off by default
81 static BOOL clksS
[10]={FALSE
,FALSE
,FALSE
,FALSE
,
82 FALSE
,FALSE
,FALSE
,FALSE
,FALSE
,FALSE
};
84 // TRUE if /S in command line
87 // avoid to set clk_n more than once
90 INT NewClkStatus
= NCS_NOT_SPECIFIED
;
92 // the clock number specified on the command line
100 // command line parsing variables
106 if (_tcsncmp (param
, _T("/?"), 2) == 0)
109 "allow the use of ten stopwaches.\n"
111 "TIMER [ON|OFF] [/S] [/n] [/Fn]\n"
113 " ON set stopwach ON\n"
114 " OFF set stopwach OFF\n"
115 " /S Split time. Return stopwach split\n"
116 " time without changing its value\n"
117 " /n Specifiy the stopwach number.\n"
118 " Stopwaches avaliable are 0 to 10\n"
119 " If it is not specified default is 1\n"
120 " /Fn Format for output\n"
123 " 1 hh%cmm%css%cdd\n"
125 cTimeSeparator
,cTimeSeparator
,cDecimalSeparator
);
128 "if none of ON, OFF or /S is specified the command\n"
129 "will toggle stopwach state\n"
135 p
= split (param
,&argc
);
138 for (i
= 0; i
< argc
; i
++)
141 if (!(_tcsicmp(&p
[i
][0],"on")) && NewClkStatus
== NCS_NOT_SPECIFIED
)
143 NewClkStatus
= NCS_ON
;
148 if (!(_tcsicmp(&p
[i
][0],"off")) && NewClkStatus
== NCS_NOT_SPECIFIED
)
150 NewClkStatus
= NCS_OFF
;
155 if (p
[i
][0] == _T('/'))
159 if (_istdigit(p
[i
][1]) && bCanNSet
)
161 clk_n
= p
[i
][1] - _T('0');
166 // set s(plit) option
167 if (_totupper(p
[i
][1]) == _T('S'))
174 if(_totupper(p
[i
][1]) == _T('F'))
176 iFormat
= p
[i
][2] - _T('0');
182 // do stuff (start/stop/read timer)
183 if(NewClkStatus
== NCS_ON
)
197 PrintElapsedTime(GetTickCount()-cT
, iFormat
);
209 if(NewClkStatus
== NCS_NOT_SPECIFIED
)
214 PrintElapsedTime(GetTickCount()-cT
, iFormat
);
227 if(NewClkStatus
== NCS_OFF
)
233 PrintElapsedTime(GetTickCount()-cT
, iFormat
);
246 #endif /* INCLUDE_CMD_TIMER */