• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdespell2
 

tdespell2

  • tdespell2
  • plugins
  • ispell
hash.cpp
1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /* enchant
3  * Copyright (C) 2003 Dom Lachowicz
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  *
20  * In addition, as a special exception, Dom Lachowicz
21  * gives permission to link the code of this program with
22  * non-LGPL Spelling Provider libraries (eg: a MSFT Office
23  * spell checker backend) and distribute linked combinations including
24  * the two. You must obey the GNU Lesser General Public License in all
25  * respects for all of the code used other than said providers. If you modify
26  * this file, you may extend this exception to your version of the
27  * file, but you are not obligated to do so. If you do not wish to
28  * do so, delete this exception statement from your version.
29  */
30 
31 /*
32  * hash.c - a simple hash function for ispell
33  *
34  * Pace Willisson, 1983
35  *
36  * Copyright 1992, 1993, Geoff Kuenning, Granada Hills, CA
37  * All rights reserved.
38  *
39  * Redistribution and use in source and binary forms, with or without
40  * modification, are permitted provided that the following conditions
41  * are met:
42  *
43  * 1. Redistributions of source code must retain the above copyright
44  * notice, this list of conditions and the following disclaimer.
45  * 2. Redistributions in binary form must reproduce the above copyright
46  * notice, this list of conditions and the following disclaimer in the
47  * documentation and/or other materials provided with the distribution.
48  * 3. All modifications to the source code must be clearly marked as
49  * such. Binary redistributions based on modified source code
50  * must be clearly marked as modified versions in the documentation
51  * and/or other materials provided with the distribution.
52  * 4. All advertising materials mentioning features or use of this software
53  * must display the following acknowledgment:
54  * This product includes software developed by Geoff Kuenning and
55  * other unpaid contributors.
56  * 5. The name of Geoff Kuenning may not be used to endorse or promote
57  * products derived from this software without specific prior
58  * written permission.
59  *
60  * THIS SOFTWARE IS PROVIDED BY GEOFF KUENNING AND CONTRIBUTORS ``AS IS'' AND
61  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
62  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
63  * ARE DISCLAIMED. IN NO EVENT SHALL GEOFF KUENNING OR CONTRIBUTORS BE LIABLE
64  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
65  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
66  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
67  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
68  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
69  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
70  * SUCH DAMAGE.
71  */
72 
73 /*
74  * $Log$
75  * Revision 1.1 2004/01/31 16:44:12 zrusin
76  * ISpell plugin.
77  *
78  * Revision 1.4 2003/08/14 17:51:27 dom
79  * update license - exception clause should be Lesser GPL
80  *
81  * Revision 1.3 2003/07/28 20:40:26 dom
82  * fix up the license clause, further win32-registry proof some directory getting functions
83  *
84  * Revision 1.2 2003/07/16 22:52:39 dom
85  * LGPL + exception license
86  *
87  * Revision 1.1 2003/07/15 01:15:05 dom
88  * ispell enchant backend
89  *
90  * Revision 1.2 2003/01/29 05:50:11 hippietrail
91  *
92  * Fixed my mess in EncodingManager.
93  * Changed many C casts to C++ casts.
94  *
95  * Revision 1.1 2003/01/24 05:52:33 hippietrail
96  *
97  * Refactored ispell code. Old ispell global variables had been put into
98  * an allocated structure, a pointer to which was passed to many functions.
99  * I have now made all such functions and variables private members of the
100  * ISpellChecker class. It was C OO, now it's C++ OO.
101  *
102  * I've fixed the makefiles and tested compilation but am unable to test
103  * operation. Please back out my changes if they cause problems which
104  * are not obvious or easy to fix.
105  *
106  * Revision 1.5 2002/09/19 05:31:15 hippietrail
107  *
108  * More Ispell cleanup. Conditional globals and DEREF macros are removed.
109  * K&R function declarations removed, converted to Doxygen style comments
110  * where possible. No code has been changed (I hope). Compiles for me but
111  * unable to test.
112  *
113  * Revision 1.4 2002/09/17 03:03:29 hippietrail
114  *
115  * After seeking permission on the developer list I've reformatted all the
116  * spelling source which seemed to have parts which used 2, 3, 4, and 8
117  * spaces for tabs. It should all look good with our standard 4-space
118  * tabs now.
119  * I've concentrated just on indentation in the actual code. More prettying
120  * could be done.
121  * * NO code changes were made *
122  *
123  * Revision 1.3 2002/09/13 17:20:13 mpritchett
124  * Fix more warnings for Linux build
125  *
126  * Revision 1.2 2001/05/12 16:05:42 thomasf
127  * Big pseudo changes to ispell to make it pass around a structure rather
128  * than rely on all sorts of gloabals willy nilly here and there. Also
129  * fixed our spelling class to work with accepting suggestions once more.
130  * This code is dirty, gross and ugly (not to mention still not supporting
131  * multiple hash sized just yet) but it works on my machine and will no
132  * doubt break other machines.
133  *
134  * Revision 1.1 2001/04/15 16:01:24 tomas_f
135  * moving to spell/xp
136  *
137  * Revision 1.3 1998/12/29 14:55:33 eric
138  *
139  * I've doctored the ispell code pretty extensively here. It is now
140  * warning-free on Win32. It also *works* on Win32 now, since I
141  * replaced all the I/O calls with ANSI standard ones.
142  *
143  * Revision 1.2 1998/12/28 23:11:30 eric
144  *
145  * modified spell code and integration to build on Windows.
146  * This is still a hack.
147  *
148  * Actually, it doesn't yet WORK on Windows. It just builds.
149  * SpellCheckInit is failing for some reason.
150  *
151  * Revision 1.1 1998/12/28 18:04:43 davet
152  * Spell checker code stripped from ispell. At this point, there are
153  * two external routines... the Init routine, and a check-a-word routine
154  * which returns a boolean value, and takes a 16 bit char string.
155  * The code resembles the ispell code as much as possible still.
156  *
157  * Revision 1.20 1994/01/25 07:11:34 geoff
158  * Get rid of all old RCS log lines in preparation for the 3.1 release.
159  *
160  */
161 
162 #include "ispell_checker.h"
163 
164 /*
165  * The following hash algorithm is due to Ian Dall, with slight modifications
166  * by Geoff Kuenning to reflect the results of testing with the English
167  * dictionaries actually distributed with ispell.
168  */
169 #define HASHSHIFT 5
170 
171 #ifdef NO_CAPITALIZATION_SUPPORT
172 #define HASHUPPER(c) c
173 #else /* NO_CAPITALIZATION_SUPPORT */
174 #define HASHUPPER(c) mytoupper(c)
175 #endif /* NO_CAPITALIZATION_SUPPORT */
176 
177 /*
178  * \param s
179  * \param hashtblsize
180  */
181 int ISpellChecker::hash (ichar_t *s, int hashtblsize)
182 {
183  long h = 0;
184  int i;
185 
186 #ifdef ICHAR_IS_CHAR
187  for (i = 4; i-- && *s != 0; )
188  h = (h << 8) | HASHUPPER (*s++);
189 #else /* ICHAR_IS_CHAR */
190  for (i = 2; i-- && *s != 0; )
191  h = (h << 16) | HASHUPPER (*s++);
192 #endif /* ICHAR_IS_CHAR */
193  while (*s != 0)
194  {
195  /*
196  * We have to do circular shifts the hard way, since C doesn't
197  * have them even though the hardware probably does. Oh, well.
198  */
199  h = (h << HASHSHIFT)
200  | ((h >> (32 - HASHSHIFT)) & ((1 << HASHSHIFT) - 1));
201  h ^= HASHUPPER (*s++);
202  }
203  return static_cast<unsigned long>(h) % hashtblsize;
204 }

tdespell2

Skip menu "tdespell2"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

tdespell2

Skip menu "tdespell2"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdespell2 by doxygen 1.8.13
This website is maintained by Timothy Pearson.