ReactOS 0.4.16-dev-91-g764881a
date.c File Reference
#include "precomp.h"
Include dependency graph for date.c:

Go to the source code of this file.

Functions

static VOID PromptDateString (VOID)
 
static BOOL ReadNumber (LPTSTR *s, LPWORD lpwValue)
 
static BOOL ReadSeparator (LPTSTR *s)
 
static BOOL ParseDate (LPTSTR s)
 
INT cmd_date (LPTSTR param)
 

Variables

static WORD awMonths [2][13]
 

Function Documentation

◆ cmd_date()

INT cmd_date ( LPTSTR  param)

Definition at line 176 of file date.c.

177{
178 LPTSTR* arg;
179 INT argc;
180 INT i;
181 BOOL bPrompt = TRUE;
182 INT nDateString = -1;
183 TCHAR szDate[40];
184
185 if (!_tcsncmp(param, _T("/?"), 2))
186 {
188 return 0;
189 }
190
191 nErrorLevel = 0;
192
193 /* Build the parameter array */
194 arg = split(param, &argc, FALSE, FALSE);
195
196 /* Check for options */
197 for (i = 0; i < argc; i++)
198 {
199 if (bEnableExtensions && (_tcsicmp(arg[i], _T("/T")) == 0))
200 bPrompt = FALSE;
201
202 if ((*arg[i] != _T('/')) && (nDateString == -1))
203 nDateString = i;
204 }
205
206 if (nDateString == -1)
207 {
209 ConOutPrintf(_T("%s\n"), GetDateString());
210 }
211
212 if (!bPrompt)
213 {
214 freep(arg);
215 return 0;
216 }
217
218 while (TRUE)
219 {
220 if (nDateString == -1)
221 {
223 ConInString(szDate, ARRAYSIZE(szDate));
224
225 TRACE("\'%s\'\n", debugstr_aw(szDate));
226
227 while (*szDate && szDate[_tcslen(szDate) - 1] < _T(' '))
228 szDate[_tcslen(szDate) - 1] = _T('\0');
229
230 if (ParseDate(szDate))
231 {
232 freep(arg);
233 return 0;
234 }
235 }
236 else
237 {
238 if (ParseDate(arg[nDateString]))
239 {
240 freep(arg);
241 return 0;
242 }
243
244 /* Force input the next time around */
245 nDateString = -1;
246 }
247
249 nErrorLevel = 1;
250 }
251
252 freep(arg);
253 return 0;
254}
static int argc
Definition: ServiceArgs.c:12
INT nErrorLevel
Definition: cmd.c:158
LPTSTR GetDateString(VOID)
Definition: locale.c:58
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:178
#define ConErrResPuts(uID)
Definition: console.h:38
#define ConOutPrintf(szStr,...)
Definition: console.h:41
static BOOL ParseDate(LPTSTR s)
Definition: date.c:93
static VOID PromptDateString(VOID)
Definition: date.c:47
#define debugstr_aw
Definition: precomp.h:44
#define STRING_DATE_ERROR
Definition: resource.h:46
#define STRING_DATE_NOW
Definition: resource.h:138
#define STRING_DATE_HELP4
Definition: resource.h:100
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
unsigned int BOOL
Definition: ntddk_ex.h:94
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 _tcsncmp
Definition: tchar.h:1428
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
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

Referenced by Initialize().

◆ ParseDate()

static BOOL ParseDate ( LPTSTR  s)
static

Definition at line 93 of file date.c.

94{
96 unsigned char leap;
97 LPTSTR p = s;
98
99 if (!*s)
100 return TRUE;
101
102 GetLocalTime (&d);
103
104 d.wYear = 0;
105 d.wDay = 0;
106 d.wMonth = 0;
107
108 switch (nDateFormat)
109 {
110 case 0: /* mmddyy */
111 default:
112 if (!ReadNumber (&p, &d.wMonth))
113 return FALSE;
114 if (!ReadSeparator (&p))
115 return FALSE;
116 if (!ReadNumber (&p, &d.wDay))
117 return FALSE;
118 if (!ReadSeparator (&p))
119 return FALSE;
120 if (!ReadNumber (&p, &d.wYear))
121 return FALSE;
122 break;
123
124 case 1: /* ddmmyy */
125 if (!ReadNumber (&p, &d.wDay))
126 return FALSE;
127 if (!ReadSeparator (&p))
128 return FALSE;
129 if (!ReadNumber (&p, &d.wMonth))
130 return FALSE;
131 if (!ReadSeparator (&p))
132 return FALSE;
133 if (!ReadNumber (&p, &d.wYear))
134 return FALSE;
135 break;
136
137 case 2: /* yymmdd */
138 if (!ReadNumber (&p, &d.wYear))
139 return FALSE;
140 if (!ReadSeparator (&p))
141 return FALSE;
142 if (!ReadNumber (&p, &d.wMonth))
143 return FALSE;
144 if (!ReadSeparator (&p))
145 return FALSE;
146 if (!ReadNumber (&p, &d.wDay))
147 return FALSE;
148 break;
149 }
150
151 /* if only entered two digits: */
152 /* assume 2000's if value less than 80 */
153 /* assume 1900's if value greater or equal 80 */
154 if (d.wYear <= 99)
155 {
156 if (d.wYear >= 80)
157 d.wYear = 1900 + d.wYear;
158 else
159 d.wYear = 2000 + d.wYear;
160 }
161
162 leap = (!(d.wYear % 4) && (d.wYear % 100)) || !(d.wYear % 400);
163
164 if ((d.wMonth >= 1 && d.wMonth <= 12) &&
165 (d.wDay >= 1 && d.wDay <= awMonths[leap][d.wMonth]) &&
166 (d.wYear >= 1980 && d.wYear <= 2099))
167 {
168 SetLocalTime (&d);
169 return TRUE;
170 }
171
172 return FALSE;
173}
INT nDateFormat
Definition: locale.c:20
static BOOL ReadNumber(LPTSTR *s, LPWORD lpwValue)
Definition: date.c:67
static BOOL ReadSeparator(LPTSTR *s)
Definition: date.c:82
static WORD awMonths[2][13]
Definition: date.c:39
BOOL WINAPI SetLocalTime(IN CONST SYSTEMTIME *lpSystemTime)
Definition: time.c:356
VOID WINAPI GetLocalTime(OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:286
GLdouble s
Definition: gl.h:2039
GLfloat GLfloat p
Definition: glext.h:8902
#define d
Definition: ke_i.h:81

Referenced by cmd_date().

◆ PromptDateString()

static VOID PromptDateString ( VOID  )
static

Definition at line 47 of file date.c.

48{
49 switch (nDateFormat)
50 {
51 case 0: /* mmddyy */
52 default:
54 break;
55
56 case 1: /* ddmmyy */
58 break;
59
60 case 2: /* yymmdd */
62 break;
63 }
64}
TCHAR cDateSeparator
Definition: locale.c:16
#define STRING_DATE_HELP2
Definition: resource.h:98
#define STRING_DATE_HELP3
Definition: resource.h:99
#define STRING_DATE_HELP1
Definition: resource.h:97
#define ConOutResPrintf(uID,...)
Definition: replace.h:31

Referenced by cmd_date().

◆ ReadNumber()

static BOOL ReadNumber ( LPTSTR s,
LPWORD  lpwValue 
)
static

Definition at line 67 of file date.c.

68{
69 if (_istdigit (**s))
70 {
71 while (_istdigit (**s))
72 {
73 *lpwValue = *lpwValue * 10 + **s - _T('0');
74 (*s)++;
75 }
76 return TRUE;
77 }
78 return FALSE;
79}
#define _istdigit
Definition: tchar.h:1494

Referenced by ParseDate().

◆ ReadSeparator()

static BOOL ReadSeparator ( LPTSTR s)
static

Definition at line 82 of file date.c.

83{
84 if (**s == _T('/') || **s == _T('-') || **s == cDateSeparator)
85 {
86 (*s)++;
87 return TRUE;
88 }
89 return FALSE;
90}

Referenced by ParseDate().

Variable Documentation

◆ awMonths

WORD awMonths[2][13]
static
Initial value:
=
{
{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
}

Definition at line 39 of file date.c.

Referenced by ParseDate().