Example #1
0
        public static void Execute(CommandExecutionContext *context)
        {
            CommandExecutionAttemptResult result = Prompter.CommandTable->HandleLine(context->parameters, false, true);

            if (result == CommandExecutionAttemptResult.NotFound)
            {
                int       indexOfSpace = context->parameters->IndexOf(" ");
                CString8 *tempStr;
                if (indexOfSpace >= 0)
                {
                    tempStr = context->parameters->Substring(0, indexOfSpace);
                }
                else
                {
                    tempStr = CString8.Copy(context->parameters);
                }

                TextMode.Write("No command '");
                TextMode.Write(tempStr);
                TextMode.WriteLine("' is available to retrieve help for.");
                TextMode.WriteLine(CommandTableHeader.inform_USE_HELP_COMMANDS);

                CString8.DISPOSE(tempStr);
                return;
            }
            if (result == CommandExecutionAttemptResult.BlankEntry)
            {
                ADC.MemoryUtil.Call((void *)Stubs.GetFunctionPointer(lblGetHelp), (void *)context);
            }
        }
Example #2
0
        private static void DispatchBuffer()
        {
            CString8 *bufferCopy = CString8.Copy(textBuffer->buffer);

            Diagnostics.Assert(bufferCopy != null, "Prompter::DispatchBuffer(): INSANITY CHECK: CString8.Copy(byte*) returned NULL");
            Prompter.QueueLine(bufferCopy);
            CString8.DISPOSE(bufferCopy);
            textBuffer->Clear();
        }
Example #3
0
        public static void Pulse()
        {
            if (running == false)
            {
                return;
            }

            CString8 *line = DequeueLine();

            if (line != null)
            {
                HandleLine(line);
                CString8.DISPOSE(line);
            }
        }
Example #4
0
        internal CommandExecutionAttemptResult HandleLine(CString8 *input, bool verboseFailure, bool useHelp)
        {
            Diagnostics.Assert(input != null, "Prompter::HandleLine(CString8*): Parameter 'input' is null");
#if Prompter_DebuggingVerbosity
            Diagnostics.Message("Prompter::HandleLine(CString8*): Function started");
#endif

            if (input->Length == 0)
            {
#if Prompter_DebuggingVerbosity
                Diagnostics.Message("Prompter::HandleLine(CString8*): Raw input is blank");
#endif
                if (verboseFailure)
                {
                    HandleEmptyCommandEntry();
                }

#if Prompter_DebuggingVerbosity
                Diagnostics.Message("Prompter::HandleLine(CString8*): RET");
#endif
                return(CommandExecutionAttemptResult.BlankEntry);
            }
            CString8 *trimmedInput = input->Trim();
            if (trimmedInput->Length == 0)
            {
#if Prompter_DebuggingVerbosity
                Diagnostics.Message("Prompter::HandleLine(CString8*): Trimmed input is blank");
#endif
                CString8.DISPOSE(trimmedInput);

                if (verboseFailure)
                {
                    HandleEmptyCommandEntry();
                }

#if Prompter_DebuggingVerbosity
                Diagnostics.Message("Prompter::HandleLine(CString8*): RET");
#endif
                return(CommandExecutionAttemptResult.BlankEntry);
            }

            int       firstSpace = trimmedInput->IndexOf(" ");
            CString8 *commandName;
            CString8 *parameters;
            if (firstSpace < 0)
            {
                commandName = trimmedInput;
                parameters  = CString8.CreateEmpty();
            }
            else
            {
                commandName = trimmedInput->Substring(0, firstSpace);
                parameters  = trimmedInput->Substring(firstSpace + 1);
            }

            CommandTableEntry *command = this.FindCommand(commandName);
            if (command == null)
            {
#if Prompter_DebuggingVerbosity
                Diagnostics.Message("Prompter::HandleLine(CString8*): Command not found");
#endif
                if (verboseFailure)
                {
                    HandleUnrecognizedCommandEntry(commandName);
                }

#if Prompter_DebuggingVerbosity
                Diagnostics.Message("Prompter::HandleLine(CString8*): Freeing contextual stuff");
#endif
                //Free up what we used
                if (commandName != trimmedInput)
                {
                    CString8.DISPOSE(commandName);
                }
                CString8.DISPOSE(trimmedInput);
                CString8.DISPOSE(parameters);
#if Prompter_DebuggingVerbosity
                Diagnostics.Message("Prompter::HandleLine(CString8*): RET");
#endif
                return(CommandExecutionAttemptResult.NotFound);
            }
            CommandExecutionContext *commandExecutionContext = CommandExecutionContext.CREATE();
            commandExecutionContext->parameters = parameters;

#if Prompter_DebuggingVerbosity
            Diagnostics.Message("Prompter::HandleLine(CString8*): Getting ready to call command");
#endif
            if (!useHelp)
            {
                ADC.MemoryUtil.Call(command->func_Execute, (void *)commandExecutionContext);
            }
            else
            {
                ADC.MemoryUtil.Call(command->func_GetHelp, (void *)commandExecutionContext);
            }
#if Prompter_DebuggingVerbosity
            Diagnostics.Message("Prompter::HandleLine(CString8*): Done calling command");
#endif

            //Free up what we used
#if Prompter_DebuggingVerbosity
            Diagnostics.Message("Prompter::HandleLine(CString8*): Freeing contextual stuff");
#endif
            if (commandName != trimmedInput)
            {
                CString8.DISPOSE(commandName);
            }
            CString8.DISPOSE(trimmedInput);
            CString8.DISPOSE(parameters);
            CommandExecutionContext.DISPOSE(commandExecutionContext);
#if Prompter_DebuggingVerbosity
            Diagnostics.Message("Prompter::HandleLine(CString8*): RET");
#endif
            return(CommandExecutionAttemptResult.Success);
        }