X-Git-Url: http://nitlanguage.org diff --git a/lib/standard/file.nit b/lib/standard/file.nit index 5390293..bbb45d2 100644 --- a/lib/standard/file.nit +++ b/lib/standard/file.nit @@ -2,6 +2,7 @@ # # Copyright 2004-2008 Jean Privat # Copyright 2008 Floréal Morandat +# Copyright 2008 Jean-Sébastien Gélinas # # 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; @@ -30,9 +31,7 @@ redef class Object # 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 @@ -53,12 +52,11 @@ 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 @@ -98,7 +96,7 @@ special BufferedIStream 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) @@ -109,6 +107,7 @@ special BufferedIStream assert cant_open_file: _file != null end + private init do end private init without_file do end end @@ -155,6 +154,7 @@ special OStream _writable = true end + private init do end private init without_file do end end @@ -195,6 +195,8 @@ redef class String 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 @@ -237,7 +239,7 @@ redef class String 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 / @@ -247,7 +249,7 @@ redef class String 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 @@ -256,6 +258,7 @@ redef class NativeString 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 @@ -277,7 +280,7 @@ special Pointer 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"