ADD: @piwi's fixes to .history

This commit is contained in:
iceman1001 2015-11-09 21:46:57 +01:00
commit cc3c0a5148
5 changed files with 20 additions and 17 deletions

View file

@ -75,7 +75,7 @@ int CmdLS(const char *Cmd){
int CmdQuit(const char *Cmd) int CmdQuit(const char *Cmd)
{ {
exit(0); exit(0);
return 0; return 99;
} }
int CmdRev(const char *Cmd) int CmdRev(const char *Cmd)
@ -174,8 +174,8 @@ bool WaitForResponse(uint32_t cmd, UsbCommand* response) {
// Entry point into our code: called whenever the user types a command and // Entry point into our code: called whenever the user types a command and
// then presses Enter, which the full command line that they typed. // then presses Enter, which the full command line that they typed.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void CommandReceived(char *Cmd) { int CommandReceived(char *Cmd) {
CmdsParse(CommandTable, Cmd); return CmdsParse(CommandTable, Cmd);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View file

@ -14,7 +14,7 @@
#include "usb_cmd.h" #include "usb_cmd.h"
#include "cmdparser.h" #include "cmdparser.h"
void UsbCommandReceived(UsbCommand *UC); void UsbCommandReceived(UsbCommand *UC);
void CommandReceived(char *Cmd); int CommandReceived(char *Cmd);
bool WaitForResponseTimeout(uint32_t cmd, UsbCommand* response, size_t ms_timeout); bool WaitForResponseTimeout(uint32_t cmd, UsbCommand* response, size_t ms_timeout);
bool WaitForResponse(uint32_t cmd, UsbCommand* response); bool WaitForResponse(uint32_t cmd, UsbCommand* response);
void clearCommandBuffer(); void clearCommandBuffer();

View file

@ -40,17 +40,17 @@ void CmdsLS(const command_t Commands[])
} }
} }
void CmdsParse(const command_t Commands[], const char *Cmd) int CmdsParse(const command_t Commands[], const char *Cmd)
{ {
if(strcmp( Cmd, "XX_internal_command_dump_XX") == 0) if(strcmp( Cmd, "XX_internal_command_dump_XX") == 0)
{// Help dump children {// Help dump children
dumpCommandsRecursive(Commands, 0); dumpCommandsRecursive(Commands, 0);
return; return 0;
} }
if(strcmp( Cmd, "XX_internal_command_dump_markdown_XX") == 0) if(strcmp( Cmd, "XX_internal_command_dump_markdown_XX") == 0)
{// Markdown help dump children {// Markdown help dump children
dumpCommandsRecursive(Commands, 1); dumpCommandsRecursive(Commands, 1);
return; return 0;
} }
char cmd_name[32]; char cmd_name[32];
int len = 0; int len = 0;
@ -77,11 +77,13 @@ void CmdsParse(const command_t Commands[], const char *Cmd)
if (Commands[i].Name) { if (Commands[i].Name) {
while (Cmd[len] == ' ') while (Cmd[len] == ' ')
++len; ++len;
Commands[i].Parse(Cmd + len); return Commands[i].Parse(Cmd + len);
} else { } else {
// show help for selected hierarchy or if command not recognised // show help for selected hierarchy or if command not recognised
CmdsHelp(Commands); CmdsHelp(Commands);
} }
return 0;
} }
char pparent[512] = {0}; char pparent[512] = {0};

View file

@ -26,7 +26,7 @@ void CmdsHelp(const command_t Commands[]);
// Print each command in the command array without help // Print each command in the command array without help
void CmdsLS(const command_t Commands[]); void CmdsLS(const command_t Commands[]);
// Parse a command line // Parse a command line
void CmdsParse(const command_t Commands[], const char *Cmd); int CmdsParse(const command_t Commands[], const char *Cmd);
void dumpCommandsRecursive(const command_t cmds[], int markdown); void dumpCommandsRecursive(const command_t cmds[], int markdown);
#endif #endif

View file

@ -155,12 +155,11 @@ static void *main_loop(void *targ) {
cmd[strlen(cmd) - 1] = 0x00; cmd[strlen(cmd) - 1] = 0x00;
if (cmd[0] != 0x00) { if (cmd[0] != 0x00) {
if (strncmp(cmd, "quit", 4) == 0) { int ret = CommandReceived(cmd);
exit(0); add_history(cmd);
if (ret == 99) { // exit or quit
break; break;
} }
CommandReceived(cmd);
add_history(cmd);
} }
free(cmd); free(cmd);
} else { } else {
@ -223,7 +222,7 @@ int main(int argc, char* argv[]) {
.usb_present = 0, .usb_present = 0,
.script_cmds_file = NULL .script_cmds_file = NULL
}; };
pthread_t main_loop_t; pthread_t main_loop_threat;
sp = uart_open(argv[1]); sp = uart_open(argv[1]);
@ -258,18 +257,20 @@ int main(int argc, char* argv[]) {
// create a mutex to avoid interlacing print commands from our different threads // create a mutex to avoid interlacing print commands from our different threads
pthread_mutex_init(&print_lock, NULL); pthread_mutex_init(&print_lock, NULL);
pthread_create(&main_loop_t, NULL, &main_loop, &marg); pthread_create(&main_loop_threat, NULL, &main_loop, &marg);
InitGraphics(argc, argv); InitGraphics(argc, argv);
MainGraphics(); MainGraphics();
pthread_join(main_loop_t, NULL); pthread_join(main_loop_threat, NULL);
// Clean up the port // Clean up the port
if (offline == 0) {
uart_close(sp); uart_close(sp);
}
// clean up mutex // clean up mutex
pthread_mutex_destroy(&print_lock); pthread_mutex_destroy(&print_lock);
return 0; exit(0);
} }