]> git.zerfleddert.de Git - proxmark3-svn/commitdiff
fix: .history was never written
authorpwpiwi <pwpiwi@users.noreply.github.com>
Fri, 6 Nov 2015 10:34:43 +0000 (11:34 +0100)
committerpwpiwi <pwpiwi@users.noreply.github.com>
Fri, 6 Nov 2015 10:34:43 +0000 (11:34 +0100)
.gitignore
client/cmdmain.c
client/cmdmain.h
client/cmdparser.c
client/cmdparser.h
client/proxmark3.c

index 880c092f175fb82959cf11fba62da1985c758a07..fa74326ed6f9297683b6124cb138becaa61bc94f 100644 (file)
@@ -1,6 +1,7 @@
 # .gitignore
 # don't push these files to the repository
 
 # .gitignore
 # don't push these files to the repository
 
+.history
 *.log
 *.eml
 *.o
 *.log
 *.eml
 *.o
index deced5585c6dc343ebe2d74a8e7f6e6068ba25c1..7bba80f4cbe784967689f6e06858ee3f3d5d36fe 100644 (file)
@@ -42,15 +42,15 @@ static int cmd_tail;//Starts as 0
 
 static command_t CommandTable[] = 
 {
 
 static command_t CommandTable[] = 
 {
-  {"help",  CmdHelp,  1, "This help. Use '<command> help' for details of a particular command."},
-  {"data",  CmdData,  1, "{ Plot window / data buffer manipulation... }"},
-  {"hf",       CmdHF,          1, "{ High Frequency commands... }"},
-  {"hw",    CmdHW,    1, "{ Hardware commands... }"},
-  {"lf",       CmdLF,          1, "{ Low Frequency commands... }"},
-  {"script", CmdScript,   1,"{ Scripting commands }"},
-  {"quit",  CmdQuit,  1, "Exit program"},
-  {"exit",  CmdQuit,  1, "Exit program"},
-  {NULL, NULL, 0, NULL}
+       {"help",        CmdHelp,        1, "This help. Use '<command> help' for details of a particular command."},
+       {"data",        CmdData,        1, "{ Plot window / data buffer manipulation... }"},
+       {"hf",          CmdHF,          1, "{ High Frequency commands... }"},
+       {"hw",          CmdHW,          1, "{ Hardware commands... }"},
+       {"lf",          CmdLF,          1, "{ Low Frequency commands... }"},
+       {"script",      CmdScript,      1, "{ Scripting commands }"},
+       {"quit",        CmdQuit,        1, "Exit program"},
+       {"exit",        CmdQuit,        1, "Exit program"},
+       {NULL, NULL, 0, NULL}
 };
 
 command_t* getTopLevelCommandTable()
 };
 
 command_t* getTopLevelCommandTable()
@@ -65,8 +65,7 @@ int CmdHelp(const char *Cmd)
 
 int CmdQuit(const char *Cmd)
 {
 
 int CmdQuit(const char *Cmd)
 {
-  exit(0);
-  return 0;
+  return 99;
 }
 /**
  * @brief This method should be called when sending a new command to the pm3. In case any old
 }
 /**
  * @brief This method should be called when sending a new command to the pm3. In case any old
@@ -164,8 +163,8 @@ bool WaitForResponse(uint32_t cmd, UsbCommand* response) {
 // Entry point into our code: called whenever the user types a command and
 // then presses Enter, which the full command line that they typed.
 //-----------------------------------------------------------------------------
 // Entry point into our code: called whenever the user types a command and
 // then presses Enter, which the full command line that they typed.
 //-----------------------------------------------------------------------------
-void CommandReceived(char *Cmd) {
-  CmdsParse(CommandTable, Cmd);
+int CommandReceived(char *Cmd) {
+       return CmdsParse(CommandTable, Cmd);
 }
 
 
 }
 
 
index 0cf2b35d436e5656d2aaf11c087f4ecc791e5c86..500320ee4fd474ab486dd3429e57868f77adcdb1 100644 (file)
@@ -14,7 +14,7 @@
 #include "usb_cmd.h"
 #include "cmdparser.h"
 void UsbCommandReceived(UsbCommand *UC);
 #include "usb_cmd.h"
 #include "cmdparser.h"
 void UsbCommandReceived(UsbCommand *UC);
-void CommandReceived(char *Cmd);
+int CommandReceived(char *Cmd);
 bool WaitForResponseTimeout(uint32_t cmd, UsbCommand* response, size_t ms_timeout);
 bool WaitForResponse(uint32_t cmd, UsbCommand* response);
 void clearCommandBuffer();
 bool WaitForResponseTimeout(uint32_t cmd, UsbCommand* response, size_t ms_timeout);
 bool WaitForResponse(uint32_t cmd, UsbCommand* response);
 void clearCommandBuffer();
index 6910e86a535b7fd8154a9e1a94acfa4cc5583650..3250899795d92fd47c1b0af1ebcebb7644cc43fd 100644 (file)
@@ -15,6 +15,7 @@
 #include "cmdparser.h"
 #include "proxmark3.h"
 
 #include "cmdparser.h"
 #include "proxmark3.h"
 
+
 void CmdsHelp(const command_t Commands[])
 {
   if (Commands[0].Name == NULL)
 void CmdsHelp(const command_t Commands[])
 {
   if (Commands[0].Name == NULL)
@@ -28,48 +29,51 @@ void CmdsHelp(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)
-  {// Help dump children
-      dumpCommandsRecursive(Commands, 0);
-      return;
-  }
-  if(strcmp( Cmd, "XX_internal_command_dump_markdown_XX") == 0)
-  {// Markdown help dump children
-      dumpCommandsRecursive(Commands, 1);
-      return;
-  }
-  char cmd_name[32];
-  int len = 0;
-  memset(cmd_name, 0, 32);
-  sscanf(Cmd, "%31s%n", cmd_name, &len);
-  int i = 0;
-  while (Commands[i].Name && strcmp(Commands[i].Name, cmd_name))
-    ++i;
+       if(strcmp( Cmd, "XX_internal_command_dump_XX") == 0)
+       {// Help dump children
+               dumpCommandsRecursive(Commands, 0);
+               return 0;
+       }
+       if(strcmp( Cmd, "XX_internal_command_dump_markdown_XX") == 0)
+       {// Markdown help dump children
+               dumpCommandsRecursive(Commands, 1);
+               return 0;
+       }
+       char cmd_name[32];
+       int len = 0;
+       memset(cmd_name, 0, 32);
+       sscanf(Cmd, "%31s%n", cmd_name, &len);
+       int i = 0;
+       while (Commands[i].Name && strcmp(Commands[i].Name, cmd_name))
+               ++i;
 
 
-  /* try to find exactly one prefix-match */
-  if(!Commands[i].Name) {
-    int last_match = 0;
-    int matches = 0;
-
-    for(i=0;Commands[i].Name;i++) {
-      if( !strncmp(Commands[i].Name, cmd_name, strlen(cmd_name)) ) {
-        last_match = i;
-        matches++;
-      }
-    }
-    if(matches == 1) i=last_match;
-  }
+       /* try to find exactly one prefix-match */
+       if(!Commands[i].Name) {
+               int last_match = 0;
+               int matches = 0;
 
 
-  if (Commands[i].Name) {
-    while (Cmd[len] == ' ')
-      ++len;
-    Commands[i].Parse(Cmd + len);
-  } else {
-    // show help for selected hierarchy or if command not recognised
-    CmdsHelp(Commands);
-  }
+               for(i=0;Commands[i].Name;i++) {
+                       if( !strncmp(Commands[i].Name, cmd_name, strlen(cmd_name)) ) {
+                               last_match = i;
+                               matches++;
+                       }
+               }
+               if(matches == 1) i=last_match;
+       }
+
+       if (Commands[i].Name) {
+               while (Cmd[len] == ' ')
+                       ++len;
+       return Commands[i].Parse(Cmd + len);
+       } else {
+               // show help for selected hierarchy or if command not recognised
+               CmdsHelp(Commands);
+       }
+
+       return 0;
 }
 
 char pparent[512] = {0};
 }
 
 char pparent[512] = {0};
index b7997eccec61e14fa3a285b50574b1bd0887de57..5217d04b692282e87e810bfbf82b218eb06d3042 100644 (file)
@@ -24,7 +24,7 @@ typedef struct command_s
 // Print help for each command in the command array
 void CmdsHelp(const command_t Commands[]);
 // Parse a command line
 // Print help for each command in the command array
 void CmdsHelp(const command_t Commands[]);
 // 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);
 
 #endif
 void dumpCommandsRecursive(const command_t cmds[], int markdown);
 
 #endif
index 2f370308f9cb4bcb3a1d09bcd89fe414161efe6f..f184d9e995e3f7078d75812aa6d907609dbb1597 100644 (file)
@@ -155,12 +155,11 @@ static void *main_loop(void *targ) {
                                cmd[strlen(cmd) - 1] = 0x00;
                        
                        if (cmd[0] != 0x00) {
                                cmd[strlen(cmd) - 1] = 0x00;
                        
                        if (cmd[0] != 0x00) {
-                               if (strncmp(cmd, "quit", 4) == 0) {
-                                       exit(0);
+                               int ret = CommandReceived(cmd);
+                               add_history(cmd);
+                               if (ret == 99) {  // exit or quit
                                        break;
                                }
                                        break;
                                }
-                               CommandReceived(cmd);
-                               add_history(cmd);
                        }
                        free(cmd);
                } else {
                        }
                        free(cmd);
                } else {
@@ -223,7 +222,7 @@ int main(int argc, char* argv[]) {
                .usb_present = 0,
                .script_cmds_file = NULL
        };
                .usb_present = 0,
                .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
        pthread_mutex_init(&print_lock, NULL);
 
        // create a mutex to avoid interlacing print commands from our different threads
        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);
 
        MainGraphics();
 
        InitGraphics(argc, argv);
 
        MainGraphics();
 
-       pthread_join(main_loop_t, NULL);
+       pthread_join(main_loop_threat, NULL);
 
        // Clean up the port
 
        // Clean up the port
-       uart_close(sp);
-  
+       if (offline == 0) {
+               uart_close(sp);
+       }
+
        // clean up mutex
        pthread_mutex_destroy(&print_lock);
        // clean up mutex
        pthread_mutex_destroy(&print_lock);
-  
-  return 0;
+
+       exit(0);
 }
 }
Impressum, Datenschutz