Skip to content

Instantly share code, notes, and snippets.

@kosh04
Created November 19, 2010 09:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kosh04/706277 to your computer and use it in GitHub Desktop.
Save kosh04/706277 to your computer and use it in GitHub Desktop.
[newLISP]シェルスクリプトからguiserver.jarを操作するテスト
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment