OLD | NEW |
1 #include "license.hunspell" | 1 #include "license.hunspell" |
2 #include "license.myspell" | 2 #include "license.myspell" |
3 | 3 |
4 #include <stdlib.h> | 4 #include <stdlib.h> |
5 #include <string.h> | 5 #include <string.h> |
6 #include <stdio.h> | 6 #include <stdio.h> |
7 | 7 |
8 #include "hunspell.hxx" | 8 #include "hunspell.hxx" |
9 #include "hunspell.h" | 9 #include "hunspell.h" |
| 10 #ifndef HUNSPELL_CHROME_CLIENT |
10 #include "config.h" | 11 #include "config.h" |
| 12 #endif |
11 #include "csutil.hxx" | 13 #include "csutil.hxx" |
12 | 14 |
| 15 #ifdef HUNSPELL_CHROME_CLIENT |
| 16 Hunspell::Hunspell(const unsigned char* bdict_data, size_t bdict_length) |
| 17 #else |
13 Hunspell::Hunspell(const char * affpath, const char * dpath, const char * key) | 18 Hunspell::Hunspell(const char * affpath, const char * dpath, const char * key) |
| 19 #endif |
14 { | 20 { |
15 encoding = NULL; | 21 encoding = NULL; |
16 csconv = NULL; | 22 csconv = NULL; |
17 utf8 = 0; | 23 utf8 = 0; |
18 complexprefixes = 0; | 24 complexprefixes = 0; |
| 25 #ifndef HUNSPELL_CHROME_CLIENT |
19 affixpath = mystrdup(affpath); | 26 affixpath = mystrdup(affpath); |
| 27 #endif |
20 maxdic = 0; | 28 maxdic = 0; |
21 | 29 |
| 30 #ifdef HUNSPELL_CHROME_CLIENT |
| 31 bdict_reader = new hunspell::BDictReader; |
| 32 bdict_reader->Init(bdict_data, bdict_length); |
| 33 |
| 34 pHMgr[0] = new HashMgr(bdict_reader); |
| 35 if (pHMgr[0]) maxdic = 1; |
| 36 |
| 37 pAMgr = new AffixMgr(bdict_reader, pHMgr, &maxdic); |
| 38 #else |
22 /* first set up the hash manager */ | 39 /* first set up the hash manager */ |
23 pHMgr[0] = new HashMgr(dpath, affpath, key); | 40 pHMgr[0] = new HashMgr(dpath, affpath, key); |
24 if (pHMgr[0]) maxdic = 1; | 41 if (pHMgr[0]) maxdic = 1; |
25 | 42 |
26 /* next set up the affix manager */ | 43 /* next set up the affix manager */ |
27 /* it needs access to the hash manager lookup methods */ | 44 /* it needs access to the hash manager lookup methods */ |
28 pAMgr = new AffixMgr(affpath, pHMgr, &maxdic, key); | 45 pAMgr = new AffixMgr(affpath, pHMgr, &maxdic, key); |
| 46 #endif |
29 | 47 |
30 /* get the preferred try string and the dictionary */ | 48 /* get the preferred try string and the dictionary */ |
31 /* encoding from the Affix Manager for that dictionary */ | 49 /* encoding from the Affix Manager for that dictionary */ |
32 char * try_string = pAMgr->get_try_string(); | 50 char * try_string = pAMgr->get_try_string(); |
33 encoding = pAMgr->get_encoding(); | 51 encoding = pAMgr->get_encoding(); |
34 csconv = get_current_cs(encoding); | 52 csconv = get_current_cs(encoding); |
35 langnum = pAMgr->get_langnum(); | 53 langnum = pAMgr->get_langnum(); |
36 utf8 = pAMgr->get_utf8(); | 54 utf8 = pAMgr->get_utf8(); |
37 complexprefixes = pAMgr->get_complexprefixes(); | 55 complexprefixes = pAMgr->get_complexprefixes(); |
38 wordbreak = pAMgr->get_breaktable(); | 56 wordbreak = pAMgr->get_breaktable(); |
(...skipping 10 matching lines...) Expand all Loading... |
49 for (int i = 0; i < maxdic; i++) delete pHMgr[i]; | 67 for (int i = 0; i < maxdic; i++) delete pHMgr[i]; |
50 maxdic = 0; | 68 maxdic = 0; |
51 pSMgr = NULL; | 69 pSMgr = NULL; |
52 pAMgr = NULL; | 70 pAMgr = NULL; |
53 #ifdef MOZILLA_CLIENT | 71 #ifdef MOZILLA_CLIENT |
54 delete [] csconv; | 72 delete [] csconv; |
55 #endif | 73 #endif |
56 csconv= NULL; | 74 csconv= NULL; |
57 if (encoding) free(encoding); | 75 if (encoding) free(encoding); |
58 encoding = NULL; | 76 encoding = NULL; |
| 77 |
| 78 #ifdef HUNSPELL_CHROME_CLIENT |
| 79 if (bdict_reader) delete bdict_reader; |
| 80 bdict_reader = NULL; |
| 81 #else |
59 if (affixpath) free(affixpath); | 82 if (affixpath) free(affixpath); |
60 affixpath = NULL; | 83 affixpath = NULL; |
| 84 #endif |
61 } | 85 } |
62 | 86 |
| 87 #ifndef HUNSPELL_CHROME_CLIENT |
63 // load extra dictionaries | 88 // load extra dictionaries |
64 int Hunspell::add_dic(const char * dpath, const char * key) { | 89 int Hunspell::add_dic(const char * dpath, const char * key) { |
65 if (maxdic == MAXDIC || !affixpath) return 1; | 90 if (maxdic == MAXDIC || !affixpath) return 1; |
66 pHMgr[maxdic] = new HashMgr(dpath, affixpath, key); | 91 pHMgr[maxdic] = new HashMgr(dpath, affixpath, key); |
67 if (pHMgr[maxdic]) maxdic++; else return 1; | 92 if (pHMgr[maxdic]) maxdic++; else return 1; |
68 return 0; | 93 return 0; |
69 } | 94 } |
| 95 #endif |
70 | 96 |
71 // make a copy of src at destination while removing all leading | 97 // make a copy of src at destination while removing all leading |
72 // blanks and removing any trailing periods after recording | 98 // blanks and removing any trailing periods after recording |
73 // their presence with the abbreviation flag | 99 // their presence with the abbreviation flag |
74 // also since already going through character by character, | 100 // also since already going through character by character, |
75 // set the capitalization type | 101 // set the capitalization type |
76 // return the length of the "cleaned" (and UTF-8 encoded) word | 102 // return the length of the "cleaned" (and UTF-8 encoded) word |
77 | 103 |
78 int Hunspell::cleanword2(char * dest, const char * src, | 104 int Hunspell::cleanword2(char * dest, const char * src, |
79 w_char * dest_utf, int * nc, int * pcaptype, int * pabbrev) | 105 w_char * dest_utf, int * nc, int * pcaptype, int * pabbrev) |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 ns--; | 338 ns--; |
313 free((*slst)[ns]); | 339 free((*slst)[ns]); |
314 } | 340 } |
315 for (int k = ns; k > 0; k--) (*slst)[k] = (*slst)[k - 1]; | 341 for (int k = ns; k > 0; k--) (*slst)[k] = (*slst)[k - 1]; |
316 (*slst)[0] = dup; | 342 (*slst)[0] = dup; |
317 return ns + 1; | 343 return ns + 1; |
318 } | 344 } |
319 | 345 |
320 int Hunspell::spell(const char * word, int * info, char ** root) | 346 int Hunspell::spell(const char * word, int * info, char ** root) |
321 { | 347 { |
| 348 #ifdef HUNSPELL_CHROME_CLIENT |
| 349 if (pHMgr) pHMgr[0]->EmptyHentryCache(); |
| 350 #endif |
322 struct hentry * rv=NULL; | 351 struct hentry * rv=NULL; |
323 // need larger vector. For example, Turkish capital letter I converted a | 352 // need larger vector. For example, Turkish capital letter I converted a |
324 // 2-byte UTF-8 character (dotless i) by mkallsmall. | 353 // 2-byte UTF-8 character (dotless i) by mkallsmall. |
325 char cw[MAXWORDUTF8LEN]; | 354 char cw[MAXWORDUTF8LEN]; |
326 char wspace[MAXWORDUTF8LEN]; | 355 char wspace[MAXWORDUTF8LEN]; |
327 w_char unicw[MAXWORDLEN]; | 356 w_char unicw[MAXWORDLEN]; |
328 // Hunspell supports XML input of the simplified API (see manual) | 357 // Hunspell supports XML input of the simplified API (see manual) |
329 if (strcmp(word, SPELL_XML) == 0) return 1; | 358 if (strcmp(word, SPELL_XML) == 0) return 1; |
330 int nc = strlen(word); | 359 int nc = strlen(word); |
331 int wl2 = 0; | 360 int wl2 = 0; |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 if (utf8) { | 589 if (utf8) { |
561 int ignoredchars_utf16_len; | 590 int ignoredchars_utf16_len; |
562 unsigned short * ignoredchars_utf16 = pAMgr->get_ignore_utf16(&ignoredch
ars_utf16_len); | 591 unsigned short * ignoredchars_utf16 = pAMgr->get_ignore_utf16(&ignoredch
ars_utf16_len); |
563 remove_ignored_chars_utf(w2, ignoredchars_utf16, ignoredchars_utf16_len)
; | 592 remove_ignored_chars_utf(w2, ignoredchars_utf16, ignoredchars_utf16_len)
; |
564 } else { | 593 } else { |
565 remove_ignored_chars(w2,ignoredchars); | 594 remove_ignored_chars(w2,ignoredchars); |
566 } | 595 } |
567 word = w2; | 596 word = w2; |
568 } else word = w; | 597 } else word = w; |
569 | 598 |
| 599 #ifdef HUNSPELL_CHROME_CLIENT |
| 600 // We need to check if the word length is valid to make coverity (Event |
| 601 // fixed_size_dest: Possible overrun of N byte fixed size buffer) happy. |
| 602 if ((utf8 && strlen(word) >= MAXWORDUTF8LEN) || (!utf8 && strlen(word) >= MAXW
ORDLEN)) |
| 603 return NULL; |
| 604 #endif |
| 605 |
570 // word reversing wrapper for complex prefixes | 606 // word reversing wrapper for complex prefixes |
571 if (complexprefixes) { | 607 if (complexprefixes) { |
572 if (word != w2) { | 608 if (word != w2) { |
573 strcpy(w2, word); | 609 strcpy(w2, word); |
574 word = w2; | 610 word = w2; |
575 } | 611 } |
576 if (utf8) reverseword_utf(w2); else reverseword(w2); | 612 if (utf8) reverseword_utf(w2); else reverseword(w2); |
577 } | 613 } |
578 | 614 |
579 // look word in hash table | 615 // look word in hash table |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 } | 686 } |
651 } | 687 } |
652 | 688 |
653 } | 689 } |
654 | 690 |
655 return he; | 691 return he; |
656 } | 692 } |
657 | 693 |
658 int Hunspell::suggest(char*** slst, const char * word) | 694 int Hunspell::suggest(char*** slst, const char * word) |
659 { | 695 { |
| 696 #ifdef HUNSPELL_CHROME_CLIENT |
| 697 if (pHMgr) pHMgr[0]->EmptyHentryCache(); |
| 698 #endif |
660 int onlycmpdsug = 0; | 699 int onlycmpdsug = 0; |
661 char cw[MAXWORDUTF8LEN]; | 700 char cw[MAXWORDUTF8LEN]; |
662 char wspace[MAXWORDUTF8LEN]; | 701 char wspace[MAXWORDUTF8LEN]; |
663 if (!pSMgr || maxdic == 0) return 0; | 702 if (!pSMgr || maxdic == 0) return 0; |
664 w_char unicw[MAXWORDLEN]; | 703 w_char unicw[MAXWORDLEN]; |
665 *slst = NULL; | 704 *slst = NULL; |
666 // process XML input of the simplified API (see manual) | 705 // process XML input of the simplified API (see manual) |
667 if (strncmp(word, SPELL_XML, sizeof(SPELL_XML) - 3) == 0) { | 706 if (strncmp(word, SPELL_XML, sizeof(SPELL_XML) - 3) == 0) { |
668 return spellml(slst, word); | 707 return spellml(slst, word); |
669 } | 708 } |
(...skipping 1197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1867 } | 1906 } |
1868 | 1907 |
1869 if (*result) return mystrdup(result); | 1908 if (*result) return mystrdup(result); |
1870 return NULL; | 1909 return NULL; |
1871 } | 1910 } |
1872 | 1911 |
1873 #endif // END OF HUNSPELL_EXPERIMENTAL CODE | 1912 #endif // END OF HUNSPELL_EXPERIMENTAL CODE |
1874 | 1913 |
1875 Hunhandle *Hunspell_create(const char * affpath, const char * dpath) | 1914 Hunhandle *Hunspell_create(const char * affpath, const char * dpath) |
1876 { | 1915 { |
| 1916 #ifdef HUNSPELL_CHROME_CLIENT |
| 1917 return NULL; |
| 1918 #else |
1877 return (Hunhandle*)(new Hunspell(affpath, dpath)); | 1919 return (Hunhandle*)(new Hunspell(affpath, dpath)); |
| 1920 #endif |
1878 } | 1921 } |
1879 | 1922 |
1880 Hunhandle *Hunspell_create_key(const char * affpath, const char * dpath, | 1923 Hunhandle *Hunspell_create_key(const char * affpath, const char * dpath, |
1881 const char * key) | 1924 const char * key) |
1882 { | 1925 { |
| 1926 #ifdef HUNSPELL_CHROME_CLIENT |
| 1927 return NULL; |
| 1928 #else |
1883 return (Hunhandle*)(new Hunspell(affpath, dpath, key)); | 1929 return (Hunhandle*)(new Hunspell(affpath, dpath, key)); |
| 1930 #endif |
1884 } | 1931 } |
1885 | 1932 |
1886 void Hunspell_destroy(Hunhandle *pHunspell) | 1933 void Hunspell_destroy(Hunhandle *pHunspell) |
1887 { | 1934 { |
1888 delete (Hunspell*)(pHunspell); | 1935 delete (Hunspell*)(pHunspell); |
1889 } | 1936 } |
1890 | 1937 |
1891 int Hunspell_spell(Hunhandle *pHunspell, const char *word) | 1938 int Hunspell_spell(Hunhandle *pHunspell, const char *word) |
1892 { | 1939 { |
1893 return ((Hunspell*)pHunspell)->spell(word); | 1940 return ((Hunspell*)pHunspell)->spell(word); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1950 | 1997 |
1951 /* remove word from the run-time dictionary */ | 1998 /* remove word from the run-time dictionary */ |
1952 | 1999 |
1953 int Hunspell_remove(Hunhandle *pHunspell, const char * word) { | 2000 int Hunspell_remove(Hunhandle *pHunspell, const char * word) { |
1954 return ((Hunspell*)pHunspell)->remove(word); | 2001 return ((Hunspell*)pHunspell)->remove(word); |
1955 } | 2002 } |
1956 | 2003 |
1957 void Hunspell_free_list(Hunhandle *, char *** slst, int n) { | 2004 void Hunspell_free_list(Hunhandle *, char *** slst, int n) { |
1958 freelist(slst, n); | 2005 freelist(slst, n); |
1959 } | 2006 } |
OLD | NEW |