From 368a5cddfbdd8503904958f4cb92d9037f476e2e Mon Sep 17 00:00:00 2001 From: Lisa Milne Date: Thu, 21 Dec 2023 10:05:14 +1000 Subject: [PATCH] remove more unnecessary objects from shell --- clite/shell.js | 84 ++++++++++++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 41 deletions(-) diff --git a/clite/shell.js b/clite/shell.js index 4c576fe..6709726 100644 --- a/clite/shell.js +++ b/clite/shell.js @@ -23,7 +23,9 @@ clite.commands.load('sh',function(args,env,io) { let exec_bufferout = null; let exec_bufferin = null; let exec_skipto = null; - let exec_cfg = {closout:false,closin:false,closerr:false}; + let exec_closout = false; + let exec_closin = false; + let exec_closerr = false; let exec_last = 0; let exec_io = {}; let exec_conditionals = []; @@ -310,9 +312,9 @@ clite.commands.load('sh',function(args,env,io) { break; } }else{ - if (exec_cfg.closin) { + if (exec_closin) { stdio.close(exec_io.stdin); - exec_cfg.closin = false; + exec_closin = false; } exec_io.stdin = io.stdin; } @@ -330,9 +332,9 @@ clite.commands.load('sh',function(args,env,io) { break; } }else{ - if (exec_cfg.closout) { + if (exec_closout) { stdio.close(exec_io.stdout); - exec_cfg.closout = false; + exec_closout = false; } exec_io.stdout = io.stdout; } @@ -349,9 +351,9 @@ clite.commands.load('sh',function(args,env,io) { break; } }else{ - if (exec_cfg.closerr) { + if (exec_closerr) { stdio.close(exec_io.stderr); - exec_cfg.closerr = false; + exec_closerr = false; } exec_io.stderr = io.stderr; } @@ -659,53 +661,53 @@ clite.commands.load('sh',function(args,env,io) { exec_last = 0; } function exec_stdin_setFile(path) { - if (exec_cfg.closin) { + if (exec_closin) { stdio.close(exec_io.stdin); - exec_cfg.closin = false; + exec_closin = false; } exec_io.stdin = stdio.open(path,stdio.flags.O_RDONLY); - exec_cfg.closin = true; + exec_closin = true; } function exec_stdin_setNull() { - if (exec_cfg.closin) { + if (exec_closin) { stdio.close(exec_io.stdin); - exec_cfg.closin = false; + exec_closin = false; } exec_io.stdin = stdio.open('/dev/null',stdio.flags.O_RDONLY); - exec_cfg.closin = true; + exec_closin = true; } function exec_stdin_setOut() { - if (exec_cfg.closin) { + if (exec_closin) { stdio.close(exec_io.stdin); - exec_cfg.closin = false; + exec_closin = false; } if (exec_bufferout) { exec_io.stdout = null; - exec_cfg.closout = false; + exec_closout = false; exec_bufferin = exec_bufferout; exec_bufferout = null; exec_io.stdin = exec_bufferin; stdio.seek(exec_io.stdin,0); - exec_cfg.closin = true; + exec_closin = true; }else{ exec_stdin_setNull(); } } function exec_stdout_setBuffered() { - if (exec_cfg.closout) { + if (exec_closout) { stdio.close(exec_io.stdout); - exec_cfg.closout = false; + exec_closout = false; if (exec_bufferout) exec_bufferout = null; } exec_bufferout = stdio.mkstemp('/tmp/shell-XXXXXX'); exec_io.stdout = exec_bufferout; - exec_cfg.closout = false; + exec_closout = false; } function exec_stdout_setFile(path) { - if (exec_cfg.closout) { + if (exec_closout) { stdio.close(exec_io.stdout); - exec_cfg.closout = false; + exec_closout = false; } var flags = stdio.flags.O_WRONLY|stdio.flags.O_CREAT|stdio.flags.O_SYNC; var p = path; @@ -716,20 +718,20 @@ clite.commands.load('sh',function(args,env,io) { flags |= stdio.flags.O_TRUNC; } exec_io.stdout = stdio.open(p,flags); - exec_cfg.closout = true; + exec_closout = true; } function exec_stdout_setNull() { - if (exec_cfg.closout) { + if (exec_closout) { stdio.close(exec_io.stdout); - exec_cfg.closout = false; + exec_closout = false; } exec_io.stdout = stdio.open('/dev/null',stdio.flags.O_WRONLY); - exec_cfg.closout = true; + exec_closout = true; } function exec_stderr_setFile(path) { - if (exec_cfg.closerr) { + if (exec_closerr) { stdio.close(exec_io.stderr); - exec_cfg.closerr = false; + exec_closerr = false; } var flags = stdio.flags.O_WRONLY|stdio.flags.O_CREAT|stdio.flags.O_SYNC; var p = path; @@ -740,39 +742,39 @@ clite.commands.load('sh',function(args,env,io) { flags |= stdio.flags.O_TRUNC; } exec_io.stderr = stdio.open(p,flags); - exec_cfg.closerr = true; + exec_closerr = true; } function exec_stderr_setNull() { - if (exec_cfg.closerr) { + if (exec_closerr) { stdio.close(exec_io.stderr); - exec_cfg.closerr = false; + exec_closerr = false; } exec_io.stderr = stdio.open('/dev/null',stdio.flags.O_WRONLY); - exec_cfg.closerr = true; + exec_closerr = true; } function exec_stderr_setOut() { - if (exec_cfg.closerr) { + if (exec_closerr) { stdio.close(exec_io.stderr); - exec_cfg.closerr = false; + exec_closerr = false; } exec_io.stderr = exec_io.stdout; - exec_cfg.closerr = exec_cfg.closout; + exec_closerr = exec_closout; } function exec_exit() { - if (exec_cfg.closin) { + if (exec_closin) { stdio.close(exec_io.stdin); - exec_cfg.closin = false; + exec_closin = false; } var out = ''; if (exec_bufferout) out = stdio.readAll(exec_bufferout); - if (exec_cfg.closout) { + if (exec_closout) { stdio.close(exec_io.stdout); - exec_cfg.closout = false; + exec_closout = false; } - if (exec_cfg.closerr) { + if (exec_closerr) { stdio.close(exec_io.stderr); - exec_cfg.closerr = false; + exec_closerr = false; } exec_active = null; exec_cmds = [];