isomorfeus-ferret 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +612 -0
- data/README.md +44 -0
- data/ext/isomorfeus_ferret_ext/benchmark.c +223 -0
- data/ext/isomorfeus_ferret_ext/benchmark.h +45 -0
- data/ext/isomorfeus_ferret_ext/benchmarks_all.h +25 -0
- data/ext/isomorfeus_ferret_ext/bm_bitvector.c +123 -0
- data/ext/isomorfeus_ferret_ext/bm_hash.c +118 -0
- data/ext/isomorfeus_ferret_ext/bm_micro_string.c +40 -0
- data/ext/isomorfeus_ferret_ext/bm_store.c +93 -0
- data/ext/isomorfeus_ferret_ext/email.rl +21 -0
- data/ext/isomorfeus_ferret_ext/extconf.rb +5 -0
- data/ext/isomorfeus_ferret_ext/fio_tmpfile.h +53 -0
- data/ext/isomorfeus_ferret_ext/frb_analysis.c +2577 -0
- data/ext/isomorfeus_ferret_ext/frb_index.c +3457 -0
- data/ext/isomorfeus_ferret_ext/frb_lang.c +9 -0
- data/ext/isomorfeus_ferret_ext/frb_lang.h +17 -0
- data/ext/isomorfeus_ferret_ext/frb_qparser.c +629 -0
- data/ext/isomorfeus_ferret_ext/frb_search.c +4460 -0
- data/ext/isomorfeus_ferret_ext/frb_store.c +515 -0
- data/ext/isomorfeus_ferret_ext/frb_threading.h +30 -0
- data/ext/isomorfeus_ferret_ext/frb_utils.c +1127 -0
- data/ext/isomorfeus_ferret_ext/frt_analysis.c +1644 -0
- data/ext/isomorfeus_ferret_ext/frt_analysis.h +247 -0
- data/ext/isomorfeus_ferret_ext/frt_array.c +124 -0
- data/ext/isomorfeus_ferret_ext/frt_array.h +54 -0
- data/ext/isomorfeus_ferret_ext/frt_bitvector.c +95 -0
- data/ext/isomorfeus_ferret_ext/frt_bitvector.h +586 -0
- data/ext/isomorfeus_ferret_ext/frt_compound_io.c +374 -0
- data/ext/isomorfeus_ferret_ext/frt_config.h +44 -0
- data/ext/isomorfeus_ferret_ext/frt_document.c +134 -0
- data/ext/isomorfeus_ferret_ext/frt_document.h +52 -0
- data/ext/isomorfeus_ferret_ext/frt_except.c +95 -0
- data/ext/isomorfeus_ferret_ext/frt_except.h +188 -0
- data/ext/isomorfeus_ferret_ext/frt_field_index.c +233 -0
- data/ext/isomorfeus_ferret_ext/frt_field_index.h +42 -0
- data/ext/isomorfeus_ferret_ext/frt_filter.c +157 -0
- data/ext/isomorfeus_ferret_ext/frt_fs_store.c +502 -0
- data/ext/isomorfeus_ferret_ext/frt_global.c +427 -0
- data/ext/isomorfeus_ferret_ext/frt_global.h +290 -0
- data/ext/isomorfeus_ferret_ext/frt_hash.c +518 -0
- data/ext/isomorfeus_ferret_ext/frt_hash.h +466 -0
- data/ext/isomorfeus_ferret_ext/frt_hashset.c +191 -0
- data/ext/isomorfeus_ferret_ext/frt_hashset.h +206 -0
- data/ext/isomorfeus_ferret_ext/frt_helper.c +62 -0
- data/ext/isomorfeus_ferret_ext/frt_helper.h +13 -0
- data/ext/isomorfeus_ferret_ext/frt_ind.c +353 -0
- data/ext/isomorfeus_ferret_ext/frt_ind.h +54 -0
- data/ext/isomorfeus_ferret_ext/frt_index.c +6377 -0
- data/ext/isomorfeus_ferret_ext/frt_index.h +880 -0
- data/ext/isomorfeus_ferret_ext/frt_lang.c +104 -0
- data/ext/isomorfeus_ferret_ext/frt_lang.h +44 -0
- data/ext/isomorfeus_ferret_ext/frt_mempool.c +87 -0
- data/ext/isomorfeus_ferret_ext/frt_mempool.h +33 -0
- data/ext/isomorfeus_ferret_ext/frt_multimapper.c +349 -0
- data/ext/isomorfeus_ferret_ext/frt_multimapper.h +52 -0
- data/ext/isomorfeus_ferret_ext/frt_posh.c +1006 -0
- data/ext/isomorfeus_ferret_ext/frt_posh.h +973 -0
- data/ext/isomorfeus_ferret_ext/frt_priorityqueue.c +147 -0
- data/ext/isomorfeus_ferret_ext/frt_priorityqueue.h +147 -0
- data/ext/isomorfeus_ferret_ext/frt_q_boolean.c +1612 -0
- data/ext/isomorfeus_ferret_ext/frt_q_const_score.c +157 -0
- data/ext/isomorfeus_ferret_ext/frt_q_filtered_query.c +209 -0
- data/ext/isomorfeus_ferret_ext/frt_q_fuzzy.c +281 -0
- data/ext/isomorfeus_ferret_ext/frt_q_match_all.c +147 -0
- data/ext/isomorfeus_ferret_ext/frt_q_multi_term.c +672 -0
- data/ext/isomorfeus_ferret_ext/frt_q_parser.c +3084 -0
- data/ext/isomorfeus_ferret_ext/frt_q_phrase.c +1182 -0
- data/ext/isomorfeus_ferret_ext/frt_q_prefix.c +98 -0
- data/ext/isomorfeus_ferret_ext/frt_q_range.c +665 -0
- data/ext/isomorfeus_ferret_ext/frt_q_span.c +2386 -0
- data/ext/isomorfeus_ferret_ext/frt_q_term.c +311 -0
- data/ext/isomorfeus_ferret_ext/frt_q_wildcard.c +166 -0
- data/ext/isomorfeus_ferret_ext/frt_ram_store.c +460 -0
- data/ext/isomorfeus_ferret_ext/frt_scanner.c +899 -0
- data/ext/isomorfeus_ferret_ext/frt_scanner.h +28 -0
- data/ext/isomorfeus_ferret_ext/frt_scanner_mb.c +6705 -0
- data/ext/isomorfeus_ferret_ext/frt_scanner_utf8.c +4419 -0
- data/ext/isomorfeus_ferret_ext/frt_search.c +1824 -0
- data/ext/isomorfeus_ferret_ext/frt_search.h +924 -0
- data/ext/isomorfeus_ferret_ext/frt_similarity.c +150 -0
- data/ext/isomorfeus_ferret_ext/frt_similarity.h +79 -0
- data/ext/isomorfeus_ferret_ext/frt_sort.c +796 -0
- data/ext/isomorfeus_ferret_ext/frt_stopwords.c +395 -0
- data/ext/isomorfeus_ferret_ext/frt_store.c +680 -0
- data/ext/isomorfeus_ferret_ext/frt_store.h +789 -0
- data/ext/isomorfeus_ferret_ext/frt_term_vectors.c +72 -0
- data/ext/isomorfeus_ferret_ext/frt_threading.h +23 -0
- data/ext/isomorfeus_ferret_ext/frt_win32.h +54 -0
- data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.c +409 -0
- data/ext/isomorfeus_ferret_ext/isomorfeus_ferret.h +95 -0
- data/ext/isomorfeus_ferret_ext/libstemmer.c +93 -0
- data/ext/isomorfeus_ferret_ext/libstemmer.h +73 -0
- data/ext/isomorfeus_ferret_ext/q_parser.y +1366 -0
- data/ext/isomorfeus_ferret_ext/scanner.h +28 -0
- data/ext/isomorfeus_ferret_ext/scanner.in +43 -0
- data/ext/isomorfeus_ferret_ext/scanner.rl +84 -0
- data/ext/isomorfeus_ferret_ext/scanner_mb.rl +200 -0
- data/ext/isomorfeus_ferret_ext/scanner_utf8.rl +85 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_danish.c +324 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_danish.h +7 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_dutch.c +610 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_dutch.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_english.c +1104 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_english.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_finnish.c +749 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_finnish.h +7 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_french.c +1233 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_french.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_german.c +490 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_german.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_hungarian.c +1217 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_hungarian.h +7 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_italian.c +1052 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_italian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_norwegian.c +283 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_norwegian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_porter.c +735 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_porter.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_portuguese.c +1003 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_portuguese.h +7 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_spanish.c +1079 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_spanish.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_swedish.c +293 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_1_swedish.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_romanian.c +984 -0
- data/ext/isomorfeus_ferret_ext/stem_ISO_8859_2_romanian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_KOI8_R_russian.c +686 -0
- data/ext/isomorfeus_ferret_ext/stem_KOI8_R_russian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_danish.c +325 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_danish.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_dutch.c +620 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_dutch.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_english.c +1111 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_english.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_finnish.c +754 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_finnish.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_french.c +1242 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_french.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_german.c +495 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_german.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_hungarian.c +1220 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_hungarian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_italian.c +1059 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_italian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_norwegian.c +285 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_norwegian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_porter.c +741 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_porter.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_portuguese.c +1009 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_portuguese.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_romanian.c +990 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_romanian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_russian.c +680 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_russian.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_spanish.c +1083 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_spanish.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_swedish.c +294 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_swedish.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_turkish.c +2191 -0
- data/ext/isomorfeus_ferret_ext/stem_UTF_8_turkish.h +6 -0
- data/ext/isomorfeus_ferret_ext/stem_api.c +66 -0
- data/ext/isomorfeus_ferret_ext/stem_api.h +26 -0
- data/ext/isomorfeus_ferret_ext/stem_header.h +57 -0
- data/ext/isomorfeus_ferret_ext/stem_modules.h +190 -0
- data/ext/isomorfeus_ferret_ext/stem_modules.txt +50 -0
- data/ext/isomorfeus_ferret_ext/stem_utilities.c +478 -0
- data/ext/isomorfeus_ferret_ext/test.c +850 -0
- data/ext/isomorfeus_ferret_ext/test.h +416 -0
- data/ext/isomorfeus_ferret_ext/test_1710.c +63 -0
- data/ext/isomorfeus_ferret_ext/test_analysis.c +1221 -0
- data/ext/isomorfeus_ferret_ext/test_array.c +272 -0
- data/ext/isomorfeus_ferret_ext/test_bitvector.c +600 -0
- data/ext/isomorfeus_ferret_ext/test_compound_io.c +170 -0
- data/ext/isomorfeus_ferret_ext/test_document.c +156 -0
- data/ext/isomorfeus_ferret_ext/test_except.c +244 -0
- data/ext/isomorfeus_ferret_ext/test_fields.c +522 -0
- data/ext/isomorfeus_ferret_ext/test_file_deleter.c +185 -0
- data/ext/isomorfeus_ferret_ext/test_filter.c +331 -0
- data/ext/isomorfeus_ferret_ext/test_fs_store.c +25 -0
- data/ext/isomorfeus_ferret_ext/test_global.c +299 -0
- data/ext/isomorfeus_ferret_ext/test_hash.c +485 -0
- data/ext/isomorfeus_ferret_ext/test_hashset.c +288 -0
- data/ext/isomorfeus_ferret_ext/test_helper.c +47 -0
- data/ext/isomorfeus_ferret_ext/test_highlighter.c +548 -0
- data/ext/isomorfeus_ferret_ext/test_index.c +2323 -0
- data/ext/isomorfeus_ferret_ext/test_lang.c +74 -0
- data/ext/isomorfeus_ferret_ext/test_mempool.c +102 -0
- data/ext/isomorfeus_ferret_ext/test_multimapper.c +64 -0
- data/ext/isomorfeus_ferret_ext/test_priorityqueue.c +213 -0
- data/ext/isomorfeus_ferret_ext/test_q_const_score.c +84 -0
- data/ext/isomorfeus_ferret_ext/test_q_filtered.c +61 -0
- data/ext/isomorfeus_ferret_ext/test_q_fuzzy.c +241 -0
- data/ext/isomorfeus_ferret_ext/test_q_parser.c +464 -0
- data/ext/isomorfeus_ferret_ext/test_q_span.c +575 -0
- data/ext/isomorfeus_ferret_ext/test_ram_store.c +77 -0
- data/ext/isomorfeus_ferret_ext/test_search.c +1874 -0
- data/ext/isomorfeus_ferret_ext/test_segments.c +167 -0
- data/ext/isomorfeus_ferret_ext/test_similarity.c +25 -0
- data/ext/isomorfeus_ferret_ext/test_sort.c +333 -0
- data/ext/isomorfeus_ferret_ext/test_store.c +591 -0
- data/ext/isomorfeus_ferret_ext/test_store.h +3 -0
- data/ext/isomorfeus_ferret_ext/test_term.c +351 -0
- data/ext/isomorfeus_ferret_ext/test_term_vectors.c +373 -0
- data/ext/isomorfeus_ferret_ext/test_test.c +83 -0
- data/ext/isomorfeus_ferret_ext/test_threading.c +188 -0
- data/ext/isomorfeus_ferret_ext/testhelper.c +561 -0
- data/ext/isomorfeus_ferret_ext/testhelper.h +25 -0
- data/ext/isomorfeus_ferret_ext/tests_all.h +87 -0
- data/ext/isomorfeus_ferret_ext/uchar-ucs4.rl +1854 -0
- data/ext/isomorfeus_ferret_ext/uchar-utf8.rl +1999 -0
- data/ext/isomorfeus_ferret_ext/url.rl +27 -0
- data/ext/isomorfeus_ferret_ext/word_list.h +15156 -0
- data/lib/isomorfeus/ferret/document.rb +132 -0
- data/lib/isomorfeus/ferret/field_symbol.rb +85 -0
- data/lib/isomorfeus/ferret/index/field_infos.rb +48 -0
- data/lib/isomorfeus/ferret/index/index.rb +970 -0
- data/lib/isomorfeus/ferret/monitor.rb +323 -0
- data/lib/isomorfeus/ferret/stdlib_patches.rb +151 -0
- data/lib/isomorfeus/ferret/version.rb +5 -0
- data/lib/isomorfeus-ferret.rb +8 -0
- metadata +307 -0
@@ -0,0 +1,374 @@
|
|
1
|
+
#include "frt_index.h"
|
2
|
+
#include "frt_array.h"
|
3
|
+
|
4
|
+
extern void frt_store_destroy(FrtStore *store);
|
5
|
+
extern FrtInStream *frt_is_new();
|
6
|
+
extern FrtStore *frt_store_new();
|
7
|
+
|
8
|
+
/****************************************************************************
|
9
|
+
*
|
10
|
+
* CompoundStore
|
11
|
+
*
|
12
|
+
****************************************************************************/
|
13
|
+
|
14
|
+
typedef struct FileEntry {
|
15
|
+
off_t offset;
|
16
|
+
off_t length;
|
17
|
+
} FileEntry;
|
18
|
+
|
19
|
+
static void cmpd_touch(FrtStore *store, const char *file_name)
|
20
|
+
{
|
21
|
+
store->dir.cmpd->store->touch(store->dir.cmpd->store, file_name);
|
22
|
+
}
|
23
|
+
|
24
|
+
static int cmpd_exists(FrtStore *store, const char *file_name)
|
25
|
+
{
|
26
|
+
if (frt_h_get(store->dir.cmpd->entries, file_name) != NULL) {
|
27
|
+
return true;
|
28
|
+
}
|
29
|
+
else {
|
30
|
+
return false;
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
static int cmpd_remove(FrtStore *store, const char *file_name)
|
35
|
+
{
|
36
|
+
(void)store;
|
37
|
+
(void)file_name;
|
38
|
+
FRT_RAISE(FRT_UNSUPPORTED_ERROR, "%s", FRT_UNSUPPORTED_ERROR_MSG);
|
39
|
+
return 0;
|
40
|
+
}
|
41
|
+
|
42
|
+
static void cmpd_rename(FrtStore *store, const char *from, const char *to)
|
43
|
+
{
|
44
|
+
(void)store;
|
45
|
+
(void)from;
|
46
|
+
(void)to;
|
47
|
+
FRT_RAISE(FRT_UNSUPPORTED_ERROR, "%s", FRT_UNSUPPORTED_ERROR_MSG);
|
48
|
+
}
|
49
|
+
|
50
|
+
static int cmpd_count(FrtStore *store)
|
51
|
+
{
|
52
|
+
return store->dir.cmpd->entries->size;
|
53
|
+
}
|
54
|
+
|
55
|
+
static void cmpd_each(FrtStore *store,
|
56
|
+
void (*func)(const char *fname, void *arg), void *arg)
|
57
|
+
{
|
58
|
+
FrtHash *ht = store->dir.cmpd->entries;
|
59
|
+
int i;
|
60
|
+
for (i = 0; i <= ht->mask; i++) {
|
61
|
+
char *fn = (char *)ht->table[i].key;
|
62
|
+
if (fn) {
|
63
|
+
func(fn, arg);
|
64
|
+
}
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
|
69
|
+
static void cmpd_clear(FrtStore *store)
|
70
|
+
{
|
71
|
+
(void)store;
|
72
|
+
FRT_RAISE(FRT_UNSUPPORTED_ERROR, "%s", FRT_UNSUPPORTED_ERROR_MSG);
|
73
|
+
}
|
74
|
+
|
75
|
+
static void cmpd_close_i(FrtStore *store)
|
76
|
+
{
|
77
|
+
FrtCompoundStore *cmpd = store->dir.cmpd;
|
78
|
+
if (cmpd->stream == NULL) {
|
79
|
+
FRT_RAISE(FRT_IO_ERROR, "Tried to close already closed compound store");
|
80
|
+
}
|
81
|
+
|
82
|
+
frt_h_destroy(cmpd->entries);
|
83
|
+
|
84
|
+
frt_is_close(cmpd->stream);
|
85
|
+
cmpd->stream = NULL;
|
86
|
+
free(store->dir.cmpd);
|
87
|
+
frt_store_destroy(store);
|
88
|
+
}
|
89
|
+
|
90
|
+
static off_t cmpd_length(FrtStore *store, const char *file_name)
|
91
|
+
{
|
92
|
+
FileEntry *fe = (FileEntry *)frt_h_get(store->dir.cmpd->entries, file_name);
|
93
|
+
if (fe != NULL) {
|
94
|
+
return fe->length;
|
95
|
+
}
|
96
|
+
else {
|
97
|
+
return 0;
|
98
|
+
}
|
99
|
+
}
|
100
|
+
|
101
|
+
static void cmpdi_seek_i(FrtInStream *is, off_t pos)
|
102
|
+
{
|
103
|
+
(void)is;
|
104
|
+
(void)pos;
|
105
|
+
}
|
106
|
+
|
107
|
+
static void cmpdi_close_i(FrtInStream *is)
|
108
|
+
{
|
109
|
+
free(is->d.cis);
|
110
|
+
}
|
111
|
+
|
112
|
+
static off_t cmpdi_length_i(FrtInStream *is)
|
113
|
+
{
|
114
|
+
return (is->d.cis->length);
|
115
|
+
}
|
116
|
+
|
117
|
+
/*
|
118
|
+
* raises: FRT_EOF_ERROR
|
119
|
+
*/
|
120
|
+
static void cmpdi_read_i(FrtInStream *is, frt_uchar *b, int len)
|
121
|
+
{
|
122
|
+
FrtCompoundInStream *cis = is->d.cis;
|
123
|
+
off_t start = frt_is_pos(is);
|
124
|
+
|
125
|
+
if ((start + len) > cis->length) {
|
126
|
+
FRT_RAISE(FRT_EOF_ERROR, "Tried to read past end of file. File length is "
|
127
|
+
"<%"FRT_OFF_T_PFX"d> and tried to read to <%"FRT_OFF_T_PFX"d>",
|
128
|
+
cis->length, start + len);
|
129
|
+
}
|
130
|
+
|
131
|
+
frt_is_seek(cis->sub, cis->offset + start);
|
132
|
+
frt_is_read_bytes(cis->sub, b, len);
|
133
|
+
}
|
134
|
+
|
135
|
+
static const struct FrtInStreamMethods CMPD_IN_STREAM_METHODS = {
|
136
|
+
cmpdi_read_i,
|
137
|
+
cmpdi_seek_i,
|
138
|
+
cmpdi_length_i,
|
139
|
+
cmpdi_close_i
|
140
|
+
};
|
141
|
+
|
142
|
+
static FrtInStream *cmpd_create_input(FrtInStream *sub_is, off_t offset, off_t length)
|
143
|
+
{
|
144
|
+
FrtInStream *is = frt_is_new();
|
145
|
+
FrtCompoundInStream *cis = FRT_ALLOC(FrtCompoundInStream);
|
146
|
+
|
147
|
+
cis->sub = sub_is;
|
148
|
+
cis->offset = offset;
|
149
|
+
cis->length = length;
|
150
|
+
is->d.cis = cis;
|
151
|
+
is->m = &CMPD_IN_STREAM_METHODS;
|
152
|
+
|
153
|
+
return is;
|
154
|
+
}
|
155
|
+
|
156
|
+
static FrtInStream *cmpd_open_input(FrtStore *store, const char *file_name)
|
157
|
+
{
|
158
|
+
FileEntry *entry;
|
159
|
+
FrtCompoundStore *cmpd = store->dir.cmpd;
|
160
|
+
FrtInStream *is;
|
161
|
+
|
162
|
+
frt_mutex_lock(&store->mutex);
|
163
|
+
if (cmpd->stream == NULL) {
|
164
|
+
frt_mutex_unlock(&store->mutex);
|
165
|
+
FRT_RAISE(FRT_IO_ERROR, "Can't open compound file input stream. Parent "
|
166
|
+
"stream is closed.");
|
167
|
+
}
|
168
|
+
|
169
|
+
entry = (FileEntry *)frt_h_get(cmpd->entries, file_name);
|
170
|
+
if (entry == NULL) {
|
171
|
+
frt_mutex_unlock(&store->mutex);
|
172
|
+
FRT_RAISE(FRT_IO_ERROR, "File %s does not exist: ", file_name);
|
173
|
+
}
|
174
|
+
|
175
|
+
is = cmpd_create_input(cmpd->stream, entry->offset, entry->length);
|
176
|
+
frt_mutex_unlock(&store->mutex);
|
177
|
+
|
178
|
+
return is;
|
179
|
+
}
|
180
|
+
|
181
|
+
static FrtOutStream *cmpd_new_output(FrtStore *store, const char *file_name)
|
182
|
+
{
|
183
|
+
(void)store;
|
184
|
+
(void)file_name;
|
185
|
+
FRT_RAISE(FRT_UNSUPPORTED_ERROR, "%s", FRT_UNSUPPORTED_ERROR_MSG);
|
186
|
+
return NULL;
|
187
|
+
}
|
188
|
+
|
189
|
+
static FrtLock *cmpd_open_lock_i(FrtStore *store, const char *lock_name)
|
190
|
+
{
|
191
|
+
(void)store;
|
192
|
+
(void)lock_name;
|
193
|
+
FRT_RAISE(FRT_UNSUPPORTED_ERROR, "%s", FRT_UNSUPPORTED_ERROR_MSG);
|
194
|
+
return NULL;
|
195
|
+
}
|
196
|
+
|
197
|
+
static void cmpd_close_lock_i(FrtLock *lock)
|
198
|
+
{
|
199
|
+
(void)lock;
|
200
|
+
FRT_RAISE(FRT_UNSUPPORTED_ERROR, "%s", FRT_UNSUPPORTED_ERROR_MSG);
|
201
|
+
}
|
202
|
+
|
203
|
+
FrtStore *frt_open_cmpd_store(FrtStore *store, const char *name)
|
204
|
+
{
|
205
|
+
int count, i;
|
206
|
+
off_t offset;
|
207
|
+
char *fname;
|
208
|
+
FileEntry *volatile entry = NULL;
|
209
|
+
FrtStore *new_store = NULL;
|
210
|
+
FrtCompoundStore *volatile cmpd = NULL;
|
211
|
+
FrtInStream *volatile is = NULL;
|
212
|
+
|
213
|
+
FRT_TRY
|
214
|
+
cmpd = FRT_ALLOC_AND_ZERO(FrtCompoundStore);
|
215
|
+
|
216
|
+
cmpd->store = store;
|
217
|
+
cmpd->name = name;
|
218
|
+
cmpd->entries = frt_h_new_str(&free, &free);
|
219
|
+
is = cmpd->stream = store->open_input(store, cmpd->name);
|
220
|
+
|
221
|
+
/* read the directory and init files */
|
222
|
+
count = frt_is_read_vint(is);
|
223
|
+
entry = NULL;
|
224
|
+
for (i = 0; i < count; i++) {
|
225
|
+
offset = (off_t)frt_is_read_i64(is);
|
226
|
+
fname = frt_is_read_string(is);
|
227
|
+
|
228
|
+
if (entry != NULL) {
|
229
|
+
/* set length of the previous entry */
|
230
|
+
entry->length = offset - entry->offset;
|
231
|
+
}
|
232
|
+
|
233
|
+
entry = FRT_ALLOC(FileEntry);
|
234
|
+
entry->offset = offset;
|
235
|
+
frt_h_set(cmpd->entries, fname, entry);
|
236
|
+
}
|
237
|
+
FRT_XCATCHALL
|
238
|
+
if (is) frt_is_close(is);
|
239
|
+
if (cmpd->entries) frt_h_destroy(cmpd->entries);
|
240
|
+
free(cmpd);
|
241
|
+
FRT_XENDTRY
|
242
|
+
|
243
|
+
/* set the length of the final entry */
|
244
|
+
if (entry != NULL) {
|
245
|
+
entry->length = frt_is_length(is) - entry->offset;
|
246
|
+
}
|
247
|
+
|
248
|
+
new_store = frt_store_new();
|
249
|
+
new_store->dir.cmpd = cmpd;
|
250
|
+
new_store->touch = &cmpd_touch;
|
251
|
+
new_store->exists = &cmpd_exists;
|
252
|
+
new_store->remove = &cmpd_remove;
|
253
|
+
new_store->rename = &cmpd_rename;
|
254
|
+
new_store->count = &cmpd_count;
|
255
|
+
new_store->clear = &cmpd_clear;
|
256
|
+
new_store->length = &cmpd_length;
|
257
|
+
new_store->each = &cmpd_each;
|
258
|
+
new_store->close_i = &cmpd_close_i;
|
259
|
+
new_store->new_output = &cmpd_new_output;
|
260
|
+
new_store->open_input = &cmpd_open_input;
|
261
|
+
new_store->open_lock_i = &cmpd_open_lock_i;
|
262
|
+
new_store->close_lock_i = &cmpd_close_lock_i;
|
263
|
+
|
264
|
+
return new_store;
|
265
|
+
}
|
266
|
+
|
267
|
+
/****************************************************************************
|
268
|
+
*
|
269
|
+
* CompoundWriter
|
270
|
+
*
|
271
|
+
****************************************************************************/
|
272
|
+
|
273
|
+
FrtCompoundWriter *frt_open_cw(FrtStore *store, char *name)
|
274
|
+
{
|
275
|
+
FrtCompoundWriter *cw = FRT_ALLOC(FrtCompoundWriter);
|
276
|
+
cw->store = store;
|
277
|
+
cw->name = name;
|
278
|
+
cw->ids = frt_hs_new_str(&free);
|
279
|
+
cw->file_entries = frt_ary_new_type_capa(FrtCWFileEntry, FRT_CW_INIT_CAPA);
|
280
|
+
return cw;
|
281
|
+
}
|
282
|
+
|
283
|
+
void frt_cw_add_file(FrtCompoundWriter *cw, char *id)
|
284
|
+
{
|
285
|
+
id = frt_estrdup(id);
|
286
|
+
if (frt_hs_add(cw->ids, id) != FRT_HASH_KEY_DOES_NOT_EXIST) {
|
287
|
+
FRT_RAISE(FRT_IO_ERROR, "Tried to add file \"%s\" which has already been "
|
288
|
+
"added to the compound store", id);
|
289
|
+
}
|
290
|
+
|
291
|
+
frt_ary_grow(cw->file_entries);
|
292
|
+
frt_ary_last(cw->file_entries).name = id;
|
293
|
+
}
|
294
|
+
|
295
|
+
static void cw_copy_file(FrtCompoundWriter *cw, FrtCWFileEntry *src, FrtOutStream *os)
|
296
|
+
{
|
297
|
+
off_t start_ptr = frt_os_pos(os);
|
298
|
+
off_t end_ptr;
|
299
|
+
off_t remainder, length, len;
|
300
|
+
frt_uchar buffer[FRT_BUFFER_SIZE];
|
301
|
+
|
302
|
+
FrtInStream *is = cw->store->open_input(cw->store, src->name);
|
303
|
+
|
304
|
+
remainder = length = frt_is_length(is);
|
305
|
+
|
306
|
+
while (remainder > 0) {
|
307
|
+
len = FRT_MIN(remainder, FRT_BUFFER_SIZE);
|
308
|
+
frt_is_read_bytes(is, buffer, len);
|
309
|
+
frt_os_write_bytes(os, buffer, len);
|
310
|
+
remainder -= len;
|
311
|
+
}
|
312
|
+
|
313
|
+
/* Verify that remainder is 0 */
|
314
|
+
if (remainder != 0) {
|
315
|
+
FRT_RAISE(FRT_IO_ERROR, "There seems to be an error in the compound file "
|
316
|
+
"should have read to the end but there are <%"FRT_OFF_T_PFX"d> "
|
317
|
+
"bytes left", remainder);
|
318
|
+
}
|
319
|
+
|
320
|
+
/* Verify that the output length diff is equal to original file */
|
321
|
+
end_ptr = frt_os_pos(os);
|
322
|
+
len = end_ptr - start_ptr;
|
323
|
+
if (len != length) {
|
324
|
+
FRT_RAISE(FRT_IO_ERROR, "Difference in compound file output file offsets "
|
325
|
+
"<%"FRT_OFF_T_PFX"d> does not match the original file lenght "
|
326
|
+
"<%"FRT_OFF_T_PFX"d>", len, length);
|
327
|
+
}
|
328
|
+
|
329
|
+
frt_is_close(is);
|
330
|
+
}
|
331
|
+
|
332
|
+
void frt_cw_close(FrtCompoundWriter *cw)
|
333
|
+
{
|
334
|
+
FrtOutStream *os = NULL;
|
335
|
+
int i;
|
336
|
+
|
337
|
+
if (cw->ids->size <= 0) {
|
338
|
+
FRT_RAISE(FRT_STATE_ERROR, "Tried to merge compound file with no entries");
|
339
|
+
}
|
340
|
+
|
341
|
+
os = cw->store->new_output(cw->store, cw->name);
|
342
|
+
|
343
|
+
frt_os_write_vint(os, frt_ary_size(cw->file_entries));
|
344
|
+
|
345
|
+
/* Write the directory with all offsets at 0.
|
346
|
+
* Remember the positions of directory entries so that we can adjust the
|
347
|
+
* offsets later */
|
348
|
+
for (i = 0; i < frt_ary_size(cw->file_entries); i++) {
|
349
|
+
cw->file_entries[i].dir_offset = frt_os_pos(os);
|
350
|
+
frt_os_write_u64(os, 0); /* for now */
|
351
|
+
frt_os_write_string(os, cw->file_entries[i].name);
|
352
|
+
}
|
353
|
+
|
354
|
+
/* Open the files and copy their data into the stream. Remember the
|
355
|
+
* locations of each file's data section. */
|
356
|
+
for (i = 0; i < frt_ary_size(cw->file_entries); i++) {
|
357
|
+
cw->file_entries[i].data_offset = frt_os_pos(os);
|
358
|
+
cw_copy_file(cw, &cw->file_entries[i], os);
|
359
|
+
}
|
360
|
+
|
361
|
+
/* Write the data offsets into the directory of the compound stream */
|
362
|
+
for (i = 0; i < frt_ary_size(cw->file_entries); i++) {
|
363
|
+
frt_os_seek(os, cw->file_entries[i].dir_offset);
|
364
|
+
frt_os_write_u64(os, cw->file_entries[i].data_offset);
|
365
|
+
}
|
366
|
+
|
367
|
+
if (os) {
|
368
|
+
frt_os_close(os);
|
369
|
+
}
|
370
|
+
|
371
|
+
frt_hs_destroy(cw->ids);
|
372
|
+
frt_ary_free(cw->file_entries);
|
373
|
+
free(cw);
|
374
|
+
}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
#ifndef FRT_DEFINES_H
|
2
|
+
#define FRT_DEFINES_H
|
3
|
+
|
4
|
+
#include <sys/types.h>
|
5
|
+
#include <limits.h>
|
6
|
+
#include "frt_posh.h"
|
7
|
+
|
8
|
+
#ifndef false
|
9
|
+
#define false 0
|
10
|
+
#endif
|
11
|
+
#ifndef true
|
12
|
+
#define true 1
|
13
|
+
#endif
|
14
|
+
|
15
|
+
#ifndef bool
|
16
|
+
typedef unsigned int bool;
|
17
|
+
#endif
|
18
|
+
typedef unsigned char frt_uchar;
|
19
|
+
|
20
|
+
typedef posh_u16_t frt_u16;
|
21
|
+
typedef posh_i16_t frt_i16;
|
22
|
+
typedef posh_u32_t frt_u32;
|
23
|
+
typedef posh_i32_t frt_i32;
|
24
|
+
typedef posh_u64_t frt_u64;
|
25
|
+
typedef posh_i64_t frt_i64;
|
26
|
+
|
27
|
+
#if ( LONG_MAX == 2147483647 ) && defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64)
|
28
|
+
#define FRT_OFF_T_PFX "ll"
|
29
|
+
#else
|
30
|
+
#define FRT_OFF_T_PFX "l"
|
31
|
+
#endif
|
32
|
+
|
33
|
+
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(__cplusplus)
|
34
|
+
#define FRT_IS_C99
|
35
|
+
#define FRT_HAS_ISO_VARARGS
|
36
|
+
#define FRT_HAS_VARARGS
|
37
|
+
#endif
|
38
|
+
|
39
|
+
#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && !defined(__cplusplus)
|
40
|
+
#define FRT_HAS_GNUC_VARARGS
|
41
|
+
#define FRT_HAS_VARARGS
|
42
|
+
#endif
|
43
|
+
|
44
|
+
#endif
|
@@ -0,0 +1,134 @@
|
|
1
|
+
#include "frt_document.h"
|
2
|
+
#include <string.h>
|
3
|
+
|
4
|
+
/****************************************************************************
|
5
|
+
*
|
6
|
+
* FrtDocField
|
7
|
+
*
|
8
|
+
****************************************************************************/
|
9
|
+
|
10
|
+
FrtDocField *frt_df_new(FrtSymbol name)
|
11
|
+
{
|
12
|
+
FrtDocField *df = FRT_ALLOC(FrtDocField);
|
13
|
+
df->name = name;
|
14
|
+
df->size = 0;
|
15
|
+
df->capa = FRT_DF_INIT_CAPA;
|
16
|
+
df->data = FRT_ALLOC_N(char *, df->capa);
|
17
|
+
df->lengths = FRT_ALLOC_N(int, df->capa);
|
18
|
+
df->destroy_data = false;
|
19
|
+
df->boost = 1.0f;
|
20
|
+
return df;
|
21
|
+
}
|
22
|
+
|
23
|
+
FrtDocField *frt_df_add_data_len(FrtDocField *df, char *data, int len)
|
24
|
+
{
|
25
|
+
if (df->size >= df->capa) {
|
26
|
+
df->capa <<= 2;
|
27
|
+
FRT_REALLOC_N(df->data, char *, df->capa);
|
28
|
+
FRT_REALLOC_N(df->lengths, int, df->capa);
|
29
|
+
}
|
30
|
+
df->data[df->size] = data;
|
31
|
+
df->lengths[df->size] = len;
|
32
|
+
df->size++;
|
33
|
+
return df;
|
34
|
+
}
|
35
|
+
|
36
|
+
FrtDocField *frt_df_add_data(FrtDocField *df, char *data)
|
37
|
+
{
|
38
|
+
return frt_df_add_data_len(df, data, strlen(data));
|
39
|
+
}
|
40
|
+
|
41
|
+
void frt_df_destroy(FrtDocField *df)
|
42
|
+
{
|
43
|
+
if (df->destroy_data) {
|
44
|
+
int i;
|
45
|
+
for (i = 0; i < df->size; i++) {
|
46
|
+
free(df->data[i]);
|
47
|
+
}
|
48
|
+
}
|
49
|
+
free(df->data);
|
50
|
+
free(df->lengths);
|
51
|
+
free(df);
|
52
|
+
}
|
53
|
+
|
54
|
+
/*
|
55
|
+
* Format for one item is: name: "data"
|
56
|
+
* for more items : name: ["data", "data", "data"]
|
57
|
+
*/
|
58
|
+
char *frt_df_to_s(FrtDocField *df)
|
59
|
+
{
|
60
|
+
const char *df_name = rb_id2name(df->name);
|
61
|
+
int i, len = 0, namelen = strlen(df_name);
|
62
|
+
char *str, *s;
|
63
|
+
for (i = 0; i < df->size; i++) {
|
64
|
+
len += df->lengths[i] + 4;
|
65
|
+
}
|
66
|
+
s = str = FRT_ALLOC_N(char, namelen + len + 5);
|
67
|
+
memcpy(s, df_name, namelen);
|
68
|
+
s += namelen;
|
69
|
+
s = frt_strapp(s, ": ");
|
70
|
+
|
71
|
+
if (df->size > 1) {
|
72
|
+
s = frt_strapp(s, "[");
|
73
|
+
}
|
74
|
+
for (i = 0; i < df->size; i++) {
|
75
|
+
if (i != 0) {
|
76
|
+
s = frt_strapp(s, ", ");
|
77
|
+
}
|
78
|
+
s = frt_strapp(s, "\"");
|
79
|
+
memcpy(s, df->data[i], df->lengths[i]);
|
80
|
+
s += df->lengths[i];
|
81
|
+
s = frt_strapp(s, "\"");
|
82
|
+
}
|
83
|
+
|
84
|
+
if (df->size > 1) {
|
85
|
+
s = frt_strapp(s, "]");
|
86
|
+
}
|
87
|
+
*s = 0;
|
88
|
+
return str;
|
89
|
+
}
|
90
|
+
|
91
|
+
/****************************************************************************
|
92
|
+
*
|
93
|
+
* FrtDocument
|
94
|
+
*
|
95
|
+
****************************************************************************/
|
96
|
+
|
97
|
+
FrtDocument *frt_doc_new()
|
98
|
+
{
|
99
|
+
FrtDocument *doc = FRT_ALLOC(FrtDocument);
|
100
|
+
doc->field_dict = frt_h_new_ptr((frt_free_ft)&frt_df_destroy);
|
101
|
+
doc->size = 0;
|
102
|
+
doc->capa = FRT_DOC_INIT_CAPA;
|
103
|
+
doc->fields = FRT_ALLOC_N(FrtDocField *, doc->capa);
|
104
|
+
doc->boost = 1.0f;
|
105
|
+
return doc;
|
106
|
+
}
|
107
|
+
|
108
|
+
FrtDocField *frt_doc_add_field(FrtDocument *doc, FrtDocField *df)
|
109
|
+
{
|
110
|
+
if (!frt_h_set_safe(doc->field_dict, (void *)df->name, df)) {
|
111
|
+
FRT_RAISE(FRT_EXCEPTION, "tried to add %s field which alread existed\n",
|
112
|
+
rb_id2name(df->name));
|
113
|
+
}
|
114
|
+
if (doc->size >= doc->capa) {
|
115
|
+
doc->capa <<= 1;
|
116
|
+
FRT_REALLOC_N(doc->fields, FrtDocField *, doc->capa);
|
117
|
+
}
|
118
|
+
doc->fields[doc->size] = df;
|
119
|
+
doc->size++;
|
120
|
+
return df;
|
121
|
+
}
|
122
|
+
|
123
|
+
FrtDocField *frt_doc_get_field(FrtDocument *doc, FrtSymbol name)
|
124
|
+
{
|
125
|
+
return (FrtDocField *)frt_h_get(doc->field_dict, (void *)name);
|
126
|
+
}
|
127
|
+
|
128
|
+
void frt_doc_destroy(FrtDocument *doc)
|
129
|
+
{
|
130
|
+
frt_h_destroy(doc->field_dict);
|
131
|
+
free(doc->fields);
|
132
|
+
free(doc);
|
133
|
+
}
|
134
|
+
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#ifndef FRT_DOCUMENT_H
|
2
|
+
#define FRT_DOCUMENT_H
|
3
|
+
|
4
|
+
#include "frt_global.h"
|
5
|
+
#include "frt_hash.h"
|
6
|
+
|
7
|
+
/****************************************************************************
|
8
|
+
*
|
9
|
+
* FrtDocField
|
10
|
+
*
|
11
|
+
****************************************************************************/
|
12
|
+
|
13
|
+
#define FRT_DF_INIT_CAPA 1
|
14
|
+
typedef struct FrtDocField
|
15
|
+
{
|
16
|
+
FrtSymbol name;
|
17
|
+
int size;
|
18
|
+
int capa;
|
19
|
+
int *lengths;
|
20
|
+
char **data;
|
21
|
+
float boost;
|
22
|
+
bool destroy_data : 1;
|
23
|
+
} FrtDocField;
|
24
|
+
|
25
|
+
extern FrtDocField *frt_df_new(FrtSymbol name);
|
26
|
+
extern FrtDocField *frt_df_add_data(FrtDocField *df, char *data);
|
27
|
+
extern FrtDocField *frt_df_add_data_len(FrtDocField *df, char *data, int len);
|
28
|
+
extern void frt_df_destroy(FrtDocField *df);
|
29
|
+
extern char *frt_df_to_s(FrtDocField *df);
|
30
|
+
|
31
|
+
/****************************************************************************
|
32
|
+
*
|
33
|
+
* FrtDocument
|
34
|
+
*
|
35
|
+
****************************************************************************/
|
36
|
+
|
37
|
+
#define FRT_DOC_INIT_CAPA 8
|
38
|
+
typedef struct FrtDocument
|
39
|
+
{
|
40
|
+
FrtHash *field_dict;
|
41
|
+
int size;
|
42
|
+
int capa;
|
43
|
+
FrtDocField **fields;
|
44
|
+
float boost;
|
45
|
+
} FrtDocument;
|
46
|
+
|
47
|
+
extern FrtDocument *frt_doc_new();
|
48
|
+
extern FrtDocField *frt_doc_add_field(FrtDocument *doc, FrtDocField *df);
|
49
|
+
extern FrtDocField *frt_doc_get_field(FrtDocument *doc, FrtSymbol name);
|
50
|
+
extern void frt_doc_destroy(FrtDocument *doc);
|
51
|
+
|
52
|
+
#endif
|
@@ -0,0 +1,95 @@
|
|
1
|
+
#include <stdarg.h>
|
2
|
+
#include "frt_global.h"
|
3
|
+
#include "frt_except.h"
|
4
|
+
#include "frt_threading.h"
|
5
|
+
|
6
|
+
const char *const ERROR_TYPES[] = {
|
7
|
+
"Body",
|
8
|
+
"Finally",
|
9
|
+
"Exception",
|
10
|
+
"IO Error",
|
11
|
+
"File Not Found Error",
|
12
|
+
"Argument Error",
|
13
|
+
"End-of-File Error",
|
14
|
+
"Unsupported Function Error",
|
15
|
+
"State Error",
|
16
|
+
"Parse Error",
|
17
|
+
"Memory Error",
|
18
|
+
"Index Error",
|
19
|
+
"Lock Error"
|
20
|
+
};
|
21
|
+
|
22
|
+
bool frt_x_do_logging = false;
|
23
|
+
bool frt_x_abort_on_exception = true;
|
24
|
+
bool frt_x_has_aborted = false;
|
25
|
+
FILE *frt_x_exception_stream = NULL;
|
26
|
+
|
27
|
+
const char *const FRT_UNSUPPORTED_ERROR_MSG = "Unsupported operation";
|
28
|
+
const char *const FRT_EOF_ERROR_MSG = "Read past end of file";
|
29
|
+
char frt_xmsg_buffer[FRT_XMSG_BUFFER_SIZE];
|
30
|
+
char frt_xmsg_buffer_final[FRT_XMSG_BUFFER_FINAL_SIZE];
|
31
|
+
|
32
|
+
static frt_thread_key_t exception_stack_key;
|
33
|
+
static frt_thread_once_t exception_stack_key_once = FRT_THREAD_ONCE_INIT;
|
34
|
+
|
35
|
+
static void exception_stack_alloc(void)
|
36
|
+
{
|
37
|
+
frt_thread_key_create(&exception_stack_key, NULL);
|
38
|
+
}
|
39
|
+
|
40
|
+
void frt_xpush_context(frt_xcontext_t *context)
|
41
|
+
{
|
42
|
+
frt_xcontext_t *top_context;
|
43
|
+
frt_thread_once(&exception_stack_key_once, *exception_stack_alloc);
|
44
|
+
top_context = (frt_xcontext_t *)frt_thread_getspecific(exception_stack_key);
|
45
|
+
context->next = top_context;
|
46
|
+
frt_thread_setspecific(exception_stack_key, context);
|
47
|
+
context->handled = true;
|
48
|
+
context->in_finally = false;
|
49
|
+
}
|
50
|
+
|
51
|
+
static void frt_xraise_context(frt_xcontext_t *context,
|
52
|
+
volatile int excode,
|
53
|
+
const char *const msg)
|
54
|
+
{
|
55
|
+
context->msg = msg;
|
56
|
+
context->excode = excode;
|
57
|
+
context->handled = false;
|
58
|
+
longjmp(context->jbuf, excode);
|
59
|
+
}
|
60
|
+
|
61
|
+
void frt_xraise(int excode, const char *const msg)
|
62
|
+
{
|
63
|
+
frt_xcontext_t *top_context;
|
64
|
+
frt_thread_once(&exception_stack_key_once, *exception_stack_alloc);
|
65
|
+
top_context = (frt_xcontext_t *)frt_thread_getspecific(exception_stack_key);
|
66
|
+
|
67
|
+
if (!top_context) {
|
68
|
+
FRT_XEXIT(ERROR_TYPES[excode], msg);
|
69
|
+
}
|
70
|
+
else if (!top_context->in_finally) {
|
71
|
+
frt_xraise_context(top_context, excode, msg);
|
72
|
+
}
|
73
|
+
else if (top_context->handled) {
|
74
|
+
top_context->msg = msg;
|
75
|
+
top_context->excode = excode;
|
76
|
+
top_context->handled = false;
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
void frt_xpop_context()
|
81
|
+
{
|
82
|
+
frt_xcontext_t *top_cxt, *context;
|
83
|
+
frt_thread_once(&exception_stack_key_once, *exception_stack_alloc);
|
84
|
+
top_cxt = (frt_xcontext_t *)frt_thread_getspecific(exception_stack_key);
|
85
|
+
context = top_cxt->next;
|
86
|
+
frt_thread_setspecific(exception_stack_key, context);
|
87
|
+
if (!top_cxt->handled) {
|
88
|
+
if (context) {
|
89
|
+
frt_xraise_context(context, top_cxt->excode, top_cxt->msg);
|
90
|
+
}
|
91
|
+
else {
|
92
|
+
FRT_XEXIT(ERROR_TYPES[top_cxt->excode], top_cxt->msg);
|
93
|
+
}
|
94
|
+
}
|
95
|
+
}
|