misc/vim: inform the user when no results are found
[nit.git] / lib / niti_runtime.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # This file is free software, which comes along with NIT. This software is
4 # distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
5 # without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
6 # PARTICULAR PURPOSE. You can modify it is you want, provided this header
7 # is kept unaltered, and a notification of the changes is added.
8 # You are allowed to redistribute it and sell it, alone or is a part of
9 # another product.
10
11 # Runtime library to loop around the main program for each line in file-name arguments
12 #
13 # Used by the interpreter when `-n` is used
14 module niti_runtime
15
16 redef class Sys
17 redef fun run do
18 if not args.is_empty then
19 open_next_stream
20 end
21 loop
22 read_next_line
23 main
24 end
25 end
26
27 # Read the next useful line from file-name arguments
28 private fun read_next_line
29 do
30 if stdin.eof then
31 open_next_stream
32 end
33 var line = stdin.read_line
34 loop
35 if not stdin.eof then break
36 open_next_stream
37 if not line.is_empty then break
38 line = stdin.read_line
39 end
40 self.line = line
41 end
42
43 # Open the next file until there is no more arguments
44 private fun open_next_stream
45 do
46 if args.is_empty then exit(0)
47 stdin.close
48 stdin = new FileReader.open(args.shift)
49 end
50
51 # The next line to process by the main program
52 var line: String
53 end