From 5d66234c47be4b7708f159aef7055613408a3725 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sun, 1 Nov 2020 17:48:23 +0900 Subject: [PATCH] empty commit message --- assets/tvdos/TVDOS.SYS | 6 ++++ assets/tvdos/command.js | 67 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/assets/tvdos/TVDOS.SYS b/assets/tvdos/TVDOS.SYS index 25b0cad..cafaca3 100644 --- a/assets/tvdos/TVDOS.SYS +++ b/assets/tvdos/TVDOS.SYS @@ -71,6 +71,12 @@ 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 fd6301a..ee29a4e 100644 --- a/assets/tvdos/command.js +++ b/assets/tvdos/command.js @@ -16,7 +16,72 @@ function greet() { let shell = {}; -shell.test = "command.js test string"; +// example input: echo "the string" > subdir\test.txt +shell.parse = function(input) { + let tokens = []; + let stringBuffer = ""; + let mode = "LITERAL"; // LITERAL, QUOTE, ESCAPE, LIMBO + let i = 0 + while (i < input.length) { + const c = input[i]; +/*digraph g { + LITERAL -> QUOTE [label="\""] + LITERAL -> LIMBO [label="space"] + LITERAL -> LITERAL [label=else] + + QUOTE -> LIMBO [label="\""] + QUOTE -> ESCAPE [label="\\"] + QUOTE -> QUOTE [label=else] + + ESCAPE -> QUOTE + + LIMBO -> LITERAL [label="not space"] + LIMBO -> LIMBO [label="space"] +}*/ + if (mode == "LITERAL") { + if (c == ' ') { + tokens.push(stringBuffer); stringBuffer = ""; + mode = "LIMBO"; + } + else if (c == '"') { + tokens.push(stringBuffer); stringBuffer = ""; + mode = "QUOTE"; + } + else { + stringBuffer += c; + } + } + else if (mode == "LIMBO") { + if (c != ' ') { + mode = "LITERAL"; + stringBuffer += c; + } + } + else if (mode == "QUOTE") { + if (c == '"') { + tokens.push(stringBuffer); stringBuffer = ""; + } + else if (c == '\\') { + mode = "ESCAPE"; + } + else { + stringBuffer += c; + } + } + else if (mode == "ESCAPE") { + + } + + // end of the input string + if (i == input.length - 1) { + stringBuffer += c; + tokens.push(stringBuffer); + } + + i += 1; + } + return tokens; +} if (exec_args !== undefined) return shell;