Below there is a patch for sc_import.tcl which adds an extra way to run 
this command. If run with

    sc_import somedatabase -

the command will read the names of PGN files to import from standard
input.

Why?
------

First, it makes it possible to do things like

    find . -name '*.pgn' -a -mtime 0   |  sc_import mydatabase -

but I wrote it mainly to workaround shell line length restrictions 
while importing a lot of PGNs.

Note also, that loong time ago I offered similar patch to scmerge
(accepted in scid 3.6.19)

Patch
------

As the file has not been touched for ages, I just attach the patched
version (scripts/sc_import.tcl).

#!/bin/sh

# sc_import:
#     Import PGN files of games into an existing Scid database.
#
# Usage:  sc_import <scid-database> <pgn-files....>
#    or:  sc_import <scid-database> -
#
# In the latter case the list of pgn names will be read from standard input.
# Example usage:
#     find . -name '*.pgn' | sc_import somedatabase -
#

# 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...>"
    puts stderr "   or: sc_import <scid-database> -"
    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
}

proc import_pgn {pgnfile} {
    global sc_base
    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
    }
}

for {set i 1} {$i < $args} {incr i} {
    set pgnfile [lindex $argv $i]
    if {$pgnfile != "-"} {
        import_pgn $pgnfile
    } else {
        puts stderr "Enter names of PGN files, one per line"
        while {[gets stdin name] != -1} {
            import_pgn $name
        }
    }
}

sc_base close
------------------------------------------------------------------------------
Xperia(TM) PLAY
It's a major breakthrough. An authentic gaming
smartphone on the nation's most reliable network.
And it wants your games.
http://p.sf.net/sfu/verizon-sfdev
_______________________________________________
Scid-users mailing list
Scid-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/scid-users

Reply via email to