diff options
author | Erich Eckner <git@eckner.net> | 2017-07-11 12:59:33 +0200 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2017-07-11 13:00:04 +0200 |
commit | a7c625c353ff06fe6c757d710ee75c02d882273d (patch) | |
tree | a2757b17f87f8060efce191687edb531e5ae92f9 | |
parent | 56422ae1ea38a09a6cafc78715cbe1436fc4bd5e (diff) | |
download | units-a7c625c353ff06fe6c757d710ee75c02d882273d.tar.xz |
lowlevelunit: add functions needed to read andor sifs
-rw-r--r-- | lowlevelunit.pas | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/lowlevelunit.pas b/lowlevelunit.pas index 09fc555..a9fdb1e 100644 --- a/lowlevelunit.pas +++ b/lowlevelunit.pas @@ -112,6 +112,12 @@ function permutation(len,rest,maxBasis: longint; basen: tLongintArray): tLongint procedure llPermutation(len,offset: longint; var ar: tLongintArray); inline; procedure fuegeSortiertHinzu(x: extended; var xa: tExtendedArray); +procedure readALine(var f: file; out s: string); +procedure readAnAndorString(var f: file; out s: string; const len: int64; checkEOL: boolean); overload; +procedure readAnAndorString(var f: file; out s: string; checkEOL: boolean); overload; + +procedure splitStrToInt(s: string; out ia: tLongintArray); + var base64Chars: array[0..63] of char; base64CharsInvers: array[char] of byte; @@ -1012,6 +1018,54 @@ begin xa[mi]:=x; end; +procedure readALine(var f: file; out s: string); +var + fPos,fSize,rLen: int64; +begin + fPos:=filePos(f); + fSize:=fileSize(f); + rLen:=0; + s:=''; + while (pos(#10,s)=0) and (rLen+fPos<fSize) do begin + rLen:=min(rLen+1024,fSize-fPos); + setlength(s,rLen); + blockread(f,s[1],rLen); + seek(f,fPos); + end; + if pos(#10,s)<>0 then begin + rLen:=pos(#10,s); + setlength(s,rLen-1); + end; + seek(f,fPos+rLen); +end; + +procedure readAnAndorString(var f: file; out s: string; const len: int64; checkEOL: boolean); +begin + setlength(s,len+2*byte(checkEOL)); + if length(s)>0 then + blockread(f,s[1],length(s)); + if checkEOL then begin + if rightStr(s,2)<>' '#10 then + raise exception.create('readAnAndorString: EOL check failed: '''+s+'''!'); + setlength(s,length(s)-2); + end; +end; + +procedure readAnAndorString(var f: file; out s: string; checkEOL: boolean); +begin + readALine(f,s); + readAnAndorString(f,s,strToInt64(s),checkEOL); +end; + +procedure splitStrToInt(s: string; out ia: tLongintArray); +begin + setlength(ia,0); + while s<>'' do begin + setlength(ia,length(ia)+1); + ia[length(ia)-1]:=strToInt(erstesArgument(s,' ',false)); + end; +end; + var b: byte; |