'use strict'; const fs = require('fs'); const _ = require('lodash'); if (process.argv.length !== 3) { console.log(`Usage: node ${process.argv[1]} FILENAME`); process.exit(1); } const file = fs.readFileSync(process.argv[2], 'utf-8'); // { // 'context': { // '_X.': { // '1': ['App', 'args', 4], ... // }, ... // }, ... // } // let dp = {}; function addApp (c, e, p, app, args, usage) { if (!dp[c]) { dp[c] = {}; } if (!dp[c][e]) { dp[c][e] = {}; } dp[c][e][p] = [app, args, usage]; } let context = '---'; let exten; for (let line of file.split('\n')) { // new extension starts let matches = line.match(/'([^']+)'(?: \(CID match '[^']*'\))? =>\s+(\d+)\.\s(\w+)\((.*)\) (\d+)/); if (matches) { // extension matches[1] is not used // priority matches[2] is not used let prio, app, args, usage; [, exten, prio, app, args, usage] = matches; addApp(context, exten, prio, app, args, usage); continue; } // next line describing extension matches = line.match(/^\s+(?:\[\w+\])?\s+(\d+)\.\s(\w+)\((.*)\) (\d+)/); if (matches) { let [, prio, app, args, usage] = matches; addApp(context, exten, prio, app, args, usage); continue; } // start of a new context matches = line.match(/^\[ Context '([^']+)' created by/); if (matches) { context = matches[1]; continue; } } const colors = require('ansi-256-colors'); function getColor(usage) { let fg = [0, 0, 0]; let bg; if (usage == 0) { bg = [3, 2, 2]; } else if (usage > 0 && usage < 10 ) { bg = [1, 3, 1]; } else if (usage > 10) { bg = [1, 5, 1]; } return function (string) { return colors.fg.getRgb.apply(colors.fg, fg) + colors.bg.getRgb.apply(colors.bg, bg) + string + colors.reset; } } let covered = 0, uncovered = 0; _.each(dp, (extens, context) => { /* // skip [..._] generated contexts if (context.match(/\d+$/)) { return; } */ console.log(`[${context}]`); _.each(extens, (prios, exten) => { _.each(prios, ([app, data, usage], prio) => { usage = +usage; if (usage) { covered++; } else { uncovered++; } console.log(getColor(usage)(`exten => ${exten},${prio},${app}(${data})`)); }); }); console.log(''); }); console.log(`Covered: ${covered}/${covered + uncovered}, ${Math.floor(100*covered / (covered + uncovered))}%`);