Frame import into message base
This commit is contained in:
@@ -1,48 +1,72 @@
|
||||
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;
|
||||
};
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,16 +76,16 @@ function cursorOff() {
|
||||
* @param error
|
||||
*/
|
||||
function getArg(key,error,abort) {
|
||||
index = argv.indexOf(key);
|
||||
index = argv.indexOf(key);
|
||||
|
||||
if ((index !== -1) && (! (argv[index+1] === undefined || argv[index+1].match(/^-/)))) {
|
||||
return argv[index+1];
|
||||
}
|
||||
if ((index !== -1) && (! (argv[index+1] === undefined || argv[index+1].match(/^-/)))) {
|
||||
return argv[index+1];
|
||||
}
|
||||
|
||||
if (abort) {
|
||||
log(LOG_ERROR,error);
|
||||
exit(1);
|
||||
}
|
||||
if (abort) {
|
||||
log(LOG_ERROR,error);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
function getFrame(page) {
|
||||
@@ -75,29 +99,43 @@ function getFrame(page) {
|
||||
}
|
||||
|
||||
try {
|
||||
frame = JSON.parse(f.read());
|
||||
x = new Frame(0);
|
||||
frame.render = x.render;
|
||||
frame = JSON.parse(f.read());
|
||||
x = new Frame(0);
|
||||
frame.render = x.render;
|
||||
|
||||
// @todo Figure out how to delete this duplicate code
|
||||
Object.defineProperty(frame,'page', {
|
||||
get: function() {return this.frame+this.index}
|
||||
});
|
||||
// @todo Figure out how to delete this duplicate code
|
||||
Object.defineProperty(frame,'page', {
|
||||
get: function() {return this.frame+this.index}
|
||||
});
|
||||
} catch (error) {
|
||||
log(LOG_ERROR,error);
|
||||
return null;
|
||||
}
|
||||
log(LOG_ERROR,error);
|
||||
return null;
|
||||
}
|
||||
|
||||
log(LOG_DEBUG,'Loaded frame: ['+frame.frame+']['+frame.index+'] ('+frame.page+')');
|
||||
log(LOG_DEBUG,'Loaded frame: ['+frame.frame+']['+frame.index+'] ('+frame.page+')');
|
||||
return frame;
|
||||
}
|
||||
|
||||
function msgBaseExport(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';
|
||||
if (! page.index)
|
||||
page.index = 'a';
|
||||
|
||||
return page.frame+page.index;
|
||||
}
|
||||
|
Reference in New Issue
Block a user