Moved ansitex completely under mods/
This commit is contained in:
64
load/defs.js
Normal file
64
load/defs.js
Normal file
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* ANSItex definitions
|
||||
*/
|
||||
|
||||
var ACTION_RELOAD =1; /* Reload the current frame */
|
||||
var ACTION_GOTO =2; /* Goto a specific frame */
|
||||
var ACTION_BACKUP =3; /* Goto previous frame */
|
||||
var ACTION_NEXT =4; /* Goto next frame */
|
||||
var ACTION_TERMINATE =6; /* Terminate the session */
|
||||
var ACTION_SUBMITRF =7; /* Submit form contents */
|
||||
var ACTION_STAR =7; /* Star command entry */
|
||||
|
||||
var MODE_BL =1; /* Typing * command on baseline */
|
||||
|
||||
var FRAME_LENGTH =22; /* Length of a frame */
|
||||
var FRAME_WIDTH =80; /* Width of a frame */
|
||||
var FRAME_HEADER =56; /* Size of page owner (length) */
|
||||
var FRAME_PAGENUM =12; /* Size of page number (length with a-z) */
|
||||
var FRAME_COST =9; /* Size of cost (length without unit)*/
|
||||
var FRAME_COSTUNIT ='c'; /* Unit of cost */
|
||||
|
||||
var FRAME_TYPE_INFO ='i';
|
||||
var FRAME_TYPE_TERMINATE ='t';
|
||||
var FRAME_TYPE_EXTERNAL ='x';
|
||||
|
||||
var ERR_NOT_IMPLEMENTED = '\1RNOT IMPLEMENTED YET?';
|
||||
var ERR_ROUTE = '\1n\1h\1WMISTAKE? \1GTRY AGAIN OR TELL US ON *08';
|
||||
|
||||
var LOGIN_FRAMES = ['98b'];
|
||||
|
||||
// Our frame object
|
||||
function Frame(frame,index) {
|
||||
if (frame === undefined) {
|
||||
print('ERROR: frame not defined.');
|
||||
exit(1);
|
||||
}
|
||||
|
||||
this.version=1;
|
||||
this.frame=parseInt(frame);
|
||||
this.index=index ? index : 'a';
|
||||
this.owner=''; // @todo
|
||||
this.cost=0; // @todo
|
||||
this.content='';
|
||||
this.isPublic=false; // @todo
|
||||
this.isAccessible=false; // @todo
|
||||
this.type = FRAME_TYPE_INFO;
|
||||
this.key=[ null,null,null,null,null,null,null,null,null,null ];
|
||||
this.raw=function() {
|
||||
return base64_decode(this.content).replace(/(\r\n|\n|\r)/gm,'');
|
||||
}
|
||||
this.render=function() {
|
||||
owner = base64_decode(this.owner);
|
||||
|
||||
return '\1n'+owner+' '.repeat(FRAME_HEADER-console.strlen(owner))+'\1n '+
|
||||
'\1W\1H'+this.page+' '.repeat(FRAME_PAGENUM-this.page.length)+' '+
|
||||
'\1G\1H'+' '.repeat(FRAME_COST-this.cost.toString().length)+this.cost+FRAME_COSTUNIT+
|
||||
(console.screen_columns > 80 ? '\n\r' : '') +
|
||||
base64_decode(this.content);
|
||||
}
|
||||
|
||||
Object.defineProperty(this,'page', {
|
||||
get: function() {return pageStr({frame: this.frame, index: this.index }); }
|
||||
});
|
||||
}
|
189
load/funcs.js
Normal file
189
load/funcs.js
Normal file
@@ -0,0 +1,189 @@
|
||||
if (!String.prototype.repeat) {
|
||||
String.prototype.repeat = function(count) {
|
||||
'use strict';
|
||||
if (this == null) {
|
||||
throw new TypeError('can\'t convert ' + this + ' to object');
|
||||
}
|
||||
var str = '' + this;
|
||||
count = +count;
|
||||
if (count != count) {
|
||||
count = 0;
|
||||
}
|
||||
if (count < 0) {
|
||||
throw new RangeError('repeat count must be non-negative');
|
||||
}
|
||||
if (count == Infinity) {
|
||||
throw new RangeError('repeat count must be less than infinity');
|
||||
}
|
||||
count = Math.floor(count);
|
||||
if (str.length == 0 || count == 0) {
|
||||
return '';
|
||||
}
|
||||
// Ensuring count is a 31-bit integer allows us to heavily optimize the
|
||||
// main part. But anyway, most current (August 2014) browsers can't handle
|
||||
// strings 1 << 28 chars or longer, so:
|
||||
if (str.length * count >= 1 << 28) {
|
||||
throw new RangeError('repeat count must not overflow maximum string size');
|
||||
}
|
||||
var rpt = '';
|
||||
for (;;) {
|
||||
if ((count & 1) == 1) {
|
||||
rpt += str;
|
||||
}
|
||||
count >>>= 1;
|
||||
if (count == 0) {
|
||||
break;
|
||||
}
|
||||
str += str;
|
||||
}
|
||||
return rpt;
|
||||
};
|
||||
}
|
||||
|
||||
function cursorOff() {
|
||||
ansiterm.send('ext_mode','clear','cursor');
|
||||
console.gotoxy(0,24);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a message base by code
|
||||
*
|
||||
* @param code
|
||||
* @returns {number | string|boolean}
|
||||
*/
|
||||
function findMsgBase(code)
|
||||
{
|
||||
if (! code)
|
||||
code = "tex_data";
|
||||
|
||||
// Find the actual sub-code
|
||||
var sub_code;
|
||||
|
||||
for (var s in msg_area.sub) {
|
||||
var sub = msg_area.sub[s];
|
||||
|
||||
if (sub.code.substr(-code.length).toLowerCase() == code)
|
||||
return sub.code;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an argument from argv, or an error if it doesnt exit
|
||||
*
|
||||
* @param key
|
||||
* @param error
|
||||
*/
|
||||
function getArg(key,error,abort) {
|
||||
index = argv.indexOf(key);
|
||||
|
||||
if ((index !== -1) && (! (argv[index+1] === undefined || argv[index+1].match(/^-/)))) {
|
||||
return argv[index+1];
|
||||
}
|
||||
|
||||
if (abort) {
|
||||
log(LOG_ERROR,error);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
function getFrame(page) {
|
||||
if (! page.index)
|
||||
page.index = 'a';
|
||||
|
||||
// @todo Need to filter out SAUCE
|
||||
f = new File(system.mods_dir+'ansitex/text/'+pageStr(page)+'.tex');
|
||||
if (! f.exists || ! f.open('r')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
frame = JSON.parse(f.read());
|
||||
x = new Frame(0);
|
||||
frame.render = x.render;
|
||||
frame.raw = x.raw;
|
||||
|
||||
// @todo Figure out how to delete this duplicate code
|
||||
Object.defineProperty(frame,'page', {
|
||||
get: function() {return this.frame+this.index}
|
||||
});
|
||||
|
||||
x = null;
|
||||
|
||||
} catch (error) {
|
||||
log(LOG_ERROR,error);
|
||||
return null;
|
||||
}
|
||||
|
||||
log(LOG_DEBUG,'Loaded frame: ['+frame.frame+']['+frame.index+'] ('+frame.page+')');
|
||||
return frame;
|
||||
}
|
||||
|
||||
function loadOptions() {
|
||||
ini = new File(file_cfgname(system.mods_dir,'ansitex/ctrl/videotex.ini'));
|
||||
|
||||
if (!ini.open("r")) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
val = ini.iniGetObject(null);
|
||||
|
||||
ini.close();
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
function msgBaseImport(msgbase,page,text) {
|
||||
var msgbase = new MsgBase(findMsgBase(msgbase));
|
||||
|
||||
log(LOG_DEBUG,'Sending ['+page+'] to message base ['+msgbase.cfg.code+']');
|
||||
|
||||
var hdr = { to:'All', from:'Videotex', subject:'Frame: '+page };
|
||||
|
||||
var body = '';
|
||||
body += text+"\r\n";
|
||||
body += "--- " + js.exec_file + " " + '1.0' + "\r\n";
|
||||
|
||||
return msgbase.save_msg(hdr, body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the frame as a string
|
||||
*/
|
||||
function pageStr(page) {
|
||||
if (! page.index)
|
||||
page.index = 'a';
|
||||
|
||||
return page.frame+page.index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the frame
|
||||
*
|
||||
* @param frame
|
||||
*/
|
||||
function saveFrame(frame) {
|
||||
file = system.mods_dir+'ansitex/text/'+frame.page+'.tex';
|
||||
w = new File(file);
|
||||
if (! w.open('w')) {
|
||||
log(LOG_ERROR,'! ERROR: Unable to create TEX file for '+frame.page);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
w.write(JSON.stringify(frame));
|
||||
w.close();
|
||||
|
||||
log(LOG_DEBUG,'Saved file: '+frame.page+'.tex');
|
||||
}
|
||||
|
||||
function sendBaseline(text,reposition) {
|
||||
console.pushxy();
|
||||
console.gotoxy(0,24);
|
||||
console.print(text);
|
||||
console.cleartoeol();
|
||||
|
||||
if (! reposition) {
|
||||
console.popxy();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user