/* 详列 scan-escapes 命中的上下文,用于人工判定是否真损坏 用法:node .sre-s23/scan-detail.js [ ...] */ const fs = require("fs"); const path = require("path"); const DIR = path.resolve(__dirname, "content"); const NAMED = { n: "换行", t: "TAB", r: "回车", b: "退格", f: "换页", v: "垂直制表", "0": "NUL" }; const DEGRADE = "+.*?$^[](){}|/dswSDW"; for (const name of process.argv.slice(2)) { const p = path.join(DIR, name + ".js"); if (!fs.existsSync(p)) { console.log(`… ${name} 不存在`); continue; } const src = fs.readFileSync(p, "utf8"); const tick = src.indexOf("`"); const body = tick < 0 ? "" : src.slice(tick); const lines = body.split("\n"); const out = []; /* 逐行找,并记录是否处于
/ 区域内 */
  let inPre = false;
  lines.forEach((ln, i) => {
    const opens = (ln.match(/]/g) || []).length;
    const closes = (ln.match(/<\/pre>/g) || []).length;
    const wasIn = inPre;
    if (opens) inPre = true;
    const here = wasIn || inPre;
    if (closes) inPre = false;
    if (!here) return;
    for (const m of ln.matchAll(/(? console.log(l)); if (out.length > 60) console.log(`  … 另 ${out.length - 60} 处`); }
  else console.log(`\n✓ ${name} 无命中`);
}