zlib: Don't use PASTE for INTMAX error messages
[jimtcl.git] / examples / jtclsh.tcl
blobb384717c698f8e3e35e31e9b5b391cd4ad1d534f
1 # Simple example of how the history extension
2 # can be used to provide line editing and history
4 # Build jimsh with the history extension and enable line editing (the default)
5 # ./configure --with-ext=history
7 package require history
9 set histfile [env HOME]/.jtclsh
10 history load $histfile
11 set prefix ""
12 while {1} {
13 # Read a complete line (script)
14 set prompt "${prefix}jim> "
15 set cmd {}
16 while {1} {
17 if {[history getline $prompt line] < 0} {
18 exit 0
20 if {$cmd ne ""} {
21 append cmd \n
23 append cmd $line
24 if {[info complete $cmd char]} {
25 break
27 set prompt "$char> "
30 if {$cmd eq "h"} {
31 history show
32 continue
35 # Don't bother adding single char commands to the history
36 if {[string length $cmd] > 1} {
37 history add $cmd
38 history save $histfile
41 # Evaluate the script and display the error
42 try {
43 set result [eval $cmd]
44 set prefix ""
45 } on {error return break continue signal} {result opts} {
46 set rcname [info returncodes $opts(-code)]
47 if {$rcname eq "ok" } {
48 # Note: return set -code to 0
49 set rcname return
50 } elseif {$rcname eq "error"} {
51 set result [errorInfo $result]
53 set prefix "\[$rcname\] "
55 if {$result ne {}} {
56 puts $result