ReactOS  0.4.14-dev-376-gaedba84
timer.c
Go to the documentation of this file.
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 //print timer value
20 #define PT(format) PrintElapsedTime(GetTickCount()-cT,format)
21 
22 
23 //current timer Time (at wich started to count)
24 #define cT clksT[clk_n]
25 
26 //current timer status
27 #define cS clksS[clk_n]
28 
29 
30 static VOID
32 {
33  DWORD h,m,s,ms;
34 
35  TRACE ("PrintElapsedTime(%d,%d)",time,format);
36 
37  switch (format)
38  {
39  case 0:
41  break;
42 
43  case 1:
44  ms = time % 1000;
45  time /= 1000;
46  s = time % 60;
47  time /=60;
48  m = time % 60;
49  h = time / 60;
53  s, cDecimalSeparator, ms/10);
54  break;
55  }
56 }
57 
58 
60 {
61  // all timers are kept
62  static DWORD clksT[10];
63 
64  // timers status
65  // set all the clocks off by default
66  static BOOL clksS[10]={FALSE,FALSE,FALSE,FALSE,
68 
69  // TRUE if /S in command line
70  BOOL bS = FALSE;
71 
72  // avoid to set clk_n more than once
73  BOOL bCanNSet = TRUE;
74 
75  INT NewClkStatus = NCS_NOT_SPECIFIED;
76 
77  // the clock number specified on the command line
78  // 1 by default
79  INT clk_n=1;
80 
81  // output format
82  INT iFormat=1;
83 
84 
85  // command line parsing variables
86  INT argc;
87  LPTSTR *p;
88 
89  INT i;
90 
91  if (_tcsncmp (param, _T("/?"), 2) == 0)
92  {
94  return 0;
95  }
96 
97  nErrorLevel = 0;
98 
99  p = split (param, &argc, FALSE, FALSE);
100 
101  //read options
102  for (i = 0; i < argc; i++)
103  {
104  //set timer on
105  if (!(_tcsicmp(&p[i][0],_T("on"))) && NewClkStatus == NCS_NOT_SPECIFIED)
106  {
107  NewClkStatus = NCS_ON;
108  continue;
109  }
110 
111  //set timer off
112  if (!(_tcsicmp(&p[i][0],_T("off"))) && NewClkStatus == NCS_NOT_SPECIFIED)
113  {
114  NewClkStatus = NCS_OFF;
115  continue;
116  }
117 
118  // other options
119  if (p[i][0] == _T('/'))
120  {
121  // set timer number
122  if (_istdigit(p[i][1]) && bCanNSet)
123  {
124  clk_n = p[i][1] - _T('0');
125  bCanNSet = FALSE;
126  continue;
127  }
128 
129  // set s(plit) option
130  if (_totupper(p[i][1]) == _T('S'))
131  {
132  bS = TRUE;
133  continue;
134  }
135 
136  // specify format
137  if (_totupper(p[i][1]) == _T('F'))
138  {
139  iFormat = p[i][2] - _T('0');
140  continue;
141  }
142  }
143  }
144 
145  // do stuff (start/stop/read timer)
146  if (NewClkStatus == NCS_ON)
147  {
148  cT=GetTickCount();
149  cS=TRUE;
150 
151  ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
153  freep(p);
154  return 0;
155  }
156 
157  if (bS)
158  {
159  if (cS)
160  {
161  ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
162  ConOutPrintf(_T("%s\n"), GetTimeString());
164  freep(p);
165  return 0;
166  }
167 
168  cT=GetTickCount();
169  cS=TRUE;
170  ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
172  freep(p);
173  return 0;
174  }
175 
176  if (NewClkStatus == NCS_NOT_SPECIFIED)
177  {
178  if (cS)
179  {
180  cS=FALSE;
181  ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
182  ConOutPrintf(_T("%s\n"), GetTimeString());
184  freep(p);
185  return 0;
186  }
187 
188  cT=GetTickCount();
189  cS=TRUE;
190  ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
192  freep(p);
193  return 0;
194  }
195 
196 
197  if (NewClkStatus == NCS_OFF)
198  {
199  if (cS)
200  {
201  cS=FALSE;
202  ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
203  ConOutPrintf(_T("%s\n"), GetTimeString());
205  freep(p);
206  return 0;
207  }
208  ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
210  freep(p);
211  return 0;
212  }
213 
214  freep(p);
215  return 0;
216 }
217 
218 #endif /* INCLUDE_CMD_TIMER */
INT nErrorLevel
Definition: cmd.c:157
static int argc
Definition: ServiceArgs.c:12
#define _istdigit
Definition: tchar.h:1494
#define NCS_NOT_SPECIFIED
Definition: timer.c:15
#define TRUE
Definition: types.h:120
#define _tcsicmp
Definition: xmlstorage.h:205
#define STRING_TIMER_HELP1
Definition: resource.h:180
#define STRING_TIMER_TIME
Definition: resource.h:213
static VOID PrintElapsedTime(DWORD time, INT format)
Definition: timer.c:31
DWORD WINAPI GetTickCount(VOID)
Definition: time.c:445
#define NCS_ON
Definition: timer.c:16
#define ConOutPrintf(szStr,...)
Definition: console.h:42
__u16 time
Definition: mkdosfs.c:366
#define _totupper
Definition: tchar.h:1509
int32_t INT
Definition: typedefs.h:56
CHAR * LPTSTR
Definition: xmlstorage.h:192
const GLfloat * m
Definition: glext.h:10848
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
LPTSTR GetTimeString(VOID)
Definition: locale.c:73
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define cT
Definition: timer.c:24
unsigned int BOOL
Definition: ntddk_ex.h:94
static VOID freep(LPSTR *p)
Definition: cmdcons.c:98
#define STRING_TIMER_HELP2
Definition: resource.h:181
INT CommandTimer(LPTSTR param)
Definition: timer.c:59
TCHAR cTimeSeparator
Definition: locale.c:17
TCHAR cDecimalSeparator
Definition: locale.c:19
#define _T(x)
Definition: vfdio.h:22
#define TRACE(s)
Definition: solgame.cpp:4
GLfloat param
Definition: glext.h:5796
static LPSTR * split(LPSTR s, LPINT args)
Definition: cmdcons.c:163
#define ConOutResPrintf(uID,...)
Definition: console.h:48
unsigned long DWORD
Definition: ntddk_ex.h:95
#define cS
Definition: timer.c:27
GLdouble s
Definition: gl.h:2039
_In_ SIZEL _In_ ULONG iFormat
Definition: winddi.h:3467
#define NCS_OFF
Definition: timer.c:17
#define STRING_TIMER_HELP3
Definition: resource.h:182
GLfloat GLfloat p
Definition: glext.h:8902
int _tcsncmp(const _TCHAR *s1, const _TCHAR *s2, size_t n)
Definition: tcsncmp.h:9
VOID ConOutPuts(LPTSTR szText)
Definition: tee.c:27