// _dump_codec_src.js —— 打印指定 codec 的 u7h / t7h 源码体(临时诊断用) // 用法: node _dump_codec_src.js 85183::Tl 85183::Rl ... 'use strict'; const fs = require('fs'); const path = require('path'); const SRC = path.join(__dirname, '..', 'src'); function MatchBrace(Src, Start) { let Depth = 0; for (let I = Start; I < Src.length; I++) { if (Src[I] === '{') Depth++; else if (Src[I] === '}') { Depth--; if (Depth === 0) return I; } } return -1; } function ClassMethod(Src, Cls, Kind) { const Head = new RegExp('\\(\\s*' + Cls.replace(/\$/g, '\\$') + '\\s*\\)\\.' + Kind + '\\s*=\\s*function\\s*\\([^)]*\\)\\s*\\{', 'g'); const Out = []; let M; while ((M = Head.exec(Src))) { const Start = M.index + M[0].length - 1; const End = MatchBrace(Src, Start); if (End > 0) Out.push(Src.slice(Start, End + 1)); } return Out; } for (const Key of process.argv.slice(2)) { const [Mod, Cls] = Key.split('::'); const File = path.join(SRC, (Mod.startsWith('module_') ? Mod : 'module_' + Mod) + '.js'); if (!fs.existsSync(File)) { console.log('!! 无源码 ' + File); continue; } const Src = fs.readFileSync(File, 'utf8'); console.log('=== ' + Key + ' ==='); for (const Kind of ['u7h', 't7h']) { const Bodies = ClassMethod(Src, Cls, Kind); if (!Bodies.length) { console.log(' [' + Kind + '] 未找到'); continue; } Bodies.forEach((B, I) => console.log(' [' + Kind + '#' + I + '] ' + B.replace(/\s+/g, ' '))); } }