Unit 'amigados' Package
[Overview][Constants][Types][Procedures and functions][Index] [#aros]

TCSource

Input structure for ReadItem and ReadArgs

Declaration

Source position: amigados.pas line 1259

type TCSource = record

  CS_Buffer: PChar;

  

Data source

  CS_Length: LongInt;

  

Length of string

  CS_CurChr: LongInt;

  

end;

Description

The TCSource data structure defines the input source for ReadItem as well as the ReadArgs call. It is a publicly defined structure which may be used by applications which use code that follows the conventions defined for access.

To initialize a TCSource, you set TCSource.CS_Buffer to a string which is used as the data source, and set CS_Length to the number of characters in the string. Normally CS_CurChr should be initialized to 0, or left as it was from prior use as a TCSource.

When passed to the dos.library functions, the value passed as PCSource is defined as follows:

if PCSource = nil then
  // Use buffered IO  as data source
else
  // Use PCSource for input character stream

The following two pseudo-code routines define how the TCSource structure is used:

function CS_ReadChar(CSource: PCSource): Integer
begin
  if CSource = nil then
  begin
    Result := ReadChar();
    Exit;
  end;
  if CSource^.CurChr >= CSource^.Length then
  begin
    Result := ENDSTREAMCHAR;
    Exit;
  end;
  Result := CSource^.Buffer[CSource^.CurChr];
  Inc(CSource^.CurChr);
end;

function CS_UnReadChar(CSource: PCSource): Boolean;
begin
  if CSource = nil then
  begin
    Result := UnReadChar();
    Exit;
  end;
  if CSource^.CurChr <= 0 then
    Result := False
  else
  begin
     Dec(CSource^.CurChr);
     Result := True;
  end;
end;
 

Documentation generated on: 2021-07-30