ferret 0.11.6 → 0.11.8.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README +10 -22
- data/RELEASE_CHANGES +137 -0
- data/RELEASE_NOTES +60 -0
- data/Rakefile +379 -274
- data/TODO +100 -8
- data/bin/ferret-browser +0 -0
- data/ext/BZLIB_blocksort.c +1094 -0
- data/ext/BZLIB_bzlib.c +1578 -0
- data/ext/BZLIB_compress.c +672 -0
- data/ext/BZLIB_crctable.c +104 -0
- data/ext/BZLIB_decompress.c +626 -0
- data/ext/BZLIB_huffman.c +205 -0
- data/ext/BZLIB_randtable.c +84 -0
- data/ext/{api.c → STEMMER_api.c} +7 -10
- data/ext/{libstemmer.c → STEMMER_libstemmer.c} +3 -2
- data/ext/{stem_ISO_8859_1_danish.c → STEMMER_stem_ISO_8859_1_danish.c} +123 -124
- data/ext/{stem_ISO_8859_1_dutch.c → STEMMER_stem_ISO_8859_1_dutch.c} +177 -188
- data/ext/STEMMER_stem_ISO_8859_1_english.c +1117 -0
- data/ext/{stem_ISO_8859_1_finnish.c → STEMMER_stem_ISO_8859_1_finnish.c} +276 -306
- data/ext/STEMMER_stem_ISO_8859_1_french.c +1246 -0
- data/ext/{stem_ISO_8859_1_german.c → STEMMER_stem_ISO_8859_1_german.c} +161 -170
- data/ext/STEMMER_stem_ISO_8859_1_hungarian.c +1230 -0
- data/ext/STEMMER_stem_ISO_8859_1_italian.c +1065 -0
- data/ext/STEMMER_stem_ISO_8859_1_norwegian.c +297 -0
- data/ext/{stem_ISO_8859_1_porter.c → STEMMER_stem_ISO_8859_1_porter.c} +263 -290
- data/ext/{stem_ISO_8859_1_portuguese.c → STEMMER_stem_ISO_8859_1_portuguese.c} +362 -380
- data/ext/STEMMER_stem_ISO_8859_1_spanish.c +1093 -0
- data/ext/STEMMER_stem_ISO_8859_1_swedish.c +307 -0
- data/ext/STEMMER_stem_ISO_8859_2_romanian.c +998 -0
- data/ext/{stem_KOI8_R_russian.c → STEMMER_stem_KOI8_R_russian.c} +244 -245
- data/ext/STEMMER_stem_UTF_8_danish.c +339 -0
- data/ext/{stem_UTF_8_dutch.c → STEMMER_stem_UTF_8_dutch.c} +192 -211
- data/ext/STEMMER_stem_UTF_8_english.c +1125 -0
- data/ext/{stem_UTF_8_finnish.c → STEMMER_stem_UTF_8_finnish.c} +284 -324
- data/ext/STEMMER_stem_UTF_8_french.c +1256 -0
- data/ext/{stem_UTF_8_german.c → STEMMER_stem_UTF_8_german.c} +170 -187
- data/ext/STEMMER_stem_UTF_8_hungarian.c +1234 -0
- data/ext/STEMMER_stem_UTF_8_italian.c +1073 -0
- data/ext/STEMMER_stem_UTF_8_norwegian.c +299 -0
- data/ext/{stem_UTF_8_porter.c → STEMMER_stem_UTF_8_porter.c} +271 -310
- data/ext/STEMMER_stem_UTF_8_portuguese.c +1023 -0
- data/ext/STEMMER_stem_UTF_8_romanian.c +1004 -0
- data/ext/STEMMER_stem_UTF_8_russian.c +694 -0
- data/ext/STEMMER_stem_UTF_8_spanish.c +1097 -0
- data/ext/STEMMER_stem_UTF_8_swedish.c +309 -0
- data/ext/STEMMER_stem_UTF_8_turkish.c +2205 -0
- data/ext/{utilities.c → STEMMER_utilities.c} +100 -68
- data/ext/analysis.c +276 -121
- data/ext/analysis.h +190 -143
- data/ext/api.h +3 -4
- data/ext/array.c +5 -3
- data/ext/array.h +52 -43
- data/ext/bitvector.c +38 -482
- data/ext/bitvector.h +446 -124
- data/ext/bzlib.h +282 -0
- data/ext/bzlib_private.h +503 -0
- data/ext/compound_io.c +23 -22
- data/ext/config.h +21 -11
- data/ext/document.c +43 -40
- data/ext/document.h +31 -21
- data/ext/except.c +20 -38
- data/ext/except.h +89 -76
- data/ext/extconf.rb +3 -2
- data/ext/ferret.c +49 -35
- data/ext/ferret.h +14 -11
- data/ext/field_index.c +262 -0
- data/ext/field_index.h +52 -0
- data/ext/filter.c +11 -10
- data/ext/fs_store.c +65 -47
- data/ext/global.c +245 -165
- data/ext/global.h +252 -54
- data/ext/hash.c +200 -243
- data/ext/hash.h +205 -163
- data/ext/hashset.c +118 -96
- data/ext/hashset.h +110 -82
- data/ext/header.h +19 -19
- data/ext/helper.c +11 -10
- data/ext/helper.h +14 -6
- data/ext/index.c +745 -366
- data/ext/index.h +503 -529
- data/ext/internal.h +1020 -0
- data/ext/lang.c +10 -0
- data/ext/lang.h +35 -15
- data/ext/mempool.c +5 -4
- data/ext/mempool.h +30 -22
- data/ext/modules.h +35 -7
- data/ext/multimapper.c +43 -2
- data/ext/multimapper.h +32 -23
- data/ext/posh.c +0 -0
- data/ext/posh.h +4 -38
- data/ext/priorityqueue.c +10 -12
- data/ext/priorityqueue.h +33 -21
- data/ext/q_boolean.c +22 -9
- data/ext/q_const_score.c +3 -2
- data/ext/q_filtered_query.c +15 -12
- data/ext/q_fuzzy.c +147 -135
- data/ext/q_match_all.c +3 -2
- data/ext/q_multi_term.c +28 -32
- data/ext/q_parser.c +451 -173
- data/ext/q_phrase.c +158 -79
- data/ext/q_prefix.c +16 -18
- data/ext/q_range.c +363 -31
- data/ext/q_span.c +130 -141
- data/ext/q_term.c +21 -21
- data/ext/q_wildcard.c +19 -23
- data/ext/r_analysis.c +369 -242
- data/ext/r_index.c +421 -434
- data/ext/r_qparser.c +142 -92
- data/ext/r_search.c +790 -407
- data/ext/r_store.c +44 -44
- data/ext/r_utils.c +264 -96
- data/ext/ram_store.c +29 -23
- data/ext/scanner.c +895 -0
- data/ext/scanner.h +36 -0
- data/ext/scanner_mb.c +6701 -0
- data/ext/scanner_utf8.c +4415 -0
- data/ext/search.c +210 -87
- data/ext/search.h +556 -488
- data/ext/similarity.c +17 -16
- data/ext/similarity.h +51 -44
- data/ext/sort.c +157 -354
- data/ext/stem_ISO_8859_1_hungarian.h +16 -0
- data/ext/stem_ISO_8859_2_romanian.h +16 -0
- data/ext/stem_UTF_8_hungarian.h +16 -0
- data/ext/stem_UTF_8_romanian.h +16 -0
- data/ext/stem_UTF_8_turkish.h +16 -0
- data/ext/stopwords.c +287 -278
- data/ext/store.c +57 -51
- data/ext/store.h +308 -286
- data/ext/symbol.c +10 -0
- data/ext/symbol.h +23 -0
- data/ext/term_vectors.c +14 -293
- data/ext/threading.h +22 -22
- data/ext/win32.h +12 -4
- data/lib/ferret.rb +2 -1
- data/lib/ferret/browser.rb +1 -1
- data/lib/ferret/field_symbol.rb +94 -0
- data/lib/ferret/index.rb +221 -34
- data/lib/ferret/number_tools.rb +6 -6
- data/lib/ferret/version.rb +3 -0
- data/test/{unit → long_running}/largefile/tc_largefile.rb +1 -1
- data/test/test_helper.rb +7 -2
- data/test/test_installed.rb +1 -0
- data/test/threading/thread_safety_index_test.rb +10 -1
- data/test/threading/thread_safety_read_write_test.rb +4 -7
- data/test/threading/thread_safety_test.rb +0 -0
- data/test/unit/analysis/tc_analyzer.rb +29 -27
- data/test/unit/analysis/tc_token_stream.rb +23 -16
- data/test/unit/index/tc_index.rb +116 -11
- data/test/unit/index/tc_index_reader.rb +27 -27
- data/test/unit/index/tc_index_writer.rb +10 -0
- data/test/unit/index/th_doc.rb +38 -21
- data/test/unit/search/tc_filter.rb +31 -10
- data/test/unit/search/tc_index_searcher.rb +6 -0
- data/test/unit/search/tm_searcher.rb +53 -1
- data/test/unit/store/tc_fs_store.rb +40 -2
- data/test/unit/store/tc_ram_store.rb +0 -0
- data/test/unit/store/tm_store.rb +0 -0
- data/test/unit/store/tm_store_lock.rb +7 -6
- data/test/unit/tc_field_symbol.rb +26 -0
- data/test/unit/ts_analysis.rb +0 -0
- data/test/unit/ts_index.rb +0 -0
- data/test/unit/ts_store.rb +0 -0
- data/test/unit/ts_utils.rb +0 -0
- data/test/unit/utils/tc_number_tools.rb +0 -0
- data/test/utils/content_generator.rb +226 -0
- metadata +262 -221
- data/ext/inc/lang.h +0 -48
- data/ext/inc/threading.h +0 -31
- data/ext/stem_ISO_8859_1_english.c +0 -1156
- data/ext/stem_ISO_8859_1_french.c +0 -1276
- data/ext/stem_ISO_8859_1_italian.c +0 -1091
- data/ext/stem_ISO_8859_1_norwegian.c +0 -296
- data/ext/stem_ISO_8859_1_spanish.c +0 -1119
- data/ext/stem_ISO_8859_1_swedish.c +0 -307
- data/ext/stem_UTF_8_danish.c +0 -344
- data/ext/stem_UTF_8_english.c +0 -1176
- data/ext/stem_UTF_8_french.c +0 -1296
- data/ext/stem_UTF_8_italian.c +0 -1113
- data/ext/stem_UTF_8_norwegian.c +0 -302
- data/ext/stem_UTF_8_portuguese.c +0 -1055
- data/ext/stem_UTF_8_russian.c +0 -709
- data/ext/stem_UTF_8_spanish.c +0 -1137
- data/ext/stem_UTF_8_swedish.c +0 -313
- data/lib/ferret_version.rb +0 -3
data/ext/compound_io.c
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
#include "index.h"
|
2
|
-
#include "array.h"
|
1
|
+
#include "index.h"
|
2
|
+
#include "array.h"
|
3
|
+
#include "internal.h"
|
3
4
|
|
4
5
|
extern void store_destroy(Store *store);
|
5
6
|
extern InStream *is_new();
|
@@ -16,12 +17,12 @@ typedef struct FileEntry {
|
|
16
17
|
off_t length;
|
17
18
|
} FileEntry;
|
18
19
|
|
19
|
-
static void cmpd_touch(Store *store, char *file_name)
|
20
|
+
static void cmpd_touch(Store *store, const char *file_name)
|
20
21
|
{
|
21
22
|
store->dir.cmpd->store->touch(store->dir.cmpd->store, file_name);
|
22
23
|
}
|
23
24
|
|
24
|
-
static int cmpd_exists(Store *store, char *file_name)
|
25
|
+
static int cmpd_exists(Store *store, const char *file_name)
|
25
26
|
{
|
26
27
|
if (h_get(store->dir.cmpd->entries, file_name) != NULL) {
|
27
28
|
return true;
|
@@ -34,23 +35,23 @@ static int cmpd_exists(Store *store, char *file_name)
|
|
34
35
|
/**
|
35
36
|
* @throws UNSUPPORTED_ERROR
|
36
37
|
*/
|
37
|
-
static int cmpd_remove(Store *store, char *file_name)
|
38
|
+
static int cmpd_remove(Store *store, const char *file_name)
|
38
39
|
{
|
39
40
|
(void)store;
|
40
41
|
(void)file_name;
|
41
|
-
RAISE(UNSUPPORTED_ERROR, UNSUPPORTED_ERROR_MSG);
|
42
|
+
RAISE(UNSUPPORTED_ERROR, "%s", UNSUPPORTED_ERROR_MSG);
|
42
43
|
return 0;
|
43
44
|
}
|
44
45
|
|
45
46
|
/**
|
46
47
|
* @throws UNSUPPORTED_ERROR
|
47
48
|
*/
|
48
|
-
static void cmpd_rename(Store *store, char *from, char *to)
|
49
|
+
static void cmpd_rename(Store *store, const char *from, const char *to)
|
49
50
|
{
|
50
51
|
(void)store;
|
51
52
|
(void)from;
|
52
53
|
(void)to;
|
53
|
-
RAISE(UNSUPPORTED_ERROR, UNSUPPORTED_ERROR_MSG);
|
54
|
+
RAISE(UNSUPPORTED_ERROR, "%s", UNSUPPORTED_ERROR_MSG);
|
54
55
|
}
|
55
56
|
|
56
57
|
static int cmpd_count(Store *store)
|
@@ -59,9 +60,9 @@ static int cmpd_count(Store *store)
|
|
59
60
|
}
|
60
61
|
|
61
62
|
static void cmpd_each(Store *store,
|
62
|
-
void (*func)(char *fname, void *arg), void *arg)
|
63
|
+
void (*func)(const char *fname, void *arg), void *arg)
|
63
64
|
{
|
64
|
-
|
65
|
+
Hash *ht = store->dir.cmpd->entries;
|
65
66
|
int i;
|
66
67
|
for (i = 0; i <= ht->mask; i++) {
|
67
68
|
char *fn = (char *)ht->table[i].key;
|
@@ -78,7 +79,7 @@ static void cmpd_each(Store *store,
|
|
78
79
|
static void cmpd_clear(Store *store)
|
79
80
|
{
|
80
81
|
(void)store;
|
81
|
-
RAISE(UNSUPPORTED_ERROR, UNSUPPORTED_ERROR_MSG);
|
82
|
+
RAISE(UNSUPPORTED_ERROR, "%s", UNSUPPORTED_ERROR_MSG);
|
82
83
|
}
|
83
84
|
|
84
85
|
static void cmpd_close_i(Store *store)
|
@@ -96,9 +97,9 @@ static void cmpd_close_i(Store *store)
|
|
96
97
|
store_destroy(store);
|
97
98
|
}
|
98
99
|
|
99
|
-
static off_t cmpd_length(Store *store, char *file_name)
|
100
|
+
static off_t cmpd_length(Store *store, const char *file_name)
|
100
101
|
{
|
101
|
-
FileEntry *fe = h_get(store->dir.cmpd->entries, file_name);
|
102
|
+
FileEntry *fe = (FileEntry *)h_get(store->dir.cmpd->entries, file_name);
|
102
103
|
if (fe != NULL) {
|
103
104
|
return fe->length;
|
104
105
|
}
|
@@ -133,7 +134,7 @@ static void cmpdi_read_i(InStream *is, uchar *b, int len)
|
|
133
134
|
|
134
135
|
if ((start + len) > cis->length) {
|
135
136
|
RAISE(EOF_ERROR, "Tried to read past end of file. File length is "
|
136
|
-
"<%"
|
137
|
+
"<%"OFF_T_PFX"d> and tried to read to <%"OFF_T_PFX"d>",
|
137
138
|
cis->length, start + len);
|
138
139
|
}
|
139
140
|
|
@@ -175,7 +176,7 @@ static InStream *cmpd_open_input(Store *store, const char *file_name)
|
|
175
176
|
"stream is closed.");
|
176
177
|
}
|
177
178
|
|
178
|
-
entry = h_get(cmpd->entries, file_name);
|
179
|
+
entry = (FileEntry *)h_get(cmpd->entries, file_name);
|
179
180
|
if (entry == NULL) {
|
180
181
|
mutex_unlock(&store->mutex);
|
181
182
|
RAISE(IO_ERROR, "File %s does not exist: ", file_name);
|
@@ -191,22 +192,22 @@ static OutStream *cmpd_new_output(Store *store, const char *file_name)
|
|
191
192
|
{
|
192
193
|
(void)store;
|
193
194
|
(void)file_name;
|
194
|
-
RAISE(UNSUPPORTED_ERROR, UNSUPPORTED_ERROR_MSG);
|
195
|
+
RAISE(UNSUPPORTED_ERROR, "%s", UNSUPPORTED_ERROR_MSG);
|
195
196
|
return NULL;
|
196
197
|
}
|
197
198
|
|
198
|
-
static Lock *cmpd_open_lock_i(Store *store, char *lock_name)
|
199
|
+
static Lock *cmpd_open_lock_i(Store *store, const char *lock_name)
|
199
200
|
{
|
200
201
|
(void)store;
|
201
202
|
(void)lock_name;
|
202
|
-
RAISE(UNSUPPORTED_ERROR, UNSUPPORTED_ERROR_MSG);
|
203
|
+
RAISE(UNSUPPORTED_ERROR, "%s", UNSUPPORTED_ERROR_MSG);
|
203
204
|
return NULL;
|
204
205
|
}
|
205
206
|
|
206
207
|
static void cmpd_close_lock_i(Lock *lock)
|
207
208
|
{
|
208
209
|
(void)lock;
|
209
|
-
RAISE(UNSUPPORTED_ERROR, UNSUPPORTED_ERROR_MSG);
|
210
|
+
RAISE(UNSUPPORTED_ERROR, "%s", UNSUPPORTED_ERROR_MSG);
|
210
211
|
}
|
211
212
|
|
212
213
|
Store *open_cmpd_store(Store *store, const char *name)
|
@@ -322,7 +323,7 @@ static void cw_copy_file(CompoundWriter *cw, CWFileEntry *src, OutStream *os)
|
|
322
323
|
/* Verify that remainder is 0 */
|
323
324
|
if (remainder != 0) {
|
324
325
|
RAISE(IO_ERROR, "There seems to be an error in the compound file "
|
325
|
-
"should have read to the end but there are <%"
|
326
|
+
"should have read to the end but there are <%"OFF_T_PFX"d> "
|
326
327
|
"bytes left", remainder);
|
327
328
|
}
|
328
329
|
|
@@ -331,8 +332,8 @@ static void cw_copy_file(CompoundWriter *cw, CWFileEntry *src, OutStream *os)
|
|
331
332
|
len = end_ptr - start_ptr;
|
332
333
|
if (len != length) {
|
333
334
|
RAISE(IO_ERROR, "Difference in compound file output file offsets "
|
334
|
-
"<%"
|
335
|
-
"<%"
|
335
|
+
"<%"OFF_T_PFX"d> does not match the original file lenght "
|
336
|
+
"<%"OFF_T_PFX"d>", len, length);
|
336
337
|
}
|
337
338
|
|
338
339
|
is_close(is);
|
data/ext/config.h
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
#ifndef FRT_DEFINES_H
|
2
2
|
#define FRT_DEFINES_H
|
3
3
|
|
4
|
+
#ifdef __cplusplus
|
5
|
+
extern "C" {
|
6
|
+
#endif
|
7
|
+
|
4
8
|
#include <sys/types.h>
|
5
9
|
#include <limits.h>
|
6
10
|
#include "posh.h"
|
@@ -12,31 +16,37 @@
|
|
12
16
|
#define true 1
|
13
17
|
#endif
|
14
18
|
|
19
|
+
#ifndef __cplusplus
|
15
20
|
typedef unsigned int bool;
|
16
|
-
|
21
|
+
#endif
|
22
|
+
typedef unsigned char frt_uchar;
|
17
23
|
|
18
|
-
typedef posh_u16_t
|
19
|
-
typedef posh_i16_t
|
20
|
-
typedef posh_u32_t
|
21
|
-
typedef posh_i32_t
|
22
|
-
typedef posh_u64_t
|
23
|
-
typedef posh_i64_t
|
24
|
+
typedef posh_u16_t frt_u16;
|
25
|
+
typedef posh_i16_t frt_i16;
|
26
|
+
typedef posh_u32_t frt_u32;
|
27
|
+
typedef posh_i32_t frt_i32;
|
28
|
+
typedef posh_u64_t frt_u64;
|
29
|
+
typedef posh_i64_t frt_i64;
|
24
30
|
|
25
31
|
#if ( LONG_MAX == 2147483647 ) && defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64)
|
26
|
-
#define
|
32
|
+
#define FRT_OFF_T_PFX "ll"
|
27
33
|
#else
|
28
|
-
#define
|
34
|
+
#define FRT_OFF_T_PFX "l"
|
29
35
|
#endif
|
30
36
|
|
31
|
-
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
|
37
|
+
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(__cplusplus)
|
32
38
|
#define FRT_IS_C99
|
33
39
|
#define FRT_HAS_ISO_VARARGS
|
34
40
|
#define FRT_HAS_VARARGS
|
35
41
|
#endif
|
36
42
|
|
37
|
-
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
43
|
+
#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && !defined(__cplusplus)
|
38
44
|
#define FRT_HAS_GNUC_VARARGS
|
39
45
|
#define FRT_HAS_VARARGS
|
40
46
|
#endif
|
41
47
|
|
48
|
+
#ifdef __cplusplus
|
49
|
+
} // extern "C"
|
50
|
+
#endif
|
51
|
+
|
42
52
|
#endif
|
data/ext/document.c
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
#include "document.h"
|
2
|
+
#include "symbol.h"
|
2
3
|
#include <string.h>
|
4
|
+
#include "internal.h"
|
3
5
|
|
4
6
|
/****************************************************************************
|
5
7
|
*
|
@@ -7,10 +9,10 @@
|
|
7
9
|
*
|
8
10
|
****************************************************************************/
|
9
11
|
|
10
|
-
DocField *df_new(
|
12
|
+
DocField *df_new(Symbol name)
|
11
13
|
{
|
12
14
|
DocField *df = ALLOC(DocField);
|
13
|
-
df->name =
|
15
|
+
df->name = name;
|
14
16
|
df->size = 0;
|
15
17
|
df->capa = DF_INIT_CAPA;
|
16
18
|
df->data = ALLOC_N(char *, df->capa);
|
@@ -48,44 +50,45 @@ void df_destroy(DocField *df)
|
|
48
50
|
}
|
49
51
|
free(df->data);
|
50
52
|
free(df->lengths);
|
51
|
-
free(df->name);
|
52
53
|
free(df);
|
53
54
|
}
|
54
55
|
|
56
|
+
/*
|
57
|
+
* Format for one item is: name: "data"
|
58
|
+
* for more items : name: ["data", "data", "data"]
|
59
|
+
*/
|
55
60
|
char *df_to_s(DocField *df)
|
56
61
|
{
|
57
|
-
|
58
|
-
|
62
|
+
#define APPEND(dst, src) ((dst)[0] = (src)[0], 1)
|
63
|
+
#define APPEND2(dst, src) (APPEND(dst, src), APPEND(dst+1, src+1), 2)
|
64
|
+
|
65
|
+
int i, len = 0, namelen = sym_len(df->name);
|
59
66
|
char *str, *s;
|
60
67
|
for (i = 0; i < df->size; i++) {
|
61
|
-
len += df->lengths[i] +
|
68
|
+
len += df->lengths[i] + 4;
|
62
69
|
}
|
63
|
-
s = str = ALLOC_N(char, len);
|
64
|
-
|
65
|
-
s +=
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
s +=
|
70
|
-
*(s++) = '"';
|
71
|
-
*(s++) = '\0';
|
70
|
+
s = str = ALLOC_N(char, namelen + len + 5);
|
71
|
+
memcpy(s, df->name, namelen);
|
72
|
+
s += namelen;
|
73
|
+
s += APPEND2(s, ": ");
|
74
|
+
|
75
|
+
if (df->size > 1) {
|
76
|
+
s += APPEND(s, "[");
|
72
77
|
}
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
strncpy(s, df->data[0], df->lengths[0]);
|
77
|
-
s += df->lengths[0];
|
78
|
-
*(s++) = '"';
|
79
|
-
for (i = 1; i < df->size; i++) {
|
80
|
-
*(s++) = ',';
|
81
|
-
*(s++) = ' ';
|
82
|
-
*(s++) = '"';
|
83
|
-
strncpy(s, df->data[i], df->lengths[i]);
|
84
|
-
s += df->lengths[i];
|
85
|
-
*(s++) = '"';
|
78
|
+
for (i = 0; i < df->size; i++) {
|
79
|
+
if (i != 0) {
|
80
|
+
s += APPEND2(s, ", ");
|
86
81
|
}
|
87
|
-
|
82
|
+
s += APPEND(s, "\"");
|
83
|
+
memcpy(s, df->data[i], df->lengths[i]);
|
84
|
+
s += df->lengths[i];
|
85
|
+
s += APPEND(s, "\"");
|
88
86
|
}
|
87
|
+
|
88
|
+
if (df->size > 1) {
|
89
|
+
s += APPEND(s, "]");
|
90
|
+
}
|
91
|
+
*s = 0;
|
89
92
|
return str;
|
90
93
|
}
|
91
94
|
|
@@ -98,7 +101,7 @@ char *df_to_s(DocField *df)
|
|
98
101
|
Document *doc_new()
|
99
102
|
{
|
100
103
|
Document *doc = ALLOC(Document);
|
101
|
-
doc->field_dict =
|
104
|
+
doc->field_dict = h_new_ptr((free_ft)&df_destroy);
|
102
105
|
doc->size = 0;
|
103
106
|
doc->capa = DOC_INIT_CAPA;
|
104
107
|
doc->fields = ALLOC_N(DocField *, doc->capa);
|
@@ -110,7 +113,7 @@ DocField *doc_add_field(Document *doc, DocField *df)
|
|
110
113
|
{
|
111
114
|
if (!h_set_safe(doc->field_dict, df->name, df)) {
|
112
115
|
RAISE(EXCEPTION, "tried to add %s field which alread existed\n",
|
113
|
-
df->name);
|
116
|
+
S(df->name));
|
114
117
|
}
|
115
118
|
if (doc->size >= doc->capa) {
|
116
119
|
doc->capa <<= 1;
|
@@ -121,29 +124,29 @@ DocField *doc_add_field(Document *doc, DocField *df)
|
|
121
124
|
return df;
|
122
125
|
}
|
123
126
|
|
124
|
-
DocField *doc_get_field(Document *doc,
|
127
|
+
DocField *doc_get_field(Document *doc, Symbol name)
|
125
128
|
{
|
126
|
-
return h_get(doc->field_dict, name);
|
129
|
+
return (DocField *)h_get(doc->field_dict, name);
|
127
130
|
}
|
128
131
|
|
129
132
|
char *doc_to_s(Document *doc)
|
130
133
|
{
|
131
134
|
int i;
|
132
|
-
int len =
|
135
|
+
int len = 0;
|
133
136
|
char **fields = ALLOC_N(char *, doc->size);
|
134
137
|
char *buf, *s;
|
138
|
+
|
135
139
|
for (i = 0; i < doc->size; i++) {
|
136
140
|
fields[i] = df_to_s(doc->fields[i]);
|
137
|
-
len += strlen(fields[i]) +
|
141
|
+
len += strlen(fields[i]) + 5;
|
138
142
|
}
|
139
|
-
s = buf = ALLOC_N(char, len);
|
140
|
-
sprintf(buf, "Document [\n");
|
141
|
-
s += strlen(buf);
|
143
|
+
s = buf = ALLOC_N(char, len + 12);
|
144
|
+
s += sprintf(buf, "Document [\n");
|
142
145
|
for (i = 0; i < doc->size; i++) {
|
143
|
-
sprintf(s, " =>%s\n", fields[i]);
|
146
|
+
s += sprintf(s, " =>%s\n", fields[i]);
|
144
147
|
free(fields[i]);
|
145
|
-
s += strlen(s);
|
146
148
|
}
|
149
|
+
free(fields);
|
147
150
|
return buf;
|
148
151
|
}
|
149
152
|
|
data/ext/document.h
CHANGED
@@ -1,53 +1,63 @@
|
|
1
1
|
#ifndef FRT_DOCUMENT_H
|
2
2
|
#define FRT_DOCUMENT_H
|
3
3
|
|
4
|
+
#ifdef __cplusplus
|
5
|
+
extern "C" {
|
6
|
+
#endif
|
7
|
+
|
4
8
|
#include "global.h"
|
9
|
+
#include "symbol.h"
|
5
10
|
#include "hash.h"
|
6
11
|
|
7
12
|
/****************************************************************************
|
8
13
|
*
|
9
|
-
*
|
14
|
+
* FrtDocField
|
10
15
|
*
|
11
16
|
****************************************************************************/
|
12
17
|
|
13
|
-
#define
|
14
|
-
typedef struct
|
18
|
+
#define FRT_DF_INIT_CAPA 1
|
19
|
+
typedef struct FrtDocField
|
15
20
|
{
|
16
|
-
|
21
|
+
FrtSymbol name;
|
17
22
|
int size;
|
18
23
|
int capa;
|
19
24
|
int *lengths;
|
20
25
|
char **data;
|
21
26
|
float boost;
|
22
27
|
bool destroy_data : 1;
|
23
|
-
|
28
|
+
bool is_compressed : 1;
|
29
|
+
} FrtDocField;
|
24
30
|
|
25
|
-
extern
|
26
|
-
extern
|
27
|
-
extern
|
28
|
-
extern void
|
29
|
-
extern char *
|
31
|
+
extern FrtDocField *frt_df_new(FrtSymbol name);
|
32
|
+
extern FrtDocField *frt_df_add_data(FrtDocField *df, char *data);
|
33
|
+
extern FrtDocField *frt_df_add_data_len(FrtDocField *df, char *data, int len);
|
34
|
+
extern void frt_df_destroy(FrtDocField *df);
|
35
|
+
extern char *frt_df_to_s(FrtDocField *df);
|
30
36
|
|
31
37
|
/****************************************************************************
|
32
38
|
*
|
33
|
-
*
|
39
|
+
* FrtDocument
|
34
40
|
*
|
35
41
|
****************************************************************************/
|
36
42
|
|
37
|
-
#define
|
38
|
-
typedef struct
|
43
|
+
#define FRT_DOC_INIT_CAPA 8
|
44
|
+
typedef struct FrtDocument
|
39
45
|
{
|
40
|
-
|
46
|
+
FrtHash *field_dict;
|
41
47
|
int size;
|
42
48
|
int capa;
|
43
|
-
|
49
|
+
FrtDocField **fields;
|
44
50
|
float boost;
|
45
|
-
}
|
51
|
+
} FrtDocument;
|
46
52
|
|
47
|
-
extern
|
48
|
-
extern
|
49
|
-
extern
|
50
|
-
extern char *
|
51
|
-
extern void
|
53
|
+
extern FrtDocument *frt_doc_new();
|
54
|
+
extern FrtDocField *frt_doc_add_field(FrtDocument *doc, FrtDocField *df);
|
55
|
+
extern FrtDocField *frt_doc_get_field(FrtDocument *doc, FrtSymbol name);
|
56
|
+
extern char *frt_doc_to_s(FrtDocument *doc);
|
57
|
+
extern void frt_doc_destroy(FrtDocument *doc);
|
58
|
+
|
59
|
+
#ifdef __cplusplus
|
60
|
+
} // extern "C"
|
61
|
+
#endif
|
52
62
|
|
53
63
|
#endif
|
data/ext/except.c
CHANGED
@@ -2,27 +2,22 @@
|
|
2
2
|
#include "global.h"
|
3
3
|
#include "except.h"
|
4
4
|
#include "threading.h"
|
5
|
+
#include "internal.h"
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
"Unsupported Function Error",
|
21
|
-
"State Error",
|
22
|
-
"Parse Error",
|
23
|
-
"Memory Error",
|
24
|
-
"Index Error",
|
25
|
-
"Lock Error"
|
7
|
+
static const char *const ERROR_TYPES[] = {
|
8
|
+
"Body",
|
9
|
+
"Finally",
|
10
|
+
"Exception",
|
11
|
+
"IO Error",
|
12
|
+
"File Not Found Error",
|
13
|
+
"Argument Error",
|
14
|
+
"End-of-File Error",
|
15
|
+
"Unsupported Function Error",
|
16
|
+
"State Error",
|
17
|
+
"Parse Error",
|
18
|
+
"Memory Error",
|
19
|
+
"Index Error",
|
20
|
+
"Lock Error"
|
26
21
|
};
|
27
22
|
|
28
23
|
char *const UNSUPPORTED_ERROR_MSG = "Unsupported operation";
|
@@ -38,24 +33,11 @@ static void exception_stack_alloc(void)
|
|
38
33
|
thread_key_create(&exception_stack_key, NULL);
|
39
34
|
}
|
40
35
|
|
41
|
-
/*
|
42
|
-
static void put_stack(char *inst, xcontext_t *top)
|
43
|
-
{
|
44
|
-
int x = 10;
|
45
|
-
fprintf(stderr, "( %s )", inst);
|
46
|
-
while (top && x--) {
|
47
|
-
fprintf(stderr, "=> %x ", top);
|
48
|
-
top = top->next;
|
49
|
-
}
|
50
|
-
fprintf(stderr, "\n");
|
51
|
-
}
|
52
|
-
*/
|
53
|
-
|
54
36
|
void xpush_context(xcontext_t *context)
|
55
37
|
{
|
56
38
|
xcontext_t *top_context;
|
57
39
|
thread_once(&exception_stack_key_once, *exception_stack_alloc);
|
58
|
-
top_context = thread_getspecific(exception_stack_key);
|
40
|
+
top_context = (xcontext_t *)thread_getspecific(exception_stack_key);
|
59
41
|
context->next = top_context;
|
60
42
|
thread_setspecific(exception_stack_key, context);
|
61
43
|
context->handled = true;
|
@@ -87,10 +69,10 @@ void xraise(int excode, const char *const msg)
|
|
87
69
|
{
|
88
70
|
xcontext_t *top_context;
|
89
71
|
thread_once(&exception_stack_key_once, *exception_stack_alloc);
|
90
|
-
top_context = thread_getspecific(exception_stack_key);
|
72
|
+
top_context = (xcontext_t *)thread_getspecific(exception_stack_key);
|
91
73
|
|
92
74
|
if (!top_context) {
|
93
|
-
|
75
|
+
XEXIT(ERROR_TYPES[excode], msg);
|
94
76
|
}
|
95
77
|
else if (!top_context->in_finally) {
|
96
78
|
xraise_context(top_context, excode, msg);
|
@@ -106,7 +88,7 @@ void xpop_context()
|
|
106
88
|
{
|
107
89
|
xcontext_t *top_cxt, *context;
|
108
90
|
thread_once(&exception_stack_key_once, *exception_stack_alloc);
|
109
|
-
top_cxt = thread_getspecific(exception_stack_key);
|
91
|
+
top_cxt = (xcontext_t *)thread_getspecific(exception_stack_key);
|
110
92
|
context = top_cxt->next;
|
111
93
|
thread_setspecific(exception_stack_key, context);
|
112
94
|
if (!top_cxt->handled) {
|
@@ -114,7 +96,7 @@ void xpop_context()
|
|
114
96
|
xraise_context(context, top_cxt->excode, top_cxt->msg);
|
115
97
|
}
|
116
98
|
else {
|
117
|
-
|
99
|
+
XEXIT(ERROR_TYPES[top_cxt->excode], top_cxt->msg);
|
118
100
|
}
|
119
101
|
}
|
120
102
|
}
|