module file
intrude import stream
-intrude import string
+intrude import ropes
import string_search
import time
# The FILE *.
private var file: nullable NativeFile = null
+ # The status of a file. see POSIX stat(2).
fun file_stat: FileStat do return _file.file_stat
# File descriptor of this file
redef fun close
do
- var i = _file.io_close
+ _file.io_close
_buffer.clear
end_reached = true
end
end
end
- private init do end
- private init without_file do end
end
# File output stream
redef fun close
do
- var i = _file.io_close
+ _file.io_close
_is_writable = false
end
self.path = path
_is_writable = true
end
-
- private init do end
- private init without_file do end
end
###############################################################################
+# Standard input stream.
class Stdin
super IFStream
- private init do
+ init do
_file = new NativeFile.native_stdin
path = "/dev/stdin"
prepare_buffer(1)
redef fun poll_in: Bool is extern "file_stdin_poll_in"
end
+# Standard output stream.
class Stdout
super OFStream
- private init do
+ init do
_file = new NativeFile.native_stdout
path = "/dev/stdout"
_is_writable = true
end
end
+# Standard error stream.
class Stderr
super OFStream
- private init do
+ init do
_file = new NativeFile.native_stderr
path = "/dev/stderr"
_is_writable = true
# Correctly join two path using the directory separator.
#
- # Using a standard "{self}/{path}" does not work when `self` is the empty string.
- # This method ensure that the join is valid.
+ # Using a standard "{self}/{path}" does not work in the following cases:
+ #
+ # * `self` is empty.
+ # * `path` ends with `'/'`.
+ # * `path` starts with `'/'`.
#
- # assert "hello".join_path("world") == "hello/world"
- # assert "hel/lo".join_path("wor/ld") == "hel/lo/wor/ld"
- # assert "".join_path("world") == "world"
- # assert "/hello".join_path("/world") == "/world"
+ # This method ensures that the join is valid.
#
- # Note: you may want to use `simplify_path` on the result
+ # assert "hello".join_path("world") == "hello/world"
+ # assert "hel/lo".join_path("wor/ld") == "hel/lo/wor/ld"
+ # assert "".join_path("world") == "world"
+ # assert "hello".join_path("/world") == "/world"
+ # assert "hello/".join_path("world") == "hello/world"
+ # assert "hello/".join_path("/world") == "/world"
#
- # Note: I you want to join a great number of path, you can write
+ # Note: You may want to use `simplify_path` on the result.
#
- # [p1, p2, p3, p4].join("/")
+ # Note: This method works only with POSIX paths.
fun join_path(path: String): String
do
if path.is_empty then return self
if self.is_empty then return path
if path.chars[0] == '/' then return path
+ if self.last == '/' then return "{self}{path}"
return "{self}/{path}"
end