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

Contents of /eclass/myspell.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations) (download)
Mon May 22 18:09:00 2006 UTC (9 years ago) by kevquinn
Branch: MAIN
Changes since 1.2: +4 -1 lines
Add app-arch/unzip to DEPEND; bug #133879 (thanks Ernestas Liubarskij, also Flameeyes)

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

  ViewVC Help
Powered by ViewVC 1.1.20