]> git.zerfleddert.de Git - proxmark3-svn/commitdiff
Fixes to implement generation of markdown auto-generated documentation
authorMartin Holst Swende <martin.holst@gmail.com>
Wed, 26 Mar 2014 21:35:25 +0000 (22:35 +0100)
committerPhilippe Teuwen <phil@teuwen.org>
Wed, 26 Mar 2014 21:39:37 +0000 (22:39 +0100)
client/cmddata.c
client/cmddata.h
client/cmdlf.c
client/cmdmain.c
client/cmdmain.h
client/cmdparser.c
client/cmdparser.h
client/proxmark3.c

index 265b0ed740414696b531a5fcec76044c45c39865..a7b8048098e290e2a198a47e20237f8d8e74a51d 100644 (file)
@@ -851,7 +851,7 @@ static command_t CommandTable[] =
 {
   {"help",          CmdHelp,            1, "This help"},
   {"amp",           CmdAmp,             1, "Amplify peaks"},
-  {"askdemod",      Cmdaskdemod,        1, "<0|1> -- Attempt to demodulate simple ASK tags"},
+  {"askdemod",      Cmdaskdemod,        1, "<0 or 1> -- Attempt to demodulate simple ASK tags"},
   {"autocorr",      CmdAutoCorr,        1, "<window length> -- Autocorrelation over window"},
   {"bitsamples",    CmdBitsamples,      0, "Get raw samples as bitstring"},
   {"bitstream",     CmdBitstream,       1, "[clock rate] -- Convert waveform into a bitstream"},
index 06ea18cc6fa3ea787957ebabd4c4148bd5d07116..2f86a94176bb49a014fa3cbd72149d77cf189a34 100644 (file)
@@ -11,6 +11,8 @@
 #ifndef CMDDATA_H__
 #define CMDDATA_H__
 
+command_t * CmdDataCommands();
+
 int CmdData(const char *Cmd);
 
 int CmdAmp(const char *Cmd);
index 4e10b8f6298d5edd533982d6184263fe4b27d23c..387e60d58865ac279a90083833ac9be46f053104 100644 (file)
@@ -536,7 +536,7 @@ static command_t CommandTable[] =
   {"io",         CmdLFIO,            1, "{ ioProx tags... }"},
   {"indalademod", CmdIndalaDemod,     1, "['224'] -- Demodulate samples for Indala 64 bit UID (option '224' for 224 bit)"},
   {"indalaclone", CmdIndalaClone,     1, "<UID> ['l']-- Clone Indala to T55x7 (tag must be in antenna)(UID in HEX)(option 'l' for 224 UID"},
-  {"read",        CmdLFRead,          0, "['h'|<divisor>] -- Read 125/134 kHz LF ID-only tag (option 'h' for 134, alternatively: f=12MHz/(divisor+1))"},
+  {"read",        CmdLFRead,          0, "['h' or <divisor>] -- Read 125/134 kHz LF ID-only tag (option 'h' for 134, alternatively: f=12MHz/(divisor+1))"},
   {"sim",         CmdLFSim,           0, "[GAP] -- Simulate LF tag from buffer with optional GAP (in microseconds)"},
   {"simbidir",    CmdLFSimBidir,      0, "Simulate LF tag (with bidirectional data transmission between reader and tag)"},
   {"simman",      CmdLFSimManchester, 0, "<Clock> <Bitstream> [GAP] Simulate arbitrary Manchester LF tag"},
index 59ab8bf5f81d3151cfc36956dd273c9922b57b48..fa358fac8b2211b0ae27eb1e32a746830303807b 100644 (file)
@@ -45,17 +45,21 @@ static int cmd_tail;//Starts as 0
 
 static command_t CommandTable[] = 
 {
-  {"help",  CmdHelp,  1, "This help. Use '<command> help' for details of the following commands:\n"},
+  {"help",  CmdHelp,  1, "This help. Use '<command> help' for details of a particular command."},
   {"data",  CmdData,  1, "{ Plot window / data buffer manipulation... }"},
-  {"exit",  CmdQuit,  1, "Exit program"},
   {"hf",    CmdHF,    1, "{ HF commands... }"},
   {"hw",    CmdHW,    1, "{ Hardware commands... }"},
   {"lf",    CmdLF,    1, "{ LF commands... }"},
-  {"quit",  CmdQuit,  1, "Quit program"},
-  {"script", CmdScript,   1,"Run script"},
+  {"script", CmdScript,   1,"{ Scripting commands }"},
+  {"quit",  CmdQuit,  1, "Exit program"},
+  {"exit",  CmdQuit,  1, "Exit program"},
   {NULL, NULL, 0, NULL}
 };
 
+command_t* getTopLevelCommandTable()
+{
+  return CommandTable;
+}
 int CmdHelp(const char *Cmd)
 {
   CmdsHelp(CommandTable);
index ce4130bb5097d83c9cebc5776ebb2e5329312f47..0cf2b35d436e5656d2aaf11c087f4ecc791e5c86 100644 (file)
 #define CMDMAIN_H__
 
 #include "usb_cmd.h"
-
+#include "cmdparser.h"
 void UsbCommandReceived(UsbCommand *UC);
 void CommandReceived(char *Cmd);
 bool WaitForResponseTimeout(uint32_t cmd, UsbCommand* response, size_t ms_timeout);
 bool WaitForResponse(uint32_t cmd, UsbCommand* response);
 void clearCommandBuffer();
+command_t* getTopLevelCommandTable();
 #endif
index 48d044d591e1583f5da7f3c932006b6f627aad5c..c971092b2363256d69e3655788c25799c6cfde22 100644 (file)
@@ -9,6 +9,7 @@
 //-----------------------------------------------------------------------------
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include "ui.h"
 #include "cmdparser.h"
@@ -21,16 +22,26 @@ void CmdsHelp(const command_t Commands[])
   int i = 0;
   while (Commands[i].Name)
   {
-    if (offline == 0 || Commands[i].Offline)
-      PrintAndLog("%-16s %s", Commands[i].Name, Commands[i].Help);
-    if (offline == 2 && !Commands[i].Offline)
-      PrintAndLog("%-14s @ %s", Commands[i].Name, Commands[i].Help);
+      if(Commands[i].Offline)
+      {
+        PrintAndLog("%-16s  \t%s", Commands[i].Name, Commands[i].Help);
+      }else
+      {
+        PrintAndLog("%-16s @\t%s", Commands[i].Name, Commands[i].Help);
+      }
     ++i;
   }
 }
 
 void CmdsParse(const command_t Commands[], const char *Cmd)
 {
+  if(strcmp( Cmd, "XX_internal_command_dump_XX") == 0)
+  {// Markdown dump children
+      dumpCommandsRecursive(Commands);
+      return;
+  }
+
+
   char cmd_name[32];
   int len = 0;
   memset(cmd_name, 0, 32);
@@ -62,3 +73,53 @@ void CmdsParse(const command_t Commands[], const char *Cmd)
     CmdsHelp(Commands);
   }
 }
+//static int tablevel = 0;
+
+char pparent[512] = {0};
+char *parent = pparent;
+
+void dumpCommandsRecursive(const command_t cmds[])
+{
+   if (cmds[0].Name == NULL)
+    return;
+
+  int i = 0;
+  char* tabulation = "###";
+  char* offline = "N";
+  // First, dump all single commands, which are not a container for 
+  // other commands
+  printf("command|offline|description\n");
+  printf("-------|-------|-----------\n");
+
+  while (cmds[i].Name)
+  {
+    if(cmds[i].Help[0] == '{' && ++i) continue;
+
+    if ( cmds[i].Offline) offline = "Y";
+    printf("|`%s%s`|%s|`%s`|\n", parent, cmds[i].Name,offline, cmds[i].Help);
+    ++i;
+  }
+  printf("\n\n");
+  i=0;
+  // Then, print the categories. These will go into subsections with their own tables
+
+  while (cmds[i].Name)
+  {
+    if(cmds[i].Help[0] != '{' && ++i)  continue;
+
+    printf("%s %s%s\n\n %s\n\n", tabulation, parent, cmds[i].Name, cmds[i].Help);        
+
+    char currentparent[512] = {0};
+    snprintf(currentparent, sizeof currentparent, "%s%s ", parent, cmds[i].Name);
+    char *old_parent = parent;
+    parent = currentparent;
+//    tablevel++;
+    // This is what causes the recursion, since commands Parse-implementation
+    // in turn calls the CmdsParse above. 
+    cmds[i].Parse("XX_internal_command_dump_XX");
+//    tablevel--;
+    parent = old_parent;
+    ++i;
+  }
+
+}
index 28c2e66ef6390c840c342a6c45975dbde1b49fc5..94aad884ca58a8cb507b45752b3cd1e34548616c 100644 (file)
@@ -25,5 +25,6 @@ typedef struct command_s
 void CmdsHelp(const command_t Commands[]);
 // Parse a command line
 void CmdsParse(const command_t Commands[], const char *Cmd);
+void dumpCommandsRecursive(const command_t cmds[]);
 
 #endif
index e40b4defe38d7dee1d3b4d48a4c1b3ae6360b615..3c7e64516d915c8a0864664a14af03d8ff75ce1e 100644 (file)
@@ -23,6 +23,8 @@
 #include "uart.h"
 #include "ui.h"
 #include "sleep.h"
+#include "cmdparser.h"
+#include "cmdmain.h"
 
 // a global mutex to prevent interlaced printing from different threads
 pthread_mutex_t print_lock;
@@ -31,7 +33,6 @@ static serial_port sp;
 static UsbCommand txcmd;
 volatile static bool txcmd_pending = false;
 
-
 void SendCommand(UsbCommand *c) {
 #if 0
   printf("Sending %d bytes\n", sizeof(UsbCommand));
@@ -206,39 +207,25 @@ static void *main_loop(void *targ) {
   return NULL;
 }
 
-#define DUMPHELP(cmd) \
-  do { \
-    printf("%s\n", cmd); \
-    printf("---------------------------------------------\n"); \
-    CommandReceived(cmd); \
-    printf("\n"); \
-  } while (0)
+//static void dumpHelp(char  *parent, ...)
+//{
+//  printf("## %s\n\n", parent);
+//  CommandReceived(parent);
+//  
+//  printf("\n");
+//}
 
-static void dumphelp()
+static void dumpAllHelp()
 {
-  offline=2;
-  printf("\n------------PROXMARK3 HELP DUMP--------------\n");
+  offline=3;
+  printf("\n# Proxmark3 command dump\n\n");
   printf("Some commands are available only if a Proxmark is actually connected,\n");
   printf("Those commands are flagged with \"@\" in front of their description.\n");
   printf("\n");
-  DUMPHELP("help");
-  DUMPHELP("data help");
-  DUMPHELP("hf help");
-  DUMPHELP("hf 14a help");
-  DUMPHELP("hf 14b help");
-  DUMPHELP("hf 15 help");
-  DUMPHELP("hf epa help");
-  DUMPHELP("hf legic help");
-  DUMPHELP("hf iclass help");
-  DUMPHELP("hf mf help");
-  DUMPHELP("hw help");
-  DUMPHELP("lf help");
-  DUMPHELP("lf em4x help");
-  DUMPHELP("lf hid help");
-  DUMPHELP("lf ti help");
-  DUMPHELP("lf hitag help");
-  DUMPHELP("lf pcf7931 help");
-  DUMPHELP("lf t55xx help");
+  command_t *cmds = getTopLevelCommandTable();
+
+  dumpCommandsRecursive(cmds);
+
 }
 
 int main(int argc, char* argv[]) {
@@ -247,18 +234,17 @@ int main(int argc, char* argv[]) {
        if (argc < 2) {
                printf("syntax: %s <port>\n\n",argv[0]);
                printf("\tLinux example:'%s /dev/ttyACM0'\n\n", argv[0]);
-               printf("help:   %s -h\n\n", argv[0]);
-               printf("\tDump all interactive help at once\n");
+    printf("help:   %s -h\n\n", argv[0]);
+    printf("\tDump all interactive help at once\n");
                return 1;
        }
   
-       if (strcmp(argv[1], "-h") == 0) {
-               printf("syntax: %s <port>\n\n",argv[0]);
-               printf("\tLinux example:'%s /dev/ttyACM0'\n\n", argv[0]);
-               offline = 2;
-               dumphelp();
-               return 0;
-       }
+  if (strcmp(argv[1], "-h") == 0) {
+    printf("syntax: %s <port>\n\n",argv[0]);
+    printf("\tLinux example:'%s /dev/ttyACM0'\n\n", argv[0]);
+    dumpAllHelp();
+    return 0;
+  }  
        // Make sure to initialize
        struct main_loop_arg marg = {
                .usb_present = 0,
Impressum, Datenschutz