sdsykes-ferret 0.11.6.19

Sign up to get free protection for your applications and to get access to all the features.
Files changed (195) hide show
  1. data/CHANGELOG +24 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README +102 -0
  4. data/Rakefile +338 -0
  5. data/TODO +17 -0
  6. data/TUTORIAL +231 -0
  7. data/bin/ferret-browser +79 -0
  8. data/ext/analysis.c +1555 -0
  9. data/ext/analysis.h +219 -0
  10. data/ext/api.c +69 -0
  11. data/ext/api.h +27 -0
  12. data/ext/array.c +123 -0
  13. data/ext/array.h +53 -0
  14. data/ext/bitvector.c +540 -0
  15. data/ext/bitvector.h +272 -0
  16. data/ext/compound_io.c +383 -0
  17. data/ext/config.h +42 -0
  18. data/ext/document.c +156 -0
  19. data/ext/document.h +53 -0
  20. data/ext/except.c +120 -0
  21. data/ext/except.h +168 -0
  22. data/ext/extconf.rb +14 -0
  23. data/ext/ferret.c +402 -0
  24. data/ext/ferret.h +91 -0
  25. data/ext/filter.c +156 -0
  26. data/ext/fs_store.c +483 -0
  27. data/ext/global.c +418 -0
  28. data/ext/global.h +117 -0
  29. data/ext/hash.c +567 -0
  30. data/ext/hash.h +473 -0
  31. data/ext/hashset.c +170 -0
  32. data/ext/hashset.h +187 -0
  33. data/ext/header.h +58 -0
  34. data/ext/helper.c +62 -0
  35. data/ext/helper.h +13 -0
  36. data/ext/inc/lang.h +48 -0
  37. data/ext/inc/threading.h +31 -0
  38. data/ext/index.c +6425 -0
  39. data/ext/index.h +961 -0
  40. data/ext/lang.h +66 -0
  41. data/ext/libstemmer.c +92 -0
  42. data/ext/libstemmer.h +79 -0
  43. data/ext/mempool.c +87 -0
  44. data/ext/mempool.h +35 -0
  45. data/ext/modules.h +162 -0
  46. data/ext/multimapper.c +310 -0
  47. data/ext/multimapper.h +51 -0
  48. data/ext/posh.c +1006 -0
  49. data/ext/posh.h +1007 -0
  50. data/ext/priorityqueue.c +151 -0
  51. data/ext/priorityqueue.h +143 -0
  52. data/ext/q_boolean.c +1608 -0
  53. data/ext/q_const_score.c +161 -0
  54. data/ext/q_filtered_query.c +209 -0
  55. data/ext/q_fuzzy.c +268 -0
  56. data/ext/q_match_all.c +148 -0
  57. data/ext/q_multi_term.c +677 -0
  58. data/ext/q_parser.c +2825 -0
  59. data/ext/q_phrase.c +1126 -0
  60. data/ext/q_prefix.c +100 -0
  61. data/ext/q_range.c +350 -0
  62. data/ext/q_span.c +2402 -0
  63. data/ext/q_term.c +337 -0
  64. data/ext/q_wildcard.c +171 -0
  65. data/ext/r_analysis.c +2575 -0
  66. data/ext/r_index.c +3472 -0
  67. data/ext/r_qparser.c +585 -0
  68. data/ext/r_search.c +4105 -0
  69. data/ext/r_store.c +513 -0
  70. data/ext/r_utils.c +963 -0
  71. data/ext/ram_store.c +471 -0
  72. data/ext/search.c +1741 -0
  73. data/ext/search.h +885 -0
  74. data/ext/similarity.c +150 -0
  75. data/ext/similarity.h +82 -0
  76. data/ext/sort.c +983 -0
  77. data/ext/stem_ISO_8859_1_danish.c +338 -0
  78. data/ext/stem_ISO_8859_1_danish.h +16 -0
  79. data/ext/stem_ISO_8859_1_dutch.c +635 -0
  80. data/ext/stem_ISO_8859_1_dutch.h +16 -0
  81. data/ext/stem_ISO_8859_1_english.c +1156 -0
  82. data/ext/stem_ISO_8859_1_english.h +16 -0
  83. data/ext/stem_ISO_8859_1_finnish.c +792 -0
  84. data/ext/stem_ISO_8859_1_finnish.h +16 -0
  85. data/ext/stem_ISO_8859_1_french.c +1276 -0
  86. data/ext/stem_ISO_8859_1_french.h +16 -0
  87. data/ext/stem_ISO_8859_1_german.c +512 -0
  88. data/ext/stem_ISO_8859_1_german.h +16 -0
  89. data/ext/stem_ISO_8859_1_italian.c +1091 -0
  90. data/ext/stem_ISO_8859_1_italian.h +16 -0
  91. data/ext/stem_ISO_8859_1_norwegian.c +296 -0
  92. data/ext/stem_ISO_8859_1_norwegian.h +16 -0
  93. data/ext/stem_ISO_8859_1_porter.c +776 -0
  94. data/ext/stem_ISO_8859_1_porter.h +16 -0
  95. data/ext/stem_ISO_8859_1_portuguese.c +1035 -0
  96. data/ext/stem_ISO_8859_1_portuguese.h +16 -0
  97. data/ext/stem_ISO_8859_1_spanish.c +1119 -0
  98. data/ext/stem_ISO_8859_1_spanish.h +16 -0
  99. data/ext/stem_ISO_8859_1_swedish.c +307 -0
  100. data/ext/stem_ISO_8859_1_swedish.h +16 -0
  101. data/ext/stem_KOI8_R_russian.c +701 -0
  102. data/ext/stem_KOI8_R_russian.h +16 -0
  103. data/ext/stem_UTF_8_danish.c +344 -0
  104. data/ext/stem_UTF_8_danish.h +16 -0
  105. data/ext/stem_UTF_8_dutch.c +653 -0
  106. data/ext/stem_UTF_8_dutch.h +16 -0
  107. data/ext/stem_UTF_8_english.c +1176 -0
  108. data/ext/stem_UTF_8_english.h +16 -0
  109. data/ext/stem_UTF_8_finnish.c +808 -0
  110. data/ext/stem_UTF_8_finnish.h +16 -0
  111. data/ext/stem_UTF_8_french.c +1296 -0
  112. data/ext/stem_UTF_8_french.h +16 -0
  113. data/ext/stem_UTF_8_german.c +526 -0
  114. data/ext/stem_UTF_8_german.h +16 -0
  115. data/ext/stem_UTF_8_italian.c +1113 -0
  116. data/ext/stem_UTF_8_italian.h +16 -0
  117. data/ext/stem_UTF_8_norwegian.c +302 -0
  118. data/ext/stem_UTF_8_norwegian.h +16 -0
  119. data/ext/stem_UTF_8_porter.c +794 -0
  120. data/ext/stem_UTF_8_porter.h +16 -0
  121. data/ext/stem_UTF_8_portuguese.c +1055 -0
  122. data/ext/stem_UTF_8_portuguese.h +16 -0
  123. data/ext/stem_UTF_8_russian.c +709 -0
  124. data/ext/stem_UTF_8_russian.h +16 -0
  125. data/ext/stem_UTF_8_spanish.c +1137 -0
  126. data/ext/stem_UTF_8_spanish.h +16 -0
  127. data/ext/stem_UTF_8_swedish.c +313 -0
  128. data/ext/stem_UTF_8_swedish.h +16 -0
  129. data/ext/stopwords.c +401 -0
  130. data/ext/store.c +692 -0
  131. data/ext/store.h +777 -0
  132. data/ext/term_vectors.c +352 -0
  133. data/ext/threading.h +31 -0
  134. data/ext/utilities.c +446 -0
  135. data/ext/win32.h +54 -0
  136. data/lib/ferret.rb +29 -0
  137. data/lib/ferret/browser.rb +246 -0
  138. data/lib/ferret/browser/s/global.js +192 -0
  139. data/lib/ferret/browser/s/style.css +148 -0
  140. data/lib/ferret/browser/views/document/list.rhtml +49 -0
  141. data/lib/ferret/browser/views/document/show.rhtml +27 -0
  142. data/lib/ferret/browser/views/error/index.rhtml +7 -0
  143. data/lib/ferret/browser/views/help/index.rhtml +8 -0
  144. data/lib/ferret/browser/views/home/index.rhtml +29 -0
  145. data/lib/ferret/browser/views/layout.rhtml +22 -0
  146. data/lib/ferret/browser/views/term-vector/index.rhtml +4 -0
  147. data/lib/ferret/browser/views/term/index.rhtml +199 -0
  148. data/lib/ferret/browser/views/term/termdocs.rhtml +1 -0
  149. data/lib/ferret/browser/webrick.rb +14 -0
  150. data/lib/ferret/document.rb +130 -0
  151. data/lib/ferret/field_infos.rb +44 -0
  152. data/lib/ferret/index.rb +786 -0
  153. data/lib/ferret/number_tools.rb +157 -0
  154. data/lib/ferret_version.rb +3 -0
  155. data/setup.rb +1555 -0
  156. data/test/test_all.rb +5 -0
  157. data/test/test_helper.rb +24 -0
  158. data/test/threading/number_to_spoken.rb +132 -0
  159. data/test/threading/thread_safety_index_test.rb +79 -0
  160. data/test/threading/thread_safety_read_write_test.rb +76 -0
  161. data/test/threading/thread_safety_test.rb +133 -0
  162. data/test/unit/analysis/tc_analyzer.rb +548 -0
  163. data/test/unit/analysis/tc_token_stream.rb +646 -0
  164. data/test/unit/index/tc_index.rb +762 -0
  165. data/test/unit/index/tc_index_reader.rb +699 -0
  166. data/test/unit/index/tc_index_writer.rb +437 -0
  167. data/test/unit/index/th_doc.rb +315 -0
  168. data/test/unit/largefile/tc_largefile.rb +46 -0
  169. data/test/unit/query_parser/tc_query_parser.rb +238 -0
  170. data/test/unit/search/tc_filter.rb +135 -0
  171. data/test/unit/search/tc_fuzzy_query.rb +147 -0
  172. data/test/unit/search/tc_index_searcher.rb +61 -0
  173. data/test/unit/search/tc_multi_searcher.rb +128 -0
  174. data/test/unit/search/tc_multiple_search_requests.rb +58 -0
  175. data/test/unit/search/tc_search_and_sort.rb +179 -0
  176. data/test/unit/search/tc_sort.rb +49 -0
  177. data/test/unit/search/tc_sort_field.rb +27 -0
  178. data/test/unit/search/tc_spans.rb +190 -0
  179. data/test/unit/search/tm_searcher.rb +384 -0
  180. data/test/unit/store/tc_fs_store.rb +77 -0
  181. data/test/unit/store/tc_ram_store.rb +35 -0
  182. data/test/unit/store/tm_store.rb +34 -0
  183. data/test/unit/store/tm_store_lock.rb +68 -0
  184. data/test/unit/tc_document.rb +81 -0
  185. data/test/unit/ts_analysis.rb +2 -0
  186. data/test/unit/ts_index.rb +2 -0
  187. data/test/unit/ts_largefile.rb +4 -0
  188. data/test/unit/ts_query_parser.rb +2 -0
  189. data/test/unit/ts_search.rb +2 -0
  190. data/test/unit/ts_store.rb +2 -0
  191. data/test/unit/ts_utils.rb +2 -0
  192. data/test/unit/utils/tc_bit_vector.rb +295 -0
  193. data/test/unit/utils/tc_number_tools.rb +117 -0
  194. data/test/unit/utils/tc_priority_queue.rb +106 -0
  195. metadata +285 -0
@@ -0,0 +1,777 @@
1
+ #ifndef FRT_STORE_H
2
+ #define FRT_STORE_H
3
+
4
+ #include <sys/types.h>
5
+ #include "global.h"
6
+ #include "hash.h"
7
+ #include "hashset.h"
8
+ #include "threading.h"
9
+
10
+ #define BUFFER_SIZE 1024
11
+ #define LOCK_PREFIX "ferret-"
12
+ #define LOCK_EXT ".lck"
13
+
14
+ #define VINT_MAX_LEN 10
15
+ #define VINT_END BUFFER_SIZE - VINT_MAX_LEN
16
+
17
+ typedef struct Buffer
18
+ {
19
+ uchar buf[BUFFER_SIZE];
20
+ off_t start;
21
+ off_t pos;
22
+ off_t len;
23
+ } Buffer;
24
+
25
+ typedef struct OutStream OutStream;
26
+ struct OutStreamMethods {
27
+ /* internal functions for the InStream */
28
+ /**
29
+ * Flush +len+ characters from +src+ to the output stream +os+
30
+ *
31
+ * @param os self
32
+ * @param src the characters to write to the output stream
33
+ * @param len the number of characters to write
34
+ * @raise IO_ERROR if there is an error writing the characters
35
+ */
36
+ void (*flush_i)(struct OutStream *os, uchar *buf, int len);
37
+
38
+ /**
39
+ * Seek +pos+ in the output stream
40
+ *
41
+ * @param os self
42
+ * @param pos the position to seek in the stream
43
+ * @raise IO_ERROR if there is an error seeking in the output stream
44
+ */
45
+ void (*seek_i)(struct OutStream *os, off_t pos);
46
+
47
+ /**
48
+ * Close any resources used by the output stream +os+
49
+ *
50
+ * @param os self
51
+ * @raise IO_ERROR if there is an closing the file
52
+ */
53
+ void (*close_i)(struct OutStream *os);
54
+ };
55
+
56
+ typedef struct RAMFile
57
+ {
58
+ char *name;
59
+ uchar **buffers;
60
+ int bufcnt;
61
+ off_t len;
62
+ int ref_cnt;
63
+ } RAMFile;
64
+
65
+ struct OutStream
66
+ {
67
+ Buffer buf;
68
+ union
69
+ {
70
+ int fd;
71
+ RAMFile *rf;
72
+ } file;
73
+ off_t pointer; /* only used by RAMOut */
74
+ const struct OutStreamMethods *m;
75
+ };
76
+
77
+ typedef struct CompoundInStream CompoundInStream;
78
+
79
+ typedef struct InStream InStream;
80
+
81
+ struct InStreamMethods
82
+ {
83
+ /**
84
+ * Read +len+ characters from the input stream into the +offset+ position in
85
+ * +buf+, an array of unsigned characters.
86
+ *
87
+ * @param is self
88
+ * @param buf an array of characters which must be allocated with at least
89
+ * +offset+ + +len+ bytes
90
+ * @param len the number of bytes to read
91
+ * @raise IO_ERROR if there is an error reading from the input stream
92
+ */
93
+ void (*read_i)(struct InStream *is, uchar *buf, int len);
94
+
95
+ /**
96
+ * Seek position +pos+ in input stream +is+
97
+ *
98
+ * @param is self
99
+ * @param pos the position to seek
100
+ * @raise IO_ERROR if the seek fails
101
+ */
102
+ void (*seek_i)(struct InStream *is, off_t pos);
103
+
104
+ /**
105
+ * Returns the length of the input stream +is+
106
+ *
107
+ * @param is self
108
+ * @raise IO_ERROR if there is an error getting the file length
109
+ */
110
+ off_t (*length_i)(struct InStream *is);
111
+
112
+ /**
113
+ * Close the resources allocated to the inputstream +is+
114
+ *
115
+ * @param is self
116
+ * @raise IO_ERROR if the close fails
117
+ */
118
+ void (*close_i)(struct InStream *is);
119
+ };
120
+
121
+ struct InStream
122
+ {
123
+ Buffer buf;
124
+ union
125
+ {
126
+ int fd;
127
+ RAMFile *rf;
128
+ } file;
129
+ union
130
+ {
131
+ off_t pointer; /* only used by RAMIn */
132
+ char *path; /* only used by FSIn */
133
+ CompoundInStream *cis;
134
+ } d;
135
+ int *ref_cnt_ptr;
136
+ const struct InStreamMethods *m;
137
+ };
138
+
139
+ struct CompoundInStream
140
+ {
141
+ InStream *sub;
142
+ off_t offset;
143
+ off_t length;
144
+ };
145
+
146
+ #define is_length(mis) mis->m->length_i(mis)
147
+
148
+ typedef struct Store Store;
149
+ typedef struct Lock Lock;
150
+ struct Lock
151
+ {
152
+ char *name;
153
+ Store *store;
154
+ int (*obtain)(Lock *lock);
155
+ int (*is_locked)(Lock *lock);
156
+ void (*release)(Lock *lock);
157
+ };
158
+
159
+ typedef struct CompoundStore
160
+ {
161
+ Store *store;
162
+ const char *name;
163
+ HashTable *entries;
164
+ InStream *stream;
165
+ } CompoundStore;
166
+
167
+ struct Store
168
+ {
169
+ int ref_cnt; /* for fs_store only */
170
+ mutex_t mutex_i; /* for internal use only */
171
+ mutex_t mutex; /* external mutex for use outside */
172
+ union
173
+ {
174
+ char *path; /* for fs_store only */
175
+ HashTable *ht; /* for ram_store only */
176
+ CompoundStore *cmpd; /* for compound_store only */
177
+ } dir;
178
+
179
+ #ifdef POSH_OS_WIN32
180
+ int file_mode;
181
+ #else
182
+ mode_t file_mode;
183
+ #endif
184
+ HashSet *locks;
185
+
186
+ /**
187
+ * Create the file +filename+ in the +store+.
188
+ *
189
+ * @param store self
190
+ * @param filename the name of the file to create
191
+ * @raise IO_ERROR if the file cannot be created
192
+ */
193
+ void (*touch)(Store *store, char *filename);
194
+
195
+ /**
196
+ * Return true if a file of name +filename+ exists in +store+.
197
+ *
198
+ * @param store self
199
+ * @param filename the name of the file to check for
200
+ * @returns true if the file exists
201
+ * @raise IO_ERROR if there is an error checking for the files existance
202
+ */
203
+ int (*exists)(Store *store, char *filename);
204
+
205
+ /**
206
+ * Remove the file +filename+ from the +store+
207
+ *
208
+ * @param store self
209
+ * @param filename the name of the file to remove
210
+ * @returns On success, zero is returned. On error, -1 is returned, and errno
211
+ * is set appropriately.
212
+ */
213
+ int (*remove)(Store *store, char *filename);
214
+
215
+ /**
216
+ * Rename the file in the +store+ from the name +from+ to the name +to+.
217
+ *
218
+ * @param store self
219
+ * @param from the name of the file to rename
220
+ * @param to the new name of the file
221
+ * @raise IO_ERROR if there is an error renaming the file
222
+ */
223
+ void (*rename)(Store *store, char *from, char *to);
224
+
225
+ /**
226
+ * Returns the number of files in the store.
227
+ *
228
+ * @param store self
229
+ * @return the number of files in the store
230
+ * @raise IO_ERROR if there is an error opening the directory
231
+ */
232
+ int (*count)(Store *store);
233
+
234
+ /**
235
+ * Call the function +func+ with each filename in the store and the arg
236
+ * that you passed. If you need to open the file you should pass the store
237
+ * as the argument. If you need to pass more than one argument, you should
238
+ * pass a struct.
239
+ *
240
+ * @param store self
241
+ * @param func the function to call with each files name and the +arg+
242
+ * passed
243
+ * @param arg the argument to pass to the function
244
+ * @raise IO_ERROR if there is an error opening the directory
245
+ */
246
+ void (*each)(Store *store, void (*func)(char *fname, void *arg),
247
+ void *arg);
248
+
249
+ /**
250
+ * Clear all the locks in the store.
251
+ *
252
+ * @param store self
253
+ * @raise IO_ERROR if there is an error opening the directory
254
+ */
255
+ void (*clear_locks)(Store *store);
256
+
257
+ /**
258
+ * Clear all files from the store except the lock files.
259
+ *
260
+ * @param store self
261
+ * @raise IO_ERROR if there is an error deleting the files
262
+ */
263
+ void (*clear)(Store *store);
264
+
265
+ /**
266
+ * Clear all files from the store including the lock files.
267
+ *
268
+ * @param store self
269
+ * @raise IO_ERROR if there is an error deleting the files
270
+ */
271
+ void (*clear_all)(Store *store);
272
+
273
+ /**
274
+ * Return the length of the file +filename+ in +store+
275
+ *
276
+ * @param store self
277
+ * @param the name of the file to check the length of
278
+ * @return the length of the file in bytes
279
+ * @raise IO_ERROR if there is an error checking the file length
280
+ */
281
+ off_t (*length)(Store *store, char *filename);
282
+
283
+ /**
284
+ * Allocate the resources needed for the output stream in the +store+ with
285
+ * the name +filename+
286
+ *
287
+ * @param store self
288
+ * @param filename the name of the output stream
289
+ * @return a newly allocated filestream
290
+ * @raise IO_ERROR if there is an error opening the output stream
291
+ * resources
292
+ */
293
+ OutStream *(*new_output)(Store *store, const char *filename);
294
+
295
+ /**
296
+ * Open an input stream in the +store+ with the name +filename+
297
+ *
298
+ * @param store self
299
+ * @param filename the name of the input stream
300
+ * @raise FILE_NOT_FOUND_ERROR if the input stream cannot be opened
301
+ */
302
+ InStream *(*open_input)(Store *store, const char *filename);
303
+
304
+ /**
305
+ * Obtain a lock on the lock +lock+
306
+ *
307
+ * @param store self
308
+ * @param lock the lock to obtain
309
+ */
310
+ Lock *(*open_lock_i)(Store *store, char *lockname);
311
+
312
+ /**
313
+ * Returns true if +lock+ is locked. To test if the file is locked:wq
314
+ *
315
+ * @param lock the lock to test
316
+ * @raise IO_ERROR if there is an error detecting the lock status
317
+ */
318
+ void (*close_lock_i)(Lock *lock);
319
+
320
+ /**
321
+ * Internal function to close the store freeing implementation specific
322
+ * resources.
323
+ *
324
+ * @param store self
325
+ */
326
+ void (*close_i)(Store *store);
327
+ };
328
+
329
+ /**
330
+ * Create a newly allocated file-system Store at the pathname designated. The
331
+ * pathname must be the name of an existing directory.
332
+ *
333
+ * @param pathname the pathname of the directory to be used by the index
334
+ * @return a newly allocated file-system Store.
335
+ */
336
+ extern Store *open_fs_store(const char *pathname);
337
+
338
+ /**
339
+ * Create a newly allocated in-memory or RAM Store.
340
+ *
341
+ * @return a newly allocated RAM Store.
342
+ */
343
+ extern Store *open_ram_store();
344
+
345
+ /**
346
+ * Create a newly allocated in-memory or RAM Store. Copy the contents of
347
+ * another store into this store. Then close the other store if required. This
348
+ * method would be used for example to read an index into memory for faster
349
+ * searching.
350
+ *
351
+ * @param store the whose contents will be copied into the newly allocated RAM
352
+ * store
353
+ * @param close_store close the store whose contents where copied
354
+ * @return a newly allocated RAM Store.
355
+ */
356
+ extern Store *open_ram_store_and_copy(Store *store, bool close_store);
357
+
358
+ /**
359
+ * Open a compound store. This is basically store which is stored within a
360
+ * single file and can in turn be stored within either a FileSystem or RAM
361
+ * store.
362
+ *
363
+ * @param store the store within which this compound store will be stored
364
+ * @param filename the name of the file in which to store the compound store
365
+ * @return a newly allocated Compound Store.
366
+ */
367
+ extern Store *open_cmpd_store(Store *store, const char *filename);
368
+
369
+ /*
370
+ * == RamStore functions ==
371
+ *
372
+ * These functions or optimizations to be used when you know you are using a
373
+ * Ram OutStream.
374
+ */
375
+
376
+ /**
377
+ * Return the length of the OutStream in bytes.
378
+ *
379
+ * @param os the OutStream who's length you want
380
+ * @return the length of +os+ in bytes
381
+ */
382
+ extern off_t ramo_length(OutStream *os);
383
+
384
+ /**
385
+ * Reset the OutStream removing any data written to it. Since it is a RAM
386
+ * file, all that needs to be done is set the length to 0.
387
+ *
388
+ * @param os the OutStream to reset
389
+ */
390
+ extern void ramo_reset(OutStream *os);
391
+
392
+ /**
393
+ * Write the contents of a RAM OutStream to another OutStream.
394
+ *
395
+ * @param from_os the OutStream to write from
396
+ * @param to_os the OutStream to write to
397
+ */
398
+ extern void ramo_write_to(OutStream *from_os, OutStream *to_os);
399
+
400
+ /**
401
+ * Create a buffer RAM OutStream which is unassociated with any RAM Store.
402
+ * This OutStream can be used to write temporary data too. When the time
403
+ * comes, this data can be written to another OutStream (which might possibly
404
+ * be a file-system OutStream) using ramo_write_to.
405
+ *
406
+ * @return A newly allocated RAM OutStream
407
+ */
408
+ extern OutStream *ram_new_buffer();
409
+
410
+ /**
411
+ * Destroy a RAM OutStream which is unassociated with any RAM Store, freeing
412
+ * all resources allocated to it.
413
+ *
414
+ * @param os the OutStream to destroy
415
+ */
416
+ extern void ram_destroy_buffer(OutStream *os);
417
+
418
+ /**
419
+ * Call the function +func+ with the +lock+ locked. The argument +arg+ will be
420
+ * passed to +func+. If you need to pass more than one argument you should use
421
+ * a struct. When the function is finished, release the lock.
422
+ *
423
+ * @param lock lock to be locked while func is called
424
+ * @param func function to call with the lock locked
425
+ * @param arg argument to pass to the function
426
+ * @raise IO_ERROR if the lock is already locked
427
+ * @see with_lock_name
428
+ */
429
+ extern void with_lock(Lock *lock, void (*func)(void *arg), void *arg);
430
+
431
+ /**
432
+ * Create a lock in the +store+ with the name +lock_name+. Call the function
433
+ * +func+ with the lock locked. The argument +arg+ will be passed to +func+.
434
+ * If you need to pass more than one argument you should use a struct. When
435
+ * the function is finished, release and destroy the lock.
436
+ *
437
+ * @param store store to open the lock in
438
+ * @param lock_name name of the lock to open
439
+ * @param func function to call with the lock locked
440
+ * @param arg argument to pass to the function
441
+ * @raise IO_ERROR if the lock is already locked
442
+ * @see with_lock
443
+ */
444
+ extern void with_lock_name(Store *store, char *lock_name,
445
+ void (*func)(void *arg), void *arg);
446
+
447
+ /**
448
+ * Remove a reference to the store. If the reference count gets to zero free
449
+ * all resources used by the store.
450
+ *
451
+ * @param store the store to be dereferenced
452
+ */
453
+ extern void store_deref(Store *store);
454
+
455
+ /**
456
+ * Flush the buffered contents of the OutStream to the store.
457
+ *
458
+ * @param os the OutStream to flush
459
+ */
460
+ extern void os_flush(OutStream *os);
461
+
462
+ /**
463
+ * Close the OutStream after flushing the buffers, also freeing all allocated
464
+ * resources.
465
+ *
466
+ * @param os the OutStream to close
467
+ */
468
+ extern void os_close(OutStream *os);
469
+
470
+ /**
471
+ * Return the current position of OutStream +os+.
472
+ *
473
+ * @param os the OutStream to get the position from
474
+ * @return the current position in OutStream +os+
475
+ */
476
+ extern off_t os_pos(OutStream *os);
477
+
478
+ /**
479
+ * Set the current position in OutStream +os+.
480
+ *
481
+ * @param os the OutStream to set the position in
482
+ * @param pos the new position in the OutStream
483
+ * @raise IO_ERROR if there is a file-system IO error seeking the file
484
+ */
485
+ extern void os_seek(OutStream *os, off_t new_pos);
486
+
487
+ /**
488
+ * Write a single byte +b+ to the OutStream +os+
489
+ *
490
+ * @param os the OutStream to write to @param b the byte to write @raise
491
+ * IO_ERROR if there is an IO error writing to the file-system
492
+ */
493
+ extern void os_write_byte(OutStream *os, uchar b);
494
+ /**
495
+ * Write +len+ bytes from buffer +buf+ to the OutStream +os+.
496
+ *
497
+ * @param os the OutStream to write to
498
+ * @param len the number of bytes to write
499
+ * @param buf the buffer from which to get the bytes to write.
500
+ * @raise IO_ERROR if there is an IO error writing to the file-system
501
+ */
502
+ extern void os_write_bytes(OutStream *os, uchar *buf, int len);
503
+
504
+ /**
505
+ * Write a 32-bit signed integer to the OutStream
506
+ *
507
+ * @param os OutStream to write to
508
+ * @param num the 32-bit signed integer to write
509
+ * @raise IO_ERROR if there is an error writing to the file-system
510
+ */
511
+ extern void os_write_i32(OutStream *os, f_i32 num);
512
+
513
+ /**
514
+ * Write a 64-bit signed integer to the OutStream
515
+ *
516
+ *
517
+ * @param os OutStream to write to
518
+ * @param num the 64-bit signed integer to write
519
+ * @raise IO_ERROR if there is an error writing to the file-system
520
+ */
521
+ extern void os_write_i64(OutStream *os, f_i64 num);
522
+
523
+ /**
524
+ * Write a 32-bit unsigned integer to the OutStream
525
+ *
526
+ * @param os OutStream to write to
527
+ * @param num the 32-bit unsigned integer to write
528
+ * @raise IO_ERROR if there is an error writing to the file-system
529
+ */
530
+ extern void os_write_u32(OutStream *os, f_u32 num);
531
+
532
+ /**
533
+ * Write a 64-bit unsigned integer to the OutStream
534
+ *
535
+ * @param os OutStream to write to
536
+ * @param num the 64-bit unsigned integer to write
537
+ * @raise IO_ERROR if there is an error writing to the file-system
538
+ */
539
+ extern void os_write_u64(OutStream *os, f_u64 num);
540
+
541
+ /**
542
+ * Write an unsigned integer to OutStream in compressed VINT format.
543
+ * TODO: describe VINT format
544
+ *
545
+ * @param os OutStream to write to
546
+ * @param num the integer to write
547
+ * @raise IO_ERROR if there is an error writing to the file-system
548
+ */
549
+ extern void os_write_vint(OutStream *os, register unsigned int num);
550
+
551
+ /**
552
+ * Write an unsigned off_t to OutStream in compressed VINT format.
553
+ * TODO: describe VINT format
554
+ *
555
+ * @param os OutStream to write to
556
+ * @param num the off_t to write
557
+ * @raise IO_ERROR if there is an error writing to the file-system
558
+ */
559
+ extern void os_write_voff_t(OutStream *os, register off_t num);
560
+
561
+ /**
562
+ * Write an unsigned long long to OutStream in compressed VINT format.
563
+ * TODO: describe VINT format
564
+ *
565
+ * @param os OutStream to write to
566
+ * @param num the long long to write
567
+ * @raise IO_ERROR if there is an error writing to the file-system
568
+ */
569
+ extern void os_write_vll(OutStream *os, register unsigned long long num);
570
+
571
+ /**
572
+ * Write a string to the OutStream. A string is an integer +length+ in VINT
573
+ * format (see os_write_vint) followed by +length+ bytes. The string can then
574
+ * be read using is_read_string.
575
+ *
576
+ * @param os OutStream to write to
577
+ * @param str the string to write
578
+ * @raise IO_ERROR if there is an error writing to the file-system
579
+ */
580
+ extern void os_write_string(OutStream *os, char *str);
581
+ /**
582
+ * Get the current position within an InStream.
583
+ *
584
+ * @param is the InStream to get the current position from
585
+ * @return the current position within the InStream +is+
586
+ */
587
+ extern off_t is_pos(InStream *is);
588
+
589
+ /**
590
+ * Set the current position in InStream +is+ to +pos+.
591
+ *
592
+ * @param is the InStream to set the current position in
593
+ * @param pos the position in InStream to seek
594
+ * @raise IO_ERROR if there is a error seeking from the file-system
595
+ * @raise EOF_ERROR if there is an attempt to seek past the end of the file
596
+ */
597
+ extern void is_seek(InStream *is, off_t pos);
598
+
599
+ /**
600
+ * Close the InStream freeing all allocated resources.
601
+ *
602
+ * @param is the InStream to close
603
+ * @raise IO_ERROR if there is an error closing the associated file
604
+ */
605
+ extern void is_close(InStream *is);
606
+
607
+ /**
608
+ * Clone the InStream allocating a new InStream structure
609
+ *
610
+ * @param is the InStream to clone
611
+ * @return a newly allocated InStream which is a clone of +is+
612
+ */
613
+ extern InStream *is_clone(InStream *is);
614
+
615
+ /**
616
+ * Read a singly byte (unsigned char) from the InStream +is+.
617
+ *
618
+ * @param is the Instream to read from
619
+ * @return a single unsigned char read from the InStream +is+
620
+ * @raise IO_ERROR if there is a error reading from the file-system
621
+ * @raise EOF_ERROR if there is an attempt to read past the end of the file
622
+ */
623
+ extern INLINE uchar is_read_byte(InStream *is);
624
+
625
+ /**
626
+ * Read +len+ bytes from InStream +is+ and write them to buffer +buf+
627
+ *
628
+ * @param is the InStream to read from
629
+ * @param buf the buffer to read into, that is copy the bytes read to
630
+ * @param len the number of bytes to read
631
+ * @return the resultant buffer +buf+
632
+ * @raise IO_ERROR if there is a error reading from the file-system
633
+ * @raise EOF_ERROR if there is an attempt to read past the end of the file
634
+ */
635
+ extern uchar *is_read_bytes(InStream *is, uchar *buf, int len);
636
+
637
+ /**
638
+ * Read a 32-bit unsigned integer from the InStream.
639
+ *
640
+ * @param is the InStream to read from
641
+ * @return a 32-bit unsigned integer
642
+ * @raise IO_ERROR if there is a error reading from the file-system
643
+ * @raise EOF_ERROR if there is an attempt to read past the end of the file
644
+ */
645
+ extern f_i32 is_read_i32(InStream *is);
646
+
647
+ /**
648
+ * Read a 64-bit unsigned integer from the InStream.
649
+ *
650
+ * @param is the InStream to read from
651
+ * @return a 64-bit unsigned integer
652
+ * @raise IO_ERROR if there is a error reading from the file-system
653
+ * @raise EOF_ERROR if there is an attempt to read past the end of the file
654
+ */
655
+ extern f_i64 is_read_i64(InStream *is);
656
+
657
+ /**
658
+ * Read a 32-bit signed integer from the InStream.
659
+ *
660
+ * @param is the InStream to read from
661
+ * @return a 32-bit signed integer
662
+ * @raise IO_ERROR if there is a error reading from the file-system
663
+ * @raise EOF_ERROR if there is an attempt to read past the end of the file
664
+ */
665
+ extern f_u32 is_read_u32(InStream *is);
666
+
667
+ /**
668
+ * Read a 64-bit signed integer from the InStream.
669
+ *
670
+ * @param is the InStream to read from
671
+ * @return a 64-bit signed integer
672
+ * @raise IO_ERROR if there is a error reading from the file-system
673
+ * @raise EOF_ERROR if there is an attempt to read past the end of the file
674
+ */
675
+ extern f_u64 is_read_u64(InStream *is);
676
+
677
+ /**
678
+ * Read a compressed (VINT) unsigned integer from the InStream.
679
+ * TODO: describe VINT format
680
+ *
681
+ * @param is the InStream to read from
682
+ * @return an int
683
+ * @raise IO_ERROR if there is a error reading from the file-system
684
+ * @raise EOF_ERROR if there is an attempt to read past the end of the file
685
+ */
686
+ extern INLINE unsigned int is_read_vint(InStream *is);
687
+
688
+ /**
689
+ * Skip _cnt_ vints. This is a convenience method used for performance reasons
690
+ * to skip large numbers of vints. It is mostly used by TermDocEnums. When
691
+ * skipping positions os the proximity index file.
692
+ *
693
+ * @param is the InStream to read from
694
+ * @param cnt the number of vints to skip
695
+ * @raise IO_ERROR if there is a error reading from the file-system
696
+ * @raise EOF_ERROR if there is an attempt to read past the end of the file
697
+ */
698
+ extern INLINE void is_skip_vints(InStream *is, register int cnt);
699
+
700
+ /**
701
+ * Read a compressed (VINT) unsigned off_t from the InStream.
702
+ * TODO: describe VINT format
703
+ *
704
+ * @param is the InStream to read from
705
+ * @return a off_t
706
+ * @raise IO_ERROR if there is a error reading from the file-system
707
+ * @raise EOF_ERROR if there is an attempt to read past the end of the file
708
+ */
709
+ extern INLINE off_t is_read_voff_t(InStream *is);
710
+
711
+ /**
712
+ * Read a compressed (VINT) unsigned long long from the InStream.
713
+ * TODO: describe VINT format
714
+ *
715
+ * @param is the InStream to read from
716
+ * @return a long long
717
+ * @raise IO_ERROR if there is a error reading from the file-system
718
+ * @raise EOF_ERROR if there is an attempt to read past the end of the file
719
+ */
720
+ extern INLINE unsigned long long is_read_vll(InStream *is);
721
+
722
+ /**
723
+ * Read a string from the InStream. A string is an integer +length+ in vint
724
+ * format (see is_read_vint) followed by +length+ bytes. This is the format
725
+ * used by os_write_string.
726
+ *
727
+ * @param is the InStream to read from
728
+ * @return a null byte delimited string
729
+ * @raise IO_ERROR if there is a error reading from the file-system
730
+ * @raise EOF_ERROR if there is an attempt to read past the end of the file
731
+ */
732
+ extern char *is_read_string(InStream *is);
733
+
734
+ /**
735
+ * Read a string from the InStream. A string is an integer +length+ in vint
736
+ * format (see is_read_vint) followed by +length+ bytes. This is the format
737
+ * used by os_write_string. This method is similar to +is_read_string+ except
738
+ * that it will safely free all memory if there is an error reading the
739
+ * string.
740
+ *
741
+ * @param is the InStream to read from
742
+ * @return a null byte delimited string
743
+ * @raise IO_ERROR if there is a error reading from the file-system
744
+ * @raise EOF_ERROR if there is an attempt to read past the end of the file
745
+ */
746
+ extern char *is_read_string_safe(InStream *is);
747
+
748
+ /**
749
+ * Copy cnt bytes from Instream _is_ to OutStream _os_.
750
+ *
751
+ * @param is the InStream to read from
752
+ * @param os the OutStream to write to
753
+ * @raise IO_ERROR
754
+ * @raise EOF_ERROR
755
+ */
756
+ extern void is2os_copy_bytes(InStream *is, OutStream *os, int cnt);
757
+
758
+ /**
759
+ * Copy cnt vints from Instream _is_ to OutStream _os_.
760
+ *
761
+ * @param is the InStream to read from
762
+ * @param os the OutStream to write to
763
+ * @raise IO_ERROR
764
+ * @raise EOF_ERROR
765
+ */
766
+ extern void is2os_copy_vints(InStream *is, OutStream *os, int cnt);
767
+
768
+ /**
769
+ * Print the filenames in a store to a buffer.
770
+ *
771
+ * @param store the store to get the filenames from
772
+ */
773
+ extern char *store_to_s(Store *store);
774
+
775
+ extern Lock *open_lock(Store *store, char *lockname);
776
+ extern void close_lock(Lock *lock);
777
+ #endif