]>
git.zerfleddert.de Git - proxmark3-svn/blob - client/cmdparser.c
3820de1769852ba5350998d8a277acee62246db3
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
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
7 //-----------------------------------------------------------------------------
9 //-----------------------------------------------------------------------------
15 #include "cmdparser.h"
16 #include "proxmark3.h"
18 void CmdsHelp(const command_t Commands
[])
20 if (Commands
[0].Name
== NULL
)
23 while (Commands
[i
].Name
)
25 if(Commands
[i
].Offline
)
27 PrintAndLog("%-16s \t%s", Commands
[i
].Name
, Commands
[i
].Help
);
30 PrintAndLog("%-16s @\t%s", Commands
[i
].Name
, Commands
[i
].Help
);
36 void CmdsParse(const command_t Commands
[], const char *Cmd
)
38 if(strcmp( Cmd
, "XX_internal_command_dump_XX") == 0)
39 {// Help dump children
40 dumpCommandsRecursive(Commands
, 0);
43 if(strcmp( Cmd
, "XX_internal_command_dump_markdown_XX") == 0)
44 {// Markdown help dump children
45 dumpCommandsRecursive(Commands
, 1);
50 memset(cmd_name
, 0, 32);
51 sscanf(Cmd
, "%31s%n", cmd_name
, &len
);
53 while (Commands
[i
].Name
&& strcmp(Commands
[i
].Name
, cmd_name
))
56 /* try to find exactly one prefix-match */
57 if(!Commands
[i
].Name
) {
61 for(i
=0;Commands
[i
].Name
;i
++) {
62 if( !strncmp(Commands
[i
].Name
, cmd_name
, strlen(cmd_name
)) ) {
67 if(matches
== 1) i
=last_match
;
70 if (Commands
[i
].Name
) {
71 while (Cmd
[len
] == ' ')
73 Commands
[i
].Parse(Cmd
+ len
);
75 // show help for selected hierarchy or if command not recognised
80 char pparent
[512] = {0};
81 char *parent
= pparent
;
83 void dumpCommandsRecursive(const command_t cmds
[], int markdown
)
85 if (cmds
[0].Name
== NULL
)
91 // First, dump all single commands, which are not a container for
94 printf("command|offline|description\n");
95 printf("-------|-------|-----------\n");
97 printf("%-*s|%-*s|%s\n",w_cmd
,"command",w_off
,"offline","description");
98 printf("%-*s|%-*s|%s\n",w_cmd
,"-------",w_off
,"-------","-----------");
103 char* cmd_offline
= "N";
104 if(cmds
[i
].Help
[0] == '{' && ++i
) continue;
106 if ( cmds
[i
].Offline
) cmd_offline
= "Y";
108 printf("|`%s%s`|%s|`%s`|\n", parent
, cmds
[i
].Name
,cmd_offline
, cmds
[i
].Help
);
110 printf("%s%-*s|%-*s|%s\n", parent
, w_cmd
-(int)strlen(parent
), cmds
[i
].Name
, w_off
, cmd_offline
, cmds
[i
].Help
);
115 // Then, print the categories. These will go into subsections with their own tables
119 if(cmds
[i
].Help
[0] != '{' && ++i
) continue;
121 printf("### %s%s\n\n %s\n\n", parent
, cmds
[i
].Name
, cmds
[i
].Help
);
123 char currentparent
[512] = {0};
124 snprintf(currentparent
, sizeof currentparent
, "%s%s ", parent
, cmds
[i
].Name
);
125 char *old_parent
= parent
;
126 parent
= currentparent
;
127 // This is what causes the recursion, since commands Parse-implementation
128 // in turn calls the CmdsParse above.
130 cmds
[i
].Parse("XX_internal_command_dump_markdown_XX");
132 cmds
[i
].Parse("XX_internal_command_dump_XX");