Skip to content
Snippets Groups Projects
Commit 9254d939 authored by deuce's avatar deuce
Browse files

When writing, use the default value if the current value is undefined.

Enfore integer limits when writing.
Add local variable declarations where needed to avoid clobbering globals.
parent c0775a84
No related branches found
No related tags found
No related merge requests found
...@@ -4,7 +4,7 @@ function GetRecordLength(RecordDef) ...@@ -4,7 +4,7 @@ function GetRecordLength(RecordDef)
var len=0; var len=0;
function GetTypeLength(fieldtype) { function GetTypeLength(fieldtype) {
switch(RecordDef[i].fieldtype) { switch(fieldtype) {
case "SignedInteger": case "SignedInteger":
case "Integer": case "Integer":
return(4); return(4);
...@@ -87,21 +87,33 @@ function RecordFile_ReadField(fieldtype) ...@@ -87,21 +87,33 @@ function RecordFile_ReadField(fieldtype)
} }
} }
function RecordFile_WriteField(val, fieldtype) function RecordFile_WriteField(val, fieldtype, def)
{ {
var i; var i;
var m=fieldtype.match(/^Array:([0-9]+):(.*)$/); var m=fieldtype.match(/^Array:([0-9]+):(.*)$/);
if(m!=null) { if(m!=null) {
var ret=new Array(); var ret=new Array();
for(i=0; i<parseInt(m[1]); i++) for(i=0; i<parseInt(m[1]); i++) {
this.WriteField(val[i], m[2]); this.WriteField(val[i], m[2], def[i]);
}
return(ret); return(ret);
} }
else { else {
if(val==undefined)
val=def;
switch(fieldtype) { switch(fieldtype) {
case "SignedInteger": case "SignedInteger":
if(val < -2147483648)
val = -2147483648;
if(val > 2147483647)
val = 2147483647;
this.file.writeBin(val,4);
case "Integer": case "Integer":
if(val<0)
val=0;
if(val>4294967295)
val=4294967295;
this.file.writeBin(val,4); this.file.writeBin(val,4);
break; break;
case "Date": case "Date":
...@@ -177,19 +189,25 @@ function RecordFile_New() ...@@ -177,19 +189,25 @@ function RecordFile_New()
function RecordFileRecord_ReInit() function RecordFileRecord_ReInit()
{ {
var i;
for(i=0; i<this.parent.fields.length; i++) for(i=0; i<this.parent.fields.length; i++)
this[this.parent.fields[i].prop]=eval(this.parent.fields[i].def.toSource); this[this.parent.fields[i].prop]=eval(this.parent.fields[i].def.toSource);
} }
function RecordFileRecord_Put() function RecordFileRecord_Put()
{ {
this.parent.file.position=(this.Record)*this.parent.RecordLength; var i;
this.parent.file.position=this.Record * this.parent.RecordLength;
for(i=0; i<this.parent.fields.length; i++) for(i=0; i<this.parent.fields.length; i++)
this.parent.WriteField(this[this.parent.fields[i].prop], this.parent.fields[i].type); this.parent.WriteField(this[this.parent.fields[i].prop], this.parent.fields[i].type, this.parent.fields[i].def);
} }
function RecordFileRecord_ReLoad(num) function RecordFileRecord_ReLoad(num)
{ {
var i;
this.parent.file.position=(this.Record)*this.parent.RecordLength; this.parent.file.position=(this.Record)*this.parent.RecordLength;
for(i=0; i<this.parent.fields.length; i++) for(i=0; i<this.parent.fields.length; i++)
this[this.parent.fields[i].prop]=this.parent.ReadField(this.parent.fields[i].type); this[this.parent.fields[i].prop]=this.parent.ReadField(this.parent.fields[i].type);
......
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