-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathma-eval
More file actions
executable file
·72 lines (52 loc) · 1.24 KB
/
ma-eval
File metadata and controls
executable file
·72 lines (52 loc) · 1.24 KB
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
#!/usr/bin/env wish
#
# evaluate code in MA-context
fconfigure stdout -translation lf
fconfigure stderr -translation lf
set exec_prefix ""
set tmpdir "/tmp"
if {[info exists env(HERE)]} {
set exec_prefix $env(HERE)/exec/
}
if {[info exists env(TMPDIR)]} {
set tmpdir $env(TMPDIR)
}
set async ""
proc Usage {{code 1}} {
puts stderr {usage: ma-eval [-h] [-async] [ID] [EXP ...]}
exit $code
}
set exp [lassign $argv id]
if {$id == "-h"} Usage
if {$id == "-async"} {
set exp [lassign $exp id]
set async "-async"
}
if {$id == ""} {
set data [read stdin]
if {$data == ""} exit
set tmpfile $tmpdir/temp-[pid].[expr rand()]
set tmp [open $tmpfile w]
puts -nonewline $tmp $data
close $tmp
set dir [pwd]
set dname "$dir/+Errors"
if {[catch [list send $dname #]]} {
exec ${exec_prefix}ma -name $dname -temporary -tag \
"$dname New Del Cut Paste Snarf Send Look Font Scroll | " &
after 100
}
send $dname AppendFile $tmpfile
file delete $tmpfile
exit
}
if {$exp == ""} {set exp [read stdin]}
if {[catch [list eval send $async $id "$exp"] result]} {
puts stderr $result
exit 1
}
if {$async != ""} exit
if {$result != ""} {
puts $result
}
exit