-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.tcl
executable file
·75 lines (59 loc) · 1.3 KB
/
main.tcl
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
73
74
75
#!/usr/local/bin/tclsh8.6
package require Tclx
proc chr_is_delimeter {chr} {
if {$chr eq " " || $chr eq "-"} {
return 1
}
return 0
}
proc waitfor {usec} {
after $usec
}
proc main {} {
set filename "lyrics.dat"
set delay_word 200
set delay_line 1000
signal ignore int
signal ignore quit
set filebuf [read_file [file join [file dirname [info script]] $filename]]
foreach buf [split $filebuf "\n"] {
set buf [string trim $buf]
if {$buf eq ""} {
puts "\r"
} else {
set lpos 0
set buflen [string length $buf]
set lastchr [expr $buflen - 1]
for {set rpos 0} {$rpos < $buflen} {incr rpos} {
set chr [string range $buf $rpos $rpos]
if {[chr_is_delimeter $chr] || $rpos == $lastchr} {
if {[chr_is_delimeter $chr]} {
set end [expr $rpos - 1]
} else {
set end $rpos
}
set word [string range $buf $lpos $end]
if {[regexp {\{(\d+)\}} $word _ usec]} {
waitfor $usec
set last_output "delay"
} else {
puts -nonewline "$word"
if {$chr eq " "} {
puts -nonewline $chr
}
flush stdout
set last_output "text"
waitfor $delay_word
}
set lpos [expr $rpos + 1]
}
}
puts "\r"
if {$last_output ne "delay"} {
waitfor $delay_line
}
}
}
return
}
if !$tcl_interactive main