File: lushslave

package info (click to toggle)
lush 1.0%2Bfinal-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 19,256 kB
  • ctags: 4,254
  • sloc: ansic: 45,498; sh: 3,138; cpp: 2,456; makefile: 372; lisp: 79; python: 5
file content (58 lines) | stat: -rwxr-xr-x 1,331 bytes parent folder | download
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
#!/bin/sh
exec lush "$0" "$@"
!#

(defvar slave-input ())
(defvar slave-output ())

(let ((port 4000))
  ;; Search available port.
  (while (not (socketaccept port)) (incr port))
  (printf "%s %d\n" (reading "|hostname" (read-string)) port)
  (flush)
  ;; Open.
  (socketaccept port 'slave-input 'slave-output) )

(de slave-debug-hook()
  (let ((err (errname)))
    ;; Uncomment to print error messages
    ;; (printf "*** %s\n" err)
    (lush-is-quiet t)
    (writing slave-output
      (print (cons 'error err))
      (flush) ) )
  (lush-is-quiet ()) )

(de slave-break-hook()
  ;; Uncomment to print error messages
  ;; (printf "*** Break\n")
  (lush-is-quiet t)
  (writing slave-output
    (print (cons 'error "Break"))
    (flush) ) 
  (lush-is-quiet ()) )

(unlock-symbol toplevel)

(de toplevel()
  (let ((debug-hook slave-debug-hook)
        (break-hook slave-break-hook))
    (lush-is-quiet ())
    (while (<> (reading slave-input (skip-char)) "\e")
      (let* ((command (reading slave-input (read)))
             (result (eval command)) )
        (writing slave-output
          (bwrite (cons 'ok result))
          (flush) ) ) )
    (lush-is-quiet t)
    (exit 0) ) )

(lock-symbol slave-input 
             slave-output
             slave-debug-hook
             slave-break-hook
             toplevel )

(toplevel)