Browse Source

* fixed stdinput reading under win32

peter 20 years ago
parent
commit
540c2c5bea
1 changed files with 56 additions and 63 deletions
  1. 56 63
      fcl/inc/iostream.pp

+ 56 - 63
fcl/inc/iostream.pp

@@ -15,94 +15,84 @@
 
 
 unit iostream;
 unit iostream;
 
 
-Interface
-
-Uses Classes;
-
-Type
-
-  TiosType = (iosInput,iosOutPut,iosError);
-  EIOStreamError = Class(EStreamError);
-
-  TIOStream = Class(THandleStream)
-    Private
-      FType,
-      FPos : Longint;
-    Public
-      Constructor Create(IOSType : TiosType);
-      Function Read(var Buffer; Count: Longint): Longint;override;
-      Function Write(const Buffer; Count: Longint): Longint;override;
-      Procedure SetSize(NewSize: Longint); override;
-      Function Seek(Offset: Longint; Origin: Word): Longint; override;
-   end;
+interface
+
+uses Classes;
+
+type
+  TIOSType = (iosInput,iosOutPut,iosError);
+  EIOStreamError = class(EStreamError);
+
+  TIOStream = class(THandleStream)
+  private
+    FType,
+    FPos : LongInt;
+    zIOSType : TIOSType;
+  public
+    constructor Create(aIOSType : TiosType);
+    function Read(var Buffer; Count : LongInt) : Longint; override;
+    function Write(const Buffer; Count : LongInt) : LongInt; override;
+    procedure SetSize(NewSize: Longint); override;
+    function Seek(Offset: Longint; Origin: Word): Longint; override;
+    end;
 
 
-Implementation
+implementation
 
 
-Const
+const
   SReadOnlyStream = 'Cannot write to an input stream.';
   SReadOnlyStream = 'Cannot write to an input stream.';
   SWriteOnlyStream = 'Cannot read from an output stream.';
   SWriteOnlyStream = 'Cannot read from an output stream.';
   SInvalidOperation = 'Cannot perform this operation on a IOStream.';
   SInvalidOperation = 'Cannot perform this operation on a IOStream.';
 
 
-Constructor TIOStream.Create(IOSType : TiosType);
-
+constructor TIOStream.Create(aIOSType : TIOSType);
 begin
 begin
 {$ifdef win32}
 {$ifdef win32}
-  Case IOSType of
-    iosOutput : FType:=Stdoutputhandle;
-    iosInput : FType:=Stdinputhandle;
-    iosError : FType:=StdErrorHandle;
+  case aIOSType of
+    iosInput : FType := StdInputHandle;
+    iosOutput : FType := StdOutputHandle;
+    iosError : FType := StdErrorHandle;
   end;
   end;
 {$else}
 {$else}
-  FType:=Ord(IOSType);
+  FType := Ord(aIOSType);
 {$endif}
 {$endif}
-  Inherited Create(Ftype);
+  inherited Create(FType);
+  zIOSType := aIOSType;
 end;
 end;
 
 
-
-Function TIOStream.Read(var Buffer; Count: Longint): Longint;
-
+function TIOStream.Read(var Buffer; Count : LongInt) : Longint;
 begin
 begin
-  If Ftype>0 then
-    Raise EIOStreamError.Create(SWriteOnlyStream)
-  else
-    begin
-    Result:=Inherited Read(Buffer,Count);
-    Inc(FPos,Result);
-    end;
+  if (zIOSType = iosOutput) then
+    raise EIOStreamError.Create(SWriteOnlyStream)
+  else begin
+    result := inherited Read(Buffer,Count);
+    inc(FPos,result);
+  end;
 end;
 end;
 
 
-
-Function TIOStream.Write(const Buffer; Count: Longint): Longint;
-
+function TIOStream.Write(const Buffer; Count : LongInt) : LongInt;
 begin
 begin
-  If Ftype=0 then
-    Raise EIOStreamError.Create(SReadOnlyStream)
-  else
-    begin
-    Result:=Inherited Write(Buffer,Count);
-    Inc(FPos,Result);
-    end;
+  if (zIOSType = iosInput) then
+    raise EIOStreamError.Create(SReadOnlyStream)
+  else begin
+    result := inherited Write(Buffer,Count);
+    inc(FPos,result);
+  end;
 end;
 end;
 
 
-
-Procedure TIOStream.SetSize(NewSize: Longint);
-
+procedure TIOStream.SetSize(NewSize: Longint);
 begin
 begin
-  Raise EIOStreamError.Create(SInvalidOperation);
+  raise EIOStreamError.Create(SInvalidOperation);
 end;
 end;
 
 
-
-Function TIOStream.Seek(Offset: Longint; Origin: Word): Longint;
-
-Const BufSize = 100;
-
-Var Buf : array[1..BufSize] of Byte;
-
+function TIOStream.Seek(Offset: Longint; Origin: Word): Longint;
+const
+  BufSize = 100;
+var
+  Buf : array[1..BufSize] of Byte;
 begin
 begin
   If (Origin=soFromCurrent) and (Offset=0) then
   If (Origin=soFromCurrent) and (Offset=0) then
      result:=FPos;
      result:=FPos;
   { Try to fake seek by reading and discarding }
   { Try to fake seek by reading and discarding }
-  if (Ftype>0) or
+  if (zIOSType = iosOutput) or
      Not((Origin=soFromCurrent) and (Offset>=0) or
      Not((Origin=soFromCurrent) and (Offset>=0) or
          ((Origin=soFrombeginning) and (OffSet>=FPos))) then
          ((Origin=soFrombeginning) and (OffSet>=FPos))) then
      Raise EIOStreamError.Create(SInvalidOperation);
      Raise EIOStreamError.Create(SInvalidOperation);
@@ -120,7 +110,10 @@ end.
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.3  2002-09-07 15:15:24  peter
+  Revision 1.4  2005-02-14 16:39:51  peter
+    * fixed stdinput reading under win32
+
+  Revision 1.3  2002/09/07 15:15:24  peter
     * old logs removed and tabs fixed
     * old logs removed and tabs fixed
 
 
 }
 }