2 * TIME.C - time internal command.
7 * 07/08/1998 (John P. Price)
10 * 27-Jul-1998 (John P Price <linux-guru@gcfl.net>)
11 * added config.h include
13 * 09-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
14 * Added locale support.
16 * 19-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
17 * Unicode and redirection safe!
20 * 04-Feb-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
21 * Fixed time input bug.
26 #ifdef INCLUDE_CMD_TIME
29 static BOOL
ParseTime (LPTSTR s
)
48 t
.wHour
= t
.wHour
* 10 + *p
- _T('0');
56 if (*p
!= cTimeSeparator
)
65 t
.wMinute
= t
.wMinute
* 10 + *p
- _T('0');
73 if (*p
!= cTimeSeparator
)
82 t
.wSecond
= t
.wSecond
* 10 + *p
- _T('0');
89 // get decimal separator
90 if (*p
== cDecimalSeparator
)
99 // t.wMilliseconds = t.wMilliseconds * 10 + *p - _T('0');
102 // t.wMilliseconds *= 10;
106 /* special case: 12 hour format */
107 if (nTimeFormat
== 0)
109 if (_totupper(*s
) == _T('P'))
114 if ((_totupper(*s
) == _T('A')) && (t
.wHour
== 12))
120 if (t
.wHour
> 23 || t
.wMinute
> 60 || t
.wSecond
> 60 || t
.wMilliseconds
> 999)
129 INT
cmd_time (LPTSTR cmd
, LPTSTR param
)
135 INT nTimeString
= -1;
137 if (!_tcsncmp (param
, _T("/?"), 2))
139 ConOutPuts (_T("Displays or sets the system time.\n"
145 "Type TIME with no parameters to display the current time setting and a prompt\n"
146 "for a new one. Press ENTER to keep the same time."));
150 /* build parameter array */
151 arg
= split (param
, &argc
, FALSE
);
153 /* check for options */
154 for (i
= 0; i
< argc
; i
++)
156 if (_tcsicmp (arg
[i
], _T("/t")) == 0)
159 if ((*arg
[i
] != _T('/')) && (nTimeString
== -1))
163 if (nTimeString
== -1)
174 if (nTimeString
== -1)
178 ConOutPrintf (_T("Enter new time: "));
183 DebugPrintf (_T("\'%s\'\n"), s
);
186 while (*s
&& s
[_tcslen (s
) - 1] < _T(' '))
187 s
[_tcslen(s
) - 1] = _T('\0');
197 if (ParseTime (arg
[nTimeString
]))
203 /* force input the next time around. */
206 ConErrPuts (_T("Invalid time."));