1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # Author: Kevin F. Quinn <kevquinn@gentoo.org>
6 # Packages: app-dicts/myspell-*
7 # Maintainer: maintainer-needed@gentoo.org
11 EXPORT_FUNCTIONS src_install pkg_preinst pkg_postinst
17 # tar, gzip, bzip2 are included in the base profile, but not unzip
18 DEPEND="app-arch/unzip"
20 # Dictionaries don't have any runtime dependencies
21 # Myspell dictionaries can be used by hunspell, openoffice and others
24 # The destination directory for myspell dictionaries
25 MYSPELL_DICTBASE="/usr/share/myspell"
27 # Legacy variable for dictionaries installed before eselect-oodict existed
28 # so has to remain for binpkg support. This variable is unmaintained -
29 # if you have a problem with it, emerge app-eselect/eselect-oodict.
30 # The location for openoffice softlinks
31 MYSPELL_OOOBASE="/usr/lib/openoffice/share/dict/ooo"
34 # set array "fields" to the elements of $1, separated by $2.
35 # This saves having to muck about with IFS all over the place.
44 # language is the second element of the ebuild name
45 # myspell-<lang>-<version>
52 get_myspell_suffixes() {
54 DICT) echo ".aff .dic" ;;
56 THES) echo ".dat .idx" ;;
60 # OOo dictionary files are held on the mirrors, rather than
61 # being fetched direct from the OOo site as upstream doesn't
62 # change the name when they rebuild the dictionaries.
63 # <lang>-<country>.zip becomes myspell-<lang>-<country>-version.zip
64 get_myspell_ooo_uri() {
65 local files fields newfile filestem srcfile dict uris
69 "${MYSPELL_SPELLING_DICTIONARIES[@]}" \
70 "${MYSPELL_HYPHENATION_DICTIONARIES[@]}" \
71 "${MYSPELL_THESAURUS_DICTIONARIES[@]}"; do
72 set_fields "${dict}" ","
73 newfile=${fields[4]// }
74 for file in "${files[@]}"; do
75 [[ ${file} == ${newfile} ]] && continue 2
77 filestem=${newfile/.zip}
78 files=("${files[@]}" "${newfile}")
79 srcfile="myspell-${filestem}-${PV}.zip"
81 uris="mirror://gentoo/${srcfile}" ||
82 uris="${uris} mirror://gentoo/${srcfile}"
88 [[ -z ${SRC_URI} ]] && SRC_URI=$(get_myspell_ooo_uri)
90 # Format of dictionary.lst files (from OOo standard
91 # dictionary.lst file):
93 # List of All Dictionaries to be Loaded by OpenOffice
94 # ---------------------------------------------------
95 # Each Entry in the list have the following space delimited fields
97 # Field 0: Entry Type "DICT" - spellchecking dictionary
98 # "HYPH" - hyphenation dictionary
99 # "THES" - thesaurus files
101 # Field 1: Language code from Locale "en" or "de" or "pt" ...
103 # Field 2: Country Code from Locale "US" or "GB" or "PT"
105 # Field 3: Root name of file(s) "en_US" or "hyph_de" or "th_en_US"
106 # (do not add extensions to the name)
108 # Format of MYSPELL_[SPELLING|HYPHENATION|THESAURUS]_DICTIONARIES:
110 # Field 0: Language code
111 # Field 1: Country code
112 # Field 2: Root name of dictionary files
113 # Field 3: Description
114 # Field 4: Archive filename
116 # This format is from the available.lst, hyphavail.lst and
117 # thesavail.lst files on the openoffice.org repository.
119 myspell_src_install() {
120 local filen fields entry dictlst
122 # Install the dictionary, hyphenation and thesaurus files.
123 # Create dictionary.lst.<lang> file containing the parts of
124 # OOo's dictionary.lst file for this language, indicating
125 # which dictionaries are relevant for each country variant
127 insinto ${MYSPELL_DICTBASE}
128 dictlst="dictionary.lst.$(get_myspell_lang)"
129 echo "# Autogenerated by ${CATEGORY}/${P}" > ${dictlst}
130 for entry in "${MYSPELL_SPELLING_DICTIONARIES[@]}"; do
131 set_fields "${entry}" ","
132 echo "DICT ${fields[0]} ${fields[1]} ${fields[2]}" >> ${dictlst}
133 doins ${fields[2]}.aff || die "Missing ${fields[2]}.aff"
134 doins ${fields[2]}.dic || die "Missing ${fields[2]}.dic"
136 for entry in "${MYSPELL_HYPHENATION_DICTIONARIES[@]}"; do
137 set_fields "${entry}" ","
138 echo "HYPH ${fields[0]} ${fields[1]} ${fields[2]}" >> ${dictlst}
139 doins ${fields[2]}.dic || die "Missing ${fields[2]}.dic"
141 for entry in "${MYSPELL_THESAURUS_DICTIONARIES[@]}"; do
142 set_fields "${entry}" ","
143 echo "THES ${fields[0]} ${fields[1]} ${fields[2]}" >> ${dictlst}
144 doins ${fields[2]}.dat || die "Missing ${fields[2]}.dat"
145 doins ${fields[2]}.idx || die "Missing ${fields[2]}.idx"
147 doins ${dictlst} || die "Failed to install ${dictlst}"
148 # Install any txt files (usually README.txt) as documentation
149 for filen in *.txt; do
150 [[ -s ${filen} ]] && dodoc ${filen}
155 # Add entries in dictionary.lst.<lang> to OOo dictionary.lst
156 # and create softlinks indicated by dictionary.lst.<lang>
157 myspell_pkg_postinst() {
158 # Update for known applications
159 if has_version ">=app-eselect/eselect-oodict-20060706"; then
160 if has_version app-office/openoffice; then
161 eselect oodict set myspell-$(get_myspell_lang)
163 if has_version app-office/openoffice-bin; then
164 # On AMD64, openoffice-bin is 32-bit so force ABI
165 has_multilib_profile && ABI=x86
166 eselect oodict set myspell-$(get_myspell_lang) --libdir $(get_libdir)
170 if has_version app-eselect/eselect-oodict; then
171 eselect oodict set myspell-$(get_myspell_lang)
175 # Legacy code for dictionaries installed before eselect-oodict existed
176 # so has to remain for binpkg support. This code is unmaintained -
177 # if you have a problem with it, emerge app-eselect/eselect-oodict.
178 [[ -d ${MYSPELL_OOOBASE} ]] || return
179 # This stuff is here, not in src_install, as the softlinks are
180 # deliberately _not_ listed in the package database.
181 local dictlst entry fields prefix suffix suffixes filen
182 # Note; can only reach this point if ${MYSPELL_DICTBASE}/${dictlst}
183 # was successfully installed
184 dictlst="dictionary.lst.$(get_myspell_lang)"
187 [[ ${fields[0]:0:1} == "#" ]] && continue
188 [[ -f ${MYSPELL_OOOBASE}/dictionary.lst ]] || \
189 touch ${MYSPELL_OOOBASE}/dictionary.lst
190 grep "^${fields[0]} ${fields[1]} ${fields[2]} " \
191 ${MYSPELL_OOOBASE}/dictionary.lst > /dev/null 2>&1 ||
192 echo "${entry}" >> ${MYSPELL_OOOBASE}/dictionary.lst
193 for suffix in $(get_myspell_suffixes ${fields[0]}); do
194 filen="${fields[3]}${suffix}"
195 [[ -h ${MYSPELL_OOOBASE}/${filen} ]] &&
196 rm -f ${MYSPELL_OOOBASE}/${filen}
197 [[ ! -f ${MYSPELL_OOOBASE}/${filen} ]] &&
198 ln -s ${MYSPELL_DICTBASE}/${filen} \
199 ${MYSPELL_OOOBASE}/${filen}
201 done < ${MYSPELL_DICTBASE}/${dictlst}
205 # Remove softlinks and entries in dictionary.lst - uses
206 # dictionary.<lang>.lst from /usr/share/myspell
207 # Done in preinst (prerm happens after postinst, which overwrites
208 # the dictionary.<lang>.lst file)
209 myspell_pkg_preinst() {
210 # Update for known applications
211 if has_version ">=app-eselect/eselect-oodict-20060706"; then
212 if has_version app-office/openoffice; then
213 # When building from source, the default library path is correct
214 eselect oodict unset myspell-$(get_myspell_lang)
216 if has_version app-office/openoffice-bin; then
217 # On AMD64, openoffice-bin is 32-bit, so get 32-bit library directory
218 has_multilib_profile && ABI=x86
219 eselect oodict unset myspell-$(get_myspell_lang) --libdir $(get_libdir)
221 eselect oodict unset myspell-$(get_myspell_lang) --libdir $(get_libdir)
224 # Previous versions of eselect-oodict didn't cater for -bin on amd64
225 if has_version app-eselect/eselect-oodict; then
226 eselect oodict unset myspell-$(get_myspell_lang)
230 # Legacy code for dictionaries installed before eselect-oodict existed
231 # Don't delete this; needed for uninstalls and binpkg support.
232 # This code is unmaintained - if you have a problem with it,
233 # emerge app-eselect/eselect-oodict.
234 local filen dictlst entry fields removeentry suffix
235 dictlst="dictionary.lst.$(get_myspell_lang)"
236 [[ -d ${MYSPELL_OOOBASE} ]] || return
237 [[ -f ${MYSPELL_DICTBASE}/${dictlst} ]] || return
240 [[ ${fields[0]:0:1} == "#" ]] && continue
241 [[ ${fields[3]} == "" ]] && continue
242 # Remove entry from dictionary.lst
243 sed -i -e "/^${fields[0]} ${fields[1]} ${fields[2]} ${fields[3]}$/ { d }" \
244 ${MYSPELL_OOOBASE}/dictionary.lst
245 # See if any other entries in dictionary.lst match the current
246 # dictionary type and filename
247 grep "^${fields[0]} .* ${fields[3]}$" ${MYSPELL_OOOBASE}/dictionary.lst \
248 2>&1 > /dev/null && continue
249 # If no other entries match, remove relevant symlinks
250 for suffix in $(get_myspell_suffixes ${fields[0]}); do
251 filen="${fields[3]}${suffix}"
252 ewarn "Removing entry ${MYSPELL_OOOBASE}/${filen}"
253 [[ -h ${MYSPELL_OOOBASE}/${filen} ]] &&
254 rm -f ${MYSPELL_OOOBASE}/${filen}
256 done < ${MYSPELL_DICTBASE}/${dictlst}