OLD | NEW |
1 ? google.patch | |
2 Index: hyphen.c | 1 Index: hyphen.c |
3 =================================================================== | 2 =================================================================== |
4 RCS file: /cvsroot/hunspell/hyphen/hyphen.c,v | 3 RCS file: /cvsroot/hunspell/hyphen/hyphen.c,v |
5 retrieving revision 1.4 | 4 retrieving revision 1.8 |
6 diff -u -r1.4 hyphen.c | 5 diff -u -r1.8 hyphen.c |
7 --- hyphen.c» 1 Dec 2010 01:30:20 -0000» 1.4 | 6 --- hyphen.c» 13 Sep 2012 07:50:49 -0000» 1.8 |
8 +++ hyphen.c» 1 Mar 2012 05:18:32 -0000 | 7 +++ hyphen.c» 6 Feb 2013 17:31:51 -0000 |
9 @@ -242,12 +242,71 @@ | 8 @@ -374,19 +374,28 @@ |
10 } | 9 HyphenDict * |
11 #endif | 10 hnj_hyphen_load (const char *fn) |
12 | 11 { |
13 +#ifdef HYPHEN_CHROME_CLIENT | 12 + HyphenDict *result; |
14 +typedef struct { | 13 + FILE *f; |
15 + const unsigned char *data; | 14 + f = fopen (fn, "r"); |
16 + size_t offset; | |
17 + size_t size; | |
18 +} hnj_file; | |
19 + | |
20 +static hnj_file * | |
21 +hnj_fopen (const unsigned char *data, size_t size) | |
22 +{ | |
23 + hnj_file *f; | |
24 + | |
25 + f = hnj_malloc (sizeof(hnj_file)); | |
26 + if (f == NULL) | 15 + if (f == NULL) |
27 + return NULL; | 16 + return NULL; |
28 + f->offset = 0; | 17 + |
29 + f->data = data; | 18 + result = hnj_hyphen_load_file(f); |
30 + f->size = size; | 19 + |
31 + return f; | 20 + fclose(f); |
| 21 + return result; |
32 +} | 22 +} |
33 + | 23 + |
34 +static void | 24 +HyphenDict * |
35 +hnj_fclose (hnj_file *f) | 25 +hnj_hyphen_load_file (FILE *f) |
36 +{ | 26 +{ |
37 + hnj_free (f); | |
38 +} | |
39 + | |
40 +static char * | |
41 +hnj_fgets (char *s, int size, hnj_file *f) | |
42 +{ | |
43 + int i; | |
44 + | |
45 + if (f->offset >= f->size) | |
46 + return NULL; | |
47 + for (i = 0; i < size - 1; i++) { | |
48 + char c; | |
49 + | |
50 + if (f->offset >= f->size) | |
51 + break; | |
52 + c = f->data[f->offset++]; | |
53 + if (c == '\r' || c == '\n') | |
54 + break; | |
55 + s[i] = c; | |
56 + } | |
57 + s[i] = '\0'; | |
58 + return s; | |
59 +} | |
60 +#else | |
61 +typedef FILE hnj_file; | |
62 +#define hnj_fopen(fn, mode) fopen((fn), (mode)) | |
63 +#define hnj_fclose(f) fclose(f) | |
64 +#define hnj_fgets(s, size, f) fgets((s), (size), (f)) | |
65 +#endif | |
66 + | |
67 +#ifdef HYPHEN_CHROME_CLIENT | |
68 +HyphenDict * | |
69 +hnj_hyphen_load (const unsigned char *data, size_t size) | |
70 +#else | |
71 HyphenDict * | |
72 hnj_hyphen_load (const char *fn) | |
73 +#endif | |
74 { | |
75 HyphenDict *dict[2]; | 27 HyphenDict *dict[2]; |
76 HashTab *hashtab; | 28 HashTab *hashtab; |
77 - FILE *f; | 29 - FILE *f; |
78 + hnj_file *f; | |
79 char buf[MAX_CHARS]; | 30 char buf[MAX_CHARS]; |
80 char word[MAX_CHARS]; | 31 int nextlevel = 0; |
81 char pattern[MAX_CHARS]; | 32 int i, j, k; |
82 @@ -261,7 +320,11 @@ | |
83 HashEntry *e; | 33 HashEntry *e; |
84 int nextlevel = 0; | 34 int state_num = 0; |
85 | 35 - |
86 +#ifdef HYPHEN_CHROME_CLIENT | 36 - f = fopen (fn, "r"); |
87 + f = hnj_fopen (data, size); | 37 - if (f == NULL) |
88 +#else | 38 - return NULL; |
89 f = fopen (fn, "r"); | 39 - |
90 +#endif | 40 // loading one or two dictionaries (separated by NEXTLEVEL keyword) |
91 if (f == NULL) | 41 for (k = 0; k < 2; k++) { |
92 return NULL; | 42 hashtab = hnj_hash_new (); |
93 | 43 @@ -497,7 +506,6 @@ |
94 @@ -291,7 +354,7 @@ | |
95 /* read in character set info */ | |
96 if (k == 0) { | |
97 for (i=0;i<MAX_NAME;i++) dict[k]->cset[i]= 0; | |
98 - if (fgets(dict[k]->cset, sizeof(dict[k]->cset),f) != NULL) { | |
99 + if (hnj_fgets(dict[k]->cset, sizeof(dict[k]->cset),f) != NULL) { | |
100 for (i=0;i<MAX_NAME;i++) | |
101 if ((dict[k]->cset[i] == '\r') || (dict[k]->cset[i] == '\n')) | |
102 dict[k]->cset[i] = 0; | |
103 @@ -304,7 +367,7 @@ | |
104 dict[k]->utf8 = dict[0]->utf8; | |
105 } | |
106 | |
107 - while (fgets (buf, sizeof(buf), f) != NULL) | |
108 + while (hnj_fgets (buf, sizeof(buf), f) != NULL) | |
109 { | |
110 if (buf[0] != '%') | |
111 » { | |
112 @@ -385,7 +448,7 @@ | |
113 if (dict[k]->utf8) { | |
114 int pu = -1; /* unicode character position */ | |
115 int ps = -1; /* unicode start position (original replind
ex) */ | |
116 - int pc = (*word == '.') ? 1: 0; /* 8-bit character position */ | |
117 + size_t pc = (*word == '.') ? 1: 0; /* 8-bit character position
*/ | |
118 for (; pc < (strlen(word) + 1); pc++) { | |
119 /* beginning of an UTF-8 character (not '10' start bits) */ | |
120 if ((((unsigned char) word[pc]) >> 6) != 2) pu++; | |
121 @@ -478,7 +541,7 @@ | |
122 #endif | 44 #endif |
123 state_num = 0; | 45 state_num = 0; |
124 } | 46 } |
125 - fclose(f); | 47 - fclose(f); |
126 + hnj_fclose(f); | 48 if (nextlevel) dict[0]->nextlevel = dict[1]; |
127 if (k == 2) dict[0]->nextlevel = dict[1]; | 49 else { |
128 return dict[0]; | 50 dict[1] -> nextlevel = dict[0]; |
129 } | |
130 Index: hyphen.h | 51 Index: hyphen.h |
131 =================================================================== | 52 =================================================================== |
132 RCS file: /cvsroot/hunspell/hyphen/hyphen.h,v | 53 RCS file: /cvsroot/hunspell/hyphen/hyphen.h,v |
133 retrieving revision 1.2 | 54 retrieving revision 1.2 |
134 diff -u -r1.2 hyphen.h | 55 diff -u -r1.2 hyphen.h |
135 --- hyphen.h 27 Nov 2010 02:20:33 -0000 1.2 | 56 --- hyphen.h 27 Nov 2010 02:20:33 -0000 1.2 |
136 +++ hyphen.h» 1 Mar 2012 05:18:33 -0000 | 57 +++ hyphen.h» 6 Feb 2013 17:31:51 -0000 |
137 @@ -93,7 +93,11 @@ | 58 @@ -94,6 +94,7 @@ |
138 int new_state; | |
139 }; | 59 }; |
140 | 60 |
141 +#ifdef HYPHEN_CHROME_CLIENT | |
142 +HyphenDict *hnj_hyphen_load (const unsigned char *data, size_t size); | |
143 +#else | |
144 HyphenDict *hnj_hyphen_load (const char *fn); | 61 HyphenDict *hnj_hyphen_load (const char *fn); |
145 +#endif | 62 +HyphenDict *hnj_hyphen_load_file (FILE *f); |
146 void hnj_hyphen_free (HyphenDict *dict); | 63 void hnj_hyphen_free (HyphenDict *dict); |
147 | 64 |
148 /* obsolete, use hnj_hyphen_hyphenate2() or *hyphenate3() functions) */ | 65 /* obsolete, use hnj_hyphen_hyphenate2() or *hyphenate3() functions) */ |
OLD | NEW |