Changeset b39568e8202274e6aed953a924659cef1f971d55

Show
Ignore:
Timestamp:
04/23/08 11:17:03 (9 months ago)
Author:
David Balmain <dbalmain@…>
Parents:
3d5c1b18b9912541a77e63bdb908db34f068b328
Children:
7799d1d6f07fd24cc0cf0b784340f994374fc5b1
git-committer:
David Balmain <dbalmain@gmail.com> / 2008-04-23T11:17:03Z+1000
Message:

Added h_new_ptr to hash.h

h_new_ptr creates a Hash that users the pointer address as the hash so it is
very efficient. If you want to use this hash with strings you need to intern
the strings. To illustrate;

Hash *h = h_new_ptr(&free);
char *key1 = estrdup("key");
char *key2 = estrdup("key");
char *val = estrdup("val");

h_set(h, key1, val);
assert(NULL == h_get(key2));

Location:
c
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • c/include/hash.h

    r3d5c1b rb39568  
    110110 
    111111/** 
    112  * Create a new Hash that uses any type of object as it's key. The 
     112 * Create a new Hash that uses any type of object as its key. The 
    113113 * Hash will store all keys and values so if you want to destroy those 
    114114 * values when the Hash is destroyed then you should pass free functions. 
     
    131131 
    132132/** 
    133  * Create a new Hash that uses null-terminated strings as it's keys. The 
     133 * Create a new Hash that uses null-terminated strings as its keys. The 
    134134 * Hash will store all keys and values so if you want to destroy those 
    135135 * values when the Hash is destroyed then you should pass free functions. 
     
    148148 
    149149/** 
    150  * Create a new Hash that uses integers as it's keys. The 
    151  * Hash will store all values so if you want to destroy those 
    152  * values when the Hash is destroyed then you should pass a free function. 
    153  * NULL will suffice otherwise. 
     150 * Create a new Hash that uses integers as its keys. The Hash will store all 
     151 * values so if you want to destroy those values when the Hash is destroyed 
     152 * then you should pass a free function.  NULL will suffice otherwise. 
    154153 * 
    155154 * @param free_value function to free the value stored in the Hash when 
     
    159158 */ 
    160159extern FrtHash *frt_h_new_int(frt_free_ft free_value); 
     160 
     161/** 
     162 * Create a new Hash that uses pointers as its keys. The Hash will store all 
     163 * values so if you want to destroy those values when the Hash is destroyed 
     164 * then you should pass a free function. NULL will suffice otherwise. 
     165 * 
     166 * @param free_value function to free the value stored in the Hash when 
     167 *    an entry is deleted, replaced or when the Hash is destroyed. If you 
     168 *    pass NULL in place of this parameter the value will not be destroyed. 
     169 * @return A newly allocated Hash 
     170 */ 
     171#define frt_h_new_ptr(free_value) frt_h_new_int(free_value) 
    161172 
    162173/** 
  • c/include/intern.h

    r553474 rb39568  
    66extern const char *frt_intern_and_free(char *str); 
    77 
     8#define FRT_I frt_intern 
     9#define FRT_IF frt_intern_and_free 
     10 
    811#endif 
  • c/include/internal.h

    r3d5c1b rb39568  
    7373#define HAS_VARARGS                        FRT_HAS_VARARGS 
    7474#define HS_MIN_SIZE                        FRT_HS_MIN_SIZE 
     75#define I                                  FRT_I 
     76#define IF                                 FRT_IF 
    7577#define INDEX_ERROR                        FRT_INDEX_ERROR 
    7678#define INDEX_INTERVAL                     FRT_INDEX_INTERVAL 
     
    524526#define h_new                                   frt_h_new 
    525527#define h_new_int                               frt_h_new_int 
     528#define h_new_ptr                               frt_h_new_ptr 
    526529#define h_new_str                               frt_h_new_str 
    527530#define h_rem                                   frt_h_rem 
  • c/src/hash.c

    r3d5c1b rb39568  
    199199} 
    200200 
    201 Hash *h_new_ptr(free_ft free_key, free_ft free_value) 
    202 { 
    203     Hash *self     = h_new_str(free_key, free_value); 
    204  
    205     self->lookup_i = &h_lookup_ptr; 
    206     self->eq_i     = NULL; 
    207     self->hash_i   = NULL; 
    208  
    209     return self; 
    210 } 
    211  
    212201Hash *h_new(hash_ft hash, eq_ft eq, free_ft free_key, free_ft free_value) 
    213202{ 
  • c/src/q_parser.c

    r4ba05f rb39568  
    207207static void qp_pop_fields(QParser *self); 
    208208 
     209/** 
     210 * +FLDS+ calls +func+ for all fields on top of the field stack. +func+ 
     211 * must return a query. If there is more than one field on top of FieldStack 
     212 * then +FLDS+ will combing all the queries returned by +func+ into a single 
     213 * BooleanQuery which it than assigns to +q+. If there is only one field, the 
     214 * return value of +func+ is assigned to +q+ directly. 
     215 */ 
    209216#define FLDS(q, func) do {\ 
    210217    TRY {\ 
     
    250257 
    251258/* Line 216 of yacc.c.  */ 
    252 #line 253 "src/q_parser.c" 
     259#line 260 "src/q_parser.c" 
    253260 
    254261#ifdef short 
     
    553560static const yytype_uint16 yyrline[] = 
    554561{ 
    555        0,   218,   218,   219,   221,   222,   223,   224,   226,   227, 
    556      228,   230,   231,   233,   234,   235,   236,   237,   238,   239, 
    557      241,   242,   243,   245,   247,   247,   249,   249,   249,   252, 
    558      253,   255,   256,   257,   258,   260,   261,   262,   263,   264, 
    559      266,   267,   268,   269,   270,   271,   272,   273,   274,   275, 
    560      276,   277 
     562       0,   225,   225,   226,   228,   229,   230,   231,   233,   234, 
     563     235,   237,   238,   240,   241,   242,   243,   244,   245,   246, 
     564     248,   249,   250,   252,   254,   254,   256,   256,   256,   259, 
     565     260,   262,   263,   264,   265,   267,   268,   269,   270,   271, 
     566     273,   274,   275,   276,   277,   278,   279,   280,   281,   282, 
     567     283,   284 
    561568}; 
    562569#endif 
     
    12171224    { 
    12181225      case 27: /* "bool_q" */ 
    1219 #line 213 "src/q_parser.y" 
     1226#line 220 "src/q_parser.y" 
    12201227        { if ((yyvaluep->query) && qp->destruct) q_deref((yyvaluep->query)); }; 
    1221 #line 1222 "src/q_parser.c" 
     1228#line 1229 "src/q_parser.c" 
    12221229        break; 
    12231230      case 28: /* "bool_clss" */ 
    1224 #line 215 "src/q_parser.y" 
     1231#line 222 "src/q_parser.y" 
    12251232        { if ((yyvaluep->bclss) && qp->destruct) bca_destroy((yyvaluep->bclss)); }; 
    1226 #line 1227 "src/q_parser.c" 
     1233#line 1234 "src/q_parser.c" 
    12271234        break; 
    12281235      case 29: /* "bool_cls" */ 
    1229 #line 214 "src/q_parser.y" 
     1236#line 221 "src/q_parser.y" 
    12301237        { if ((yyvaluep->bcls) && qp->destruct) bc_deref((yyvaluep->bcls)); }; 
    1231 #line 1232 "src/q_parser.c" 
     1238#line 1239 "src/q_parser.c" 
    12321239        break; 
    12331240      case 30: /* "boosted_q" */ 
    1234 #line 213 "src/q_parser.y" 
     1241#line 220 "src/q_parser.y" 
    12351242        { if ((yyvaluep->query) && qp->destruct) q_deref((yyvaluep->query)); }; 
    1236 #line 1237 "src/q_parser.c" 
     1243#line 1244 "src/q_parser.c" 
    12371244        break; 
    12381245      case 31: /* "q" */ 
    1239 #line 213 "src/q_parser.y" 
     1246#line 220 "src/q_parser.y" 
    12401247        { if ((yyvaluep->query) && qp->destruct) q_deref((yyvaluep->query)); }; 
    1241 #line 1242 "src/q_parser.c" 
     1248#line 1249 "src/q_parser.c" 
    12421249        break; 
    12431250      case 32: /* "term_q" */ 
    1244 #line 213 "src/q_parser.y" 
     1251#line 220 "src/q_parser.y" 
    12451252        { if ((yyvaluep->query) && qp->destruct) q_deref((yyvaluep->query)); }; 
    1246 #line 1247 "src/q_parser.c" 
     1253#line 1254 "src/q_parser.c" 
    12471254        break; 
    12481255      case 33: /* "wild_q" */ 
    1249 #line 213 "src/q_parser.y" 
     1256#line 220 "src/q_parser.y" 
    12501257        { if ((yyvaluep->query) && qp->destruct) q_deref((yyvaluep->query)); }; 
    1251 #line 1252 "src/q_parser.c" 
     1258#line 1259 "src/q_parser.c" 
    12521259        break; 
    12531260      case 34: /* "field_q" */ 
    1254 #line 213 "src/q_parser.y" 
     1261#line 220 "src/q_parser.y" 
    12551262        { if ((yyvaluep->query) && qp->destruct) q_deref((yyvaluep->query)); }; 
    1256 #line 1257 "src/q_parser.c" 
     1263#line 1264 "src/q_parser.c" 
    12571264        break; 
    12581265      case 39: /* "phrase_q" */ 
    1259 #line 213 "src/q_parser.y" 
     1266#line 220 "src/q_parser.y" 
    12601267        { if ((yyvaluep->query) && qp->destruct) q_deref((yyvaluep->query)); }; 
    1261 #line 1262 "src/q_parser.c" 
     1268#line 1269 "src/q_parser.c" 
    12621269        break; 
    12631270      case 40: /* "ph_words" */ 
    1264 #line 216 "src/q_parser.y" 
     1271#line 223 "src/q_parser.y" 
    12651272        { if ((yyvaluep->phrase) && qp->destruct) ph_destroy((yyvaluep->phrase)); }; 
    1266 #line 1267 "src/q_parser.c" 
     1273#line 1274 "src/q_parser.c" 
    12671274        break; 
    12681275      case 41: /* "range_q" */ 
    1269 #line 213 "src/q_parser.y" 
     1276#line 220 "src/q_parser.y" 
    12701277        { if ((yyvaluep->query) && qp->destruct) q_deref((yyvaluep->query)); }; 
    1271 #line 1272 "src/q_parser.c" 
     1278#line 1279 "src/q_parser.c" 
    12721279        break; 
    12731280 
     
    15781585    { 
    15791586        case 2: 
    1580 #line 218 "src/q_parser.y" 
     1587#line 225 "src/q_parser.y" 
    15811588    {   qp->result = (yyval.query) = NULL; } 
    15821589    break; 
    15831590 
    15841591  case 3: 
    1585 #line 219 "src/q_parser.y" 
     1592#line 226 "src/q_parser.y" 
    15861593    { T qp->result = (yyval.query) = get_bool_q((yyvsp[(1) - (1)].bclss)); E } 
    15871594    break; 
    15881595 
    15891596  case 4: 
    1590 #line 221 "src/q_parser.y" 
     1597#line 228 "src/q_parser.y" 
    15911598    { T (yyval.bclss) = first_cls((yyvsp[(1) - (1)].bcls)); E } 
    15921599    break; 
    15931600 
    15941601  case 5: 
    1595 #line 222 "src/q_parser.y" 
     1602#line 229 "src/q_parser.y" 
    15961603    { T (yyval.bclss) = add_and_cls((yyvsp[(1) - (3)].bclss), (yyvsp[(3) - (3)].bcls)); E } 
    15971604    break; 
    15981605 
    15991606  case 6: 
    1600 #line 223 "src/q_parser.y" 
     1607#line 230 "src/q_parser.y" 
    16011608    { T (yyval.bclss) = add_or_cls((yyvsp[(1) - (3)].bclss), (yyvsp[(3) - (3)].bcls)); E } 
    16021609    break; 
    16031610 
    16041611  case 7: 
    1605 #line 224 "src/q_parser.y" 
     1612#line 231 "src/q_parser.y" 
    16061613    { T (yyval.bclss) = add_default_cls(qp, (yyvsp[(1) - (2)].bclss), (yyvsp[(2) - (2)].bcls)); E } 
    16071614    break; 
    16081615 
    16091616  case 8: 
    1610 #line 226 "src/q_parser.y" 
     1617#line 233 "src/q_parser.y" 
    16111618    { T (yyval.bcls) = get_bool_cls((yyvsp[(2) - (2)].query), BC_MUST); E } 
    16121619    break; 
    16131620 
    16141621  case 9: 
    1615 #line 227 "src/q_parser.y" 
     1622#line 234 "src/q_parser.y" 
    16161623    { T (yyval.bcls) = get_bool_cls((yyvsp[(2) - (2)].query), BC_MUST_NOT); E } 
    16171624    break; 
    16181625 
    16191626  case 10: 
    1620 #line 228 "src/q_parser.y" 
     1627#line 235 "src/q_parser.y" 
    16211628    { T (yyval.bcls) = get_bool_cls((yyvsp[(1) - (1)].query), BC_SHOULD); E } 
    16221629    break; 
    16231630 
    16241631  case 12: 
    1625 #line 231 "src/q_parser.y" 
     1632#line 238 "src/q_parser.y" 
    16261633    { T if ((yyvsp[(1) - (3)].query)) sscanf((yyvsp[(3) - (3)].str),"%f",&((yyvsp[(1) - (3)].query)->boost));  (yyval.query)=(yyvsp[(1) - (3)].query); E } 
    16271634    break; 
    16281635 
    16291636  case 14: 
    1630 #line 234 "src/q_parser.y" 
     1637#line 241 "src/q_parser.y" 
    16311638    { T (yyval.query) = bq_new_max(true, qp->max_clauses); E } 
    16321639    break; 
    16331640 
    16341641  case 15: 
    1635 #line 235 "src/q_parser.y" 
     1642#line 242 "src/q_parser.y" 
    16361643    { T (yyval.query) = get_bool_q((yyvsp[(2) - (3)].bclss)); E } 
    16371644    break; 
    16381645 
    16391646  case 20: 
    1640 #line 241 "src/q_parser.y" 
     1647#line 248 "src/q_parser.y" 
    16411648    { FLDS((yyval.query), get_term_q(qp, field, (yyvsp[(1) - (1)].str))); Y} 
    16421649    break; 
    16431650 
    16441651  case 21: 
    1645 #line 242 "src/q_parser.y" 
     1652#line 249 "src/q_parser.y" 
    16461653    { FLDS((yyval.query), get_fuzzy_q(qp, field, (yyvsp[(1) - (3)].str), (yyvsp[(3) - (3)].str))); Y} 
    16471654    break; 
    16481655 
    16491656  case 22: 
    1650 #line 243 "src/q_parser.y" 
     1657#line 250 "src/q_parser.y" 
    16511658    { FLDS((yyval.query), get_fuzzy_q(qp, field, (yyvsp[(1) - (2)].str), NULL)); Y} 
    16521659    break; 
    16531660 
    16541661  case 23: 
    1655 #line 245 "src/q_parser.y" 
     1662#line 252 "src/q_parser.y" 
    16561663    { FLDS((yyval.query), get_wild_q(qp, field, (yyvsp[(1) - (1)].str))); Y} 
    16571664    break; 
    16581665 
    16591666  case 24: 
    1660 #line 247 "src/q_parser.y" 
     1667#line 254 "src/q_parser.y" 
    16611668    { qp_pop_fields(qp); } 
    16621669    break; 
    16631670 
    16641671  case 25: 
    1665 #line 248 "src/q_parser.y" 
     1672#line 255 "src/q_parser.y" 
    16661673    { (yyval.query) = (yyvsp[(3) - (4)].query); } 
    16671674    break; 
    16681675 
    16691676  case 26: 
    1670 #line 249 "src/q_parser.y" 
     1677#line 256 "src/q_parser.y" 
    16711678    { qp_push_fields(qp, qp->all_fields, false); } 
    16721679    break; 
    16731680 
    16741681  case 27: 
    1675 #line 249 "src/q_parser.y" 
     1682#line 256 "src/q_parser.y" 
    16761683    { qp_pop_fields(qp); } 
    16771684    break; 
    16781685 
    16791686  case 28: 
    1680 #line 250 "src/q_parser.y" 
     1687#line 257 "src/q_parser.y" 
    16811688    { (yyval.query) = (yyvsp[(4) - (5)].query); } 
    16821689    break; 
    16831690 
    16841691  case 29: 
    1685 #line 252 "src/q_parser.y" 
     1692#line 259 "src/q_parser.y" 
    16861693    { (yyval.hashset) = first_field(qp, (yyvsp[(1) - (1)].str)); } 
    16871694    break; 
    16881695 
    16891696  case 30: 
    1690 #line 253 "src/q_parser.y" 
     1697#line 260 "src/q_parser.y" 
    16911698    { (yyval.hashset) = add_field(qp, (yyvsp[(3) - (3)].str));} 
    16921699    break; 
    16931700 
    16941701  case 31: 
    1695 #line 255 "src/q_parser.y" 
     1702#line 262 "src/q_parser.y" 
    16961703    { (yyval.query) = get_phrase_q(qp, (yyvsp[(2) - (3)].phrase), NULL); } 
    16971704    break; 
    16981705 
    16991706  case 32: 
    1700 #line 256 "src/q_parser.y" 
     1707#line 263 "src/q_parser.y" 
    17011708    { (yyval.query) = get_phrase_q(qp, (yyvsp[(2) - (5)].phrase), (yyvsp[(5) - (5)].str)); } 
    17021709    break; 
    17031710 
    17041711  case 33: 
    1705 #line 257 "src/q_parser.y" 
     1712#line 264 "src/q_parser.y" 
    17061713    { (yyval.query) = NULL; } 
    17071714    break; 
    17081715 
    17091716  case 34: 
    1710 #line 258 "src/q_parser.y" 
     1717#line 265 "src/q_parser.y" 
    17111718    { (yyval.query) = NULL; (void)(yyvsp[(4) - (4)].str);} 
    17121719    break; 
    17131720 
    17141721  case 35: 
    1715 #line 260 "src/q_parser.y" 
     1722#line 267 "src/q_parser.y" 
    17161723    { (yyval.phrase) = ph_first_word((yyvsp[(1) - (1)].str)); } 
    17171724    break; 
    17181725 
    17191726  case 36: 
    1720 #line 261 "src/q_parser.y" 
     1727#line 268 "src/q_parser.y" 
    17211728    { (yyval.phrase) = ph_first_word(NULL); } 
    17221729    break; 
    17231730 
    17241731  case 37: 
    1725 #line 262 "src/q_parser.y" 
     1732#line 269 "src/q_parser.y" 
    17261733    { (yyval.phrase) = ph_add_word((yyvsp[(1) - (2)].phrase), (yyvsp[(2) - (2)].str)); } 
    17271734    break; 
    17281735 
    17291736  case 38: 
    1730 #line 263 "src/q_parser.y" 
     1737#line 270 "src/q_parser.y" 
    17311738    { (yyval.phrase) = ph_add_word((yyvsp[(1) - (3)].phrase), NULL); } 
    17321739    break; 
    17331740 
    17341741  case 39: 
    1735 #line 264 "src/q_parser.y" 
     1742#line 271 "src/q_parser.y" 
    17361743    { (yyval.phrase) = ph_add_multi_word((yyvsp[(1) - (3)].phrase), (yyvsp[(3) - (3)].str));  } 
    17371744    break; 
    17381745 
    17391746  case 40: 
    1740 #line 266 "src/q_parser.y" 
     1747#line 273 "src/q_parser.y" 
    17411748    { FLDS((yyval.query), get_r_q(qp, field, (yyvsp[(2) - (4)].str),  (yyvsp[(3) - (4)].str),  true,  true)); Y} 
    17421749    break; 
    17431750 
    17441751  case 41: 
    1745 #line 267 "src/q_parser.y" 
     1752#line 274 "src/q_parser.y" 
    17461753    { FLDS((yyval.query), get_r_q(qp, field, (yyvsp[(2) - (4)].str),  (yyvsp[(3) - (4)].str),  true,  false)); Y} 
    17471754    break; 
    17481755 
    17491756  case 42: 
    1750 #line 268 "src/q_parser.y" 
     1757#line 275 "src/q_parser.y" 
    17511758    { FLDS((yyval.query), get_r_q(qp, field, (yyvsp[(2) - (4)].str),  (yyvsp[(3) - (4)].str),  false, true)); Y} 
    17521759    break; 
    17531760 
    17541761  case 43: 
    1755 #line 269 "src/q_parser.y" 
     1762#line 276 "src/q_parser.y" 
    17561763    { FLDS((yyval.query), get_r_q(qp, field, (yyvsp[(2) - (4)].str),  (yyvsp[(3) - (4)].str),  false, false)); Y} 
    17571764    break; 
    17581765 
    17591766  case 44: 
    1760 #line 270 "src/q_parser.y" 
     1767#line 277 "src/q_parser.y" 
    17611768    { FLDS((yyval.query), get_r_q(qp, field, NULL,(yyvsp[(2) - (3)].str),  false, false)); Y} 
    17621769    break; 
    17631770 
    17641771  case 45: 
    1765 #line 271 "src/q_parser.y" 
     1772#line 278 "src/q_parser.y" 
    17661773    { FLDS((yyval.query), get_r_q(qp, field, NULL,(yyvsp[(2) - (3)].str),  false, true)); Y} 
    17671774    break; 
    17681775 
    17691776  case 46: 
    1770 #line 272 "src/q_parser.y" 
     1777#line 279 "src/q_parser.y" 
    17711778    { FLDS((yyval.query), get_r_q(qp, field, (yyvsp[(2) - (3)].str),  NULL,true,  false)); Y} 
    17721779    break; 
    17731780 
    17741781  case 47: 
    1775 #line 273 "src/q_parser.y" 
     1782#line 280 "src/q_parser.y" 
    17761783    { FLDS((yyval.query), get_r_q(qp, field, (yyvsp[(2) - (3)].str),  NULL,false, false)); Y} 
    17771784    break; 
    17781785 
    17791786  case 48: 
    1780 #line 274 "src/q_parser.y" 
     1787#line 281 "src/q_parser.y" 
    17811788    { FLDS((yyval.query), get_r_q(qp, field, NULL,(yyvsp[(2) - (2)].str),  false, false)); Y} 
    17821789    break; 
    17831790 
    17841791  case 49: 
    1785 #line 275 "src/q_parser.y" 
     1792#line 282 "src/q_parser.y" 
    17861793    { FLDS((yyval.query), get_r_q(qp, field, NULL,(yyvsp[(3) - (3)].str),  false, true)); Y} 
    17871794    break; 
    17881795 
    17891796  case 50: 
    1790 #line 276 "src/q_parser.y" 
     1797#line 283 "src/q_parser.y" 
    17911798    { FLDS((yyval.query), get_r_q(qp, field, (yyvsp[(3) - (3)].str),  NULL,true,  false)); Y} 
    17921799    break; 
    17931800 
    17941801  case 51: 
    1795 #line 277 "src/q_parser.y" 
     1802#line 284 "src/q_parser.y" 
    17961803    { FLDS((yyval.query), get_r_q(qp, field, (yyvsp[(2) - (2)].str),  NULL,false, false)); Y} 
    17971804    break; 
     
    17991806 
    18001807/* Line 1267 of yacc.c.  */ 
    1801 #line 1802 "src/q_parser.c" 
     1808#line 1809 "src/q_parser.c" 
    18021809      default: break; 
    18031810    } 
     
    20132020 
    20142021 
    2015 #line 279 "src/q_parser.y" 
     2022#line 286 "src/q_parser.y" 
    20162023 
    20172024 
     
    20192026static const char *not_word =   " \t()[]{}!\"~^|<>="; 
    20202027 
     2028/** 
     2029 * +get_word+ gets the next query-word from the query string. A query-word is 
     2030 * basically a string of non-special or escaped special characters. It is 
     2031 * Analyzer agnostic. It is up to the get_*_q methods to tokenize the word and 
     2032 * turn it into a +Query+. See the documentation for each get_*_q method to 
     2033 * see how it handles tokenization. 
     2034 * 
     2035 * Note that +get_word+ is also responsible for returning field names and 
     2036 * matching the special tokens 'AND', 'NOT', 'REQ' and 'OR'. 
     2037 */ 
    20212038static int get_word(YYSTYPE *lvalp, QParser *qp) 
    20222039{ 
     
    20622079                *bufp++ = c; 
    20632080        } 
    2064         /* we've exceeded the static buffer. switch to the dynamic 
    2065            one. */ 
     2081        /* we've exceeded the static buffer. switch to the dynamic one. The 
     2082         * dynamic buffer is allocated enough space to hold the whole query 
     2083         * string so it's capacity doesn't need to be checked again once 
     2084         * allocated. */ 
    20662085        if (!qp->dynbuf && ((bufp - buf) == MAX_WORD_SIZE)) { 
    20672086            qp->dynbuf = ALLOC_AND_ZERO_N(char, strlen(qp->qstr) + 1); 
     
    20732092get_word_done: 
    20742093    qp->qstrp--; 
    2075     /* check for keywords. There are only four so we have a bit of a hack which 
    2076      * just checks for all of them. */ 
     2094    /* check for keywords. There are only four so we have a bit of a hack 
     2095     * which just checks for all of them. */ 
    20772096    *bufp = '\0'; 
    20782097    len = (int)(bufp - buf); 
     
    20942113} 
    20952114 
     2115/** 
     2116 * +yylex+ is the lexing method called by the QueryParser. It breaks the 
     2117 * query up into special characters; 
     2118 *  
     2119 *     ( "&:()[]{}!\"~^|<>=*?+-" ) 
     2120 * 
     2121 * and tokens;  
     2122 *  
     2123 *   - QWRD 
     2124 *   - WILD_STR 
     2125 *   - AND['AND', '&&'] 
     2126 *   - OR['OR', '||'] 
     2127 *   - REQ['REQ', '+'] 
     2128 *   - NOT['NOT', '-', '~'] 
     2129 * 
     2130 * QWRD tokens are query word tokens which are made up of characters other 
     2131 * than the special characters. They can also contain special characters when 
     2132 * escaped with a backslash '\'. WILD_STR is the same as QWRD except that it 
     2133 * may also contain '?' and '*' characters. 
     2134 * 
     2135 * If any of the special chars are seen they will usually be returned straight 
     2136 * away. The exceptions are the wild chars '*' and '?', and '&' which will be 
     2137 * treated as a plain old word character unless followed by another '&'. 
     2138 *  
     2139 * If no special characters or tokens are found then yylex delegates to 
     2140 * +get_word+ which will fetch the next query-word. 
     2141 */ 
    20962142static int yylex(YYSTYPE *lvalp, QParser *qp) 
    20972143{ 
     
    21322178} 
    21332179 
     2180/** 
     2181 * yyerror gets called if there is an parse error with the yacc parser. 
     2182 * It is responsible for clearing any memory that was allocated during the 
     2183 * parsing process. 
     2184 */ 
    21342185static int yyerror(QParser *qp, char const *msg) 
    21352186{ 
     
    21522203#define BQ(query) ((BooleanQuery *)(query)) 
    21532204 
     2205/** 
     2206 * The QueryParser caches a tokenizer for each field so that it doesn't need 
     2207 * to allocate a new tokenizer for each term in the query. This would be quite 
     2208 * expensive as tokenizers use quite a large hunk of memory. 
     2209 * 
     2210 * This method returns the query parser for a particular field and sets it up 
     2211 * with the text to be tokenized. 
     2212 */ 
    21542213static TokenStream *get_cached_ts(QParser *qp, char *field, char *text) 
    21552214{ 
     
    21722231} 
    21732232 
     2233/** 
     2234 * Turns a BooleanClause array into a BooleanQuery. It will optimize the query 
     2235 * if 0 or 1 clauses are present to NULL or the actual query in the clause 
     2236 * respectively. 
     2237 */ 
    21742238static Query *get_bool_q(BCArray *bca) 
    21752239{ 
     
    22072271} 
    22082272 
     2273/** 
     2274 * Base method for appending BooleanClauses to a BooleanClause array. This 
     2275 * method doesn't care about the type of clause (MUST, SHOULD, MUST_NOT). 
     2276 */ 
    22092277static void bca_add_clause(BCArray *bca, BooleanClause *clause) 
    22102278{ 
     
    22172285} 
    22182286 
     2287/** 
     2288 * Add the first clause to a BooleanClause array. This method is also 
     2289 * responsible for allocating a new BooleanClause array. 
     2290 */ 
    22192291static BCArray *first_cls(BooleanClause *clause) 
    22202292{ 
     
    22282300} 
    22292301 
     2302/** 
     2303 * Add AND clause to the BooleanClause array. The means that it will set the 
     2304 * clause being added and the previously added clause from SHOULD clauses to 
     2305 * MUST clauses. (If they are currently MUST_NOT clauses they stay as they 
     2306 * are.) 
     2307 */