]> git.zerfleddert.de Git - proxmark3-svn/blame - client/cliparser/cliparser.h
Merge pull request #969 from pwpiwi/gcc10_fixes
[proxmark3-svn] / client / cliparser / cliparser.h
CommitLineData
6e3d8d67
OM
1//-----------------------------------------------------------------------------
2// Copyright (C) 2017 Merlok
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 line parser core commands
9//-----------------------------------------------------------------------------
10
11#include "argtable3.h"
12#include "util.h"
13#include <stdbool.h>
14
15#define arg_param_begin arg_lit0("hH", "help", "print this help and exit")
16#define arg_param_end arg_end(20)
17
18#define arg_getsize(a) (sizeof(a) / sizeof(a[0]))
19#define arg_get_lit(n)(((struct arg_lit*)argtable[n])->count)
ae3340a0 20#define arg_get_int_count(n)(((struct arg_int*)argtable[n])->count)
6e3d8d67 21#define arg_get_int(n)(((struct arg_int*)argtable[n])->ival[0])
c8a0f550 22#define arg_get_int_def(n,def)(arg_get_int_count(n)?(arg_get_int(n)):(def))
6e3d8d67 23#define arg_get_str(n)((struct arg_str*)argtable[n])
f23565c3 24#define arg_get_str_len(n)(strlen(((struct arg_str*)argtable[n])->sval[0]))
6e3d8d67 25
11146fc1
OM
26#define arg_strx1(shortopts, longopts, datatype, glossary) (arg_strn((shortopts), (longopts), (datatype), 1, 250, (glossary)))
27#define arg_strx0(shortopts, longopts, datatype, glossary) (arg_strn((shortopts), (longopts), (datatype), 0, 250, (glossary)))
28
6e3d8d67 29#define CLIExecWithReturn(cmd, atbl, ifempty) if (CLIParserParseString(cmd, atbl, arg_getsize(atbl), ifempty)){CLIParserFree();return 0;}
95b697f0
OM
30#define CLIGetHexBLessWithReturn(paramnum, data, datalen, delta) if (CLIParamHexToBuf(arg_get_str(paramnum), data, sizeof(data) - (delta), datalen)) {CLIParserFree();return 1;}
31#define CLIGetHexWithReturn(paramnum, data, datalen) if (CLIParamHexToBuf(arg_get_str(paramnum), data, sizeof(data), datalen)) {CLIParserFree();return 1;}
32#define CLIGetStrWithReturn(paramnum, data, datalen) if (CLIParamStrToBuf(arg_get_str(paramnum), data, sizeof(data), datalen)) {CLIParserFree();return 1;}
6e3d8d67
OM
33
34extern int CLIParserInit(char *vprogramName, char *vprogramHint, char *vprogramHelp);
35extern int CLIParserParseString(const char* str, void* argtable[], size_t vargtableLen, bool allowEmptyExec);
11146fc1 36extern int CLIParserParseStringEx(const char* str, void* vargtable[], size_t vargtableLen, bool allowEmptyExec, bool clueData);
6e3d8d67
OM
37extern int CLIParserParseArg(int argc, char **argv, void* argtable[], size_t vargtableLen, bool allowEmptyExec);
38extern void CLIParserFree();
39
40extern int CLIParamHexToBuf(struct arg_str *argstr, uint8_t *data, int maxdatalen, int *datalen);
95b697f0 41extern int CLIParamStrToBuf(struct arg_str *argstr, uint8_t *data, int maxdatalen, int *datalen);
Impressum, Datenschutz