| 1 | #!/bin/bash |
| 2 | |
| 3 | sourced () { |
| 4 | [[ "$0" != "${BASH_SOURCE[0]}" ]] |
| 5 | } |
| 6 | |
| 7 | main () { |
| 8 | set -e -u |
| 9 | apertium -d . nob-nno "$@" |
| 10 | } |
| 11 | |
| 12 | |
| 13 | # TODO: read the <incompatibilities> section and remove any where both have v="true" |
| 14 | |
| 15 | allPrefsExceptNPK () { |
| 16 | cd "$(dirname "${BASH_SOURCE[0]}")"/.. |
| 17 | set -o pipefail |
| 18 | grep -o '<preference *id="[^"]*"' prefs/nob-nno.xml \ |
| 19 | | sed 's,.*id=",,;s,"$,,' \ |
| 20 | | grep -vxe infa_infe -e me_vi |
| 21 | } |
| 22 | |
| 23 | # shopt -s inherit_errexit # apparently this doesn't exist in bash<4.4 |
| 24 | AP_SETVAR="$(allPrefsExceptNPK | tr '\n' ',' | sed 's/,$//' )" |
| 25 | export AP_SETVAR |
| 26 | |
| 27 | # Simple sanity test, shout if we can't find all the variable names in one of monodix and biprefs |
| 28 | selftest () { |
| 29 | ( |
| 30 | cd "$(dirname "${BASH_SOURCE[0]}")"/.. |
| 31 | if [[ ! -f ../apertium-nno/apertium-nno.nno.dix ]]; then |
| 32 | echo "$PWD/../apertium-nno/apertium-nno.nno.dix doesn't exist, skipping selftest" |
| 33 | return |
| 34 | fi |
| 35 | allPrefsExceptNPK | while IFS=$'\n' read -r x; do |
| 36 | if [[ $x == kløyvd_inf ]]; then |
| 37 | # no sdef for this one, lemma-list in genprefs instead |
| 38 | continue |
| 39 | fi |
| 40 | grep -q -w -F "VAR:$x" apertium-nno-nob.nob-nno.biprefs.rlx \ |
| 41 | || grep -q -w -F "VAR:$x" merge-quotes.rlx \ |
| 42 | || grep -q -F "sdef n=\"v:$x\"" ../apertium-nno/apertium-nno.nno.dix \ |
| 43 | || echo "WARNING: v:$x not found in nno.dix / merge-quotes.rlx / biprefs.rlx" >&2 |
| 44 | done |
| 45 | ) |
| 46 | } |
| 47 | |
| 48 | # shellcheck disable=SC2310 |
| 49 | if sourced; then |
| 50 | selftest |
| 51 | else |
| 52 | main "$@" |
| 53 | fi |