]> cvs.zerfleddert.de Git - proxmark3-svn/blame - client/cmdparser.c
/client/Makefile: Output object files to the obj subdir.
[proxmark3-svn] / client / cmdparser.c
CommitLineData
7fe9b0b7 1#include <stdio.h>
2#include <string.h>
3#include "ui.h"
4#include "cmdparser.h"
5
6void 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
19void 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;
5d5311a2 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++) {
83819845 35 if( !strncmp(Commands[i].Name, cmd_name, strlen(cmd_name)) ) {
36 last_match = i;
37 matches++;
38 }
5d5311a2 39 }
40 if(matches == 1) i=last_match;
41 }
42
7fe9b0b7 43 if (Commands[i].Name)
44 Commands[i].Parse(Cmd + len);
45 else
c37d2e70 46 // show help (always first in array) for selected hierarchy or if command not recognised
040a7baa 47 CmdsHelp(Commands);
7fe9b0b7 48}
Impressum, Datenschutz