File: sc_import.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 (45 lines) | stat: -rw-r--r-- 1,125 bytes parent folder | download | duplicates (4)
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
#!/bin/sh

# sc_import:
#     Import PGN files of games into an existing Scid database.
#
# Usage:  sc_import <scid-database> <pgn-files....>

# The next line restarts using tcscid: \
exec tcscid "$0" "$@"

set args [llength $argv]
if {$args < 1} {
    puts stderr "Usage: sc_import <scid-database> <pgn-files...>"
    exit 1
}

# Open the database:
set basename [lindex $argv 0]
if {[catch {sc_base open $basename} result]} {
    puts stderr "Error opening database \"$basename\": $result"
    exit 1
}
if {[sc_base isReadOnly]} {
    puts stderr "Error: database \"$basename\" is read-only."
    exit 1
}

for {set i 1} {$i < $args} {incr i} {
    set pgnfile [lindex $argv $i]
    if {[catch {sc_base import file $pgnfile} result]} {
        puts stderr "Error importing \"$pgnfile\": $result"
        exit 1
    }
    set numImported [lindex $result 0]
    set warnings [lindex $result 1]
        puts "Imported $numImported games from $pgnfile"
    if {$warnings == ""} {
        puts "There were no PGN errors or warnings."
    } else {
        puts "PGN errors/warnings:"
        puts $warnings
    }
}

sc_base close