| 1 | #!/bin/bash |
| 2 | |
| 3 | # |
| 4 | # liblouis Braille Translation and Back-Translation Library |
| 5 | # |
| 6 | # Copyright (C) 2022 Anna Stan, Nicolas Morel, Kalilou Mamadou Dramé |
| 7 | # |
| 8 | # This file is part of liblouis. |
| 9 | # |
| 10 | # liblouis is free software: you can redistribute it and/or modify it |
| 11 | # under the terms of the GNU Lesser General Public License as published |
| 12 | # by the Free Software Foundation, either version 2.1 of the License, or |
| 13 | # (at your option) any later version. |
| 14 | # |
| 15 | # liblouis is distributed in the hope that it will be useful, but |
| 16 | # WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | # Lesser General Public License for more details. |
| 19 | # |
| 20 | # You should have received a copy of the GNU Lesser General Public |
| 21 | # License along with liblouis. If not, see <http://www.gnu.org/licenses/>. |
| 22 | # |
| 23 | |
| 24 | if [[ $# -lt 1 ]] |
| 25 | then |
| 26 | echo "Usage: $0 <corpus-dir>" |
| 27 | echo "Usage: $0 --preserve-txt <corpus-dir> (minimize corpus but keep .txt files intact)" |
| 28 | exit 1 |
| 29 | fi |
| 30 | |
| 31 | preserve_txt=0 |
| 32 | if [[ "$1" == "--preserve-txt" ]] |
| 33 | then |
| 34 | preserve_txt=1 |
| 35 | CORPUS_DIR=$2 |
| 36 | else |
| 37 | CORPUS_DIR=$1 |
| 38 | fi |
| 39 | |
| 40 | ROOT_PWD=../../ |
| 41 | export FUZZ_TABLE=$ROOT_PWD/tables/en-us-g2.ctb |
| 42 | FUZZER=$ROOT_PWD/tests/fuzzing/fuzz_translate |
| 43 | |
| 44 | TMP_DIR=$(mktemp -d) |
| 45 | echo "Merging..." |
| 46 | `$FUZZER -merge=1 $TMP_DIR $CORPUS_DIR` |
| 47 | echo "Removing old files..." |
| 48 | if [[ $preserve_txt -eq 1 ]] |
| 49 | then |
| 50 | echo " => Preserve .txt files" |
| 51 | rm -rvf $(find $CORPUS_DIR | grep -vE "*.txt|$CORPUS_DIR") 2>/dev/null |
| 52 | else |
| 53 | rm -rf $CORPUS_DIR/* 2>/dev/null |
| 54 | fi |
| 55 | cp $TMP_DIR/* $CORPUS_DIR 2>/dev/null |
| 56 | rm -rf $TMP_DIR |
| 57 | echo "Merging done !" |