From 93eee8dd74fbc32b9e8e35d8c2f752854f94cf6e Mon Sep 17 00:00:00 2001 From: Bradley Bell Date: Thu, 11 Dec 2014 23:42:45 -0800 Subject: [PATCH] get rid of execute and complete callbacks --- include/cmd.h | 3 +++ include/console.h | 2 -- main/cmd.c | 8 ++++++++ main/console.c | 47 ++--------------------------------------------- 4 files changed, 13 insertions(+), 47 deletions(-) diff --git a/include/cmd.h b/include/cmd.h index 845211cf..b3a85019 100644 --- a/include/cmd.h +++ b/include/cmd.h @@ -12,6 +12,9 @@ void cmd_init(void); /* Parse an input string */ void cmd_parse(char *input); +/* Attempt to autocomplete an input string */ +char *cmd_complete(char *input); + typedef void (*cmd_handler_t)(int argc, char *argv[]); void cmd_addcommand(char *cmd_name, cmd_handler_t cmd_func); diff --git a/include/console.h b/include/console.h index 1fea5e38..e8b05242 100644 --- a/include/console.h +++ b/include/console.h @@ -87,8 +87,6 @@ typedef struct console_information_td { unsigned char ConsoleAlpha; //! The consoles alpha level #endif int CommandScrollBack; //! How much the users scrolled back in the command lines - void(*CmdFunction)(char* command); //! The Function that is executed if you press in the console - char*(*TabFunction)(char* command); //! The Function that is executed if you press in the console } ConsoleInformation; diff --git a/main/cmd.c b/main/cmd.c index a6665995..db007b51 100644 --- a/main/cmd.c +++ b/main/cmd.c @@ -134,6 +134,14 @@ void cmd_parse(char *input) } +/* Attempt to autocomplete an input string */ +char *cmd_complete(char *input) +{ + CON_Out(" No autocomplete yet"); + return NULL; +} + + int cmd_handle_keybinding(unsigned char key) { if (cmd_keybinding_list[key]) { diff --git a/main/console.c b/main/console.c index 000d870f..78cb6fe7 100644 --- a/main/console.c +++ b/main/console.c @@ -64,15 +64,6 @@ void CON_SetPrompt(char* newprompt); void CON_SetHideKey(int key); /*! Internal: executes the command typed in at the console (called if you press ENTER)*/ void CON_Execute(char* command); -/*! Sets the callback function that is called if a command was typed in. The function could look like this: - void my_command_handler(char* command). @param console: the console the command - came from. @param command: the command string that was typed in. */ -void CON_SetExecuteFunction(void(*CmdFunction)(char* command)); -/*! Sets the callback tabulator completion function. char* my_tabcompletion(char* command). If Tab is - pressed, the function gets called with the already typed in command. my_tabcompletion then checks if if can - complete the command or if it should display a list of all matching commands (with CON_Out()). Returns the - completed command or NULL if no completion was made. */ -void CON_SetTabCompletion(char*(*TabFunction)(char* command)); /*! Internal: Gets called when TAB was pressed */ void CON_TabCompletion(void); /*! Internal: makes newline (same as printf("\n") or CON_Out("\n") ) */ @@ -83,11 +74,6 @@ void CON_NewLineCommand(void); void CON_UpdateConsole(void); -/*! Internal: Default Execute callback */ -void Default_CmdFunction(char* command); -/*! Internal: Default TabCompletion callback */ -char* Default_TabFunction(char* command); - /*! Internal: draws the commandline the user is typing in to the screen. called by update? */ void DrawCommandLine(); @@ -511,9 +497,6 @@ ConsoleInformation *CON_Init(grs_font *Font, grs_screen *DisplayScreen, int line newinfo->Prompt = CON_DEFAULT_PROMPT; newinfo->HideKey = CON_DEFAULT_HIDEKEY; - CON_SetExecuteFunction(Default_CmdFunction); - CON_SetTabCompletion(Default_TabFunction); - /* make sure that the size of the console is valid */ if(w > newinfo->OutputScreen->sc_w || w < Font->ft_w * 32) w = newinfo->OutputScreen->sc_w; @@ -990,24 +973,7 @@ void CON_SetHideKey(int key) { /* Executes the command entered */ void CON_Execute(char* command) { if(console) - console->CmdFunction(command); -} - -void CON_SetExecuteFunction(void(*CmdFunction)(char* command)) { - if(console) - console->CmdFunction = CmdFunction; -} - -void Default_CmdFunction(char* command) { - CON_Out(" No CommandFunction registered"); - CON_Out(" use 'CON_SetExecuteFunction' to register one"); - CON_Out(" "); - CON_Out("Unknown Command \"%s\"", command); -} - -void CON_SetTabCompletion(char*(*TabFunction)(char* command)) { - if(console) - console->TabFunction = TabFunction; + cmd_parse(command); } void CON_TabCompletion(void) { @@ -1018,7 +984,7 @@ void CON_TabCompletion(void) { return; command = d_strdup(console->LCommand); - command = console->TabFunction(command); + command = cmd_complete(command); if(!command) return; //no tab completion took place so return silently @@ -1040,13 +1006,6 @@ void CON_TabCompletion(void) { console->LCommand[j+1] = '\0'; } -char* Default_TabFunction(char* command) { - CON_Out(" No TabFunction registered"); - CON_Out(" use 'CON_SetTabCompletion' to register one"); - CON_Out(" "); - return NULL; -} - void Cursor_Left(void) { char temp[CON_CHARS_PER_LINE]; @@ -1219,8 +1178,6 @@ void con_init(void) Console = CON_Init(&fake_font, &fake_screen, CON_NUM_LINES, 0, 0, 320, 200); console = Console; - CON_SetExecuteFunction(cmd_parse); - cmd_init(); /* Initialise the cvars */ -- 2.39.2