From be750cbc9454b30f93262ecdfb44afc334890a4a Mon Sep 17 00:00:00 2001 From: Joe Nicholson Date: Sat, 12 Nov 2016 20:30:10 +0000 Subject: [PATCH 1/2] Correct read function to stop trimming of final character of user input, correcting loss of final character during INPUT A$;PRINT A$ --- lib/IOInterface.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/IOInterface.js b/lib/IOInterface.js index 7d04abc..d0a21fd 100644 --- a/lib/IOInterface.js +++ b/lib/IOInterface.js @@ -103,7 +103,7 @@ IOInterface.prototype.readln = function(callback) { this.read(function(char, value, cancel) { if (char === "\n") { cancel(); - var result = value.substring(0, value.length - 2); + var result = value.substring(0, value.length - 1); callback(result); } }); From e77f8f902eb017ea729e17c6e7f89202d747c723 Mon Sep 17 00:00:00 2001 From: Joe Nicholson Date: Sun, 13 Nov 2016 15:31:16 +0000 Subject: [PATCH 2/2] Add SHELL command to allow BASIC to access the shell --- lib/parser/commands/ShellCommand.js | 64 +++++++++++++++++++++++++++++ lib/parser/commands/index.js | 3 ++ 2 files changed, 67 insertions(+) create mode 100644 lib/parser/commands/ShellCommand.js diff --git a/lib/parser/commands/ShellCommand.js b/lib/parser/commands/ShellCommand.js new file mode 100644 index 0000000..826c94c --- /dev/null +++ b/lib/parser/commands/ShellCommand.js @@ -0,0 +1,64 @@ +/* ************************************************************************** + Additional Command to Execute Shell Command from BASIC + Joe Nicholson Rufilla Ltd. + ************************************************************************** +*/ + +var statements = require('../statements'); +var SyntaxError = require('../SyntaxError'); +var rl = require('../../IOInterface').getDefault(); + +var exec = require('child_process').exec; + +/** + * Shells execution + * + * @param {String} args The arguments to the command + * @param {Function} define + * @constructor + */ +function ShellCommand(args, define) { + if (args.length) { + this.message = new statements.ExpressionStatement(args, define); + if (this.message.error) throw this.message.error; + } else this.message = new statements.StringStatement("[<< Shelld, Press RETURN to Continue >>]"); +} + +/** + * Converts the command arguments to a string + * + * @returns {string} + */ +ShellCommand.prototype.toString = function() { + return this.message.toString(); +}; + +/** + * Converts the command to JSON + * + * @returns {Object} + */ +ShellCommand.prototype.toJSON = function() { + return { + message: this.message.toJSON() + }; +}; + +/** + * Executes the command + * + * @param {ExecutionContext} data + * @param {Function} next + */ +ShellCommand.prototype.execute = function(data, next) { + var message = this.message.execute(data); + data.validate(message, 'string'); + + // Executre the shell command + exec(message, function (error, stdout, stderr) { + console.log(stdout); + next(); + }); +}; + +module.exports = ShellCommand; \ No newline at end of file diff --git a/lib/parser/commands/index.js b/lib/parser/commands/index.js index 42abe6b..0ba2087 100644 --- a/lib/parser/commands/index.js +++ b/lib/parser/commands/index.js @@ -21,6 +21,9 @@ exports.restore = require('./RestoreCommand'); exports.data = require('./DataCommand'); exports.read = require('./ReadCommand'); +// Added by Joe +exports.shell = require('./ShellCommand'); + // Graphic commands exports.color = require('./ColorCommand'); exports.tcolor = require('./TcolorCommand');