]> git.zerfleddert.de Git - proxmark3-svn/blob - client/cmdparser.c
Improvements/Fixes to 14443 sniffing/snooping
[proxmark3-svn] / client / cmdparser.c
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
3 //
4 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
5 // at your option, any later version. See the LICENSE.txt file for the text of
6 // the license.
7 //-----------------------------------------------------------------------------
8 // Command parser
9 //-----------------------------------------------------------------------------
10
11 #include <stdio.h>
12 #include <string.h>
13 #include "ui.h"
14 #include "cmdparser.h"
15 #include "proxmark3.h"
16
17 void CmdsHelp(const command_t Commands[])
18 {
19 if (Commands[0].Name == NULL)
20 return;
21 int i = 0;
22 while (Commands[i].Name)
23 {
24 if (!offline || Commands[i].Offline)
25 PrintAndLog("%-16s %s", Commands[i].Name, Commands[i].Help);
26 ++i;
27 }
28 }
29
30 void CmdsParse(const command_t Commands[], const char *Cmd)
31 {
32 char cmd_name[32];
33 int len = 0;
34 memset(cmd_name, 0, 32);
35 sscanf(Cmd, "%31s%n", cmd_name, &len);
36 int i = 0;
37 while (Commands[i].Name && strcmp(Commands[i].Name, cmd_name))
38 ++i;
39
40 /* try to find exactly one prefix-match */
41 if(!Commands[i].Name) {
42 int last_match = 0;
43 int matches = 0;
44
45 for(i=0;Commands[i].Name;i++) {
46 if( !strncmp(Commands[i].Name, cmd_name, strlen(cmd_name)) ) {
47 last_match = i;
48 matches++;
49 }
50 }
51 if(matches == 1) i=last_match;
52 }
53
54 if (Commands[i].Name) {
55 while (Cmd[len] == ' ')
56 ++len;
57 Commands[i].Parse(Cmd + len);
58 } else {
59 // show help for selected hierarchy or if command not recognised
60 CmdsHelp(Commands);
61 }
62 }
Impressum, Datenschutz