ReactOS  0.4.14-dev-384-g5b37caa
date.c File Reference
#include "precomp.h"
Include dependency graph for date.c:

Go to the source code of this file.

Functions

static VOID PrintDateString (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 
184  if (!_tcsncmp (param, _T("/?"), 2))
185  {
187  return 0;
188  }
189 
190  nErrorLevel = 0;
191 
192  /* build parameter array */
193  arg = split (param, &argc, FALSE, FALSE);
194 
195  /* check for options */
196  for (i = 0; i < argc; i++)
197  {
198  if (_tcsicmp (arg[i], _T("/t")) == 0)
199  bPrompt = FALSE;
200  if ((*arg[i] != _T('/')) && (nDateString == -1))
201  nDateString = i;
202  }
203 
204  if (nDateString == -1)
205  ConOutPrintf(_T("%s"), GetDateString());
206 
207  if (!bPrompt)
208  {
209  freep (arg);
210  return 0;
211  }
212 
213  if (nDateString == -1)
214  {
215  while (TRUE) /* forever loop */
216  {
217  TCHAR s[40];
218 
219  PrintDateString ();
220  ConInString (s, 40);
221  TRACE ("\'%s\'\n", debugstr_aw(s));
222  while (*s && s[_tcslen (s) - 1] < _T(' '))
223  s[_tcslen (s) - 1] = _T('\0');
224  if (ParseDate (s))
225  {
226  freep (arg);
227  return 0;
228  }
230  }
231  }
232  else
233  {
234  if (!ParseDate (arg[nDateString]))
235  {
236  while (TRUE) /* forever loop */
237  {
238  TCHAR s[40];
240 
241  PrintDateString ();
242  ConInString (s, 40);
243 
244  while (*s && s[_tcslen (s) - 1] < _T(' '))
245  s[_tcslen (s) - 1] = _T('\0');
246  if (ParseDate (s))
247  {
248  freep (arg);
249  return 0;
250  }
251  }
252  }
253  }
254 
255  freep (arg);
256  return 0;
257 }
INT nErrorLevel
Definition: cmd.c:157
static int argc
Definition: ServiceArgs.c:12
#define TRUE
Definition: types.h:120
#define _tcsicmp
Definition: xmlstorage.h:205
#define ConErrResPuts(uID)
Definition: console.h:39
#define debugstr_aw
Definition: precomp.h:43
static VOID ConInString(LPWSTR lpInput, DWORD dwLength)
Definition: label.c:56
#define ConOutPrintf(szStr,...)
Definition: console.h:42
void * arg
Definition: msvc.h:12
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
int32_t INT
Definition: typedefs.h:56
CHAR * LPTSTR
Definition: xmlstorage.h:192
static BOOL ParseDate(LPTSTR s)
Definition: date.c:93
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
unsigned int BOOL
Definition: ntddk_ex.h:94
static VOID PrintDateString(VOID)
Definition: date.c:47
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
static VOID freep(LPSTR *p)
Definition: cmdcons.c:98
char TCHAR
Definition: xmlstorage.h:189
#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
LPTSTR GetDateString(VOID)
Definition: locale.c:58
GLdouble s
Definition: gl.h:2039
#define STRING_DATE_HELP4
Definition: resource.h:99
#define STRING_DATE_ERROR
Definition: resource.h:39
int _tcsncmp(const _TCHAR *s1, const _TCHAR *s2, size_t n)
Definition: tcsncmp.h:9

Referenced by Initialize().

◆ ParseDate()

static BOOL ParseDate ( LPTSTR  s)
static

Definition at line 93 of file date.c.

94 {
95  SYSTEMTIME d;
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 }
#define TRUE
Definition: types.h:120
static WORD awMonths[2][13]
Definition: date.c:39
CHAR * LPTSTR
Definition: xmlstorage.h:192
VOID WINAPI GetLocalTime(OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:276
#define d
Definition: ke_i.h:81
static BOOL ReadSeparator(LPTSTR *s)
Definition: date.c:82
GLdouble s
Definition: gl.h:2039
INT nDateFormat
Definition: locale.c:20
GLfloat GLfloat p
Definition: glext.h:8902
BOOL WINAPI SetLocalTime(IN CONST SYSTEMTIME *lpSystemTime)
Definition: time.c:346
static BOOL ReadNumber(LPTSTR *s, LPWORD lpwValue)
Definition: date.c:67

Referenced by cmd_date().

◆ PrintDateString()

static VOID PrintDateString ( 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 }
#define STRING_DATE_HELP2
Definition: resource.h:97
#define ConOutResPrintf(uID,...)
Definition: console.h:48
#define STRING_DATE_HELP1
Definition: resource.h:96
TCHAR cDateSeparator
Definition: locale.c:16
#define STRING_DATE_HELP3
Definition: resource.h:98
INT nDateFormat
Definition: locale.c:20

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
#define TRUE
Definition: types.h:120
#define _T(x)
Definition: vfdio.h:22
GLdouble s
Definition: gl.h:2039

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 }
#define TRUE
Definition: types.h:120
#define _T(x)
Definition: vfdio.h:22
TCHAR cDateSeparator
Definition: locale.c:16
GLdouble s
Definition: gl.h:2039

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().