summaryrefslogtreecommitdiff
path: root/plugins/SpellChecker/src/dictionary.cpp
blob: b6bf37a6559e269befef4e6b0713ce5addae4183 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
/*
Copyright (C) 2006-2010 Ricardo Pescuma Domenecci

This is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.

This is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Library General Public License for more details.

You should have received a copy of the GNU Library General Public
License along with this file; see the file license.txt.  If
not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.  
*/


#include "commons.h"

#include "hunspell/config.h"
#include "hunspell/hunspell.hxx"
#include "hunspell/csutil.hxx"


#include "codepages.cpp"


DWORD WINAPI LoadThread(LPVOID hd);

// Additional languages that i could not find in Windows
TCHAR *aditionalLanguages[] = {
	LPGENT("tl_PH"), LPGENT("Tagalog (Philippines)"),
	LPGENT("de_frami_neu"), LPGENT("German (Germany)")
};



#define LANGUAGE_NOT_LOADED		 1
#define LANGUAGE_LOADING		-1
#define LANGUAGE_LOADED			 0



class HunspellDictionary : public Dictionary {
protected:
	TCHAR fileWithoutExtension[1024];
	TCHAR userPath[1024];
	volatile int loaded;
	Hunspell *hunspell;
	TCHAR *wordChars;
	UINT codePage;

	void loadCustomDict()
	{
		TCHAR filename[1024];
		mir_sntprintf(filename, SIZEOF(filename), L"%s\\%s.cdic", userPath, language);

		FILE *file = _tfopen(filename, L"rb");
		if (file != NULL) 
		{
			char tmp[1024];
			char c;
			int pos = 0;
			while((c = fgetc(file)) != EOF) 
			{
				if (c == '\n' || c == '\r' || pos >= SIZEOF(tmp) - 1) 
				{
					if (pos > 0)
					{
						tmp[pos] = '\0';
						hunspell->add(tmp);
					}

					pos = 0;
				}
				else
				{
					tmp[pos] = c;
					pos ++;
				}
			}
			fclose(file);
		}
	}

	void appendToCustomDict(const TCHAR *word)
	{
		CreateDirectoryTreeT(userPath);

		TCHAR filename[1024];
		mir_sntprintf(filename, SIZEOF(filename), L"%s\\%s.cdic", userPath, language);

		FILE *file = _tfopen(filename, L"ab");
		if (file != NULL) 
		{
			char tmp[1024];
			toHunspell(tmp, word, SIZEOF(tmp));
			fprintf(file, "%s\n", tmp);
			fclose(file);
		}
	}

	virtual void addWordInternal(const TCHAR * word)
	{
		if (loaded != LANGUAGE_LOADED)
			return;

		char hunspell_word[1024];
		toHunspell(hunspell_word, word, SIZEOF(hunspell_word));

		hunspell->add(hunspell_word);
	}

	void toHunspell(char *hunspellWord, const TCHAR *word, size_t hunspellWordLen)
	{

		WideCharToMultiByte(codePage, 0, word, -1, hunspellWord, hunspellWordLen, NULL, NULL);

	}

	TCHAR * fromHunspell(const char *hunspellWord)
	{

		int len = MultiByteToWideChar(codePage, 0, hunspellWord, -1, NULL, 0);
		WCHAR *ret = (WCHAR *) malloc((len + 1) * sizeof(WCHAR));
		MultiByteToWideChar(codePage, 0, hunspellWord, -1, ret, len + 1);
		return ret;

	}

	TCHAR * fromHunspellAndFree(char *hunspellWord)
	{
		if (hunspellWord == NULL)
			return NULL;
		
		TCHAR *ret = fromHunspell(hunspellWord);
		free(hunspellWord);
		return ret;
	}

public:
	HunspellDictionary(TCHAR *aLanguage, TCHAR *aFileWithoutExtension, TCHAR *anUserPath, TCHAR *aSource)
	{
		lstrcpyn(language, aLanguage, SIZEOF(language));
		lstrcpyn(fileWithoutExtension, aFileWithoutExtension, SIZEOF(fileWithoutExtension));
		lstrcpyn(userPath, anUserPath, SIZEOF(userPath));
		if (aSource == NULL)
			source[0] = _T('\0');
		else
			lstrcpyn(source, aSource, SIZEOF(source));

		loaded = LANGUAGE_NOT_LOADED;
		localized_name[0] = _T('\0');
		english_name[0] = _T('\0');
		full_name[0] = _T('\0');
		hunspell = NULL;
		wordChars = NULL;
		codePage = CP_ACP;
		autoReplace = NULL;
	}

	virtual ~HunspellDictionary()
	{
		if (hunspell != NULL)
			delete hunspell;
		if (wordChars != NULL)
			free(wordChars);
	}

	TCHAR * merge(TCHAR * s1, TCHAR *s2)
	{
		int len1 = (s1 == NULL ? 0 : lstrlen(s1));
		int len2 = (s2 == NULL ? 0 : lstrlen(s2));

		TCHAR *ret;
		if (len1 > 0 && len2 > 0) 
		{
			ret = (TCHAR *) malloc(sizeof(TCHAR) * (len1 + len2 + 1));
			lstrcpyn(ret, s1, len1+1);
			lstrcpyn(&ret[len1], s2, len2+1);

			FREE(s1);
			FREE(s2);
		}
		else if (len1 > 0)
		{
			ret = s1;
			FREE(s2);
		}
		else if (len2 > 0)
		{
			ret = s2;
			FREE(s1);
		}
		else
		{
			ret = (TCHAR *) malloc(sizeof(TCHAR));
			ret[0] = 0;

			FREE(s1);
			FREE(s2);
		}

		// Remove duplicated chars
		int last = lstrlen(ret) - 1;
		for(int i = 0; i <= last; i++)
		{
			TCHAR c = ret[i];
			for(int j = last; j > i; j--)
			{
				if (c != ret[j])
					continue;
				if (j != last)
					ret[j] = ret[last];
				ret[last] = _T('\0');
				last--;
			}
		}

		return ret;
	}


	void loadThread()
	{
		char dic[1024];
		char aff[1024];


		mir_snprintf(dic, SIZEOF(dic), "%S.dic", fileWithoutExtension);
		mir_snprintf(aff, SIZEOF(aff), "%S.aff", fileWithoutExtension);


		hunspell = new Hunspell(aff, dic);

		// Get codepage
		const char *dic_enc = hunspell->get_dic_encoding();

		TCHAR *hwordchars;
		if (strcmp(dic_enc, "UTF-8") == 0)
		{
			codePage = CP_UTF8;


			int wcs_len;
			hwordchars = fromHunspell((char *) hunspell->get_wordchars_utf16(&wcs_len));

		}
		else
		{
			for (int i = 0; i < SIZEOF(codepages); i++)
			{
				if (_strcmpi(codepages[i].name, dic_enc) == 0)
				{
					if (IsValidCodePage(codepages[i].codepage))
						codePage = codepages[i].codepage;
					break;
				}
			}
			
			hwordchars = fromHunspell(hunspell->get_wordchars());
		}

		TCHAR *casechars = fromHunspellAndFree(get_casechars(dic_enc));
		TCHAR *try_string = fromHunspellAndFree(hunspell->get_try_string());

		wordChars = merge(merge(casechars, hwordchars), try_string);

		// Make a suggestion to load hunspell internalls
		char ** words = NULL;
		int count = hunspell->suggest(&words, "asdf");
		for (int i = 0; i < count; i++)
			free(words[i]);
		if (words != NULL) 
			free(words);

		loadCustomDict();

		loaded = LANGUAGE_LOADED;
	}

	// Return TRUE if the word is correct
	virtual BOOL spell(const TCHAR *word)
	{
		load();
		if (loaded != LANGUAGE_LOADED)
			return TRUE;

		// TODO Check if it was generated by auto-replacement

		char hunspell_word[1024];
		toHunspell(hunspell_word, word, SIZEOF(hunspell_word));

		return hunspell->spell(hunspell_word);
	}

	// Return a list of suggestions to a word
	virtual Suggestions suggest(const TCHAR * word)
	{
		Suggestions ret = {0};

		load();
		if (loaded != LANGUAGE_LOADED)
			return ret;

		char hunspell_word[1024];
		toHunspell(hunspell_word, word, SIZEOF(hunspell_word));

		char ** words = NULL;
		ret.count = hunspell->suggest(&words, hunspell_word);

		if (ret.count > 0)
		{
			// Oki, lets make our array
			ret.words = (TCHAR **) malloc(ret.count * sizeof(TCHAR *));
			for (unsigned i = 0; i < ret.count; i++)
			{
				ret.words[i] = fromHunspell(words[i]);
				free(words[i]);
			}
		}

		if (words != NULL)
			free(words);

		return ret;
	}

	// Return a list of auto suggestions to a word
	virtual Suggestions autoSuggest(const TCHAR * word)
	{
		Suggestions ret = {0};

		load();
		if (loaded != LANGUAGE_LOADED)
			return ret;

		char hunspell_word[1024];
		toHunspell(hunspell_word, word, SIZEOF(hunspell_word));

		char ** words;
		int count = hunspell->suggest_auto(&words, hunspell_word);

		if (count <= 0)
			return ret;

		// Oki, lets make our array
		ret.count = count;
		ret.words = (TCHAR **) malloc(ret.count * sizeof(TCHAR *));
		for (int i = 0; i < count; i++)
		{
			ret.words[i] = fromHunspell(words[i]);
			free(words[i]);
		}
		free(words);

		return ret;
	}

	// Return a list of auto suggestions to a word
	// You have to free the list AND each item
	virtual TCHAR * autoSuggestOne(const TCHAR * word)
	{
		load();
		if (loaded != LANGUAGE_LOADED)
			return NULL;

		char hunspell_word[1024];
		toHunspell(hunspell_word, word, SIZEOF(hunspell_word));

		char ** words;
		int count = hunspell->suggest_auto(&words, hunspell_word);

		if (count <= 0)
			return NULL;

		TCHAR *ret = fromHunspell(words[0]);

		// Oki, lets make our array
		for (int i = 0; i < count; i++)
			free(words[i]);
		free(words);

		return ret;
	}

	// Return TRUE if the char is a word char
	virtual BOOL isWordChar(TCHAR c)
	{
		if (c == 0)
			return FALSE;

		load();
		if (loaded != LANGUAGE_LOADED)
			return TRUE;

		return _tcschr(wordChars, (_TINT) c) != NULL;
	}

	// Assert that all needed data is loaded
	virtual void load()	
	{
		if (loaded == LANGUAGE_NOT_LOADED)
		{
			loaded = LANGUAGE_LOADING;

			DWORD thread_id;
			CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) LoadThread, 
				(LPVOID) this, 0, &thread_id);
		}
	}

	virtual BOOL isLoaded()
	{
		return loaded == LANGUAGE_LOADED;
	}


	// Add a word to the user custom dict
	virtual void addWord(const TCHAR * word)
	{
		addWordInternal(word);
		appendToCustomDict(word);
	}
	
	// Add a word to the list of ignored words
	virtual void ignoreWord(const TCHAR * word)
	{
		addWordInternal(word);
	}
};


DWORD WINAPI LoadThread(LPVOID hd)
{
	HunspellDictionary *dict = (HunspellDictionary *) hd;
	dict->loadThread();
	return 0;
}



// To use with EnumLocalesProc :(
LIST<Dictionary> *tmp_dicts;

// To get the names of the languages
BOOL CALLBACK EnumLocalesProc(LPTSTR lpLocaleString)
{
	TCHAR *stopped = NULL;
	USHORT langID = (USHORT) _tcstol(lpLocaleString, &stopped, 16);

	TCHAR ini[32];
	TCHAR end[32];
	GetLocaleInfo(MAKELCID(langID, 0), LOCALE_SISO639LANGNAME, ini, SIZEOF(ini));
	GetLocaleInfo(MAKELCID(langID, 0), LOCALE_SISO3166CTRYNAME, end, SIZEOF(end));

	TCHAR name[64];
	mir_sntprintf(name, SIZEOF(name), L"%s_%s", ini, end);

	for(int i = 0; i < tmp_dicts->getCount(); i++)
	{
		Dictionary *dict = (*tmp_dicts)[i];
		if (lstrcmpi(dict->language, name) == 0)
		{
#define LOCALE_SLOCALIZEDLANGUAGENAME 0x0000006f
#define LOCALE_SNATIVEDISPLAYNAME 0x00000073
			
			GetLocaleInfo(MAKELCID(langID, 0), LOCALE_SENGLANGUAGE, dict->english_name, SIZEOF(dict->english_name));

			GetLocaleInfo(MAKELCID(langID, 0), LOCALE_SLANGUAGE, dict->localized_name, SIZEOF(dict->localized_name));
			if (dict->localized_name[0] == 0)
				GetLocaleInfo(MAKELCID(langID, 0), LOCALE_SLOCALIZEDLANGUAGENAME, dict->localized_name, SIZEOF(dict->localized_name));
			if (dict->localized_name[0] == 0)
				GetLocaleInfo(MAKELCID(langID, 0), LOCALE_SNATIVEDISPLAYNAME, dict->localized_name, SIZEOF(dict->localized_name));
			if (dict->localized_name[0] == 0 && dict->english_name[0] != 0)
			{
				TCHAR country[1024];
				GetLocaleInfo(MAKELCID(langID, 0), LOCALE_SENGCOUNTRY, country, SIZEOF(country));

				TCHAR name[1024];
				if (country[0] != 0)
					mir_sntprintf(name, SIZEOF(name), L"%s (%s)", dict->english_name, country);
				else
					lstrcpyn(name, dict->english_name, SIZEOF(name));

				lstrcpyn(dict->localized_name, TranslateTS(name), SIZEOF(dict->localized_name));
			}

			if (dict->localized_name[0] != 0)
			{
				mir_sntprintf(dict->full_name, SIZEOF(dict->full_name), L"%s [%s]", dict->localized_name, dict->language);
			}
			break;
		}
	}
	return TRUE;
}


void GetDictsInfo(LIST<Dictionary> &dicts)
{
	tmp_dicts = &dicts;
	EnumSystemLocales(EnumLocalesProc, LCID_SUPPORTED);

	// Try to get name from DB
	for(int i = 0; i < dicts.getCount(); i++)
	{
		Dictionary *dict = dicts[i];
		
		if (dict->full_name[0] == _T('\0'))
		{
			DBVARIANT dbv;

			char lang[128];
			WideCharToMultiByte(CP_ACP, 0, dict->language, -1, lang, sizeof(lang), NULL, NULL);
			if (!db_get_ts(NULL, MODULE_NAME, lang, &dbv))

			{
				lstrcpyn(dict->localized_name, dbv.ptszVal, SIZEOF(dict->localized_name));
				DBFreeVariant(&dbv);
			}

			if (dict->localized_name[0] == _T('\0'))
			{
				for(size_t j = 0; j < SIZEOF(aditionalLanguages); j+=2)
				{
					if (lstrcmp(aditionalLanguages[j], dict->language) == 0)
					{
						lstrcpyn(dict->localized_name, aditionalLanguages[j+1], SIZEOF(dict->localized_name));
						break;
					}
				}
			}

			if (dict->localized_name[0] != _T('\0'))
			{
				mir_sntprintf(dict->full_name, SIZEOF(dict->full_name), L"%s [%s]", dict->localized_name, dict->language);
			}
			else
			{
				lstrcpyn(dict->full_name, dict->language, SIZEOF(dict->full_name));
			}
		}
	}
}


void GetHunspellDictionariesFromFolder(LIST<Dictionary> &dicts, TCHAR *path, TCHAR *user_path, TCHAR *source)
{
	// Load the language files and create an array with then
	TCHAR file[1024];
	mir_sntprintf(file, SIZEOF(file), L"%s\\*.dic", path);

	BOOL found = FALSE;

	WIN32_FIND_DATA ffd = {0};
	HANDLE hFFD = FindFirstFile(file, &ffd);
	if (hFFD != INVALID_HANDLE_VALUE)
	{
		do
		{
			mir_sntprintf(file, SIZEOF(file), L"%s\\%s", path, ffd.cFileName);

			// Check .dic
			DWORD attrib = GetFileAttributes(file);
			if (attrib == 0xFFFFFFFF || (attrib & FILE_ATTRIBUTE_DIRECTORY))
				continue;

			// See if .aff exists too
			lstrcpy(&file[lstrlen(file) - 4], L".aff");
			attrib = GetFileAttributes(file);
			if (attrib == 0xFFFFFFFF || (attrib & FILE_ATTRIBUTE_DIRECTORY))
				continue;

			ffd.cFileName[lstrlen(ffd.cFileName)-4] = _T('\0');

			TCHAR *lang = ffd.cFileName;

			// Replace - for _
			int i;
			for(i = 0; i < lstrlen(lang); i++)
				if (lang[i] == _T('-'))
					lang[i] = _T('_');

			// Check if dict is new
			BOOL exists = FALSE;
			for(i = 0; i < dicts.getCount() && !exists; i++)
				if (lstrcmp(dicts[i]->language, lang) == 0)
					exists = TRUE;

			if (!exists)
			{
				found = TRUE;
				file[lstrlen(file) - 4] = _T('\0');
				dicts.insert(new HunspellDictionary(lang, file, user_path, source));
			}
		}
		while(FindNextFile(hFFD, &ffd));

		FindClose(hFFD);
	}
}


// Return a list of avaible languages
void GetAvaibleDictionaries(LIST<Dictionary> &dicts, TCHAR *path, TCHAR *user_path)
{
	// Get miranda folder dicts
	GetHunspellDictionariesFromFolder(dicts, path, user_path, NULL);

	if (opts.use_other_apps_dicts)
	{
		TCHAR *otherHunspellApps[] = { L"Thunderbird", L"thunderbird.exe", 
									   L"Firefox", L"firefox.exe" };

#define APPPATH  L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\%s"
#define MUICACHE L"Software\\Microsoft\\Windows\\ShellNoRoam\\MUICache"

		// Get other apps dicts
		for (int i = 0; i < SIZEOF(otherHunspellApps); i += 2)
		{
			TCHAR key[1024];
			mir_sntprintf(key, SIZEOF(key), APPPATH, otherHunspellApps[i+1]);

			HKEY hKey = 0;
			LONG lResult = 0;
			if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, key, 0, KEY_QUERY_VALUE, &hKey))
			{
				DWORD size = SIZEOF(key);
				lResult = RegQueryValueEx(hKey, L"Path", NULL, NULL, (LPBYTE)key, &size);
				RegCloseKey(hKey);
			}
			else 
			{ 
				// Not found in installed apps - Try MUICache
				lResult = RegOpenKeyEx(HKEY_CURRENT_USER, MUICACHE, 0, KEY_QUERY_VALUE, &hKey);
				if (ERROR_SUCCESS == lResult)
				{
					DWORD numValues;
					if (ERROR_SUCCESS != RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL, &numValues, NULL, NULL, NULL, NULL)) 
						numValues = 0;

					lResult = ERROR_NO_MORE_ITEMS;
					for (DWORD local = 0; local < numValues; local++) 
					{
						DWORD cchValue = SIZEOF(key);
						if (ERROR_SUCCESS != RegEnumValue(hKey, local, key, &cchValue, NULL, NULL, NULL, NULL)) 
							break;
						key[cchValue] = 0;
						TCHAR *pos;
						if (pos = _tcsrchr(key, _T('\\')))
						{
							if (lstrcmpi(&pos[1], otherHunspellApps[i+1]) == 0)
							{
								pos[0] = 0;
								lResult = ERROR_SUCCESS;
								break;
							}
						}
					}
					RegCloseKey(hKey);
				} 
			}

			if (ERROR_SUCCESS == lResult)
			{
				TCHAR folder[1024];
				mir_sntprintf(folder, SIZEOF(folder), L"%s\\Dictionaries", key);

				GetHunspellDictionariesFromFolder(languages, folder, user_path, otherHunspellApps[i]);
			}       
		}
	}

	GetDictsInfo(dicts);

	// Yeah, yeah, yeah, I know, but this is the easiest way...
	SortedList *sl = (SortedList *) &dicts;

	// Sort dicts
	for(int i = 0; i < dicts.getCount(); i++)
	{
		for(int j = i + 1; j < dicts.getCount(); j++)
		{
			if (lstrcmp(dicts[i]->full_name, dicts[j]->full_name) > 0)
			{
				Dictionary *dict = dicts[i];
				sl->items[i] = dicts[j];
				sl->items[j] = dict;
			}
		}
	}
}


// Free the list returned by GetAvaibleDictionaries
void FreeDictionaries(LIST<Dictionary> &dicts)
{
	for (int i = 0; i < dicts.getCount(); i++)
	{
		delete dicts[i];
	}
	dicts.destroy();
}


// Free the list returned by GetAvaibleDictionaries
void FreeSuggestions(Suggestions &suggestions)
{
	for (size_t i = 0; i < suggestions.count; i++)
	{
		free(suggestions.words[i]);
	}
	free(suggestions.words);

	suggestions.words = NULL;
	suggestions.count = 0;
}