/** * One decompile of a WinHelp file: helpdeco in a fresh instance with the .hlp * in its in-memory file system, returning every file it wrote (the RTF * topics, the project file, pictures, phrases, icon, baggage). Used by * worker.mjs in the browser and by the site's tests in Node. * * helpdeco stops to ask "Press CR to continue at your own risk" when part of * a help file is damaged; stdin always answers with a carriage return, so it * carries on and the page reports what it said. * * Written for johnmcm.com (2026); part of the module published at /source/helpdeco/. */ const CR = 13; /** * Decompiles `bytes` (a .hlp called `name`). `createHelpdeco` is the module * factory; `options` is passed to it (locateFile, instantiateWasm...). * Resolves { code, files: { name, data }[], log: string[] }. */ export async function decompile(createHelpdeco, name, bytes, options = {}) { const log = []; const m = await createHelpdeco({ print: (line) => log.push(line), printErr: (line) => log.push(line), stdin: () => CR, ...options, }); m.FS.mkdir('/w'); m.FS.chdir('/w'); m.FS.writeFile(`/w/${name}`, bytes); let code = 0; try { code = m.callMain([name, '-y']) ?? 0; } catch (err) { if (typeof err?.status === 'number') code = err.status; else throw err; } const files = []; for (const f of m.FS.readdir('/w')) { if (f === '.' || f === '..' || f === name) continue; const path = `/w/${f}`; if (m.FS.isFile(m.FS.stat(path).mode)) files.push({ name: f, data: m.FS.readFile(path) }); } return { code, files, log }; }