1 /* Copyright(C) 2004-2005 Brazil 2 3 This library is free software; you can redistribute it and/or 4 modify it under the terms of the GNU Lesser General Public 5 License as published by the Free Software Foundation; either 6 version 2.1 of the License, or (at your option) any later version. 7 8 This library is distributed in the hope that it will be useful, 9 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 Lesser General Public License for more details. 12 13 You should have received a copy of the GNU Lesser General Public 14 License along with this library; if not, write to the Free Software 15 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 */ 17 #ifndef SEN_SNIP_H 18 #define SEN_SNIP_H 19 20 #ifndef SENNA_H 21 #include "senna_in.h" 22 #endif /* SENNA_H */ 23 24 #ifndef SEN_STR_H 25 #include "str.h" 26 #endif /* SEN_STR_H */ 27 28 #define ASIZE 256U 29 #define MAX_SNIP_TAG_COUNT 512U 30 #define MAX_SNIP_COND_COUNT 32U 31 #define MAX_SNIP_RESULT_COUNT 16U 32 33 #ifdef __cplusplus 34 extern "C" 35 { 36 #endif 37 38 #define SNIPCOND_NONSTOP 0 39 #define SNIPCOND_STOP 1 40 #define SNIPCOND_ACROSS 2 41 42 #define SEN_QUERY_SCAN_ALLOCCONDS 0x0002 43 44 typedef struct _snip_cond 45 { 46 /* initial parameters */ 47 const char *opentag; 48 const char *closetag; 49 size_t opentag_len; 50 size_t closetag_len; 51 sen_nstr *keyword; 52 53 /* Tuned BM pre */ 54 size_t bmBc[ASIZE]; 55 size_t shift; 56 57 /* Tuned BM temporal result */ 58 size_t found; 59 size_t last_found; 60 size_t last_offset; 61 size_t start_offset; 62 size_t end_offset; 63 size_t found_alpha_head; 64 65 /* search result */ 66 int count; 67 68 /* stop flag */ 69 int_least8_t stopflag; 70 } snip_cond; 71 72 typedef struct 73 { 74 size_t start_offset; 75 size_t end_offset; 76 snip_cond *cond; 77 } _snip_tag_result; 78 79 typedef struct 80 { 81 size_t start_offset; 82 size_t end_offset; 83 unsigned int first_tag_result_idx; 84 unsigned int last_tag_result_idx; 85 unsigned int tag_count; 86 } _snip_result; 87 88 struct _sen_snip 89 { 90 sen_encoding encoding; 91 int flags; 92 size_t width; 93 unsigned int max_results; 94 const char *defaultopentag; 95 const char *defaultclosetag; 96 size_t defaultopentag_len; 97 size_t defaultclosetag_len; 98 99 sen_snip_mapping *mapping; 100 101 snip_cond cond[MAX_SNIP_COND_COUNT]; 102 unsigned int cond_len; 103 104 unsigned int tag_count; 105 unsigned int snip_count; 106 107 const char *string; 108 sen_nstr *nstr; 109 110 _snip_result snip_result[MAX_SNIP_RESULT_COUNT]; 111 _snip_tag_result tag_result[MAX_SNIP_TAG_COUNT]; 112 113 size_t max_tagged_len; 114 }; 115 116 sen_rc sen_snip_cond_init(snip_cond *sc, const char *keyword, unsigned int keyword_len, 117 sen_encoding enc, int flags); 118 void sen_snip_cond_reinit(snip_cond *cond); 119 sen_rc sen_snip_cond_close(snip_cond *cond); 120 void sen_bm_tunedbm(snip_cond *cond, sen_nstr *object, int flags); 121 122 #ifdef __cplusplus 123 } 124 #endif 125 126 #endif /* SEN_SNIP_H */ 127