From 5801aeefe16431e8a39d651b8c4810f3b8b3dd87 Mon Sep 17 00:00:00 2001 From: Arun Persaud Date: Sat, 7 May 2011 18:40:23 -0700 Subject: [PATCH] lng2po.sh: added command line options, GPL header also use a temporary file generated with mktemp instead of a hard coded one --- po/lng2po.sh | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- po/metascript | 2 +- 2 files changed, 96 insertions(+), 8 deletions(-) diff --git a/po/lng2po.sh b/po/lng2po.sh index efeda02..aa73656 100755 --- a/po/lng2po.sh +++ b/po/lng2po.sh @@ -1,8 +1,96 @@ -cp winboard/$1 language.lng -recode latin-1 language.lng -ed language.lng < metascript -rm language.lng -cp xboard.pot language.po -ed language.po < script -rm script +#!/bin/bash +# lng2po.sh -- translating .lng files to .po files for XBoard/Winboard, +# part of XBoard GNU project +# +# Copyright 2011 Free Software Foundation, Inc. +# ------------------------------------------------------------------------ +# +# GNU XBoard is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or (at +# your option) any later version. +# +# GNU XBoard is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see http://www.gnu.org/licenses/. * +# +# ------------------------------------------------------------------------ + + +INFO="lng2po.sh (translating .lng files to .po files for XBoard/Winboard)" +USAGE="Usage: `basename $0` [-hv] [-o outputfile] [-e encoding] + default encoding: latin-1 + default output file: ./language.po" + +VERSION="1" + +# default options +OUTPUT="language.po" +ENCODING="latin-1" +INPUT="" +TMPFILE=`mktemp lng2poXXXXX` + +# parse command line arguments +while getopts hvo:e: OPT; do + case "$OPT" in + h) echo $USAGE + exit 0 + ;; + v) echo "`basename $0` version: $VERSION" + exit 0 + ;; + o) OUTPUT=$OPTARG + ;; + e) ENCODING=$OPTARG + ;; + \?) # getopts issues an error message + echo $USAGE >&2 + exit 1 + ;; + :) echo " Error:options -e and -o need an argument" + exit 2 + ;; + esac +done + +# move past the parsed commands in $@ +shift `expr $OPTIND - 1` + +# check if an input file was given and if it exists in ./ or winboard/languages +# also check if it's a .lng file +if [ $# -ne 1 ]; then + echo " Error: Need to specify an input file" + exit 3 +else + if [ ${1: -4} == ".lng" ]; then + INPUT=$1 + else + echo " Error: Input file needs to be a .lng file" + exit 4 + fi +fi + +if [ -e winboard/language/$INPUT ]; then + INPUT=winboard/language/$INPUT +fi + +if [ -e $INPUT ]; then + # do the conversion + + cp $INPUT $TMPFILE + recode $ENCODING $TMPFILE + ed $TMPFILE < metascript + rm $TMPFILE + cp xboard.pot $OUTPUT + ed $OUTPUT < lng2po-helper-script + rm lng2po-helper-script + echo "created $OUTPUT" +else + echo " Error: Couldn't find input file ($INPUT) in current directory or winboard/languages" + exit 5 +fi diff --git a/po/metascript b/po/metascript index b5125cd..e44f604 100644 --- a/po/metascript +++ b/po/metascript @@ -120,6 +120,6 @@ w q . 1,$g/@@@@@@/s//./ -w script +w lng2po-helper-script q -- 1.7.0.4