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
36 static BOOL
ParseTime (LPTSTR s
)
55 t
.wHour
= t
.wHour
* 10 + *p
- _T('0');
63 if (*p
!= cTimeSeparator
)
72 t
.wMinute
= t
.wMinute
* 10 + *p
- _T('0');
80 if (*p
!= cTimeSeparator
)
89 t
.wSecond
= t
.wSecond
* 10 + *p
- _T('0');
96 // get decimal separator
97 if (*p
== cDecimalSeparator
)
104 while (_istdigit(*p
))
106 // t.wMilliseconds = t.wMilliseconds * 10 + *p - _T('0');
109 // t.wMilliseconds *= 10;
113 /* special case: 12 hour format */
114 if (nTimeFormat
== 0)
116 if (_totupper(*s
) == _T('P'))
121 if ((_totupper(*s
) == _T('A')) && (t
.wHour
== 12))
127 if (t
.wHour
> 23 || t
.wMinute
> 60 || t
.wSecond
> 60 || t
.wMilliseconds
> 999)
136 INT
cmd_time (LPTSTR cmd
, LPTSTR param
)
142 INT nTimeString
= -1;
144 if (!_tcsncmp (param
, _T("/?"), 2))
146 ConOutPuts (_T("Displays or sets the system time.\n"
152 "Type TIME with no parameters to display the current time setting and a prompt\n"
153 "for a new one. Press ENTER to keep the same time."));
157 /* build parameter array */
158 arg
= split (param
, &argc
);
160 /* check for options */
161 for (i
= 0; i
< argc
; i
++)
163 if (_tcsicmp (arg
[i
], _T("/t")) == 0)
166 if ((*arg
[i
] != _T('/')) && (nTimeString
== -1))
170 if (nTimeString
== -1)
181 if (nTimeString
== -1)
185 ConOutPrintf (_T("Enter new time: "));
190 DebugPrintf ("\'%s\'\n", s
);
193 while (*s
&& s
[_tcslen (s
) - 1] < _T(' '))
194 s
[_tcslen(s
) - 1] = _T('\0');
204 if (ParseTime (arg
[nTimeString
]))
210 /* force input the next time around. */
213 ConErrPuts (_T("Invalid time."));