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