ReactOS  0.4.14-dev-49-gfb4591c
cmdcons.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS text-mode setup
4  * FILE: base/setup/usetup/cmdcons.c
5  * PURPOSE: Recovery console
6  * PROGRAMMER:
7  */
8 
9 #include "usetup.h"
10 
11 #define NDEBUG
12 #include <debug.h>
13 
14 
15 //#define FEATURE_HISTORY
16 
17 typedef struct _CONSOLE_STATE
18 {
24 
25 typedef struct tagCOMMAND
26 {
30  VOID (*help)(VOID);
31 } COMMAND, *LPCOMMAND;
32 
33 
34 static
35 VOID
36 HelpCls(VOID);
37 
38 static
39 INT
42  LPSTR param);
43 
44 static
45 VOID
47 
48 static
49 INT
52  LPSTR param);
53 
54 static
55 VOID
56 HelpExit(VOID);
57 
58 static
59 INT
62  LPSTR param);
63 
64 static
65 VOID
66 HelpHelp(VOID);
67 
68 static
69 INT
72  LPSTR param);
73 
74 static
75 VOID
77 
78 static
79 INT
82  LPSTR param);
83 
84 COMMAND
86 {
87  {"cls", 0, CommandCls, HelpCls},
88  {"dumpsector", 0, CommandDumpSector, HelpDumpSector},
89  {"exit", 0, CommandExit, HelpExit},
90  {"help", 0, CommandHelp, HelpHelp},
91  {"partinfo", 0, CommandPartInfo, HelpPartInfo},
92  {NULL, 0, NULL}
93 };
94 
95 
96 static
97 VOID
99  LPSTR *p)
100 {
101  LPSTR *q;
102 
103  if (!p)
104  return;
105 
106  q = p;
107  while (*q)
108  RtlFreeHeap(ProcessHeap, 0, *q++);
109 
111 }
112 
113 
114 static
115 VOID
117  LPSTR in)
118 {
119  LPSTR out = in;
120 
121  for (; *in; in++)
122  {
123  if (*in != '"')
124  *out++ = *in;
125  }
126 
127  *out = '\0';
128 }
129 
130 
131 BOOL
133  LPINT ac,
134  LPSTR **arg,
135  LPCSTR entry)
136 {
137  LPSTR q;
138  LPSTR *oldarg;
139 
141  if (q == NULL)
142  return FALSE;
143 
144  strcpy(q, entry);
145  oldarg = *arg;
146  *arg = RtlReAllocateHeap(ProcessHeap, 0, oldarg, (*ac + 2) * sizeof(LPSTR));
147  if (*arg == NULL)
148  {
150  *arg = oldarg;
151  return FALSE;
152  }
153 
154  /* save new entry */
155  (*arg)[*ac] = q;
156  (*arg)[++(*ac)] = NULL;
157 
158  return TRUE;
159 }
160 
161 static
162 LPSTR *
164  LPSTR s,
165  LPINT args)
166 {
167  LPSTR *arg;
168  LPSTR start;
169  LPSTR q;
170  INT ac;
171  INT_PTR len;
172  BOOL bQuoted;
173 
174  arg = RtlAllocateHeap(ProcessHeap, 0 , sizeof(LPTSTR));
175  if (arg == NULL)
176  return NULL;
177 
178  *arg = NULL;
179 
180  ac = 0;
181  while (*s)
182  {
183  bQuoted = FALSE;
184 
185  /* skip leading spaces */
186  while (*s && (isspace(*s) || iscntrl(*s)))
187  ++s;
188 
189  start = s;
190 
191  /* the first character can be '/' */
192  if (*s == '/')
193  s++;
194 
195  /* skip to next word delimiter or start of next option */
196  while (isprint(*s))
197  {
198  /* if quote (") then set bQuoted */
199  bQuoted ^= (*s == '\"');
200 
201  /* Check if we have unquoted text */
202  if (!bQuoted)
203  {
204  /* check for separators */
205  if (isspace(*s) || (*s == '/'))
206  {
207  /* Make length at least one character */
208  if (s == start)
209  s++;
210  break;
211  }
212  }
213 
214  s++;
215  }
216 
217  /* a word was found */
218  if (s != start)
219  {
220  len = s - start;
221  q = RtlAllocateHeap(ProcessHeap, 0, len + 1);
222  if (q == NULL)
223  {
224  freep(arg);
225  return NULL;
226  }
227 
228  memcpy(q, start, len);
229  q[len] = '\0';
230 
231  StripQuotes(q);
232 
233  if (!add_entry(&ac, &arg, q))
234  {
236  freep(arg);
237  return NULL;
238  }
239 
241  }
242  }
243 
244  *args = ac;
245 
246  return arg;
247 }
248 
249 
250 static
251 VOID
253 {
254  CONSOLE_ConOutPrintf("CLS\n\nClears the screen.\n\n");
255 }
256 
257 
258 static
259 INT
262  LPSTR param)
263 {
264  if (!strcmp(param, "/?"))
265  {
266  HelpCls();
267  return 0;
268  }
269 
271  CONSOLE_SetCursorXY(0, 0);
272 
273  return 0;
274 }
275 
276 
278 {
279  ULONG offset = 0;
280  PUCHAR ptr;
281 
282  while (offset < (size & ~15))
283  {
284  ptr = (PUCHAR)((ULONG_PTR)buffer + offset);
285  CONSOLE_ConOutPrintf("%04lx %02hx %02hx %02hx %02hx %02hx %02hx %02hx %02hx %02hx %02hx %02hx %02hx %02hx %02hx %02hx %02hx\n",
286  offset,
287  ptr[0],
288  ptr[1],
289  ptr[2],
290  ptr[3],
291  ptr[4],
292  ptr[5],
293  ptr[6],
294  ptr[7],
295  ptr[8],
296  ptr[9],
297  ptr[10],
298  ptr[11],
299  ptr[12],
300  ptr[13],
301  ptr[14],
302  ptr[15]);
303  offset += 16;
304  }
305 
306  if (offset < size)
307  {
308  ptr = (PUCHAR)((ULONG_PTR)buffer + offset);
309  CONSOLE_ConOutPrintf("%04lx ", offset);
310  while (offset < size)
311  {
312  CONSOLE_ConOutPrintf(" %02hx", *ptr);
313  offset++;
314  ptr++;
315  }
316 
317  CONSOLE_ConOutPrintf("\n");
318  }
319 
320  CONSOLE_ConOutPrintf("\n");
321 }
322 
323 
324 static
325 VOID
327 {
328  CONSOLE_ConOutPrintf("DUMPSECT DiskNumber Sector\n\nDumps a disk sector to the screen.\n\n");
329 }
330 
331 
332 static
333 INT
336  LPSTR param)
337 {
340  UNICODE_STRING PathName;
341  HANDLE hDisk = NULL;
342  DISK_GEOMETRY DiskGeometry;
344 
345  LPTSTR *argv = NULL;
346  INT argc = 0;
347  WCHAR DriveName[40];
348  ULONG ulDrive;
349 // ULONG ulSector;
351  PUCHAR Buffer = NULL;
352 
353  DPRINT1("param: %s\n", param);
354 
355  if (!strcmp(param, "/?"))
356  {
357  HelpDumpSector();
358  return 0;
359  }
360 
361  argv = split(param, &argc);
362 
363  DPRINT1("argc: %d\n", argc);
364  DPRINT1("argv: %p\n", argv);
365 
366  if (argc != 2)
367  {
368  goto done;
369  }
370 
371  DPRINT1("Device: %s\n", argv[0]);
372  DPRINT1("Sector: %s\n", argv[1]);
373 
374  ulDrive = strtoul(argv[0], NULL, 0);
375 // ulSector = strtoul(argv[1], NULL, 0);
376  Sector.QuadPart = _atoi64(argv[1]);
377 
378  /* Build full drive name */
379 // swprintf(DriveName, L"\\\\.\\PHYSICALDRIVE%lu", ulDrive);
380  swprintf(DriveName, L"\\Device\\Harddisk%lu\\Partition0", ulDrive);
381 
382  RtlInitUnicodeString(&PathName,
383  DriveName);
384 
386  &PathName,
388  NULL,
389  NULL);
390 
391  Status = NtOpenFile(&hDisk,
394  &IoStatusBlock,
397  if (!NT_SUCCESS(Status))
398  {
399  DPRINT1("NtCreateFile failed (Status 0x%08lx)\n", Status);
400  goto done;
401  }
402 
404  NULL,
405  NULL,
406  NULL,
407  &IoStatusBlock,
409  NULL,
410  0,
411  &DiskGeometry,
412  sizeof(DISK_GEOMETRY));
413  if (!NT_SUCCESS(Status))
414  {
415  DPRINT1("NtDeviceIoControlFile failed (Status 0x%08lx)\n", Status);
416  goto done;
417  }
418 
419  DPRINT1("Drive number: %lu\n", ulDrive);
420  DPRINT1("Cylinders: %I64u\nMediaType: %x\nTracksPerCylinder: %lu\n"
421  "SectorsPerTrack: %lu\nBytesPerSector: %lu\n\n",
422  DiskGeometry.Cylinders.QuadPart,
423  DiskGeometry.MediaType,
424  DiskGeometry.TracksPerCylinder,
425  DiskGeometry.SectorsPerTrack,
426  DiskGeometry.BytesPerSector);
427 
428  DPRINT1("Sector: %I64u\n", Sector.QuadPart);
429 
430  SectorCount.QuadPart = DiskGeometry.Cylinders.QuadPart *
431  (ULONGLONG)DiskGeometry.TracksPerCylinder *
432  (ULONGLONG)DiskGeometry.SectorsPerTrack;
433  if (Sector.QuadPart >= SectorCount.QuadPart)
434  {
435  CONSOLE_ConOutPrintf("Invalid sector number! Valid range: [0 - %I64u]\n", SectorCount.QuadPart - 1);
436  goto done;
437  }
438 
439  Buffer = RtlAllocateHeap(ProcessHeap, 0, DiskGeometry.BytesPerSector);
440  if (Buffer == NULL)
441  {
442  DPRINT1("Buffer allocation failed\n");
443  goto done;
444  }
445 
446 
447  Offset.QuadPart = Sector.QuadPart * DiskGeometry.BytesPerSector;
448  DPRINT1("Offset: %I64u\n", Offset.QuadPart);
449 
450  Status = NtReadFile(hDisk,
451  NULL,
452  NULL,
453  NULL,
454  &IoStatusBlock,
455  Buffer,
456  DiskGeometry.BytesPerSector,
457  &Offset,
458  NULL);
459  if (!NT_SUCCESS(Status))
460  {
461  DPRINT1("NtReadFile failed (Status 0x%08lx)\n", Status);
462  goto done;
463  }
464 
465  HexDump(Buffer, DiskGeometry.BytesPerSector);
466 
467 done:
468  if (Buffer != NULL)
470 
471  if (hDisk != NULL)
472  NtClose(hDisk);
473 
474  freep(argv);
475 
476  return 0;
477 }
478 
479 
480 static
481 VOID
483 {
484  CONSOLE_ConOutPrintf("EXIT\n\nExits the repair console.\n\n");
485 }
486 
487 
488 static
489 INT
492  LPSTR param)
493 {
494  if (!strcmp(param, "/?"))
495  {
496  HelpExit();
497  return 0;
498  }
499 
500  State->bExit = TRUE;
501 
502  return 0;
503 }
504 
505 
506 static
507 VOID
509 {
510  CONSOLE_ConOutPrintf("HELP [Command]\n\nShows help on repair console commands.\n\n");
511 }
512 
513 
514 static
515 INT
518  LPSTR param)
519 {
520  LPCOMMAND cmdptr;
521 
522  DPRINT1("param: %p %u '%s'\n", param, strlen(param), param);
523 
524  if (!strcmp(param, "/?"))
525  {
526  HelpHelp();
527  return 0;
528  }
529 
530  if (param != NULL && strlen(param) > 0)
531  {
532  for (cmdptr = Commands; cmdptr->name != NULL; cmdptr++)
533  {
534  if (!stricmp(param, cmdptr->name))
535  {
536  if (cmdptr->help != NULL)
537  {
538  cmdptr->help();
539  return 0;
540  }
541  }
542  }
543  }
544 
545  CONSOLE_ConOutPrintf("CLS\n");
546  CONSOLE_ConOutPrintf("DUMPSECTOR\n");
547  CONSOLE_ConOutPrintf("EXIT\n");
548  CONSOLE_ConOutPrintf("HELP\n");
549  CONSOLE_ConOutPrintf("\n");
550 
551  return 0;
552 }
553 
554 
555 static
556 VOID
558 {
559  CONSOLE_ConOutPrintf("PARTINFO DiskNumber\n\nDumps a partition table to the screen.\n\n");
560 }
561 
562 
563 static
564 INT
567  LPSTR param)
568 {
571  UNICODE_STRING PathName;
572  HANDLE hDisk = NULL;
573  DISK_GEOMETRY DiskGeometry;
575 
576  LPTSTR *argv = NULL;
577  INT argc = 0;
578  WCHAR DriveName[40];
579  ULONG ulDrive, i;
580  PDRIVE_LAYOUT_INFORMATION LayoutBuffer = NULL;
582 
583  DPRINT1("param: %s\n", param);
584 
585  if (!strcmp(param, "/?"))
586  {
587  HelpPartInfo();
588  return 0;
589  }
590 
591  argv = split(param, &argc);
592 
593  DPRINT1("argc: %d\n", argc);
594  DPRINT1("argv: %p\n", argv);
595 
596  if (argc != 1)
597  {
598  goto done;
599  }
600 
601  DPRINT1("Device: %s\n", argv[0]);
602 
603  ulDrive = strtoul(argv[0], NULL, 0);
604 
605  /* Build full drive name */
606  swprintf(DriveName, L"\\Device\\Harddisk%lu\\Partition0", ulDrive);
607 
608  RtlInitUnicodeString(&PathName,
609  DriveName);
610 
612  &PathName,
614  NULL,
615  NULL);
616 
617  Status = NtOpenFile(&hDisk,
620  &IoStatusBlock,
623  if (!NT_SUCCESS(Status))
624  {
625  DPRINT1("NtCreateFile failed (Status 0x%08lx)\n", Status);
626  goto done;
627  }
628 
630  NULL,
631  NULL,
632  NULL,
633  &IoStatusBlock,
635  NULL,
636  0,
637  &DiskGeometry,
638  sizeof(DISK_GEOMETRY));
639  if (!NT_SUCCESS(Status))
640  {
641  DPRINT1("NtDeviceIoControlFile failed (Status 0x%08lx)\n", Status);
642  goto done;
643  }
644 
645  CONSOLE_ConOutPrintf("Drive number: %lu\n", ulDrive);
646  CONSOLE_ConOutPrintf("Cylinders: %I64u\nMediaType: %x\nTracksPerCylinder: %lu\n"
647  "SectorsPerTrack: %lu\nBytesPerSector: %lu\n\n",
648  DiskGeometry.Cylinders.QuadPart,
649  DiskGeometry.MediaType,
650  DiskGeometry.TracksPerCylinder,
651  DiskGeometry.SectorsPerTrack,
652  DiskGeometry.BytesPerSector);
653 
654  LayoutBuffer = RtlAllocateHeap(ProcessHeap,
656  8192);
657  if (LayoutBuffer == NULL)
658  {
659  DPRINT1("LayoutBuffer allocation failed\n");
660  goto done;
661  }
662 
664  NULL,
665  NULL,
666  NULL,
667  &IoStatusBlock,
669  NULL,
670  0,
671  LayoutBuffer,
672  8192);
673  if (!NT_SUCCESS(Status))
674  {
675  DPRINT1("NtDeviceIoControlFile(IOCTL_DISK_GET_DRIVE_LAYOUT) failed (Status 0x%08lx)\n", Status);
676  goto done;
677  }
678 
679  CONSOLE_ConOutPrintf("Partitions: %lu Signature: %lx\n\n",
680  LayoutBuffer->PartitionCount,
681  LayoutBuffer->Signature);
682 
683  CONSOLE_ConOutPrintf(" # Start Size Hidden Nr Type Boot\n");
684  CONSOLE_ConOutPrintf("-- --------------- --------------- ------------ -- ---- ----\n");
685 
686  for (i = 0; i < LayoutBuffer->PartitionCount; i++)
687  {
688  PartitionInfo = &LayoutBuffer->PartitionEntry[i];
689 
690  CONSOLE_ConOutPrintf("%2lu %15I64u %15I64u %12lu %2lu %2x %c\n",
691  i,
692  PartitionInfo->StartingOffset.QuadPart / DiskGeometry.BytesPerSector,
693  PartitionInfo->PartitionLength.QuadPart / DiskGeometry.BytesPerSector,
694  PartitionInfo->HiddenSectors,
695  PartitionInfo->PartitionNumber,
696  PartitionInfo->PartitionType,
697  PartitionInfo->BootIndicator ? '*': ' ');
698  }
699 
700  CONSOLE_ConOutPrintf("\n");
701 
702 done:
703  if (LayoutBuffer != NULL)
704  RtlFreeHeap(ProcessHeap, 0, LayoutBuffer);
705 
706  if (hDisk != NULL)
707  NtClose(hDisk);
708 
709  freep(argv);
710 
711  return 0;
712 }
713 
714 
715 static
716 VOID
718  LPSTR str,
719  INT maxlen,
720  SHORT orgx,
721  SHORT orgy)
722 {
723  INT count;
724 
725  CONSOLE_SetCursorXY(orgx, orgy);
726  for (count = 0; count < (INT)strlen(str); count++)
727  CONSOLE_ConOutChar(' ');
728  memset(str, 0, maxlen);
729  CONSOLE_SetCursorXY(orgx, orgy);
730 }
731 
732 
733 static
734 BOOL
737  LPSTR str,
738  INT maxlen)
739 {
740  SHORT orgx; /* origin x/y */
741  SHORT orgy;
742  SHORT curx; /*current x/y cursor position*/
743  SHORT cury;
744  SHORT tempscreen;
745  INT count; /*used in some for loops*/
746  INT current = 0; /*the position of the cursor in the string (str)*/
747  INT charcount = 0;/*chars in the string (str)*/
748  INPUT_RECORD ir;
749  CHAR ch;
750  BOOL bReturn = FALSE;
751  BOOL bCharInput;
752 #ifdef FEATURE_HISTORY
753  //BOOL bContinue=FALSE;/*is TRUE the second case will not be executed*/
754  CHAR PreviousChar;
755 #endif
756 
757 
758  CONSOLE_GetCursorXY(&orgx, &orgy);
759  curx = orgx;
760  cury = orgy;
761 
762  memset(str, 0, maxlen * sizeof(CHAR));
763 
764  CONSOLE_SetCursorType(State->bInsert, TRUE);
765 
766  do
767  {
768  bReturn = FALSE;
769  CONSOLE_ConInKey(&ir);
770 
774  {
775  switch (ir.Event.KeyEvent.wVirtualKeyCode)
776  {
777 #ifdef FEATURE_HISTORY
778  case 'K':
779  /*add the current command line to the history*/
782  {
783  if (str[0])
784  History(0,str);
785 
786  ClearCommandLine (str, maxlen, orgx, orgy);
787  current = charcount = 0;
788  curx = orgx;
789  cury = orgy;
790  //bContinue=TRUE;
791  break;
792  }
793 
794  case 'D':
795  /*delete current history entry*/
798  {
799  ClearCommandLine (str, maxlen, orgx, orgy);
801  current = charcount = strlen (str);
802  ConOutPrintf("%s", str);
803  GetCursorXY(&curx, &cury);
804  //bContinue=TRUE;
805  break;
806  }
807 
808 #endif /*FEATURE_HISTORY*/
809  }
810  }
811 
812  bCharInput = FALSE;
813 
814  switch (ir.Event.KeyEvent.wVirtualKeyCode)
815  {
816  case VK_BACK:
817  /* <BACKSPACE> - delete character to left of cursor */
818  if (current > 0 && charcount > 0)
819  {
820  if (current == charcount)
821  {
822  /* if at end of line */
823  str[current - 1] = L'\0';
824  if (CONSOLE_GetCursorX () != 0)
825  {
826  CONSOLE_ConOutPrintf("\b \b");
827  curx--;
828  }
829  else
830  {
831  CONSOLE_SetCursorXY((SHORT)(State->maxx - 1), (SHORT)(CONSOLE_GetCursorY () - 1));
832  CONSOLE_ConOutChar(' ');
833  CONSOLE_SetCursorXY((SHORT)(State->maxx - 1), (SHORT)(CONSOLE_GetCursorY () - 1));
834  cury--;
835  curx = State->maxx - 1;
836  }
837  }
838  else
839  {
840  for (count = current - 1; count < charcount; count++)
841  str[count] = str[count + 1];
842  if (CONSOLE_GetCursorX () != 0)
843  {
845  curx--;
846  }
847  else
848  {
849  CONSOLE_SetCursorXY ((SHORT)(State->maxx - 1), (SHORT)(CONSOLE_GetCursorY () - 1));
850  cury--;
851  curx = State->maxx - 1;
852  }
853  CONSOLE_GetCursorXY(&curx, &cury);
854  CONSOLE_ConOutPrintf("%s ", &str[current - 1]);
855  CONSOLE_SetCursorXY(curx, cury);
856  }
857  charcount--;
858  current--;
859  }
860  break;
861 
862  case VK_INSERT:
863  /* toggle insert/overstrike mode */
864  State->bInsert ^= TRUE;
865  CONSOLE_SetCursorType(State->bInsert, TRUE);
866  break;
867 
868  case VK_DELETE:
869  /* delete character under cursor */
870  if (current != charcount && charcount > 0)
871  {
872  for (count = current; count < charcount; count++)
873  str[count] = str[count + 1];
874  charcount--;
875  CONSOLE_GetCursorXY(&curx, &cury);
876  CONSOLE_ConOutPrintf("%s ", &str[current]);
877  CONSOLE_SetCursorXY(curx, cury);
878  }
879  break;
880 
881  case VK_HOME:
882  /* goto beginning of string */
883  if (current != 0)
884  {
885  CONSOLE_SetCursorXY(orgx, orgy);
886  curx = orgx;
887  cury = orgy;
888  current = 0;
889  }
890  break;
891 
892  case VK_END:
893  /* goto end of string */
894  if (current != charcount)
895  {
896  CONSOLE_SetCursorXY(orgx, orgy);
897  CONSOLE_ConOutPrintf("%s", str);
898  CONSOLE_GetCursorXY(&curx, &cury);
899  current = charcount;
900  }
901  break;
902 
903  case 'M':
904  case 'C':
905  /* ^M does the same as return */
906  bCharInput = TRUE;
907  if (!(ir.Event.KeyEvent.dwControlKeyState &
909  {
910  break;
911  }
912 
913  case VK_RETURN:
914  /* end input, return to main */
915 #ifdef FEATURE_HISTORY
916  /* add to the history */
917  if (str[0])
918  History (0, str);
919 #endif
920  str[charcount] = '\0';
921  CONSOLE_ConOutChar('\n');
922  bReturn = TRUE;
923  break;
924 
925  case VK_ESCAPE:
926  /* clear str Make this callable! */
927  ClearCommandLine (str, maxlen, orgx, orgy);
928  curx = orgx;
929  cury = orgy;
930  current = charcount = 0;
931  break;
932 
933 #ifdef FEATURE_HISTORY
934  case VK_F3:
936 #endif
937  case VK_UP:
938 #ifdef FEATURE_HISTORY
939  /* get previous command from buffer */
940  ClearCommandLine (str, maxlen, orgx, orgy);
941  History (-1, str);
942  current = charcount = strlen (str);
943  if (((charcount + orgx) / maxx) + orgy > maxy - 1)
944  orgy += maxy - ((charcount + orgx) / maxx + orgy + 1);
945  CONSOLE_ConOutPrintf("%s", str);
946  CONSOLE_GetCursorXY(&curx, &cury);
947 #endif
948  break;
949 
950  case VK_DOWN:
951 #ifdef FEATURE_HISTORY
952  /* get next command from buffer */
953  ClearCommandLine (str, maxlen, orgx, orgy);
954  History (1, str);
955  current = charcount = strlen (str);
956  if (((charcount + orgx) / maxx) + orgy > maxy - 1)
957  orgy += maxy - ((charcount + orgx) / maxx + orgy + 1);
958  CONSOLE_ConOutPrintf("%s", str);
959  CONSOLE_GetCursorXY(&curx, &cury);
960 #endif
961  break;
962 
963  case VK_LEFT:
964  /* move cursor left */
965  if (current > 0)
966  {
967  current--;
968  if (CONSOLE_GetCursorX() == 0)
969  {
970  CONSOLE_SetCursorXY((SHORT)(State->maxx - 1), (SHORT)(CONSOLE_GetCursorY () - 1));
971  curx = State->maxx - 1;
972  cury--;
973  }
974  else
975  {
977  curx--;
978  }
979  }
980  break;
981 
982  case VK_RIGHT:
983  /* move cursor right */
984  if (current != charcount)
985  {
986  current++;
987  if (CONSOLE_GetCursorX() == State->maxx - 1)
988  {
990  curx = 0;
991  cury++;
992  }
993  else
994  {
996  curx++;
997  }
998  }
999 #ifdef FEATURE_HISTORY
1000  else
1001  {
1002  LPCSTR last = PeekHistory(-1);
1003  if (last && charcount < (INT)strlen (last))
1004  {
1005  PreviousChar = last[current];
1006  CONSOLE_ConOutChar(PreviousChar);
1007  CONSOLE_GetCursorXY(&curx, &cury);
1008  str[current++] = PreviousChar;
1009  charcount++;
1010  }
1011  }
1012 #endif
1013  break;
1014 
1015  default:
1016  /* This input is just a normal char */
1017  bCharInput = TRUE;
1018 
1019  }
1020 
1021  ch = ir.Event.KeyEvent.uChar.UnicodeChar;
1022  if (ch >= 32 && (charcount != (maxlen - 2)) && bCharInput)
1023  {
1024  /* insert character into string... */
1025  if (State->bInsert && current != charcount)
1026  {
1027  /* If this character insertion will cause screen scrolling,
1028  * adjust the saved origin of the command prompt. */
1029  tempscreen = strlen(str + current) + curx;
1030  if ((tempscreen % State->maxx) == (State->maxx - 1) &&
1031  (tempscreen / State->maxx) + cury == (State->maxy - 1))
1032  {
1033  orgy--;
1034  cury--;
1035  }
1036 
1037  for (count = charcount; count > current; count--)
1038  str[count] = str[count - 1];
1039  str[current++] = ch;
1040  if (curx == State->maxx - 1)
1041  curx = 0, cury++;
1042  else
1043  curx++;
1044  CONSOLE_ConOutPrintf("%s", &str[current - 1]);
1045  CONSOLE_SetCursorXY(curx, cury);
1046  charcount++;
1047  }
1048  else
1049  {
1050  if (current == charcount)
1051  charcount++;
1052  str[current++] = ch;
1053  if (CONSOLE_GetCursorX () == State->maxx - 1 && CONSOLE_GetCursorY () == State->maxy - 1)
1054  orgy--, cury--;
1055  if (CONSOLE_GetCursorX () == State->maxx - 1)
1056  curx = 0, cury++;
1057  else
1058  curx++;
1059  CONSOLE_ConOutChar(ch);
1060  }
1061  }
1062  }
1063  while (!bReturn);
1064 
1065  CONSOLE_SetCursorType(State->bInsert, TRUE);
1066 
1067  return TRUE;
1068 }
1069 
1070 
1071 static
1072 BOOL
1074  CHAR c)
1075 {
1076  return (c == '/' || c == '=' || c == '\0' || isspace(c));
1077 }
1078 
1079 
1080 static
1081 VOID
1084  LPSTR line)
1085 {
1086  CHAR com[MAX_PATH]; /* the first word in the command */
1087  LPSTR cp = com;
1088 // LPSTR cstart;
1089  LPSTR rest = line; /* pointer to the rest of the command line */
1090 // INT cl;
1091  LPCOMMAND cmdptr;
1092 
1093  DPRINT1("DoCommand: (\'%s\')\n", line);
1094 
1095  /* Skip over initial white space */
1096  while (isspace(*rest))
1097  rest++;
1098 
1099 // cstart = rest;
1100 
1101  /* Anything to do ? */
1102  if (*rest)
1103  {
1104  /* Copy over 1st word as lower case */
1105  while (!IsDelimiter(*rest))
1106  *cp++ = tolower(*rest++);
1107 
1108  /* Terminate first word */
1109  *cp = '\0';
1110 
1111  /* Skip over whitespace to rest of line */
1112  while (isspace (*rest))
1113  rest++;
1114 
1115  /* Scan internal command table */
1116  for (cmdptr = Commands; ; cmdptr++)
1117  {
1118  /* If end of table execute ext cmd */
1119  if (cmdptr->name == NULL)
1120  {
1121  CONSOLE_ConOutPuts("Unknown command. Enter HELP to get a list of commands.");
1122  break;
1123  }
1124 
1125  if (stricmp(com, cmdptr->name) == 0)
1126  {
1127  cmdptr->func(State, rest);
1128  break;
1129  }
1130 
1131 #if 0
1132  /* The following code handles the case of commands like CD which
1133  * are recognised even when the command name and parameter are
1134  * not space separated.
1135  *
1136  * e.g dir..
1137  * cd\freda
1138  */
1139 
1140  /* Get length of command name */
1141  cl = strlen(cmdptr->name);
1142 
1143  if ((cmdptr->flags & CMD_SPECIAL) &&
1144  (!strncmp (cmdptr->name, com, cl)) &&
1145  (strchr("\\.-", *(com + cl))))
1146  {
1147  /* OK its one of the specials...*/
1148 
1149  /* Call with new rest */
1150  cmdptr->func(State, cstart + cl);
1151  break;
1152  }
1153 #endif
1154  }
1155  }
1156 }
1157 
1158 
1159 VOID
1161 {
1162  CHAR szInputBuffer[256];
1165 
1167 
1168  /* get screen size */
1169  State.maxx = csbi.dwSize.X;
1170  State.maxy = csbi.dwSize.Y;
1171  State.bInsert = TRUE;
1172  State.bExit = FALSE;
1173 
1175  CONSOLE_SetCursorXY(0, 0);
1176 
1177  CONSOLE_ConOutPrintf("ReactOS Recovery Console\n\nEnter HELP to get a list of commands.\n\n");
1178 
1179  while (!State.bExit)
1180  {
1181  /* Prompt */
1182  CONSOLE_ConOutPrintf(">");
1183 
1184  ReadCommand(&State, szInputBuffer, 256);
1185 DPRINT1("%s\n", szInputBuffer);
1186 
1187  DoCommand(&State, szInputBuffer);
1188 
1189 // Cmd = ParseCommand(NULL);
1190 // if (!Cmd)
1191 // continue;
1192 
1193 // ExecuteCommand(Cmd);
1194 // FreeCommand(Cmd);
1195  }
1196 }
1197 
1198 /* EOF */
BOOLEAN bExit
Definition: cmdcons.c:22
GLenum func
Definition: glext.h:6028
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
VOID RecoveryConsole(VOID)
Definition: cmdcons.c:1160
struct tagCOMMAND * LPCOMMAND
static int argc
Definition: ServiceArgs.c:12
#define isspace(c)
Definition: acclib.h:69
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
#define TRUE
Definition: types.h:120
WCHAR UnicodeChar
Definition: wincon.h:230
SHORT maxy
Definition: cmdcons.c:20
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
POINT last
Definition: font.c:46
static INT CommandPartInfo(PCONSOLE_STATE State, LPSTR param)
Definition: cmdcons.c:565
VOID CONSOLE_ConOutChar(IN CHAR c)
Definition: consup.c:106
VOID GetCursorXY(PSHORT x, PSHORT y)
Definition: console.c:200
GLuint GLuint GLsizei count
Definition: gl.h:1545
unsigned char * PUCHAR
Definition: retypes.h:3
char CHAR
Definition: xmlstorage.h:175
VOID History_move_to_bottom(VOID)
Definition: history.c:280
static BOOL ReadCommand(PCONSOLE_STATE State, LPSTR str, INT maxlen)
Definition: cmdcons.c:735
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
#define INT
Definition: polytest.cpp:20
GLintptr offset
Definition: glext.h:5920
DWORD dwControlKeyState
Definition: wincon.h:233
#define VK_LEFT
Definition: winuser.h:2199
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:152
GLuint buffer
Definition: glext.h:5915
#define ConOutPrintf(szStr,...)
Definition: console.h:42
VOID __cdecl CONSOLE_ConOutPrintf(IN LPCSTR szFormat,...)
Definition: consup.c:159
SHORT CONSOLE_GetCursorY(VOID)
Definition: consup.c:200
void * arg
Definition: msvc.h:12
ULONG BytesPerSector
Definition: ntdddisk.h:376
#define VK_DOWN
Definition: winuser.h:2202
ULONG TracksPerCylinder
Definition: ntdddisk.h:374
#define VK_INSERT
Definition: winuser.h:2207
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
int32_t INT_PTR
Definition: typedefs.h:62
#define argv
Definition: mplay32.c:18
#define VK_ESCAPE
Definition: winuser.h:2189
char * LPSTR
Definition: xmlstorage.h:182
NTSYSAPI PVOID WINAPI RtlReAllocateHeap(HANDLE, ULONG, PVOID, SIZE_T)
Definition: heap.c:2561
Definition: match.c:390
static VOID StripQuotes(LPSTR in)
Definition: cmdcons.c:116
INT flags
Definition: cmdcons.c:28
int32_t INT
Definition: typedefs.h:56
#define VK_RETURN
Definition: winuser.h:2176
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define FILE_SHARE_READ
Definition: compat.h:125
VOID(* help)(VOID)
Definition: cmdcons.c:30
static VOID HelpDumpSector(VOID)
Definition: cmdcons.c:326
WORD wVirtualKeyCode
Definition: wincon.h:227
union _INPUT_RECORD::@3154 Event
uint32_t ULONG_PTR
Definition: typedefs.h:63
static INT CommandCls(PCONSOLE_STATE State, LPSTR param)
Definition: cmdcons.c:260
INT(* func)(PCONSOLE_STATE, LPSTR)
Definition: cmdcons.c:29
static VOID HelpCls(VOID)
Definition: cmdcons.c:252
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define VK_HOME
Definition: winuser.h:2198
struct _CONSOLE_STATE * PCONSOLE_STATE
SHORT maxy
Definition: cmdinput.c:116
#define VK_UP
Definition: winuser.h:2200
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
unsigned int BOOL
Definition: ntddk_ex.h:94
short SHORT
Definition: pedump.c:59
VOID CONSOLE_ClearScreen(VOID)
Definition: consup.c:235
static VOID HelpHelp(VOID)
Definition: cmdcons.c:508
static PVOID ptr
Definition: dispmode.c:27
const WCHAR * str
unsigned char BOOLEAN
VOID CONSOLE_SetCursorType(IN BOOL bInsert, IN BOOL bVisible)
Definition: consup.c:210
static VOID freep(LPSTR *p)
Definition: cmdcons.c:98
smooth NULL
Definition: ftsmooth.c:416
PARTITION_INFORMATION PartitionEntry[1]
Definition: ntdddisk.h:471
BOOLEAN bInsert
Definition: cmdcons.c:21
Definition: parser.c:48
Definition: bufpool.h:45
const char * LPCSTR
Definition: xmlstorage.h:183
#define VK_DELETE
Definition: winuser.h:2208
BOOL WINAPI GetConsoleScreenBufferInfo(IN HANDLE hConsoleOutput, OUT PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo)
Definition: console.c:544
_Check_return_ _CRTIMP int __cdecl stricmp(_In_z_ const char *_Str1, _In_z_ const char *_Str2)
#define LEFT_ALT_PRESSED
Definition: wincon.h:132
struct _CONSOLE_STATE CONSOLE_STATE
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
ULONG X
Definition: bl.h:1340
static VOID HelpPartInfo(VOID)
Definition: cmdcons.c:557
NTSYSAPI NTSTATUS NTAPI NtOpenFile(OUT PHANDLE phFile, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG ShareMode, IN ULONG OpenMode)
Definition: file.c:3951
static VOID HelpExit(VOID)
Definition: cmdcons.c:482
union _KEY_EVENT_RECORD::@3153 uChar
GLsizeiptr size
Definition: glext.h:5919
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static VOID ClearCommandLine(LPSTR str, INT maxlen, SHORT orgx, SHORT orgy)
Definition: cmdcons.c:717
uint64_t ULONGLONG
Definition: typedefs.h:65
LARGE_INTEGER Cylinders
Definition: ntdddisk.h:372
ULONG SectorsPerTrack
Definition: ntdddisk.h:375
#define OBJ_INHERIT
Definition: winternl.h:225
void HexDump(PUCHAR buffer, ULONG size)
Definition: cmdcons.c:277
GLfloat param
Definition: glext.h:5796
#define MAX_PATH
Definition: compat.h:26
SHORT CONSOLE_GetCursorX(VOID)
Definition: consup.c:190
#define swprintf(buf, format,...)
Definition: sprintf.c:56
static LPSTR * split(LPSTR s, LPINT args)
Definition: cmdcons.c:163
const GLubyte * c
Definition: glext.h:8905
static INT CommandHelp(PCONSOLE_STATE State, LPSTR param)
Definition: cmdcons.c:516
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
KEY_EVENT_RECORD KeyEvent
Definition: wincon.h:263
_In_ ULONG _In_ struct _SET_PARTITION_INFORMATION_EX * PartitionInfo
Definition: iofuncs.h:2101
static FILE * out
Definition: regtests2xml.c:44
MEDIA_TYPE MediaType
Definition: ntdddisk.h:373
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define VK_F3
Definition: winuser.h:2232
char line[200]
Definition: main.c:97
#define LEFT_CTRL_PRESSED
Definition: wincon.h:134
VOID CONSOLE_ConOutPuts(IN LPCSTR szText)
Definition: consup.c:120
static const WCHAR L[]
Definition: oid.c:1250
COMMAND Commands[]
Definition: cmdcons.c:85
#define VOID
Definition: acefi.h:82
VOID History_del_current_entry(LPTSTR str)
Definition: history.c:175
uint32_t entry
Definition: isohybrid.c:63
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
GLdouble s
Definition: gl.h:2039
#define GENERIC_READ
Definition: compat.h:124
#define STD_OUTPUT_HANDLE
Definition: winbase.h:265
#define SYNCHRONIZE
Definition: nt_native.h:61
static BOOL IsDelimiter(CHAR c)
Definition: cmdcons.c:1073
#define VK_BACK
Definition: winuser.h:2173
ULONG SectorCount
Definition: part_xbox.c:32
HANDLE ProcessHeap
Definition: servman.c:15
Status
Definition: gdiplustypes.h:24
#define VK_RIGHT
Definition: winuser.h:2201
#define IOCTL_DISK_GET_DRIVE_LAYOUT
Definition: ntdddisk.h:76
_Check_return_ _CRTIMP int __cdecl iscntrl(_In_ int _C)
LPCTSTR PeekHistory(INT)
Definition: history.c:287
VOID CONSOLE_GetCursorXY(PSHORT x, PSHORT y)
Definition: consup.c:177
enum State_ State
Definition: pofuncs.h:54
static INT CommandDumpSector(PCONSOLE_STATE State, LPSTR param)
Definition: cmdcons.c:334
GLuint in
Definition: glext.h:9616
SHORT maxx
Definition: cmdcons.c:19
GLuint start
Definition: gl.h:1545
#define CMD_SPECIAL
Definition: cmd.h:107
_Check_return_ __MINGW_EXTENSION _CRTIMP __int64 __cdecl _atoi64(_In_z_ const char *_String)
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
static VOID DoCommand(PCONSOLE_STATE State, LPSTR line)
Definition: cmdcons.c:1082
#define FILE_RANDOM_ACCESS
Definition: from_kernel.h:38
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
char * strchr(const char *String, int ch)
Definition: utclib.c:501
#define DPRINT1
Definition: precomp.h:8
#define isprint(c)
Definition: acclib.h:73
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
POINT cp
Definition: magnifier.c:59
struct tagCOMMAND COMMAND
VOID CONSOLE_SetCursorXY(IN SHORT x, IN SHORT y)
Definition: consup.c:223
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
unsigned int ULONG
Definition: retypes.h:1
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
LPSTR name
Definition: cmdcons.c:27
SHORT maxx
Definition: cmdinput.c:115
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define RIGHT_CTRL_PRESSED
Definition: wincon.h:133
VOID History(INT, LPTSTR)
Definition: history.c:326
static INT CommandExit(PCONSOLE_STATE State, LPSTR param)
Definition: cmdcons.c:490
GLfloat GLfloat p
Definition: glext.h:8902
Definition: main.c:14
ULONG Y
Definition: bl.h:1341
#define memset(x, y, z)
Definition: compat.h:39
int tolower(int c)
Definition: utclib.c:902
#define VK_END
Definition: winuser.h:2197
#define RIGHT_ALT_PRESSED
Definition: wincon.h:131
#define IOCTL_DISK_GET_DRIVE_GEOMETRY
Definition: cdrw_usr.h:169
VOID CONSOLE_ConInKey(OUT PINPUT_RECORD Buffer)
Definition: consup.c:62
NTSTATUS NTAPI NtReadFile(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, PVOID Buffer, ULONG Length, PLARGE_INTEGER ByteOffset, PULONG Key)
struct task_struct * current
Definition: linux.c:32
LONGLONG QuadPart
Definition: typedefs.h:112
BOOL add_entry(LPINT ac, LPSTR **arg, LPCSTR entry)
Definition: cmdcons.c:132
int * LPINT
Definition: windef.h:178