summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin F. Quinn <kevquinn@gentoo.org>2006-05-01 15:24:39 +0000
committerKevin F. Quinn <kevquinn@gentoo.org>2006-05-01 15:24:39 +0000
commit679750b69d9e0aaf852fd2506a07c8d17171f507 (patch)
treedbca330b9b49da8b229cadcc296e43b535f16c21 /eclass/myspell.eclass
parentOptional support for deprecated ssl ciphers. (diff)
downloadhistorical-679750b69d9e0aaf852fd2506a07c8d17171f507.tar.gz
historical-679750b69d9e0aaf852fd2506a07c8d17171f507.tar.bz2
historical-679750b69d9e0aaf852fd2506a07c8d17171f507.zip
New eclass for myspell ebuilds
Diffstat (limited to 'eclass/myspell.eclass')
-rw-r--r--eclass/myspell.eclass198
1 files changed, 198 insertions, 0 deletions
diff --git a/eclass/myspell.eclass b/eclass/myspell.eclass
new file mode 100644
index 000000000000..f90a16f1504f
--- /dev/null
+++ b/eclass/myspell.eclass
@@ -0,0 +1,198 @@
+# Copyright 1999-2006 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/eclass/myspell.eclass,v 1.1 2006/05/01 15:24:39 kevquinn Exp $
+
+EXPORT_FUNCTIONS src_install pkg_postinst pkg_prerm
+
+IUSE=""
+
+SLOT="0"
+
+# The console application for using myspell dictionaries is
+# hunspell (which is making myspell itself obsolete).
+RDEPEND="app-text/hunspell"
+
+# The destination directory for myspell dictionaries
+MYSPELL_DICTBASE="/usr/share/myspell"
+
+# The location for openoffice softlinks
+MYSPELL_OOOBASE="/usr/lib/openoffice/share/dict/ooo"
+
+
+# set array "fields" to the elements of $1, separated by $2.
+# This saves having to muck about with IFS all over the place.
+set_fields() {
+ local old_IFS
+ old_IFS="${IFS}"
+ IFS=$2
+ fields=($1)
+ IFS="${old_IFS}"
+}
+
+# language is the second element of the ebuild name
+# myspell-<lang>-<version>
+get_myspell_lang() {
+ local fields
+ set_fields "${P}" "-"
+ echo ${fields[1]}
+}
+
+get_myspell_suffixes() {
+ case $1 in
+ DICT) echo ".aff .dic" ;;
+ HYPH) echo ".dic" ;;
+ THES) echo ".dat .idx" ;;
+ esac
+}
+
+# OOo dictionary files are held on the mirrors, rather than
+# being fetched direct from the OOo site as upstream doesn't
+# change the name when they rebuild the dictionaries.
+# <lang>-<country>.zip becomes myspell-<lang>-<country>-version.zip
+get_myspell_ooo_uri() {
+ local files fields newfile filestem srcfile dict uris
+ files=()
+ uris=""
+ for dict in \
+ "${MYSPELL_SPELLING_DICTIONARIES[@]}" \
+ "${MYSPELL_HYPHENATION_DICTIONARIES[@]}" \
+ "${MYSPELL_THESAURUS_DICTIONARIES[@]}"; do
+ set_fields "${dict}" ","
+ newfile=${fields[4]// }
+ for file in "${files[@]}"; do
+ [[ ${file} == ${newfile} ]] && continue 2
+ done
+ filestem=${newfile/.zip}
+ files=("${files[@]}" "${newfile}")
+ srcfile="myspell-${filestem}-${PV}.zip"
+ [[ -z ${uris} ]] &&
+ uris="mirror://gentoo/${srcfile}" ||
+ uris="${uris} mirror://gentoo/${srcfile}"
+ done
+ echo "${uris}"
+}
+
+
+[[ -z ${SRC_URI} ]] && SRC_URI=$(get_myspell_ooo_uri)
+
+# Format of dictionary.lst files (from OOo standard
+# dictionary.lst file):
+#
+# List of All Dictionaries to be Loaded by OpenOffice
+# ---------------------------------------------------
+# Each Entry in the list have the following space delimited fields
+#
+# Field 0: Entry Type "DICT" - spellchecking dictionary
+# "HYPH" - hyphenation dictionary
+# "THES" - thesaurus files
+#
+# Field 1: Language code from Locale "en" or "de" or "pt" ...
+#
+# Field 2: Country Code from Locale "US" or "GB" or "PT"
+#
+# Field 3: Root name of file(s) "en_US" or "hyph_de" or "th_en_US"
+# (do not add extensions to the name)
+
+# Format of MYSPELL_[SPELLING|HYPHENATION|THESAURUS]_DICTIONARIES:
+#
+# Field 0: Language code
+# Field 1: Country code
+# Field 2: Root name of dictionary files
+# Field 3: Description
+# Field 4: Archive filename
+#
+# This format is from the available.lst, hyphavail.lst and
+# thesavail.lst files on the openoffice.org repository.
+
+myspell_src_install() {
+ local filen fields entry dictlst
+ cd ${WORKDIR}
+ # Install the dictionary, hyphenation and thesaurus files.
+ # Create dictionary.lst.<lang> file containing the parts of
+ # OOo's dictionary.lst file for this language, indicating
+ # which dictionaries are relevant for each country variant
+ # of the language.
+ insinto ${MYSPELL_DICTBASE}
+ dictlst="dictionary.lst.$(get_myspell_lang)"
+ echo "# Autogenerated by ${CATEGORY}/${P}" > ${dictlst}
+ for entry in "${MYSPELL_SPELLING_DICTIONARIES[@]}"; do
+ set_fields "${entry}" ","
+ echo "DICT ${fields[0]} ${fields[1]} ${fields[2]}" >> ${dictlst}
+ doins ${fields[2]}.aff || die "Missing ${fields[2]}.aff"
+ doins ${fields[2]}.dic || die "Missing ${fields[2]}.dic"
+ done
+ for entry in "${MYSPELL_HYPHENATION_DICTIONARIES[@]}"; do
+ set_fields "${entry}" ","
+ echo "HYPH ${fields[0]} ${fields[1]} ${fields[2]}" >> ${dictlst}
+ doins ${fields[2]}.dic || die "Missing ${fields[2]}.dic"
+ done
+ for entry in "${MYSPELL_THESAURUS_DICTIONARIES[@]}"; do
+ set_fields "${entry}" ","
+ echo "THES ${fields[0]} ${fields[1]} ${fields[2]}" >> ${dictlst}
+ doins ${fields[2]}.dat || die "Missing ${fields[2]}.dat"
+ doins ${fields[2]}.idx || die "Missing ${fields[2]}.idx"
+ done
+ doins ${dictlst} || die "Failed to install ${dictlist}"
+ # Install any txt files (usually README.txt) as documentation
+ for filen in $(ls *.txt 2> /dev/null); do
+ dodoc ${filen}
+ done
+}
+
+
+# Add entries in dictionary.lst.<lang> to OOo dictionary.lst
+# and create softlinks indicated by dictionary.lst.<lang>
+myspell_pkg_postinst() {
+ [[ -d ${MYSPELL_OOOBASE} ]] || return
+ # This stuff is here, not in src_install, as the softlinks are
+ # deliberately _not_ listed in the package database.
+ local dictlst entry fields prefix suffix suffixes filen
+ # Note; can only reach this point if ${MYSPELL_DICTBASE}/${dictlst}
+ # was successfully installed
+ dictlst="dictionary.lst.$(get_myspell_lang)"
+ while read entry; do
+ fields=(${entry})
+ [[ ${fields[0]:0:1} == "#" ]] && continue
+ [[ -f ${MYSPELL_OOOBASE}/dictionary.lst ]] || \
+ touch ${MYSPELL_OOOBASE}/dictionary.lst
+ grep "^${fields[0]} ${fields[1]} ${fields[2]} " \
+ ${MYSPELL_OOOBASE}/dictionary.lst > /dev/null 2>&1 ||
+ echo "${entry}" >> ${MYSPELL_OOOBASE}/dictionary.lst
+ for suffix in $(get_myspell_suffixes ${fields[0]}); do
+ filen="${fields[3]}${suffix}"
+ [[ ! -f ${MYSPELL_OOOBASE}/${filen} ]] &&
+ ln -s ${MYSPELL_DICTBASE}/${filen} \
+ ${MYSPELL_OOOBASE}/${filen}
+ done
+ done < ${MYSPELL_DICTBASE}/${dictlst}
+}
+
+
+# Remove softlinks and entries in dictionary.lst - uses
+# dictionary.<lang>.lst from /usr/share/myspell so has to
+# be prerm not postrm.
+myspell_pkg_prerm() {
+ local filen dictlst entry fields removeentry suffix
+ dictlst="dictionary.lst.$(get_myspell_lang)"
+ [[ -d ${MYSPELL_OOOBASE} ]] || return
+ while read entry; do
+ fields=(${entry})
+ [[ ${fields[0]:0:1} == "#" ]] && continue
+ # Remove entry from dictionary.lst
+ sed -i -e "/^${fields[0]} ${fields[1]} ${fields[2]} ${fields[3]}$/ { d }" \
+ ${MYSPELL_OOOBASE}/dictionary.lst
+ # See if any other entries in dictionary.lst match the current
+ # dictionary type and filename
+ grep "^${fields[0]} .* ${fields[3]}$" ${MYSPELL_OOOBASE}/dictionary.lst \
+ 2>&1 > /dev/null && continue
+ # If no other entries match, remove relevant symlinks
+ for suffix in $(get_myspell_suffixes ${fields[0]}); do
+ filen="${fields[3]}${suffix}"
+ if [[ -h ${MYSPELL_OOOBASE}/${filen} ]]; then
+ rm -f ${MYSPELL_OOOBASE}/${filen}
+ fi
+ done
+
+ done < ${MYSPELL_DICTBASE}/${dictlst}
+}
+