2 This file is part of Kiten, a KDE Japanese Reference Tool...
3 Copyright (C) 2001 Jason Katz-Brown <jason@katzbrown.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program 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
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 #include <qmemarray.h>
29 #include <qstringlist.h>
31 #include <sys/types.h>
33 typedef unsigned int uint32_t;
42 enum TextType
{ Text_Kanji
, Text_Kana
, Text_Latin
};
44 // returns the TextType of the first part of the text
45 KDE_EXPORT TextType
textType(const QString
&text
);
47 // File needs to be able to give out Arrays based on its mmap'd data.
48 // But, we don't want the users of the arrays to have to remember to
49 // resetRawData() after using them, since that's bound to fail sooner or later.
51 // This class handles it for us.
52 template<class T
> class Array
: public QMemArray
<T
>
63 template<class T
> Array
<T
>::Array(T
*d
, int s
)
68 setRawData(data
, dataSize
/ sizeof(T
));
71 template<class T
> Array
<T
>::~Array()
73 resetRawData(data
, dataSize
/ sizeof(T
));
76 // File manages all the files, pointers, and memory management associated
77 // with a single dictionary.
81 File(QString path
, QString name
);
86 Array
<const unsigned char> dict(void);
87 Array
<const uint32_t> index(void);
90 int indexLength(void);
92 // replacement for exceptions thrown in the constructor
95 unsigned char lookup(unsigned i
, int offset
);
96 QCString
lookup(unsigned i
);
101 const unsigned char * dictPtr
;
104 const uint32_t * indexPtr
;
109 class KDE_EXPORT Entry
113 Entry(const QString
&, const QString
&, const QStringList
&);
115 Entry(const QString
&, QStringList
&, QStringList
&, unsigned int grade
, unsigned int freq
, unsigned int strokes
, unsigned int miscount
);
116 // default (for containers)
117 Entry(const QString
& = QString::null
);
119 Entry(const QString
&, bool header
);
123 QStringList
meanings();
124 QStringList
readings();
125 QString
firstReading();
130 bool extendedKanjiInfo();
131 unsigned int grade();
132 unsigned int strokes();
133 unsigned int miscount();
139 QStringList Meanings
;
143 QStringList Readings
;
145 bool ExtendedKanjiInfo
;
147 unsigned int Strokes
;
148 unsigned int Miscount
;
154 QValueList
<Entry
> list
;
161 enum SearchType
{ Search_Beginning
, Search_FullWord
, Search_Anywhere
};
162 enum DictionaryType
{ Edict
, Kanjidict
};
164 class KDE_EXPORT Index
: public QObject
172 void setDictList(const QStringList
&files
, const QStringList
&names
);
173 void setKanjiDictList(const QStringList
&files
, const QStringList
&names
);
175 SearchResult
search(QRegExp
, const QString
&, bool common
);
176 SearchResult
searchKanji(QRegExp
, const QString
&, bool common
);
177 SearchResult
searchPrevious(QRegExp
, const QString
&, SearchResult
, bool common
);
179 // convenience function to create suitable regexps
180 static QRegExp
createRegExp(SearchType type
, const QString
&text
, DictionaryType dictionaryType
, bool caseSensitive
= false);
183 QPtrList
<File
> dictFiles
;
184 QPtrList
<File
> kanjiDictFiles
;
186 void loadDictList(QPtrList
<File
> &fileList
, const QStringList
&dictList
, const QStringList
&dictNameList
);
188 QStringList
doSearch(File
&, const QString
&);
189 SearchResult
scanResults(QRegExp regexp
, QStringList results
, bool common
);
190 SearchResult
scanKanjiResults(QRegExp regexp
, QStringList results
, bool common
);
191 int stringCompare(File
&, int index
, QCString
);
194 // lotsa helper functions
195 KDE_EXPORT QString
prettyKanjiReading(QStringList
);
196 KDE_EXPORT QString
prettyMeaning(QStringList
);
197 KDE_EXPORT Entry
parse(const QString
&);
198 KDE_EXPORT Entry
kanjiParse(const QString
&);
199 KDE_EXPORT
Dict::Entry
firstEntry(Dict::SearchResult
);
200 KDE_EXPORT QString
firstEntryText(Dict::SearchResult
);
202 int eucStringCompare(const char *str1
, const char *str2
);
203 bool isEUC(unsigned char c
);