Debian Codegraph @

tools/lou_maketable.d/lou_maketable.in

raw
1 #!/usr/bin/env bash
2 #
3 # liblouis Braille Translation and Back-Translation Library
4 #
5 # Copyright (C) 2017 Bert Frees
6 #
7 # This file is part of liblouis.
8 #
9 # liblouis is free software: you can redistribute it and/or modify it
10 # under the terms of the GNU Lesser General Public License as published
11 # by the Free Software Foundation, either version 2.1 of the License, or
12 # (at your option) any later version.
13 #
14 # liblouis is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Lesser General Public License for more details.
18 #
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with liblouis. If not, see <http://www.gnu.org/licenses/>.
21 #
22
23 if ! make --version 2>/dev/null | grep 'GNU Make' >/dev/null; then
24 echo "ERROR: GNU make is required to run this program" >&2
25 exit 1
26 fi
27 if ! which patgen >/dev/null; then
28 echo "ERROR: patgen is required to run this program" >&2
29 exit 1
30 fi
31 if ! which python3 >/dev/null; then
32 echo "ERROR: python3 is required to run this program" >&2
33 exit 1
34 fi
35
36 if ! python3 -c "from louis import liblouis" 2>/dev/null; then
37 echo "ERROR: the Liblouis python bindings must be installed to run this program" >&2
38 exit 1
39 fi
40
41 function print_help {
42 echo "Usage: $0 [OPTIONS] [COMMAND]" >&2
43 echo "" >&2
44 echo "Commands:" >&2
45 echo " clean clean up generated files" >&2
46 echo "" >&2
47 echo "Options:" >&2
48 echo " --config=FILE read configuration options from FILE (required)"
49 echo " --verbose print debug messages" >&2
50 echo " -h, --help display this help and exit" >&2
51 echo " -v, --version display version information and exit" >&2
52 echo "" >&2
53 echo "Configuration options:" >&2
54 echo " CONTRACTIONS_TABLE location of file where contraction rules are moved to" >&2
55 echo " from the working file" >&2
56 echo " PATTERNS_TABLE location of file where generated hyphenation patterns" >&2
57 echo " are stored" >&2
58 echo " BASE_TABLE base translation table that is augmented with the" >&2
59 echo " generated contractions and patterns tables in order to" >&2
60 echo " get the final result" >&2
61 echo " DICTIONARY location of SQLite database that contains the certified" >&2
62 echo " braille translations of words and where chunk data will" >&2
63 echo " be stored" >&2
64 echo " WORKING_FILE location of file where suggestions for new contraction" >&2
65 echo " rules are written and from which changes to contraction" >&2
66 echo " table and dictionary are read" >&2
67 echo "" >&2
68 echo "Environment variables:" >&2
69 echo " LOUIS_TABLEPATH colon-separated list of directories that is searched" >&2
70 echo " to resolve the base table" >&2
71 echo " EDITOR program that is used to open the working file" >&2
72 echo "" >&2
73 echo "Report bugs to @PACKAGE_BUGREPORT@." >&2
74 echo "@PACKAGE_NAME@ home page: <@PACKAGE_URL@>" >&2
75 }
76
77 HELP=false
78 VERSION=false
79 VERBOSE=false
80
81 function unexpected_argument {
82 echo "ERROR: Unexpected argument: $1" >&2
83 echo "" >&2
84 print_help
85 exit 1
86 }
87
88 while [ $# -gt 0 ]; do
89 if [[ -n ${CMD+x} ]]; then
90 unexpected_argument
91 fi
92 case $1 in
93 -h|--help)
94 if $HELP; then
95 unexpected_argument
96 fi
97 HELP=true
98 ;;
99 -v|--version)
100 if $VERSION; then
101 unexpected_argument
102 fi
103 VERSION=true
104 ;;
105 --verbose)
106 if $VERBOSE; then
107 unexpected_argument
108 fi
109 VERBOSE=true
110 ;;
111 --config=*)
112 if [[ -n ${CONFIG_FILE+x} ]]; then
113 unexpected_argument
114 fi
115 CONFIG_FILE=${1#--config=}
116 ;;
117 clean)
118 CMD=clean
119 ;;
120 *)
121 unexpected_argument
122 ;;
123 esac
124 shift
125 done
126
127 if $HELP; then
128 print_help
129 exit 0
130 fi
131
132 if $VERSION; then
133 echo "lou_maketable (Liblouis) @VERSION@" >&2
134 echo "Copyright (C) 2017 Bert Frees." >&2
135 echo "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>." >&2
136 echo "This is free software: you are free to change and redistribute it." >&2
137 echo "There is NO WARRANTY, to the extent permitted by law." >&2
138 echo "" >&2
139 echo "Written by Bert Frees." >&2
140 exit 0
141 fi
142
143 if [[ -n ${CONFIG_FILE+x} ]]; then
144 if ! [ -e "$CONFIG_FILE" ]; then
145 echo "ERROR: Unexisting file: $CONFIG_FILE" >&2
146 exit 1
147 fi
148 else
149 echo "ERROR: Please specify a configuration file" >&2
150 echo "" >&2
151 print_help
152 exit 1
153 fi
154
155 if ! [[ -n ${CMD+x} ]]; then
156 CMD=suggestions
157 fi
158
159
160 # This file is installed in the parent directory of the lou_maketable.d directory. When run from
161 # within the source code it is sourced from a file within the parent directory. In both cases the
162 # relative path to the lou_maketable.mk file should be "lou_maketable.d/lou_maketable.mk".
163
164 CURDIR=$(cd $(dirname "$0") && pwd)
165
166 make -f $CURDIR/lou_maketable.d/lou_maketable.mk VERBOSE=$VERBOSE CONFIG_FILE=$CONFIG_FILE $CMD