some more win32k 64 bit fixes
[reactos.git] / reactos / base / shell / cmd / timer.c
1 /*
2 * TIMER.C - timer internal command.
3 *
4 * clone from 4nt timer command
5 *
6 * 20 Aug 1999
7 * started - Paolo Pantaleo <paolopan@freemail.it>
8 */
9
10 #include <precomp.h>
11
12 #ifdef INCLUDE_CMD_TIMER
13
14
15 #define NCS_NOT_SPECIFIED -1
16 #define NCS_ON 1
17 #define NCS_OFF 0
18
19
20
21
22
23 //print timer value
24 #define PT(format) PrintElapsedTime(GetTickCount()-cT,format)
25
26
27 //current timer Time (at wich started to count)
28 #define cT clksT[clk_n]
29
30 //current timer status
31 #define cS clksS[clk_n]
32
33
34 static VOID
35 PrintElapsedTime (DWORD time,INT format)
36 {
37 TCHAR szMsg[RC_STRING_MAX_SIZE];
38 DWORD h,m,s,ms;
39
40 TRACE ("PrintElapsedTime(%d,%d)",time,format);
41
42 switch (format)
43 {
44 case 0:
45 LoadString(CMD_ModuleHandle, STRING_TIMER_HELP1, szMsg, RC_STRING_MAX_SIZE);
46 ConOutPrintf(szMsg, time);
47 break;
48
49 case 1:
50 ms = time % 1000;
51 time /= 1000;
52 s = time % 60;
53 time /=60;
54 m = time % 60;
55 h = time / 60;
56 LoadString( CMD_ModuleHandle, STRING_TIMER_HELP2, szMsg, RC_STRING_MAX_SIZE);
57 ConOutPrintf(szMsg,
58 h, cTimeSeparator,
59 m, cTimeSeparator,
60 s, cDecimalSeparator, ms/10);
61 break;
62 }
63 }
64
65
66 INT CommandTimer (LPTSTR cmd, LPTSTR param)
67 {
68 TCHAR szMsg[RC_STRING_MAX_SIZE];
69
70 // all timers are kept
71 static DWORD clksT[10];
72
73 // timers status
74 // set all the clocks off by default
75 static BOOL clksS[10]={FALSE,FALSE,FALSE,FALSE,
76 FALSE,FALSE,FALSE,FALSE,FALSE,FALSE};
77
78 // TRUE if /S in command line
79 BOOL bS = FALSE;
80
81 // avoid to set clk_n more than once
82 BOOL bCanNSet = TRUE;
83
84 INT NewClkStatus = NCS_NOT_SPECIFIED;
85
86 // the clock number specified on the command line
87 // 1 by default
88 INT clk_n=1;
89
90 // output format
91 INT iFormat=1;
92
93
94 // command line parsing variables
95 INT argc;
96 LPTSTR *p;
97
98 INT i;
99
100 if (_tcsncmp (param, _T("/?"), 2) == 0)
101 {
102 LoadString(CMD_ModuleHandle, STRING_TIMER_HELP3, szMsg, RC_STRING_MAX_SIZE);
103 ConOutPrintf(szMsg, cTimeSeparator, cTimeSeparator, cDecimalSeparator);
104 return 0;
105 }
106
107 nErrorLevel = 0;
108
109 LoadString( CMD_ModuleHandle, STRING_TIMER_TIME, szMsg, RC_STRING_MAX_SIZE);
110
111 p = split (param, &argc, FALSE);
112
113 //read options
114 for (i = 0; i < argc; i++)
115 {
116 //set timer on
117 if (!(_tcsicmp(&p[i][0],_T("on"))) && NewClkStatus == NCS_NOT_SPECIFIED)
118 {
119 NewClkStatus = NCS_ON;
120 continue;
121 }
122
123 //set timer off
124 if (!(_tcsicmp(&p[i][0],_T("off"))) && NewClkStatus == NCS_NOT_SPECIFIED)
125 {
126 NewClkStatus = NCS_OFF;
127 continue;
128 }
129
130 // other options
131 if (p[i][0] == _T('/'))
132 {
133 // set timer number
134 if (_istdigit(p[i][1]) && bCanNSet)
135 {
136 clk_n = p[i][1] - _T('0');
137 bCanNSet = FALSE;
138 continue;
139 }
140
141 // set s(plit) option
142 if (_totupper(p[i][1]) == _T('S'))
143 {
144 bS = TRUE;
145 continue;
146 }
147
148 // specify format
149 if (_totupper(p[i][1]) == _T('F'))
150 {
151 iFormat = p[i][2] - _T('0');
152 continue;
153 }
154 }
155 }
156
157 // do stuff (start/stop/read timer)
158 if(NewClkStatus == NCS_ON)
159 {
160 cT=GetTickCount();
161 cS=TRUE;
162
163 ConOutPrintf (szMsg,clk_n,cS?_T("ON"):_T("OFF"));
164 PrintTime();
165 freep(p);
166 return 0;
167 }
168
169 if(bS)
170 {
171 if(cS)
172 {
173 ConOutPrintf (szMsg,clk_n,cS?_T("ON"):_T("OFF"));
174 PrintTime();
175 PrintElapsedTime(GetTickCount()-cT, iFormat);
176 freep(p);
177 return 0;
178 }
179
180 cT=GetTickCount();
181 cS=TRUE;
182 ConOutPrintf (szMsg,clk_n,cS?_T("ON"):_T("OFF"));
183 PrintTime();
184 freep(p);
185 return 0;
186 }
187
188 if (NewClkStatus == NCS_NOT_SPECIFIED)
189 {
190 if (cS)
191 {
192 cS=FALSE;
193 ConOutPrintf (szMsg,clk_n,cS?_T("ON"):_T("OFF"));
194 PrintTime();
195 PrintElapsedTime(GetTickCount()-cT, iFormat);
196 freep(p);
197 return 0;
198 }
199
200 cT=GetTickCount();
201 cS=TRUE;
202 ConOutPrintf (szMsg,clk_n,cS?_T("ON"):_T("OFF"));
203 PrintTime();
204 freep(p);
205 return 0;
206 }
207
208
209 if (NewClkStatus == NCS_OFF)
210 {
211 if (cS)
212 {
213 cS=FALSE;
214 ConOutPrintf (szMsg,clk_n,cS?_T("ON"):_T("OFF"));
215 PrintTime();
216 PrintElapsedTime(GetTickCount()-cT, iFormat);
217 freep(p);
218 return 0;
219 }
220 ConOutPrintf (szMsg,clk_n,cS?_T("ON"):_T("OFF"));
221 PrintTime();
222 freep(p);
223 return 0;
224 }
225
226 freep(p);
227 return 0;
228 }
229
230 #endif /* INCLUDE_CMD_TIMER */