public
Created

[newLISP]シェルスクリプトからguiserver.jarを操作するテスト

  • Download Gist
guiserver-alt.sh
Shell
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
#!/bin/bash
# newLISP-GSを他のプログラミング言語から動かしてみたい
# Time-stamp: <2010-11-19T17:52:59JST>
 
# 必要な要素
# - ソケット通信(TCP/IP),ポートを監視できるとなお良い
# - base64 encode/decode
 
# FIXME
# - シェルスクリプトなので当然Win32環境で使えない
# - guiserverからのコールバック(S式)を扱えるように
# - 子プロセスの後片付け
 
: ${NEWLISPDIR:=$HOME/src/newlisp-10.2.16/guiserver}
 
HOST=localhost
PORT=47011
GUISERVER=${1:-$NEWLISPDIR/guiserver.jar}
JAVA=${JAVA_HOME:-/usr}/bin/java
 
$JAVA -jar $GUISERVER $PORT &
 
sleep 1 # sync
 
send() {
echo "$*" >&3
}
 
setup-server() {
# LOGFILE=/tmp/nl-httpd.log
# touch $LOGFILE
# newlisp -c -d $(($PORT + 1)) -L $LOGFILE &
nc -l localhost $(($PORT + 1)) &
}
 
base64-enc() {
echo "$1" | base64 --wrap=0 -
}
 
exec 3<>/dev/tcp/$HOST/$PORT # bash -> guiserver
setup-server # bash <- guiserver
 
URL="http://www.newlisp.org/"
PAGE="
<html>
<center><br><h2>Text panes for HTML</h2></center>
<blockquote>
<p>This is a page of <i>html</i> text with a clickable hyperlink
<a href='$URL'>html-demo.lsp</a>.</p>
 
<p>The previous link expects the file <tt>html-demo.lsp</tt> in
the current directory from where the program was started.</p>
 
<p>Only simple pages are processed correctly.</p>
 
</blockquote>
</html>
"
 
send "frame" HtmlDemo 100 100 400 270 $(base64-enc "HTML text-pane demo") nil
send "text-pane" HtmlPane htmlpane-callback "text/html" 200 500
send "set-editable" HtmlPane nil
send "set-tab-size" HtmlPane 4
send "set-font" HtmlPane $(base64-enc "Monospaced") 14 plain
send "set-color" HtmlPane 1 1 0.96 1.0
send "set-text" HtmlPane $(base64-enc "$PAGE")
send "append-text" HtmlPane $(base64-enc "This is appended text")
send "add-to" HtmlDemo HtmlPane
send "set-visible" HtmlDemo true
#send "listen"
 
cat <&3
 
# Cleanup
pgrep -l newlisp; pgrep -l java
# killall newlisp
# killall java
3<&-
 
exit

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.