Add commands to tokenizer for "options" in command line#2024
Open
MaxineMuster wants to merge 3 commits intoopenshwprojects:mainfrom
Open
Add commands to tokenizer for "options" in command line#2024MaxineMuster wants to merge 3 commits intoopenshwprojects:mainfrom
MaxineMuster wants to merge 3 commits intoopenshwprojects:mainfrom
Conversation
You can check for options like SDA=<pin-ID or pin name> / type=SHT4x / chan_t=<channel> or even str="a string" // use new TOKENIZER_ALLOW_QUOTES_IN_NAMEDARG_VALUE for this -SCL <pin-ID or pin name> / -type SHT3x / chan_h <channel> or even -str "another string" // will "only" need TOKENIZER_ALLOW_QUOTES new command are (all will need a default in case the option is not found): const char *Tokenizer_GetArgEqualDefault(const char *search, const char *def); int Tokenizer_GetArgEqualInteger(const char *search, const int def); int Tokenizer_GetPinEqual(const char *search, const int def); You can also check for a "single" option (like "-v" or "-single_mode") bool Tokenizer_IsStringPresent(const char *search); Added selftest for the new commands, too.
Changed to minimized version, only allowing to serch for args like "-SDA P16" Only one new funktion, all others are "#defines" in default but can be compiled as functions using "#define TOKENIZER_PARAM_EXTENSION 1"
Contributor
Author
|
Streamlined and minimized addition: Now only args like "-SDA 4 -SCL P5" are possible (removed "XY=9" style) Only one new function, all others as "optional" functions (enable with "#define TOKENIZER_PARAM_EXTENSION 1"), else they can be used as #defines using the one new function. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I often struggle on the parameters order e.g. when starting a driver like AHT2x:
is it
<sda> <scl> <channel temp> <channel hum>?or
<scl> <sda> <channel hum> <channel temp>?or ...
So I like a call with "named" arguments like
SDA=17 SCL=19 chan_h=3 chan_t=4which is totally equal to
chan_h=3 SCL=19 chan_t=4 SDA=17So I tried to add some "useful" extension to tokenizer code to allow this sort of arguments.
With this change you can check for options like this:
SDA=<pin-ID or pin name> / type=SHT4x / chan_t=<channel>or even
str="a string"// use new TOKENIZER_ALLOW_QUOTES_IN_NAMEDARG_VALUE for this-SCL <pin-ID or pin name> / -type SHT3x / chan_h <channel>or
-str "another string"// will "only" need TOKENIZER_ALLOW_QUOTESnew command are (all will need a default in case the option is not found):
const char *Tokenizer_GetArgEqualDefault(const char *search, const char *def);
int Tokenizer_GetArgEqualInteger(const char *search, const int def);
int Tokenizer_GetPinEqual(const char *search, const int def);
You can also check for a "single" option (like "-v" or "-single_mode")
bool Tokenizer_IsStringPresent(const char *search);
Added selftest for the new commands, too.