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

Contents of /eclass/myspell.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations) (download)
Mon May 1 15:24:39 2006 UTC (8 years, 4 months ago) by kevquinn
Branch: MAIN
New eclass for myspell ebuilds

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

  ViewVC Help
Powered by ViewVC 1.1.20