Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

618 lines
15 KiB

  1. #include "brian.h"
  2. VOID
  3. FullEnterTime(
  4. PUSHORT BufferPointer,
  5. CSHORT Year,
  6. CSHORT Month,
  7. CSHORT Day,
  8. CSHORT Hour,
  9. CSHORT Minute,
  10. CSHORT Second,
  11. CSHORT MSecond
  12. );
  13. VOID
  14. FullDisplayTime (
  15. USHORT BufferIndex
  16. );
  17. VOID
  18. PrintTime (
  19. IN PTIME Time
  20. )
  21. {
  22. TIME_FIELDS TimeFields;
  23. RtlTimeToTimeFields( Time, &TimeFields );
  24. printf( "%02u-%02u-%02u %02u:%02u:%02u",
  25. TimeFields.Month,
  26. TimeFields.Day,
  27. TimeFields.Year % 100,
  28. TimeFields.Hour,
  29. TimeFields.Minute,
  30. TimeFields.Second );
  31. return;
  32. }
  33. VOID
  34. BPrintTime (
  35. IN PTIME Time
  36. )
  37. {
  38. TIME_FIELDS TimeFields;
  39. RtlTimeToTimeFields( Time, &TimeFields );
  40. bprint "%02u-%02u-%02u %02u:%02u:%02u",
  41. TimeFields.Month,
  42. TimeFields.Day,
  43. ((USHORT) (TimeFields.Year - 1900)) > 100
  44. ? 0
  45. : TimeFields.Year - 1900,
  46. TimeFields.Hour,
  47. TimeFields.Minute,
  48. TimeFields.Second );
  49. return;
  50. }
  51. VOID
  52. InputEnterTime (
  53. IN PCHAR ParamBuffer
  54. )
  55. {
  56. USHORT ActualIndex;
  57. PUSHORT BufferPointer;
  58. CSHORT Year;
  59. CSHORT Month;
  60. CSHORT Day;
  61. CSHORT Hour;
  62. CSHORT Minute;
  63. CSHORT Second;
  64. CSHORT MSecond;
  65. BOOLEAN LastInput;
  66. BOOLEAN ParmSpecified;
  67. ActualIndex = 0;
  68. BufferPointer = NULL;
  69. Year = 1601;
  70. Month = 1;
  71. Day = 1;
  72. Hour = 0;
  73. Minute = 0;
  74. Second = 0;
  75. MSecond = 0;
  76. ParmSpecified = FALSE;
  77. LastInput = TRUE;
  78. //
  79. // While there is more input, analyze the parameter and update the
  80. // query flags.
  81. //
  82. while (TRUE) {
  83. ULONG DummyCount;
  84. //
  85. // Swallow leading white spaces.
  86. //
  87. ParamBuffer = SwallowWhite( ParamBuffer, &DummyCount );
  88. if (*ParamBuffer) {
  89. //
  90. // If the next parameter is legal then check the paramter value.
  91. // Update the parameter value.
  92. //
  93. if ((*ParamBuffer == '-'
  94. || *ParamBuffer == '/')
  95. && (ParamBuffer++, *ParamBuffer != '\0')) {
  96. //
  97. // Switch on the next character.
  98. //
  99. switch( *ParamBuffer ) {
  100. //
  101. // Check buffer index.
  102. //
  103. case 'b' :
  104. case 'B' :
  105. //
  106. // Move to the next character, as long as there
  107. // are no white spaces continue analyzing letters.
  108. // On the first bad letter, skip to the next
  109. // parameter.
  110. //
  111. ParamBuffer++;
  112. ActualIndex = (USHORT) AsciiToInteger( ParamBuffer );
  113. BufferPointer = &ActualIndex;
  114. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  115. ParmSpecified = TRUE;
  116. break;
  117. //
  118. // Enter the year value.
  119. //
  120. case 'y' :
  121. case 'Y' :
  122. //
  123. // Move to the next character, as long as there
  124. // are no white spaces continue analyzing letters.
  125. // On the first bad letter, skip to the next
  126. // parameter.
  127. //
  128. ParamBuffer++;
  129. Year = (CSHORT) AsciiToInteger( ParamBuffer );
  130. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  131. ParmSpecified = TRUE;
  132. break;
  133. //
  134. // Check the month value.
  135. //
  136. case 'm' :
  137. case 'M' :
  138. //
  139. // Move to the next character, as long as there
  140. // are no white spaces continue analyzing letters.
  141. // On the first bad letter, skip to the next
  142. // parameter.
  143. //
  144. ParamBuffer++;
  145. Month = (CSHORT) AsciiToInteger( ParamBuffer );
  146. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  147. ParmSpecified = TRUE;
  148. break;
  149. //
  150. // Enter the day value.
  151. //
  152. case 'd' :
  153. case 'D' :
  154. //
  155. // Move to the next character, as long as there
  156. // are no white spaces continue analyzing letters.
  157. // On the first bad letter, skip to the next
  158. // parameter.
  159. //
  160. ParamBuffer++;
  161. Day = (CSHORT) AsciiToInteger( ParamBuffer );
  162. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  163. ParmSpecified = TRUE;
  164. break;
  165. //
  166. // Enter the hour value.
  167. //
  168. case 'h' :
  169. case 'H' :
  170. //
  171. // Move to the next character, as long as there
  172. // are no white spaces continue analyzing letters.
  173. // On the first bad letter, skip to the next
  174. // parameter.
  175. //
  176. ParamBuffer++;
  177. Hour = (CSHORT) AsciiToInteger( ParamBuffer );
  178. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  179. ParmSpecified = TRUE;
  180. break;
  181. //
  182. // Enter the minute value.
  183. //
  184. case 'i' :
  185. case 'I' :
  186. //
  187. // Move to the next character, as long as there
  188. // are no white spaces continue analyzing letters.
  189. // On the first bad letter, skip to the next
  190. // parameter.
  191. //
  192. ParamBuffer++;
  193. Minute = (CSHORT) AsciiToInteger( ParamBuffer );
  194. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  195. ParmSpecified = TRUE;
  196. break;
  197. //
  198. // Enter the second value.
  199. //
  200. case 's' :
  201. case 'S' :
  202. //
  203. // Move to the next character, as long as there
  204. // are no white spaces continue analyzing letters.
  205. // On the first bad letter, skip to the next
  206. // parameter.
  207. //
  208. ParamBuffer++;
  209. Second = (CSHORT) AsciiToInteger( ParamBuffer );
  210. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  211. ParmSpecified = TRUE;
  212. break;
  213. //
  214. // Check the millesecond value.
  215. //
  216. case 'c' :
  217. case 'C' :
  218. //
  219. // Move to the next character, as long as there
  220. // are no white spaces continue analyzing letters.
  221. // On the first bad letter, skip to the next
  222. // parameter.
  223. //
  224. ParamBuffer++;
  225. MSecond = (CSHORT) AsciiToInteger( ParamBuffer );
  226. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  227. ParmSpecified = TRUE;
  228. break;
  229. default :
  230. //
  231. // Swallow to the next white space and continue the
  232. // loop.
  233. //
  234. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  235. }
  236. }
  237. //
  238. // Else the text is invalid, skip the entire block.
  239. //
  240. //
  241. //
  242. // Else if there is no input then exit.
  243. //
  244. } else if ( LastInput ) {
  245. break;
  246. //
  247. // Else try to read another line for open parameters.
  248. //
  249. } else {
  250. }
  251. }
  252. //
  253. // If no parameters were received then display the syntax message.
  254. //
  255. if (!ParmSpecified) {
  256. printf( "\n Usage: et [options]*\n" );
  257. printf( "\n Options:" );
  258. printf( "\n -b<digits> Buffer index" );
  259. printf( "\n -y<digits> Year (1601...)" );
  260. printf( "\n -m<digits> Month (1..12)" );
  261. printf( "\n -d<digits> Day (1..31)" );
  262. printf( "\n -h<digits> Hour (0..23)" );
  263. printf( "\n -i<digits> Minute (0..59)" );
  264. printf( "\n -s<digits> Second (0..59)" );
  265. printf( "\n -c<digits> Milleseconds (0..999)" );
  266. printf( "\n\n" );
  267. //
  268. // Else call the routine to enter the time.
  269. //
  270. } else {
  271. FullEnterTime( BufferPointer,
  272. Year,
  273. Month,
  274. Day,
  275. Hour,
  276. Minute,
  277. Second,
  278. MSecond );
  279. }
  280. return;
  281. }
  282. VOID
  283. FullEnterTime(
  284. IN PUSHORT BufferPointer,
  285. IN CSHORT Year,
  286. IN CSHORT Month,
  287. IN CSHORT Day,
  288. IN CSHORT Hour,
  289. IN CSHORT Minute,
  290. IN CSHORT Second,
  291. IN CSHORT MSecond
  292. )
  293. {
  294. NTSTATUS Status;
  295. TIME_FIELDS TimeFields;
  296. USHORT BufferIndex;
  297. //
  298. // If we need a buffer, allocate it now.
  299. //
  300. try {
  301. if (BufferPointer == NULL) {
  302. SIZE_T ThisLength;
  303. ULONG TempIndex;
  304. ThisLength = sizeof( TIME );
  305. Status = AllocateBuffer( 0L, &ThisLength, &TempIndex );
  306. BufferIndex = (USHORT) TempIndex;
  307. BufferPointer = &BufferIndex;
  308. if (!NT_SUCCESS( Status )) {
  309. printf( "\n\tFullEnterTime: Unable to allocate a buffer -> %08lx",
  310. Status );
  311. try_return( NOTHING );
  312. }
  313. printf( "\n\tFullEnterTime: Using buffer -> %04x", *BufferPointer );
  314. printf( "\n" );
  315. }
  316. //
  317. // Check that the buffer index is valid.
  318. //
  319. if (*BufferPointer >= MAX_BUFFERS) {
  320. printf( "\n\tFullEnterTime: The buffer index is invalid" );
  321. try_return( NOTHING );
  322. }
  323. //
  324. // Enter the values in the time field structure.
  325. //
  326. TimeFields.Year = Year;
  327. TimeFields.Month = Month;
  328. TimeFields.Day = Day;
  329. TimeFields.Hour = Hour;
  330. TimeFields.Minute = Minute;
  331. TimeFields.Second = Second;
  332. TimeFields.Milliseconds = MSecond;
  333. //
  334. // Convert the time field to TIME format for our buffer.
  335. //
  336. if (!RtlTimeFieldsToTime( &TimeFields,
  337. (PTIME) Buffers[*BufferPointer].Buffer )) {
  338. printf( "\n\tFullEnterTime: Invalid time format" );
  339. try_return( NOTHING );
  340. }
  341. try_exit: NOTHING;
  342. } finally {
  343. }
  344. return;
  345. }
  346. VOID
  347. InputDisplayTime (
  348. IN PCHAR ParamBuffer
  349. )
  350. {
  351. USHORT BufferIndex;
  352. BOOLEAN ParamReceived;
  353. BOOLEAN LastInput;
  354. //
  355. // Set the defaults.
  356. //
  357. BufferIndex = 0;
  358. ParamReceived = FALSE;
  359. LastInput = TRUE;
  360. //
  361. // While there is more input, analyze the parameter and update the
  362. // query flags.
  363. //
  364. while (TRUE) {
  365. ULONG DummyCount;
  366. //
  367. // Swallow leading white spaces.
  368. //
  369. ParamBuffer = SwallowWhite( ParamBuffer, &DummyCount );
  370. if (*ParamBuffer) {
  371. //
  372. // If the next parameter is legal then check the paramter value.
  373. // Update the parameter value.
  374. //
  375. if ((*ParamBuffer == '-'
  376. || *ParamBuffer == '/')
  377. && (ParamBuffer++, *ParamBuffer != '\0')) {
  378. //
  379. // Switch on the next character.
  380. //
  381. switch( *ParamBuffer ) {
  382. //
  383. // Check the buffer index.
  384. //
  385. case 'b' :
  386. case 'B' :
  387. //
  388. // Move to the next character, as long as there
  389. // are no white spaces continue analyzing letters.
  390. // On the first bad letter, skip to the next
  391. // parameter.
  392. //
  393. ParamBuffer++;
  394. BufferIndex = (USHORT) AsciiToInteger( ParamBuffer );
  395. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  396. ParamReceived = TRUE;
  397. break;
  398. default :
  399. //
  400. // Swallow to the next white space and continue the
  401. // loop.
  402. //
  403. ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
  404. }
  405. }
  406. //
  407. // Else the text is invalid, skip the entire block.
  408. //
  409. //
  410. //
  411. // Else if there is no input then exit.
  412. //
  413. } else if ( LastInput ) {
  414. break;
  415. //
  416. // Else try to read another line for open parameters.
  417. //
  418. } else {
  419. }
  420. }
  421. //
  422. // If no parameters were received then display the syntax message.
  423. //
  424. if (!ParamReceived) {
  425. printf( "\n Usage: dqf [options]* -b<digits> [options]*\n" );
  426. printf( "\n Options:" );
  427. printf( "\n -b<digits> Buffer index" );
  428. printf( "\n -c<char> Key to buffer format" );
  429. printf( "\n\n" );
  430. //
  431. // Else call our display buffer routine.
  432. //
  433. } else {
  434. FullDisplayTime( BufferIndex );
  435. }
  436. return;
  437. }
  438. VOID
  439. FullDisplayTime (
  440. USHORT BufferIndex
  441. )
  442. {
  443. //
  444. // Check that the buffer index is valid and the buffer is used.
  445. //
  446. if (BufferIndex >= MAX_BUFFERS
  447. || Buffers[BufferIndex].Used == FALSE) {
  448. bprint "\n\tFullDisplayTime: Invalid buffer index" );
  449. } else {
  450. printf( "\n\tFullDisplayTime: Index %d ", BufferIndex );
  451. PrintTime( (PTIME) Buffers[BufferIndex].Buffer );
  452. }
  453. printf( "\n" );
  454. return;
  455. }