Esempio n. 1
0
void ExecuteCommand(nodeT **t,char command,int key)
{
   /* printf("\nExcuteCommand Hit here\n");*/
    double i;
		int h;
		int count;

    switch (toupper(command)) {
        case 'I': InsertNode(t, key);break;
        case 'D': printf("\n");DeleteNode(t, key);printf("\n"); break;
        case 'F': printf("\n");FindNode(*t,key);printf("\n"); break;
        case 'O': printf("\n");ListInOrder(*t); printf("\n");break;
        case 'P': printf("\n");PreOrderWalk(*t);printf("\n"); break;
        case 'A': printf("\n");PostOrderWalk(*t);printf("\n"); break;
        case 'L': printf("\n");NodeLevelOrder(*t);printf("\n"); break;
        case 'S': printf("\n");i=add(*t);printf("Sum of tree is:%f\n",i); break;
        case 'N': printf("\n");printf("Min:");Min(*t); printf("\n");break;
        case 'X': printf("\n");printf("Max:");Max(*t); printf("\n");break;
        case 'T': printf("\n");h=height(*t); printf("Height:%d\n",h);break;
        case 'C': printf("\n");count=Count(*t); printf("Number of inputs is:%d\n",count);break;
        case 'H': printf("\n");HelpCommand(); printf("\n");break;
        case 'Q': free_all(*t);exit(0);
        default:  printf("Illegal command\n"); break;
    }
}
Esempio n. 2
0
int main()
{
    treeT *t = NULL;
    char command = '\0';
    int key= 0;
    int quit = 0;
    int flag = 1;
    printf("\nPlease enter a command and a number.If no number is needed enter 1.Here is a help command:\n");
    HelpCommand();
    /****create tree and call excute command***/
    while(1)
    {	
        printf("*");
        	fscanf(stdin,"%c %d",&command,&key);
					if( key == '\0' || command == '\0')
						{
									fscanf(stdin,"%c %d",&command,&key);
						}
        ExecuteCommand(&t,command,key);
        printf("\nCOMMAND = %c, KEY=%d\n",command,key);
				key =command = '\0';
				
    }


    return(0);

}
Esempio n. 3
0
int main () 
{
  stackADT operandStack;
  string line;
  char ch;

  printf("RPN kalkulator -- symulacja (napisz H aby otrzymać pomoc)\n");
  operandStack=NewStack();
  while (TRUE) {
    printf("> ");
    line=GetLine();
    ch=toupper(line[0]);
    switch (ch) {
      case 'Q': exit(0);
      case 'H': HelpCommand(); break;
      case 'C': ClearStack(operandStack); break;
      case 'D': DisplayStack(operandStack); break;
      default: if (isdigit(ch))
          Push(operandStack, StringToReal(line));
        else
          ApplyOperator(ch, operandStack);
        break;
    }
  }
}
Esempio n. 4
0
static void AutoComplete(p_shell_context_t context)
{
    int32_t len;
    int32_t minLen;
    uint8_t i = 0;
    const shell_command_context_t *tmpCommand = NULL;
    const char *namePtr;
    const char *cmdName;

    minLen = 0;
    namePtr = NULL;

    if (!StrLen(context->line))
    {
        return;
    }
    context->printf_data_func("\r\n");
    /* Empty tab, list all commands */
    if (context->line[0] == '\0')
    {
        HelpCommand(context, 0, NULL);
        return;
    }
    /* Do auto complete */
    for (i = 0; i < g_RegisteredCommands.numberOfCommandInList; i++)
    {
        tmpCommand = g_RegisteredCommands.CommandList[i];
        cmdName = tmpCommand->pcCommand;
        if (StrCompare(context->line, cmdName, StrLen(context->line)) == 0)
        {
            if (minLen == 0)
            {
                namePtr = cmdName;
                minLen = StrLen(namePtr);
                /* Show possible matches */
                context->printf_data_func("%s\r\n", cmdName);
                continue;
            }
            len = StrCompare(namePtr, cmdName, StrLen(namePtr));
            if (len < 0)
            {
                len = len * (-1);
            }
            if (len < minLen)
            {
                minLen = len;
            }
        }
    }
    /* Auto complete string */
    if (namePtr)
    {
        StrCopy(context->line, namePtr, minLen);
    }
    context->printf_data_func("%s%s", context->prompt, context->line);
    return;
}
Esempio n. 5
0
static void ExecuteCommand(bufferADT buffer, string line)
{
    int i;

    switch (toupper(line[0])) {
      case 'I': for (i = 1; line[i] != '\0'; i++) {
                    InsertCharacter(buffer, line[i]);
                }
                break;
      case 'D': DeleteCharacter(buffer); break;
      case 'F': MoveCursorForward(buffer); break;
      case 'B': MoveCursorBackward(buffer); break;
      case 'J': MoveCursorToStart(buffer); break;
      case 'E': MoveCursorToEnd(buffer); break;
      case 'H': HelpCommand(); break;
      case 'Q': exit(0);
      default:  printf("Illegal command\n"); break;
    }
}
Esempio n. 6
0
//int _tmain(/*int argc, TCHAR* argv[], TCHAR* envp[]*/)
int main ()
{
  int nRetCode = 0;

  HRESULT hr;

  CSettings *pSettings = NULL;
  CPrompt *pPrompt = NULL;

  CShellCommandsLinkedList CommandsList(Console);

  CShellCommandExit ExitCommand;
  CommandsList.AddCommand(&ExitCommand);

  CShellCommandVersion VersionCommand;
  CommandsList.AddCommand(&VersionCommand);

  CShellCommandHelp HelpCommand(CommandsList);
  CommandsList.AddCommand(&HelpCommand);

  CShellCommandDir DirCommand(Tree);
  CommandsList.AddCommand(&DirCommand);

  CShellCommandChangeKey ChangeKeyCommand(Tree);
  CommandsList.AddCommand(&ChangeKeyCommand);

  CShellCommandValue ValueCommand(Tree);
  CommandsList.AddCommand(&ValueCommand);

  CShellCommandOwner OwnerCommand(Tree);
  CommandsList.AddCommand(&OwnerCommand);

  CShellCommandDACL DACLCommand(Tree);
  CommandsList.AddCommand(&DACLCommand);

  CShellCommandSACL SACLCommand(Tree);
  CommandsList.AddCommand(&SACLCommand);

  CShellCommandConnect ConnectCommand(Tree);
  CommandsList.AddCommand(&ConnectCommand);

  CShellCommandNewKey NewKeyCommand(Tree);
  CommandsList.AddCommand(&NewKeyCommand);

  CShellCommandDeleteKey DeleteKeyCommand(Tree);
  CommandsList.AddCommand(&DeleteKeyCommand);

  CShellCommandSetValue SetValueCommand(Tree);
  CommandsList.AddCommand(&SetValueCommand);

  CShellCommandDeleteValue DeleteValueCommand(Tree);
  CommandsList.AddCommand(&DeleteValueCommand);

  CArgumentParser Parser;

  pSettings = new (std::nothrow) CSettings();
  if (!pSettings)
	{
		_ftprintf(stderr,_T("Cannot initialize settings. Out of memory.\n"));
		goto Abort;
	}

  hr = pSettings->Load(SETTINGS_REGISTRY_KEY);
  if (FAILED(hr))
	{
		_ftprintf(stderr,_T("Cannot load settings. Error is 0x%X.\n"),(unsigned int)hr);
		goto Abort;
	}

  pPrompt = new (std::nothrow) CPrompt(Tree,hr);
  if (!pPrompt)
	{
		_ftprintf(stderr,_T("Cannot initialize prompt. Out of memory.\n"));
		goto Abort;
	}

  if (FAILED(hr))
	{
		_ftprintf(stderr,_T("Cannot initialize prompt. Error is 0x%X.\n"),(unsigned int)hr);
		goto Abort;
	}

// input buffer size in chars
#define INPUT_BUFFER_SIZE	1024
//#define INPUT_BUFFER_SIZE	128
//#define INPUT_BUFFER_SIZE	10

	TCHAR *pchCommand;

  pchCommand = Console.Init(INPUT_BUFFER_SIZE,10);
  if (pchCommand == NULL)
  {
    _ftprintf(stderr,_T("Cannot initialize console.\n"));
    nRetCode = 1;
    goto Exit;
  }

	Console.SetReplaceCompletionCallback(CompletionCallback);

	WORD wOldConsoleAttribute;
	if (!Console.GetTextAttribute(wOldConsoleAttribute)) goto Abort;

	Console.SetTitle(_T("Registry Explorer"));
	Console.SetTextAttribute(pSettings->GetNormalTextAttributes());

	VERIFY(SetConsoleCtrlHandler((PHANDLER_ROUTINE)HandlerRoutine,TRUE));

	if (!Console.Write(HELLO_MSG
	//(_L(__TIMESTAMP__))
	)) goto Abort;

  //Tree.SetDesiredOpenKeyAccess(KEY_READ);

  hr = pPrompt->SetPrompt(pSettings->GetPrompt());
  if (FAILED(hr))
  {
    _ftprintf(stderr,_T("Cannot initialize prompt. Error is 0x%X.\n"),(unsigned int)hr);
    goto Abort;
  }

GetCommand:
	// prompt
	// TODO: make prompt user-customizable
	Console.EnableWrite();
	pPrompt->ShowPrompt(Console);
	Console.FlushInputBuffer();

	blnCommandExecutionInProgress = FALSE;

	// Set command line color
  Console.SetTextAttribute(pSettings->GetCommandTextAttributes());
	if (!Console.ReadLine())
    goto Abort;

	// Set normal color
	Console.SetTextAttribute(pSettings->GetNormalTextAttributes());

	Console.BeginScrollingOperation();
	blnCommandExecutionInProgress = TRUE;

	// Parse command line (1st step - convert to multi sz)
	Parser.SetArgumentList(pchCommand);

	int nCommandReturnValue;
	switch(CommandsList.Execute(Parser,nCommandReturnValue))
	{
	case -1:	// not recognized command
		{
			Parser.ResetArgumentIteration();
			TCHAR *pchCommandItself = Parser.GetNextArgument();
			size_t cmdlen = _tcslen(pchCommandItself);
			if ((!cmdlen)||
				(pchCommandItself[cmdlen-1] != _T('\\'))||
				(Parser.GetNextArgument())||
				(!Tree.ChangeCurrentKey(pchCommandItself)))
			{
				Console.Write(_T("Unknown command \""));
				Console.Write(pchCommandItself);
				Console.Write(_T("\"\n"));
			}
		}
	case -2:	// empty line
		goto GetCommand;
	case 0:	// exit command
		nRetCode = 0;
		Console.SetTextAttribute(wOldConsoleAttribute);
		goto Exit;
	default:
		Console.Write(_T("\n"));
		goto GetCommand;
	}

Abort:
	_ftprintf(stderr,_T("Abnormal program termination.\nPlease report bugs to ") EMAIL _T("\n"));
	nRetCode = 1;

Exit:

  if (pSettings)
    delete pSettings;

  if (pPrompt)
    delete pPrompt;

	return nRetCode;
}
Esempio n. 7
0
VOID
Monitor(
    IN ULONG CallerSource,
    IN PFW_EXCEPTION_FRAME Frame
    )
/*++

Routine Description:

    This is the main dispatch routine to the various commands
    that can be typed at the monitor prompt.

    
Arguments:

    For Alpha/Jensen:
    
    CallerSource	0 if exception (or bugcheck, on Alpha/Jensen)
    			3 if called from boot menu

    Frame               the machine / exception state.

    
Return Value:

    None.

--*/

{
    CHAR Buffer[2][128];
    ULONG ParityDiag[3];
    PULONG ParDiag;
    ULONG BufferIndex;
    PCHAR Argv[10];
    PCHAR Tmp;
    CHAR  String[128];
    BOOLEAN CommandValid;
    GETSTRING_ACTION Action;

#ifdef ALPHA_FW_KDHOOKS

    //
    // If this is a breakpoint exception which is recognized, process it.
    // Otherwise, continue into the Monitor.
    //

    if ((Frame->ExceptionType == FW_EXC_BPT) &&
	(FwKdProcessBreakpoint(Frame) == TRUE)) {
	
	//
	// This does not return.
	//
	      
        FwRfe(Frame);
    }

#endif
    
    FwPrint(MON_MONITOR_MSG);
    FwPrint(MON_PRESS_H_MSG);

    //
    // Initialize command line to null.
    //
    Argv[0] = (PCHAR)NULL;

    if (CallerSource !=3) {

        //
        // Display Cause of exception.
        //

        if ((Frame->ExceptionType >= FW_EXC_FIRST) &&
            (Frame->ExceptionType <= FW_EXC_LAST)
            )
              { FwPrint(ExceptionNameTable[(Frame->ExceptionType & 0xf)]);}
	else
	      { FwPrint("** !! Unknown Exception"); }

        FwPrint(MON_EXCEPTION_MSG);

	FwPrint("PC = 0x%016Lx, VA = 0x%016Lx\r\n",
		Frame->ExceptionFaultingInstructionAddress,
		Frame->ExceptionVa);

        //
	// If an exception happened before the ARC console was opened,
	// a call to JzGetString will not work since JzGetString calls
	// ArcRead.  So, close the console (nothing bad will happen if these
	// are not already opened) and reopen it.
	//

        FwClose(ARC_CONSOLE_INPUT);
        FwClose(ARC_CONSOLE_OUTPUT);

#ifdef ALPHA_FW_KDHOOKS

	//
        // If we are built with the kernel debugger stubs, and have come
	// here because of an exception, we want to enter the debugger.
	//

        Frame->ExceptionType = FW_EXC_BPT;
        DbgBreakPoint();

#endif

	FwOpenConsole();
    }

    //
    // Initialize Static variables.
    //
    DefaultAddress = KSEG0_BASE;
    DataSize = MON_QUAD;
    BufferIndex = 0;

    //
    // loop forever getting commands and dispatching them
    //

    while(TRUE) {

        //
        // print prompt
        //

        FwPrint(">");

        //
        // read a command.
        //

        do {
            Action = JzGetString(Buffer[BufferIndex], 128, NULL,
				 FwRow+1, FwColumn+1, FALSE);
        } while ((Action != GetStringSuccess) && (Action != GetStringEscape));
        FwPrint(FW_CRLF_MSG);

        //
        // convert string to lower case.
        //

        for (Tmp=Buffer[BufferIndex];*Tmp;*Tmp++) {
            *Tmp=tolower(*Tmp);
        }

        //
        // if escape was pressed, simulate a quit command.
        //

        if (Action == GetStringEscape) {
            Argc = 1;
            Argv[0] = "q";

        //
        // separate command line into tokens delimited by spaces
        // load up Argv with pointers to arguments and put count in Argc
        //

        } else if (*Buffer[BufferIndex] != '\0') {
            Tmp = Buffer[BufferIndex];
            Argc = 0;
            //
            // Skip leading blanks
            //
            while ( *Tmp == ' ') {
                Tmp++;
            }
            while ( *Tmp ) {
                Argv[Argc++] = Tmp;
                while ( *Tmp ) {
                    if (*Tmp == ' ') {
                        *Tmp++ = '\0';
                        while ( *Tmp == ' ') {
                            Tmp++;
                        }
                        break;
                    }
                    Tmp++;
                }
            }

            //
            // Increment index so that next command is read into the other
            // buffer. And we preserve the previous one.
            //
            BufferIndex = (BufferIndex+1) & 0x1;
        } else {
            //
            // repeat the last command already in Argv Argc
            //
        }
        //
        // if first argument is not null, then dispatch to routines.
        //
        if (Argv[0] != (PCHAR) NULL) {
            CurrentArg = 1;
            CurrentCommand = GetCommand(Argv[0]);
            switch(CurrentCommand) {
                case DumpByte:
                case DumpWord:
                case DumpLongword:
                case DumpQuad:
                        DataSizeShift = (CurrentCommand - Dump -1);
                        DataSize = 1 << DataSizeShift;
                        DataSizeMask = DataSize-1;
                case Dump:
                        CommandValid = DumpCommand(Argv,Frame);
                        break;

                case EnterByte:
                case EnterWord:
                case EnterLongword:
		case EnterQuad:
                        DataSizeShift = (CurrentCommand - Enter -1);
                        DataSize = 1 << DataSizeShift;
                        DataSizeMask = DataSize-1;
                case Enter:
                        CommandValid = EnterCommand(Argv,Frame);
                        break;

                case Help:
                case Help2:
			HelpCommand();
			break;

                case DepositByte:
                case DepositWord:
                case DepositLongword:
                case DepositQuad:
                        DataSizeShift = (CurrentCommand - Deposit -1);
                        DataSize = 1 << DataSizeShift;
                        DataSizeMask = DataSize-1;
                case Deposit:
                        CommandValid = DepositCommand(Argv,Frame);
                        break;
                case ExamineByte:
                case ExamineWord:
                case ExamineLongword:
                case ExamineQuad:
                        DataSizeShift = (CurrentCommand - Examine -1);
                        DataSize = 1 << DataSizeShift;
                        DataSizeMask = DataSize-1;
                case Examine:
                        CommandValid = ExamineCommand(Argv,Frame);
                        break;

 		case IOReadByte:
 		case IOReadWord:
 		case IOReadLongword:
                        DataSizeShift = (CurrentCommand - IORead -1);
                        DataSize = 1 << DataSizeShift;
                        DataSizeMask = DataSize-1;
		case IORead:
			CommandValid = IOReadCommand(Argv, Frame);
			break;
			
#if 0

 		case IOWriteByte:
 		case IOWriteWord:
 		case IOWriteLongword:
                        DataSizeShift = (CurrentCommand - IOWrite -1);
                        DataSize = 1 << DataSizeShift;
                        DataSizeMask = DataSize-1;
		case IOWrite:
			CommandValid = IOWriteCommand(Argv, Frame);
			break;
			
#endif

                case Register:
		case IntegerRegisterDump:
		case FloatingRegisterDump:
                        CommandValid = RegisterCommand(Argv, Frame);
                        break;

                case Zero:
                        CommandValid = ZeroCommand(Argv,Frame);
                        break;

                case Fill:
                        CommandValid = FillCommand(Argv,Frame);
                        break;

#if 0
		case AvailableDevices:
			CommandValid = FwDumpLookupTable();
			break;
#endif

                case Quit:
                        if (CallerSource == 3) {
                            return;
                        } else {
                            //
                            // We came because of an exception.
                            // The only way to exit is reseting the system.
                            //
                            FwPrint(MON_NO_RETURN_MSG);
                            FwPrint(MON_RESET_MACHINE_MSG);

                            do {
                                Action = JzGetString(Buffer[BufferIndex],
						     128,
						     NULL,
						     FwRow+1,
						     FwColumn+1,
						     FALSE);
                            } while ((Action != GetStringSuccess) && (Action != GetStringEscape));
                            FwPrint(FW_CRLF_MSG);

                            Buffer[BufferIndex][0]=tolower(Buffer[BufferIndex][0]);
                            if (strcmp(Buffer[BufferIndex],"y") == 0) {
                                ResetSystem();
                            }
                            break;
                        }

                case invalidcommand:

                        FwPrint(MON_UNRECOGNIZED_COMMAND_MSG);

                        //
                        // Clear the argument so that re-do last command
                        // doesn't repeat the erroneous command.
                        //

                        CommandValid = FALSE;
                        break;
            }

            if (!CommandValid) {
                Argv[0] = (PCHAR) NULL;
            }
        }
    }
}