]> git.zerfleddert.de Git - proxmark3-svn/blame - client/cmdparser.c
Add option -h to dump complete set of supported commands
[proxmark3-svn] / client / cmdparser.c
CommitLineData
a553f267 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
7fe9b0b7 11#include <stdio.h>
12#include <string.h>
13#include "ui.h"
14#include "cmdparser.h"
902cb3c0 15#include "proxmark3.h"
7fe9b0b7 16
17void CmdsHelp(const command_t Commands[])
18{
19 if (Commands[0].Name == NULL)
20 return;
21 int i = 0;
22 while (Commands[i].Name)
23 {
ae7aa73d 24 if (offline == 0 || Commands[i].Offline)
7fe9b0b7 25 PrintAndLog("%-16s %s", Commands[i].Name, Commands[i].Help);
ae7aa73d
PT
26 if (offline == 2 && !Commands[i].Offline)
27 PrintAndLog("%-14s @ %s", Commands[i].Name, Commands[i].Help);
7fe9b0b7 28 ++i;
29 }
30}
31
9cb00f30 32void CmdsParse(const command_t Commands[], const char *Cmd)
7fe9b0b7 33{
34 char cmd_name[32];
35 int len = 0;
36 memset(cmd_name, 0, 32);
37 sscanf(Cmd, "%31s%n", cmd_name, &len);
38 int i = 0;
39 while (Commands[i].Name && strcmp(Commands[i].Name, cmd_name))
40 ++i;
5d5311a2 41
42 /* try to find exactly one prefix-match */
43 if(!Commands[i].Name) {
44 int last_match = 0;
45 int matches = 0;
46
47 for(i=0;Commands[i].Name;i++) {
83819845 48 if( !strncmp(Commands[i].Name, cmd_name, strlen(cmd_name)) ) {
49 last_match = i;
50 matches++;
51 }
5d5311a2 52 }
53 if(matches == 1) i=last_match;
54 }
55
035303ac 56 if (Commands[i].Name) {
57 while (Cmd[len] == ' ')
58 ++len;
7fe9b0b7 59 Commands[i].Parse(Cmd + len);
035303ac 60 } else {
fcdfc43e 61 // show help for selected hierarchy or if command not recognised
040a7baa 62 CmdsHelp(Commands);
035303ac 63 }
7fe9b0b7 64}
Impressum, Datenschutz