From 21cf3794563ca017caa3209ce8863de3204b5c6f Mon Sep 17 00:00:00 2001 From: pikastech Date: Tue, 7 Jun 2022 17:39:55 +0800 Subject: [PATCH] solve '\r\n' in PikaVM_runFile() --- port/linux/test/cJSON-test.cpp | 2 +- src/PikaVM.c | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/port/linux/test/cJSON-test.cpp b/port/linux/test/cJSON-test.cpp index 53a737473..224277244 100644 --- a/port/linux/test/cJSON-test.cpp +++ b/port/linux/test/cJSON-test.cpp @@ -428,7 +428,7 @@ TEST(cJSON, test7) { /* collect */ /* assert */ - EXPECT_STREQ(log_buff[0], "Android\r\n"); + EXPECT_STREQ(log_buff[0], "shopping\r\n"); /* deinit */ obj_deinit(pikaMain); EXPECT_EQ(pikaMemNow(), 0); diff --git a/src/PikaVM.c b/src/PikaVM.c index 04d6afe61..50bd4a53f 100644 --- a/src/PikaVM.c +++ b/src/PikaVM.c @@ -1091,9 +1091,17 @@ exit: VMParameters* pikaVM_runFile(PikaObj* self, char* filename) { Arg* file_arg = arg_loadFile(NULL, filename); - char* py_lines = (char*)arg_getBytes(file_arg); - VMParameters* res = pikaVM_run(self, py_lines); + char* lines = (char*)arg_getBytes(file_arg); + Args buffs = {0}; + /* replace the "\r\n" to "\n" */ + lines = strsReplace(&buffs, lines, "\r\n", "\n"); + /* clear the void line */ + lines = strsReplace(&buffs, lines, "\n\n", "\n"); + /* add '\n' at the end */ + lines = strsAppend(&buffs, lines, "\n\n"); + VMParameters* res = pikaVM_run(self, lines); arg_deinit(file_arg); + strsDeinit(&buffs); return res; }