Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygentimer.c
Go to the documentation of this file.
00001 /* 00002 * TIMER.C - timer internal command. 00003 * 00004 * clone from 4nt timer command 00005 * 00006 * 20 Aug 1999 00007 * started - Paolo Pantaleo <paolopan@freemail.it> 00008 */ 00009 00010 #include <precomp.h> 00011 00012 #ifdef INCLUDE_CMD_TIMER 00013 00014 00015 #define NCS_NOT_SPECIFIED -1 00016 #define NCS_ON 1 00017 #define NCS_OFF 0 00018 00019 00020 00021 00022 00023 //print timer value 00024 #define PT(format) PrintElapsedTime(GetTickCount()-cT,format) 00025 00026 00027 //current timer Time (at wich started to count) 00028 #define cT clksT[clk_n] 00029 00030 //current timer status 00031 #define cS clksS[clk_n] 00032 00033 00034 static VOID 00035 PrintElapsedTime (DWORD time,INT format) 00036 { 00037 DWORD h,m,s,ms; 00038 00039 TRACE ("PrintElapsedTime(%d,%d)",time,format); 00040 00041 switch (format) 00042 { 00043 case 0: 00044 ConOutResPrintf(STRING_TIMER_HELP1, time); 00045 break; 00046 00047 case 1: 00048 ms = time % 1000; 00049 time /= 1000; 00050 s = time % 60; 00051 time /=60; 00052 m = time % 60; 00053 h = time / 60; 00054 ConOutResPrintf(STRING_TIMER_HELP2, 00055 h, cTimeSeparator, 00056 m, cTimeSeparator, 00057 s, cDecimalSeparator, ms/10); 00058 break; 00059 } 00060 } 00061 00062 00063 INT CommandTimer (LPTSTR param) 00064 { 00065 // all timers are kept 00066 static DWORD clksT[10]; 00067 00068 // timers status 00069 // set all the clocks off by default 00070 static BOOL clksS[10]={FALSE,FALSE,FALSE,FALSE, 00071 FALSE,FALSE,FALSE,FALSE,FALSE,FALSE}; 00072 00073 // TRUE if /S in command line 00074 BOOL bS = FALSE; 00075 00076 // avoid to set clk_n more than once 00077 BOOL bCanNSet = TRUE; 00078 00079 INT NewClkStatus = NCS_NOT_SPECIFIED; 00080 00081 // the clock number specified on the command line 00082 // 1 by default 00083 INT clk_n=1; 00084 00085 // output format 00086 INT iFormat=1; 00087 00088 00089 // command line parsing variables 00090 INT argc; 00091 LPTSTR *p; 00092 00093 INT i; 00094 00095 if (_tcsncmp (param, _T("/?"), 2) == 0) 00096 { 00097 ConOutResPrintf(STRING_TIMER_HELP3, cTimeSeparator, cTimeSeparator, cDecimalSeparator); 00098 return 0; 00099 } 00100 00101 nErrorLevel = 0; 00102 00103 p = split (param, &argc, FALSE, FALSE); 00104 00105 //read options 00106 for (i = 0; i < argc; i++) 00107 { 00108 //set timer on 00109 if (!(_tcsicmp(&p[i][0],_T("on"))) && NewClkStatus == NCS_NOT_SPECIFIED) 00110 { 00111 NewClkStatus = NCS_ON; 00112 continue; 00113 } 00114 00115 //set timer off 00116 if (!(_tcsicmp(&p[i][0],_T("off"))) && NewClkStatus == NCS_NOT_SPECIFIED) 00117 { 00118 NewClkStatus = NCS_OFF; 00119 continue; 00120 } 00121 00122 // other options 00123 if (p[i][0] == _T('/')) 00124 { 00125 // set timer number 00126 if (_istdigit(p[i][1]) && bCanNSet) 00127 { 00128 clk_n = p[i][1] - _T('0'); 00129 bCanNSet = FALSE; 00130 continue; 00131 } 00132 00133 // set s(plit) option 00134 if (_totupper(p[i][1]) == _T('S')) 00135 { 00136 bS = TRUE; 00137 continue; 00138 } 00139 00140 // specify format 00141 if (_totupper(p[i][1]) == _T('F')) 00142 { 00143 iFormat = p[i][2] - _T('0'); 00144 continue; 00145 } 00146 } 00147 } 00148 00149 // do stuff (start/stop/read timer) 00150 if(NewClkStatus == NCS_ON) 00151 { 00152 cT=GetTickCount(); 00153 cS=TRUE; 00154 00155 ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF")); 00156 ConOutPuts(GetTimeString()); 00157 freep(p); 00158 return 0; 00159 } 00160 00161 if(bS) 00162 { 00163 if(cS) 00164 { 00165 ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF")); 00166 ConOutPuts(GetTimeString()); 00167 PrintElapsedTime(GetTickCount()-cT, iFormat); 00168 freep(p); 00169 return 0; 00170 } 00171 00172 cT=GetTickCount(); 00173 cS=TRUE; 00174 ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF")); 00175 ConOutPuts(GetTimeString()); 00176 freep(p); 00177 return 0; 00178 } 00179 00180 if (NewClkStatus == NCS_NOT_SPECIFIED) 00181 { 00182 if (cS) 00183 { 00184 cS=FALSE; 00185 ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF")); 00186 ConOutPuts(GetTimeString()); 00187 PrintElapsedTime(GetTickCount()-cT, iFormat); 00188 freep(p); 00189 return 0; 00190 } 00191 00192 cT=GetTickCount(); 00193 cS=TRUE; 00194 ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF")); 00195 ConOutPuts(GetTimeString()); 00196 freep(p); 00197 return 0; 00198 } 00199 00200 00201 if (NewClkStatus == NCS_OFF) 00202 { 00203 if (cS) 00204 { 00205 cS=FALSE; 00206 ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF")); 00207 ConOutPuts(GetTimeString()); 00208 PrintElapsedTime(GetTickCount()-cT, iFormat); 00209 freep(p); 00210 return 0; 00211 } 00212 ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF")); 00213 ConOutPuts(GetTimeString()); 00214 freep(p); 00215 return 0; 00216 } 00217 00218 freep(p); 00219 return 0; 00220 } 00221 00222 #endif /* INCLUDE_CMD_TIMER */ Generated on Sun May 27 2012 04:18:16 for ReactOS by
1.7.6.1
|