Skip to content
Snippets Groups Projects
Commit 504e4c1b authored by mcmlxxix's avatar mcmlxxix
Browse files

allow array length as a parameter to readArray()

added CNF.getBytes() to determine the size (in bytes) of a data structure
parent e3862961
No related branches found
No related tags found
No related merge requests found
......@@ -36,9 +36,13 @@ var CNF = new (function() {
}
/* read a set of records from xtrn.cnf */
function readArray(file,struct) {
function readArray(file,struct,length) {
var list = [];
var records = getInt(file,UINT16_T);
var records;
if(length == undefined)
records = getInt(file,UINT16_T);
else
records = length;
for(var i=0;i<records;i++) {
var data = readRecord(file,struct);
list[i] = data;
......@@ -66,7 +70,7 @@ var CNF = new (function() {
data[p] = readRecord(file,struct[p].bytes);
break;
case "lst":
data[p] = readArray(file,struct[p].bytes);
data[p] = readArray(file,struct[p].bytes,struct[p].length);
break;
case "ntv":
data[p] = readNative(file,struct[p].bytes);
......@@ -144,6 +148,15 @@ var CNF = new (function() {
}
}
/* determine the size of a record (in bytes) */
this.getBytes = function(struct) {
var bytes = 0;
for each(var p in struct) {
bytes += p.bytes;
}
return bytes;
}
/* read records from .cnf file */
this.read = function(fileName,struct) {
var f = new File(fileName);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment