mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-05-12 12:41:25 +00:00
product-mini/nuttx: Use readline for repl mode (#469)
The EOL of NuttX is configurable (CR/LF/CRLF), the implementation of getline in NuttX need CR or LF as line delimiter(CRLF not supported). Then we should use readline for better compatibility. Signed-off-by: Huang Qi <huangqi3@xiaomi.com> Co-authored-by: Huang Qi <huangqi3@xiaomi.com>
This commit is contained in:
parent
7f4e519edc
commit
619c2b383c
|
@ -10,6 +10,8 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <system/readline.h>
|
||||||
|
|
||||||
#include "bh_platform.h"
|
#include "bh_platform.h"
|
||||||
#include "bh_read_file.h"
|
#include "bh_read_file.h"
|
||||||
#include "wasm_export.h"
|
#include "wasm_export.h"
|
||||||
|
@ -119,13 +121,20 @@ split_string(char *str, int *count)
|
||||||
static void *
|
static void *
|
||||||
app_instance_repl(wasm_module_inst_t module_inst)
|
app_instance_repl(wasm_module_inst_t module_inst)
|
||||||
{
|
{
|
||||||
char *cmd = NULL;
|
size_t len = 128;
|
||||||
size_t len = 0;
|
char *cmd = malloc(len);
|
||||||
ssize_t n;
|
ssize_t n;
|
||||||
|
|
||||||
while ((printf("webassembly> "), n = getline(&cmd, &len, stdin)) != -1) {
|
if (NULL == cmd) {
|
||||||
|
LOG_ERROR("Wasm repl cmd buffer alloc failed.\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (
|
||||||
|
(printf("webassembly> "), fflush(stdout), n = std_readline(cmd, len))
|
||||||
|
!= -1) {
|
||||||
bh_assert(n > 0);
|
bh_assert(n > 0);
|
||||||
if (cmd[n - 1] == '\n') {
|
if ((cmd[n - 1] == '\n') || (cmd[n - 1] == '\r')) {
|
||||||
if (n == 1)
|
if (n == 1)
|
||||||
continue;
|
continue;
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue
Block a user