| 1 | # liblouis Braille Translation and Back-Translation Library |
| 2 | # |
| 3 | # Copyright (C) 2017 Bert Frees |
| 4 | # |
| 5 | # This file is part of liblouis. |
| 6 | # |
| 7 | # liblouis is free software: you can redistribute it and/or modify it |
| 8 | # under the terms of the GNU Lesser General Public License as published |
| 9 | # by the Free Software Foundation, either version 2.1 of the License, or |
| 10 | # (at your option) any later version. |
| 11 | # |
| 12 | # liblouis is distributed in the hope that it will be useful, but |
| 13 | # WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | # Lesser General Public License for more details. |
| 16 | # |
| 17 | # You should have received a copy of the GNU Lesser General Public |
| 18 | # License along with liblouis. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # |
| 20 | |
| 21 | CURDIR=$(cd $(dirname "$0") && pwd) |
| 22 | WORKING_FILE=${1} |
| 23 | CONTRACTIONS_TABLE=${2} |
| 24 | BASE_TABLE=${3} |
| 25 | RULE_GREP="^[ \t]*[+-]\?\(nocross[ \t][ \t]*\)\?\(always\|word\|begword\|endword\|midword\|begmidword\|midendword\|prfword\|sufword\)" |
| 26 | set -e |
| 27 | [[ $VERBOSE == true ]] && set -x |
| 28 | if [ -e $WORKING_FILE ]; then |
| 29 | cat $WORKING_FILE | grep -v "^$" | grep -v "^#" > tmp || true |
| 30 | mv tmp $WORKING_FILE |
| 31 | if cat $WORKING_FILE | grep "$RULE_GREP" > tmp; then |
| 32 | python3 $CURDIR/submit_rules.py -t $BASE_TABLE tmp $CONTRACTIONS_TABLE > tmp2 |
| 33 | mv tmp2 tmp |
| 34 | cat <<- EOF > $CONTRACTIONS_TABLE |
| 35 | ################################## |
| 36 | # don't edit this file directly! # |
| 37 | ################################## |
| 38 | EOF |
| 39 | cat tmp >> $CONTRACTIONS_TABLE |
| 40 | cat $WORKING_FILE | grep -v "$RULE_GREP" > tmp || true |
| 41 | mv tmp $WORKING_FILE |
| 42 | else |
| 43 | rm -f tmp |
| 44 | fi |
| 45 | [ -s $WORKING_FILE ] || rm $WORKING_FILE |
| 46 | fi |