55 #define CHAR_positional "positional"
89 #define RDWR_CREAT (RX_O_RDWR | RX_O_CREAT)
90 #define WR_CREAT (RX_O_WRONLY | RX_O_CREAT)
91 #define IREAD_IWRITE (RX_S_IREAD | RX_S_IWRITE)
108 if (streamPtr == NULL)
142 *((
size_t *)userparms) = offset;
173 *((
int64_t *)userparms) = offset;
364 context->RaiseException1(err, sub1);
378 context->RaiseException2(err, sub1, sub2);
394 context->RaiseException3(err, sub1, sub2, sub3);
411 context->RaiseException4(err, sub1, sub2, sub3, sub4);
429 context->RaiseException5(err, sub1, sub2, sub3, sub4, sub5);
560 char *tmp = (
char *)malloc(strlen(opts) + 1);
569 bool result = strstr(tmp,
"NOBUFFER") != NULL ? true :
false;
716 if (
parser(tts, options, NULL) != 0)
739 char char_buffer =
' ';
751 if (
ctrl_z != char_buffer)
900 char char_buffer =
' ';
912 if (
ctrl_z != char_buffer)
1023 if (update_position)
1028 if (bytesRead != length)
1138 memset(buffer,
' ',
sizeof(buffer));
1140 while (writeLength > 0)
1142 size_t bytesWritten;
1143 writeBuffer(buffer, writeLength <
sizeof(buffer) ? writeLength :
sizeof(buffer), bytesWritten);
1144 writeLength -= bytesWritten;
1162 if (length > write_length)
1164 length = write_length;
1167 size_t padding = write_length - length;
1192 if (!
fileInfo.
seek(position - 1, SEEK_SET, newPosition))
1211 if (style == SEEK_SET)
1272 if (
size() >= position)
1367 size_t currentLength = 0;
1372 char *readPosition = buffer + currentLength;
1373 size_t bytesRead = 0;
1374 if (!
fileInfo.
gets(readPosition, bufferSize - currentLength, bytesRead))
1379 currentLength += bytesRead;
1388 if (buffer[currentLength - 1] ==
'\n')
1391 return context->NewString(buffer, currentLength - 1);
1399 return context->NewString(buffer, currentLength);
1418 size_t currentLength = 0;
1423 char *readPosition = buffer + currentLength;
1424 size_t bytesRead = 0;
1425 if (!
fileInfo.
gets(readPosition, bufferSize - currentLength, bytesRead))
1431 currentLength += bytesRead;
1440 if (buffer[currentLength - 1] ==
'\n')
1443 context->ArrayAppendString(result, buffer, currentLength - 1);
1452 context->ArrayAppendString(result, buffer, currentLength);
1516 if (read_length == 0)
1526 char *buffer = (
char *)
context->BufferStringData(result);
1539 if (bytesRead < read_length)
1566 return context->NullString();
1600 size_t length =
context->StringLength(data);
1601 const char *stringData =
context->StringData(data);
1616 size_t bytesWritten;
1619 if (bytesWritten != length)
1632 RexxMethod3(
size_t, stream_charout,
CSELF, streamPtr, OPTIONAL_RexxStringObject, data, OPTIONAL_int64_t, position)
1663 if (count != 1 && count != 0)
1693 char *buffer = (
char *)
context->BufferStringData(temp);
1700 return context->FinishBufferString(temp, bytesRead);
1729 return context->NullString();
1762 char *buffer = (
char *)
context->BufferStringData(temp);
1769 context->FinishBufferString(temp, bytesRead);
1770 context->ArrayAppend(result, temp);
1793 return stream_info->
arrayin(result);
1862 return lineCount - currentLine;
1906 if (toupper(*option) ==
'N')
1910 else if (toupper(*option) !=
'C')
1920 return stream_info->
lines(quick);
1962 return remainder > 0 ? remainder : 0;
1973 return stream_info->
chars();
2025 const char *stringData =
context->StringData(data);
2026 size_t length =
context->StringLength(data);
2083 RexxMethod3(
int, stream_lineout,
CSELF, streamPtr, OPTIONAL_RexxStringObject,
string, OPTIONAL_int64_t, position)
2128 if (stream_info == NULL)
2133 stream_info->
setContext(context, context->NullString());
2159 if (stream_info == NULL)
2164 stream_info->
setContext(context, context->NullString());
2176 context->DropObjectVariable(
"CSELF");
2269 if (options != NULL)
2342 #ifdef STREAM_AUTOSYNC
2349 #ifdef STREAM_SHAREDOPEN
2382 #ifdef STREAM_AUTOSYNC
2386 #ifdef STREAM_SHAREDOPEN
2394 if (
parser(tts, options, NULL) != 0)
2447 snprintf(
work,
sizeof work,
"ERROR:%d", ENOENT);
2471 if (!
open(oflag, pmode, shared))
2520 char char_buffer =
' ';
2532 if (
ctrl_z != char_buffer)
2625 int style = SEEK_SET;
2626 bool styleSet =
false;
2627 bool seekBack =
false;
2628 int position_flags = 0;
2632 if (options != NULL)
2695 if (
parser(tts, options, (
void *)(&offset)) != 0)
2920 newLinePosition = lastLine - offset;
2928 newLinePosition = offset;
2936 newLinePosition = offset + current_line;
2942 if (newLinePosition < 1)
2944 newLinePosition = 1;
2948 return setLinePosition(newLinePosition, current_line, current_position);
2970 current_position = 1;
2972 return current_line;
2980 current_line = new_line;
2981 return current_line;
3024 if (current_position == 0)
3026 current_position = 1;
3048 int position_flags = 0;
3051 if (options != NULL)
3094 if (
parser(tts, options, NULL) != 0)
3109 return context->WholeNumberToObject(1);
3120 return context->Int64ToObject(position);
3279 current_line += offset - move;
3285 return current_line;
3302 if (current_line == offset)
3304 return current_line;
3308 if (current_line > offset || current_line <= 0)
3312 current_position = 1;
3314 return readForwardByLine(offset - current_line, current_line, current_position);
3388 stream_info->
setContext(context, context->NullString());
3439 stream_info->
setContext(context, context->NullString());
3464 stream_info->
setContext(context, context->NullString());
3487 return "PERSISTENT";
3515 return context->Int64ToObject(streamsize);
3523 return context->Int64ToObject(streamsize);
3562 stream_info->
setContext(context, context->NullString());
3574 stream_info->
setContext(context, context->NullString());
3611 stream_info->
setContext(context, context->NullString());
3629 return context->NewStringFromAsciiz(
"UNKNOWN:");
3633 return context->NewStringFromAsciiz(
"NOTREADY:EOF");
3638 const char *errorString = NULL;
3645 if (errorString != NULL)
3661 const char *errorString = NULL;
3667 if (errorString != NULL)
3682 return context->NewStringFromAsciiz(
"READY:");
3695 stream_info->
setContext(context, context->NullString());
3730 context->SetObjectVariable(
"CSELF", streamPtr);
int parser(TokenDefinition *ttsp, const char *TokenString, void *userparms)
RexxMethod2(int, stream_arrayin, CSELF, streamPtr, RexxArrayObject, result)
const int position_by_line
const char * StreamInfoProperty
StreamInfo * checkStreamInfo(RexxMethodContext *context, void *streamPtr, RexxObjectPtr result)
const int query_read_position
const int position_offset_specified
const int query_line_position
int position_offset(TokenDefinition *ttsp, StreamToken &tokenizer, void *userparms)
const int operation_nocreate
const int query_write_position
const int query_system_position
const int position_by_char
int unknown_tr(TokenDefinition *ttsp, StreamToken &tokenizer, void *userparms)
int reclength_token(TokenDefinition *ttsp, StreamToken &tokenizer, void *userparms)
RexxMethod1(int64_t, stream_chars, CSELF, streamPtr)
bool hasNoBufferOption(const char *opts)
const int query_char_position
const int operation_write
RexxMethod3(RexxStringObject, stream_charin, CSELF, streamPtr, OPTIONAL_int64_t, position, OPTIONAL_size_t, read_length)
void setLineReadPosition(int64_t position)
const char * getTimeStamp()
int64_t charWritePosition
const char * streamOpen(const char *options)
bool open(int openFlags, int openMode, int sharedFlag)
StreamInfo(RexxObjectPtr s, const char *inputName)
void implicitOpen(int type)
RexxStringObject readVariableLine()
int64_t setLinePositions()
char * allocateBuffer(size_t length)
int64_t lineReadCharPosition
int64_t readForwardByLine(int64_t offset, int64_t ¤t_line, int64_t ¤t_position)
int64_t lineWriteCharPosition
int64_t seekLinePosition(int64_t offset, int direction, int64_t ¤t_line, int64_t ¤t_position)
const char * streamExists()
int64_t getLineWritePosition()
RexxMethodContext * context
char stream_name[SysFileSystem::MaximumFileNameBuffer]
const char * handleOpen(const char *options)
RexxStringObject charin(bool setPosition, int64_t position, size_t read_length)
void resetLinePositions()
void setContext(RexxMethodContext *c, RexxObjectPtr d)
void writeBuffer(const char *data, size_t length, size_t &bytesWritten)
int lineout(RexxStringObject data, bool setPosition, int64_t position)
RexxObjectPtr defaultResult
const char * streamFlush()
size_t binaryRecordLength
int64_t seekToVariableLine(int64_t offset, int64_t ¤t_line, int64_t ¤t_position)
const char * openStd(const char *options)
char qualified_name[SysFileSystem::MaximumFileNameLength]
int64_t getLineReadPosition()
void setCharWritePosition(int64_t position)
int64_t queryLinePosition(int64_t current_position)
RexxStringObject getDescription()
void setCharReadPosition(int64_t position)
void writeFixedLine(const char *data, size_t length)
RexxObjectPtr getStreamSize()
char * getDefaultBuffer(size_t &length)
int64_t countStreamLines(int64_t currentLinePosition, int64_t currentPosition)
void setLineWritePosition(int64_t position)
const char * getStreamType()
RexxObjectPtr queryHandle()
void appendVariableLine(RexxArrayObject r)
RexxObjectPtr queryStreamPosition(const char *options)
void raiseException(int err)
int64_t lineWritePosition
RexxStringObject readLine(char *buffer, size_t length, bool update_position)
void completeLine(size_t writeLength)
void setPosition(int64_t position, int64_t &newPosition)
int64_t setLinePosition(int64_t new_line, int64_t ¤t_line, int64_t ¤t_position)
int64_t streamPosition(const char *options)
int arrayin(RexxArrayObject r)
char * extendBuffer(size_t &length)
void setWritePosition(int64_t position)
int64_t lines(bool quick)
void writeLine(const char *data, size_t length, size_t &bytesWritten)
RexxStringObject linein(bool setPosition, int64_t position, size_t count)
void readBuffer(char *data, size_t length, size_t &bytesRead)
size_t charout(RexxStringObject data, bool setPosition, int64_t position)
const char * getQualifiedName()
const char * streamClose()
void setReadPosition(int64_t position)
bool toNumber(int64_t &num)
bool putLine(const char *buffer, size_t len, size_t &bytesWritten)
bool gets(char *buffer, size_t len, size_t &bytesRead)
bool getSize(int64_t &size)
bool seek(int64_t offset, int direction, int64_t &position)
bool seekForwardLines(int64_t startPosition, int64_t &lineCount, int64_t &endPosition)
bool getPosition(int64_t &position)
void setBuffering(bool buffer, size_t length)
bool getTimeStamp(const char *&time)
bool open(const char *name, int openFlags, int openMode, int shareMode)
bool read(char *buf, size_t len, size_t &bytesRead)
bool countLines(int64_t &count)
bool write(const char *data, size_t len, size_t &bytesWritten)
static bool fileExists(const char *name)
static void qualifyStreamName(const char *unqualifiedName, char *qualifiedName, size_t bufferSize)
static void strupper(char *str)
static int strCaselessCompare(const char *opt1, const char *opt2)
#define argumentExists(i)
#define argumentOmitted(i)
#define Rexx_Error_Incorrect_method_noarg
#define Rexx_Error_Incorrect_method
#define Rexx_Error_Incorrect_method_positive
#define Rexx_Error_Incorrect_method_stream_type
#define Rexx_Error_System_service
struct _RexxStringObject * RexxStringObject
struct _RexxArrayObject * RexxArrayObject
struct _RexxBufferStringObject * RexxBufferStringObject
struct _RexxObjectPtr * RexxObjectPtr
struct _RexxPointerObject * RexxPointerObject