mirror of
https://github.com/inexorabletash/jsbasic.git
synced 2024-12-26 03:29:22 +00:00
Avoid RegExp.$1 and friends
This commit is contained in:
parent
78428020d8
commit
3cb6079d58
75
dos.js
75
dos.js
@ -57,6 +57,7 @@ function DOS(tty) {
|
|||||||
|
|
||||||
// Internal - crack arguments e.g. ",S6,D1"
|
// Internal - crack arguments e.g. ",S6,D1"
|
||||||
function parseArgs(str, opts) {
|
function parseArgs(str, opts) {
|
||||||
|
str = str || '';
|
||||||
opts = opts || '';
|
opts = opts || '';
|
||||||
|
|
||||||
// Set these to zero so they're always defined when passed into command handlers
|
// Set these to zero so they're always defined when passed into command handlers
|
||||||
@ -73,12 +74,13 @@ function DOS(tty) {
|
|||||||
O: undefined // Echo Output
|
O: undefined // Echo Output
|
||||||
};
|
};
|
||||||
|
|
||||||
while (str.match(/^,?\s*([VDSLRBACIO])\s*([0-9]+|\$[0-9A-Fa-f]+)?\s*([\x20-\x7E]*)/)) {
|
var m;
|
||||||
if (opts.indexOf(RegExp.$1) === -1) {
|
while ((m = str.match(/^,?\s*([VDSLRBACIO])\s*([0-9]+|\$[0-9A-Fa-f]+)?\s*([\x20-\x7E]*)/))) {
|
||||||
|
if (opts.indexOf(m[1]) === -1) {
|
||||||
doserror(DOSErrors.INVALID_OPTION);
|
doserror(DOSErrors.INVALID_OPTION);
|
||||||
}
|
}
|
||||||
args[RegExp.$1] = Number(RegExp.$2);
|
args[m[1]] = Number(m[2]);
|
||||||
str = RegExp.$3;
|
str = m[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (str.length > 0) {
|
if (str.length > 0) {
|
||||||
@ -288,9 +290,10 @@ function DOS(tty) {
|
|||||||
tty.writeString(command + "\r");
|
tty.writeString(command + "\r");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command.match(/^MON([\x20-\x7E]*)/)) {
|
var m;
|
||||||
|
if ((m = command.match(/^MON([\x20-\x7E]*)/))) {
|
||||||
// MON[,C][,I][,O] Traces DOS 3.3 commands ('Commands', 'Input' and 'Output')
|
// MON[,C][,I][,O] Traces DOS 3.3 commands ('Commands', 'Input' and 'Output')
|
||||||
args = parseArgs(RegExp.$1, 'ICO');
|
args = parseArgs(m[1], 'ICO');
|
||||||
|
|
||||||
if (args.I !== undefined) {
|
if (args.I !== undefined) {
|
||||||
monico |= MON_I;
|
monico |= MON_I;
|
||||||
@ -302,9 +305,9 @@ function DOS(tty) {
|
|||||||
monico |= MON_O;
|
monico |= MON_O;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (command.match(/^NOMON([\x20-\x7E]*)/)) {
|
} else if ((m = command.match(/^NOMON([\x20-\x7E]*)/))) {
|
||||||
// NOMON[,C][,I][,O] Cancels tracing of DOS 3.3 commands ('Commands', 'Input' and 'Output')
|
// NOMON[,C][,I][,O] Cancels tracing of DOS 3.3 commands ('Commands', 'Input' and 'Output')
|
||||||
args = parseArgs(RegExp.$1, 'ICO');
|
args = parseArgs(m[1], 'ICO');
|
||||||
if (args.I !== undefined) {
|
if (args.I !== undefined) {
|
||||||
monico &= ~MON_I;
|
monico &= ~MON_I;
|
||||||
}
|
}
|
||||||
@ -314,50 +317,50 @@ function DOS(tty) {
|
|||||||
if (args.O !== undefined) {
|
if (args.O !== undefined) {
|
||||||
monico &= ~MON_O;
|
monico &= ~MON_O;
|
||||||
}
|
}
|
||||||
} else if (command.match(/^OPEN\s*([\x20-\x2B\x2D-\x7E]+)(,[\x20-\x7E]*)?/)) {
|
} else if ((m = command.match(/^OPEN\s*([\x20-\x2B\x2D-\x7E]+)(,[\x20-\x7E]*)?/))) {
|
||||||
// OPEN filename[,Llen] Opens a text file.
|
// OPEN filename[,Llen] Opens a text file.
|
||||||
filename = RegExp.$1;
|
filename = m[1];
|
||||||
args = parseArgs(RegExp.$2, 'L');
|
args = parseArgs(m[2], 'L');
|
||||||
open(filename, args.L);
|
open(filename, args.L);
|
||||||
} else if (command.match(/^APPEND\s*([\x20-\x2B\x2D-\x7E]+)(,[\x20-\x7E]*)?/)) {
|
} else if ((m = command.match(/^APPEND\s*([\x20-\x2B\x2D-\x7E]+)(,[\x20-\x7E]*)?/))) {
|
||||||
// APPEND filename Appends to a text file.
|
// APPEND filename Appends to a text file.
|
||||||
filename = RegExp.$1;
|
filename = m[1];
|
||||||
args = parseArgs(RegExp.$2);
|
args = parseArgs(m[2]);
|
||||||
append(filename, args.L);
|
append(filename, args.L);
|
||||||
} else if (command.match(/^CLOSE\s*([\x20-\x2B\x2D-\x7E]+)?(,[\x20-\x7E]*)?/)) {
|
} else if ((m = command.match(/^CLOSE\s*([\x20-\x2B\x2D-\x7E]+)?(,[\x20-\x7E]*)?/))) {
|
||||||
// CLOSE [filename] Closes specified (or all) open text files.
|
// CLOSE [filename] Closes specified (or all) open text files.
|
||||||
filename = RegExp.$1;
|
filename = m[1];
|
||||||
close(filename);
|
close(filename);
|
||||||
} else if (command.match(/^POSITION\s*([\x20-\x2B\x2D-\x7E]+)(,[\x20-\x7E]*)?/)) {
|
} else if ((m = command.match(/^POSITION\s*([\x20-\x2B\x2D-\x7E]+)(,[\x20-\x7E]*)?/))) {
|
||||||
// POSITION filename[,Rnum] Advances position in text file.
|
// POSITION filename[,Rnum] Advances position in text file.
|
||||||
filename = RegExp.$1;
|
filename = m[1];
|
||||||
args = parseArgs(RegExp.$2, 'R');
|
args = parseArgs(m[2], 'R');
|
||||||
position(filename, args.R);
|
position(filename, args.R);
|
||||||
} else if (command.match(/^READ\s*([\x20-\x2B\x2D-\x7E]+)(,[\x20-\x7E]*)?/)) {
|
} else if ((m = command.match(/^READ\s*([\x20-\x2B\x2D-\x7E]+)(,[\x20-\x7E]*)?/))) {
|
||||||
// READ filename[,Rnum][,Bbyte] Reads from a text file.
|
// READ filename[,Rnum][,Bbyte] Reads from a text file.
|
||||||
filename = RegExp.$1;
|
filename = m[1];
|
||||||
args = parseArgs(RegExp.$2, 'RB');
|
args = parseArgs(m[2], 'RB');
|
||||||
read(filename, args.R, args.B);
|
read(filename, args.R, args.B);
|
||||||
} else if (command.match(/^WRITE\s*([\x20-\x2B\x2D-\x7E]+)(,[\x20-\x7E]*)?/)) {
|
} else if ((m = command.match(/^WRITE\s*([\x20-\x2B\x2D-\x7E]+)(,[\x20-\x7E]*)?/))) {
|
||||||
// WRITE filename[,Rnum][,Bbyte] Writes to a text file.
|
// WRITE filename[,Rnum][,Bbyte] Writes to a text file.
|
||||||
filename = RegExp.$1;
|
filename = m[1];
|
||||||
args = parseArgs(RegExp.$2, 'RB');
|
args = parseArgs(m[2], 'RB');
|
||||||
write(filename, args.R, args.B);
|
write(filename, args.R, args.B);
|
||||||
} else if (command.match(/^DELETE\s*([\x20-\x2B\x2D-\x7E]+)(,[\x20-\x7E]*)?/)) {
|
} else if ((m = command.match(/^DELETE\s*([\x20-\x2B\x2D-\x7E]+)(,[\x20-\x7E]*)?/))) {
|
||||||
// DELETE filename Delete a file
|
// DELETE filename Delete a file
|
||||||
filename = RegExp.$1;
|
filename = m[1];
|
||||||
args = parseArgs(RegExp.$2);
|
args = parseArgs(m[2]);
|
||||||
unlink(filename);
|
unlink(filename);
|
||||||
} else if (command.match(/^RENAME\s*([\x20-\x2B\x2D-\x7E]+),\s*([\x20-\x2B\x2D-\x7E]+)(,[\x20-\x7E]*)?/)) {
|
} else if ((m = command.match(/^RENAME\s*([\x20-\x2B\x2D-\x7E]+),\s*([\x20-\x2B\x2D-\x7E]+)(,[\x20-\x7E]*)?/))) {
|
||||||
// RENAME filename,filename Rename a file
|
// RENAME filename,filename Rename a file
|
||||||
filename = RegExp.$1;
|
filename = m[1];
|
||||||
filename2 = RegExp.$2;
|
filename2 = m[2];
|
||||||
args = parseArgs(RegExp.$3);
|
args = parseArgs(m[3]);
|
||||||
rename(filename, filename2);
|
rename(filename, filename2);
|
||||||
} else if (command.match(/^PR#\s*([\x20-\x2B\x2D-\x7E]+)(,[\x20-\x7E]*)?/)) {
|
} else if ((m = command.match(/^PR#\s*([\x20-\x2B\x2D-\x7E]+)(,[\x20-\x7E]*)?/))) {
|
||||||
// PR# slot Direct output to slot
|
// PR# slot Direct output to slot
|
||||||
slot = Number(RegExp.$1);
|
slot = Number(m[1]);
|
||||||
args = parseArgs(RegExp.$2);
|
args = parseArgs(m[2]);
|
||||||
if (slot === 0) {
|
if (slot === 0) {
|
||||||
if (tty.setFirmwareActive) { tty.setFirmwareActive(false); }
|
if (tty.setFirmwareActive) { tty.setFirmwareActive(false); }
|
||||||
} else if (slot === 3) {
|
} else if (slot === 3) {
|
||||||
@ -365,7 +368,7 @@ function DOS(tty) {
|
|||||||
} else {
|
} else {
|
||||||
doserror(DOSErrors.RANGE_ERROR);
|
doserror(DOSErrors.RANGE_ERROR);
|
||||||
}
|
}
|
||||||
} else if (command.match(/^$/)) {
|
} else if ((m = command.match(/^$/))) {
|
||||||
// Null command - terminates a READ/WRITE, but doesn't CLOSE
|
// Null command - terminates a READ/WRITE, but doesn't CLOSE
|
||||||
// (leaves record length intact on open buffer)
|
// (leaves record length intact on open buffer)
|
||||||
activebuffer = null;
|
activebuffer = null;
|
||||||
|
Loading…
Reference in New Issue
Block a user