#!/usr/bin/env node /** * @fileoverview Node command-line XML extraction tool * @author Jeff Parsons * @version 1.0 * Created 2017-Jun-20 * * Copyright © 2012-2017 Jeff Parsons * * This file is part of PCjs, a computer emulation software project at . * * 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 . * * 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 * . * * 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. */ var fs = require("fs"); /** * println(s) * * @param {*} s */ function println(s) { console.log(s); } function processManifest(sManifest) { try { var sXML = fs.readFileSync(sManifest, 'utf-8'); } catch(err) { println("error: unable to read manifest: " + sManifest); return; } var aMatchDisks = sXML.match(/]*>[\S\s]*?<\/disk>/g); if (!aMatchDisks) { println("warning: no disks found in: " + sManifest); return; } for (var iDisk = 0; iDisk < aMatchDisks.length; iDisk++) { var sDisk = aMatchDisks[iDisk]; var matchDir = sDisk.match(/dir="(.*?)"/); var matchLink = sDisk.match(/href="(.*?)"/); var matchDiskName = sDisk.match(/(.*?)<\/name>/); var aMatchFiles = sDisk.match(/]*>[\S\s]*?<\/file>/g); var sDiskName = matchDiskName && matchDiskName[1]; if (!aMatchFiles || !sDiskName) { println("warning: no files in disk: " + sDiskName); return; } println("### Directory of " + sDiskName + "\n"); println("\t Volume in drive A " + (matchDiskName? ("is " + matchDiskName[1]) : "has no label")); println("\t Directory of A:\\\n\t"); for (var iFile = 0; iFile < aMatchFiles.length; iFile++) { var sFile = aMatchFiles[iFile]; var matchSize = sFile.match(/size="([0-9]*)"/); var matchTime = sFile.match(/time="([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9]) ([0-9][0-9]):([0-9][0-9]):([0-9][0-9])"/); var matchFileName = sFile.match(/>(.*?)= 0) { sBaseName = sFileName.substr(0, i); sExtension = sFileName.substr(i + 1); } sBaseName = (sBaseName + " ").substr(0, 9); sExtension = (sExtension + " ").substr(0, 3); sSize = (" " + sSize).slice(-9); var iMonth = +matchTime[2]; var sDate = (" " + iMonth).slice(-4) + '-' + matchTime[3] + '-' + matchTime[1].substr(2); var iHour = +matchTime[4]; var sSuffix; if (iHour < 12) { sSuffix = "a"; if (!iHour) iHour = 12; } else { sSuffix = "p"; if (iHour > 12) iHour -= 12; } var sTime = (" " + iHour).slice(-4) + ':' + matchTime[5] + sSuffix; println("\t" + sBaseName + sExtension + sSize + sDate + sTime); } println(""); } } processManifest("../../../disks/pcx86/tools/microsoft/pascal/4.00/manifest.xml");