2018-10-11 16:48:46 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Copyright (C) 2017 Merlok
|
|
|
|
//
|
|
|
|
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
|
|
|
// at your option, any later version. See the LICENSE.txt file for the text of
|
|
|
|
// the license.
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Command line parser core commands
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2019-04-11 07:16:25 +08:00
|
|
|
#ifndef __CLIPARSER_H
|
|
|
|
#define __CLIPARSER_H
|
2018-10-11 16:48:46 +08:00
|
|
|
#include "argtable3.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
#define arg_param_begin arg_lit0("hH", "help", "print this help and exit")
|
|
|
|
#define arg_param_end arg_end(20)
|
|
|
|
|
|
|
|
#define arg_getsize(a) (sizeof(a) / sizeof(a[0]))
|
|
|
|
#define arg_get_lit(n)(((struct arg_lit*)argtable[n])->count)
|
2018-10-24 23:18:05 +08:00
|
|
|
#define arg_get_int_count(n)(((struct arg_int*)argtable[n])->count)
|
2018-10-11 16:48:46 +08:00
|
|
|
#define arg_get_int(n)(((struct arg_int*)argtable[n])->ival[0])
|
2018-10-24 23:18:05 +08:00
|
|
|
#define arg_get_int_def(n,def)(arg_get_int_count(n)?(arg_get_int(n)):(def))
|
2018-10-11 16:48:46 +08:00
|
|
|
#define arg_get_str(n)((struct arg_str*)argtable[n])
|
|
|
|
#define arg_get_str_len(n)(strlen(((struct arg_str*)argtable[n])->sval[0]))
|
|
|
|
|
|
|
|
#define arg_strx1(shortopts, longopts, datatype, glossary) (arg_strn((shortopts), (longopts), (datatype), 1, 250, (glossary)))
|
|
|
|
#define arg_strx0(shortopts, longopts, datatype, glossary) (arg_strn((shortopts), (longopts), (datatype), 0, 250, (glossary)))
|
|
|
|
|
2019-05-27 21:15:53 +08:00
|
|
|
#define CLIExecWithReturn(cmd, atbl, ifempty) if (CLIParserParseString(cmd, atbl, arg_getsize(atbl), ifempty)){CLIParserFree();return PM3_ESOFT;}
|
|
|
|
#define CLIGetHexBLessWithReturn(paramnum, data, datalen, delta) if (CLIParamHexToBuf(arg_get_str(paramnum), data, sizeof(data) - (delta), datalen)) {CLIParserFree();return PM3_ESOFT;}
|
|
|
|
#define CLIGetHexWithReturn(paramnum, data, datalen) if (CLIParamHexToBuf(arg_get_str(paramnum), data, sizeof(data), datalen)) {CLIParserFree();return PM3_ESOFT;}
|
|
|
|
#define CLIGetStrWithReturn(paramnum, data, datalen) if (CLIParamStrToBuf(arg_get_str(paramnum), data, sizeof(data), datalen)) {CLIParserFree();return PM3_ESOFT;}
|
2018-10-11 16:48:46 +08:00
|
|
|
|
2019-04-10 16:21:42 +08:00
|
|
|
int CLIParserInit(const char *vprogramName, const char *vprogramHint, const char *vprogramHelp);
|
2019-04-07 03:46:00 +08:00
|
|
|
int CLIParserParseString(const char *str, void *vargtable[], size_t vargtableLen, bool allowEmptyExec);
|
2019-04-06 06:52:55 +08:00
|
|
|
int CLIParserParseStringEx(const char *str, void *vargtable[], size_t vargtableLen, bool allowEmptyExec, bool clueData);
|
2019-04-07 03:46:00 +08:00
|
|
|
int CLIParserParseArg(int argc, char **argv, void *vargtable[], size_t vargtableLen, bool allowEmptyExec);
|
2019-04-10 04:42:23 +08:00
|
|
|
void CLIParserFree(void);
|
2018-10-11 16:48:46 +08:00
|
|
|
|
2019-04-06 06:52:55 +08:00
|
|
|
int CLIParamHexToBuf(struct arg_str *argstr, uint8_t *data, int maxdatalen, int *datalen);
|
|
|
|
int CLIParamStrToBuf(struct arg_str *argstr, uint8_t *data, int maxdatalen, int *datalen);
|
2019-04-11 07:16:25 +08:00
|
|
|
#endif
|