Various changes to preferences object, file loading, and error logging.
[jben.git] / kdict.h
blobfc0e89eb57edbdee66e4ccab4ad4adbe47aa0fcd
1 /*
2 Project: J-Ben
3 Author: Paul Goins
4 Website: http://www.vultaire.net/software/jben/
5 License: GNU General Public License (GPL) version 2
6 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt)
8 File: kdict.h
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>
24 #ifndef kdict_h
25 #define kdict_h
27 #define KD_SUCCESS 0x0
28 #define KD_FAILURE 0x80000000
30 /* Onyomi/kunyomi/nanori/radical readings */
31 #define KDO_READINGS 0x1
32 /* English meanings */
33 #define KDO_MEANINGS 0x2
34 /* Grade, frequency, stroke count(s) */
35 #define KDO_HIGHIMPORTANCE 0x4
36 /* Enable dictionary display */
37 #define KDO_DICTIONARIES 0x8
38 /* Less important miscellanea, plus radical #'s */
39 #define KDO_LOWIMPORTANCE 0x10
40 /* Enable cross-referencing with vocab study list */
41 #define KDO_VOCABCROSSREF 0x20
42 /* KanjiCafe.com Stroke Order Diagrams (if present) */
43 #define KDO_SOD_STATIC 0x40
44 #define KDO_SOD_ANIM 0x80
45 /* All options (except UNHANDLED) */
46 #define KDO_ALL 0xFF
47 /* All unhandled dictionary stuff */
48 #define KDO_UNHANDLED 0x8000
50 /* Hn...: "New Japanese-English Character Dictionary" by Jack Halpern. "Halpern" field 1 in JWPce. */
51 #define KDD_NJECD 0x1
52 /* Nn...: "Modern Reader's Japanese-English Character Dictionary" by Andrew Nelson. "Nelson" field 1 in JWPce. */
53 #define KDD_MRJECD 0x2
54 /* Vn...: "The New Nelson Japanese-English Character Dictionary" by John Haig. "Nelson" field 2 in JWPce. */
55 #define KDD_NNJECD 0x4
56 /* More "D" codes... add as needed */
57 /* DBnnn: Japanese for Busy People, AJLT */
58 #define KDD_JBP 0x8
59 /* DCnnnn: The Kanji Way to Japanese Language Power, Dale Crowley */
60 #define KDD_KWJLP 0x10
61 /* DGnnn: Kodansha Compact Kanji Guide */
62 #define KDD_KCKG 0x20
63 /* DHnnnn: A Guide To Reading and Writing Japanese, Ken Hensall et al. */
64 #define KDD_GTRWJH 0x40
65 /* DJnnnn: Kanji in Context, Nishiguchi and Kono */
66 #define KDD_KIC 0x80
67 /* DKnnnn: Kanji Learners Dictionary, Jack Halpern */
68 #define KDD_KLD 0x100
69 /* DOnnnn: Essential Kanji, P.G. O'Neill */
70 #define KDD_EK 0x200
71 /* DRnnnn: 2001 Kanji, Father Joseph De Roo */
72 #define KDD_DR 0x400
73 /* DSnnnn: A Guide To Reading and Writing Japanese, Florence Sakade */
74 #define KDD_GTRWJS 0x800
75 /* DTnnn: Tuttle Kanji Cards, Alexander Kask */
76 #define KDD_TKC 0x1000
77 /* DFnnnn: Japanese Kanji Flashcards, White Rabbit Press */
78 #define KDD_JKF 0x2000
79 /* "Pn...-n...-n..." - SKIP codes used by Halpern dictionaries */
80 #define KDD_SKIP 0x4000
81 /* Inxnn.n: Kanji Dictionary, Spahn & Hadamitzky */
82 #define KDD_KD 0x8000
83 /* INnnnn: Kanji & Kana, Spahn & Hadamitzky */
84 #define KDD_KK 0x10000
85 /* Qnnnn.n: Four Corner code, used by various dictionaries in China and Japan */
86 #define KDD_FC 0x20000
87 /* MNnnnnnnn: Morohashi Daikanwajiten, index number */
88 #define KDD_MOROI 0x40000
89 /* MPnn.nnnn: Morohashi Daikanwajiten, volume.page number */
90 #define KDD_MOROVP 0x80000
91 /* Morohashi Daikanwajiten (Both indexing options) */
92 #define KDD_MORO KDD_MOROI | KDD_MOROVP;
93 /* Ennnn: A Guide to Remembering Japanese Characters, Kenneth G. Henshal */
94 #define KDD_GRJC 0x100000
95 /* Knnnn: Gakken Kanji Dictionary ("A New Dictionary of Kanji Usage") */
96 #define KDD_GKD 0x200000
97 /* Lnnnn: Remembering The Kanji, James Heisig */
98 #define KDD_RTK 0x400000
99 /* Onnnn[A]: Japanese Names, P.G. O'Neill */
100 #define KDD_JN 0x800000
101 /* Show EVERYTHING!
102 This is a lot of output, so it's probably for debug purposes only. */
103 #define KDD_ALL 0xFFFFFFFF
105 #include "boosthm.h"
106 #include <string>
107 #include <iostream>
108 #include <list>
109 #include <map>
110 using namespace std;
112 class KInfo {
113 public:
114 KInfo();
116 string literal;
117 map<string,string> codepoint;
118 unsigned char radical, radicalNelson;
119 int grade;
120 int strokeCount;
121 list<int> misstrokes;
122 map<string,string> variant;
123 int freq;
124 string radicalName;
125 map<string,string> dictCode;
126 map<string,string> queryCode;
127 list< pair<string,string> > skipMisclass;
128 list<string> pinyin, korean_r, korean_h,
129 onyomi, kunyomi, nanori;
130 /* FOR NOW: I am ignoring onyomi and kunyomi r_status and on_type flags.
131 In the KANJIDIC2 dated 2008-02-12, there was only one entry, "行く",
132 which had any of these flags. Not worth the effort. */
133 map<string, list<string> > meaning;
136 class KDict {
137 public:
138 static const KDict *Get();
139 static void Destroy();
140 ~KDict();
142 /* General purpose access functions */
143 static wstring KInfoToHtml(const KInfo& kInfo);
144 static wstring KInfoToHtml(const KInfo& kInfo,
145 long options, long dictionaries);
146 const KInfo* GetEntry(const wchar_t key) const;
147 const BoostHM<wchar_t, KInfo>* GetHashTable() const;
149 /* Other functions */
150 bool MainDataLoaded() const;
151 private:
152 /* Hidden constructor */
153 KDict();
155 /* Dictionary file loaders */
156 int LoadKanjidic(const char* filename, const char* jisStd="jis208");
157 int LoadKanjidic2(const char* filename);
158 int LoadRadkfile(const char* filename);
159 int LoadKradfile(const char* filename);
161 /* Kanjidic-specific stuff */
162 void KanjidicToKInfo(const string& kanjidicEntry, KInfo& k,
163 const char* jisStd);
164 void KanjidicParser(char* kanjidicRawData, const char* jisStd);
165 static wstring ConvertKanjidicEntry(const wstring& s);
167 /* Data */
168 static KDict *kdictSingleton;
169 BoostHM<wchar_t, KInfo> kdictData;
170 BoostHM<wchar_t, wstring> radkData, kradData;
171 BoostHM<wchar_t, int> radkDataStrokes;
174 #endif