ReactOS 0.4.16-dev-306-g647d351
cmdcons.c File Reference
#include "usetup.h"
#include <debug.h>
Include dependency graph for cmdcons.c:

Go to the source code of this file.

Classes

struct  _CONSOLE_STATE
 
struct  tagCOMMAND
 

Macros

#define NDEBUG
 

Typedefs

typedef struct _CONSOLE_STATE CONSOLE_STATE
 
typedef struct _CONSOLE_STATEPCONSOLE_STATE
 
typedef struct tagCOMMAND COMMAND
 
typedef struct tagCOMMANDLPCOMMAND
 

Functions

static VOID HelpCls (VOID)
 
static INT CommandCls (PCONSOLE_STATE State, LPSTR param)
 
static VOID HelpDumpSector (VOID)
 
static INT CommandDumpSector (PCONSOLE_STATE State, LPSTR param)
 
static VOID HelpExit (VOID)
 
static INT CommandExit (PCONSOLE_STATE State, LPSTR param)
 
static VOID HelpHelp (VOID)
 
static INT CommandHelp (PCONSOLE_STATE State, LPSTR param)
 
static VOID HelpPartInfo (VOID)
 
static INT CommandPartInfo (PCONSOLE_STATE State, LPSTR param)
 
static VOID freep (LPSTR *p)
 
static VOID StripQuotes (LPSTR in)
 
BOOL add_entry (LPINT ac, LPSTR **arg, LPCSTR entry)
 
static LPSTRsplit (LPSTR s, LPINT args)
 
void HexDump (PUCHAR buffer, ULONG size)
 
static VOID ClearCommandLine (LPSTR str, INT maxlen, SHORT orgx, SHORT orgy)
 
static BOOL ReadCommand (PCONSOLE_STATE State, LPSTR str, INT maxlen)
 
static BOOL IsDelimiter (CHAR c)
 
static VOID DoCommand (PCONSOLE_STATE State, LPSTR line)
 
VOID RecoveryConsole (VOID)
 

Variables

COMMAND Commands []
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 11 of file cmdcons.c.

Typedef Documentation

◆ COMMAND

◆ CONSOLE_STATE

◆ LPCOMMAND

◆ PCONSOLE_STATE

Function Documentation

◆ add_entry()

BOOL add_entry ( LPINT  ac,
LPSTR **  arg,
LPCSTR  entry 
)

Definition at line 132 of file cmdcons.c.

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}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
HANDLE ProcessHeap
Definition: servman.c:15
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:590
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
NTSYSAPI PVOID WINAPI RtlReAllocateHeap(HANDLE, ULONG, PVOID, SIZE_T)
Definition: heap.c:2686
uint32_t entry
Definition: isohybrid.c:63
void * arg
Definition: msvc.h:10
char * LPSTR
Definition: xmlstorage.h:182

Referenced by CommandDir(), DirReadParam(), and split().

◆ ClearCommandLine()

static VOID ClearCommandLine ( LPSTR  str,
INT  maxlen,
SHORT  orgx,
SHORT  orgy 
)
static

Definition at line 717 of file cmdcons.c.

722{
723 INT count;
724
725 CONSOLE_SetCursorXY(orgx, orgy);
726 for (count = 0; count < (INT)strlen(str); count++)
728 memset(str, 0, maxlen);
729 CONSOLE_SetCursorXY(orgx, orgy);
730}
VOID CONSOLE_SetCursorXY(IN SHORT x, IN SHORT y)
Definition: consup.c:227
VOID CONSOLE_ConOutChar(IN CHAR c)
Definition: consup.c:114
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define INT
Definition: polytest.cpp:20
const WCHAR * str
#define memset(x, y, z)
Definition: compat.h:39
int32_t INT
Definition: typedefs.h:58

Referenced by ReadCommand().

◆ CommandCls()

static INT CommandCls ( PCONSOLE_STATE  State,
LPSTR  param 
)
static

Definition at line 260 of file cmdcons.c.

263{
264 if (!strcmp(param, "/?"))
265 {
266 HelpCls();
267 return 0;
268 }
269
272
273 return 0;
274}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
static VOID HelpCls(VOID)
Definition: cmdcons.c:252
VOID CONSOLE_ClearScreen(VOID)
Definition: consup.c:239
GLfloat param
Definition: glext.h:5796

◆ CommandDumpSector()

static INT CommandDumpSector ( PCONSOLE_STATE  State,
LPSTR  param 
)
static

Definition at line 334 of file cmdcons.c.

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;
352
353 DPRINT1("param: %s\n", param);
354
355 if (!strcmp(param, "/?"))
356 {
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,
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,
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
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,
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
467done:
468 if (Buffer != NULL)
470
471 if (hDisk != NULL)
472 NtClose(hDisk);
473
474 freep(argv);
475
476 return 0;
477}
static int argc
Definition: ServiceArgs.c:12
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
__int64 CDECL _atoi64(const char *nptr)
Definition: atoi64.c:18
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
#define DPRINT1
Definition: precomp.h:8
#define IOCTL_DISK_GET_DRIVE_GEOMETRY
Definition: cdrw_usr.h:169
Definition: bufpool.h:45
void HexDump(PUCHAR buffer, ULONG size)
Definition: cmdcons.c:277
static VOID HelpDumpSector(VOID)
Definition: cmdcons.c:326
static VOID freep(LPSTR *p)
Definition: cmdcons.c:98
static LPSTR * split(LPSTR s, LPINT args)
Definition: cmdcons.c:163
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
VOID __cdecl CONSOLE_ConOutPrintf(IN LPCSTR szFormat,...)
Definition: consup.c:163
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define GENERIC_READ
Definition: compat.h:135
#define FILE_SHARE_READ
Definition: compat.h:136
#define swprintf
Definition: precomp.h:40
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
#define FILE_RANDOM_ACCESS
Definition: from_kernel.h:38
Status
Definition: gdiplustypes.h:25
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define OBJ_INHERIT
Definition: winternl.h:225
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define argv
Definition: mplay32.c:18
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:3952
#define SYNCHRONIZE
Definition: nt_native.h:61
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
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)
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define L(x)
Definition: ntvdm.h:50
ULONG SectorCount
Definition: part_xbox.c:31
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)
MEDIA_TYPE MediaType
Definition: ntdddisk.h:401
LARGE_INTEGER Cylinders
Definition: ntdddisk.h:400
ULONG TracksPerCylinder
Definition: ntdddisk.h:402
ULONG SectorsPerTrack
Definition: ntdddisk.h:403
ULONG BytesPerSector
Definition: ntdddisk.h:404
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
uint64_t ULONGLONG
Definition: typedefs.h:67
LONGLONG QuadPart
Definition: typedefs.h:114
__wchar_t WCHAR
Definition: xmlstorage.h:180
CHAR * LPTSTR
Definition: xmlstorage.h:192

◆ CommandExit()

static INT CommandExit ( PCONSOLE_STATE  State,
LPSTR  param 
)
static

Definition at line 490 of file cmdcons.c.

493{
494 if (!strcmp(param, "/?"))
495 {
496 HelpExit();
497 return 0;
498 }
499
500 State->bExit = TRUE;
501
502 return 0;
503}
static VOID HelpExit(VOID)
Definition: cmdcons.c:482

◆ CommandHelp()

static INT CommandHelp ( PCONSOLE_STATE  State,
LPSTR  param 
)
static

Definition at line 516 of file cmdcons.c.

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");
550
551 return 0;
552}
#define _stricmp
Definition: cat.c:22
static VOID HelpHelp(VOID)
Definition: cmdcons.c:508
COMMAND Commands[]
Definition: cmdcons.c:85
VOID(* help)(VOID)
Definition: cmdcons.c:30
LPSTR name
Definition: cmdcons.c:27

◆ CommandPartInfo()

static INT CommandPartInfo ( PCONSOLE_STATE  State,
LPSTR  param 
)
static

Definition at line 565 of file cmdcons.c.

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,
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,
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,
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
701
702done:
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}
static VOID HelpPartInfo(VOID)
Definition: cmdcons.c:557
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
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 IOCTL_DISK_GET_DRIVE_LAYOUT
Definition: ntdddisk.h:91
PARTITION_INFORMATION PartitionEntry[1]
Definition: ntdddisk.h:421
_In_ ULONG _In_ struct _SET_PARTITION_INFORMATION_EX * PartitionInfo
Definition: iofuncs.h:2105

◆ DoCommand()

static VOID DoCommand ( PCONSOLE_STATE  State,
LPSTR  line 
)
static

Definition at line 1082 of file cmdcons.c.

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}
#define isspace(c)
Definition: acclib.h:69
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
int tolower(int c)
Definition: utclib.c:902
char * strchr(const char *String, int ch)
Definition: utclib.c:501
#define CMD_SPECIAL
Definition: cmd.h:140
static BOOL IsDelimiter(CHAR c)
Definition: cmdcons.c:1073
VOID CONSOLE_ConOutPuts(IN LPCSTR szText)
Definition: consup.c:127
#define MAX_PATH
Definition: compat.h:34
POINT cp
Definition: magnifier.c:59
Definition: parser.c:49
INT(* func)(PCONSOLE_STATE, LPSTR)
Definition: cmdcons.c:29
INT flags
Definition: cmdcons.c:28
char CHAR
Definition: xmlstorage.h:175

Referenced by cmd_call(), and RecoveryConsole().

◆ freep()

static VOID freep ( LPSTR p)
static

Definition at line 98 of file cmdcons.c.

100{
101 LPSTR *q;
102
103 if (!p)
104 return;
105
106 q = p;
107 while (*q)
108 RtlFreeHeap(ProcessHeap, 0, *q++);
109
111}
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by cmd_copy(), cmd_date(), cmd_mkdir(), cmd_mklink(), cmd_move(), cmd_rename(), cmd_rmdir(), cmd_setlocal(), cmd_time(), cmd_type(), CommandChoice(), CommandDelete(), CommandDir(), CommandDumpSector(), CommandFree(), CommandPartInfo(), CommandTimer(), DirReadParam(), and split().

◆ HelpCls()

static VOID HelpCls ( VOID  )
static

Definition at line 252 of file cmdcons.c.

253{
254 CONSOLE_ConOutPrintf("CLS\n\nClears the screen.\n\n");
255}

Referenced by CommandCls().

◆ HelpDumpSector()

static VOID HelpDumpSector ( VOID  )
static

Definition at line 326 of file cmdcons.c.

327{
328 CONSOLE_ConOutPrintf("DUMPSECT DiskNumber Sector\n\nDumps a disk sector to the screen.\n\n");
329}

Referenced by CommandDumpSector().

◆ HelpExit()

static VOID HelpExit ( VOID  )
static

Definition at line 482 of file cmdcons.c.

483{
484 CONSOLE_ConOutPrintf("EXIT\n\nExits the repair console.\n\n");
485}

Referenced by CommandExit().

◆ HelpHelp()

static VOID HelpHelp ( VOID  )
static

Definition at line 508 of file cmdcons.c.

509{
510 CONSOLE_ConOutPrintf("HELP [Command]\n\nShows help on repair console commands.\n\n");
511}

Referenced by CommandHelp().

◆ HelpPartInfo()

static VOID HelpPartInfo ( VOID  )
static

Definition at line 557 of file cmdcons.c.

558{
559 CONSOLE_ConOutPrintf("PARTINFO DiskNumber\n\nDumps a partition table to the screen.\n\n");
560}

Referenced by CommandPartInfo().

◆ HexDump()

void HexDump ( PUCHAR  buffer,
ULONG  size 
)

Definition at line 277 of file cmdcons.c.

278{
279 ULONG offset = 0;
280 PUCHAR ptr;
281
282 while (offset < (size & ~15))
283 {
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 {
309 CONSOLE_ConOutPrintf("%04lx ", offset);
310 while (offset < size)
311 {
312 CONSOLE_ConOutPrintf(" %02hx", *ptr);
313 offset++;
314 ptr++;
315 }
316
318 }
319
321}
GLsizeiptr size
Definition: glext.h:5919
GLuint buffer
Definition: glext.h:5915
GLintptr offset
Definition: glext.h:5920
static PVOID ptr
Definition: dispmode.c:27
uint32_t ULONG_PTR
Definition: typedefs.h:65

Referenced by CommandDumpSector(), and main().

◆ IsDelimiter()

static BOOL IsDelimiter ( CHAR  c)
static

Definition at line 1073 of file cmdcons.c.

1075{
1076 return (c == '/' || c == '=' || c == '\0' || isspace(c));
1077}
const GLubyte * c
Definition: glext.h:8905

Referenced by DoCommand().

◆ ReadCommand()

static BOOL ReadCommand ( PCONSOLE_STATE  State,
LPSTR  str,
INT  maxlen 
)
static

Definition at line 735 of file cmdcons.c.

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
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));
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;
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);
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);
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;
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);
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);
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
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 = (USHORT)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++;
1060 }
1061 }
1062 }
1063 while (!bReturn);
1064
1065 CONSOLE_SetCursorType(State->bInsert, TRUE);
1066
1067 return TRUE;
1068}
VOID GetCursorXY(PSHORT x, PSHORT y)
Definition: console.c:196
#define ConOutPrintf(szStr,...)
Definition: console.h:41
VOID History_move_to_bottom(VOID)
Definition: history.c:280
VOID History(INT dir, LPTSTR commandline)
Definition: history.c:326
VOID History_del_current_entry(LPTSTR str)
Definition: history.c:175
LPCTSTR PeekHistory(INT dir)
Definition: history.c:287
static VOID ClearCommandLine(LPSTR str, INT maxlen, SHORT orgx, SHORT orgy)
Definition: cmdcons.c:717
SHORT maxx
Definition: cmdinput.c:115
SHORT maxy
Definition: cmdinput.c:116
SHORT CONSOLE_GetCursorY(VOID)
Definition: consup.c:204
VOID CONSOLE_GetCursorXY(OUT PSHORT x, OUT PSHORT y)
Definition: consup.c:181
VOID CONSOLE_ConInKey(OUT PINPUT_RECORD Buffer)
Definition: consup.c:70
SHORT CONSOLE_GetCursorX(VOID)
Definition: consup.c:194
VOID CONSOLE_SetCursorType(IN BOOL bInsert, IN BOOL bVisible)
Definition: consup.c:214
unsigned int BOOL
Definition: ntddk_ex.h:94
struct task_struct * current
Definition: linux.c:32
static UINT UINT last
Definition: font.c:45
short SHORT
Definition: pedump.c:59
unsigned short USHORT
Definition: pedump.c:61
union _INPUT_RECORD::@3286 Event
KEY_EVENT_RECORD KeyEvent
Definition: wincon.h:275
union _KEY_EVENT_RECORD::@3285 uChar
DWORD dwControlKeyState
Definition: wincon.h:248
WORD wVirtualKeyCode
Definition: wincon.h:242
WCHAR UnicodeChar
Definition: wincon.h:245
#define LEFT_CTRL_PRESSED
Definition: wincon.h:140
#define RIGHT_CTRL_PRESSED
Definition: wincon.h:139
#define RIGHT_ALT_PRESSED
Definition: wincon.h:137
#define LEFT_ALT_PRESSED
Definition: wincon.h:138
#define VK_UP
Definition: winuser.h:2228
#define VK_RETURN
Definition: winuser.h:2204
#define VK_END
Definition: winuser.h:2225
#define VK_HOME
Definition: winuser.h:2226
#define VK_BACK
Definition: winuser.h:2201
#define VK_F3
Definition: winuser.h:2260
#define VK_LEFT
Definition: winuser.h:2227
#define VK_RIGHT
Definition: winuser.h:2229
#define VK_DOWN
Definition: winuser.h:2230
#define VK_DELETE
Definition: winuser.h:2236
#define VK_ESCAPE
Definition: winuser.h:2217
#define VK_INSERT
Definition: winuser.h:2235
const char * LPCSTR
Definition: xmlstorage.h:183

Referenced by ReadLine(), and RecoveryConsole().

◆ RecoveryConsole()

VOID RecoveryConsole ( VOID  )

Definition at line 1160 of file cmdcons.c.

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 */
1183
1184 ReadCommand(&State, szInputBuffer, 256);
1185DPRINT1("%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}
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:203
BOOL WINAPI GetConsoleScreenBufferInfo(IN HANDLE hConsoleOutput, OUT PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo)
Definition: console.c:595
static BOOL ReadCommand(PCONSOLE_STATE State, LPSTR str, INT maxlen)
Definition: cmdcons.c:735
static VOID DoCommand(PCONSOLE_STATE State, LPSTR line)
Definition: cmdcons.c:1082
SHORT Y
Definition: blue.h:27
SHORT X
Definition: blue.h:26
#define STD_OUTPUT_HANDLE
Definition: winbase.h:294

Referenced by RunUSetup().

◆ split()

static LPSTR * split ( LPSTR  s,
LPINT  args 
)
static

Definition at line 163 of file cmdcons.c.

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}
#define isprint(c)
Definition: acclib.h:73
static VOID StripQuotes(LPSTR in)
Definition: cmdcons.c:116
BOOL add_entry(LPINT ac, LPSTR **arg, LPCSTR entry)
Definition: cmdcons.c:132
GLuint start
Definition: gl.h:1545
GLdouble s
Definition: gl.h:2039
GLenum GLsizei len
Definition: glext.h:6722
_Check_return_ _CRTIMP int __cdecl iscntrl(_In_ int _C)
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
Definition: match.c:390
int32_t INT_PTR
Definition: typedefs.h:64

Referenced by cmd_copy(), cmd_date(), cmd_mkdir(), cmd_mklink(), cmd_rename(), cmd_rmdir(), cmd_time(), cmd_type(), CommandChoice(), CommandDelete(), CommandDumpSector(), CommandFree(), CommandPartInfo(), CommandTimer(), ext4_ext_convert_to_initialized(), ext4_split_extent_at(), and gray_render_conic().

◆ StripQuotes()

static VOID StripQuotes ( LPSTR  in)
static

Definition at line 116 of file cmdcons.c.

118{
119 LPSTR out = in;
120
121 for (; *in; in++)
122 {
123 if (*in != '"')
124 *out++ = *in;
125 }
126
127 *out = '\0';
128}
GLuint in
Definition: glext.h:9616
static FILE * out
Definition: regtests2xml.c:44

Referenced by cmd_chdir(), cmd_set(), cmd_start(), DirReadParam(), Execute(), ExecuteIf(), ForDir(), ForF(), ParseFor(), PerformRedirection(), SetRootPath(), and split().

Variable Documentation

◆ Commands

COMMAND Commands[]
Initial value:
=
{
{"cls", 0, CommandCls, HelpCls},
{"dumpsector", 0, CommandDumpSector, HelpDumpSector},
{"exit", 0, CommandExit, HelpExit},
{"help", 0, CommandHelp, HelpHelp},
{"partinfo", 0, CommandPartInfo, HelpPartInfo},
{NULL, 0, NULL}
}
static INT CommandDumpSector(PCONSOLE_STATE State, LPSTR param)
Definition: cmdcons.c:334
static INT CommandHelp(PCONSOLE_STATE State, LPSTR param)
Definition: cmdcons.c:516
static INT CommandCls(PCONSOLE_STATE State, LPSTR param)
Definition: cmdcons.c:260
static INT CommandExit(PCONSOLE_STATE State, LPSTR param)
Definition: cmdcons.c:490
static INT CommandPartInfo(PCONSOLE_STATE State, LPSTR param)
Definition: cmdcons.c:565

Definition at line 85 of file cmdcons.c.

Referenced by CommandHelp(), and DoCommand().