Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: third_party/hyphen/google.patch

Issue 9545017: Adds a hy-phen-ator. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « third_party/hyphen/README.chromium ('k') | third_party/hyphen/hyph_en_US.dic » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 ? google.patch
2 Index: hyphen.c
3 ===================================================================
4 RCS file: /cvsroot/hunspell/hyphen/hyphen.c,v
5 retrieving revision 1.4
6 diff -u -r1.4 hyphen.c
7 --- hyphen.c 1 Dec 2010 01:30:20 -0000 1.4
8 +++ hyphen.c 1 Mar 2012 05:18:32 -0000
9 @@ -242,12 +242,71 @@
10 }
11 #endif
12
13 +#ifdef HYPHEN_CHROME_CLIENT
14 +typedef struct {
15 + const unsigned char *data;
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)
27 + return NULL;
28 + f->offset = 0;
29 + f->data = data;
30 + f->size = size;
31 + return f;
32 +}
33 +
34 +static void
35 +hnj_fclose (hnj_file *f)
36 +{
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];
76 HashTab *hashtab;
77 - FILE *f;
78 + hnj_file *f;
79 char buf[MAX_CHARS];
80 char word[MAX_CHARS];
81 char pattern[MAX_CHARS];
82 @@ -261,7 +320,11 @@
83 HashEntry *e;
84 int nextlevel = 0;
85
86 +#ifdef HYPHEN_CHROME_CLIENT
87 + f = hnj_fopen (data, size);
88 +#else
89 f = fopen (fn, "r");
90 +#endif
91 if (f == NULL)
92 return NULL;
93
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
123 state_num = 0;
124 }
125 - fclose(f);
126 + hnj_fclose(f);
127 if (k == 2) dict[0]->nextlevel = dict[1];
128 return dict[0];
129 }
130 Index: hyphen.h
131 ===================================================================
132 RCS file: /cvsroot/hunspell/hyphen/hyphen.h,v
133 retrieving revision 1.2
134 diff -u -r1.2 hyphen.h
135 --- hyphen.h 27 Nov 2010 02:20:33 -0000 1.2
136 +++ hyphen.h 1 Mar 2012 05:18:33 -0000
137 @@ -93,7 +93,11 @@
138 int new_state;
139 };
140
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);
145 +#endif
146 void hnj_hyphen_free (HyphenDict *dict);
147
148 /* obsolete, use hnj_hyphen_hyphenate2() or *hyphenate3() functions) */
OLDNEW
« no previous file with comments | « third_party/hyphen/README.chromium ('k') | third_party/hyphen/hyph_en_US.dic » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698