sbbs/frames_check.js

122 lines
2.9 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 many SBBS definitions
require('sbbsdefs.js','SS_USERON');
// Load text.dat definitions
require('text.js','TOTAL_TEXT');
// Key definitions
require('key_defs.js','KEY_ESC');
ansi = load({},'ansiterm_lib.js');
load('ansitex/load/funcs.js');
2022-12-09 06:19:33 +00:00
// ANSItex specific includes
require('ansitex/load/defs.js','ACTION_EXIT');
require('ansitex/load/frame-ansi.js','FRAME_ANSI');
require('ansitex/load/frame-viewdata.js','FRAME_VIEWDATA');
/* parse command arguments */
if (argv.length !== 1) {
writeln('! ERROR: Need only 1 argument');
exit(1);
}
//const vtx_ext = 'tex';
const vtx_src = 'bin';
const ans_src = 'ans';
const page = argv.shift();
const vtx_srcname = page+'.'+vtx_src;
const ans_srcname = page+'.'+ans_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
vtx = new FrameViewdata();
vtx.load(page);
if (! vtx.content) {
writeln('- ! ERROR: VTX File doesnt exist? :'+page);
errors = true;
} else {
// Check content between TEX/ANS & VTX/BIN
vtx_srcfile = new File(system.mods_dir+'ansitex/text/'+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 = base64_decode(vtx.content);
var y = vtx_srcfile.read();
// Check Content
if (x !== y) {
writeln(' - Page Content :'+md5_calc(x));
writeln(' - Source Content :'+md5_calc(y));
writeln('- ! WARNING: Content Differs.'+base64_decode(vtx.content));
errors = true;
}
}
}
ans = new FrameAnsi();
ans.load(page);
if (! ans.content) {
writeln('- ! ERROR: ANS File doesnt exist? :'+page);
errors = true;
} else {
// Check content between TEX/ANS & VTX/BIN
ans_srcfile = new File(system.mods_dir+'ansitex/text/'+ans_srcname);
if (! ans_srcfile.exists || ! ans_srcfile.open('r')) {
writeln('- ! ERROR: VTX SRC File doesnt exist? :'+ans_srcname);
errors = true;
} else {
writeln('- LOADING: ANS Source :'+ans_srcname);
var x = base64_decode(ans.content);
var y = ans_srcfile.read();
if (x !== y) {
// Check Content
writeln(' - Page Content :'+md5_calc(x,true));
writeln(' - Source Content :'+md5_calc(y,true));
writeln('- ! WARNING: Content Differs.'+base64_decode(vtx.content));
errors = true;
}
}
}
// Checking keys
if (vtx.content && ans.content)
for each (var k in ['frame','index','key','cost','owner','type','isPublic','isAccessible']) {
if (JSON.stringify(vtx[k]) !== JSON.stringify(ans[k])) {
writeln('- Checking KEY: '+k);
writeln(' - ! VTX: '+vtx[k]);
writeln(' - ! ANS: '+ans[k]);
errors = true;
}
}
if (errors)
exit(1);
else
writeln('= OK');