# assert i2.eof
# ~~~
#
- # NOTE: Only LINE FEED (`\n`) is considered to delimit the end of lines.
+ # NOTE: Use `append_line_to` if the line terminator needs to be preserved.
fun read_line: String
do
+ if last_error != null then return ""
- assert not eof
+ if eof then return ""
var s = new FlatBuffer
append_line_to(s)
- return s.to_s
+ return s.to_s.chomp
end
# Read all the lines until the eof.
end
# Read all the stream until the eof.
+ #
+ # The content of the file is returned verbatim.
+ #
+ # ~~~
+ # var txt = "Hello\n\nWorld\n"
+ # var i = new StringIStream(txt)
+ # assert i.read_all == txt
+ # ~~~
fun read_all: String
do
+ if last_error != null then return ""
var s = new FlatBuffer
while not eof do
var c = read_char
# Read a string until the end of the line and append it to `s`.
#
- # SEE: `read_line` for details.
+ # Unlike `read_line` and other related methods,
+ # 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)
+ # var b = new FlatBuffer
+ # i.append_line_to(b)
+ # assert b == "Hello\n"
+ # i.append_line_to(b)
+ # assert b == "Hello\n\n"
+ # i.append_line_to(b)
+ # assert b == txt
+ # 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
+ # var b2 = new FlatBuffer
+ # i2.append_line_to(b2)
+ # assert b2 == "hello"
+ # assert i2.eof
+ # ~~~
+ #
+ # NOTE: The single character LINE FEED (`\n`) delimits the end of lines.
+ # Therefore CARRIAGE RETURN & LINE FEED (`\r\n`) is also recognized.
fun append_line_to(s: Buffer)
do
+ if last_error != null then return
loop
var x = read_char
if x == -1 then
super IStream
redef fun read_char
do
- if _buffer_pos >= _buffer.length then
- fill_buffer
- end
- if _buffer_pos >= _buffer.length then
- if last_error != null then return 0
- if eof then last_error = new IOError("Stream has reached eof")
- if _buffer_pos >= _buffer.length then
- fill_buffer
- end
- if _buffer_pos >= _buffer.length then
++ if last_error != null then return -1
++ if eof then
++ last_error = new IOError("Stream has reached eof")
return -1
end
var c = _buffer.chars[_buffer_pos]
redef fun read(i)
do
+ if last_error != null then return ""
if _buffer.length == _buffer_pos then
if not eof then
- fill_buffer
return read(i)
end
return ""
var model = new Model
var mb = new ModelBuilder(model, tc)
- if opt_depends.value then
- if opt_recursive.value then
- print "-M incompatible with -r"
- exit 1
+ if tc.option_context.rest.is_empty then tc.option_context.rest.add "."
+ var files
+ if opt_recursive.value then
+ files = new Array[String]
+ for d in tc.option_context.rest do
+ var pipe = new IProcess("find", d, "-name", "*.nit")
+ while not pipe.eof do
+ var l = pipe.read_line
+ if l == "" then break # last line
- l = l.substring(0,l.length-1) # strip last oef
+ files.add l
+ end
+ pipe.close
+ pipe.wait
+ if pipe.status != 0 and not opt_keep.value then exit 1
end
-
- mb.parse(tc.option_context.rest)
else
- var files
- if opt_recursive.value then
- files = new Array[String]
- for d in tc.option_context.rest do
- var pipe = new IProcess("find", d, "-name", "*.nit")
- while not pipe.eof do
- var l = pipe.read_line
- if l == "" then break # last line
- files.add l
+ files = tc.option_context.rest
+ end
+
+ if sum == 0 then
+ # If one of the file is a group, default is `opt_tree` instead of `opt_project`
+ for a in files do
+ var g = mb.get_mgroup(a)
+ if g != null then
+ opt_tree.value = true
+ opt_project.value = false
+ break
+ end
+ end
+ end
+
+ # Identify all relevant files
+ for a in files do
+ var g = mb.get_mgroup(a)
+ var mp = mb.identify_file(a)
+ if g != null and not opt_project.value then
+ mb.visit_group(g)
+ end
+ if g == null and mp == null then
+ # not a group not a module, then look at files in the directory
+ var fs = a.files
+ for f in fs do
+ g = mb.get_mgroup(a/f)
+ if g != null and not opt_project.value then
+ mb.visit_group(g)
end
- pipe.close
- pipe.wait
- if pipe.status != 0 and not opt_keep.value then exit 1
+ mp = mb.identify_file(a/f)
+ #print "{a/f}: {mp or else "?"}"
end
- else
- files = tc.option_context.rest
end
+ end
- for a in files do
- var mp = mb.identify_file(a)
- if mp == null then
- tc.check_errors
+ # Load modules to get more informations
+ for mp in mb.identified_files do
+ if not opt_paths.value or opt_depends.value then
+ var mm = mb.load_module(mp.filepath)
+ if mm != null and opt_depends.value then
+ mb.build_module_importation(mm)
end
end
end