ReactOS 0.4.16-dev-106-g10b08aa
time.c
Go to the documentation of this file.
1/*
2 * TIME.C - time internal command.
3 *
4 *
5 * History:
6 *
7 * 07/08/1998 (John P. Price)
8 * started.
9 *
10 * 27-Jul-1998 (John P Price <linux-guru@gcfl.net>)
11 * added config.h include
12 *
13 * 09-Jan-1999 (Eric Kohl)
14 * Added locale support.
15 *
16 * 19-Jan-1999 (Eric Kohl)
17 * Unicode and redirection safe!
18 * Added "/t" option.
19 *
20 * 04-Feb-1999 (Eric Kohl)
21 * Fixed time input bug.
22 *
23 * 30-Apr-2005 (Magnus Olsen <magnus@greatlord.com>)
24 * Remove all hardcoded strings in En.rc.
25 */
26
27#include "precomp.h"
28
29#ifdef INCLUDE_CMD_TIME
30
31
33{
35 LPTSTR p = s;
36
37 if (!*s)
38 return TRUE;
39
40 GetLocalTime (&t);
41 t.wHour = 0;
42 t.wMinute = 0;
43 t.wSecond = 0;
44 t.wMilliseconds = 0;
45
46 // first get hour
47 if (_istdigit(*p))
48 {
49 while (_istdigit(*p))
50 {
51 t.wHour = t.wHour * 10 + *p - _T('0');
52 p++;
53 }
54 }
55 else
56 return FALSE;
57
58 // get time separator
59 if (*p != cTimeSeparator)
60 return FALSE;
61 p++;
62
63 // now get minutes
64 if (_istdigit(*p))
65 {
66 while (_istdigit(*p))
67 {
68 t.wMinute = t.wMinute * 10 + *p - _T('0');
69 p++;
70 }
71 }
72 else
73 return FALSE;
74
75 // get time separator
76 if (*p != cTimeSeparator)
77 return FALSE;
78 p++;
79
80 // now get seconds
81 if (_istdigit(*p))
82 {
83 while (_istdigit(*p))
84 {
85 t.wSecond = t.wSecond * 10 + *p - _T('0');
86 p++;
87 }
88 }
89 else
90 return FALSE;
91
92 // get decimal separator
93 if (*p == cDecimalSeparator)
94 {
95 p++;
96
97 // now get hundreths
98 if (_istdigit(*p))
99 {
100 while (_istdigit(*p))
101 {
102 // t.wMilliseconds = t.wMilliseconds * 10 + *p - _T('0');
103 p++;
104 }
105 // t.wMilliseconds *= 10;
106 }
107 }
108
109 /* special case: 12 hour format */
110 if (nTimeFormat == 0)
111 {
112 if (_totupper(*s) == _T('P'))
113 {
114 t.wHour += 12;
115 }
116
117 if ((_totupper(*s) == _T('A')) && (t.wHour == 12))
118 {
119 t.wHour = 0;
120 }
121 }
122
123 if (t.wHour > 23 || t.wMinute > 60 || t.wSecond > 60 || t.wMilliseconds > 999)
124 return FALSE;
125
126 SetLocalTime (&t);
127
128 return TRUE;
129}
130
131
133{
134 LPTSTR* arg;
135 INT argc;
136 INT i;
137 INT nTimeString = -1;
138 TCHAR szTime[40];
139
140 if (!_tcsncmp(param, _T("/?"), 2))
141 {
143 return 0;
144 }
145
146 nErrorLevel = 0;
147
148 /* Build the parameter array */
149 arg = split(param, &argc, FALSE, FALSE);
150
151 /* Check for options */
152 for (i = 0; i < argc; i++)
153 {
154 if (bEnableExtensions && (_tcsicmp(arg[i], _T("/T")) == 0))
155 {
156 /* Display current time in short format */
157 SYSTEMTIME st;
158 GetLocalTime(&st);
159 FormatTime(szTime, &st);
160 ConOutPrintf(_T("%s\n"), szTime);
161 freep(arg);
162 return 0;
163 }
164
165 if ((*arg[i] != _T('/')) && (nTimeString == -1))
166 nTimeString = i;
167 }
168
169 if (nTimeString == -1)
170 {
172 ConOutPrintf(_T("%s\n"), GetTimeString());
173 }
174
175 while (TRUE)
176 {
177 if (nTimeString == -1)
178 {
181
182 TRACE("\'%s\'\n", debugstr_aw(szTime));
183
184 while (*szTime && szTime[_tcslen(szTime) - 1] < _T(' '))
185 szTime[_tcslen(szTime) - 1] = _T('\0');
186
187 if (ParseTime(szTime))
188 {
189 freep(arg);
190 return 0;
191 }
192 }
193 else
194 {
195 if (ParseTime(arg[nTimeString]))
196 {
197 freep(arg);
198 return 0;
199 }
200
201 /* Force input the next time around */
202 nTimeString = -1;
203 }
204
206 nErrorLevel = 1;
207 }
208
209 freep(arg);
210 return 0;
211}
212
213#endif
static int argc
Definition: ServiceArgs.c:12
INT nErrorLevel
Definition: cmd.c:158
INT nTimeFormat
Definition: locale.c:21
TCHAR cTimeSeparator
Definition: locale.c:17
LPTSTR GetTimeString(VOID)
Definition: locale.c:70
TCHAR cDecimalSeparator
Definition: locale.c:19
INT FormatTime(TCHAR *, LPSYSTEMTIME)
Definition: dir.c:704
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:178
#define ConErrResPuts(uID)
Definition: console.h:38
#define ConOutPrintf(szStr,...)
Definition: console.h:41
#define debugstr_aw
Definition: precomp.h:44
#define STRING_TIME_ERROR
Definition: resource.h:64
#define STRING_TIME_HELP2
Definition: resource.h:180
#define STRING_TIME_HELP1
Definition: resource.h:179
#define STRING_TIME_NOW
Definition: resource.h:139
INT cmd_time(LPTSTR param)
Definition: time.c:132
static BOOL ParseTime(LPTSTR s)
Definition: time.c:32
static VOID freep(LPSTR *p)
Definition: cmdcons.c:98
static LPSTR * split(LPSTR s, LPINT args)
Definition: cmdcons.c:163
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
BOOL WINAPI SetLocalTime(IN CONST SYSTEMTIME *lpSystemTime)
Definition: time.c:356
VOID WINAPI GetLocalTime(OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:286
unsigned int BOOL
Definition: ntddk_ex.h:94
GLdouble s
Definition: gl.h:2039
GLdouble GLdouble t
Definition: gl.h:2047
GLfloat GLfloat p
Definition: glext.h:8902
GLfloat param
Definition: glext.h:5796
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 _istdigit
Definition: tchar.h:1494
#define _tcsncmp
Definition: tchar.h:1428
#define _totupper
Definition: tchar.h:1509
static VOID ConInString(LPWSTR lpInput, DWORD dwLength)
Definition: label.c:56
BOOL bEnableExtensions
Definition: more.c:53
#define ConOutResPuts(uID)
Definition: replace.h:28
#define TRACE(s)
Definition: solgame.cpp:4
TCHAR szTime[64]
Definition: solitaire.cpp:20
int32_t INT
Definition: typedefs.h:58
#define _T(x)
Definition: vfdio.h:22
void * arg
Definition: msvc.h:10
char TCHAR
Definition: xmlstorage.h:189
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define _tcslen
Definition: xmlstorage.h:198
#define _tcsicmp
Definition: xmlstorage.h:205