const fs = require('fs');
|
const path = require('path');
|
|
const sourceFile = 'CB_IMGPSScanImp.pas.bk';
|
const base_path = 'doc/curtis/prompt/scanimpl_analysis';
|
const outputFile = path.join(base_path, 'step1_raw_methods.json');
|
|
function extract() {
|
const lines = fs.readFileSync(sourceFile, 'utf8').split('\n');
|
const totalLines = lines.length;
|
const methods = [];
|
const regex = /^(procedure|function)\s+TCB_IMGPSScanX\./i;
|
|
for (let i = 0; i < totalLines; i++) {
|
const line = lines[i];
|
if (regex.test(line)) {
|
methods.push({
|
matcher: line.trim(),
|
lIndex: i + 1,
|
rIndex: -1 // To be filled
|
});
|
}
|
}
|
|
for (let i = 0; i < methods.length; i++) {
|
if (i < methods.length - 1) {
|
methods[i].rIndex = methods[i + 1].lIndex - 1;
|
} else {
|
methods[i].rIndex = totalLines;
|
}
|
}
|
|
if (!fs.existsSync(base_path)) {
|
fs.mkdirSync(base_path, {recursive: true});
|
}
|
fs.writeFileSync(outputFile, JSON.stringify(methods, null, 2), 'utf8');
|
console.log(`Extracted ${methods.length} methods to ${outputFile}`);
|
}
|
|
extract();
|