Support -f (flush) option to board_get command
This commit is contained in:
parent
32e460b8f3
commit
8848ad6833
27
shell.c
27
shell.c
@ -4044,17 +4044,21 @@ static void
|
||||
cmd_board_get(struct shell_ctx *ctx, int argc, char **argv) {
|
||||
(void)argv;
|
||||
const char *usage = \
|
||||
"usage: board_get [-l] [-n]\n";
|
||||
"usage: board_get [<-l|-a>] [-n]\n";
|
||||
if (argc > 2) {
|
||||
fputs(usage, ctx->fout);
|
||||
return;
|
||||
}
|
||||
optparse_init(&ctx->opts, argv);
|
||||
int flush = 0;
|
||||
int line = 0;
|
||||
int force_newline = 0;
|
||||
int opt;
|
||||
while ((opt = optparse(&ctx->opts, "ln")) != -1) {
|
||||
while ((opt = optparse(&ctx->opts, "fln")) != -1) {
|
||||
switch (opt) {
|
||||
case 'f':
|
||||
flush = 1;
|
||||
__attribute__((fallthrough)); // TODO: use [[fallthrough]]; (C23)
|
||||
case 'l':
|
||||
line = 1;
|
||||
break;
|
||||
@ -4084,7 +4088,7 @@ cmd_board_get(struct shell_ctx *ctx, int argc, char **argv) {
|
||||
if (c.status) {
|
||||
fputc(c.value, ctx->fout);
|
||||
}
|
||||
} while (c.status && (c.value != '\n'));
|
||||
} while (c.status && ((c.value != '\n') || flush));
|
||||
if (force_newline) {
|
||||
fputc('\n', ctx->fout);
|
||||
}
|
||||
@ -4101,6 +4105,23 @@ cmd_board_put(struct shell_ctx *ctx, int argc, char **argv) {
|
||||
return;
|
||||
}
|
||||
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();
|
||||
umka_sys_board_put(c);
|
||||
COVERAGE_OFF();
|
||||
|
@ -13,3 +13,17 @@ d
|
||||
hi
|
||||
/>
|
||||
/> 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
|
@ -9,3 +9,14 @@ board_put i
|
||||
board_get -ln
|
||||
|
||||
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
|
||||
|
@ -13,3 +13,17 @@ d
|
||||
hi
|
||||
/>
|
||||
/> 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
|
@ -9,3 +9,14 @@ board_put i
|
||||
board_get -ln
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user