Skip to content
This repository was archived by the owner on Dec 24, 2020. It is now read-only.

Commit

Permalink
Added new "machines.js" script to help generate VSCode launch configs
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffpar committed Jun 10, 2018
1 parent 1198952 commit 828bf66
Show file tree
Hide file tree
Showing 20 changed files with 284 additions and 31 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"MD002": false,
"MD003": false,
"MD004": false,
"MD009": false,
"MD010": false,
"MD025": false,
"MD029": false,
Expand All @@ -37,6 +38,6 @@
"npm.autoDetect": "off",
"typescript.tsc.autoDetect": "off",
"typescript.validate.enable": false,
"window.zoomLevel": 0,
"window.zoomLevel": 0,
"workbench.quickOpen.closeOnFocusLost": false
}
2 changes: 1 addition & 1 deletion disks/pcx86/shareware/pcsig08/1001/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ PC-SIG Library 8th Edition CD-ROM (April 1990): Disks 1001-1500

The machine below has access to all 2,121 diskette images from the PC-SIG Library 8th Edition CD-ROM (April 1990).
The directory listings were generated from our [PCSIG08 Disk Manifest](https://jeffpar.github.io/pcjs-disks/pcx86/shareware/pcsig08/manifest.xml)
using the PCjs <a href="/modules/diskdump/bin/disklist.js">disklist</a> utility, which was much more expedient than
using the PCjs <a href="/modules/diskdump/bin/manifest.js">manifest</a> utility, which was much more expedient than
using PC DOS to load and list every disk's contents.

Preceding each directory listing is a **Load Disk** button that will automatically load the corresponding disk into
Expand Down
2 changes: 1 addition & 1 deletion disks/pcx86/shareware/pcsig08/1501/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ PC-SIG Library 8th Edition CD-ROM (April 1990): Disks 1501-2121

The machine below has access to all 2,121 diskette images from the PC-SIG Library 8th Edition CD-ROM (April 1990).
The directory listings were generated from our [PCSIG08 Disk Manifest](https://jeffpar.github.io/pcjs-disks/pcx86/shareware/pcsig08/manifest.xml)
using the PCjs <a href="/modules/diskdump/bin/disklist.js">disklist</a> utility, which was much more expedient than
using the PCjs <a href="/modules/diskdump/bin/manifest.js">manifest</a> utility, which was much more expedient than
using PC DOS to load and list every disk's contents.

Preceding each directory listing is a **Load Disk** button that will automatically load the corresponding disk into
Expand Down
2 changes: 1 addition & 1 deletion disks/pcx86/shareware/pcsig08/501/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ PC-SIG Library 8th Edition CD-ROM (April 1990): Disks 501-1000

The machine below has access to all 2,121 diskette images from the PC-SIG Library 8th Edition CD-ROM (April 1990).
The directory listings were generated from our [PCSIG08 Disk Manifest](https://jeffpar.github.io/pcjs-disks/pcx86/shareware/pcsig08/manifest.xml)
using the PCjs <a href="/modules/diskdump/bin/disklist.js">disklist</a> utility, which was much more expedient than
using the PCjs <a href="/modules/diskdump/bin/manifest.js">manifest</a> utility, which was much more expedient than
using PC DOS to load and list every disk's contents.

Preceding each directory listing is a **Load Disk** button that will automatically load the corresponding disk into
Expand Down
2 changes: 1 addition & 1 deletion disks/pcx86/shareware/pcsig08/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The machine below has access to all 2,121 diskette images from the
[PC-SIG Library 8th Edition CD-ROM (April 1990)](http://cd.textfiles.com/pcsig08).
The directory listings were generated from our
[PCSIG08 Disk Manifest](https://jeffpar.github.io/pcjs-disks/pcx86/shareware/pcsig08/manifest.xml)
using the PCjs <a href="/modules/diskdump/bin/disklist.js">disklist</a> utility, rather than using PC DOS to load and
using the PCjs <a href="/modules/diskdump/bin/manifest.js">manifest</a> utility, rather than using PC DOS to load and
list every disk's contents.

Preceding each directory listing is a **Load Disk** button that will automatically load the corresponding disk into
Expand Down
2 changes: 1 addition & 1 deletion modules/diskdump/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ folder was generated.
The equivalent web server API request would look like:

http://localhost:8088/api/v1/dump?path=/apps/pcx86/1981/visicalc/vc.com;README.md&format=img

DiskDump is a port of the earlier PCjs **convdisk.php** utility.
170 changes: 170 additions & 0 deletions modules/diskdump/bin/machines.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
#!/usr/bin/env node
/**
* @fileoverview Node command-line machine extraction tool
* @author <a href="mailto:[email protected]">Jeff Parsons</a>
* @copyright © 2012-2018 Jeff Parsons
*
* This file is part of PCjs, a computer emulation software project at <https://www.pcjs.org>.
*
* PCjs is free software: you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* PCjs is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with PCjs. If not,
* see <http://www.gnu.org/licenses/gpl.html>.
*
* You are required to include the above copyright notice in every modified copy of this work
* and to display that copyright notice when the software starts running; see COPYRIGHT in
* <https://www.pcjs.org/modules/shared/lib/defines.js>.
*
* Some PCjs files also attempt to load external resource files, such as character-image files,
* ROM files, and disk image files. Those external resource files are not considered part of PCjs
* for purposes of the GNU General Public License, and the author does not claim any copyright
* as to their contents.
*/

"use strict";

var fs = require("fs");
var glob = require("glob");
var path = require("path");
var defines = require("../../shared/lib/defines");
var Str = require("../..//shared/lib/strlib");
var Proc = require("../../shared/lib/proclib");
var args = Proc.getArgs();

/**
* printf(format, ...args)
*
* @param {string} format
* @param {...} args
*/
function printf(format, ...args)
{
process.stdout.write(Str.sprintf(format, ...args));
}

/**
* processMachines(sDir, fDebug)
*
* @param {string} sDir
* @param {boolean} [fDebug] (true if --debug is specified on the command-line)
*/
function processMachines(sDir, fDebug)
{
let aMachines = [];
let asFiles = glob.sync(path.join(sDir, "**", "README.md"));
for (let i = 0; i < asFiles.length; i++) {
let sFile = asFiles[i], sMarkdown;
try {
sMarkdown = fs.readFileSync(sFile, {encoding: "utf8"});
} catch(err) {
printf("error: %s\n", err.message);
process.exit(1);
}

let sDir = path.dirname(sFile);
let sParent = ".." + path.sep;
while (sDir.indexOf(sParent) == 0) sDir = sDir.substr(sParent.length);
let j = sDir.indexOf(path.sep);
let sCategory = j > 0? sDir.charAt(0).toUpperCase() + sDir.substring(1, j) : "";
sDir = path.sep + sDir + path.sep;

if (fDebug) printf("opened %s\n", sFile);
/*
* Check the file for Front Matter (ie, a header at the top of the file delineated by "---" lines)
* that includes both a "title" property and a "machines" section.
*/
let matchFM = sMarkdown.match(/^---[\s\S]*?\ntitle:\s*"?(.*?)"?\n[\s\S]*?machines:([\s\S]*?\n)\S/);
if (matchFM) {
let sTitle = matchFM[1].replace(/&amp;/g, '&');
let asMachines = matchFM[2].split("\n - ");
for (let sMachine of asMachines) {
if (!sMachine) continue;
let machine = {};
machine.title = sTitle;
machine.directory = sDir;
machine.category = sCategory;
let aProps = sMachine.split("\n ");
processProperties(machine, aProps, 0, "");
/*
* When no "config" property is provided, a "machine.xml" in the same directory is implied.
*/
if (!machine.config) machine.config = path.join(sDir, "machine.xml");
if (fDebug) printf("%2j\n", machine);
aMachines.push(machine);
}
}
}
let launch = {};
launch.version = "0.1.0";
launch.configurations = [];
let aTitles = {}, aDirectories = {};
for (let i = 0; i < aMachines.length; i++) {
let machine = aMachines[i];
/*
* We're letting this slide because there are a variety of pages (eg, machine "array" demos)
* that contain multiple machines; such pages need only one launch entry.
*/
if (aDirectories[machine.directory]) {
// printf('warning: duplicate machine directory "%s"\n', machine.directory);
continue;
}
aDirectories[machine.directory] = machine;
if (aTitles[machine.title]) {
printf('warning: duplicate machine title "%s"\n', machine.title);
printf('current: %s\n', machine.directory);
printf('original: %s\n\n', aTitles[machine.title].directory);
continue;
}
aTitles[machine.title] = machine;
let entry = {};
entry.name = machine.title;
if (machine.category) entry.name = machine.category + ": " + entry.name;
entry.type = "chrome";
entry.request = "launch";
entry.url = "http://localhost:8088" + machine.directory;
entry.webroot = '$' + "{workspaceFolder}";
launch.configurations.push(entry);
}
printf("%2j\n", launch);
}

/**
* processProperties(obj, aProps, iProp, sIndent)
*
* @param {Object} obj (the object to update)
* @param {Array.<string>} aProps (array of property strings)
* @param {number} iProp (index within aProps to process)
* @param {string} sIndent (some quantity of spaces, initially none)
* @return {number} (updated iProp)
*/
function processProperties(obj, aProps, iProp, sIndent)
{
let re = new RegExp("^" + sIndent + "([^ :]*):\\s*(.*)");
while (iProp < aProps.length) {
let sProp = aProps[iProp];
let prop = re.exec(sProp);
if (!prop) break;
iProp++;
if (!prop[2]) {
obj[prop[1]] = {};
iProp = processProperties(obj[prop[1]], aProps, iProp, sIndent + " ");
} else {
obj[prop[1]] = prop[2];
}
}
return iProp;
}

if (args.argc > 1) {
let argv = args.argv;
processMachines(argv[1], argv['debug']);
process.exit(0);
}

printf("usage: node machines.js [directory]\n");
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
/**
* @fileoverview Node command-line XML extraction tool
* @author <a href="mailto:[email protected]">Jeff Parsons</a>
* @version 1.0
* Created 2017-Jun-20
*
* Copyright © 2012-2018 Jeff Parsons <[email protected]>
* @copyright © 2012-2018 Jeff Parsons
*
* This file is part of PCjs, a computer emulation software project at <https://www.pcjs.org>.
*
Expand All @@ -30,9 +27,11 @@
* as to their contents.
*/

"use strict";

var fs = require("fs");
var defines = require("../../shared/lib/defines");
var Str = require("../../../modules/shared/lib/strlib");
var Str = require("../../shared/lib/strlib");
var Proc = require("../../shared/lib/proclib");
var args = Proc.getArgs();

Expand All @@ -47,6 +46,11 @@ function printf(format, ...args)
process.stdout.write(Str.sprintf(format, ...args));
}

/**
* processManifest(sManifest)
*
* @param {string} sManifest
*/
function processManifest(sManifest)
{
try {
Expand Down Expand Up @@ -127,4 +131,4 @@ if (args.argc > 1) {
process.exit(0);
}

printf("usage: node disklist.js <manifest>\n");
printf("usage: node manifest.js [manifest]\n");
17 changes: 15 additions & 2 deletions modules/shared/lib/strlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ class Str {
* We could use "arg |= 0", but there may be some value to supporting integers > 32 bits.
*
* Also, unlike the 'X' and 'x' hexadecimal cases, there's no need to explicitly check for a string
* arguments, because the call to trunc() automatically coerces any string value to a (decimal) number.
* arguments, because Math.trunc() automatically coerces any string value to a (decimal) number.
*/
arg = Math.trunc(arg);
/* falls through */
Expand All @@ -672,11 +672,24 @@ class Str {
buffer += s;
break;

case 'j':
/*
* 'j' is one of our non-standard extensions to the sprintf() interface; it signals that
* the caller is providing an Object that should be rendered as JSON. If a width is included
* (eg, "%2j"), it's used as an indentation value; otherwise, no whitespace is added.
*/
buffer += JSON.stringify(arg, null, width || null);
break;

case 'c':
arg = String.fromCharCode(arg);
/* falls through */

case 's':
/*
* 's' includes some non-standard behavior: if the argument is not actually a string, we
* "coerce" it to a string, using its associated toString() method.
*/
if (typeof arg == "string") {
while (arg.length < width) {
if (flags.indexOf('-') >= 0) {
Expand Down Expand Up @@ -722,7 +735,7 @@ class Str {

default:
/*
* The supported ANSI C set of types: "dioxXucsfeEgGpn%"
* For reference purposes, the standard ANSI C set of types is "dioxXucsfeEgGpn%"
*/
buffer += "(unrecognized printf type %" + type + ")";
break;
Expand Down
17 changes: 15 additions & 2 deletions versions/c1pjs/1.71.5/c1p-uncompiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ class Str {
* We could use "arg |= 0", but there may be some value to supporting integers > 32 bits.
*
* Also, unlike the 'X' and 'x' hexadecimal cases, there's no need to explicitly check for a string
* arguments, because the call to trunc() automatically coerces any string value to a (decimal) number.
* arguments, because Math.trunc() automatically coerces any string value to a (decimal) number.
*/
arg = Math.trunc(arg);
/* falls through */
Expand All @@ -826,11 +826,24 @@ class Str {
buffer += s;
break;

case 'j':
/*
* 'j' is one of our non-standard extensions to the sprintf() interface; it signals that
* the caller is providing an Object that should be rendered as JSON. If a width is included
* (eg, "%2j"), it's used as an indentation value; otherwise, no whitespace is added.
*/
buffer += JSON.stringify(arg, null, width || null);
break;

case 'c':
arg = String.fromCharCode(arg);
/* falls through */

case 's':
/*
* 's' includes some non-standard behavior: if the argument is not actually a string, we
* "coerce" it to a string, using its associated toString() method.
*/
if (typeof arg == "string") {
while (arg.length < width) {
if (flags.indexOf('-') >= 0) {
Expand Down Expand Up @@ -876,7 +889,7 @@ class Str {

default:
/*
* The supported ANSI C set of types: "dioxXucsfeEgGpn%"
* For reference purposes, the standard ANSI C set of types is "dioxXucsfeEgGpn%"
*/
buffer += "(unrecognized printf type %" + type + ")";
break;
Expand Down
2 changes: 1 addition & 1 deletion versions/c1pjs/1.71.5/c1p.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit 828bf66

Please sign in to comment.