ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

time.c
Go to the documentation of this file.
00001 /*
00002  *  TIME.C - time internal command.
00003  *
00004  *
00005  *  History:
00006  *
00007  *    07/08/1998 (John P. Price)
00008  *        started.
00009  *
00010  *    27-Jul-1998 (John P Price <linux-guru@gcfl.net>)
00011  *        added config.h include
00012  *
00013  *    09-Jan-1999 (Eric Kohl)
00014  *        Added locale support.
00015  *
00016  *    19-Jan-1999 (Eric Kohl)
00017  *        Unicode and redirection safe!
00018  *        Added "/t" option.
00019  *
00020  *    04-Feb-1999 (Eric Kohl)
00021  *        Fixed time input bug.
00022  *
00023  *    30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
00024  *        Remove all hardcode string to En.rc.
00025  */
00026 
00027 #include <precomp.h>
00028 
00029 #ifdef INCLUDE_CMD_TIME
00030 
00031 
00032 static BOOL ParseTime (LPTSTR s)
00033 {
00034     SYSTEMTIME t;
00035     LPTSTR p = s;
00036 
00037     if (!*s)
00038         return TRUE;
00039 
00040     GetLocalTime (&t);
00041     t.wHour = 0;
00042     t.wMinute = 0;
00043     t.wSecond = 0;
00044     t.wMilliseconds = 0;
00045 
00046     // first get hour
00047     if (_istdigit(*p))
00048     {
00049         while (_istdigit(*p))
00050         {
00051             t.wHour = t.wHour * 10 + *p - _T('0');
00052             p++;
00053         }
00054     }
00055     else
00056         return FALSE;
00057 
00058     // get time separator
00059     if (*p != cTimeSeparator)
00060         return FALSE;
00061     p++;
00062 
00063     // now get minutes
00064     if (_istdigit(*p))
00065     {
00066         while (_istdigit(*p))
00067         {
00068             t.wMinute = t.wMinute * 10 + *p - _T('0');
00069             p++;
00070         }
00071     }
00072     else
00073         return FALSE;
00074 
00075     // get time separator
00076     if (*p != cTimeSeparator)
00077         return FALSE;
00078     p++;
00079 
00080     // now get seconds
00081     if (_istdigit(*p))
00082     {
00083         while (_istdigit(*p))
00084         {
00085             t.wSecond = t.wSecond * 10 + *p - _T('0');
00086             p++;
00087         }
00088     }
00089     else
00090         return FALSE;
00091 
00092     // get decimal separator
00093     if (*p == cDecimalSeparator)
00094     {
00095         p++;
00096 
00097         // now get hundreths
00098         if (_istdigit(*p))
00099         {
00100             while (_istdigit(*p))
00101             {
00102 //              t.wMilliseconds = t.wMilliseconds * 10 + *p - _T('0');
00103                 p++;
00104             }
00105 //          t.wMilliseconds *= 10;
00106         }
00107     }
00108 
00109     /* special case: 12 hour format */
00110     if (nTimeFormat == 0)
00111     {
00112         if (_totupper(*s) == _T('P'))
00113         {
00114             t.wHour += 12;
00115         }
00116 
00117         if ((_totupper(*s) == _T('A')) && (t.wHour == 12))
00118         {
00119             t.wHour = 0;
00120         }
00121     }
00122 
00123     if (t.wHour > 23 || t.wMinute > 60 || t.wSecond > 60 || t.wMilliseconds > 999)
00124         return FALSE;
00125 
00126     SetLocalTime (&t);
00127 
00128     return TRUE;
00129 }
00130 
00131 
00132 INT cmd_time (LPTSTR param)
00133 {
00134     LPTSTR *arg;
00135     INT    argc;
00136     INT    i;
00137     INT    nTimeString = -1;
00138 
00139     if (!_tcsncmp (param, _T("/?"), 2))
00140     {
00141         ConOutResPaging(TRUE,STRING_TIME_HELP1);
00142         return 0;
00143     }
00144 
00145   nErrorLevel = 0;
00146 
00147     /* build parameter array */
00148     arg = split (param, &argc, FALSE, FALSE);
00149 
00150     /* check for options */
00151     for (i = 0; i < argc; i++)
00152     {
00153         if (_tcsicmp (arg[i], _T("/t")) == 0)
00154         {
00155             /* Display current time in short format */
00156             SYSTEMTIME st;
00157             TCHAR szTime[20];
00158             GetLocalTime(&st);
00159             FormatTime(szTime, &st);
00160             ConOutPuts(szTime);
00161             freep(arg);
00162             return 0;
00163         }
00164 
00165         if ((*arg[i] != _T('/')) && (nTimeString == -1))
00166             nTimeString = i;
00167     }
00168 
00169     if (nTimeString == -1)
00170     {
00171         ConOutResPrintf(STRING_LOCALE_HELP1);
00172         ConOutPrintf(_T(": %s\n"), GetTimeString());
00173     }
00174 
00175     while (1)
00176     {
00177         if (nTimeString == -1)
00178         {
00179             TCHAR  s[40];
00180 
00181             ConOutResPuts(STRING_TIME_HELP2);
00182 
00183             ConInString (s, 40);
00184 
00185             TRACE ("\'%s\'\n", debugstr_aw(s));
00186 
00187             while (*s && s[_tcslen (s) - 1] < _T(' '))
00188                 s[_tcslen(s) - 1] = _T('\0');
00189 
00190             if (ParseTime (s))
00191             {
00192                 freep (arg);
00193                 return 0;
00194             }
00195         }
00196         else
00197         {
00198             if (ParseTime (arg[nTimeString]))
00199             {
00200                 freep (arg);
00201                 return 0;
00202             }
00203 
00204             /* force input the next time around. */
00205             nTimeString = -1;
00206         }
00207 
00208         ConErrResPuts(STRING_TIME_ERROR1);
00209     nErrorLevel = 1;
00210     }
00211 
00212     freep (arg);
00213 
00214     return 0;
00215 }
00216 
00217 #endif

Generated on Fri May 25 2012 04:16:33 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.