1
#include "license.hunspell"
2
#include "license.myspell"
11
RepList::RepList(int n) {
12
dat = (replentry **) malloc(sizeof(replentry *) * n);
13
if (dat == 0) size = 0; else size = n;
19
for (int i = 0; i < pos; i++) {
20
free(dat[i]->pattern);
21
free(dat[i]->pattern2);
27
int RepList::get_pos() {
31
replentry * RepList::item(int n) {
35
int RepList::near(const char * word) {
38
while ((p2 - p1) > 1) {
39
int m = (p1 + p2) / 2;
40
// fprintf(stderr, "m: %d p1: %d p2: %d dat: %s\n", m, p1, p2, dat[m]->pattern);
41
int c = strcmp(word, dat[m]->pattern);
43
if (c < 0) p2 = m; else p1 = p2 = m;
46
// fprintf(stderr, "NEAR: %s (word: %s)\n", dat[p1]->pattern, word);
50
int RepList::match(const char * word, int n) {
51
if (strncmp(word, dat[n]->pattern, strlen(dat[n]->pattern)) == 0) return strlen(dat[n]->pattern);
55
int RepList::add(char * pat1, char * pat2) {
56
if (pos >= size || pat1 == NULL || pat2 == NULL) return 1;
57
replentry * r = (replentry *) malloc(sizeof(replentry));
58
if (r == NULL) return 1;
59
r->pattern = mystrrep(pat1, "_", " ");
60
r->pattern2 = mystrrep(pat2, "_", " ");
62
for (int i = pos - 1; i > 0; i--) {
64
if (strcmp(r->pattern, dat[i - 1]->pattern) < 0) {
72
int RepList::conv(const char * word, char * dest) {
75
// for (int i = 0; i < pos; i++) fprintf(stderr, "%d. %s\n", i, dat[i]->pattern);
76
for (size_t i = 0; i < strlen(word); i++) {
77
int n = near(word + i);
78
int l = match(word + i, n);
80
strcpy(dest + stl, dat[n]->pattern2);
81
stl += strlen(dat[n]->pattern2);
84
} else dest[stl++] = word[i];
87
// fprintf(stderr, "i: %s o: %s change: %d\n", word, dest, change);