Updated MarkOut and HTMLOut components to use embedPC() with the new 'parms' parameter instead of the old 'state' parameter.
This allows us to continue using the Node web server to debug machines that are launched using new YAML-based Markdown machines settings, the most important being 'automount' (otherwise those machines might not be loaded with the correct disks)
This commit is contained in:
parent
79c9b4beca
commit
1ca377fb68
9 changed files with 96 additions and 41 deletions
|
|
@ -1850,7 +1850,10 @@ HTMLOut.prototype.processMachines = function(aMachines, done)
|
|||
|
||||
var sScriptEmbed = "";
|
||||
if (infoMachine['func']) {
|
||||
sScriptEmbed = '<script type="text/javascript">' + 'window.' + infoMachine['func'] + '("' + infoMachine['id'] + '","' + infoMachine['xml'] + '"' + (infoMachine['xsl']? (',"' + infoMachine['xsl'] + '"') : ',""') + (infoMachine['state']? (',"' + infoMachine['state'] + '"') : '') + ');</script>';
|
||||
sScriptEmbed = '<script type="text/javascript">' + 'window.' + infoMachine['func'];
|
||||
sScriptEmbed += "('" + infoMachine['id'] + "','" + infoMachine['xml'] + "'";
|
||||
sScriptEmbed += (infoMachine['xsl']? (",'" + infoMachine['xsl'] + "'") : ",''");
|
||||
sScriptEmbed += (infoMachine['parms']? (",'" + infoMachine['parms'] + "'") : '') + ');</script>';
|
||||
}
|
||||
|
||||
var asFiles = [];
|
||||
|
|
|
|||
|
|
@ -231,14 +231,14 @@ MarkOut.setOptions = function(options)
|
|||
* The infoMachine object should contain, at a minimum:
|
||||
*
|
||||
* {
|
||||
* 'class': sMachineClass, // eg, "pc"
|
||||
* 'func': sMachineFunc,
|
||||
* 'id': sMachineID,
|
||||
* 'xml': sMachineXMLFile,
|
||||
* 'xsl': sMachineXSLFile,
|
||||
* 'version': sMachineVersion, // eg, "1.13.0"
|
||||
* 'class': sMachineClass, // eg, "pc"
|
||||
* 'func': sMachineFunc,
|
||||
* 'id': sMachineID,
|
||||
* 'xml': sMachineXMLFile,
|
||||
* 'xsl': sMachineXSLFile,
|
||||
* 'version': sMachineVersion,// eg, "1.13.0"
|
||||
* 'debugger': fDebugger, // eg, false
|
||||
* 'state': sMachineState
|
||||
* 'parms': sMachineParms
|
||||
* }
|
||||
*
|
||||
* This is an internal function, used by convertMDMachineLinks() to record all the machines defined
|
||||
|
|
@ -375,16 +375,54 @@ MarkOut.prototype.convertMD = function(sIndent)
|
|||
for (var iMachine = 0; iMachine < asMachines.length; iMachine++) {
|
||||
if (!asMachines[iMachine]) continue;
|
||||
var id = null;
|
||||
var aOptions, machine = {};
|
||||
var reOption = /([^\s]+):\s*([^\n]*)/g;
|
||||
var aOptions, aaOptions = [], machine = {};
|
||||
var reOption = /([ \t]*)([^\s]+):[ \t]*([^\n]*)/g;
|
||||
while (aOptions = reOption.exec(asMachines[iMachine])) {
|
||||
if (!id && aOptions[1] == "id") {
|
||||
id = aOptions[2];
|
||||
}
|
||||
else {
|
||||
machine[aOptions[1]] = aOptions[2];
|
||||
}
|
||||
aaOptions.push(aOptions);
|
||||
}
|
||||
for (var iOption = 0; iOption < aaOptions.length; iOption++) {
|
||||
var aOptions = aaOptions[iOption];
|
||||
var sSpace = aOptions[1], sName = aOptions[2], sValue = aOptions[3];
|
||||
if (!id && sName == 'id') {
|
||||
id = sValue;
|
||||
} else if (sName == 'automount') {
|
||||
/*
|
||||
* I take a simplistic approach to parsing the object definition associated with "automount",
|
||||
* because I know it only consist of 1 or more drive letters, each of which may be followed by
|
||||
* 1 or 2 additional properties (eg, "name" and "path"). If we need to support other JSON
|
||||
* object definitions in the future, this will have to be generalized.
|
||||
*
|
||||
* Here's an example of "automount" output:
|
||||
*
|
||||
* {"A":{"name":"OS/2 FOOTBALL Boot Disk (v7.68.17)","path":"/disks/pc/os2/misc/football/debugger/FOOTBALL-7.68.17.json"}}
|
||||
*/
|
||||
sValue = '{';
|
||||
var cDrives = 0, cProps = 0, iProp;
|
||||
for (iProp = iOption + 1; iProp < aaOptions.length; iProp++) {
|
||||
var sPropSpace = aaOptions[iProp][1];
|
||||
if (sPropSpace.length <= sSpace.length) break;
|
||||
var sPropName = aaOptions[iProp][2];
|
||||
var sPropValue = aaOptions[iProp][3];
|
||||
if (!sPropValue) {
|
||||
if (cProps) sValue += '}';
|
||||
if (cDrives++) sValue += ',';
|
||||
sValue += '"' + sPropName + '":{';
|
||||
cProps = 0;
|
||||
} else {
|
||||
if (cProps++) sValue += ',';
|
||||
sValue += '"' + sPropName + '":"' + sPropValue + '"';
|
||||
}
|
||||
}
|
||||
if (cProps++) sValue += '}';
|
||||
sValue += '}';
|
||||
iOption = iProp - 1;
|
||||
}
|
||||
machine[sName] = sValue;
|
||||
}
|
||||
/*
|
||||
* Any 'state' and 'automount' properties must now be merged into a 'parms' property.
|
||||
*/
|
||||
machine['parms'] = '{state:"' + (machine['state'] || "") + '",autoMount:' + machine['automount'] + '}';
|
||||
if (id) this.aMachineDefs[id] = machine;
|
||||
}
|
||||
}
|
||||
|
|
@ -952,7 +990,7 @@ MarkOut.prototype.convertMDImageLinks = function(sBlock, sIndent)
|
|||
* Before we call convertMDLinks() to process any normal Markdown-style links, we first look for our own
|
||||
* special flavor of "machine" Markdown links; ie:
|
||||
*
|
||||
* [IBM PC](/devices/pc/machine/5150/mda/64kb/ "PCjs:demoPC:stylesheet:version:options:state")
|
||||
* [IBM PC](/devices/pc/machine/5150/mda/64kb/ "PCjs:demoPC:stylesheet:version:options:parms")
|
||||
*
|
||||
* where a special title attribute triggers generation of an embedded machine rather than a link.
|
||||
*
|
||||
|
|
@ -965,6 +1003,11 @@ MarkOut.prototype.convertMDImageLinks = function(sBlock, sIndent)
|
|||
*
|
||||
* If the link ends with a slash, then it's an implied reference to a "machine.xml".
|
||||
*
|
||||
* UPDATE: Since parms containing JSON may also contain colons, machine Markdown links may now use '|'
|
||||
* instead of ':' as separators; eg:
|
||||
*
|
||||
* [IBM PC](/devices/pc/machine/5150/mda/64kb/ "PCjs|demoPC|stylesheet|version|options|parms")
|
||||
*
|
||||
* Granted, there are a number of things we could be smarter about. First, you probably don't care about the
|
||||
* ID for the <div>; it's purely a mechanism for telling the script where to embed the machine, so we could
|
||||
* auto-generate an ID for you, but on the other hand, there might actually be situations where you want to style
|
||||
|
|
@ -989,7 +1032,7 @@ MarkOut.prototype.convertMDImageLinks = function(sBlock, sIndent)
|
|||
MarkOut.prototype.convertMDMachineLinks = function(sBlock)
|
||||
{
|
||||
var aMatch, sReplacement;
|
||||
var sMachine, sMachineID, sMachineXMLFile, sMachineXSLFile, sMachineVersion, sMachineOptions, sMachineState;
|
||||
var sMachine, sMachineID, sMachineXMLFile, sMachineXSLFile, sMachineVersion, sMachineOptions, sMachineParms;
|
||||
|
||||
/*
|
||||
* Before we start looking for Markdown-style machine links, see if there are any Liquid-style machines,
|
||||
|
|
@ -1008,8 +1051,8 @@ MarkOut.prototype.convertMDMachineLinks = function(sBlock)
|
|||
sMachineXMLFile = machine['config'] || "machine.xml";
|
||||
sMachineXSLFile = machine['template'] || "";
|
||||
sMachineVersion = (machine['uncompiled'] && machine['uncompiled'] == "true"? "uncompiled" : "");
|
||||
sMachineState = machine['state'] || "";
|
||||
sReplacement = "[Embedded PC](" + sMachineXMLFile + ' "' + sMachine + 'js:' + sMachineID + ':' + sMachineXSLFile + '::' + sMachineOptions + ':' + sMachineState + '")';
|
||||
sMachineParms = machine['parms'] || "";
|
||||
sReplacement = "[Embedded PC](" + sMachineXMLFile + ' "' + sMachine + 'js|' + sMachineID + '|' + sMachineXSLFile + '||' + sMachineOptions + '|' + sMachineParms + '")';
|
||||
}
|
||||
sBlock = sBlock.replace(aMatch[0], sReplacement);
|
||||
reIncludes.lastIndex = 0; // reset lastIndex, since we just modified the string that reIncludes is iterating over
|
||||
|
|
@ -1019,7 +1062,7 @@ MarkOut.prototype.convertMDMachineLinks = function(sBlock)
|
|||
* Start looking for Markdown-style machine links now...
|
||||
*/
|
||||
var cMatches = 0;
|
||||
var reMachines = /\[(.*?)]\((.*?)\s*"(PC|C1P)js:(.*?)"\)/gi;
|
||||
var reMachines = /\[(.*?)]\((.*?)\s*"(PC|C1P)js[:|](.*?)"\)/gi;
|
||||
|
||||
while ((aMatch = reMachines.exec(sBlock))) {
|
||||
|
||||
|
|
@ -1029,14 +1072,14 @@ MarkOut.prototype.convertMDMachineLinks = function(sBlock)
|
|||
sMachine = aMatch[3].toUpperCase();
|
||||
var sMachineFunc = "embed" + sMachine;
|
||||
var sMachineClass = sMachine.toLowerCase();
|
||||
var aMachineParms = aMatch[4].split(':');
|
||||
var aMachineParms = aMatch[4].split(aMatch[4].indexOf('|') > 0? '|' : ':');
|
||||
var sMachineMessage = "Waiting for " + sMachine + "js to load";
|
||||
|
||||
sMachineID = aMachineParms[0];
|
||||
sMachineXSLFile = aMachineParms[1] || "";
|
||||
sMachineVersion = aMachineParms[2] || this.sMachineVersion;
|
||||
sMachineOptions = aMachineParms[3] || "";
|
||||
sMachineState = aMachineParms[4] || "";
|
||||
sMachineParms = aMachineParms[4] || "";
|
||||
var aMachineOptions = sMachineOptions.split(',');
|
||||
var fDebugger = (aMachineOptions.indexOf("debugger") >= 0);
|
||||
|
||||
|
|
@ -1071,14 +1114,14 @@ MarkOut.prototype.convertMDMachineLinks = function(sBlock)
|
|||
cMatches++;
|
||||
|
||||
this.addMachine({
|
||||
'class': sMachineClass, // eg, a machine class, such as "pc" or "c1p"
|
||||
'func': sMachineFunc,
|
||||
'id': sMachineID,
|
||||
'xml': sMachineXMLFile,
|
||||
'xsl': sMachineXSLFile,
|
||||
'version': sMachineVersion, // eg, "1.10", "*" to select the current version, or "uncompiled"; "*" is the default
|
||||
'class': sMachineClass, // eg, a machine class, such as "pc" or "c1p"
|
||||
'func': sMachineFunc,
|
||||
'id': sMachineID,
|
||||
'xml': sMachineXMLFile,
|
||||
'xsl': sMachineXSLFile,
|
||||
'version': sMachineVersion,// eg, "1.10", "*" to select the current version, or "uncompiled"; "*" is the default
|
||||
'debugger': fDebugger, // eg, true or false; false is the default
|
||||
'state': sMachineState}
|
||||
'parms': sMachineParms}
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -131,13 +131,22 @@ function parseXML(sXML, sXMLFile, idMachine, sParms, fResolve, display, done)
|
|||
*/
|
||||
if (!sParms) {
|
||||
sParms = '{';
|
||||
} else if (sParms.substr(0, 1) == '{') {
|
||||
} else if (sParms.slice(-1) == '}') {
|
||||
sParms = sParms.slice(0, -1);
|
||||
if (sParms.length > 1) sParms += ',';
|
||||
} else { // backward compatibility: sParms is actually sStateFile
|
||||
} else { // sParms must just be a "state" file, so encode it as a "state" property
|
||||
sParms = '{state:"' + sParms + '",';
|
||||
}
|
||||
sParms += 'url:"' + sURL + '"}';
|
||||
/*
|
||||
* Note that while we no longer generate a machine XML file with a "state" attribute (because it's
|
||||
* encoded inside the "parms" attribute), the XSL file must still cope with "state" attributes inside
|
||||
* other XML files; for example, manifest XML files like /apps/pc/1981/visicalc/manifest.xml contain
|
||||
* machine elements with "state" attributes that must still be passed down to the computer element
|
||||
* "the old fashioned way".
|
||||
*
|
||||
* Until/unless that changes, components.xsl cannot be simplified as much as I might have hoped.
|
||||
*/
|
||||
sXML = sXML.replace(/(<machine[^>]*\sid=)(['"]).*?\2/, "$1$2" + idMachine + "$2" + (sParms? " parms='" + sParms + "'" : "") + (sURL? ' url="' + sURL + '"' : ''));
|
||||
}
|
||||
/*
|
||||
|
|
|
|||
Loading…
Reference in a new issue