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/>.
26 pipe_loc
= "/tmp/sclang-pipe" unless (pipe_loc
= ENV["SCVIM_PIPE_LOC"])
28 if ENV["SCLANG_RUNDIR"]
29 rundir
= ENV["SCLANG_RUNDIR"]
30 elsif RUBY_PLATFORM =~
/darwin/
31 rundir
= "/Applications/SuperCollider/"
34 pid_loc
= "/tmp/sclangpipe_app-pid" unless (pid_loc
= ENV["SCVIM_PIPE_PID_LOC"])
35 app
= `which sclang`.chomp
37 mac_loc
= "/Applications/SuperCollider/sclang"
38 if RUBY_PLATFORM =~
/darwin/ and File
.exists
?(mac_loc
)
41 puts
"cannot find sclang executable, is it in your path?"
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
53 opts
.on("-d <path>", "Set runtime directory") do |d
|
57 opts
.on("-g <memory-growth>[km]", "Set heap growth (default 256k)") do |g
|
58 sclangargs
= sclangargs
+ " -g #{g}"
61 opts
.on("-l <path>", "Set library configuration file") do |l
|
62 sclangargs
= sclangargs
+ " -l #{l}"
65 opts
.on("-m <memory-space>[km]", "Set initial heap size (default 2m)") do |m
|
66 sclangargs
= sclangargs
+ " -m #{m}"
69 opts
.on("-u <network-port-number>", "Set UDP listening port (default 57120)") do |p
|
70 sclangargs
= sclangargs
+ " -u #{p}"
73 opts
.on("-r", "Call Main.run on startup") do
74 sclangargs
= sclangargs
+ " -r"
77 opts
.on("-s", "Call Main.stop on shutdown") do
78 sclangargs
= sclangargs
+ " -s"
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
)
90 system("mkfifo", pipe_loc
)
96 IO
.popen("#{app} -d #{rundir.chomp} #{sclangargs}", "w") do |sclang
|
104 $p = Process
.fork
{ pipeproc
.call
}
106 #if we get a hup then we kill the pipe process and
109 Process
.kill("INT", $p)
110 $p = Process
.fork
{ pipeproc
.call
}
115 FileUtils
.rm(pipe_loc
)
116 FileUtils
.rm(pid_loc
)
120 #we sleep until a signal comes