From: <Mar...@ub...> - 2001-10-15 08:18:02
|
Hi, I started thinking at the weekend how to open a database file in an existing SCID instance if one already exists on the display with a free database slot (similar to the netscape remote functionality, or Emacs' server/client operation). I ended up with the following wish script, which works, but needs some additional error checking to make it bulletproof. I use it as the default open mechanism for SCID .si files under KDE. Disclaimer - it currently loops through all the files given to it on the command line. This means it might try to open a file in a SCID that is currently busy, and bad things *might* happen. (In fact bad things might happen if it is used whilst the SCID instance is busy independently of this script...) Bad things may also happen if you try to open a database that's already open - I haven't looked into the behaviour of openBase in that situation. It works by using Tcl's [send] fucntionality to execute commands in the tkscid interpreter. Hopefully, the formatting won't be screwed up in email transit... Assumptions: nohup, wish and scid are in the user's path. It will probably only work under Unix. (although cygwin might allow it to run under windows) Cheers, Mark #!/bin/sh # Emacs please open me in -*-Tcl-*- mode # the next line restarts using wish if it is in the path \ exec wish "$0" ${1+"$@"} # # we don't need the Tk window (although we have to use wish to # get the winfo and send (probably) commands) # wm withdraw . # # openFileInSCID looks for an existing SCID on the current display # with a vacant DB slot and opens the given file in that SCID. If # no appropriate SCID is running, [exec] one. SCID interpreters # (at least on my system) seem to be called "scid" "scid #2" etc. # proc openFileInSCID { file } { foreach i [winfo interps] { if { [string match "*scid*" $i] } { # check the free slots set free [send $i sc_base count free] if { $free != 0 } { remoteOpen $i $file return } } } # if we got here then we couldn't find a SCID with a free slot # so we need to exec one. nohup is necessary since we want # SCID to stay around after this script exits. exec nohup scid $file & } # # remoteOpen is the backend to openFileInSCID - it needs an interp # name as returned by winfo interps and a database filename # *without* the ".si" extension. No error checking is currently # done. In particular, we should really be checking if the # openBase succeeds, and producing an appropriate error or retrying # if not. # proc remoteOpen { interp file } { send $interp busyCursor . send $interp openBase $file send $interp [list catch {sc_game load 1}] send $interp unbusyCursor . send $interp set glstart 1 send $interp updateGList send $interp updateTreeWin send $interp updateStatsWin send $interp updateMenuStates send $interp updateBoardAndPgn .board send $interp updateTitle send $interp updateStatusBar } # # we do this for every file given on the command line. Probably # need to either wait for a period or do something cleverer in # remoteOpen to avoid race conditions. # foreach file $argv { openFileInSCID [file rootname $file] } exit 0 # That's all folks Visit our website at http://www.ubswarburg.com This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of e-mail transmission. If verification is required please request a hard-copy version. This message is provided for informational purposes and should not be construed as a solicitation or offer to buy or sell any securities or related financial instruments. |