#
# Copyright 2004-2008 Jean Privat <jean@pryen.org>
# Copyright 2008 Floréal Morandat <morandat@lirmm.fr>
+# Copyright 2008 Jean-Sébastien Gélinas <calestar@gmail.com>
#
# This file is free software, which comes along with NIT. This software is
# distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# Print an `object' on the standard output (`stdout') and add a newline.
protected meth print(object: Object)
do
- if object != null then
- stdout.write(object.to_s)
- end
+ stdout.write(object.to_s)
stdout.write("\n")
end
class FStream
special IOS
special NativeFileCapable
-
# The path of the file.
- readable attr _path: String
+ readable attr _path: nullable String = null
# The FILE *.
- attr _file: NativeFile
+ attr _file: nullable NativeFile = null
meth file_stat: FileStat
do return _file.file_stat end
end
# End of file?
- redef readable attr _end_reached: Bool
+ redef readable attr _end_reached: Bool = false
# Open the file at `path' for reading.
init open(path: String)
assert cant_open_file: _file != null
end
+ private init do end
private init without_file do end
end
_writable = true
end
+ private init do end
private init without_file do end
end
meth file_stat: FileStat do return to_cstring.file_stat
+ meth file_delete: Bool do return to_cstring.file_delete
+
meth strip_extension(ext: String): String
do
if has_suffix(ext) then
meth mkdir
do
var dirs = self.split_with("/")
- var path = new String
+ var path = new Buffer
if dirs.is_empty then return
if dirs[0].is_empty then
# it was a starting /
if d.is_empty then continue
path.append(d)
path.add('/')
- path.to_cstring.file_mkdir
+ path.to_s.to_cstring.file_mkdir
end
end
end
private meth file_exists: Bool is extern "string_NativeString_NativeString_file_exists_0"
private meth file_stat: FileStat is extern "string_NativeString_NativeString_file_stat_0"
private meth file_mkdir: Bool is extern "string_NativeString_NativeString_file_mkdir_0"
+ private meth file_delete: Bool is extern "string_NativeString_NativeString_file_delete_0"
end
universal FileStat
meth file_stat: FileStat is extern "file_NativeFile_NativeFile_file_stat_0"
end
-private class NativeFileCapable
+private interface NativeFileCapable
meth io_open_read(path: NativeString): NativeFile is extern "file_NativeFileCapable_NativeFileCapable_io_open_read_1"
meth io_open_write(path: NativeString): NativeFile is extern "file_NativeFileCapable_NativeFileCapable_io_open_write_1"
meth native_stdin: NativeFile is extern "file_NativeFileCapable_NativeFileCapable_native_stdin_0"