diff --git a/add-eco.sh b/add-eco.sh new file mode 100755 index 0000000..773477d --- /dev/null +++ b/add-eco.sh @@ -0,0 +1,68 @@ +#!/usr/bin/env bash +# +# add-eco.sh - add ECO and openings to a PGN file. +# +# Usage: add-eco.sh [-e ecofile] [fromdir] [todir] +# add-eco.sh [-e ecofile] [fromdir] + +CMD="${0##*/}" + +PATH=$PATH:./pgn-extract + +force=f # dest file overwrite +ecodir=./eco +ecofile=eco.pgn +from=./pgn-orig +to=./pgn + +usage() { + printf "Usage: %s [-ef] from-dir to-dir\n" "$CMD" + return 0 +} + +while getopts "e:fh" todo; do + case "$todo" in + e) + ecofile="$OPTARG" + ;; + f) + force=t + ;; + h) + usage + exit 0 + ;; + *) + usage + ;; + esac +done + +# Now check remaining arguments +shift $((OPTIND - 1)) + +(( $# > 2 )) && usage && exit 1 +(( $# > 0 )) && from="$1" +(( $# > 1 )) && to="$2" +echo "from=$from to=$to eco=$ecodir/$ecofile" + +if ! [[ -d "$from" ]]; then + printf "%s: Source directory missing. Exiting.\n" "$from" + usage + exit 1 +elif ! [[ -d "$to" ]]; then + printf "%s: Destination directory missing. Exiting.\n" "$to" + usage + exit 1 +fi + +for if in "$from"/*.pgn; do + fn=$(basename "$if") + of="$to/$fn" + printf "Converting %s to %s\n" "$if" "$of" + if [[ -e $of && $force != t ]]; then + printf "Destination file %s already exists, skipping...\n" "$of" + continue + fi + pgn-extract --allownullmoves -e"$ecodir/$ecofile" "$if" -o"$of" +done diff --git a/build-br-from-parts.php b/build-br-from-parts.php index 7f66cf9..98ea140 100755 --- a/build-br-from-parts.php +++ b/build-br-from-parts.php @@ -2,7 +2,7 @@