Prechádzať zdrojové kódy

+ implemented TRelObjInput.CanReadObjData

git-svn-id: trunk@45540 -
nickysn 5 rokov pred
rodič
commit
11cc085870
1 zmenil súbory, kde vykonal 118 pridanie a 0 odobranie
  1. 118 0
      compiler/ogrel.pas

+ 118 - 0
compiler/ogrel.pas

@@ -540,8 +540,126 @@ implementation
       end;
 
     class function TRelObjInput.CanReadObjData(AReader: TObjectreader): boolean;
+      const
+        MaxBufSize=512;
+      var
+        Buf: array [0..MaxBufSize-1] of Char;
+        BufSize: Integer = 0;
+        BufPos: Integer = 0;
+
+        function FillBuf: boolean;
+          begin
+            BufPos:=0;
+            BufSize:=min(AReader.size-AReader.Pos,MaxBufSize);
+            if BufSize>0 then
+              result:=AReader.read(Buf,BufSize)
+            else
+              result:=true;
+          end;
+
+        function AtEndOfBuf: boolean;
+          begin
+            result:=BufPos=BufSize;
+          end;
+
+        function AtEoF: boolean;
+          begin
+            result:=AtEndOfBuf and (AReader.Pos=AReader.size);
+          end;
+
+        function ReadChar(out c: char): boolean;
+          begin
+            c:=#0;
+            if AtEndOfBuf then
+              begin
+                result:=FillBuf;
+                if not result then
+                  exit;
+              end;
+            if not AtEndOfBuf then
+              begin
+                c:=Buf[BufPos];
+                Inc(BufPos);
+                result:=true;
+              end
+            else
+              result:=false;
+          end;
+
+        function PeekChar(out c: char): boolean;
+          begin
+            c:=#0;
+            if AtEndOfBuf then
+              begin
+                result:=FillBuf;
+                if not result then
+                  exit;
+              end;
+            if not AtEndOfBuf then
+              begin
+                c:=Buf[BufPos];
+                result:=true;
+              end
+            else
+              result:=false;
+          end;
+
+        function ReadLine(out s: string): boolean;
+          var
+            c: Char;
+          begin
+            s:='';
+            if AtEoF then
+              begin
+                result:=false;
+                exit;
+              end;
+            repeat
+              if not AtEoF then
+                begin
+                  if not ReadChar(c) then
+                    begin
+                      result:=false;
+                      exit;
+                    end;
+                  if not (c in [#13,#10]) then
+                    s:=s+c;
+                end;
+            until (c in [#13,#10]) or AtEoF;
+            if (c=#13) and not AtEoF then
+              begin
+                if not PeekChar(c) then
+                  begin
+                    result:=false;
+                    exit;
+                  end;
+                if c=#10 then
+                  begin
+                    if not ReadChar(c) then
+                      begin
+                        result:=false;
+                        exit;
+                      end;
+                  end;
+              end;
+            result:=true;
+          end;
+
+      var
+        s: string;
       begin
         result:=false;
+        while not AtEoF do
+          begin
+            if not ReadLine(s) then
+              exit;
+            s:=Trim(s);
+            if s<>'' then
+              begin
+                result:=s='XL2';
+                exit;
+              end;
+          end;
       end;