From e57a9cd09ccd9651c6bc769d19e87b8aca1fd5eb Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Sat, 26 Aug 2017 03:54:36 +0300 Subject: [PATCH] xdyn cosmetix (File -> TStream) --- src/shared/xdynrec.pas | 2 +- src/shared/xparser.pas | 62 +++++++++++++++--------------------------- 2 files changed, 23 insertions(+), 41 deletions(-) diff --git a/src/shared/xdynrec.pas b/src/shared/xdynrec.pas index f3400d8..0774c13 100644 --- a/src/shared/xdynrec.pas +++ b/src/shared/xdynrec.pas @@ -19,7 +19,7 @@ unit xdynrec; interface uses - xparser; + xparser, Classes; // ////////////////////////////////////////////////////////////////////////// // diff --git a/src/shared/xparser.pas b/src/shared/xparser.pas index 503a9a0..a7b8a51 100644 --- a/src/shared/xparser.pas +++ b/src/shared/xparser.pas @@ -18,6 +18,9 @@ unit xparser; interface +uses + Classes; + // ////////////////////////////////////////////////////////////////////////// // type @@ -79,7 +82,7 @@ type mTokInt: Integer; protected - procedure warmup (); virtual; abstract; // called in constructor to warm up the system + procedure warmup (); virtual; // called in constructor to warm up the system procedure loadNextChar (); virtual; abstract; // loads next char into mNextChar; #0 means 'eof' public @@ -132,10 +135,9 @@ type type TFileTextParser = class(TTextParser) private - mFile: File; + mFile: TStream; protected - procedure warmup (); override; // called in constructor to warm up the system procedure loadNextChar (); override; // loads next char into mNextChar; #0 means 'eof' public @@ -149,7 +151,6 @@ type mPos: Integer; protected - procedure warmup (); override; // called in constructor to warm up the system procedure loadNextChar (); override; // loads next char into mNextChar; #0 means 'eof' public @@ -184,7 +185,7 @@ type type TFileTextWriter = class(TTextWriter) private - mFile: File; + mFile: TStream; protected procedure putBuf (constref buf; len: SizeUInt); override; @@ -433,6 +434,15 @@ end; function TTextParser.isEOF (): Boolean; inline; begin result := (mCurChar = #0); end; +procedure TTextParser.warmup (); +begin + mNextChar := ' '; + loadNextChar(); + mCurChar := mNextChar; + if (mNextChar <> #0) then loadNextChar(); +end; + + function TTextParser.skipChar (): Boolean; begin if (mCurChar = #0) then begin result := false; exit; end; @@ -777,35 +787,23 @@ end; // ////////////////////////////////////////////////////////////////////////// // constructor TFileTextParser.Create (const fname: AnsiString; loadToken: Boolean=true); begin - AssignFile(mFile, fname); - Reset(mFile, 1); + mFile := openDiskFileRO(fname); inherited Create(loadToken); end; destructor TFileTextParser.Destroy (); begin - CloseFile(mFile); + mFile.Free(); inherited; end; -procedure TFileTextParser.warmup (); -var - rd: Integer; -begin - blockRead(mFile, mCurChar, 1, rd); - if (rd = 0) then begin mCurChar := #0; exit; end; - if (mCurChar = #0) then mCurChar := ' '; - loadNextChar(); -end; - - procedure TFileTextParser.loadNextChar (); var rd: Integer; begin - blockRead(mFile, mNextChar, 1, rd); + rd := mFile.Read(mNextChar, 1); if (rd = 0) then begin mNextChar := #0; exit; end; if (mNextChar = #0) then mNextChar := ' '; end; @@ -827,20 +825,6 @@ begin end; -procedure TStrTextParser.warmup (); -begin - if (mPos > Length(mStr)) then - begin - mCurChar := #0; - mNextChar := #0; - exit; - end; - mCurChar := mStr[mPos]; Inc(mPos); - if (mCurChar = #0) then mCurChar := ' '; - loadNextChar(); -end; - - procedure TStrTextParser.loadNextChar (); begin mNextChar := #0; @@ -864,28 +848,26 @@ procedure TTextWriter.unindent (); begin Dec(mIndent, 2); end; // ////////////////////////////////////////////////////////////////////////// // constructor TFileTextWriter.Create (const fname: AnsiString); begin - AssignFile(mFile, fname); - Rewrite(mFile, 1); + mFile := createDiskFile(fname); inherited Create(); end; destructor TFileTextWriter.Destroy (); begin - CloseFile(mFile); + mFile.Free(); + inherited; end; procedure TFileTextWriter.putBuf (constref buf; len: SizeUInt); var - wr: SizeUInt; pc: PChar; begin if (len > 0) then begin pc := @buf; - BlockWrite(mFile, pc^, len, wr); - if (wr <> len) then raise Exception.Create('write error'); + mFile.WriteBuffer(pc^, len); { while (len > 0) do begin -- 2.29.2