hedgewars/uPhysFSLayer.pas
changeset 10122 cefede760264
parent 10101 781f0c19e59b
child 10123 64e72781d344
equal deleted inserted replaced
10121:8b65699beb56 10122:cefede760264
    21 
    21 
    22 function pfsOpenRead(fname: shortstring): PFSFile;
    22 function pfsOpenRead(fname: shortstring): PFSFile;
    23 function pfsClose(f: PFSFile): boolean;
    23 function pfsClose(f: PFSFile): boolean;
    24 
    24 
    25 procedure pfsReadLn(f: PFSFile; var s: shortstring);
    25 procedure pfsReadLn(f: PFSFile; var s: shortstring);
    26 procedure pfsReadLnA(f: PFSFile; var s: PChar);
    26 procedure pfsReadLnA(f: PFSFile; var s: ansistring);
    27 function pfsBlockRead(f: PFSFile; buf: pointer; size: Int64): Int64;
    27 function pfsBlockRead(f: PFSFile; buf: pointer; size: Int64): Int64;
    28 function pfsEOF(f: PFSFile): boolean;
    28 function pfsEOF(f: PFSFile): boolean;
    29 
    29 
    30 function pfsExists(fname: shortstring): boolean;
    30 function pfsExists(fname: shortstring): boolean;
    31 
    31 
    97         inc(s[0]);
    97         inc(s[0]);
    98         s[byte(s[0])]:= c
    98         s[byte(s[0])]:= c
    99         end
    99         end
   100 end;
   100 end;
   101 
   101 
   102 procedure pfsReadLnA(f: PFSFile; var s: PChar);
   102 procedure pfsReadLnA(f: PFSFile; var s: ansistring);
   103 var l, bufsize: Longword;
   103 var c: char;
   104     r: Int64;
   104     b: shortstring;
   105     b: PChar;
       
   106 begin
   105 begin
   107 bufsize:= 256;
   106 s:= '';
   108 s:= StrAlloc(bufsize);
   107 b[0]:= #0;
   109 l:= 0;
       
   110 
   108 
   111 repeat
   109 while (PHYSFS_readBytes(f, @c, 1) = 1) and (c <> #10) do
   112     r:= PHYSFS_readBytes(f, @s[l], 1);
   110     if (c <> #13) then
   113 
       
   114     if (r = 1) and (s[l] <> #13) then
       
   115         begin
   111         begin
   116         inc(l);
   112         inc(b[0]);
   117         if l = bufsize then
   113         b[byte(b[0])]:= c;
       
   114         if b[0] = #255 then
   118             begin
   115             begin
   119             b:= s;
   116             s:= s + b;
   120             inc(bufsize, 256);
   117             b[0]:= #0
   121             s:= StrAlloc(bufsize);
       
   122             StrCopy(s, b);
       
   123             StrDispose(b)
       
   124             end
   118             end
   125         end;
   119         end;
   126 
   120         
   127 until (r = 0) or (s[l - 1] = #10);
   121 s:= s + b
   128 
       
   129 if (r = 0) then s[l]:= #0 else s[l - 1]:= #0
       
   130 end;
   122 end;
   131 
   123 
   132 function pfsBlockRead(f: PFSFile; buf: pointer; size: Int64): Int64;
   124 function pfsBlockRead(f: PFSFile; buf: pointer; size: Int64): Int64;
   133 var r: Int64;
   125 var r: Int64;
   134 begin
   126 begin