class IProcess
super Process
super IStream
+
+ # File Descriptor used for the input.
- var stream_in: FDIStream is noinit
+ var stream_in: IFStream is noinit
redef fun close do stream_in.close
end
end
+ redef class Int
+ # Creates a file stream from a file descriptor `fd` using the file access `mode`.
+ #
+ # NOTE: The `mode` specified must be compatible with the one used in the file descriptor.
+ private fun fd_to_stream(mode: NativeString): NativeFile is extern "file_int_fdtostream"
+ end
+
+ # Constant for read-only file streams
+ private fun read_only: NativeString do return "r".to_cstring
+
+ # Constant for write-only file streams
+ #
+ # If a stream is opened on a file with this method,
+ # it will wipe the previous file if any.
+ # Else, it will create the file.
+ private fun wipe_write: NativeString do return "w".to_cstring
+
###############################################################################
+# Standard input stream.
class Stdin
super IFStream
end
# Read a string until the end of the line.
+ #
+ # The line terminator '\n', if any, is preserved in each line.
+ # Use the method `Text::chomp` to safely remove it.
+ #
+ # ~~~
+ # var txt = "Hello\n\nWorld\n"
+ # var i = new StringIStream(txt)
+ # assert i.read_line == "Hello\n"
+ # assert i.read_line == "\n"
+ # assert i.read_line == "World\n"
+ # assert i.eof
+ # ~~~
+ #
+ # If `\n` is not present at the end of the result, it means that
+ # a non-eol terminated last line was returned.
+ #
+ # ~~~
+ # var i2 = new StringIStream("hello")
+ # assert not i2.eof
+ # assert i2.read_line == "hello"
+ # assert i2.eof
+ # ~~~
+ #
+ # NOTE: Only LINE FEED (`\n`) is considered to delimit the end of lines.
fun read_line: String
do
+ if last_error != null then return ""
assert not eof
var s = new FlatBuffer
append_line_to(s)
end
# Read a string until the end of the line and append it to `s`.
+ #
+ # SEE: `read_line` for details.
fun append_line_to(s: Buffer)
do
+ if last_error != null then return
loop
var x = read_char
if x == -1 then
end
end
+# An Input/Output Stream
- interface IOStream
+ abstract class IOStream
super IStream
super OStream
end