cleanup
This commit is contained in:
parent
c4de02651e
commit
eefc2842a6
205
lib/tput.js
205
lib/tput.js
|
@ -232,26 +232,6 @@ Tput.prototype.parseExtended = function(data, _data, _h, _i) {
|
|||
, v
|
||||
, o;
|
||||
|
||||
var bools = data.slice(10, 12);
|
||||
var numbers = data.slice(12, 16);
|
||||
var strings = data.slice(16, 130);
|
||||
var stringData = data.slice(130, 612);
|
||||
var sym = data.slice(612, 928);
|
||||
|
||||
console.log(_h);
|
||||
console.log(_i);
|
||||
console.log(_data.length);
|
||||
process.exit(0);
|
||||
|
||||
console.log({
|
||||
bools: JSON.stringify(bools.toString('ascii')),
|
||||
numbers: JSON.stringify(numbers.toString('ascii')),
|
||||
strings: JSON.stringify(strings.toString('ascii')),
|
||||
stringData: JSON.stringify(stringData.toString('ascii')),
|
||||
sym: JSON.stringify(sym.toString('ascii'))
|
||||
});
|
||||
process.exit(0);
|
||||
|
||||
var h = info.header = {
|
||||
dataSize: data.length,
|
||||
headerSize: 10,
|
||||
|
@ -270,17 +250,13 @@ Tput.prototype.parseExtended = function(data, _data, _h, _i) {
|
|||
|
||||
i = h.headerSize;
|
||||
|
||||
console.log(h);
|
||||
//process.exit(0);
|
||||
|
||||
var b_start = i;
|
||||
// Booleans Section
|
||||
// One byte for each flag
|
||||
// Same order as <term.h>
|
||||
info.bools = [];
|
||||
var _bools = [];
|
||||
l = i + h.boolCount;
|
||||
for (; i < l; i++) {
|
||||
info.bools.push(!!data[i]);
|
||||
_bools.push(!!data[i]);
|
||||
}
|
||||
|
||||
// Null byte in between to make sure numbers begin on an even byte.
|
||||
|
@ -288,62 +264,44 @@ Tput.prototype.parseExtended = function(data, _data, _h, _i) {
|
|||
assert.equal(data[i], 0);
|
||||
i++;
|
||||
}
|
||||
var b_end = i;
|
||||
|
||||
var no_start = i;
|
||||
// Numbers Section
|
||||
info.numbers = [];
|
||||
var _numbers = [];
|
||||
l = i + h.numCount * 2;
|
||||
for (; i < l; i += 2) {
|
||||
if (data[i + 1] === 0377 && data[i] === 0377) {
|
||||
info.numbers.push(-1);
|
||||
_numbers.push(-1);
|
||||
} else {
|
||||
info.numbers.push((data[i + 1] << 8) | data[i]);
|
||||
_numbers.push((data[i + 1] << 8) | data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// looks like: ffff 0000
|
||||
// 0000920: 1b6c 001b 6d00 0200 0100 3900 7500 a802 .l..m.....9.u...
|
||||
// 0000930: 0100 ffff ffff 0000 0700 0e00 1500 1c00 ................
|
||||
//console.log(data.slice(i, i + 10));
|
||||
//process.exit(0);
|
||||
// XXX - WHY?
|
||||
if (data[i + 1] === 0377 && data[i] === 0377) {
|
||||
i += 2;
|
||||
}
|
||||
var no_end = i;
|
||||
|
||||
var sto_start = i;
|
||||
// Strings Section
|
||||
info.strings = [];
|
||||
var _strings = [];
|
||||
l = i + h.strCount * 2;
|
||||
for (; i < l; i += 2) {
|
||||
if (data[i + 1] === 0377 && data[i] === 0377) {
|
||||
//break; // XXX - WHY?
|
||||
info.strings.push(-1);
|
||||
_strings.push(-1);
|
||||
} else {
|
||||
info.strings.push((data[i + 1] << 8) | data[i]);
|
||||
_strings.push((data[i + 1] << 8) | data[i]);
|
||||
}
|
||||
}
|
||||
var sto_end = l;
|
||||
|
||||
// 0000990: 3b01 4201 4901 5001 5701 5e01 6501 ffff ;.B.I.P.W.^.e...
|
||||
// 00009a0: ffff ffff ffff 0000 0300 0600 0900 0c00 ................
|
||||
// i = 130, l = 130
|
||||
//console.log(data.slice(i, i + 10));
|
||||
//process.exit(0);
|
||||
//i--; // without this it's on `03`
|
||||
//i = l - 1;
|
||||
//assert.equal(data[i], 0);
|
||||
i = l;
|
||||
// i = l;
|
||||
|
||||
var st_start = i;
|
||||
// String Table
|
||||
var last = 0;
|
||||
info.strings.forEach(function(offset, k) {
|
||||
if (offset > last) last = offset;
|
||||
|
||||
_strings.forEach(function(offset, k) {
|
||||
if (offset === -1) {
|
||||
info.strings[k] = '';
|
||||
_strings[k] = '';
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -355,84 +313,45 @@ Tput.prototype.parseExtended = function(data, _data, _h, _i) {
|
|||
|
||||
while (data[j]) j++;
|
||||
|
||||
if (j - i > last) last = j - i;
|
||||
|
||||
if (s >= data.length || j > data.length) {
|
||||
//info.strings[k] = '';
|
||||
_strings[k] = '';
|
||||
return;
|
||||
}
|
||||
|
||||
info.strings[k] = data.toString('ascii', s, j);
|
||||
info.strings[k] = (s - i) + '-' + (j - i) + '-' + info.strings[k];
|
||||
_strings[k] = data.toString('ascii', s, j);
|
||||
});
|
||||
last += i;
|
||||
var st_end = last + 120;
|
||||
|
||||
console.log(data.slice(last, last + 120));
|
||||
console.log('strings: ' + info.strings.length);
|
||||
// missing 17 strings in the next 120 bytes (maybe unused?)
|
||||
// total: 74, 4a - or could be 73, 49, or 75, 4b
|
||||
console.log(JSON.stringify(data.slice(last, last + 120).toString('ascii').split('\0')));
|
||||
//process.exit(0);
|
||||
|
||||
// Symbol Table
|
||||
// XXX - WHY?
|
||||
//i = i + h.strTableSize;
|
||||
//i = (i + h.strCount * 2 + _h.strCount * 2);
|
||||
//console.log('cur: %d, needed: %d, needed2: %d, toffset: %d', i, h.lastStrTableOffset - 68, last + 120, _i + i);
|
||||
//process.exit(0);
|
||||
//i = h.lastStrTableOffset - 68;
|
||||
i = last + 120;
|
||||
i = h.lastStrTableOffset - 68;
|
||||
l = data.length;
|
||||
|
||||
console.log(data.slice(i - 10, i + 10));
|
||||
console.log(JSON.stringify(data.slice(i - 10, i + 10).toString('ascii')));
|
||||
//process.exit(0);
|
||||
|
||||
var sym = []
|
||||
, j = 0;
|
||||
|
||||
var sym_start = i;
|
||||
for (; i < l; i++) {
|
||||
j = i;
|
||||
while (data[j]) j++;
|
||||
sym.push(data.toString('ascii', i, j));
|
||||
i = j;
|
||||
}
|
||||
var sym_end = i;
|
||||
|
||||
console.log({
|
||||
header: '0' + ' - ' + h.headerSize,
|
||||
bools: b_start + ' - ' + b_end,
|
||||
numbers: no_start + ' - ' + no_end,
|
||||
strings: sto_start + ' - ' + sto_end,
|
||||
stringData: st_start + ' - ' + st_end,
|
||||
sym: sym_start + ' - ' + sym_end
|
||||
// Identify by name
|
||||
info.bools = {};
|
||||
_bools.forEach(function(bool) {
|
||||
info.bools[sym.shift()] = bool;
|
||||
});
|
||||
|
||||
console.log(sym);
|
||||
console.log(sym.length);
|
||||
console.log(info.strings.length);
|
||||
//process.exit(0);
|
||||
|
||||
var _bools = {}
|
||||
, _numbers = {}
|
||||
, _strings = {};
|
||||
|
||||
info.bools.forEach(function(bool) {
|
||||
_bools[sym.shift()] = bool;
|
||||
info.numbers = {};
|
||||
_numbers.forEach(function(number) {
|
||||
info.numbers[sym.shift()] = number;
|
||||
});
|
||||
info.bools = _bools;
|
||||
|
||||
info.numbers.forEach(function(number) {
|
||||
_numbers[sym.shift()] = number;
|
||||
info.strings = {};
|
||||
_strings.forEach(function(string) {
|
||||
info.strings[sym.shift()] = string;
|
||||
});
|
||||
info.numbers = _numbers;
|
||||
|
||||
info.strings.forEach(function(string) {
|
||||
_strings[sym.shift()] = string;
|
||||
});
|
||||
info.strings = _strings;
|
||||
assert.deepEqual(info, ext_test);
|
||||
|
||||
console.log(info);
|
||||
process.exit(0);
|
||||
|
@ -440,6 +359,76 @@ Tput.prototype.parseExtended = function(data, _data, _h, _i) {
|
|||
return info;
|
||||
};
|
||||
|
||||
var ext_test =
|
||||
{ header:
|
||||
{ dataSize: 928,
|
||||
headerSize: 10,
|
||||
boolCount: 2,
|
||||
numCount: 1,
|
||||
strCount: 57,
|
||||
strTableSize: 117,
|
||||
lastStrTableOffset: 680,
|
||||
total: 245 },
|
||||
bools: { AX: true, XT: false },
|
||||
numbers: { U8: -1 },
|
||||
strings:
|
||||
{ XM: '\u0003',
|
||||
kDC3: '\f',
|
||||
kDC4: ' ',
|
||||
kDC5: '.',
|
||||
kDC6: 'B',
|
||||
kDC7: 'T',
|
||||
kDN: 'l',
|
||||
kDN3: '~',
|
||||
kDN4: '<27>',
|
||||
kDN5: '<27>',
|
||||
kDN6: '<27>',
|
||||
kDN7: '<27>',
|
||||
kEND3: '<27>',
|
||||
kEND4: '<27>',
|
||||
kEND5: '\u0003\u0001\t\u0001\u000f\u0001\u0013\u0001\u0018\u0001\u001d\u0001"\u0001\'\u0001,\u00010\u00014\u00018\u0001\u001b[3;3~',
|
||||
kEND6: '\u0003\u0001\t\u0001\u000f\u0001\u0013\u0001\u0018\u0001\u001d\u0001"\u0001\'\u0001,\u00010\u00014\u00018\u0001\u001b[3;3~',
|
||||
kEND7: '\u0003\u0001\t\u0001\u000f\u0001\u0013\u0001\u0018\u0001\u001d\u0001"\u0001\'\u0001,\u00010\u00014\u00018\u0001\u001b[3;3~',
|
||||
kHOM3: '\u0003\u0001\t\u0001\u000f\u0001\u0013\u0001\u0018\u0001\u001d\u0001"\u0001\'\u0001,\u00010\u00014\u00018\u0001\u001b[3;3~',
|
||||
kHOM4: '\u001b[3;4~',
|
||||
kHOM5: '\u001b[3;5~',
|
||||
kHOM6: '\u001b[3;6~',
|
||||
kHOM7: '\u001b[3;7~',
|
||||
kIC3: '\u001b[1;2B',
|
||||
kIC4: '\u001b[1;3B',
|
||||
kIC5: '\u001b[1;4B',
|
||||
kIC6: '\u001b[1;5B',
|
||||
kIC7: '\u001b[1;6B',
|
||||
kLFT3: '\u001b[1;7B',
|
||||
kLFT4: '\u001b[1;3F',
|
||||
kLFT5: '\u001b[1;4F',
|
||||
kLFT6: '\u001b[1;5F',
|
||||
kLFT7: '\u001b[1;6F',
|
||||
kNXT3: '\u001b[1;7F',
|
||||
kNXT4: '\u001b[1;3H',
|
||||
kNXT5: '\u001b[1;4H',
|
||||
kNXT6: '\u001b[1;5H',
|
||||
kNXT7: '\u001b[1;6H',
|
||||
kPRV3: '\u001b[1;7H',
|
||||
kPRV4: '\u001b[2;3~',
|
||||
kPRV5: '\u001b[2;4~',
|
||||
kPRV6: '\u001b[2;5~',
|
||||
kPRV7: '\u001b[2;6~',
|
||||
kRIT3: '\u001b[2;7~',
|
||||
kRIT4: '\u001b[1;3D',
|
||||
kRIT5: '\u001b[1;4D',
|
||||
kRIT6: '\u001b[1;5D',
|
||||
kRIT7: '\u001b[1;6D',
|
||||
kUP: '\u001b[1;7D',
|
||||
kUP3: '\u001b[6;3~',
|
||||
kUP4: '\u001b[6;4~',
|
||||
kUP5: '\u001b[6;5~',
|
||||
kUP6: '\u001b[6;6~',
|
||||
kUP7: '',
|
||||
ka2: '',
|
||||
kb1: '',
|
||||
kb3: '',
|
||||
kc2: '\u0003' } };
|
||||
|
||||
/**
|
||||
* Compiler - terminfo cap->javascript
|
||||
|
@ -453,8 +442,6 @@ Tput.prototype.compile = function(key) {
|
|||
console.log(this.info);
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
this.methods = {};
|
||||
this.info.all = {};
|
||||
|
||||
|
|
Loading…
Reference in New Issue