From fff855fc79a5bea256c6d7b9bcc6ffecf48d0846 Mon Sep 17 00:00:00 2001 From: anseki Date: Tue, 24 Mar 2015 20:37:20 +0900 Subject: [PATCH] Fix: error of `decodeDOS` when no arg --- lib/read.cs.js | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/lib/read.cs.js b/lib/read.cs.js index ce7226e..fa843d2 100644 --- a/lib/read.cs.js +++ b/lib/read.cs.js @@ -27,26 +27,14 @@ while (typeof(arg = args.shift()) === 'string') { } if (typeof options.display === 'string' && options.display !== '') { - ttyWrite(options.encoded ? decodeDOS(options.display) : options.display); + writeTTY(options.encoded ? decodeDOS(options.display) : options.display); } -WScript.StdOut.Write("'" + (options.noEchoBack ? readS() : ttyRead()) + "'"); +WScript.StdOut.Write("'" + (options.noEchoBack ? readS() : readTTY()) + "'"); WScript.Quit(); -function ttyRead() { - var text; - try { - text = getFso().OpenTextFile('CONIN$', FSO_ForReading).ReadLine(); - } catch (e) { - WScript.StdErr.WriteLine('TTY Read Error: ' + e.number + - '\n' + e.description); - WScript.Quit(1); - } - return text; -} - -function ttyWrite(text) { +function writeTTY(text) { try { tty = tty || getFso().OpenTextFile('CONOUT$', FSO_ForWriting, true); tty.Write(text); @@ -57,9 +45,16 @@ function ttyWrite(text) { } } -function getFso() { - if (!fso) { fso = new ActiveXObject('Scripting.FileSystemObject'); } - return fso; +function readTTY() { + var text; + try { + text = getFso().OpenTextFile('CONIN$', FSO_ForReading).ReadLine(); + } catch (e) { + WScript.StdErr.WriteLine('TTY Read Error: ' + e.number + + '\n' + e.description); + WScript.Quit(1); + } + return text; } function readS() { @@ -103,18 +98,23 @@ function scriptPW() { '\n' + e.description); WScript.Quit(1); } - ttyWrite('\n'); + writeTTY('\n'); return pw; } +function getFso() { + if (!fso) { fso = new ActiveXObject('Scripting.FileSystemObject'); } + return fso; +} + +function getShell() { + if (!shell) { shell = WScript.CreateObject('WScript.Shell'); } + return shell; +} + function shellExec(cmd, callback) { // callback(exitCode, stdout, stderr, error) var wsExec, stdout = '', stderr = '', noOutput; - function getShell() { - if (!shell) { shell = WScript.CreateObject('WScript.Shell'); } - return shell; - } - try { wsExec = getShell().Exec(cmd); } catch (e) { @@ -143,7 +143,7 @@ function shellExec(cmd, callback) { // callback(exitCode, stdout, stderr, error) } function decodeDOS(arg) { - return arg.replace(/#(\d+);/g, function(str, charCode) { + return (arg + '').replace(/#(\d+);/g, function(str, charCode) { return String.fromCharCode(+charCode); }); }