Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit 68c9f24f authored by deuce's avatar deuce

Add 8-bit integer and "Pascal" string support.

parent 6c799a3c
......@@ -9,6 +9,9 @@ function getRecordLength(RecordDef)
switch(fieldtype) {
case "Float":
return(22);
case "SignedInteger8":
case "Integer8":
return(1);
case "SignedInteger16":
case "Integer16":
return(2);
......@@ -24,6 +27,10 @@ function getRecordLength(RecordDef)
if(m !== null) {
return(parseInt(m[1]));
}
m=fieldtype.match(/^PString:([0-9]+)$/);
if(m !== null) {
return(parseInt(m[1]+1));
}
return(0);
}
}
......@@ -460,6 +467,7 @@ RecordFile.prototype.readField = function(fieldtype)
var m=fieldtype.match(/^Array:([0-9]+):(.*)$/);
var ret;
var tmp;
var tmp2;
if(m !== null) {
ret = [];
......@@ -489,6 +497,14 @@ RecordFile.prototype.readField = function(fieldtype)
return(ret);
case "Integer16":
return(this.file.readBin(2));
case "SignedInteger8":
ret=this.file.readBin(1);
if(ret>=127) {
ret-=256;
}
return(ret);
case "Integer8":
return(this.file.readBin(1));
case "Date":
tmp=this.file.read(8);
return(tmp.replace(/\x00/g,""));
......@@ -503,6 +519,12 @@ RecordFile.prototype.readField = function(fieldtype)
tmp=this.file.read(parseInt(m[1]));
return(tmp.replace(/\x00/g,""));
}
m=fieldtype.match(/^PString:([0-9]+)$/);
if(m !== null) {
tmp=this.file.readBin(1);
tmp2=this.file.read(parseInt(m[1]));
return(tmp.substr(0, tmp));
}
return(null);
}
}
......@@ -576,6 +598,24 @@ RecordFile.prototype.writeField = function(val, fieldtype, def)
}
this.file.writeBin(val,2);
break;
case "SignedInteger8":
if(val < -128) {
val = -128;
}
if(val > 127) {
val = 127;
}
this.file.writeBin(val,1);
break;
case "Integer16":
if(val<0) {
val=0;
}
if(val>255) {
val=255;
}
this.file.writeBin(val,2);
break;
case "Date":
wr=val.substr(0,8);
while(wr.length < 8) {
......@@ -601,6 +641,16 @@ RecordFile.prototype.writeField = function(val, fieldtype, def)
}
this.file.write(wr,len);
}
m=fieldtype.match(/^PString:([0-9]+)$/);
if(m !== null) {
this.file.writeBin(wr.length, 1);
len=parseInt(m[1]);
wr=val.substr(0,len);
while(wr.length < len) {
wr=wr+"\x00";
}
this.file.write(wr,len);
}
}
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment