Processing and Storing Text

File, Instream, Outstream and Buffer are used to store text both internally within ABC as well as the operating system in which ABC is running.

File

A file is an ABC object which corresponds to a file in the operating system. You may open, read text, write text and close the file. Files only allow you to read and write text without concern for lines or formatted text. InStream and OutStream provide the additional functionality to process line-based text input and output. For additional functionality, refer to Type PartsList.

Parts

name:String (filename of file)
id:Integer (internal file ID of file)

Type Methods

This section lists methods available when Type File is receiver.

exists filename:String
REPLY Boolean

Reply TRUE if filename exists in operating system

delete filename:String
REPLY String

Delete filename from the operating system. I don't know why it replies with a string.

Instance Methods

This section lists methods which are available to instances of File.

open filename:String for mode:Integer

Open filename for #reading, #writing or #appending.
SIGNAL "Invalid mode for File".

fopen filename:String mode mode:Integer
REPLY Integer

Actually open filename with mode. Reply with an integer status.

read n:Integer
REPLY String

Reply with the next n characters from me.

write data:String

Write data on to me.

close

Close me.

Instream

Type Instream is used to read in text from a file or an internal stream. For additional functionality, refer to Type PartsList.

Parts

data:String (current data for stream)
marker:Integer (location of last read point in data)
infile:File (file to read from)

Type Methods

This section lists methods available when Type Instream is receiver.

newstring source:String

Reply with an internal stream and initialize with source.

newfile filename:String

Reply with an external stream which uses filename as its source.

Instance Methods

This section lists methods which are available to instances of Instream.

charsLeft
REPLY Integer

Reply with the number of characters left in data. There may be more characters in the file.

upToEnd
REPLY String

Reply with the string of characters left to read. There may be more characters in the file.

next
REPLY Integer

Reply with the next character to read and advance marker.

peek
REPLY Integer

Reply with the next character to read but don't advance marker.

advance n:Integer

Advance the marker n characters.

get n:Integer
REPLY String

Get the next n characters.

put n:Integer

Back up the marker n characters.

skipSpaces

Advance the marker to the next no space character. Space characters are space, newline, formfeed and tab.

getWordDelimitedBy delim:String
REPLY String

Get the next word up to a character found in delim.

getWord
REPLY String

Get the next word up to a space tab or new line.

getQuotedString ch:Integer
REPLY String

Get the next string surrounded by the ch character.
SIGNAL "Missing ''''"

getInteger
REPLY Integer

Reply with the next integer in the input.

getLine
REPLY String

Reply with the next line in the input. A line is terminated by a newline character. The returned line does not include the newline. NIL is returned if me is already at the end of the input.

atEnd
REPLY Boolean

Reply TRUE if me is at the end of the input.

close

Close the file if one was being used.

Outstream

Type Outstream is used to write text text to a file or an internal stream. For additional functionality, refer to Type PartsList.

Parts

text:Array (Lines of text for internal streams)
width:Integer (max width of line)
line:String (current line being output)
outfile:File (file to write to)

Type Methods

This section lists methods available when Type Outstream is receiver.

newfile filename:String width size:Integer

Reply with a new stream with filename and width.

newstring size:Integer

Reply with a new internal stream and width size.

Instance Methods

This section lists methods which are available to instances of Outstream.

print s:String

Append s to current output line. If length of line exceeds width, find space to break output line and append to text array for internal stream, or to file for file stream.

printLine s:String

Append s to current line and create a new line.

newline

Append output line to output and start new line.

close
REPLY Array

Close any open file for a file stream or reply with the array of strings for internal stream.

Buffer

Type buffer provides the ability to efficiently buffer output characters and strings without using any file i/o. The buffer will automatically resize up to 4000 characters. For additional functionality, refer to Type PartsList.

Parts

theBuffer:String (the data)
mark:Integer (current location in buffer)

Type Methods

This section lists methods available when Type Buffer is receiver.

new
Reply with an empty buffer of 50 characters.

Instance Methods

This section lists methods which are available to instances of Buffer.

printChar aChar:Integer

Put aChar at the next location in the buffer and resize if needed.
SIGNAL "Buffer overflow"

printString aString:String

Put the characters in aString at the next locations in the buffer.

initialize

Initialize the buffer to 50 characters.

asString
REPLY String

Reply with the current value of the buffer.