StreamInfo Class Reference

#include <StreamNative.hpp>

Public Types

enum  { DefaultBufferSize = 512 }
 
enum  StreamState {
  StreamUnknown = 0 , StreamReady = 1 , StreamNotready = 2 , StreamEof = 3 ,
  StreamError = 4
}
 

Public Member Functions

 StreamInfo (RexxObjectPtr s, const char *inputName)
 
void setContext (RexxMethodContext *c, RexxObjectPtr d)
 
char * allocateBuffer (size_t length)
 
char * getDefaultBuffer (size_t &length)
 
char * extendBuffer (size_t &length)
 
void freeBuffer ()
 
bool open (int openFlags, int openMode, int sharedFlag)
 
int64_t size ()
 
void notreadyError ()
 
void notreadyError (int error_code, RexxObjectPtr result=NULL)
 
void raiseException (int err)
 
void raiseException (int err, RexxObjectPtr sub1)
 
void raiseException (int err, RexxObjectPtr sub1, RexxObjectPtr sub2)
 
void raiseException (int err, RexxObjectPtr sub1, RexxObjectPtr sub2, RexxObjectPtr sub3)
 
void raiseException (int err, RexxObjectPtr sub1, RexxObjectPtr sub2, RexxObjectPtr sub3, RexxObjectPtr sub4)
 
void raiseException (int err, RexxObjectPtr sub1, RexxObjectPtr sub2, RexxObjectPtr sub3, RexxObjectPtr sub4, RexxObjectPtr sub5)
 
void eof (RexxObjectPtr)
 
void eof ()
 
void checkEof ()
 
void checkStreamType ()
 
void close ()
 
const char * openStd (const char *options)
 
const char * handleOpen (const char *options)
 
void resetFields ()
 
void implicitOpen (int type)
 
void readSetup ()
 
void writeSetup ()
 
RexxStringObject readLine (char *buffer, size_t length, bool update_position)
 
void resolveStreamName ()
 
void writeBuffer (const char *data, size_t length, size_t &bytesWritten)
 
void writeLine (const char *data, size_t length, size_t &bytesWritten)
 
void readBuffer (char *data, size_t length, size_t &bytesRead)
 
void completeLine (size_t writeLength)
 
void writeFixedLine (const char *data, size_t length)
 
void setPosition (int64_t position, int64_t &newPosition)
 
void setPosition (int64_t offset, int style, int64_t &newPosition)
 
void setReadPosition (int64_t position)
 
void setWritePosition (int64_t position)
 
void setCharReadPosition (int64_t position)
 
void setLineReadPosition (int64_t position)
 
void setCharWritePosition (int64_t position)
 
void setLineWritePosition (int64_t position)
 
RexxStringObject readVariableLine ()
 
void appendVariableLine (RexxArrayObject r)
 
void lineReadIncrement ()
 
void resetLinePositions ()
 
RexxStringObject charin (bool setPosition, int64_t position, size_t read_length)
 
size_t charout (RexxStringObject data, bool setPosition, int64_t position)
 
RexxStringObject linein (bool setPosition, int64_t position, size_t count)
 
int arrayin (RexxArrayObject r)
 
int64_t lines (bool quick)
 
int64_t chars ()
 
int lineout (RexxStringObject data, bool setPosition, int64_t position)
 
const char * streamClose ()
 
const char * streamFlush ()
 
const char * streamOpen (const char *options)
 
void setHandle (int fh)
 
int64_t streamPosition (const char *options)
 
int64_t getLineSize ()
 
int64_t seekLinePosition (int64_t offset, int direction, int64_t &current_line, int64_t &current_position)
 
int64_t setLinePosition (int64_t new_line, int64_t &current_line, int64_t &current_position)
 
int64_t queryLinePosition (int64_t current_position)
 
RexxObjectPtr queryStreamPosition (const char *options)
 
int64_t getLineReadPosition ()
 
int64_t getLineWritePosition ()
 
int64_t readForwardByLine (int64_t offset, int64_t &current_line, int64_t &current_position)
 
int64_t seekToVariableLine (int64_t offset, int64_t &current_line, int64_t &current_position)
 
int64_t setLinePositions ()
 
const char * getQualifiedName ()
 
const char * streamExists ()
 
RexxObjectPtr queryHandle ()
 
const char * getStreamType ()
 
RexxObjectPtr getStreamSize ()
 
const char * getTimeStamp ()
 
const char * getState ()
 
RexxStringObject getDescription ()
 
int64_t countStreamLines (int64_t currentLinePosition, int64_t currentPosition)
 
void setStandard ()
 

Protected Attributes

RexxMethodContextcontext
 
RexxObjectPtr self
 
RexxObjectPtr defaultResult
 
char stream_name [SysFileSystem::MaximumFileNameBuffer]
 
char qualified_name [SysFileSystem::MaximumFileNameLength]
 
int64_t charReadPosition
 
int64_t charWritePosition
 
int64_t lineReadPosition
 
int64_t lineWritePosition
 
int64_t lineReadCharPosition
 
int64_t lineWriteCharPosition
 
int64_t stream_line_size
 
StreamState state
 
int errorInfo
 
size_t binaryRecordLength
 
char * bufferAddress
 
size_t bufferLength
 
SysFile fileInfo
 
bool read_only
 
bool write_only
 
bool read_write
 
bool append
 
bool nobuffer
 
bool stdstream
 
bool last_op_was_read
 
bool opened_as_handle
 
bool transient
 
bool record_based
 
bool isopen
 

Friends

class LineBuffer
 

Detailed Description

Definition at line 65 of file StreamNative.hpp.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
DefaultBufferSize 

Definition at line 69 of file StreamNative.hpp.

◆ StreamState

Enumerator
StreamUnknown 
StreamReady 
StreamNotready 
StreamEof 
StreamError 

Definition at line 74 of file StreamNative.hpp.

Constructor & Destructor Documentation

◆ StreamInfo()

StreamInfo::StreamInfo ( RexxObjectPtr  s,
const char *  inputName 
)

Constructor for a StreamInfo object.

Parameters
sThe Stream object this is attached to.
inputNameThe initial input name specified on the new call.

Definition at line 3706 of file StreamNative.cpp.

References bufferAddress, bufferLength, SysFileSystem::MaximumPathLength, resetFields(), state, stream_name, and StreamUnknown.

Member Function Documentation

◆ allocateBuffer()

char * StreamInfo::allocateBuffer ( size_t  length)

Get the buffer attached to this stream. If the existing buffer is large enough for the requested usage, then use it. Otherwise, allocate a larger one.

Parameters
lengthRequired buffer length
Returns
Pointer to the buffer area.

Definition at line 204 of file StreamNative.cpp.

References bufferAddress, bufferLength, DefaultBufferSize, raiseException(), and Rexx_Error_System_service.

Referenced by extendBuffer(), and getDefaultBuffer().

◆ appendVariableLine()

void StreamInfo::appendVariableLine ( RexxArrayObject  result)

Read in a variable length line, searching for the eol marker for the line.

Returns
The read line.

Definition at line 1412 of file StreamNative.cpp.

References SysFile::atEof(), checkEof(), context, extendBuffer(), fileInfo, getDefaultBuffer(), SysFile::gets(), and lineReadIncrement().

Referenced by arrayin().

◆ arrayin()

int StreamInfo::arrayin ( RexxArrayObject  result)

Perform a line-oriented arrayin operation on the stream

Parameters
setPositionIndicates whether it is necessary to move the read pointer before reading.
positionNew target position.
countcount of lines to read.
Returns
A string object containing the read characters.

Definition at line 1743 of file StreamNative.cpp.

References appendVariableLine(), binaryRecordLength, charReadPosition, context, readBuffer(), readSetup(), and record_based.

Referenced by RexxMethod2().

◆ charin()

RexxStringObject StreamInfo::charin ( bool  _setPosition,
int64_t  position,
size_t  read_length 
)

Perform a charin() operation on the stream.

Parameters
setPositionIndicates whether it is necessary to move the read pointer before reading.
positionNew target position.
read_lengthLength to read.
Returns
A string object containing the read characters.

Definition at line 1507 of file StreamNative.cpp.

References context, eof(), readBuffer(), readSetup(), resetLinePositions(), and setCharReadPosition().

Referenced by RexxMethod3().

◆ charout()

size_t StreamInfo::charout ( RexxStringObject  data,
bool  _setPosition,
int64_t  position 
)

Write character data to the stream.

Parameters
dataThe string object data we're writing.
setPositionAn order to reset the position information.
positionThe new write position, if specified.
Returns
The residual count on the write.

Definition at line 1579 of file StreamNative.cpp.

References close(), context, defaultResult, notreadyError(), NULLOBJECT, resetLinePositions(), setCharWritePosition(), writeBuffer(), and writeSetup().

Referenced by RexxMethod3().

◆ chars()

int64_t StreamInfo::chars ( )

Return the remaining character indicator for a stream. For transient streams, this is a 1/0 value. For persistent streams, this is the remaining data left in the stream.

Returns
A count of characters in the stream.

Definition at line 1940 of file StreamNative.cpp.

References charReadPosition, fileInfo, SysFile::hasData(), implicitOpen(), isopen, SysFile::isTransient(), operation_nocreate, read_only, read_write, and size().

Referenced by RexxMethod1().

◆ checkEof()

void StreamInfo::checkEof ( )

Raise the appropriate not ready condition, checking first for an eof condition.

Parameters
resultA result object to be passed with the Notready condition.

Definition at line 467 of file StreamNative.cpp.

References SysFile::atEof(), eof(), fileInfo, and notreadyError().

Referenced by appendVariableLine(), readLine(), readVariableLine(), and setPosition().

◆ checkStreamType()

void StreamInfo::checkStreamType ( )

Get the type of the stream in question.

Parameters
binaryIndicates whether we believe this to be a binary stream, or not.

Definition at line 489 of file StreamNative.cpp.

References binaryRecordLength, fileInfo, SysFile::isTransient(), raiseException(), record_based, Rexx_Error_Incorrect_method, and size().

Referenced by handleOpen(), implicitOpen(), and streamOpen().

◆ close()

void StreamInfo::close ( )

Close stream, performing any data flushes that might be required.

This raises a NOTREADY condition if any errors occur on the close.

Definition at line 534 of file StreamNative.cpp.

References SysFile::close(), context, defaultResult, SysFile::errorInfo(), fileInfo, freeBuffer(), isopen, notreadyError(), state, and StreamUnknown.

Referenced by charout(), lineout(), streamClose(), and streamOpen().

◆ completeLine()

void StreamInfo::completeLine ( size_t  writeLength)

Write out the remainder of an output line for a record oriented I/O operation.

Definition at line 1134 of file StreamNative.cpp.

References writeBuffer().

Referenced by lineout(), and writeFixedLine().

◆ countStreamLines()

int64_t StreamInfo::countStreamLines ( int64_t  currentLinePosition,
int64_t  currentPosition 
)

Count the number of lines in the file. If we already have a pseudo line count, we can just return that.

Parameters
currentLinePositionThe current line position we're scanning from.
currentPositionThe position to start counting from.
Returns
The number of lines in the file.

Definition at line 3746 of file StreamNative.cpp.

References SysFile::countLines(), fileInfo, notreadyError(), setPosition(), and stream_line_size.

Referenced by getLineSize(), and lines().

◆ eof() [1/2]

void StreamInfo::eof ( )

Process an EOF condition for a stream.

Definition at line 438 of file StreamNative.cpp.

References defaultResult.

Referenced by charin(), checkEof(), readLine(), and setCharReadPosition().

◆ eof() [2/2]

void StreamInfo::eof ( RexxObjectPtr  result)

Process an EOF condition for a stream.

Parameters
resultA result object returned with the NotReady condition.

Definition at line 449 of file StreamNative.cpp.

References context, state, stream_name, and StreamEof.

◆ extendBuffer()

char * StreamInfo::extendBuffer ( size_t &  length)

Extend the current I/O buffer, keeping any data in the buffer intact.

Parameters
lengthThe length of the extended buffer.
Returns
Pointer to the reallocated buffer.

Definition at line 260 of file StreamNative.cpp.

References allocateBuffer(), bufferAddress, bufferLength, and DefaultBufferSize.

Referenced by appendVariableLine(), and readVariableLine().

◆ freeBuffer()

void StreamInfo::freeBuffer ( )

Release the buffer, if any, attached to this stream object.

Definition at line 273 of file StreamNative.cpp.

References bufferAddress, and bufferLength.

Referenced by close().

◆ getDefaultBuffer()

char * StreamInfo::getDefaultBuffer ( size_t &  length)

Get a buffer of at least the default size, returning a to the buffer and the current size.

Parameters
lengthThe returned buffer length.
Returns
The pointer to the allocated buffer.

Definition at line 242 of file StreamNative.cpp.

References allocateBuffer(), bufferAddress, bufferLength, and DefaultBufferSize.

Referenced by appendVariableLine(), and readVariableLine().

◆ getDescription()

RexxStringObject StreamInfo::getDescription ( )

Retrieve a description string for the stream.

Returns
A string describing the stream state and error information.

Definition at line 3622 of file StreamNative.cpp.

References context, errorInfo, NULLOBJECT, state, StreamEof, StreamError, StreamNotready, StreamReady, StreamUnknown, and work.

Referenced by RexxMethod1().

◆ getLineReadPosition()

int64_t StreamInfo::getLineReadPosition ( )

Calculate the line position of the stream based on the position and the type.

Returns
The 64-bit line position of the stream.

Definition at line 3170 of file StreamNative.cpp.

References binaryRecordLength, charReadPosition, lineReadCharPosition, lineReadPosition, queryLinePosition(), and record_based.

Referenced by queryStreamPosition().

◆ getLineSize()

int64_t StreamInfo::getLineSize ( )

Get the line size for this stream. If we're using fixed length records, we can calculate this directly from the size. If it is a variable-line stream, we might have already calculated the size and kept the information. If not, we're going to have go and count every line.

Returns
The number of lines in the stream.

Definition at line 2865 of file StreamNative.cpp.

References binaryRecordLength, countStreamLines(), record_based, and size().

Referenced by seekLinePosition().

◆ getLineWritePosition()

int64_t StreamInfo::getLineWritePosition ( )

Calculate the line position of the stream based on the defined I/O type.

Returns
Calculated 64-bit stream line position.

Definition at line 3200 of file StreamNative.cpp.

References binaryRecordLength, charWritePosition, lineWriteCharPosition, lineWritePosition, queryLinePosition(), and record_based.

Referenced by queryStreamPosition().

◆ getQualifiedName()

const char * StreamInfo::getQualifiedName ( )

Return the qualified name of a stream.

Returns
The character string qualified name.

Definition at line 3374 of file StreamNative.cpp.

References qualified_name, and resolveStreamName().

Referenced by RexxMethod1().

◆ getState()

const char * StreamInfo::getState ( )

Get the stream state as a string. This value is a constant, and does not contain any addtional information.

Returns
A string token with the stream state.

Definition at line 3585 of file StreamNative.cpp.

References state, StreamEof, StreamError, StreamNotready, StreamReady, and StreamUnknown.

Referenced by RexxMethod1().

◆ getStreamSize()

RexxObjectPtr StreamInfo::getStreamSize ( )

Get the size of the stream, regardless of whether it is open or not.

Returns
The int64_t size of the stream. Devices return a 0 size.

Definition at line 3507 of file StreamNative.cpp.

References context, fileInfo, SysFile::getSize(), isopen, qualified_name, and resolveStreamName().

Referenced by RexxMethod1().

◆ getStreamType()

const char * StreamInfo::getStreamType ( )

Return the type of stream (persistent or transient).

Returns
String value of the type. Returns either "PERSISTENT", "TRANSIENT", or "UNKNOWN", if the stream is not open.

Definition at line 3475 of file StreamNative.cpp.

References isopen.

Referenced by RexxMethod1().

◆ getTimeStamp()

const char * StreamInfo::getTimeStamp ( )

Get the time stamp of the stream (in character form), regardless of whether it is open or not.

Returns
A character string time stamp for the stream. Returns "" for streams where a time stamp is meaningless.

Definition at line 3537 of file StreamNative.cpp.

References fileInfo, SysFile::getTimeStamp(), isopen, qualified_name, and resolveStreamName().

Referenced by RexxMethod1().

◆ handleOpen()

const char * StreamInfo::handleOpen ( const char *  options)

Do a stream open using a supplied file handle. This open process parses all of the open parameters, setting the appropriate state

Parameters
optionsThe character string open optins.
Returns
The stream state (READY/NOTREADY)

Definition at line 654 of file StreamNative.cpp.

References binaryRecordLength, BitOr, CallItem, charWritePosition, checkStreamType(), ctrl_z, fileInfo, isopen, SysFile::isTransient(), lineWriteCharPosition, lineWritePosition, MEB, MIB, nobuffer, notreadyError(), parser(), qualified_name, raiseException(), RDWR_CREAT, SysFile::read(), read_only, read_write, reclength_token(), record_based, resetFields(), Rexx_Error_Incorrect_method, RX_O_RDONLY, SetBool, setPosition(), size(), state, stream_name, StreamReady, unknown_tr(), WR_CREAT, and write_only.

Referenced by implicitOpen(), and streamOpen().

◆ implicitOpen()

◆ linein()

RexxStringObject StreamInfo::linein ( bool  _setPosition,
int64_t  position,
size_t  count 
)

Perform a linein() operation on the stream.

Parameters
setPositionIndicates whether it is necessary to move the read pointer before reading.
positionNew target position.
countcount of lines to read.
Returns
A string object containing the read characters.

Definition at line 1661 of file StreamNative.cpp.

References binaryRecordLength, charReadPosition, context, raiseException(), readBuffer(), readSetup(), readVariableLine(), record_based, Rexx_Error_Incorrect_method, and setLineReadPosition().

Referenced by RexxMethod3().

◆ lineout()

int StreamInfo::lineout ( RexxStringObject  data,
bool  _setPosition,
int64_t  position 
)

Write a line out to the stream.

Parameters
dataThe string object to write.
setPositionIndicates whether we've been given a line position to use for the write.
positionThe provided line position.
Returns
0 if everything worked. All failures result in notready conditions, which throw an exception.

Definition at line 1998 of file StreamNative.cpp.

References append, binaryRecordLength, charWritePosition, close(), completeLine(), context, lineWriteCharPosition, lineWritePosition, NULLOBJECT, raiseException(), record_based, Rexx_Error_Incorrect_method, setLineWritePosition(), size(), stream_line_size, writeFixedLine(), writeLine(), and writeSetup().

Referenced by RexxMethod3().

◆ lineReadIncrement()

void StreamInfo::lineReadIncrement ( )

Increments the read positions, including the line-orientated positions, after a single line has been read. Assumes one line has actually been read.

Definition at line 1462 of file StreamNative.cpp.

References charReadPosition, fileInfo, SysFile::getPosition(), last_op_was_read, lineReadCharPosition, lineReadPosition, and notreadyError().

Referenced by appendVariableLine(), and readVariableLine().

◆ lines()

int64_t StreamInfo::lines ( bool  quick)

Count the number lines in the stream.

Parameters
quickControls whether we just return a 1/0 indicicator that there is more data, or do an actualy count of the lines.
Returns
Either a 1/0 indicator of more or the actual count of lines.

Definition at line 1817 of file StreamNative.cpp.

References binaryRecordLength, charReadPosition, countStreamLines(), fileInfo, SysFile::hasData(), implicitOpen(), isopen, SysFile::isTransient(), lineReadPosition, operation_nocreate, read_only, read_write, readSetup(), record_based, size(), and stream_line_size.

Referenced by RexxMethod2().

◆ notreadyError() [1/2]

void StreamInfo::notreadyError ( )

◆ notreadyError() [2/2]

void StreamInfo::notreadyError ( int  error_code,
RexxObjectPtr  result = NULL 
)

Raise a stream error condition, including raising a NOTREADY condition.

Parameters
error_codeThe Rexx error condition to raise.
resultA NOTREADY condition result object.

Definition at line 327 of file StreamNative.cpp.

References SysFile::clearErrors(), context, defaultResult, errorInfo, fileInfo, NULLOBJECT, state, stream_name, and StreamError.

◆ open()

bool StreamInfo::open ( int  openFlags,
int  openMode,
int  sharedFlag 
)

Open the stream in the specified mode.

Parameters
openFlagsOpen flags as defined by the _sopen() library function
openModeMode flags as defined by the _sopen() function.
sharedFlagSharing flags as defined by _sopen()
Returns
true if the file is opened successfully, false for any failures.

Definition at line 294 of file StreamNative.cpp.

References fileInfo, SysFile::open(), and qualified_name.

Referenced by implicitOpen(), and streamOpen().

◆ openStd()

const char * StreamInfo::openStd ( const char *  options)

Open a standard stream, using the provided options string.

Parameters
optionsOpen parameters, in character string form.
Returns
The open condition string.

Definition at line 582 of file StreamNative.cpp.

References append, fileInfo, hasNoBufferOption(), isopen, SysFile::isTransient(), nobuffer, qualified_name, read_only, SysFile::setBuffering(), SysFile::setStdErr(), SysFile::setStdIn(), SysFile::setStdOut(), state, Utilities::strCaselessCompare(), stream_name, and StreamReady.

Referenced by implicitOpen(), and streamOpen().

◆ queryHandle()

RexxObjectPtr StreamInfo::queryHandle ( )

Return the handle value for the stream.

Returns
The binary handle for the stream.

Definition at line 3449 of file StreamNative.cpp.

References context, fileInfo, SysFile::getHandle(), and isopen.

Referenced by RexxMethod1().

◆ queryLinePosition()

int64_t StreamInfo::queryLinePosition ( int64_t  current_position)

Determine the count of lines from the file beginning to specified stream location.

Parameters
current_positionThe target position we're trying to convert for a char position into a line position.
Returns
A count indicating which logical line current_position lies within.

Definition at line 3022 of file StreamNative.cpp.

References SysFile::countLines(), fileInfo, and notreadyError().

Referenced by getLineReadPosition(), and getLineWritePosition().

◆ queryStreamPosition()

RexxObjectPtr StreamInfo::queryStreamPosition ( const char *  options)

process a method-level stream query call.

Parameters
optionsThe string options that determine the requested options.
Returns
The numeric position value as either a line or char position.

Definition at line 3046 of file StreamNative.cpp.

References BitOr, charReadPosition, charWritePosition, context, fileInfo, getLineReadPosition(), getLineWritePosition(), SysFile::getPosition(), isopen, ME, notreadyError(), parser(), query_char_position, query_line_position, query_read_position, query_system_position, query_write_position, raiseException(), Rexx_Error_Incorrect_method, unknown_tr(), and write_only.

Referenced by RexxMethod2().

◆ raiseException() [1/6]

void StreamInfo::raiseException ( int  err)

Raise an exception for the stream code.

Parameters
errThe raised error code.

Definition at line 349 of file StreamNative.cpp.

References context.

Referenced by allocateBuffer(), checkStreamType(), handleOpen(), linein(), lineout(), queryStreamPosition(), setCharReadPosition(), setCharWritePosition(), setLineReadPosition(), setLineWritePosition(), streamOpen(), and streamPosition().

◆ raiseException() [2/6]

void StreamInfo::raiseException ( int  err,
RexxObjectPtr  sub1 
)

Raise an exception for the stream code.

Parameters
errThe raised error code.
sub1First error substitution value.

Definition at line 362 of file StreamNative.cpp.

References context.

◆ raiseException() [3/6]

void StreamInfo::raiseException ( int  err,
RexxObjectPtr  sub1,
RexxObjectPtr  sub2 
)

Raise an exception for the stream code.

Parameters
errThe raised error code.
sub1First error substitution value.
sub2Second error substitution value.

Definition at line 376 of file StreamNative.cpp.

References context.

◆ raiseException() [4/6]

void StreamInfo::raiseException ( int  err,
RexxObjectPtr  sub1,
RexxObjectPtr  sub2,
RexxObjectPtr  sub3 
)

Raise an exception for the stream code.

Parameters
errThe raised error code.
sub1First error substitution value.
sub2Second error substitution value.
sub3Third error substitution value.

Definition at line 392 of file StreamNative.cpp.

References context.

◆ raiseException() [5/6]

void StreamInfo::raiseException ( int  err,
RexxObjectPtr  sub1,
RexxObjectPtr  sub2,
RexxObjectPtr  sub3,
RexxObjectPtr  sub4 
)

Raise an exception for the stream code.

Parameters
errThe raised error code.
sub1First error substitution value.
sub2Second error substitution value.
sub3Third error substitution value.
sub4Fourth error substitution value.

Definition at line 409 of file StreamNative.cpp.

References context.

◆ raiseException() [6/6]

void StreamInfo::raiseException ( int  err,
RexxObjectPtr  sub1,
RexxObjectPtr  sub2,
RexxObjectPtr  sub3,
RexxObjectPtr  sub4,
RexxObjectPtr  sub5 
)

Raise an exception for the stream code.

Parameters
errThe raised error code.
sub1First error substitution value.
sub2Second error substitution value.
sub3Third error substitution value.
sub4Fourth error substitution value.
sub5Fifth error substitution value.

Definition at line 427 of file StreamNative.cpp.

References context.

◆ readBuffer()

void StreamInfo::readBuffer ( char *  data,
size_t  length,
size_t &  bytesRead 
)

Read a buffer of data from the current position for the given length. This also updates our character input position information.

Parameters
dataThe location to place the data.
lengthThe length to read.
bytesReadThe number of bytes actually read.

Definition at line 1119 of file StreamNative.cpp.

References charReadPosition, fileInfo, notreadyError(), and SysFile::read().

Referenced by arrayin(), charin(), and linein().

◆ readForwardByLine()

int64_t StreamInfo::readForwardByLine ( int64_t  offset,
int64_t current_line,
int64_t current_position 
)

Move forward the specified number of lines in the file.

Parameters
offsetNumber of lines to move.
current_lineCurrent line position in the file.
current_positionThe current character position to read from.
Returns
The new current line position.

Definition at line 3258 of file StreamNative.cpp.

References fileInfo, notreadyError(), readSetup(), SysFile::seekForwardLines(), setPosition(), and stream_line_size.

Referenced by seekToVariableLine().

◆ readLine()

RexxStringObject StreamInfo::readLine ( char *  buffer,
size_t  length,
bool  update_position 
)

Read a line from the stream

Parameters
bufferThe data to write to the stream
lengthThe length of the data buffer.
update_positiondetermines whether the read will also update the write position.
Returns
A string object representing the line.

Definition at line 1005 of file StreamNative.cpp.

References charReadPosition, checkEof(), context, defaultResult, eof(), fileInfo, and SysFile::read().

◆ readSetup()

void StreamInfo::readSetup ( )

◆ readVariableLine()

RexxStringObject StreamInfo::readVariableLine ( )

Read in a variable length line, searching for the eol marker for the line.

Returns
The read line.

Definition at line 1361 of file StreamNative.cpp.

References SysFile::atEof(), checkEof(), context, extendBuffer(), fileInfo, getDefaultBuffer(), SysFile::gets(), and lineReadIncrement().

Referenced by linein().

◆ resetFields()

◆ resetLinePositions()

void StreamInfo::resetLinePositions ( )

Reset all line-oriented position information after an operation that will invalidate the values (for example, a charin() or charout() operation).

Definition at line 1487 of file StreamNative.cpp.

References lineReadCharPosition, lineReadPosition, and stream_line_size.

Referenced by charin(), charout(), and streamPosition().

◆ resolveStreamName()

void StreamInfo::resolveStreamName ( )

Convert a specified stream name into it's fully qualified name.

Definition at line 1044 of file StreamNative.cpp.

References qualified_name, SysFileSystem::qualifyStreamName(), and stream_name.

Referenced by getQualifiedName(), getStreamSize(), getTimeStamp(), implicitOpen(), streamExists(), and streamOpen().

◆ seekLinePosition()

int64_t StreamInfo::seekLinePosition ( int64_t  offset,
int  direction,
int64_t current_line,
int64_t current_position 
)

Perform a seek operation by line position instead of character. The seek can be relative to either the front, end, or current positions.

Parameters
offsetThe offset to move. This can be negative for SEEK_CUR.
directionThe position to seek from. This can be SEEK_SET, SEEK_CUR, or SEEK_END (using the stdio.h constants directly).
current_lineThe current line position we're seeking from. This can be either the stream read or write position. This value is updated on completion of the seek.
current_positionThe current character position associated with this operation. This is also updated with the seek.
Returns
The new line position.

Definition at line 2909 of file StreamNative.cpp.

References getLineSize(), and setLinePosition().

Referenced by streamPosition().

◆ seekToVariableLine()

int64_t StreamInfo::seekToVariableLine ( int64_t  offset,
int64_t current_line,
int64_t current_position 
)

Seek to a specific line position

Parameters
offsetThe new target position
current_lineThe starting line position
current_positionThe starting character position.
Returns

Definition at line 3300 of file StreamNative.cpp.

References readForwardByLine().

Referenced by setLinePosition().

◆ setCharReadPosition()

void StreamInfo::setCharReadPosition ( int64_t  position)

Set the current character read position, raising a NOTREADY condition of there is a problem.

Parameters
positionThe target stream position.
resultA result object returned to the caller after raising the condition.

Definition at line 1260 of file StreamNative.cpp.

References CHAR_positional, context, eof(), raiseException(), Rexx_Error_Incorrect_method_positive, Rexx_Error_Incorrect_method_stream_type, setReadPosition(), and size().

Referenced by charin().

◆ setCharWritePosition()

void StreamInfo::setCharWritePosition ( int64_t  position)

Set the char write position.

Parameters
positionThe target position.

Definition at line 1313 of file StreamNative.cpp.

References CHAR_positional, context, raiseException(), Rexx_Error_Incorrect_method_positive, Rexx_Error_Incorrect_method_stream_type, and setWritePosition().

Referenced by charout().

◆ setContext()

void StreamInfo::setContext ( RexxMethodContext c,
RexxObjectPtr  d 
)
inline

Definition at line 84 of file StreamNative.hpp.

References context, and defaultResult.

Referenced by checkStreamInfo(), and RexxMethod1().

◆ setHandle()

void StreamInfo::setHandle ( int  fh)

Set a stream to be opened with a specified handle.

Parameters
fhThe input file handle.

Definition at line 2578 of file StreamNative.cpp.

References fileInfo, SysFile::open(), and opened_as_handle.

Referenced by RexxMethod2().

◆ setLinePosition()

int64_t StreamInfo::setLinePosition ( int64_t  new_line,
int64_t current_line,
int64_t current_position 
)

Set a line position to an explicit line number. This takes into account differences between record and variable line streams.

Parameters
new_lineThe target new_line position.
current_lineThe current line position we're seeking from.
current_positionThe current character position we're seeking from.
Returns
The new line position.

Definition at line 2965 of file StreamNative.cpp.

References binaryRecordLength, record_based, and seekToVariableLine().

Referenced by seekLinePosition(), setLineReadPosition(), and setLineWritePosition().

◆ setLinePositions()

int64_t StreamInfo::setLinePositions ( )

Make sure we have valid line positions set. If we've just been doing character operations up to this point, our line positions will not be set. This may require reading the file and counting up to the positions.

Returns

Definition at line 3326 of file StreamNative.cpp.

References charReadPosition, charWritePosition, SysFile::countLines(), fileInfo, lineReadCharPosition, lineReadPosition, lineWriteCharPosition, lineWritePosition, notreadyError(), and readSetup().

◆ setLineReadPosition()

void StreamInfo::setLineReadPosition ( int64_t  position)

Set the line read position.

Parameters
positionThe target position.

Definition at line 1290 of file StreamNative.cpp.

References CHAR_positional, context, lineReadCharPosition, lineReadPosition, raiseException(), Rexx_Error_Incorrect_method_positive, Rexx_Error_Incorrect_method_stream_type, setLinePosition(), and setReadPosition().

Referenced by linein().

◆ setLineWritePosition()

void StreamInfo::setLineWritePosition ( int64_t  position)

Set the line write position.

Parameters
positionThe target position.
resultA result value to be used when raising a condition.

Definition at line 1333 of file StreamNative.cpp.

References CHAR_positional, context, lineWriteCharPosition, lineWritePosition, raiseException(), Rexx_Error_Incorrect_method_positive, Rexx_Error_Incorrect_method_stream_type, setLinePosition(), and setWritePosition().

Referenced by lineout().

◆ setPosition() [1/2]

void StreamInfo::setPosition ( int64_t  offset,
int  style,
int64_t newPosition 
)

Move the stream position, with error checking.

Parameters
positionThe target position.
newPositionThe updated final position of the move.

Definition at line 1208 of file StreamNative.cpp.

References checkEof(), fileInfo, and SysFile::seek().

◆ setPosition() [2/2]

void StreamInfo::setPosition ( int64_t  position,
int64_t newPosition 
)

Move the stream position, with error checking.

Parameters
positionThe target position.
newPositionThe updated final position of the move.

Definition at line 1181 of file StreamNative.cpp.

References checkEof(), fileInfo, implicitOpen(), isopen, operation_nocreate, and SysFile::seek().

Referenced by countStreamLines(), handleOpen(), implicitOpen(), readForwardByLine(), readSetup(), setReadPosition(), setWritePosition(), streamOpen(), streamPosition(), and writeSetup().

◆ setReadPosition()

void StreamInfo::setReadPosition ( int64_t  position)

Sets the current read position for the stream. This updates charReadPosition to point to the target location.

Parameters
positionThe target character position (Rexx coordinates, which means 1 based rather than the native zero-based).

Definition at line 1234 of file StreamNative.cpp.

References charReadPosition, and setPosition().

Referenced by setCharReadPosition(), and setLineReadPosition().

◆ setStandard()

void StreamInfo::setStandard ( )
inline

Definition at line 164 of file StreamNative.hpp.

References stdstream.

Referenced by RexxMethod1().

◆ setWritePosition()

void StreamInfo::setWritePosition ( int64_t  position)

Sets the current write position for the stream. This updates charWritePosition to point to the target location.

Parameters
positionThe target character position (Rexx coordinates, which means 1 based rather than the native zero-based).

Definition at line 1246 of file StreamNative.cpp.

References charWritePosition, and setPosition().

Referenced by setCharWritePosition(), and setLineWritePosition().

◆ size()

int64_t StreamInfo::size ( )

Retrieve the size of the stream, if available.

Returns
The 64-bit stream size of the target stream.

Definition at line 304 of file StreamNative.cpp.

References fileInfo, and SysFile::getSize().

Referenced by chars(), checkStreamType(), getLineSize(), handleOpen(), implicitOpen(), lineout(), lines(), setCharReadPosition(), and streamOpen().

◆ streamClose()

const char * StreamInfo::streamClose ( )

Close the stream.

Returns
The character string success/failure indicator.

Definition at line 2107 of file StreamNative.cpp.

References close(), isopen, state, and StreamUnknown.

Referenced by RexxMethod1().

◆ streamExists()

const char * StreamInfo::streamExists ( )

Check if a stream exists. If it does, the qualified name is returned. This does not need to be an open stream for this to succeed.

Returns
The resolved stream name, or "" if not resolvable.

Definition at line 3401 of file StreamNative.cpp.

References SysFileSystem::fileExists(), fileInfo, SysFile::isDevice(), isopen, opened_as_handle, qualified_name, resolveStreamName(), and stream_name.

Referenced by RexxMethod1().

◆ streamFlush()

const char * StreamInfo::streamFlush ( )

Try to flush the stream, returning the appropriate error state if there is a problem.

Returns
"READY" if everything works. If this fails, a notready condition is raised and an exception is thrown.

Definition at line 2197 of file StreamNative.cpp.

References context, SysFile::errorInfo(), fileInfo, SysFile::flush(), notreadyError(), and work.

Referenced by RexxMethod1().

◆ streamOpen()

◆ streamPosition()

◆ writeBuffer()

void StreamInfo::writeBuffer ( const char *  data,
size_t  length,
size_t &  bytesWritten 
)

Write a buffer of data to the stream, raising an notready condition if it fails.

Parameters
dataPointer to the first byte of data
lengthlength of the data buffer
bytesWrittenActual number of bytes written to the stream.

Definition at line 1061 of file StreamNative.cpp.

References charWritePosition, fileInfo, SysFile::getPosition(), notreadyError(), and SysFile::write().

Referenced by charout(), completeLine(), and writeFixedLine().

◆ writeFixedLine()

void StreamInfo::writeFixedLine ( const char *  data,
size_t  length 
)

Write out a fixed record line, padding with blanks if the line is not of the correct size.

Parameters
dataThe data to write.
lengthlength of the buffered data.
Returns
The line residual count.

Definition at line 1157 of file StreamNative.cpp.

References binaryRecordLength, charWritePosition, completeLine(), and writeBuffer().

Referenced by lineout().

◆ writeLine()

void StreamInfo::writeLine ( const char *  data,
size_t  length,
size_t &  bytesWritten 
)

Write a terminated line of data to the stream, raising an notready condition if it fails.

Parameters
dataPointer to the first byte of data
lengthlength of the data buffer
bytesWrittenActual number of bytes written to the stream.

Definition at line 1090 of file StreamNative.cpp.

References charWritePosition, fileInfo, SysFile::getPosition(), notreadyError(), and SysFile::putLine().

Referenced by lineout().

◆ writeSetup()

void StreamInfo::writeSetup ( )

Set up the stream for a write operation.

Definition at line 961 of file StreamNative.cpp.

References append, charWritePosition, fileInfo, SysFile::getPosition(), implicitOpen(), isopen, notreadyError(), operation_write, read_only, setPosition(), state, and StreamReady.

Referenced by charout(), and lineout().

Friends And Related Function Documentation

◆ LineBuffer

friend class LineBuffer
friend

Definition at line 67 of file StreamNative.hpp.

Member Data Documentation

◆ append

bool StreamInfo::append
protected

Definition at line 195 of file StreamNative.hpp.

Referenced by lineout(), openStd(), resetFields(), streamOpen(), streamPosition(), and writeSetup().

◆ binaryRecordLength

◆ bufferAddress

char* StreamInfo::bufferAddress
protected

◆ bufferLength

size_t StreamInfo::bufferLength
protected

◆ charReadPosition

◆ charWritePosition

◆ context

◆ defaultResult

RexxObjectPtr StreamInfo::defaultResult
protected

Definition at line 170 of file StreamNative.hpp.

Referenced by charout(), close(), eof(), implicitOpen(), notreadyError(), readLine(), and setContext().

◆ errorInfo

int StreamInfo::errorInfo
protected

Definition at line 183 of file StreamNative.hpp.

Referenced by getDescription(), and notreadyError().

◆ fileInfo

◆ isopen

◆ last_op_was_read

bool StreamInfo::last_op_was_read
protected

Definition at line 198 of file StreamNative.hpp.

Referenced by lineReadIncrement(), resetFields(), and streamPosition().

◆ lineReadCharPosition

int64_t StreamInfo::lineReadCharPosition
protected

◆ lineReadPosition

◆ lineWriteCharPosition

int64_t StreamInfo::lineWriteCharPosition
protected

◆ lineWritePosition

◆ nobuffer

bool StreamInfo::nobuffer
protected

Definition at line 196 of file StreamNative.hpp.

Referenced by handleOpen(), openStd(), resetFields(), and streamOpen().

◆ opened_as_handle

bool StreamInfo::opened_as_handle
protected

Definition at line 199 of file StreamNative.hpp.

Referenced by implicitOpen(), resetFields(), setHandle(), streamExists(), and streamOpen().

◆ qualified_name

◆ read_only

bool StreamInfo::read_only
protected

◆ read_write

bool StreamInfo::read_write
protected

◆ record_based

◆ self

RexxObjectPtr StreamInfo::self
protected

Definition at line 169 of file StreamNative.hpp.

◆ state

◆ stdstream

bool StreamInfo::stdstream
protected

Definition at line 197 of file StreamNative.hpp.

Referenced by implicitOpen(), resetFields(), setStandard(), and streamOpen().

◆ stream_line_size

int64_t StreamInfo::stream_line_size
protected

◆ stream_name

char StreamInfo::stream_name[SysFileSystem::MaximumFileNameBuffer]
protected

◆ transient

bool StreamInfo::transient
protected

Definition at line 200 of file StreamNative.hpp.

◆ write_only

bool StreamInfo::write_only
protected

The documentation for this class was generated from the following files: