Skip to content

Commit

Permalink
Fixed parsing of multiple pc.js commands
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffpar committed Aug 18, 2023
1 parent 2e7c358 commit 164e1d0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
7 changes: 2 additions & 5 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -466,12 +466,9 @@
"request": "launch",
"program": "${workspaceFolder}/tools/pc/pc.js",
"args": [
"dir",
"--floppy",
"--drivetype=40:2:5",
"--halt"
"chkdsk c:,quit"
],
"cwd": "${workspaceFolder}/tools/pc/disks/MSDOS330/SRC/MBR",
"cwd": "${workspaceFolder}/tools/pc/disks/MSDOS330",
"stopOnEntry": false,
"console": "integratedTerminal",
"outFiles": [
Expand Down
13 changes: 9 additions & 4 deletions tools/pc/pc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,11 @@ async function readXML(sFile, xml, sNode, aTags, iTag, done)
* An external DOS command is allowed if we can find a matching COM, EXE, or BAT file somewhere
* within the specified directory. Internal DOS commands are allowed if they're on the list below.
*
* Multiple commands are allowed, separated by commas, but only the first one will be checked
* for validity; I had toyed with the idea of using semicolons instead of commas, but shells like
* break commands apart at semicolon boundaries unless they're escaped, and that's a pain, so commas
* it is.
*
* NOTE: The list of internal commands below is not intended to be exhaustive; it's just a start.
*
* @param {string} sDir
Expand All @@ -1052,7 +1057,7 @@ async function readXML(sFile, xml, sNode, aTags, iTag, done)
function checkCommand(sDir, sCommand)
{
if (sCommand) {
let aParts = sCommand.split(sCommand.indexOf(',') >= 0? ',' : ' ');
let aParts = sCommand.split(/([ ,])/);
let sProgram = aParts[0].toUpperCase();
const aInternal = ["CD", "COPY", "DEL", "DIR", "ECHO", "MKDIR", "PAUSE", "RMDIR", "SET", "TYPE", "VER"];

Expand All @@ -1067,13 +1072,13 @@ function checkCommand(sDir, sCommand)
if (!aFiles.length) {
sCommand = "";
} else {
let sArguments = aParts.slice(1).join(' ');
let sArguments = sCommand.slice(aParts[0].length);
sCommand = aFiles[0];
if (sCommand.indexOf(sDir) == 0) {
sCommand = sCommand.slice(sDir.length);
}
sCommand = sCommand.replace(/\//g, '\\');
sCommand = (sCommand[0] != '\\'? '\\' : '') + sCommand + (sArguments? " " + sArguments : "");
sCommand = (sCommand[0] != '\\'? '\\' : '') + sCommand + sArguments;
}
}
}
Expand Down Expand Up @@ -1119,7 +1124,7 @@ function getSystemDisk(type, version)
* As for AUTOEXEC.BAT, we read any existing file (or create an empty file) and append the provided command.
*
* @param {string} sDir
* @param {string} [sCommand] (eg, "COPY A:*.COM C:", "PKUNZIP DEMO.ZIP", etc; multiple commands can be separated by commas)
* @param {string} [sCommand] (eg, "COPY A:*.COM C:"; multiple commands can be separated by commas)
* @param {boolean} [fLog]
* @returns {string} (error message, if any)
*/
Expand Down

0 comments on commit 164e1d0

Please sign in to comment.