[evolution-patches] Evolution-exchange's outstanding Win32 diffs
- From: Tor Lillqvist <tlillqvist novell com>
- To: evolution-patches gnome org
- Subject: [evolution-patches] Evolution-exchange's outstanding Win32 diffs
- Date: Wed, 18 Jan 2006 16:02:45 +0200
I remembered that most of the Win32 work on evolution-exchange is yet to
be committed. Could somebody have a quick glance through this and give
an okay, thanks?
Cheers,
--tml
--- lingucomponent/source/spellcheck/hunspell.orig/hashmgr.hxx Fri Jan 6 15:10:45 2006
+++ lingucomponent/source/spellcheck/hunspell/hashmgr.hxx Tue Jan 17 18:23:42 2006
@@ -13,6 +13,11 @@ class HashMgr
flag flag_mode;
int complexprefixes;
int utf8;
+ char * buffer;
+ size_t length;
+
+ size_t seek_newline(size_t from_offset) const;
+ int slurp(int fd);
public:
HashMgr(const char * tpath, const char * apath);
@@ -30,7 +35,7 @@ public:
private:
int load_tables(const char * tpath);
- int add_word(const char * word, int wl, unsigned short * ap, int al, const char * desc);
+ int add_word(char * word, int wl, unsigned short * ap, int al, char * desc);
int load_config(const char * affpath);
};
--- lingucomponent/source/spellcheck/hunspell.orig/hashmgr.cxx Fri Jan 6 15:10:34 2006
+++ lingucomponent/source/spellcheck/hunspell/hashmgr.cxx Tue Jan 17 19:24:50 2006
@@ -4,10 +4,23 @@
#include <cstdlib>
#include <cstring>
#include <cctype>
-#ifdef HAVE_FCNTL_H
+#include <cstdio>
+
+#include <sys/types.h>
+#include <sys/stat.h>
#include <fcntl.h>
+#include <errno.h>
+
+#ifndef _O_BINARY
+#define _O_BINARY 0
+#endif
+
+#ifdef W32
+#include <io.h>
+#ifdef _MSC_VER
+typedef int ssize_t;
+#endif
#endif
-#include <cstdio>
#include "hashmgr.hxx"
#include "csutil.hxx"
@@ -17,6 +30,8 @@
using namespace std;
#endif
+#define IS_END(c) ((c) == '\r' || (c) == '\n')
+
// build a hash table from a munched word list
HashMgr::HashMgr(const char * tpath, const char * apath)
@@ -48,23 +63,25 @@ HashMgr::~HashMgr()
for (int i=0; i < tablesize; i++) {
struct hentry * pt = &tableptr[i];
struct hentry * nt = NULL;
+ // pt->description is non-NULL only for hentrys read in from a
+ // file (and it points inside buffer, and should thus not be
+ // freed), and for them pt->word also points inside buffer and
+ // should not be freed.
if (pt) {
if (pt->astr) free(pt->astr);
- if (pt->word) free(pt->word);
- if (pt->description) free(pt->description);
-
+ if (!pt->description && pt->word) free(pt->word);
pt = pt->next;
}
while(pt) {
nt = pt->next;
if (pt->astr) free(pt->astr);
- if (pt->word) free(pt->word);
- if (pt->description) free(pt->description);
+ if (!pt->description && pt->word) free(pt->word);
free(pt);
pt = nt;
}
}
free(tableptr);
+ free(buffer);
}
tablesize = 0;
}
@@ -86,34 +103,32 @@ struct hentry * HashMgr::lookup(const ch
// add a word to the hash table (private)
-int HashMgr::add_word(const char * word, int wl, unsigned short * aff, int al, const char * desc)
+int HashMgr::add_word(char * word, int wl, unsigned short * aff, int al, char * desc)
{
- char * st = mystrdup(word);
- if (wl && !st) return 1;
if (complexprefixes) {
- if (utf8) reverseword_utf(st); else reverseword(st);
+ if (utf8) reverseword_utf(word); else reverseword(word);
}
- int i = hash(st);
+ int i = hash(word);
struct hentry * dp = &tableptr[i];
if (dp->word == NULL) {
dp->wlen = wl;
dp->alen = al;
- dp->word = st;
+ dp->word = word;
dp->astr = aff;
dp->next = NULL;
dp->next_homonym = NULL;
- dp->description = mystrdup(desc);
+ dp->description = desc;
if (desc && !dp->description) return 1;
} else {
struct hentry* hp = (struct hentry *) malloc (sizeof(struct hentry));
if (!hp) return 1;
hp->wlen = wl;
hp->alen = al;
- hp->word = st;
+ hp->word = word;
hp->astr = aff;
hp->next = NULL;
hp->next_homonym = NULL;
- hp->description = mystrdup(desc);
+ hp->description = desc;
if (desc && !hp->description) return 1;
while (dp->next != NULL) {
if ((!dp->next_homonym) && strcmp(hp->word, dp->word) == 0) dp->next_homonym = hp;
@@ -137,7 +152,7 @@ int HashMgr::put_word(const char * word,
} else {
flags = NULL;
}
- add_word(word, wl, flags, al, NULL);
+ add_word(mystrdup(word), wl, flags, al, NULL);
return 0;
}
@@ -148,7 +163,7 @@ int HashMgr::put_word_pattern(const char
if (!dp || !dp->astr) return 1;
flags = (unsigned short *) malloc (dp->alen * sizeof(short));
memcpy((void *) flags, (void *) dp->astr, dp->alen * sizeof(short));
- add_word(word, wl, flags, dp->alen, NULL);
+ add_word(mystrdup(word), wl, flags, dp->alen, NULL);
return 0;
}
@@ -178,38 +193,100 @@ struct hentry * HashMgr::walk_hashtable(
return hp;
}
+size_t
+HashMgr::seek_newline( size_t i ) const
+{
+ while (i < length && !IS_END(buffer[i])) i++;
+ while (i < length && IS_END(buffer[i])) i++;
+ return i;
+}
+
+int
+HashMgr::slurp( int fd )
+{
+ struct stat st;
+ size_t offset;
+ size_t bytes;
+ ssize_t count;
+
+ if (fstat(fd, &st) == -1)
+ return 1;
+
+ length = st.st_size;
+
+ buffer = new char[length + 1];
+
+ offset = 0;
+ bytes = length;
+ do {
+ count = read (fd, buffer + offset, bytes);
+ if (count < 0) {
+ if (errno == EINTR)
+ continue;
+ else
+ return 1;
+ }
+ bytes -= count;
+ offset += count;
+ } while (bytes > 0);
+ // zero-terminate just to be sure
+ buffer[length] = '\0';
+
+ return 0;
+}
+
// load a munched word list and build a hash table on the fly
int HashMgr::load_tables(const char * tpath)
{
- int wl, al;
+ int al;
char * ap;
char * dp;
unsigned short * flags;
+ size_t cur_line, next_line;
// raw dictionary - munched file
- FILE * rawdict = fopen(tpath, "r");
- if (rawdict == NULL) return 1;
+ int rawdict = open(tpath, O_RDONLY|_O_BINARY);
+ if (rawdict == -1) return 1;
+
+ if (slurp (rawdict)) {
+ close (rawdict);
+ return 1;
+ }
+
+ // get hash table size from first line
+ tablesize = atoi (buffer);
+ if (tablesize <= 0) {
+ fprintf(stderr, "error - missing or invalid word count in dictionary file\n");
+ return 4;
+ }
- // first read the first line of file to get hash table size */
- char ts[MAXDELEN];
- if (! fgets(ts, MAXDELEN-1,rawdict)) return 2;
- mychomp(ts);
- if ((*ts < '1') || (*ts > '9')) fprintf(stderr, "error - missing word count in dictionary file\n");
- tablesize = atoi(ts);
- if (!tablesize) return 4;
tablesize = tablesize + 5 + USERWORD;
- if ((tablesize %2) == 0) tablesize++;
+
+ // Bin any small prime factors
+ while (!(tablesize % 2) || !(tablesize % 3) || !(tablesize % 5 ) ||
+ !(tablesize % 7) || !(tablesize % 11) || !(tablesize % 13 ))
+ tablesize++;
// allocate the hash table
tableptr = (struct hentry *) calloc(tablesize, sizeof(struct hentry));
if (! tableptr) return 3;
for (int i=0; i<tablesize; i++) tableptr[i].word = NULL;
+ cur_line = seek_newline (0);
+
// loop through all words on much list and add to hash
// table and create word and affix strings
- while (fgets(ts,MAXDELEN-1,rawdict)) {
- mychomp(ts);
+ while (cur_line < length) {
+ next_line = seek_newline (cur_line);
+
+ if (IS_END(buffer[next_line-1]))
+ buffer[next_line-1] = '\0';
+ if (IS_END(buffer[next_line-2]))
+ buffer[next_line-2] = '\0';
+
+ char *ts = buffer + cur_line;
+
// split each line into word and morphological description
dp = strchr(ts,'\t');
@@ -217,7 +294,7 @@ int HashMgr::load_tables(const char * tp
*dp = '\0';
dp++;
} else {
- dp = NULL;
+ dp = buffer+next_line-1;
}
// split each line into word and affix char strings
@@ -233,14 +310,13 @@ int HashMgr::load_tables(const char * tp
flags = NULL;
}
- wl = strlen(ts);
-
// add the word and its index
- if (add_word(ts,wl,flags,al,dp)) return 5;
+ if (add_word(ts,strlen(ts),flags,al,dp)) return 5;
+ cur_line = next_line;
}
- fclose(rawdict);
+ close(rawdict);
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]