const fs = require('fs'); const path = require('path'); const sourceFile = 'CB_IMGPSScanImp.pas.bk'; const base_path = 'doc/curtis/prompt/scanimpl_analysis'; const remainingsFile = path.join(base_path, 'scanimpl_annalysis.remainings.txt'); const modules = [ 'ScannerController', 'BusinessLogic', 'ImageProcessor', 'TransportManager', 'UIView' ]; function validate() { const lines = fs.readFileSync(sourceFile, 'utf8').split('\n'); const totalLines = lines.length; const allCapturedMethods = []; modules.forEach(mod => { const filePath = path.join(base_path, `scanimpl_annalysis.${mod}.json`); if (fs.existsSync(filePath)) { const methods = JSON.parse(fs.readFileSync(filePath, 'utf8')); allCapturedMethods.push(...methods); } }); const coveredLines = new Uint8Array(totalLines + 1); allCapturedMethods.forEach(m => { const sourceLine = lines[m.lIndex - 1].trim(); if (sourceLine !== m.matcher) { console.error(`Mismatch at line ${m.lIndex}: Expected "${m.matcher}", got "${sourceLine}"`); } for (let i = m.lIndex; i <= m.rIndex; i++) { coveredLines[i] = 1; } }); let remainings = []; let start = -1; for (let i = 1; i <= totalLines; i++) { if (!coveredLines[i]) { if (start === -1) start = i; } else { if (start !== -1) { remainings.push({lIndex: start, rIndex: i - 1}); start = -1; } } } if (start !== -1) remainings.push({lIndex: start, rIndex: totalLines}); const remainingsText = remainings.map(r => { const content = lines.slice(r.lIndex - 1, r.rIndex).join('\n'); return `[Lines ${r.lIndex} - ${r.rIndex}]\n${content}\n----------------------------------------\n`; }).join('\n'); fs.writeFileSync(remainingsFile, remainingsText, 'utf8'); console.log(`Validation complete. Remainings saved to ${remainingsFile}`); } validate();