sbbs/tools/frames_check.js

145 lines
3.3 KiB
JavaScript
Raw Normal View History

/**
* This will go through our videotex and ansitex frames and check for inconsistencies.
*
* We'll check for:
* + Mismatched metadata items
* + Out of sync content
*/
load('ansitex/load/funcs.js');
// Our page handler
load('ansitex/load/page.js');
/* parse command arguments */
if (argv.length !== 1) {
writeln('! ERROR: Need only 1 argument');
exit(1);
}
//const vtx_ext = 'tex';
const vtx_src = 'bin';
const tex_src = 'ans';
const page = argv.shift();
const vtx_srcname = page+'.'+vtx_src;
const tex_srcname = page+'.'+tex_src;
var errors = false;
PAGE_FILE_PREFX = /^[0-9]+[a-z]$/;
if (! PAGE_FILE_PREFX.test(page)) {
writeln('PAGE is not a frame: '+page);
exit(2);
}
writeln('Comparing Frame: '+page);
// Load frame
require(ANSITEX_HOME+'/load/session/viewdata.js','SESSION_VIEWDATA');
vtx = new Page();
if (! vtx.import(FRAMES_HOME+SESSION_EXT+'/'+page)) {
writeln('- ! ERROR: VTX File doesnt exist? :'+page);
errors = true;
} else {
// Check content between TEX/ANS & VTX/BIN
vtx_srcfile = new File(FRAMES_HOME+SESSION_EXT+'/'+vtx_srcname);
if (! vtx_srcfile.exists || ! vtx_srcfile.open('r')) {
writeln('- ! ERROR: VTX SRC File doesnt exist? :'+vtx_srcname);
errors = true;
} else {
writeln('- LOADING: VTX Source :'+vtx_srcname);
var x = md5_calc(vtx.raw);
var y = md5_calc(vtx_srcfile.read());
// Check Content
if (x !== y) {
writeln(' - Page Content :'+x);
writeln(' - Source Content :'+y);
writeln('- ! WARNING: Content Differs.');
errors = true;
} else {
writeln('= Source matches.');
}
}
}
require(ANSITEX_HOME+'/load/session/ansitex.js','SESSION_ANSITEX');
tex = new Page();
if (! tex.import(FRAMES_HOME+SESSION_EXT+'/'+page)) {
writeln('- ! ERROR: TEX File doesnt exist? :'+page);
errors = true;
} else {
// Check content between TEX/ANS & VTX/BIN
tex_srcfile = new File(FRAMES_HOME+SESSION_EXT+'/'+tex_srcname);
if (! tex_srcfile.exists || ! tex_srcfile.open('r')) {
writeln('- ! ERROR: TEX SRC File doesnt exist? :'+tex_srcname);
errors = true;
} else {
writeln('- LOADING: TEX Source :'+tex_srcname);
var x = md5_calc(tex.raw);
var y = md5_calc(tex_srcfile.read());
if (x !== y) {
// Check Content
writeln(' - Page Content :'+x);
writeln(' - Source Content :'+y);
writeln('- ! WARNING: Content Differs.');
errors = true;
} else {
writeln('= Source matches.');
}
}
}
// Checking keys
if (vtx.raw && tex.raw) {
writeln('- Checking Page: ');
if (vtx.name.toString() !== tex.name.toString()) {
writeln(' - ! VTX: '+vtx.name.toString());
writeln(' - ! TEX: '+tex.name.toString());
} else {
writeln(' = PAGE: '+vtx.name.toString());
}
for each (var k in ['key','cost','type']) {
writeln('- Checking KEY: '+k);
if (JSON.stringify(vtx[k]) !== JSON.stringify(tex[k])) {
writeln(' - ! VTX: '+vtx[k]);
writeln(' - ! TEX: '+tex[k]);
errors = true;
} else {
writeln(' = KEY: '+vtx[k]);
}
}
for each (var k in ['isAccessible','isPublic']) {
writeln('- Checking Property: '+k);
if (JSON.stringify(vtx.__properties__[k]) !== JSON.stringify(tex.__properties__[k])) {
writeln(' - ! VTX: '+vtx.__properties__[k]);
writeln(' - ! TEX: '+tex.__properties__[k]);
errors = true;
} else {
writeln(' = KEY: '+vtx.__properties__[k]);
}
}
}
if (errors)
exit(1);
else
writeln('= OK');