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
24 #define PT(format) PrintElapsedTime(GetTickCount()-cT,format)
27 //current timer Time (at wich started to count)
28 #define cT clksT[clk_n]
30 //current timer status
31 #define cS clksS[clk_n]
35 PrintElapsedTime (DWORD time
,INT format
)
37 TCHAR szMsg
[RC_STRING_MAX_SIZE
];
40 TRACE ("PrintElapsedTime(%d,%d)",time
,format
);
45 LoadString(CMD_ModuleHandle
, STRING_TIMER_HELP1
, szMsg
, RC_STRING_MAX_SIZE
);
46 ConOutPrintf(szMsg
, time
);
56 LoadString( CMD_ModuleHandle
, STRING_TIMER_HELP2
, szMsg
, RC_STRING_MAX_SIZE
);
60 s
, cDecimalSeparator
, ms
/10);
66 INT
CommandTimer (LPTSTR cmd
, LPTSTR param
)
68 TCHAR szMsg
[RC_STRING_MAX_SIZE
];
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)
102 LoadString(CMD_ModuleHandle
, STRING_TIMER_HELP3
, szMsg
, RC_STRING_MAX_SIZE
);
103 ConOutPrintf(szMsg
, cTimeSeparator
, cTimeSeparator
, cDecimalSeparator
);
109 LoadString( CMD_ModuleHandle
, STRING_TIMER_TIME
, szMsg
, RC_STRING_MAX_SIZE
);
111 p
= split (param
, &argc
, FALSE
);
114 for (i
= 0; i
< argc
; i
++)
117 if (!(_tcsicmp(&p
[i
][0],_T("on"))) && NewClkStatus
== NCS_NOT_SPECIFIED
)
119 NewClkStatus
= NCS_ON
;
124 if (!(_tcsicmp(&p
[i
][0],_T("off"))) && NewClkStatus
== NCS_NOT_SPECIFIED
)
126 NewClkStatus
= NCS_OFF
;
131 if (p
[i
][0] == _T('/'))
134 if (_istdigit(p
[i
][1]) && bCanNSet
)
136 clk_n
= p
[i
][1] - _T('0');
141 // set s(plit) option
142 if (_totupper(p
[i
][1]) == _T('S'))
149 if (_totupper(p
[i
][1]) == _T('F'))
151 iFormat
= p
[i
][2] - _T('0');
157 // do stuff (start/stop/read timer)
158 if(NewClkStatus
== NCS_ON
)
163 ConOutPrintf (szMsg
,clk_n
,cS
?_T("ON"):_T("OFF"));
173 ConOutPrintf (szMsg
,clk_n
,cS
?_T("ON"):_T("OFF"));
175 PrintElapsedTime(GetTickCount()-cT
, iFormat
);
182 ConOutPrintf (szMsg
,clk_n
,cS
?_T("ON"):_T("OFF"));
188 if (NewClkStatus
== NCS_NOT_SPECIFIED
)
193 ConOutPrintf (szMsg
,clk_n
,cS
?_T("ON"):_T("OFF"));
195 PrintElapsedTime(GetTickCount()-cT
, iFormat
);
202 ConOutPrintf (szMsg
,clk_n
,cS
?_T("ON"):_T("OFF"));
209 if (NewClkStatus
== NCS_OFF
)
214 ConOutPrintf (szMsg
,clk_n
,cS
?_T("ON"):_T("OFF"));
216 PrintElapsedTime(GetTickCount()-cT
, iFormat
);
220 ConOutPrintf (szMsg
,clk_n
,cS
?_T("ON"):_T("OFF"));
230 #endif /* INCLUDE_CMD_TIMER */