-
Notifications
You must be signed in to change notification settings - Fork 5
/
gps_get
61 lines (53 loc) · 1.71 KB
/
gps_get
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env ruby
require 'gps_pvt/util'
require 'uri'
$stderr.puts <<__STRING__
Usage: #{__FILE__} file_or_URI(s) ...
This utility outputs GNSS data specified with file_or_URI(s).
A file_or_URI having additional ".gz" or ".Z" extension is recognized as a compressed file, and the decompression is performed before output.
In addition to a local file, major URIs such as http(s)://..., ftp://..., and ntrip:// are supported.
Serial port (COMn for Windows, /dev/tty* for *NIX) is also acceptable as an input file name.
__STRING__
options = []
files = ARGV.collect{|arg|
next arg unless arg =~ /^--([^=]+)=?/
k, v = [$1.downcase.to_sym, $']
options << [$1.to_sym, $']
nil
}.compact
spec2io = proc{|spec, mode_r|
mode_r = ((nil == mode_r) || mode_r)
is_stream = false
if (!(uri = URI::parse(spec)).instance_of?(URI::Generic) rescue false) then
spec = uri
is_stream = true if uri.kind_of?(URI::Ntrip)
else
is_stream = GPS_PVT::Util::special_stream?(spec)
end
if is_stream || (!mode_r) then
GPS_PVT::Util::open(spec, mode_r ? 'r' : 'a+')
else
open(GPS_PVT::Util::get_txt(spec), 'r')
end
}
STDIN.binmode
STDOUT.binmode
dst, io_dst = proc{|spec| [spec, spec2io.call(spec, false)]}.call('-')
options.reject!{|k, v|
case k
when :out
dst, io_dst = [v, spec2io.call(v, false)]
next true
end
false
}
raise "Unknown option: #{options.first}" unless options.empty?
$stderr.puts "out: #{{'-' => '(stdout)'}[dst] || dst}"
threads = files.collect{|src|
$stderr.puts "in: #{{'-' => '(stdin)'}[src] || src}"
io_src = spec2io.call(src)
Thread.start{
io_dst.write(io_src.read(128)) until io_src.eof?
}
}
threads.each{|t| t.join}