dpse / tcli Goto Github PK
View Code? Open in Web Editor NEWTiny command line interface for embedded systems
License: MIT License
Tiny command line interface for embedded systems
License: MIT License
Could you tag a commit you are particularly happy with to make a release?
When using tclie_init(&tclie, output_fn, output_fn_arg)
, the output function is being called with &tclie
instead of arg
.
Is this expected?
When using tcli_init(&tcli, output_fn, output_fn_arg)
, the output function is called with output_fn_arg
, as I would expect.
A feature I've used in past embedded CLI systems was a regularly formed syntax for the command usage description, which the command parser used to determine the validity of arguments.
Here's some examples of the 'usage descriptions':
Description | Comment |
---|---|
reset |
Single word command, must match exactly. |
config save |
Two word command, spaces around the words are ignored. |
can speed <rate> |
Two word command, with mandatory argument. |
set <attr> [value] |
One word command, with mandatory and optional argument. |
echo ... |
One word command, with arbitrary number of arguments. |
<reg> = <value> |
One word command ('=') embedded between mandatory arguments. |
when <reg> is <value> echo ... |
Three word command, with two mandatory arguments and arbitrary optional. |
The command handler worked just as yours does now, passing in all words in the argument as argc, argv.
The improvements over what you have now is:
<reg> = <value>
case)By e.g. building whole token tree before matching.
Pointers to strings that will not be modified by the library should be const char *
, not char *
.
Notably: tclie_cmd_t's name & desc fields, and tclie_user_t's name and password fields.
This is very important in embedded systems, as const char *
strings can be allocated in ROM, saving precious RAM.
Add missing TCLI_COMPLETE preprocessor barrier:
diff -u a/source/tclie.c b/source/tclie.c
--- a/source/tclie.c 2022-09-20 15:36:47.499476363 -0400
+++ b/source/tclie.c 2022-09-20 15:37:59.739855525 -0400
@@ -645,8 +645,10 @@ static bool tclie_pattern_match(tclie_t
};
const bool matches = tclie_pattern_match_token(&token, &p);
+#if TCLI_COMPLETE
if (arg_index != 0)
tclie_pattern_match_complete_options(&p);
+#endif
return matches && arg_index == argc;
}
#endif
compl is a reserved keyword in C++, it should not be used in .h files.
The assert(target != subject)
in tclie_pattern_compare()
fails on systems when the compiler optimizes const char *
strings that have the same content to the same memory location (ie GCC optimization level -Os
or -fmerge-constants
).
If two pointers are equal, then by definition the strings are the same. Return true instead of assert.
Suggested patch:
diff -u a/source/tclie.c b/source/tclie.c
--- a/source/tclie.c 2022-09-20 15:36:47.499476363 -0400
+++ b/source/tclie.c 2022-09-20 15:37:59.739855525 -0400
@@ -112,7 +112,10 @@ static bool tclie_pattern_compare(const
{
assert(target);
assert(subject);
- assert(target != subject);
+
+ if (target == subject) {
+ return true;
+ }
while (target_len != 0 && *target != '\0' && *subject != '\0') {
if (*target++ != *subject++)
The typedef for a struct should not itself be 'const', ie:
This is bad:
typedef const struct foo_s {
} foo_t;
This is preferred:
typedef struct foo_s {
} foo_t;
Rationale is that with the former, it is not possible to dynamically construct command definitions at runtime.
The following functions are very useful to have exported outside the library, when using a raw UART for output from a command:
void tcli_clear_screen(tcli_t *tcli);
void tcli_out(tcli_t *tcli, const char *str);
void tcli_flush(tcli_t *tcli);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.