From 7a7bc00777974fca03289f0cb11f9b178de1d043 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 24 Feb 2013 19:15:53 -0600 Subject: [PATCH] add comments explaining extended parsing. --- lib/tput.js | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/lib/tput.js b/lib/tput.js index 99ebb25..e2aeba7 100644 --- a/lib/tput.js +++ b/lib/tput.js @@ -213,24 +213,25 @@ Tput.prototype.parseTerminfo = function(data) { // lastStrTableOffset: 680, // total: 245 }, -// For xterm, offsets: -// { header: '0 - 10', -// bools: '10 - 12', -// numbers: '12 - 14', +// For xterm, layout: +// { header: '0 - 10', // length: 10 +// bools: '10 - 12', // length: 2 +// numbers: '12 - 14', // length: 2 // strings: '14 - 128', // length: 114 (57 short) -// symstrings: '128 - 248', // length: 120 (60 short) -// stringData: '248 - 612', -// sym: '612 - 928' } +// symoffsets: '128 - 248', // length: 120 (60 short) +// stringtable: '248 - 612', // length: 364 +// sym: '612 - 928' } // length: 316 // -// header size: 10 -// bools size: 2 -// numbers size: 4 -// string-offset size: 114 -// sym-offset size: 120 -// string table size: 364 -// sym size: 316 -// 364 + 316 === 680 (lastStrTableOffset) -// data.length - h.lastStrTableOffset === 248 (sym-offset size) +// How lastStrTableOffset works: +// data.length - h.lastStrTableOffset === 248 (sym-offset end, string-table start) +// 364 + 316 === 680 (lastStrTableOffset) +// How strTableSize works: +// h.strCount + [symOffsetCount] === h.strTableSize +// 57 + 60 === 117 (strTableSize) +// symOffsetCount doesn't actually exist in the header. it's just implied. +// Getting the number of sym offsets: +// h.symOffsetCount = h.strTableSize - h.strCount; +// h.symOffsetSize = (h.strTableSize - h.strCount) * 2; Tput.prototype.parseExtended = function(data) { var info = {} @@ -247,6 +248,8 @@ Tput.prototype.parseExtended = function(data) { lastStrTableOffset: (data[i + 9] << 8) | data[i + 8] }; + // h.symOffsetCount = h.strTableSize - h.strCount; + h.total = h.headerSize + h.boolCount + h.numCount * 2 @@ -294,6 +297,7 @@ Tput.prototype.parseExtended = function(data) { // Pass over the sym offsets and get to the string table. i = data.length - h.lastStrTableOffset; + // i += h.symOffsetCount * 2; // String Table var high = 0; @@ -328,7 +332,7 @@ Tput.prototype.parseExtended = function(data) { l = data.length; var sym = [] - , j = 0; + , j; for (; i < l; i++) { j = i;