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

Contents of /eclass/myspell.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download)
Tue May 9 18:20:47 2006 UTC (8 years, 3 months ago) by kevquinn
Branch: MAIN
Changes since 1.1: +13 -9 lines
Move prerm code to preinst, as it uses data from previous installed version
that gets wiped out in preinst - prerm happens after preinst, not before.

1 kevquinn 1.1 # Copyright 1999-2006 Gentoo Foundation
2     # Distributed under the terms of the GNU General Public License v2
3 kevquinn 1.2 # $Header: /var/cvsroot/gentoo-x86/eclass/myspell.eclass,v 1.1 2006/05/01 15:24:39 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     # 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 kevquinn 1.2 doins ${dictlst} || die "Failed to install ${dictlst}"
136 kevquinn 1.1 # 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 kevquinn 1.2 [[ -h ${MYSPELL_OOOBASE}/${filen} ]] &&
164     rm -f ${MYSPELL_OOOBASE}/${filen}
165 kevquinn 1.1 [[ ! -f ${MYSPELL_OOOBASE}/${filen} ]] &&
166     ln -s ${MYSPELL_DICTBASE}/${filen} \
167     ${MYSPELL_OOOBASE}/${filen}
168     done
169     done < ${MYSPELL_DICTBASE}/${dictlst}
170     }
171    
172    
173     # Remove softlinks and entries in dictionary.lst - uses
174 kevquinn 1.2 # dictionary.<lang>.lst from /usr/share/myspell
175     # Done in preinst (prerm happens after postinst, which overwrites
176     # the dictionary.<lang>.lst file)
177     myspell_pkg_preinst() {
178 kevquinn 1.1 local filen dictlst entry fields removeentry suffix
179     dictlst="dictionary.lst.$(get_myspell_lang)"
180     [[ -d ${MYSPELL_OOOBASE} ]] || return
181 kevquinn 1.2 [[ -f ${MYSPELL_DICTBASE}/${dictlst} ]] || return
182 kevquinn 1.1 while read entry; do
183     fields=(${entry})
184     [[ ${fields[0]:0:1} == "#" ]] && continue
185 kevquinn 1.2 [[ ${fields[3]} == "" ]] && continue
186 kevquinn 1.1 # Remove entry from dictionary.lst
187     sed -i -e "/^${fields[0]} ${fields[1]} ${fields[2]} ${fields[3]}$/ { d }" \
188     ${MYSPELL_OOOBASE}/dictionary.lst
189     # See if any other entries in dictionary.lst match the current
190     # dictionary type and filename
191     grep "^${fields[0]} .* ${fields[3]}$" ${MYSPELL_OOOBASE}/dictionary.lst \
192     2>&1 > /dev/null && continue
193     # If no other entries match, remove relevant symlinks
194     for suffix in $(get_myspell_suffixes ${fields[0]}); do
195     filen="${fields[3]}${suffix}"
196 kevquinn 1.2 ewarn "Removing entry ${MYSPELL_OOOBASE}/${filen}"
197     [[ -h ${MYSPELL_OOOBASE}/${filen} ]] &&
198 kevquinn 1.1 rm -f ${MYSPELL_OOOBASE}/${filen}
199     done
200     done < ${MYSPELL_DICTBASE}/${dictlst}
201     }

  ViewVC Help
Powered by ViewVC 1.1.20