Merge pull request #2139 from jmichelp/quotes

Support double-quoted arguments in CLI
This commit is contained in:
Iceman 2023-10-18 11:15:17 +02:00 committed by GitHub
commit 119a4c5efa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View file

@ -3,6 +3,8 @@ All notable changes to this project will be documented in this file.
This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log...
## [unreleased][unreleased]
- Add support for quoted arguments in the CLI, allowing spaces in them which
are removed automatically (@jmichelp)
- Added UDP support on Windows (@wh201906)
- Added client communication timeout to preferences (@iceman1001)
- Added IPv6 support (@wh201906)

View file

@ -147,6 +147,7 @@ enum ParserState {
PS_FIRST,
PS_ARGUMENT,
PS_OPTION,
PS_QUOTE,
};
#define isSpace(c)(c == ' ' || c == '\t')
@ -195,6 +196,10 @@ int CLIParserParseStringEx(CLIParserContext *ctx, const char *str, void *vargtab
case PS_ARGUMENT:
if (state == PS_FIRST)
state = PS_ARGUMENT;
if (str[i] == '"') {
state = PS_QUOTE;
break;
}
if (isSpace(str[i])) {
spaceptr = bufptr;
state = PS_FIRST;
@ -215,6 +220,16 @@ int CLIParserParseStringEx(CLIParserContext *ctx, const char *str, void *vargtab
*bufptr = str[i];
bufptr++;
break;
case PS_QUOTE:
if (str[i] == '"') {
*bufptr++ = 0x00;
state = PS_FIRST;
} else {
if (isSpace(str[i]) == false) {
*bufptr++ = str[i];
}
}
break;
}
if (bufptr > bufptrend) {
PrintAndLogEx(ERR, "ERROR: Line too long\n");