Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygendate.c
Go to the documentation of this file.
00001 /* 00002 * DATE.C - date internal command. 00003 * 00004 * 00005 * History: 00006 * 00007 * 08 Jul 1998 (John P. Price) 00008 * started. 00009 * 00010 * 20 Jul 1998 (John P. Price) 00011 * corrected number of days for December from 30 to 31. 00012 * (Thanx to Steffen Kaiser for bug report) 00013 * 00014 * 27-Jul-1998 (John P Price <linux-guru@gcfl.net>) 00015 * added config.h include 00016 * 00017 * 29-Jul-1998 (Rob Lake) 00018 * fixed stand-alone mode. 00019 * Added Pacific C compatible dos_getdate functions 00020 * 00021 * 09-Jan-1999 (Eric Kohl) 00022 * Added locale support 00023 * 00024 * 23-Jan-1999 (Eric Kohl) 00025 * Unicode and redirection safe! 00026 * 00027 * 04-Feb-1999 (Eric Kohl) 00028 * Fixed date input bug. 00029 * 00030 * 03-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>) 00031 * Remove all hardcode string to En.rc 00032 */ 00033 00034 #include <precomp.h> 00035 00036 #ifdef INCLUDE_CMD_DATE 00037 00038 00039 static WORD awMonths[2][13] = 00040 { 00041 {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, 00042 {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} 00043 }; 00044 00045 00046 static VOID 00047 PrintDateString (VOID) 00048 { 00049 switch (nDateFormat) 00050 { 00051 case 0: /* mmddyy */ 00052 default: 00053 ConOutResPrintf(STRING_DATE_HELP1, cDateSeparator, cDateSeparator); 00054 break; 00055 00056 case 1: /* ddmmyy */ 00057 ConOutResPrintf(STRING_DATE_HELP2, cDateSeparator, cDateSeparator); 00058 break; 00059 00060 case 2: /* yymmdd */ 00061 ConOutResPrintf(STRING_DATE_HELP3, cDateSeparator, cDateSeparator); 00062 break; 00063 } 00064 } 00065 00066 00067 static BOOL 00068 ReadNumber (LPTSTR *s, LPWORD lpwValue) 00069 { 00070 if (_istdigit (**s)) 00071 { 00072 while (_istdigit (**s)) 00073 { 00074 *lpwValue = *lpwValue * 10 + **s - _T('0'); 00075 (*s)++; 00076 } 00077 return TRUE; 00078 } 00079 return FALSE; 00080 } 00081 00082 00083 static BOOL 00084 ReadSeparator (LPTSTR *s) 00085 { 00086 if (**s == _T('/') || **s == _T('-') || **s == cDateSeparator) 00087 { 00088 (*s)++; 00089 return TRUE; 00090 } 00091 return FALSE; 00092 } 00093 00094 00095 static BOOL 00096 ParseDate (LPTSTR s) 00097 { 00098 SYSTEMTIME d; 00099 unsigned char leap; 00100 LPTSTR p = s; 00101 00102 if (!*s) 00103 return TRUE; 00104 00105 GetLocalTime (&d); 00106 00107 d.wYear = 0; 00108 d.wDay = 0; 00109 d.wMonth = 0; 00110 00111 switch (nDateFormat) 00112 { 00113 case 0: /* mmddyy */ 00114 default: 00115 if (!ReadNumber (&p, &d.wMonth)) 00116 return FALSE; 00117 if (!ReadSeparator (&p)) 00118 return FALSE; 00119 if (!ReadNumber (&p, &d.wDay)) 00120 return FALSE; 00121 if (!ReadSeparator (&p)) 00122 return FALSE; 00123 if (!ReadNumber (&p, &d.wYear)) 00124 return FALSE; 00125 break; 00126 00127 case 1: /* ddmmyy */ 00128 if (!ReadNumber (&p, &d.wDay)) 00129 return FALSE; 00130 if (!ReadSeparator (&p)) 00131 return FALSE; 00132 if (!ReadNumber (&p, &d.wMonth)) 00133 return FALSE; 00134 if (!ReadSeparator (&p)) 00135 return FALSE; 00136 if (!ReadNumber (&p, &d.wYear)) 00137 return FALSE; 00138 break; 00139 00140 case 2: /* yymmdd */ 00141 if (!ReadNumber (&p, &d.wYear)) 00142 return FALSE; 00143 if (!ReadSeparator (&p)) 00144 return FALSE; 00145 if (!ReadNumber (&p, &d.wMonth)) 00146 return FALSE; 00147 if (!ReadSeparator (&p)) 00148 return FALSE; 00149 if (!ReadNumber (&p, &d.wDay)) 00150 return FALSE; 00151 break; 00152 } 00153 00154 /* if only entered two digits: */ 00155 /* assume 2000's if value less than 80 */ 00156 /* assume 1900's if value greater or equal 80 */ 00157 if (d.wYear <= 99) 00158 { 00159 if (d.wYear >= 80) 00160 d.wYear = 1900 + d.wYear; 00161 else 00162 d.wYear = 2000 + d.wYear; 00163 } 00164 00165 leap = (!(d.wYear % 4) && (d.wYear % 100)) || !(d.wYear % 400); 00166 00167 if ((d.wMonth >= 1 && d.wMonth <= 12) && 00168 (d.wDay >= 1 && d.wDay <= awMonths[leap][d.wMonth]) && 00169 (d.wYear >= 1980 && d.wYear <= 2099)) 00170 { 00171 SetLocalTime (&d); 00172 return TRUE; 00173 } 00174 00175 return FALSE; 00176 } 00177 00178 00179 INT cmd_date (LPTSTR param) 00180 { 00181 LPTSTR *arg; 00182 INT argc; 00183 INT i; 00184 BOOL bPrompt = TRUE; 00185 INT nDateString = -1; 00186 00187 if (!_tcsncmp (param, _T("/?"), 2)) 00188 { 00189 ConOutResPaging(TRUE,STRING_DATE_HELP4); 00190 return 0; 00191 } 00192 00193 nErrorLevel = 0; 00194 00195 /* build parameter array */ 00196 arg = split (param, &argc, FALSE, FALSE); 00197 00198 /* check for options */ 00199 for (i = 0; i < argc; i++) 00200 { 00201 if (_tcsicmp (arg[i], _T("/t")) == 0) 00202 bPrompt = FALSE; 00203 if ((*arg[i] != _T('/')) && (nDateString == -1)) 00204 nDateString = i; 00205 } 00206 00207 if (nDateString == -1) 00208 ConOutPrintf(_T("%s"), GetDateString()); 00209 00210 if (!bPrompt) 00211 { 00212 freep (arg); 00213 return 0; 00214 } 00215 00216 if (nDateString == -1) 00217 { 00218 while (TRUE) /* forever loop */ 00219 { 00220 TCHAR s[40]; 00221 00222 PrintDateString (); 00223 ConInString (s, 40); 00224 TRACE ("\'%s\'\n", debugstr_aw(s)); 00225 while (*s && s[_tcslen (s) - 1] < _T(' ')) 00226 s[_tcslen (s) - 1] = _T('\0'); 00227 if (ParseDate (s)) 00228 { 00229 freep (arg); 00230 return 0; 00231 } 00232 ConErrResPuts(STRING_DATE_ERROR); 00233 00234 } 00235 } 00236 else 00237 { 00238 if (!ParseDate (arg[nDateString])) 00239 { 00240 while (TRUE) /* forever loop */ 00241 { 00242 TCHAR s[40]; 00243 ConErrResPuts(STRING_DATE_ERROR); 00244 00245 PrintDateString (); 00246 ConInString (s, 40); 00247 00248 while (*s && s[_tcslen (s) - 1] < _T(' ')) 00249 s[_tcslen (s) - 1] = _T('\0'); 00250 if (ParseDate (s)) 00251 { 00252 freep (arg); 00253 return 0; 00254 } 00255 } 00256 } 00257 } 00258 00259 freep (arg); 00260 00261 return 0; 00262 } 00263 #endif /* INCLUDE_CMD_DATE */ 00264 00265 /* EOF */ Generated on Mon May 28 2012 04:17:59 for ReactOS by
1.7.6.1
|