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/store.c
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
#include "store.h"
|
2
2
|
#include <string.h>
|
3
|
+
#include "internal.h"
|
3
4
|
|
4
5
|
#define VINT_MAX_LEN 10
|
5
6
|
#define VINT_END BUFFER_SIZE - VINT_MAX_LEN
|
@@ -10,7 +11,7 @@
|
|
10
11
|
void with_lock(Lock *lock, void (*func)(void *arg), void *arg)
|
11
12
|
{
|
12
13
|
if (!lock->obtain(lock)) {
|
13
|
-
RAISE(
|
14
|
+
RAISE(LOCK_ERROR, "couldn't obtain lock \"%s\"", lock->name);
|
14
15
|
}
|
15
16
|
func(arg);
|
16
17
|
lock->release(lock);
|
@@ -19,7 +20,7 @@ void with_lock(Lock *lock, void (*func)(void *arg), void *arg)
|
|
19
20
|
/*
|
20
21
|
* TODO: add try finally
|
21
22
|
*/
|
22
|
-
void with_lock_name(Store *store, char *lock_name,
|
23
|
+
void with_lock_name(Store *store, const char *lock_name,
|
23
24
|
void (*func)(void *arg), void *arg)
|
24
25
|
{
|
25
26
|
Lock *lock = store->open_lock_i(store, lock_name);
|
@@ -42,7 +43,7 @@ void store_deref(Store *store)
|
|
42
43
|
}
|
43
44
|
}
|
44
45
|
|
45
|
-
Lock *open_lock(Store *store, char *lockname)
|
46
|
+
Lock *open_lock(Store *store, const char *lockname)
|
46
47
|
{
|
47
48
|
Lock *lock = store->open_lock_i(store, lockname);
|
48
49
|
hs_add(store->locks, lock);
|
@@ -54,7 +55,7 @@ void close_lock(Lock *lock)
|
|
54
55
|
hs_del(lock->store->locks, lock);
|
55
56
|
}
|
56
57
|
|
57
|
-
void close_lock_i(Lock *lock)
|
58
|
+
static void close_lock_i(Lock *lock)
|
58
59
|
{
|
59
60
|
lock->store->close_lock_i(lock);
|
60
61
|
}
|
@@ -68,7 +69,7 @@ Store *store_new()
|
|
68
69
|
store->ref_cnt = 1;
|
69
70
|
mutex_init(&store->mutex_i, NULL);
|
70
71
|
mutex_init(&store->mutex, NULL);
|
71
|
-
store->locks =
|
72
|
+
store->locks = hs_new_ptr((free_ft)&close_lock_i);
|
72
73
|
return store;
|
73
74
|
}
|
74
75
|
|
@@ -151,7 +152,7 @@ INLINE void os_write_byte(OutStream *os, uchar b)
|
|
151
152
|
write_byte(os, b);
|
152
153
|
}
|
153
154
|
|
154
|
-
void os_write_bytes(OutStream *os, uchar *buf, int len)
|
155
|
+
void os_write_bytes(OutStream *os, const uchar *buf, int len)
|
155
156
|
{
|
156
157
|
if (os->buf.pos > 0) { /* flush buffer */
|
157
158
|
os_flush(os);
|
@@ -200,7 +201,7 @@ InStream *is_new()
|
|
200
201
|
* @raise IO_ERROR if there is a error reading from the filesystem
|
201
202
|
* @raise EOF_ERROR if there is an attempt to read past the end of the file
|
202
203
|
*/
|
203
|
-
void is_refill(InStream *is)
|
204
|
+
static void is_refill(InStream *is)
|
204
205
|
{
|
205
206
|
off_t start = is->buf.start + is->buf.pos;
|
206
207
|
off_t last = start + BUFFER_SIZE;
|
@@ -212,8 +213,8 @@ void is_refill(InStream *is)
|
|
212
213
|
|
213
214
|
is->buf.len = last - start;
|
214
215
|
if (is->buf.len <= 0) {
|
215
|
-
RAISE(EOF_ERROR, "current pos = %"
|
216
|
-
"file length = %"
|
216
|
+
RAISE(EOF_ERROR, "current pos = %"OFF_T_PFX"d, "
|
217
|
+
"file length = %"OFF_T_PFX"d", start, flen);
|
217
218
|
}
|
218
219
|
|
219
220
|
is->m->read_i(is, is->buf.buf, is->buf.len);
|
@@ -303,44 +304,44 @@ InStream *is_clone(InStream *is)
|
|
303
304
|
return new_index_i;
|
304
305
|
}
|
305
306
|
|
306
|
-
|
307
|
+
i32 is_read_i32(InStream *is)
|
307
308
|
{
|
308
|
-
return ((
|
309
|
-
((
|
310
|
-
((
|
311
|
-
((
|
309
|
+
return ((i32)is_read_byte(is) << 24) |
|
310
|
+
((i32)is_read_byte(is) << 16) |
|
311
|
+
((i32)is_read_byte(is) << 8) |
|
312
|
+
((i32)is_read_byte(is));
|
312
313
|
}
|
313
314
|
|
314
|
-
|
315
|
+
i64 is_read_i64(InStream *is)
|
315
316
|
{
|
316
|
-
return ((
|
317
|
-
((
|
318
|
-
((
|
319
|
-
((
|
320
|
-
((
|
321
|
-
((
|
322
|
-
((
|
323
|
-
((
|
317
|
+
return ((i64)is_read_byte(is) << 56) |
|
318
|
+
((i64)is_read_byte(is) << 48) |
|
319
|
+
((i64)is_read_byte(is) << 40) |
|
320
|
+
((i64)is_read_byte(is) << 32) |
|
321
|
+
((i64)is_read_byte(is) << 24) |
|
322
|
+
((i64)is_read_byte(is) << 16) |
|
323
|
+
((i64)is_read_byte(is) << 8) |
|
324
|
+
((i64)is_read_byte(is));
|
324
325
|
}
|
325
326
|
|
326
|
-
|
327
|
+
u32 is_read_u32(InStream *is)
|
327
328
|
{
|
328
|
-
return ((
|
329
|
-
((
|
330
|
-
((
|
331
|
-
((
|
329
|
+
return ((u32)is_read_byte(is) << 24) |
|
330
|
+
((u32)is_read_byte(is) << 16) |
|
331
|
+
((u32)is_read_byte(is) << 8) |
|
332
|
+
((u32)is_read_byte(is));
|
332
333
|
}
|
333
334
|
|
334
|
-
|
335
|
+
u64 is_read_u64(InStream *is)
|
335
336
|
{
|
336
|
-
return ((
|
337
|
-
((
|
338
|
-
((
|
339
|
-
((
|
340
|
-
((
|
341
|
-
((
|
342
|
-
((
|
343
|
-
((
|
337
|
+
return ((u64)is_read_byte(is) << 56) |
|
338
|
+
((u64)is_read_byte(is) << 48) |
|
339
|
+
((u64)is_read_byte(is) << 40) |
|
340
|
+
((u64)is_read_byte(is) << 32) |
|
341
|
+
((u64)is_read_byte(is) << 24) |
|
342
|
+
((u64)is_read_byte(is) << 16) |
|
343
|
+
((u64)is_read_byte(is) << 8) |
|
344
|
+
((u64)is_read_byte(is));
|
344
345
|
}
|
345
346
|
|
346
347
|
/* optimized to use unchecked read_byte if there is definitely space */
|
@@ -404,9 +405,9 @@ INLINE off_t is_read_voff_t(InStream *is)
|
|
404
405
|
}
|
405
406
|
|
406
407
|
/* optimized to use unchecked read_byte if there is definitely space */
|
407
|
-
INLINE
|
408
|
+
INLINE u64 is_read_vll(InStream *is)
|
408
409
|
{
|
409
|
-
register
|
410
|
+
register u64 res, b;
|
410
411
|
register int shift = 7;
|
411
412
|
|
412
413
|
if (is->buf.pos > (is->buf.len - VINT_MAX_LEN)) {
|
@@ -441,8 +442,10 @@ INLINE void is_skip_vints(InStream *is, register int cnt)
|
|
441
442
|
}
|
442
443
|
}
|
443
444
|
|
444
|
-
|
445
|
-
|
445
|
+
/*
|
446
|
+
* FIXME: Not used. Do we need/want this?
|
447
|
+
static INLINE void is_read_chars(InStream *is, char *buffer,
|
448
|
+
int off, int len)
|
446
449
|
{
|
447
450
|
int end, i;
|
448
451
|
|
@@ -452,6 +455,7 @@ INLINE void is_read_chars(InStream *is, char *buffer,
|
|
452
455
|
buffer[i] = is_read_byte(is);
|
453
456
|
}
|
454
457
|
}
|
458
|
+
*/
|
455
459
|
|
456
460
|
char *is_read_string(InStream *is)
|
457
461
|
{
|
@@ -497,7 +501,7 @@ char *is_read_string_safe(InStream *is)
|
|
497
501
|
return str;
|
498
502
|
}
|
499
503
|
|
500
|
-
void os_write_i32(OutStream *os,
|
504
|
+
void os_write_i32(OutStream *os, i32 num)
|
501
505
|
{
|
502
506
|
os_write_byte(os, (uchar)((num >> 24) & 0xFF));
|
503
507
|
os_write_byte(os, (uchar)((num >> 16) & 0xFF));
|
@@ -505,7 +509,7 @@ void os_write_i32(OutStream *os, f_i32 num)
|
|
505
509
|
os_write_byte(os, (uchar)(num & 0xFF));
|
506
510
|
}
|
507
511
|
|
508
|
-
void os_write_i64(OutStream *os,
|
512
|
+
void os_write_i64(OutStream *os, i64 num)
|
509
513
|
{
|
510
514
|
os_write_byte(os, (uchar)((num >> 56) & 0xFF));
|
511
515
|
os_write_byte(os, (uchar)((num >> 48) & 0xFF));
|
@@ -517,7 +521,7 @@ void os_write_i64(OutStream *os, f_i64 num)
|
|
517
521
|
os_write_byte(os, (uchar)(num & 0xFF));
|
518
522
|
}
|
519
523
|
|
520
|
-
void os_write_u32(OutStream *os,
|
524
|
+
void os_write_u32(OutStream *os, u32 num)
|
521
525
|
{
|
522
526
|
os_write_byte(os, (uchar)((num >> 24) & 0xFF));
|
523
527
|
os_write_byte(os, (uchar)((num >> 16) & 0xFF));
|
@@ -525,7 +529,7 @@ void os_write_u32(OutStream *os, f_u32 num)
|
|
525
529
|
os_write_byte(os, (uchar)(num & 0xFF));
|
526
530
|
}
|
527
531
|
|
528
|
-
void os_write_u64(OutStream *os,
|
532
|
+
void os_write_u64(OutStream *os, u64 num)
|
529
533
|
{
|
530
534
|
os_write_byte(os, (uchar)((num >> 56) & 0xFF));
|
531
535
|
os_write_byte(os, (uchar)((num >> 48) & 0xFF));
|
@@ -576,7 +580,7 @@ INLINE void os_write_voff_t(OutStream *os, register off_t num)
|
|
576
580
|
}
|
577
581
|
|
578
582
|
/* optimized to use an unchecked write if there is space */
|
579
|
-
INLINE void os_write_vll(OutStream *os, register
|
583
|
+
INLINE void os_write_vll(OutStream *os, register u64 num)
|
580
584
|
{
|
581
585
|
if (os->buf.pos > VINT_END) {
|
582
586
|
while (num > 127) {
|
@@ -594,13 +598,15 @@ INLINE void os_write_vll(OutStream *os, register unsigned long long num)
|
|
594
598
|
}
|
595
599
|
}
|
596
600
|
|
597
|
-
void
|
601
|
+
INLINE void os_write_string_len(OutStream *os, const char *str, int len)
|
598
602
|
{
|
599
|
-
int len = (int)strlen(str);
|
600
603
|
os_write_vint(os, len);
|
601
|
-
|
602
604
|
os_write_bytes(os, (uchar *)str, len);
|
603
605
|
}
|
606
|
+
void os_write_string(OutStream *os, const char *str)
|
607
|
+
{
|
608
|
+
os_write_string_len(os, str, (int)strlen(str));
|
609
|
+
}
|
604
610
|
|
605
611
|
/**
|
606
612
|
* Determine if the filename is the name of a lock file. Return 1 if it is, 0
|
@@ -609,7 +615,7 @@ void os_write_string(OutStream *os, char *str)
|
|
609
615
|
* @param filename the name of the file to check
|
610
616
|
* @return 1 (true) if the file is a lock file, 0 (false) otherwise
|
611
617
|
*/
|
612
|
-
int file_is_lock(char *filename)
|
618
|
+
int file_is_lock(const char *filename)
|
613
619
|
{
|
614
620
|
int start = (int) strlen(filename) - 4;
|
615
621
|
return ((start > 0) && (strcmp(LOCK_EXT, &filename[start]) == 0));
|
@@ -652,7 +658,7 @@ struct FileNameListArg
|
|
652
658
|
/**
|
653
659
|
* Test function used to test store->each function
|
654
660
|
*/
|
655
|
-
static void add_file_name(char *fname, void *arg)
|
661
|
+
static void add_file_name(const char *fname, void *arg)
|
656
662
|
{
|
657
663
|
struct FileNameListArg *fnl = (struct FileNameListArg *)arg;
|
658
664
|
if (fnl->count >= fnl->size) {
|
data/ext/store.h
CHANGED
@@ -7,78 +7,74 @@
|
|
7
7
|
#include "hashset.h"
|
8
8
|
#include "threading.h"
|
9
9
|
|
10
|
-
#define
|
11
|
-
#define
|
12
|
-
#define LOCK_EXT ".lck"
|
10
|
+
#define FRT_LOCK_PREFIX "ferret-"
|
11
|
+
#define FRT_LOCK_EXT ".lck"
|
13
12
|
|
14
|
-
|
15
|
-
#define VINT_END BUFFER_SIZE - VINT_MAX_LEN
|
16
|
-
|
17
|
-
typedef struct Buffer
|
13
|
+
typedef struct FrtBuffer
|
18
14
|
{
|
19
|
-
|
15
|
+
frt_uchar buf[FRT_BUFFER_SIZE];
|
20
16
|
off_t start;
|
21
17
|
off_t pos;
|
22
18
|
off_t len;
|
23
|
-
}
|
19
|
+
} FrtBuffer;
|
24
20
|
|
25
|
-
typedef struct
|
26
|
-
struct
|
27
|
-
/* internal functions for the
|
21
|
+
typedef struct FrtOutStream FrtOutStream;
|
22
|
+
struct FrtOutStreamMethods {
|
23
|
+
/* internal functions for the FrtInStream */
|
28
24
|
/**
|
29
25
|
* Flush +len+ characters from +src+ to the output stream +os+
|
30
26
|
*
|
31
27
|
* @param os self
|
32
28
|
* @param src the characters to write to the output stream
|
33
29
|
* @param len the number of characters to write
|
34
|
-
* @raise
|
30
|
+
* @raise FRT_IO_ERROR if there is an error writing the characters
|
35
31
|
*/
|
36
|
-
void (*flush_i)(struct
|
32
|
+
void (*flush_i)(struct FrtOutStream *os, const frt_uchar *buf, int len);
|
37
33
|
|
38
34
|
/**
|
39
35
|
* Seek +pos+ in the output stream
|
40
36
|
*
|
41
37
|
* @param os self
|
42
38
|
* @param pos the position to seek in the stream
|
43
|
-
* @raise
|
39
|
+
* @raise FRT_IO_ERROR if there is an error seeking in the output stream
|
44
40
|
*/
|
45
|
-
void (*seek_i)(struct
|
41
|
+
void (*seek_i)(struct FrtOutStream *os, off_t pos);
|
46
42
|
|
47
43
|
/**
|
48
44
|
* Close any resources used by the output stream +os+
|
49
45
|
*
|
50
46
|
* @param os self
|
51
|
-
* @raise
|
47
|
+
* @raise FRT_IO_ERROR if there is an closing the file
|
52
48
|
*/
|
53
|
-
void (*close_i)(struct
|
49
|
+
void (*close_i)(struct FrtOutStream *os);
|
54
50
|
};
|
55
51
|
|
56
|
-
typedef struct
|
52
|
+
typedef struct FrtRAMFile
|
57
53
|
{
|
58
54
|
char *name;
|
59
|
-
|
55
|
+
frt_uchar **buffers;
|
60
56
|
int bufcnt;
|
61
57
|
off_t len;
|
62
58
|
int ref_cnt;
|
63
|
-
}
|
59
|
+
} FrtRAMFile;
|
64
60
|
|
65
|
-
struct
|
61
|
+
struct FrtOutStream
|
66
62
|
{
|
67
|
-
|
63
|
+
FrtBuffer buf;
|
68
64
|
union
|
69
65
|
{
|
70
66
|
int fd;
|
71
|
-
|
67
|
+
FrtRAMFile *rf;
|
72
68
|
} file;
|
73
69
|
off_t pointer; /* only used by RAMOut */
|
74
|
-
const struct
|
70
|
+
const struct FrtOutStreamMethods *m;
|
75
71
|
};
|
76
72
|
|
77
|
-
typedef struct
|
73
|
+
typedef struct FrtCompoundInStream FrtCompoundInStream;
|
78
74
|
|
79
|
-
typedef struct
|
75
|
+
typedef struct FrtInStream FrtInStream;
|
80
76
|
|
81
|
-
struct
|
77
|
+
struct FrtInStreamMethods
|
82
78
|
{
|
83
79
|
/**
|
84
80
|
* Read +len+ characters from the input stream into the +offset+ position in
|
@@ -88,92 +84,92 @@ struct InStreamMethods
|
|
88
84
|
* @param buf an array of characters which must be allocated with at least
|
89
85
|
* +offset+ + +len+ bytes
|
90
86
|
* @param len the number of bytes to read
|
91
|
-
* @raise
|
87
|
+
* @raise FRT_IO_ERROR if there is an error reading from the input stream
|
92
88
|
*/
|
93
|
-
void (*read_i)(struct
|
89
|
+
void (*read_i)(struct FrtInStream *is, frt_uchar *buf, int len);
|
94
90
|
|
95
91
|
/**
|
96
92
|
* Seek position +pos+ in input stream +is+
|
97
93
|
*
|
98
94
|
* @param is self
|
99
95
|
* @param pos the position to seek
|
100
|
-
* @raise
|
96
|
+
* @raise FRT_IO_ERROR if the seek fails
|
101
97
|
*/
|
102
|
-
void (*seek_i)(struct
|
98
|
+
void (*seek_i)(struct FrtInStream *is, off_t pos);
|
103
99
|
|
104
100
|
/**
|
105
101
|
* Returns the length of the input stream +is+
|
106
102
|
*
|
107
103
|
* @param is self
|
108
|
-
* @raise
|
104
|
+
* @raise FRT_IO_ERROR if there is an error getting the file length
|
109
105
|
*/
|
110
|
-
off_t (*length_i)(struct
|
111
|
-
|
106
|
+
off_t (*length_i)(struct FrtInStream *is);
|
107
|
+
|
112
108
|
/**
|
113
109
|
* Close the resources allocated to the inputstream +is+
|
114
110
|
*
|
115
111
|
* @param is self
|
116
|
-
* @raise
|
112
|
+
* @raise FRT_IO_ERROR if the close fails
|
117
113
|
*/
|
118
|
-
void (*close_i)(struct
|
114
|
+
void (*close_i)(struct FrtInStream *is);
|
119
115
|
};
|
120
116
|
|
121
|
-
struct
|
117
|
+
struct FrtInStream
|
122
118
|
{
|
123
|
-
|
119
|
+
FrtBuffer buf;
|
124
120
|
union
|
125
121
|
{
|
126
122
|
int fd;
|
127
|
-
|
123
|
+
FrtRAMFile *rf;
|
128
124
|
} file;
|
129
125
|
union
|
130
126
|
{
|
131
|
-
off_t pointer;
|
127
|
+
off_t pointer; /* only used by RAMIn */
|
132
128
|
char *path; /* only used by FSIn */
|
133
|
-
|
129
|
+
FrtCompoundInStream *cis;
|
134
130
|
} d;
|
135
131
|
int *ref_cnt_ptr;
|
136
|
-
const struct
|
132
|
+
const struct FrtInStreamMethods *m;
|
137
133
|
};
|
138
134
|
|
139
|
-
struct
|
135
|
+
struct FrtCompoundInStream
|
140
136
|
{
|
141
|
-
|
137
|
+
FrtInStream *sub;
|
142
138
|
off_t offset;
|
143
139
|
off_t length;
|
144
140
|
};
|
145
141
|
|
146
142
|
#define is_length(mis) mis->m->length_i(mis)
|
147
143
|
|
148
|
-
typedef struct
|
149
|
-
typedef struct
|
150
|
-
struct
|
144
|
+
typedef struct FrtStore FrtStore;
|
145
|
+
typedef struct FrtLock FrtLock;
|
146
|
+
struct FrtLock
|
151
147
|
{
|
152
148
|
char *name;
|
153
|
-
|
154
|
-
int (*obtain)(
|
155
|
-
int (*is_locked)(
|
156
|
-
void (*release)(
|
149
|
+
FrtStore *store;
|
150
|
+
int (*obtain)(FrtLock *lock);
|
151
|
+
int (*is_locked)(FrtLock *lock);
|
152
|
+
void (*release)(FrtLock *lock);
|
157
153
|
};
|
158
154
|
|
159
|
-
typedef struct
|
155
|
+
typedef struct FrtCompoundStore
|
160
156
|
{
|
161
|
-
|
157
|
+
FrtStore *store;
|
162
158
|
const char *name;
|
163
|
-
|
164
|
-
|
165
|
-
}
|
159
|
+
FrtHash *entries;
|
160
|
+
FrtInStream *stream;
|
161
|
+
} FrtCompoundStore;
|
166
162
|
|
167
|
-
struct
|
163
|
+
struct FrtStore
|
168
164
|
{
|
169
165
|
int ref_cnt; /* for fs_store only */
|
170
|
-
|
171
|
-
|
166
|
+
frt_mutex_t mutex_i; /* for internal use only */
|
167
|
+
frt_mutex_t mutex; /* external mutex for use outside */
|
172
168
|
union
|
173
169
|
{
|
174
170
|
char *path; /* for fs_store only */
|
175
|
-
|
176
|
-
|
171
|
+
FrtHash *ht; /* for ram_store only */
|
172
|
+
FrtCompoundStore *cmpd; /* for compound_store only */
|
177
173
|
} dir;
|
178
174
|
|
179
175
|
#ifdef POSH_OS_WIN32
|
@@ -181,16 +177,16 @@ struct Store
|
|
181
177
|
#else
|
182
178
|
mode_t file_mode;
|
183
179
|
#endif
|
184
|
-
|
180
|
+
FrtHashSet *locks;
|
185
181
|
|
186
182
|
/**
|
187
183
|
* Create the file +filename+ in the +store+.
|
188
184
|
*
|
189
185
|
* @param store self
|
190
186
|
* @param filename the name of the file to create
|
191
|
-
* @raise
|
187
|
+
* @raise FRT_IO_ERROR if the file cannot be created
|
192
188
|
*/
|
193
|
-
void (*touch)(
|
189
|
+
void (*touch)(FrtStore *store, const char *filename);
|
194
190
|
|
195
191
|
/**
|
196
192
|
* Return true if a file of name +filename+ exists in +store+.
|
@@ -198,9 +194,9 @@ struct Store
|
|
198
194
|
* @param store self
|
199
195
|
* @param filename the name of the file to check for
|
200
196
|
* @returns true if the file exists
|
201
|
-
* @raise
|
197
|
+
* @raise FRT_IO_ERROR if there is an error checking for the files existance
|
202
198
|
*/
|
203
|
-
int (*exists)(
|
199
|
+
int (*exists)(FrtStore *store, const char *filename);
|
204
200
|
|
205
201
|
/**
|
206
202
|
* Remove the file +filename+ from the +store+
|
@@ -210,7 +206,7 @@ struct Store
|
|
210
206
|
* @returns On success, zero is returned. On error, -1 is returned, and errno
|
211
207
|
* is set appropriately.
|
212
208
|
*/
|
213
|
-
int (*remove)(
|
209
|
+
int (*remove)(FrtStore *store, const char *filename);
|
214
210
|
|
215
211
|
/**
|
216
212
|
* Rename the file in the +store+ from the name +from+ to the name +to+.
|
@@ -218,18 +214,18 @@ struct Store
|
|
218
214
|
* @param store self
|
219
215
|
* @param from the name of the file to rename
|
220
216
|
* @param to the new name of the file
|
221
|
-
* @raise
|
217
|
+
* @raise FRT_IO_ERROR if there is an error renaming the file
|
222
218
|
*/
|
223
|
-
void (*rename)(
|
219
|
+
void (*rename)(FrtStore *store, const char *from, const char *to);
|
224
220
|
|
225
221
|
/**
|
226
222
|
* Returns the number of files in the store.
|
227
223
|
*
|
228
224
|
* @param store self
|
229
225
|
* @return the number of files in the store
|
230
|
-
* @raise
|
226
|
+
* @raise FRT_IO_ERROR if there is an error opening the directory
|
231
227
|
*/
|
232
|
-
int (*count)(
|
228
|
+
int (*count)(FrtStore *store);
|
233
229
|
|
234
230
|
/**
|
235
231
|
* Call the function +func+ with each filename in the store and the arg
|
@@ -241,34 +237,34 @@ struct Store
|
|
241
237
|
* @param func the function to call with each files name and the +arg+
|
242
238
|
* passed
|
243
239
|
* @param arg the argument to pass to the function
|
244
|
-
* @raise
|
240
|
+
* @raise FRT_IO_ERROR if there is an error opening the directory
|
245
241
|
*/
|
246
|
-
void (*each)(
|
242
|
+
void (*each)(FrtStore *store, void (*func)(const char *fname, void *arg),
|
247
243
|
void *arg);
|
248
244
|
|
249
245
|
/**
|
250
246
|
* Clear all the locks in the store.
|
251
247
|
*
|
252
248
|
* @param store self
|
253
|
-
* @raise
|
249
|
+
* @raise FRT_IO_ERROR if there is an error opening the directory
|
254
250
|
*/
|
255
|
-
void (*clear_locks)(
|
251
|
+
void (*clear_locks)(FrtStore *store);
|
256
252
|
|
257
253
|
/**
|
258
254
|
* Clear all files from the store except the lock files.
|
259
255
|
*
|
260
256
|
* @param store self
|
261
|
-
* @raise
|
257
|
+
* @raise FRT_IO_ERROR if there is an error deleting the files
|
262
258
|
*/
|
263
|
-
void (*clear)(
|
259
|
+
void (*clear)(FrtStore *store);
|
264
260
|
|
265
261
|
/**
|
266
262
|
* Clear all files from the store including the lock files.
|
267
263
|
*
|
268
264
|
* @param store self
|
269
|
-
* @raise
|
265
|
+
* @raise FRT_IO_ERROR if there is an error deleting the files
|
270
266
|
*/
|
271
|
-
void (*clear_all)(
|
267
|
+
void (*clear_all)(FrtStore *store);
|
272
268
|
|
273
269
|
/**
|
274
270
|
* Return the length of the file +filename+ in +store+
|
@@ -276,9 +272,9 @@ struct Store
|
|
276
272
|
* @param store self
|
277
273
|
* @param the name of the file to check the length of
|
278
274
|
* @return the length of the file in bytes
|
279
|
-
* @raise
|
275
|
+
* @raise FRT_IO_ERROR if there is an error checking the file length
|
280
276
|
*/
|
281
|
-
off_t (*length)(
|
277
|
+
off_t (*length)(FrtStore *store, const char *filename);
|
282
278
|
|
283
279
|
/**
|
284
280
|
* Allocate the resources needed for the output stream in the +store+ with
|
@@ -287,19 +283,19 @@ struct Store
|
|
287
283
|
* @param store self
|
288
284
|
* @param filename the name of the output stream
|
289
285
|
* @return a newly allocated filestream
|
290
|
-
* @raise
|
286
|
+
* @raise FRT_IO_ERROR if there is an error opening the output stream
|
291
287
|
* resources
|
292
288
|
*/
|
293
|
-
|
289
|
+
FrtOutStream *(*new_output)(FrtStore *store, const char *filename);
|
294
290
|
|
295
291
|
/**
|
296
292
|
* Open an input stream in the +store+ with the name +filename+
|
297
293
|
*
|
298
294
|
* @param store self
|
299
295
|
* @param filename the name of the input stream
|
300
|
-
* @raise
|
296
|
+
* @raise FRT_FILE_NOT_FOUND_ERROR if the input stream cannot be opened
|
301
297
|
*/
|
302
|
-
|
298
|
+
FrtInStream *(*open_input)(FrtStore *store, const char *filename);
|
303
299
|
|
304
300
|
/**
|
305
301
|
* Obtain a lock on the lock +lock+
|
@@ -307,15 +303,15 @@ struct Store
|
|
307
303
|
* @param store self
|
308
304
|
* @param lock the lock to obtain
|
309
305
|
*/
|
310
|
-
|
306
|
+
FrtLock *(*open_lock_i)(FrtStore *store, const char *lockname);
|
311
307
|
|
312
308
|
/**
|
313
309
|
* Returns true if +lock+ is locked. To test if the file is locked:wq
|
314
310
|
*
|
315
311
|
* @param lock the lock to test
|
316
|
-
* @raise
|
312
|
+
* @raise FRT_IO_ERROR if there is an error detecting the lock status
|
317
313
|
*/
|
318
|
-
void (*close_lock_i)(
|
314
|
+
void (*close_lock_i)(FrtLock *lock);
|
319
315
|
|
320
316
|
/**
|
321
317
|
* Internal function to close the store freeing implementation specific
|
@@ -323,27 +319,27 @@ struct Store
|
|
323
319
|
*
|
324
320
|
* @param store self
|
325
321
|
*/
|
326
|
-
void (*close_i)(
|
322
|
+
void (*close_i)(FrtStore *store);
|
327
323
|
};
|
328
324
|
|
329
325
|
/**
|
330
|
-
* Create a newly allocated file-system
|
326
|
+
* Create a newly allocated file-system FrtStore at the pathname designated. The
|
331
327
|
* pathname must be the name of an existing directory.
|
332
328
|
*
|
333
329
|
* @param pathname the pathname of the directory to be used by the index
|
334
|
-
* @return a newly allocated file-system
|
330
|
+
* @return a newly allocated file-system FrtStore.
|
335
331
|
*/
|
336
|
-
extern
|
332
|
+
extern FrtStore *frt_open_fs_store(const char *pathname);
|
337
333
|
|
338
334
|
/**
|
339
|
-
* Create a newly allocated in-memory or RAM
|
335
|
+
* Create a newly allocated in-memory or RAM FrtStore.
|
340
336
|
*
|
341
|
-
* @return a newly allocated RAM
|
337
|
+
* @return a newly allocated RAM FrtStore.
|
342
338
|
*/
|
343
|
-
extern
|
339
|
+
extern FrtStore *frt_open_ram_store();
|
344
340
|
|
345
341
|
/**
|
346
|
-
* Create a newly allocated in-memory or RAM
|
342
|
+
* Create a newly allocated in-memory or RAM FrtStore. Copy the contents of
|
347
343
|
* another store into this store. Then close the other store if required. This
|
348
344
|
* method would be used for example to read an index into memory for faster
|
349
345
|
* searching.
|
@@ -351,9 +347,9 @@ extern Store *open_ram_store();
|
|
351
347
|
* @param store the whose contents will be copied into the newly allocated RAM
|
352
348
|
* store
|
353
349
|
* @param close_store close the store whose contents where copied
|
354
|
-
* @return a newly allocated RAM
|
350
|
+
* @return a newly allocated RAM FrtStore.
|
355
351
|
*/
|
356
|
-
extern
|
352
|
+
extern FrtStore *frt_open_ram_store_and_copy(FrtStore *store, bool close_store);
|
357
353
|
|
358
354
|
/**
|
359
355
|
* Open a compound store. This is basically store which is stored within a
|
@@ -362,86 +358,86 @@ extern Store *open_ram_store_and_copy(Store *store, bool close_store);
|
|
362
358
|
*
|
363
359
|
* @param store the store within which this compound store will be stored
|
364
360
|
* @param filename the name of the file in which to store the compound store
|
365
|
-
* @return a newly allocated Compound
|
361
|
+
* @return a newly allocated Compound FrtStore.
|
366
362
|
*/
|
367
|
-
extern
|
363
|
+
extern FrtStore *frt_open_cmpd_store(FrtStore *store, const char *filename);
|
368
364
|
|
369
|
-
/*
|
365
|
+
/*
|
370
366
|
* == RamStore functions ==
|
371
367
|
*
|
372
368
|
* These functions or optimizations to be used when you know you are using a
|
373
|
-
* Ram
|
369
|
+
* Ram FrtOutStream.
|
374
370
|
*/
|
375
371
|
|
376
372
|
/**
|
377
|
-
* Return the length of the
|
373
|
+
* Return the length of the FrtOutStream in bytes.
|
378
374
|
*
|
379
|
-
* @param os the
|
375
|
+
* @param os the FrtOutStream who's length you want
|
380
376
|
* @return the length of +os+ in bytes
|
381
377
|
*/
|
382
|
-
extern off_t
|
378
|
+
extern off_t frt_ramo_length(FrtOutStream *os);
|
383
379
|
|
384
380
|
/**
|
385
|
-
* Reset the
|
381
|
+
* Reset the FrtOutStream removing any data written to it. Since it is a RAM
|
386
382
|
* file, all that needs to be done is set the length to 0.
|
387
383
|
*
|
388
|
-
* @param os the
|
384
|
+
* @param os the FrtOutStream to reset
|
389
385
|
*/
|
390
|
-
extern void
|
386
|
+
extern void frt_ramo_reset(FrtOutStream *os);
|
391
387
|
|
392
388
|
/**
|
393
|
-
* Write the contents of a RAM
|
389
|
+
* Write the contents of a RAM FrtOutStream to another FrtOutStream.
|
394
390
|
*
|
395
|
-
* @param from_os the
|
396
|
-
* @param to_os the
|
391
|
+
* @param from_os the FrtOutStream to write from
|
392
|
+
* @param to_os the FrtOutStream to write to
|
397
393
|
*/
|
398
|
-
extern void
|
394
|
+
extern void frt_ramo_write_to(FrtOutStream *from_os, FrtOutStream *to_os);
|
399
395
|
|
400
396
|
/**
|
401
|
-
* Create a buffer RAM
|
402
|
-
* This
|
403
|
-
* comes, this data can be written to another
|
404
|
-
* be a file-system
|
397
|
+
* Create a buffer RAM FrtOutStream which is unassociated with any RAM FrtStore.
|
398
|
+
* This FrtOutStream can be used to write temporary data too. When the time
|
399
|
+
* comes, this data can be written to another FrtOutStream (which might possibly
|
400
|
+
* be a file-system FrtOutStream) using frt_ramo_write_to.
|
405
401
|
*
|
406
|
-
* @return A newly allocated RAM
|
402
|
+
* @return A newly allocated RAM FrtOutStream
|
407
403
|
*/
|
408
|
-
extern
|
404
|
+
extern FrtOutStream *frt_ram_new_buffer();
|
409
405
|
|
410
406
|
/**
|
411
|
-
* Destroy a RAM
|
407
|
+
* Destroy a RAM FrtOutStream which is unassociated with any RAM FrtStore, freeing
|
412
408
|
* all resources allocated to it.
|
413
409
|
*
|
414
|
-
* @param os the
|
410
|
+
* @param os the FrtOutStream to destroy
|
415
411
|
*/
|
416
|
-
extern void
|
412
|
+
extern void frt_ram_destroy_buffer(FrtOutStream *os);
|
417
413
|
|
418
414
|
/**
|
419
415
|
* Call the function +func+ with the +lock+ locked. The argument +arg+ will be
|
420
416
|
* passed to +func+. If you need to pass more than one argument you should use
|
421
417
|
* a struct. When the function is finished, release the lock.
|
422
|
-
*
|
418
|
+
*
|
423
419
|
* @param lock lock to be locked while func is called
|
424
420
|
* @param func function to call with the lock locked
|
425
421
|
* @param arg argument to pass to the function
|
426
|
-
* @raise
|
427
|
-
* @see
|
422
|
+
* @raise FRT_IO_ERROR if the lock is already locked
|
423
|
+
* @see frt_with_lock_name
|
428
424
|
*/
|
429
|
-
extern void
|
425
|
+
extern void frt_with_lock(FrtLock *lock, void (*func)(void *arg), void *arg);
|
430
426
|
|
431
427
|
/**
|
432
428
|
* Create a lock in the +store+ with the name +lock_name+. Call the function
|
433
429
|
* +func+ with the lock locked. The argument +arg+ will be passed to +func+.
|
434
430
|
* If you need to pass more than one argument you should use a struct. When
|
435
431
|
* the function is finished, release and destroy the lock.
|
436
|
-
*
|
432
|
+
*
|
437
433
|
* @param store store to open the lock in
|
438
434
|
* @param lock_name name of the lock to open
|
439
435
|
* @param func function to call with the lock locked
|
440
436
|
* @param arg argument to pass to the function
|
441
|
-
* @raise
|
442
|
-
* @see
|
437
|
+
* @raise FRT_IO_ERROR if the lock is already locked
|
438
|
+
* @see frt_with_lock
|
443
439
|
*/
|
444
|
-
extern void
|
440
|
+
extern void frt_with_lock_name(FrtStore *store, const char *lock_name,
|
445
441
|
void (*func)(void *arg), void *arg);
|
446
442
|
|
447
443
|
/**
|
@@ -450,328 +446,354 @@ extern void with_lock_name(Store *store, char *lock_name,
|
|
450
446
|
*
|
451
447
|
* @param store the store to be dereferenced
|
452
448
|
*/
|
453
|
-
extern void
|
449
|
+
extern void frt_store_deref(FrtStore *store);
|
454
450
|
|
455
451
|
/**
|
456
|
-
* Flush the buffered contents of the
|
452
|
+
* Flush the buffered contents of the FrtOutStream to the store.
|
457
453
|
*
|
458
|
-
* @param os the
|
454
|
+
* @param os the FrtOutStream to flush
|
459
455
|
*/
|
460
|
-
extern void
|
456
|
+
extern void frt_os_flush(FrtOutStream *os);
|
461
457
|
|
462
458
|
/**
|
463
|
-
* Close the
|
459
|
+
* Close the FrtOutStream after flushing the buffers, also freeing all allocated
|
464
460
|
* resources.
|
465
461
|
*
|
466
|
-
* @param os the
|
462
|
+
* @param os the FrtOutStream to close
|
467
463
|
*/
|
468
|
-
extern void
|
464
|
+
extern void frt_os_close(FrtOutStream *os);
|
469
465
|
|
470
466
|
/**
|
471
|
-
* Return the current position of
|
467
|
+
* Return the current position of FrtOutStream +os+.
|
472
468
|
*
|
473
|
-
* @param os the
|
474
|
-
* @return the current position in
|
469
|
+
* @param os the FrtOutStream to get the position from
|
470
|
+
* @return the current position in FrtOutStream +os+
|
475
471
|
*/
|
476
|
-
extern off_t
|
472
|
+
extern off_t frt_os_pos(FrtOutStream *os);
|
477
473
|
|
478
474
|
/**
|
479
|
-
* Set the current position in
|
475
|
+
* Set the current position in FrtOutStream +os+.
|
480
476
|
*
|
481
|
-
* @param os the
|
482
|
-
* @param pos the new position in the
|
483
|
-
* @raise
|
477
|
+
* @param os the FrtOutStream to set the position in
|
478
|
+
* @param pos the new position in the FrtOutStream
|
479
|
+
* @raise FRT_IO_ERROR if there is a file-system IO error seeking the file
|
484
480
|
*/
|
485
|
-
extern void
|
481
|
+
extern void frt_os_seek(FrtOutStream *os, off_t new_pos);
|
486
482
|
|
487
483
|
/**
|
488
|
-
* Write a single byte +b+ to the
|
484
|
+
* Write a single byte +b+ to the FrtOutStream +os+
|
489
485
|
*
|
490
|
-
* @param os the
|
491
|
-
*
|
486
|
+
* @param os the FrtOutStream to write to @param b the byte to write @raise
|
487
|
+
* FRT_IO_ERROR if there is an IO error writing to the file-system
|
492
488
|
*/
|
493
|
-
extern void
|
489
|
+
extern void frt_os_write_byte(FrtOutStream *os, frt_uchar b);
|
494
490
|
/**
|
495
|
-
* Write +len+ bytes from buffer +buf+ to the
|
491
|
+
* Write +len+ bytes from buffer +buf+ to the FrtOutStream +os+.
|
496
492
|
*
|
497
|
-
* @param os the
|
493
|
+
* @param os the FrtOutStream to write to
|
498
494
|
* @param len the number of bytes to write
|
499
495
|
* @param buf the buffer from which to get the bytes to write.
|
500
|
-
* @raise
|
496
|
+
* @raise FRT_IO_ERROR if there is an IO error writing to the file-system
|
501
497
|
*/
|
502
|
-
extern void
|
498
|
+
extern void frt_os_write_bytes(FrtOutStream *os, const frt_uchar *buf, int len);
|
503
499
|
|
504
500
|
/**
|
505
|
-
* Write a 32-bit signed integer to the
|
501
|
+
* Write a 32-bit signed integer to the FrtOutStream
|
506
502
|
*
|
507
|
-
* @param os
|
503
|
+
* @param os FrtOutStream to write to
|
508
504
|
* @param num the 32-bit signed integer to write
|
509
|
-
* @raise
|
505
|
+
* @raise FRT_IO_ERROR if there is an error writing to the file-system
|
510
506
|
*/
|
511
|
-
extern void
|
507
|
+
extern void frt_os_write_i32(FrtOutStream *os, frt_i32 num);
|
512
508
|
|
513
509
|
/**
|
514
|
-
* Write a 64-bit signed integer to the
|
510
|
+
* Write a 64-bit signed integer to the FrtOutStream
|
515
511
|
*
|
516
512
|
*
|
517
|
-
* @param os
|
513
|
+
* @param os FrtOutStream to write to
|
518
514
|
* @param num the 64-bit signed integer to write
|
519
|
-
* @raise
|
515
|
+
* @raise FRT_IO_ERROR if there is an error writing to the file-system
|
520
516
|
*/
|
521
|
-
extern void
|
517
|
+
extern void frt_os_write_i64(FrtOutStream *os, frt_i64 num);
|
522
518
|
|
523
519
|
/**
|
524
|
-
* Write a 32-bit unsigned integer to the
|
520
|
+
* Write a 32-bit unsigned integer to the FrtOutStream
|
525
521
|
*
|
526
|
-
* @param os
|
522
|
+
* @param os FrtOutStream to write to
|
527
523
|
* @param num the 32-bit unsigned integer to write
|
528
|
-
* @raise
|
524
|
+
* @raise FRT_IO_ERROR if there is an error writing to the file-system
|
529
525
|
*/
|
530
|
-
extern void
|
526
|
+
extern void frt_os_write_u32(FrtOutStream *os, frt_u32 num);
|
531
527
|
|
532
528
|
/**
|
533
|
-
* Write a 64-bit unsigned integer to the
|
529
|
+
* Write a 64-bit unsigned integer to the FrtOutStream
|
534
530
|
*
|
535
|
-
* @param os
|
531
|
+
* @param os FrtOutStream to write to
|
536
532
|
* @param num the 64-bit unsigned integer to write
|
537
|
-
* @raise
|
533
|
+
* @raise FRT_IO_ERROR if there is an error writing to the file-system
|
538
534
|
*/
|
539
|
-
extern void
|
535
|
+
extern void frt_os_write_u64(FrtOutStream *os, frt_u64 num);
|
540
536
|
|
541
537
|
/**
|
542
|
-
* Write an unsigned integer to
|
538
|
+
* Write an unsigned integer to FrtOutStream in compressed VINT format.
|
543
539
|
* TODO: describe VINT format
|
544
540
|
*
|
545
|
-
* @param os
|
541
|
+
* @param os FrtOutStream to write to
|
546
542
|
* @param num the integer to write
|
547
|
-
* @raise
|
543
|
+
* @raise FRT_IO_ERROR if there is an error writing to the file-system
|
548
544
|
*/
|
549
|
-
extern void
|
545
|
+
extern void frt_os_write_vint(FrtOutStream *os, register unsigned int num);
|
550
546
|
|
551
547
|
/**
|
552
|
-
* Write an unsigned off_t to
|
548
|
+
* Write an unsigned off_t to FrtOutStream in compressed VINT format.
|
553
549
|
* TODO: describe VINT format
|
554
550
|
*
|
555
|
-
* @param os
|
551
|
+
* @param os FrtOutStream to write to
|
556
552
|
* @param num the off_t to write
|
557
|
-
* @raise
|
553
|
+
* @raise FRT_IO_ERROR if there is an error writing to the file-system
|
558
554
|
*/
|
559
|
-
extern void
|
555
|
+
extern void frt_os_write_voff_t(FrtOutStream *os, register off_t num);
|
560
556
|
|
561
557
|
/**
|
562
|
-
* Write an unsigned
|
558
|
+
* Write an unsigned 64bit int to FrtOutStream in compressed VINT format.
|
563
559
|
* TODO: describe VINT format
|
564
560
|
*
|
565
|
-
* @param os
|
566
|
-
* @param num the
|
567
|
-
* @raise
|
561
|
+
* @param os FrtOutStream to write to
|
562
|
+
* @param num the 64bit int to write
|
563
|
+
* @raise FRT_IO_ERROR if there is an error writing to the file-system
|
564
|
+
*/
|
565
|
+
extern void frt_os_write_vll(FrtOutStream *os, register frt_u64 num);
|
566
|
+
|
567
|
+
/**
|
568
|
+
* Write a string with known length to the FrtOutStream. A string is an
|
569
|
+
* integer +length+ in VINT format (see frt_os_write_vint) followed by
|
570
|
+
* +length+ bytes. The string can then be read using frt_is_read_string.
|
571
|
+
*
|
572
|
+
* @param os FrtOutStream to write to
|
573
|
+
* @param str the string to write
|
574
|
+
* @param len the length of the string to write
|
575
|
+
* @raise FRT_IO_ERROR if there is an error writing to the file-system
|
568
576
|
*/
|
569
|
-
extern void
|
577
|
+
extern FRT_INLINE void frt_os_write_string_len(FrtOutStream *os,
|
578
|
+
const char *str,
|
579
|
+
int len);
|
570
580
|
|
571
581
|
/**
|
572
|
-
* Write a string to the
|
573
|
-
* format (see
|
574
|
-
* be read using
|
582
|
+
* Write a string to the FrtOutStream. A string is an integer +length+ in VINT
|
583
|
+
* format (see frt_os_write_vint) followed by +length+ bytes. The string can then
|
584
|
+
* be read using frt_is_read_string.
|
575
585
|
*
|
576
|
-
* @param os
|
586
|
+
* @param os FrtOutStream to write to
|
577
587
|
* @param str the string to write
|
578
|
-
* @raise
|
588
|
+
* @raise FRT_IO_ERROR if there is an error writing to the file-system
|
579
589
|
*/
|
580
|
-
extern void
|
590
|
+
extern void frt_os_write_string(FrtOutStream *os, const char *str);
|
591
|
+
|
581
592
|
/**
|
582
|
-
* Get the current position within an
|
593
|
+
* Get the current position within an FrtInStream.
|
583
594
|
*
|
584
|
-
* @param is the
|
585
|
-
* @return the current position within the
|
595
|
+
* @param is the FrtInStream to get the current position from
|
596
|
+
* @return the current position within the FrtInStream +is+
|
586
597
|
*/
|
587
|
-
extern off_t
|
598
|
+
extern off_t frt_is_pos(FrtInStream *is);
|
588
599
|
|
589
600
|
/**
|
590
|
-
* Set the current position in
|
601
|
+
* Set the current position in FrtInStream +is+ to +pos+.
|
591
602
|
*
|
592
|
-
* @param is the
|
593
|
-
* @param pos the position in
|
594
|
-
* @raise
|
595
|
-
* @raise
|
603
|
+
* @param is the FrtInStream to set the current position in
|
604
|
+
* @param pos the position in FrtInStream to seek
|
605
|
+
* @raise FRT_IO_ERROR if there is a error seeking from the file-system
|
606
|
+
* @raise FRT_EOF_ERROR if there is an attempt to seek past the end of the file
|
596
607
|
*/
|
597
|
-
extern void
|
608
|
+
extern void frt_is_seek(FrtInStream *is, off_t pos);
|
598
609
|
|
599
610
|
/**
|
600
|
-
* Close the
|
611
|
+
* Close the FrtInStream freeing all allocated resources.
|
601
612
|
*
|
602
|
-
* @param is the
|
603
|
-
* @raise
|
613
|
+
* @param is the FrtInStream to close
|
614
|
+
* @raise FRT_IO_ERROR if there is an error closing the associated file
|
604
615
|
*/
|
605
|
-
extern void
|
616
|
+
extern void frt_is_close(FrtInStream *is);
|
606
617
|
|
607
618
|
/**
|
608
|
-
* Clone the
|
619
|
+
* Clone the FrtInStream allocating a new FrtInStream structure
|
609
620
|
*
|
610
|
-
* @param is the
|
611
|
-
* @return a newly allocated
|
621
|
+
* @param is the FrtInStream to clone
|
622
|
+
* @return a newly allocated FrtInStream which is a clone of +is+
|
612
623
|
*/
|
613
|
-
extern
|
624
|
+
extern FrtInStream *frt_is_clone(FrtInStream *is);
|
614
625
|
|
615
626
|
/**
|
616
|
-
* Read a singly byte (unsigned char) from the
|
627
|
+
* Read a singly byte (unsigned char) from the FrtInStream +is+.
|
617
628
|
*
|
618
629
|
* @param is the Instream to read from
|
619
|
-
* @return a single unsigned char read from the
|
620
|
-
* @raise
|
621
|
-
* @raise
|
630
|
+
* @return a single unsigned char read from the FrtInStream +is+
|
631
|
+
* @raise FRT_IO_ERROR if there is a error reading from the file-system
|
632
|
+
* @raise FRT_EOF_ERROR if there is an attempt to read past the end of the file
|
622
633
|
*/
|
623
|
-
extern
|
634
|
+
extern FRT_INLINE frt_uchar frt_is_read_byte(FrtInStream *is);
|
624
635
|
|
625
636
|
/**
|
626
|
-
* Read +len+ bytes from
|
637
|
+
* Read +len+ bytes from FrtInStream +is+ and write them to buffer +buf+
|
627
638
|
*
|
628
|
-
* @param is the
|
639
|
+
* @param is the FrtInStream to read from
|
629
640
|
* @param buf the buffer to read into, that is copy the bytes read to
|
630
641
|
* @param len the number of bytes to read
|
631
642
|
* @return the resultant buffer +buf+
|
632
|
-
* @raise
|
633
|
-
* @raise
|
643
|
+
* @raise FRT_IO_ERROR if there is a error reading from the file-system
|
644
|
+
* @raise FRT_EOF_ERROR if there is an attempt to read past the end of the file
|
634
645
|
*/
|
635
|
-
extern
|
646
|
+
extern frt_uchar *frt_is_read_bytes(FrtInStream *is, frt_uchar *buf, int len);
|
636
647
|
|
637
648
|
/**
|
638
|
-
* Read a 32-bit unsigned integer from the
|
649
|
+
* Read a 32-bit unsigned integer from the FrtInStream.
|
639
650
|
*
|
640
|
-
* @param is the
|
651
|
+
* @param is the FrtInStream to read from
|
641
652
|
* @return a 32-bit unsigned integer
|
642
|
-
* @raise
|
643
|
-
* @raise
|
653
|
+
* @raise FRT_IO_ERROR if there is a error reading from the file-system
|
654
|
+
* @raise FRT_EOF_ERROR if there is an attempt to read past the end of the file
|
644
655
|
*/
|
645
|
-
extern
|
656
|
+
extern frt_i32 frt_is_read_i32(FrtInStream *is);
|
646
657
|
|
647
658
|
/**
|
648
|
-
* Read a 64-bit unsigned integer from the
|
659
|
+
* Read a 64-bit unsigned integer from the FrtInStream.
|
649
660
|
*
|
650
|
-
* @param is the
|
661
|
+
* @param is the FrtInStream to read from
|
651
662
|
* @return a 64-bit unsigned integer
|
652
|
-
* @raise
|
653
|
-
* @raise
|
663
|
+
* @raise FRT_IO_ERROR if there is a error reading from the file-system
|
664
|
+
* @raise FRT_EOF_ERROR if there is an attempt to read past the end of the file
|
654
665
|
*/
|
655
|
-
extern
|
666
|
+
extern frt_i64 frt_is_read_i64(FrtInStream *is);
|
656
667
|
|
657
668
|
/**
|
658
|
-
* Read a 32-bit signed integer from the
|
669
|
+
* Read a 32-bit signed integer from the FrtInStream.
|
659
670
|
*
|
660
|
-
* @param is the
|
671
|
+
* @param is the FrtInStream to read from
|
661
672
|
* @return a 32-bit signed integer
|
662
|
-
* @raise
|
663
|
-
* @raise
|
673
|
+
* @raise FRT_IO_ERROR if there is a error reading from the file-system
|
674
|
+
* @raise FRT_EOF_ERROR if there is an attempt to read past the end of the file
|
664
675
|
*/
|
665
|
-
extern
|
676
|
+
extern frt_u32 frt_is_read_u32(FrtInStream *is);
|
666
677
|
|
667
678
|
/**
|
668
|
-
* Read a 64-bit signed integer from the
|
679
|
+
* Read a 64-bit signed integer from the FrtInStream.
|
669
680
|
*
|
670
|
-
* @param is the
|
681
|
+
* @param is the FrtInStream to read from
|
671
682
|
* @return a 64-bit signed integer
|
672
|
-
* @raise
|
673
|
-
* @raise
|
683
|
+
* @raise FRT_IO_ERROR if there is a error reading from the file-system
|
684
|
+
* @raise FRT_EOF_ERROR if there is an attempt to read past the end of the file
|
674
685
|
*/
|
675
|
-
extern
|
686
|
+
extern frt_u64 frt_is_read_u64(FrtInStream *is);
|
676
687
|
|
677
688
|
/**
|
678
|
-
* Read a compressed (VINT) unsigned integer from the
|
689
|
+
* Read a compressed (VINT) unsigned integer from the FrtInStream.
|
679
690
|
* TODO: describe VINT format
|
680
691
|
*
|
681
|
-
* @param is the
|
692
|
+
* @param is the FrtInStream to read from
|
682
693
|
* @return an int
|
683
|
-
* @raise
|
684
|
-
* @raise
|
694
|
+
* @raise FRT_IO_ERROR if there is a error reading from the file-system
|
695
|
+
* @raise FRT_EOF_ERROR if there is an attempt to read past the end of the file
|
685
696
|
*/
|
686
|
-
extern
|
697
|
+
extern FRT_INLINE unsigned int frt_is_read_vint(FrtInStream *is);
|
687
698
|
|
688
699
|
/**
|
689
700
|
* Skip _cnt_ vints. This is a convenience method used for performance reasons
|
690
701
|
* to skip large numbers of vints. It is mostly used by TermDocEnums. When
|
691
702
|
* skipping positions os the proximity index file.
|
692
703
|
*
|
693
|
-
* @param is the
|
704
|
+
* @param is the FrtInStream to read from
|
694
705
|
* @param cnt the number of vints to skip
|
695
|
-
* @raise
|
696
|
-
* @raise
|
706
|
+
* @raise FRT_IO_ERROR if there is a error reading from the file-system
|
707
|
+
* @raise FRT_EOF_ERROR if there is an attempt to read past the end of the file
|
697
708
|
*/
|
698
|
-
extern
|
709
|
+
extern FRT_INLINE void frt_is_skip_vints(FrtInStream *is, register int cnt);
|
699
710
|
|
700
711
|
/**
|
701
|
-
* Read a compressed (VINT) unsigned off_t from the
|
712
|
+
* Read a compressed (VINT) unsigned off_t from the FrtInStream.
|
702
713
|
* TODO: describe VINT format
|
703
714
|
*
|
704
|
-
* @param is the
|
715
|
+
* @param is the FrtInStream to read from
|
705
716
|
* @return a off_t
|
706
|
-
* @raise
|
707
|
-
* @raise
|
717
|
+
* @raise FRT_IO_ERROR if there is a error reading from the file-system
|
718
|
+
* @raise FRT_EOF_ERROR if there is an attempt to read past the end of the file
|
708
719
|
*/
|
709
|
-
extern
|
720
|
+
extern FRT_INLINE off_t frt_is_read_voff_t(FrtInStream *is);
|
710
721
|
|
711
722
|
/**
|
712
|
-
* Read a compressed (VINT) unsigned
|
723
|
+
* Read a compressed (VINT) unsigned 64bit int from the FrtInStream.
|
713
724
|
* TODO: describe VINT format
|
714
725
|
*
|
715
|
-
* @param is the
|
716
|
-
* @return a
|
717
|
-
* @raise
|
718
|
-
* @raise
|
726
|
+
* @param is the FrtInStream to read from
|
727
|
+
* @return a 64bit int
|
728
|
+
* @raise FRT_IO_ERROR if there is a error reading from the file-system
|
729
|
+
* @raise FRT_EOF_ERROR if there is an attempt to read past the end of the file
|
719
730
|
*/
|
720
|
-
extern
|
731
|
+
extern FRT_INLINE frt_u64 frt_is_read_vll(FrtInStream *is);
|
721
732
|
|
722
733
|
/**
|
723
|
-
* Read a string from the
|
724
|
-
* format (see
|
725
|
-
* used by
|
734
|
+
* Read a string from the FrtInStream. A string is an integer +length+ in vint
|
735
|
+
* format (see frt_is_read_vint) followed by +length+ bytes. This is the format
|
736
|
+
* used by frt_os_write_string.
|
726
737
|
*
|
727
|
-
* @param is the
|
738
|
+
* @param is the FrtInStream to read from
|
728
739
|
* @return a null byte delimited string
|
729
|
-
* @raise
|
730
|
-
* @raise
|
740
|
+
* @raise FRT_IO_ERROR if there is a error reading from the file-system
|
741
|
+
* @raise FRT_EOF_ERROR if there is an attempt to read past the end of the file
|
731
742
|
*/
|
732
|
-
extern char *
|
743
|
+
extern char *frt_is_read_string(FrtInStream *is);
|
733
744
|
|
734
745
|
/**
|
735
|
-
* Read a string from the
|
736
|
-
* format (see
|
737
|
-
* used by
|
746
|
+
* Read a string from the FrtInStream. A string is an integer +length+ in vint
|
747
|
+
* format (see frt_is_read_vint) followed by +length+ bytes. This is the format
|
748
|
+
* used by frt_os_write_string. This method is similar to +frt_is_read_string+ except
|
738
749
|
* that it will safely free all memory if there is an error reading the
|
739
750
|
* string.
|
740
751
|
*
|
741
|
-
* @param is the
|
752
|
+
* @param is the FrtInStream to read from
|
742
753
|
* @return a null byte delimited string
|
743
|
-
* @raise
|
744
|
-
* @raise
|
754
|
+
* @raise FRT_IO_ERROR if there is a error reading from the file-system
|
755
|
+
* @raise FRT_EOF_ERROR if there is an attempt to read past the end of the file
|
745
756
|
*/
|
746
|
-
extern char *
|
757
|
+
extern char *frt_is_read_string_safe(FrtInStream *is);
|
747
758
|
|
748
759
|
/**
|
749
|
-
* Copy cnt bytes from Instream _is_ to
|
760
|
+
* Copy cnt bytes from Instream _is_ to FrtOutStream _os_.
|
750
761
|
*
|
751
|
-
* @param is the
|
752
|
-
* @param os the
|
753
|
-
* @raise
|
754
|
-
* @raise
|
762
|
+
* @param is the FrtInStream to read from
|
763
|
+
* @param os the FrtOutStream to write to
|
764
|
+
* @raise FRT_IO_ERROR
|
765
|
+
* @raise FRT_EOF_ERROR
|
755
766
|
*/
|
756
|
-
extern void
|
767
|
+
extern void frt_is2os_copy_bytes(FrtInStream *is, FrtOutStream *os, int cnt);
|
757
768
|
|
758
769
|
/**
|
759
|
-
* Copy cnt vints from Instream _is_ to
|
770
|
+
* Copy cnt vints from Instream _is_ to FrtOutStream _os_.
|
760
771
|
*
|
761
|
-
* @param is the
|
762
|
-
* @param os the
|
763
|
-
* @raise
|
764
|
-
* @raise
|
772
|
+
* @param is the FrtInStream to read from
|
773
|
+
* @param os the FrtOutStream to write to
|
774
|
+
* @raise FRT_IO_ERROR
|
775
|
+
* @raise FRT_EOF_ERROR
|
765
776
|
*/
|
766
|
-
extern void
|
777
|
+
extern void frt_is2os_copy_vints(FrtInStream *is, FrtOutStream *os, int cnt);
|
767
778
|
|
768
779
|
/**
|
769
780
|
* Print the filenames in a store to a buffer.
|
770
781
|
*
|
771
782
|
* @param store the store to get the filenames from
|
772
783
|
*/
|
773
|
-
extern char *
|
784
|
+
extern char *frt_store_to_s(FrtStore *store);
|
785
|
+
|
786
|
+
extern FrtLock *frt_open_lock(FrtStore *store, const char *lockname);
|
787
|
+
extern void frt_close_lock(FrtLock *lock);
|
788
|
+
|
789
|
+
/* required by submodules
|
790
|
+
* FIXME document. Perhaps include in different header?? */
|
791
|
+
extern FrtStore *frt_store_new();
|
792
|
+
extern void frt_store_destroy(FrtStore *store);
|
793
|
+
extern FrtOutStream *frt_os_new();
|
794
|
+
extern FrtInStream *frt_is_new();
|
795
|
+
extern int frt_file_is_lock(const char *filename);
|
796
|
+
extern bool frt_file_name_filter_is_index_file(const char *file_name,
|
797
|
+
bool include_locks);
|
774
798
|
|
775
|
-
extern Lock *open_lock(Store *store, char *lockname);
|
776
|
-
extern void close_lock(Lock *lock);
|
777
799
|
#endif
|