/[gentoo-x86]/eclass/myspell.eclass
Gentoo

Contents of /eclass/myspell.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (hide annotations) (download)
Thu Jun 15 11:25:18 2006 UTC (8 years, 7 months ago) by kevquinn
Branch: MAIN
Changes since 1.3: +21 -4 lines
Remove dependency on hunspell, add use of eselect-oodict, add author info.

1 kevquinn 1.1 # Copyright 1999-2006 Gentoo Foundation
2     # Distributed under the terms of the GNU General Public License v2
3 kevquinn 1.4 # $Header: /var/cvsroot/gentoo-x86/eclass/myspell.eclass,v 1.3 2006/05/22 18:09:00 kevquinn Exp $
4    
5     # Author: Kevin F. Quinn <kevquinn@gentoo.org>
6     # Packages: app-dicts/myspell-*
7     # Herd: app-dicts
8 kevquinn 1.1
9 kevquinn 1.2 EXPORT_FUNCTIONS src_install pkg_preinst pkg_postinst
10 kevquinn 1.1
11     IUSE=""
12    
13     SLOT="0"
14    
15 kevquinn 1.3 # tar, gzip, bzip2 are included in the base profile, but not unzip
16     DEPEND="app-arch/unzip"
17    
18 kevquinn 1.4 # Dictionaries don't have any runtime dependencies
19     # Myspell dictionaries can be used by hunspell, openoffice and others
20     RDEPEND=""
21 kevquinn 1.1
22     # The destination directory for myspell dictionaries
23     MYSPELL_DICTBASE="/usr/share/myspell"
24    
25     # The location for openoffice softlinks
26     MYSPELL_OOOBASE="/usr/lib/openoffice/share/dict/ooo"
27    
28    
29     # set array "fields" to the elements of $1, separated by $2.
30     # This saves having to muck about with IFS all over the place.
31     set_fields() {
32     local old_IFS
33     old_IFS="${IFS}"
34     IFS=$2
35     fields=($1)
36     IFS="${old_IFS}"
37     }
38    
39     # language is the second element of the ebuild name
40     # myspell-<lang>-<version>
41     get_myspell_lang() {
42     local fields
43     set_fields "${P}" "-"
44     echo ${fields[1]}
45     }
46    
47     get_myspell_suffixes() {
48     case $1 in
49     DICT) echo ".aff .dic" ;;
50     HYPH) echo ".dic" ;;
51     THES) echo ".dat .idx" ;;
52     esac
53     }
54    
55     # OOo dictionary files are held on the mirrors, rather than
56     # being fetched direct from the OOo site as upstream doesn't
57     # change the name when they rebuild the dictionaries.
58     # <lang>-<country>.zip becomes myspell-<lang>-<country>-version.zip
59     get_myspell_ooo_uri() {
60     local files fields newfile filestem srcfile dict uris
61     files=()
62     uris=""
63     for dict in \
64     "${MYSPELL_SPELLING_DICTIONARIES[@]}" \
65     "${MYSPELL_HYPHENATION_DICTIONARIES[@]}" \
66     "${MYSPELL_THESAURUS_DICTIONARIES[@]}"; do
67     set_fields "${dict}" ","
68     newfile=${fields[4]// }
69     for file in "${files[@]}"; do
70     [[ ${file} == ${newfile} ]] && continue 2
71     done
72     filestem=${newfile/.zip}
73     files=("${files[@]}" "${newfile}")
74     srcfile="myspell-${filestem}-${PV}.zip"
75     [[ -z ${uris} ]] &&
76     uris="mirror://gentoo/${srcfile}" ||
77     uris="${uris} mirror://gentoo/${srcfile}"
78     done
79     echo "${uris}"
80     }
81    
82    
83     [[ -z ${SRC_URI} ]] && SRC_URI=$(get_myspell_ooo_uri)
84    
85     # Format of dictionary.lst files (from OOo standard
86     # dictionary.lst file):
87     #
88     # List of All Dictionaries to be Loaded by OpenOffice
89     # ---------------------------------------------------
90     # Each Entry in the list have the following space delimited fields
91     #
92     # Field 0: Entry Type "DICT" - spellchecking dictionary
93     # "HYPH" - hyphenation dictionary
94     # "THES" - thesaurus files
95     #
96     # Field 1: Language code from Locale "en" or "de" or "pt" ...
97     #
98     # Field 2: Country Code from Locale "US" or "GB" or "PT"
99     #
100     # Field 3: Root name of file(s) "en_US" or "hyph_de" or "th_en_US"
101     # (do not add extensions to the name)
102    
103     # Format of MYSPELL_[SPELLING|HYPHENATION|THESAURUS]_DICTIONARIES:
104     #
105     # Field 0: Language code
106     # Field 1: Country code
107     # Field 2: Root name of dictionary files
108     # Field 3: Description
109     # Field 4: Archive filename
110     #
111     # This format is from the available.lst, hyphavail.lst and
112     # thesavail.lst files on the openoffice.org repository.
113    
114     myspell_src_install() {
115     local filen fields entry dictlst
116     cd ${WORKDIR}
117     # Install the dictionary, hyphenation and thesaurus files.
118     # Create dictionary.lst.<lang> file containing the parts of
119     # OOo's dictionary.lst file for this language, indicating
120     # which dictionaries are relevant for each country variant
121     # of the language.
122     insinto ${MYSPELL_DICTBASE}
123     dictlst="dictionary.lst.$(get_myspell_lang)"
124     echo "# Autogenerated by ${CATEGORY}/${P}" > ${dictlst}
125     for entry in "${MYSPELL_SPELLING_DICTIONARIES[@]}"; do
126     set_fields "${entry}" ","
127     echo "DICT ${fields[0]} ${fields[1]} ${fields[2]}" >> ${dictlst}
128     doins ${fields[2]}.aff || die "Missing ${fields[2]}.aff"
129     doins ${fields[2]}.dic || die "Missing ${fields[2]}.dic"
130     done
131     for entry in "${MYSPELL_HYPHENATION_DICTIONARIES[@]}"; do
132     set_fields "${entry}" ","
133     echo "HYPH ${fields[0]} ${fields[1]} ${fields[2]}" >> ${dictlst}
134     doins ${fields[2]}.dic || die "Missing ${fields[2]}.dic"
135     done
136     for entry in "${MYSPELL_THESAURUS_DICTIONARIES[@]}"; do
137     set_fields "${entry}" ","
138     echo "THES ${fields[0]} ${fields[1]} ${fields[2]}" >> ${dictlst}
139     doins ${fields[2]}.dat || die "Missing ${fields[2]}.dat"
140     doins ${fields[2]}.idx || die "Missing ${fields[2]}.idx"
141     done
142 kevquinn 1.2 doins ${dictlst} || die "Failed to install ${dictlst}"
143 kevquinn 1.1 # Install any txt files (usually README.txt) as documentation
144     for filen in $(ls *.txt 2> /dev/null); do
145     dodoc ${filen}
146     done
147     }
148    
149    
150     # Add entries in dictionary.lst.<lang> to OOo dictionary.lst
151     # and create softlinks indicated by dictionary.lst.<lang>
152     myspell_pkg_postinst() {
153 kevquinn 1.4 has_version eselect-oodict &&
154     eselect oodict set myspell-$(get_myspell_lang)
155    
156     # Legacy code for dictionaries installed before eselect-oodict existed
157     # so has to remain for binpkg support. This code is unmaintained -
158     # if you have a problem with it, emerge eselect-oodict.
159 kevquinn 1.1 [[ -d ${MYSPELL_OOOBASE} ]] || return
160     # This stuff is here, not in src_install, as the softlinks are
161     # deliberately _not_ listed in the package database.
162     local dictlst entry fields prefix suffix suffixes filen
163     # Note; can only reach this point if ${MYSPELL_DICTBASE}/${dictlst}
164     # was successfully installed
165     dictlst="dictionary.lst.$(get_myspell_lang)"
166     while read entry; do
167     fields=(${entry})
168     [[ ${fields[0]:0:1} == "#" ]] && continue
169     [[ -f ${MYSPELL_OOOBASE}/dictionary.lst ]] || \
170     touch ${MYSPELL_OOOBASE}/dictionary.lst
171     grep "^${fields[0]} ${fields[1]} ${fields[2]} " \
172     ${MYSPELL_OOOBASE}/dictionary.lst > /dev/null 2>&1 ||
173     echo "${entry}" >> ${MYSPELL_OOOBASE}/dictionary.lst
174     for suffix in $(get_myspell_suffixes ${fields[0]}); do
175     filen="${fields[3]}${suffix}"
176 kevquinn 1.2 [[ -h ${MYSPELL_OOOBASE}/${filen} ]] &&
177     rm -f ${MYSPELL_OOOBASE}/${filen}
178 kevquinn 1.1 [[ ! -f ${MYSPELL_OOOBASE}/${filen} ]] &&
179     ln -s ${MYSPELL_DICTBASE}/${filen} \
180     ${MYSPELL_OOOBASE}/${filen}
181     done
182     done < ${MYSPELL_DICTBASE}/${dictlst}
183     }
184    
185    
186     # Remove softlinks and entries in dictionary.lst - uses
187 kevquinn 1.2 # dictionary.<lang>.lst from /usr/share/myspell
188     # Done in preinst (prerm happens after postinst, which overwrites
189     # the dictionary.<lang>.lst file)
190     myspell_pkg_preinst() {
191 kevquinn 1.4 if has_version app-admin/eselect-oodict; then
192     eselect oodict unset myspell-$(get_myspell_lang)
193     return
194     fi
195    
196     # Legacy code for dictionaries installed before eselect-oodict existed
197     # Don't delete this; needed for uninstalls and binpkg support.
198 kevquinn 1.1 local filen dictlst entry fields removeentry suffix
199     dictlst="dictionary.lst.$(get_myspell_lang)"
200     [[ -d ${MYSPELL_OOOBASE} ]] || return
201 kevquinn 1.2 [[ -f ${MYSPELL_DICTBASE}/${dictlst} ]] || return
202 kevquinn 1.1 while read entry; do
203     fields=(${entry})
204     [[ ${fields[0]:0:1} == "#" ]] && continue
205 kevquinn 1.2 [[ ${fields[3]} == "" ]] && continue
206 kevquinn 1.1 # Remove entry from dictionary.lst
207     sed -i -e "/^${fields[0]} ${fields[1]} ${fields[2]} ${fields[3]}$/ { d }" \
208     ${MYSPELL_OOOBASE}/dictionary.lst
209     # See if any other entries in dictionary.lst match the current
210     # dictionary type and filename
211     grep "^${fields[0]} .* ${fields[3]}$" ${MYSPELL_OOOBASE}/dictionary.lst \
212     2>&1 > /dev/null && continue
213     # If no other entries match, remove relevant symlinks
214     for suffix in $(get_myspell_suffixes ${fields[0]}); do
215     filen="${fields[3]}${suffix}"
216 kevquinn 1.2 ewarn "Removing entry ${MYSPELL_OOOBASE}/${filen}"
217     [[ -h ${MYSPELL_OOOBASE}/${filen} ]] &&
218 kevquinn 1.1 rm -f ${MYSPELL_OOOBASE}/${filen}
219     done
220     done < ${MYSPELL_DICTBASE}/${dictlst}
221     }

  ViewVC Help
Powered by ViewVC 1.1.20