Compare commits
10 Commits
Author | SHA1 | Date |
---|---|---|
Paul van Tilburg | 6ee6a68694 | |
Paul van Tilburg | 5b7130c2f9 | |
Paul van Tilburg | fb1a0606fd | |
Paul van Tilburg | 174ec96c6d | |
Paul van Tilburg | 2c996c7a18 | |
Paul van Tilburg | 0fe0a966f0 | |
Paul van Tilburg | 240ea58411 | |
Paul van Tilburg | 84b231d729 | |
Paul van Tilburg | d78227a8e2 | |
Paul van Tilburg | c50791cba1 |
48
rubberin
48
rubberin
|
@ -70,10 +70,8 @@ def compile(infile, mode)
|
|||
params = ARGV.join(" ")
|
||||
err_file = infile.with_extname("err")
|
||||
|
||||
_ret = system "rubber --inplace #{mode_opt} #{params} #{infile} 2> #{err_file}"
|
||||
system "rubber --inplace #{mode_opt} #{params} #{infile} 2> #{err_file}"
|
||||
File.open(err_file) { |file| puts file.read }
|
||||
# Remove the output save file if compile was succesful.
|
||||
# clean(infile) if ret
|
||||
end
|
||||
|
||||
# Start the right viewer based on the mode.
|
||||
|
@ -109,7 +107,7 @@ end
|
|||
|
||||
## Initialisation
|
||||
PROGRAM = File.basename($PROGRAM_NAME).freeze
|
||||
VERSION = "0.7".freeze
|
||||
VERSION = "0.9".freeze
|
||||
|
||||
# Parse the command line options.
|
||||
# Determine the compile mode from the options.
|
||||
|
@ -128,8 +126,10 @@ opts.each do |opt, _arg|
|
|||
when "--ps"
|
||||
mode = :ps
|
||||
when "--pdf"
|
||||
mode = if mode == :ps then :pspdf
|
||||
else :pdf
|
||||
mode = if mode == :ps
|
||||
:pspdf
|
||||
else
|
||||
:pdf
|
||||
end
|
||||
when "--version"
|
||||
puts "#{PROGRAM} #{VERSION}"
|
||||
|
@ -143,12 +143,9 @@ if ARGV.empty?
|
|||
exit 1
|
||||
else
|
||||
infile = Pathname.new(ARGV.shift)
|
||||
def infile.base
|
||||
basename(extname)
|
||||
end
|
||||
|
||||
def infile.with_extname(ext)
|
||||
file = base
|
||||
file = dirname + basename(extname)
|
||||
file.extname = ".#{ext}"
|
||||
file
|
||||
end
|
||||
|
@ -162,7 +159,7 @@ rescue SystemCallError => e
|
|||
exit 2
|
||||
end
|
||||
|
||||
# Find the dependancies of the input file using rubber-info and
|
||||
# Find the dependencies of the input file using rubber-info and
|
||||
# do an initial run.
|
||||
files = `rubber-info --deps #{infile}`.chomp.split
|
||||
compile(infile, mode)
|
||||
|
@ -175,23 +172,14 @@ viewer_pid =
|
|||
view(infile, mode)
|
||||
# If xdvi/evince exits, this program should exit too.
|
||||
puts "#{PROGRAM}: viewer exited, so will I!"
|
||||
Process.kill("TERM", pid)
|
||||
Process.kill("HUP", pid)
|
||||
end
|
||||
|
||||
# Handle signals.
|
||||
["INT", "TERM", "QUIT"].each do |sig|
|
||||
Signal.trap(sig) do
|
||||
Process.kill(sig, viewer_pid)
|
||||
clean(infile)
|
||||
exit
|
||||
end
|
||||
end
|
||||
|
||||
## Main event loop
|
||||
|
||||
# Add input file with dependancies to the watch list and start event loop.
|
||||
notifier = INotify::Notifier.new
|
||||
dirs = files.map { |file| Pathname.new(file).dirname.realpath }.uniq
|
||||
dirs = files.map { |file| Pathname.new(file).dirname }.uniq
|
||||
dirs.each do |dir|
|
||||
# Set up a watch per directory
|
||||
notifier.watch(dir.to_s, :close_write) do |ev|
|
||||
|
@ -199,11 +187,25 @@ dirs.each do |dir|
|
|||
file_path = (dir + ev.name).to_s
|
||||
next unless files.include? file_path
|
||||
|
||||
puts "I: file #{ev.name} modified, compiling #{infile}..."
|
||||
puts "#{PROGRAM}: file #{ev.name} modified, compiling #{infile}..."
|
||||
compile(infile, mode)
|
||||
reload(infile, mode)
|
||||
puts
|
||||
end
|
||||
end
|
||||
|
||||
# Handle signals during the main event loop.
|
||||
["INT", "TERM", "QUIT"].each do |sig|
|
||||
Signal.trap(sig) do
|
||||
puts "#{PROGRAM}: caught signal #{sig}, stopping the viewer..."
|
||||
Process.kill(sig, viewer_pid)
|
||||
notifier.stop
|
||||
end
|
||||
end
|
||||
Signal.trap("HUP") { notifier.stop }
|
||||
|
||||
# Run the main event loop.
|
||||
notifier.run
|
||||
|
||||
# Clean before finishing!
|
||||
clean(infile)
|
||||
|
|
Loading…
Reference in New Issue