]> cvs.zerfleddert.de Git - proxmark3-svn/blob - client/cmdparser.c
command parser shortcuts e.g. 'd p' will call 'data plot' (from rumpeltux)
[proxmark3-svn] / client / cmdparser.c
1 #include <stdio.h>
2 #include <string.h>
3 #include "ui.h"
4 #include "cmdparser.h"
5
6 void CmdsHelp(const command_t Commands[])
7 {
8 if (Commands[0].Name == NULL)
9 return;
10 int i = 0;
11 while (Commands[i].Name)
12 {
13 if (!offline || Commands[i].Offline)
14 PrintAndLog("%-16s %s", Commands[i].Name, Commands[i].Help);
15 ++i;
16 }
17 }
18
19 void CmdsParse(const command_t Commands[], const char *Cmd)
20 {
21 char cmd_name[32];
22 int len = 0;
23 memset(cmd_name, 0, 32);
24 sscanf(Cmd, "%31s%n", cmd_name, &len);
25 int i = 0;
26 while (Commands[i].Name && strcmp(Commands[i].Name, cmd_name))
27 ++i;
28
29 /* try to find exactly one prefix-match */
30 if(!Commands[i].Name) {
31 int last_match = 0;
32 int matches = 0;
33
34 for(i=0;Commands[i].Name;i++) {
35 if( !strncmp(Commands[i].Name, cmd_name, strlen(cmd_name)) ) {
36 last_match = i;
37 matches++;
38 }
39 }
40 if(matches == 1) i=last_match;
41 }
42
43 if (Commands[i].Name)
44 Commands[i].Parse(Cmd + len);
45 else
46 // show help (always first in array) for selected hierarchy or if command not recognised
47 CmdsHelp(Commands);
48 }
Impressum, Datenschutz