File: Progress.tcl

package info (click to toggle)
dart 0.20061109-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 5,668 kB
  • ctags: 247
  • sloc: tcl: 5,652; perl: 256; python: 141; cpp: 79; makefile: 68; sh: 36
file content (65 lines) | stat: -rw-r--r-- 1,410 bytes parent folder | download | duplicates (2)
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
set Progress(Size) 0
set Progress(BS) ""
set Progress(Width) 20

for { set i 0 } { $i < $Progress(Width) } { incr i } {
  append Progress(BS) "\b"
}

set Spinner(\\) "|"
set Spinner(|) "/"
set Spinner(/) "-"
set Spinner(-) "\\"

set Spinner(Symbol) "\\"

set Progress(Time) [clock clicks]

proc Status { {last 0} } {
  global Progress Spinner
  if { $last } {
    puts [format "  Size: %5dK" [expr int($Progress(Size) / 1024.0)]]
    return
  }
  if { $Progress(Count) == 0 } {
    puts "\t. == 1024 bytes of log file"
    puts -nonewline "\t"
    incr Progress(Count)
    return
  }
  puts -nonewline "."
  if { ( $Progress(Count) % 50 ) == 0
     && $Progress(Count) != 0 } {
    puts -nonewline [format "  Size: %5dK\n\t" [expr int($Progress(Size) / 1024.0)]]
  }
  incr Progress(Count)
}


proc ReportProgress { inFile outFile {Verbose 0} } {
  global Progress
  flush stdout
  set Progress(Size) 0
  set Progress(Count) 0
  set dsize 0.0
  if { !$Verbose } {
    Status
  }
  while { ![eof $inFile] } {
    set line [read $inFile 256]
    if { $Verbose } { puts -nonewline stdout $line }
    puts -nonewline $outFile $line
  
    set dsize [expr [string length $line] + $dsize]
    incr Progress(Size) [string length $line]
    set t2 [clock clicks]
    # puts "Time: $time T2: $t2"
    if { !$Verbose
         && ( $Progress(Size) % 1024 ) == 0 } { Status }
  }
  if { !$Verbose } {
    Status 1
  }
}