File: jtclsh.tcl

package info (click to toggle)
openocd 0.8.0-4%2Bdeb7u1
  • links: PTS
  • area: main
  • in suites: jessie
  • size: 24,840 kB
  • sloc: ansic: 267,518; sh: 15,640; tcl: 6,888; asm: 1,684; cpp: 1,671; makefile: 1,185; perl: 717; python: 708; haskell: 35
file content (36 lines) | stat: -rw-r--r-- 860 bytes parent folder | download | duplicates (3)
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
# Simple example of how the history extension
# can be used to provide line editing and history

# Build jimsh with the history extension and enable line editing (the default)
# ./configure --with-ext=history

package require history

set histfile [env HOME]/.jtclsh
history load $histfile
while 1 {
	if {[history getline "jim> " cmd] < 0} {
		break
	}
	if {$cmd eq "h"} {
		history show
		continue
	}
	# Don't bother adding single char commands to the history
	if {[string length $cmd] > 1} {
		history add $cmd
		history save $histfile
	}
	# jimsh also does:
	# - check for a complete command: [info complete]
	# - handle other non-error return codes and changes the prompt: [info returncodes]
	# - displays the complete error message: [errorInfo]
	try {
		set result [eval $cmd]
		if {$result ne {}} {
			puts $result
		}
	} on error msg {
		puts $msg
	}
}