Support -f (flush) option to board_get command

This commit is contained in:
Ivan Baravy 2023-07-19 21:10:24 +01:00
parent 32e460b8f3
commit 8848ad6833
5 changed files with 74 additions and 3 deletions

27
shell.c
View File

@ -4044,17 +4044,21 @@ static void
cmd_board_get(struct shell_ctx *ctx, int argc, char **argv) { cmd_board_get(struct shell_ctx *ctx, int argc, char **argv) {
(void)argv; (void)argv;
const char *usage = \ const char *usage = \
"usage: board_get [-l] [-n]\n"; "usage: board_get [<-l|-a>] [-n]\n";
if (argc > 2) { if (argc > 2) {
fputs(usage, ctx->fout); fputs(usage, ctx->fout);
return; return;
} }
optparse_init(&ctx->opts, argv); optparse_init(&ctx->opts, argv);
int flush = 0;
int line = 0; int line = 0;
int force_newline = 0; int force_newline = 0;
int opt; int opt;
while ((opt = optparse(&ctx->opts, "ln")) != -1) { while ((opt = optparse(&ctx->opts, "fln")) != -1) {
switch (opt) { switch (opt) {
case 'f':
flush = 1;
__attribute__((fallthrough)); // TODO: use [[fallthrough]]; (C23)
case 'l': case 'l':
line = 1; line = 1;
break; break;
@ -4084,7 +4088,7 @@ cmd_board_get(struct shell_ctx *ctx, int argc, char **argv) {
if (c.status) { if (c.status) {
fputc(c.value, ctx->fout); fputc(c.value, ctx->fout);
} }
} while (c.status && (c.value != '\n')); } while (c.status && ((c.value != '\n') || flush));
if (force_newline) { if (force_newline) {
fputc('\n', ctx->fout); fputc('\n', ctx->fout);
} }
@ -4101,6 +4105,23 @@ cmd_board_put(struct shell_ctx *ctx, int argc, char **argv) {
return; return;
} }
char c = argv[1][0]; char c = argv[1][0];
if (c == '\\') {
switch ((c = argv[1][1])) {
case 'n':
c = '\n';
break;
case 'r':
c = '\r';
break;
case 't':
c = '\t';
break;
default:
fprintf(ctx->fout, "unknown escape symbol: '%c'\n", c);
c = '?';
break;
}
}
COVERAGE_ON(); COVERAGE_ON();
umka_sys_board_put(c); umka_sys_board_put(c);
COVERAGE_OFF(); COVERAGE_OFF();

View File

@ -13,3 +13,17 @@ d
hi hi
/> />
/> board_get -l /> board_get -l
/>
/> board_put a
/> board_put \n
/> board_put b
/> board_put c
/> board_put \n
/> board_put d
/> board_put e
/> board_put f
/>
/> board_get -f
a
bc
def

View File

@ -9,3 +9,14 @@ board_put i
board_get -ln board_get -ln
board_get -l board_get -l
board_put a
board_put \n
board_put b
board_put c
board_put \n
board_put d
board_put e
board_put f
board_get -f

View File

@ -13,3 +13,17 @@ d
hi hi
/> />
/> board_get -l /> board_get -l
/>
/> board_put a
/> board_put \n
/> board_put b
/> board_put c
/> board_put \n
/> board_put d
/> board_put e
/> board_put f
/>
/> board_get -f
a
bc
def

View File

@ -9,3 +9,14 @@ board_put i
board_get -ln board_get -ln
board_get -l board_get -l
board_put a
board_put \n
board_put b
board_put c
board_put \n
board_put d
board_put e
board_put f
board_get -f