File: sc_tree.tcl

package info (click to toggle)
scid 3.6.1-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 8,640 kB
  • ctags: 5,099
  • sloc: tcl: 59,342; cpp: 40,922; ansic: 5,482; sh: 2,479; makefile: 350; python: 278
file content (56 lines) | stat: -rw-r--r-- 1,304 bytes parent folder | download | duplicates (5)
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
#!/bin/sh
# \
exec tcscid "$0" "$@"

proc usage {} {
  puts stderr {Usage: sc_tree [-eco <eco-file>] [-pgn <output-file>] <database> [moves...]}
  puts stderr {Example: sc_tree -pgn out.pgn mygames 1.e4 e6}
  exit 1
}

set ecoFile ""
set pgnFile ""

if {[llength $argv] == 0} { usage }
while {[lindex $argv 0] == "-eco"  ||  [lindex $argv 0] == "-pgn"} {
  if {[llength $argv] < 3} { usage }
  if {[lindex $argv 0] == "-eco"} {
    set ecoFile [lindex $argv 1]
  } else {
    set pgnFile [lindex $argv 1]
  }
  set argv [lrange $argv 2 end]
}

set base [lindex $argv 0]
set argv [lrange $argv 1 end]
if {[llength $argv] > 0  && [catch {eval sc_move addSan $argv} err]} {
  puts stderr "Error in move list: $err"
  exit 1
}

if {$ecoFile != ""} {
  if {[catch {sc_eco read $ecoFile} err]} {
    puts stderr "Unable to read ECO file: $ecoFile"
    exit 1
  }
}

if {[catch {sc_base open -fast -readonly $base} err]} {
  puts stderr "Error opening database \"$base\": $err"
  exit 1
}

puts [sc_tree search]

if {$pgnFile != ""} {
  puts ""
  if {[file exists $pgnFile]} {
    puts "Output file \"[file tail $pgnFile]\" already exists! It was not altered."
  } else {
    sc_base export filter PGN $pgnFile -comments 1 -variations 1
    puts "Wrote [sc_filter count] games to $pgnFile"
  }
}

sc_base close