class library: Spawner - don't access PriorityQueue-array
[supercollider.git] / editors / scvim / bin / sclangpipe_app
blob0bc8606ec8a3fd021b6a71ba31ee7ab38b3898d8
1 #!/usr/bin/env ruby
2 #SCvim pipe
3 #this is a script to pass things from scvim to sclang
5 #Copyright 2007 Alex Norman
7 #This file is part of SCVIM.
9 #SCVIM is free software: you can redistribute it and/or modify
10 #it under the terms of the GNU General Public License as published by
11 #the Free Software Foundation, either version 3 of the License, or
12 #(at your option) any later version.
14 #SCVIM is distributed in the hope that it will be useful,
15 #but WITHOUT ANY WARRANTY; without even the implied warranty of
16 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 #GNU General Public License for more details.
19 #You should have received a copy of the GNU General Public License
20 #along with SCVIM. If not, see <http://www.gnu.org/licenses/>.
22 require 'fileutils'
23 require 'open3'
24 require 'optparse'
26 pipe_loc = "/tmp/sclang-pipe" unless (pipe_loc = ENV["SCVIM_PIPE_LOC"])
27 rundir = "/tmp/"
28 if ENV["SCLANG_RUNDIR"]
29 rundir = ENV["SCLANG_RUNDIR"]
30 elsif RUBY_PLATFORM =~ /darwin/
31 rundir = "/Applications/SuperCollider/"
32 end
34 pid_loc = "/tmp/sclangpipe_app-pid" unless (pid_loc = ENV["SCVIM_PIPE_PID_LOC"])
35 app = `which sclang`.chomp
36 if app.empty?
37 mac_loc = "/Applications/SuperCollider/sclang"
38 if RUBY_PLATFORM =~ /darwin/ and File.exists?(mac_loc)
39 app = mac_loc
40 else
41 puts "cannot find sclang executable, is it in your path?"
42 exit -1
43 end
44 end
46 sclangargs = "-i scvim" # this arg must always be passed, so that sclang knows to load classes from folders named "scide_scvim"
48 opts = OptionParser.new do |opts|
49 opts.on("-h", "--help", "Display this help") do
50 puts opts
51 exit
52 end
53 opts.on("-d <path>", "Set runtime directory") do |d|
54 rundir = d
55 end
57 opts.on("-g <memory-growth>[km]", "Set heap growth (default 256k)") do |g|
58 sclangargs = sclangargs + " -g #{g}"
59 end
61 opts.on("-l <path>", "Set library configuration file") do |l|
62 sclangargs = sclangargs + " -l #{l}"
63 end
65 opts.on("-m <memory-space>[km]", "Set initial heap size (default 2m)") do |m|
66 sclangargs = sclangargs + " -m #{m}"
67 end
69 opts.on("-u <network-port-number>", "Set UDP listening port (default 57120)") do |p|
70 sclangargs = sclangargs + " -u #{p}"
71 end
73 opts.on("-r", "Call Main.run on startup") do
74 sclangargs = sclangargs + " -r"
75 end
77 opts.on("-s", "Call Main.stop on shutdown") do
78 sclangargs = sclangargs + " -s"
79 end
81 end
83 opts.parse!(ARGV)
85 File.open(pid_loc, "w"){ |f| f.puts Process.pid }
87 #remove the pipe if it exists
88 FileUtils.rm(pipe_loc) if File.exists?(pipe_loc)
89 #make a new pipe
90 system("mkfifo", pipe_loc)
92 pipeproc = Proc.new {
93 trap("INT") do
94 Process.exit
95 end
96 IO.popen("#{app} -d #{rundir.chomp} #{sclangargs}", "w") do |sclang|
97 loop {
98 x = `cat #{pipe_loc}`
99 sclang.print x if x
104 $p = Process.fork { pipeproc.call }
106 #if we get a hup then we kill the pipe process and
107 #restart it
108 trap("HUP") do
109 Process.kill("INT", $p)
110 $p = Process.fork { pipeproc.call }
113 #clean up after us
114 trap("INT") do
115 FileUtils.rm(pipe_loc)
116 FileUtils.rm(pid_loc)
117 exit
120 #we sleep until a signal comes
121 sleep(1) until false