mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-14 18:48:13 -07:00
client: fix mix of spaces & tabs
This commit is contained in:
parent
112411042f
commit
0d9223a547
197 changed files with 49383 additions and 49383 deletions
File diff suppressed because it is too large
Load diff
|
@ -20,186 +20,186 @@ char *programHelp = NULL;
|
|||
char buf[500] = {0};
|
||||
|
||||
int CLIParserInit(char *vprogramName, char *vprogramHint, char *vprogramHelp) {
|
||||
argtable = NULL;
|
||||
argtableLen = 0;
|
||||
programName = vprogramName;
|
||||
programHint = vprogramHint;
|
||||
programHelp = vprogramHelp;
|
||||
memset(buf, 0x00, 500);
|
||||
argtable = NULL;
|
||||
argtableLen = 0;
|
||||
programName = vprogramName;
|
||||
programHint = vprogramHint;
|
||||
programHelp = vprogramHelp;
|
||||
memset(buf, 0x00, 500);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CLIParserParseArg(int argc, char **argv, void* vargtable[], size_t vargtableLen, bool allowEmptyExec) {
|
||||
int nerrors;
|
||||
int nerrors;
|
||||
|
||||
argtable = vargtable;
|
||||
argtableLen = vargtableLen;
|
||||
argtable = vargtable;
|
||||
argtableLen = vargtableLen;
|
||||
|
||||
/* verify the argtable[] entries were allocated sucessfully */
|
||||
if (arg_nullcheck(argtable) != 0) {
|
||||
/* NULL entries were detected, some allocations must have failed */
|
||||
printf("ERROR: Insufficient memory\n");
|
||||
return 2;
|
||||
}
|
||||
/* Parse the command line as defined by argtable[] */
|
||||
nerrors = arg_parse(argc, argv, argtable);
|
||||
/* verify the argtable[] entries were allocated sucessfully */
|
||||
if (arg_nullcheck(argtable) != 0) {
|
||||
/* NULL entries were detected, some allocations must have failed */
|
||||
printf("ERROR: Insufficient memory\n");
|
||||
return 2;
|
||||
}
|
||||
/* Parse the command line as defined by argtable[] */
|
||||
nerrors = arg_parse(argc, argv, argtable);
|
||||
|
||||
/* special case: '--help' takes precedence over error reporting */
|
||||
if ((argc < 2 && !allowEmptyExec) ||((struct arg_lit *)argtable[0])->count > 0) { // help must be the first record
|
||||
printf("Usage: %s", programName);
|
||||
arg_print_syntaxv(stdout, argtable, "\n");
|
||||
if (programHint)
|
||||
printf("%s\n\n", programHint);
|
||||
arg_print_glossary(stdout, argtable, " %-20s %s\n");
|
||||
printf("\n");
|
||||
if (programHelp)
|
||||
printf("%s \n", programHelp);
|
||||
/* special case: '--help' takes precedence over error reporting */
|
||||
if ((argc < 2 && !allowEmptyExec) ||((struct arg_lit *)argtable[0])->count > 0) { // help must be the first record
|
||||
printf("Usage: %s", programName);
|
||||
arg_print_syntaxv(stdout, argtable, "\n");
|
||||
if (programHint)
|
||||
printf("%s\n\n", programHint);
|
||||
arg_print_glossary(stdout, argtable, " %-20s %s\n");
|
||||
printf("\n");
|
||||
if (programHelp)
|
||||
printf("%s \n", programHelp);
|
||||
|
||||
return 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* If the parser returned any errors then display them and exit */
|
||||
if (nerrors > 0) {
|
||||
/* Display the error details contained in the arg_end struct.*/
|
||||
arg_print_errors(stdout, ((struct arg_end *)argtable[vargtableLen - 1]), programName);
|
||||
printf("Try '%s --help' for more information.\n", programName);
|
||||
/* If the parser returned any errors then display them and exit */
|
||||
if (nerrors > 0) {
|
||||
/* Display the error details contained in the arg_end struct.*/
|
||||
arg_print_errors(stdout, ((struct arg_end *)argtable[vargtableLen - 1]), programName);
|
||||
printf("Try '%s --help' for more information.\n", programName);
|
||||
|
||||
return 3;
|
||||
}
|
||||
return 3;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
enum ParserState {
|
||||
PS_FIRST,
|
||||
PS_ARGUMENT,
|
||||
PS_OPTION,
|
||||
PS_FIRST,
|
||||
PS_ARGUMENT,
|
||||
PS_OPTION,
|
||||
};
|
||||
|
||||
#define isSpace(c)(c == ' ' || c == '\t')
|
||||
|
||||
int CLIParserParseString(const char* str, void* vargtable[], size_t vargtableLen, bool allowEmptyExec) {
|
||||
return CLIParserParseStringEx(str, vargtable, vargtableLen, allowEmptyExec, false);
|
||||
return CLIParserParseStringEx(str, vargtable, vargtableLen, allowEmptyExec, false);
|
||||
}
|
||||
|
||||
int CLIParserParseStringEx(const char* str, void* vargtable[], size_t vargtableLen, bool allowEmptyExec, bool clueData) {
|
||||
int argc = 0;
|
||||
char *argv[200] = {NULL};
|
||||
int argc = 0;
|
||||
char *argv[200] = {NULL};
|
||||
|
||||
int len = strlen(str);
|
||||
char *bufptr = buf;
|
||||
char *spaceptr = NULL;
|
||||
enum ParserState state = PS_FIRST;
|
||||
int len = strlen(str);
|
||||
char *bufptr = buf;
|
||||
char *spaceptr = NULL;
|
||||
enum ParserState state = PS_FIRST;
|
||||
|
||||
argv[argc++] = bufptr;
|
||||
// param0 = program name
|
||||
memcpy(buf, programName, strlen(programName) + 1); // with 0x00
|
||||
bufptr += strlen(programName) + 1;
|
||||
if (len)
|
||||
argv[argc++] = bufptr;
|
||||
argv[argc++] = bufptr;
|
||||
// param0 = program name
|
||||
memcpy(buf, programName, strlen(programName) + 1); // with 0x00
|
||||
bufptr += strlen(programName) + 1;
|
||||
if (len)
|
||||
argv[argc++] = bufptr;
|
||||
|
||||
// parse params
|
||||
for (int i = 0; i < len; i++) {
|
||||
switch(state){
|
||||
case PS_FIRST: // first char
|
||||
if (!clueData || str[i] == '-'){ // first char before space is '-' - next element - option OR not "clueData" for not-option fields
|
||||
state = PS_OPTION;
|
||||
// parse params
|
||||
for (int i = 0; i < len; i++) {
|
||||
switch(state){
|
||||
case PS_FIRST: // first char
|
||||
if (!clueData || str[i] == '-'){ // first char before space is '-' - next element - option OR not "clueData" for not-option fields
|
||||
state = PS_OPTION;
|
||||
|
||||
if (spaceptr) {
|
||||
bufptr = spaceptr;
|
||||
*bufptr = 0x00;
|
||||
bufptr++;
|
||||
argv[argc++] = bufptr;
|
||||
}
|
||||
}
|
||||
spaceptr = NULL;
|
||||
case PS_ARGUMENT:
|
||||
if (state == PS_FIRST)
|
||||
state = PS_ARGUMENT;
|
||||
if (isSpace(str[i])) {
|
||||
spaceptr = bufptr;
|
||||
state = PS_FIRST;
|
||||
}
|
||||
*bufptr = str[i];
|
||||
bufptr++;
|
||||
break;
|
||||
case PS_OPTION:
|
||||
if (isSpace(str[i])){
|
||||
state = PS_FIRST;
|
||||
if (spaceptr) {
|
||||
bufptr = spaceptr;
|
||||
*bufptr = 0x00;
|
||||
bufptr++;
|
||||
argv[argc++] = bufptr;
|
||||
}
|
||||
}
|
||||
spaceptr = NULL;
|
||||
case PS_ARGUMENT:
|
||||
if (state == PS_FIRST)
|
||||
state = PS_ARGUMENT;
|
||||
if (isSpace(str[i])) {
|
||||
spaceptr = bufptr;
|
||||
state = PS_FIRST;
|
||||
}
|
||||
*bufptr = str[i];
|
||||
bufptr++;
|
||||
break;
|
||||
case PS_OPTION:
|
||||
if (isSpace(str[i])){
|
||||
state = PS_FIRST;
|
||||
|
||||
*bufptr = 0x00;
|
||||
bufptr++;
|
||||
argv[argc++] = bufptr;
|
||||
break;
|
||||
}
|
||||
*bufptr = 0x00;
|
||||
bufptr++;
|
||||
argv[argc++] = bufptr;
|
||||
break;
|
||||
}
|
||||
|
||||
*bufptr = str[i];
|
||||
bufptr++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
*bufptr = str[i];
|
||||
bufptr++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return CLIParserParseArg(argc, argv, vargtable, vargtableLen, allowEmptyExec);
|
||||
return CLIParserParseArg(argc, argv, vargtable, vargtableLen, allowEmptyExec);
|
||||
}
|
||||
|
||||
void CLIParserFree() {
|
||||
arg_freetable(argtable, argtableLen);
|
||||
argtable = NULL;
|
||||
arg_freetable(argtable, argtableLen);
|
||||
argtable = NULL;
|
||||
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
// convertors
|
||||
int CLIParamHexToBuf(struct arg_str *argstr, uint8_t *data, int maxdatalen, int *datalen) {
|
||||
*datalen = 0;
|
||||
*datalen = 0;
|
||||
|
||||
int ibuf = 0;
|
||||
uint8_t buf[256] = {0};
|
||||
int res = CLIParamStrToBuf(argstr, buf, maxdatalen * 2, &ibuf); // *2 because here HEX
|
||||
if (res || !ibuf)
|
||||
return res;
|
||||
int ibuf = 0;
|
||||
uint8_t buf[256] = {0};
|
||||
int res = CLIParamStrToBuf(argstr, buf, maxdatalen * 2, &ibuf); // *2 because here HEX
|
||||
if (res || !ibuf)
|
||||
return res;
|
||||
|
||||
switch(param_gethex_to_eol((char *)buf, 0, data, maxdatalen, datalen)) {
|
||||
case 1:
|
||||
printf("Parameter error: Invalid HEX value.\n");
|
||||
return 1;
|
||||
case 2:
|
||||
printf("Parameter error: parameter too large.\n");
|
||||
return 2;
|
||||
case 3:
|
||||
printf("Parameter error: Hex string must have even number of digits.\n");
|
||||
return 3;
|
||||
}
|
||||
switch(param_gethex_to_eol((char *)buf, 0, data, maxdatalen, datalen)) {
|
||||
case 1:
|
||||
printf("Parameter error: Invalid HEX value.\n");
|
||||
return 1;
|
||||
case 2:
|
||||
printf("Parameter error: parameter too large.\n");
|
||||
return 2;
|
||||
case 3:
|
||||
printf("Parameter error: Hex string must have even number of digits.\n");
|
||||
return 3;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CLIParamStrToBuf(struct arg_str *argstr, uint8_t *data, int maxdatalen, int *datalen) {
|
||||
*datalen = 0;
|
||||
if (!argstr->count)
|
||||
return 0;
|
||||
*datalen = 0;
|
||||
if (!argstr->count)
|
||||
return 0;
|
||||
|
||||
uint8_t buf[256] = {0};
|
||||
int ibuf = 0;
|
||||
uint8_t buf[256] = {0};
|
||||
int ibuf = 0;
|
||||
|
||||
for (int i = 0; i < argstr->count; i++) {
|
||||
int len = strlen(argstr->sval[i]);
|
||||
memcpy(&buf[ibuf], argstr->sval[i], len);
|
||||
ibuf += len;
|
||||
}
|
||||
buf[ibuf] = 0;
|
||||
for (int i = 0; i < argstr->count; i++) {
|
||||
int len = strlen(argstr->sval[i]);
|
||||
memcpy(&buf[ibuf], argstr->sval[i], len);
|
||||
ibuf += len;
|
||||
}
|
||||
buf[ibuf] = 0;
|
||||
|
||||
if (!ibuf)
|
||||
return 0;
|
||||
if (!ibuf)
|
||||
return 0;
|
||||
|
||||
if (ibuf > maxdatalen)
|
||||
return 2;
|
||||
if (ibuf > maxdatalen)
|
||||
return 2;
|
||||
|
||||
memcpy(data, buf, ibuf);
|
||||
*datalen = ibuf;
|
||||
memcpy(data, buf, ibuf);
|
||||
*datalen = ibuf;
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* $NetBSD: getopt.h,v 1.4 2000/07/07 10:43:54 ad Exp $ */
|
||||
/* $FreeBSD$ */
|
||||
/* $NetBSD: getopt.h,v 1.4 2000/07/07 10:43:54 ad Exp $ */
|
||||
/* $FreeBSD$ */
|
||||
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-2-Clause-NetBSD
|
||||
|
@ -46,34 +46,34 @@
|
|||
#define optional_argument 2
|
||||
|
||||
struct option {
|
||||
/* name of long option */
|
||||
const char *name;
|
||||
/*
|
||||
* one of no_argument, required_argument, and optional_argument:
|
||||
* whether option takes an argument
|
||||
*/
|
||||
int has_arg;
|
||||
/* if not NULL, set *flag to val when option found */
|
||||
int *flag;
|
||||
/* if flag not NULL, value to set *flag to; else return value */
|
||||
int val;
|
||||
/* name of long option */
|
||||
const char *name;
|
||||
/*
|
||||
* one of no_argument, required_argument, and optional_argument:
|
||||
* whether option takes an argument
|
||||
*/
|
||||
int has_arg;
|
||||
/* if not NULL, set *flag to val when option found */
|
||||
int *flag;
|
||||
/* if flag not NULL, value to set *flag to; else return value */
|
||||
int val;
|
||||
};
|
||||
|
||||
__BEGIN_DECLS
|
||||
int getopt_long(int, char * const *, const char *,
|
||||
const struct option *, int *);
|
||||
int getopt_long_only(int, char * const *, const char *,
|
||||
const struct option *, int *);
|
||||
int getopt_long(int, char * const *, const char *,
|
||||
const struct option *, int *);
|
||||
int getopt_long_only(int, char * const *, const char *,
|
||||
const struct option *, int *);
|
||||
#ifndef _GETOPT_DECLARED
|
||||
#define _GETOPT_DECLARED
|
||||
int getopt(int, char * const [], const char *);
|
||||
#define _GETOPT_DECLARED
|
||||
int getopt(int, char * const [], const char *);
|
||||
|
||||
extern char *optarg; /* getopt(3) external variables */
|
||||
extern char *optarg; /* getopt(3) external variables */
|
||||
extern int optind, opterr, optopt;
|
||||
#endif
|
||||
#ifndef _OPTRESET_DECLARED
|
||||
#define _OPTRESET_DECLARED
|
||||
extern int optreset; /* getopt(3) external variable */
|
||||
#define _OPTRESET_DECLARED
|
||||
extern int optreset; /* getopt(3) external variable */
|
||||
#endif
|
||||
__END_DECLS
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue