From a2e74313a1ef23a7250294332cd3bf73c4b3dd59 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sun, 1 Nov 2020 18:41:39 +0900 Subject: [PATCH] cmd parser --- assets/tvdos/TVDOS.SYS | 11 +++++------ assets/tvdos/command.js | 22 +++++++++++++--------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/assets/tvdos/TVDOS.SYS b/assets/tvdos/TVDOS.SYS index cafaca3..0c13be3 100644 --- a/assets/tvdos/TVDOS.SYS +++ b/assets/tvdos/TVDOS.SYS @@ -8,6 +8,11 @@ _TVDOS.DRIVES["A"] = _BIOS.FIRST_BOOTABLE_PORT; //TODO +_TVDOS.defaults = { + path: [ + "" + ] +}; Object.freeze(_TVDOS); /////////////////////////////////////////////////////////////////////////////// @@ -71,12 +76,6 @@ var execApp = function(cmdsrc, args) { /////////////////////////////////////////////////////////////////////////////// // Boot script -_TVDOS.defaults = { - path: [ - "" - ] -}; - filesystem.open("A", "tvdos/command.js", "R"); let cmdsrc = filesystem.readAll("A"); diff --git a/assets/tvdos/command.js b/assets/tvdos/command.js index ee29a4e..2405c8b 100644 --- a/assets/tvdos/command.js +++ b/assets/tvdos/command.js @@ -36,6 +36,7 @@ shell.parse = function(input) { ESCAPE -> QUOTE LIMBO -> LITERAL [label="not space"] + LIMBO -> QUOTE [label="\""] LIMBO -> LIMBO [label="space"] }*/ if (mode == "LITERAL") { @@ -52,7 +53,10 @@ shell.parse = function(input) { } } else if (mode == "LIMBO") { - if (c != ' ') { + if (c == '"') { + mode = "QUOTE"; + } + else if (c != ' ') { mode = "LITERAL"; stringBuffer += c; } @@ -60,6 +64,7 @@ shell.parse = function(input) { else if (mode == "QUOTE") { if (c == '"') { tokens.push(stringBuffer); stringBuffer = ""; + mode = "LIMBO"; } else if (c == '\\') { mode = "ESCAPE"; @@ -72,14 +77,13 @@ shell.parse = function(input) { } - // end of the input string - if (i == input.length - 1) { - stringBuffer += c; - tokens.push(stringBuffer); - } - i += 1; } + + if (stringBuffer.length > 0) { + tokens.push(stringBuffer); + } + return tokens; } if (exec_args !== undefined) return shell; @@ -116,8 +120,8 @@ while (true) { else if (key === 10 || key === 13) { println(); try { - println("You entered: " + cmdbuf); - + let tokens = shell.parse(cmdbuf); + tokens.forEach(function(it) { println(it+"_"); }); } catch (e) { printerrln(e);