Changeset 2041
- Timestamp:
- 02/29/08 23:18:18 (3 months ago)
- Files:
-
- libswish3/trunk/src/Makefile.am (modified) (1 diff)
- libswish3/trunk/src/libswish3/Makefile.am (modified) (1 diff)
- libswish3/trunk/src/libswish3/analyzer.c (modified) (2 diffs)
- libswish3/trunk/src/libswish3/config.c (modified) (18 diffs)
- libswish3/trunk/src/libswish3/hash.c (modified) (1 diff)
- libswish3/trunk/src/libswish3/libswish3.h (modified) (11 diffs)
- libswish3/trunk/src/libswish3/metaname.c (added)
- libswish3/trunk/src/libswish3/mime_types.c (modified) (2 diffs)
- libswish3/trunk/src/libswish3/namedbuffer.c (modified) (4 diffs)
- libswish3/trunk/src/libswish3/parser.c (modified) (5 diffs)
- libswish3/trunk/src/libswish3/property.c (added)
- libswish3/trunk/src/libswish3/string.c (modified) (10 diffs)
- libswish3/trunk/src/swish_header.c (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
libswish3/trunk/src/Makefile.am
r1955 r2041 9 9 # -pg is for profiling -- don't use in production 10 10 11 bin_PROGRAMS = swish_lint swish_words swish_isw utf8test 11 bin_PROGRAMS = swish_lint swish_words swish_isw utf8test swish_header 12 12 check_PROGRAMS = swish_lint 13 13 swish_lint_SOURCES = swish_lint.c $(myheaders) 14 14 swish_words_SOURCES = swish_words.c $(myheaders) 15 swish_isw_SOURCES = swish_isw.c 15 swish_isw_SOURCES = swish_isw.c 16 swish_header_SOURCES = swish_header.c $(myheaders) 16 17 utf8test_SOURCES = utf8test.c $(myheaders) 17 18 libswish3/trunk/src/libswish3/Makefile.am
r1930 r2041 26 26 swish.c \ 27 27 analyzer.c \ 28 property.c \ 29 metaname.c \ 28 30 $(myheaders) 29 31 libswish3/trunk/src/libswish3/analyzer.c
r2028 r2041 33 33 a = swish_xmalloc(sizeof(swish_Analyzer)); 34 34 35 /* TODO get th isfrom config */35 /* TODO get these all from config */ 36 36 a->maxwordlen = SWISH_MAX_WORD_LEN; 37 37 a->minwordlen = SWISH_MIN_WORD_LEN; 38 38 a->lc = 1; 39 39 a->ref_cnt = 0; 40 a->tokenize = config->flags->tokenize; 40 41 41 if (xmlStrEqual((xmlChar*)SWISH_DEFAULT_VALUE, 42 xmlHashLookup( 43 swish_subconfig_hash(config,(xmlChar*)SWISH_WORDS), 44 (xmlChar*)SWISH_PARSE_WORDS 45 ) 46 ) 47 ) 48 { 49 a->tokenize = 1; 50 } 51 else 52 { 53 if (SWISH_DEBUG) 54 SWISH_DEBUG_MSG("skipping WordList"); 55 56 a->tokenize = 0; 57 } 58 42 if (!a->tokenize && SWISH_DEBUG) 43 SWISH_DEBUG_MSG("skipping WordList"); 44 59 45 /* tokenizer set in the parse* function */ 60 46 a->tokenizer = NULL; … … 66 52 a->regex = NULL; 67 53 68 a->stash = NULL;54 a->stash = NULL; 69 55 70 56 return a; libswish3/trunk/src/libswish3/config.c
r2028 r2041 24 24 */ 25 25 26 27 /* #include <libxml/hash.h> */28 26 #include <libxml/xmlstring.h> 29 27 #include <sys/param.h> … … 40 38 41 39 42 static void config_val_printer(xmlChar * val, xmlChar * str, xmlChar * key); 43 static void config_printer(xmlHashTablePtr vhash, xmlChar * str, xmlChar * key); 44 static void free_config1(void *payload, xmlChar * confName); 45 static void free_config2(void *payload, xmlChar * key); 40 static void config_printer(xmlChar * val, xmlChar * str, xmlChar * key); 41 46 42 static xmlDocPtr parse_xml_config(xmlChar * conf); 47 static int is_multi(xmlNode * node); 48 static int is_equal(xmlNode * node); 49 static int is_top_level(xmlNode * node); 50 static xmlChar *get_node_value(xmlNode * node); 51 static xmlChar *get_node_key(xmlNode * node); 52 static xmlChar *get_node_type(xmlNode * node); 43 static xmlChar *get_node_name(xmlNode * node); 53 44 static xmlNode *get_dom_root(xmlDocPtr doc); 54 static int node_has_key(xmlNode * node); 55 static int node_has_value(xmlNode * node); 56 static int node_has_type(xmlNode * node); 57 static int node_has_attr(xmlNode * node, const xmlChar * att); 58 static void add_multi_node_to_cv(xmlNode * node, swish_ConfigValue * cv); 59 45 46 static void free_string(xmlChar *payload, xmlChar *key); 47 static void free_props(swish_Property *prop, xmlChar *propname); 48 static void free_metas(swish_MetaName *meta, xmlChar *metaname); 60 49 61 50 static void 62 free_ config2(void*payload, xmlChar * key)51 free_string(xmlChar *payload, xmlChar * key) 63 52 { 64 53 if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 65 SWISH_DEBUG_MSG(" freeing config %s => %s", key, (xmlChar *)payload);66 67 swish_xfree( (xmlChar *)payload);54 SWISH_DEBUG_MSG(" freeing config %s => %s", key, payload); 55 56 swish_xfree(payload); 68 57 } 69 58 70 59 static void 71 free_config1(void *payload, xmlChar * confName) 72 { 73 int size = xmlHashSize((xmlHashTablePtr) payload); 74 75 if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 76 { 77 SWISH_DEBUG_MSG(" freeing config %s =>", confName); 78 SWISH_DEBUG_MSG(" num of keys in config hash: %d", size); 79 SWISH_DEBUG_MSG(" ptr addr: 0x%x %d", (int) payload, (int) payload); 80 } 81 82 xmlHashFree((xmlHashTablePtr) payload, (xmlHashDeallocator) free_config2); 83 60 free_props(swish_Property *prop, xmlChar *propname) 61 { 62 if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) { 63 SWISH_DEBUG_MSG(" freeing config->prop %s", propname); 64 swish_debug_property((swish_Property*)prop); 65 } 66 prop->ref_cnt--; 67 swish_free_property(prop); 68 } 69 70 static void 71 free_metas(swish_MetaName *meta, xmlChar *metaname) 72 { 73 if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) { 74 SWISH_DEBUG_MSG(" freeing config->meta %s", metaname); 75 swish_debug_metaname((swish_MetaName*)meta); 76 } 77 meta->ref_cnt--; 78 swish_free_metaname(meta); 84 79 } 85 80 … … 87 82 swish_free_config(swish_Config * config) 88 83 { 89 int size = xmlHashSize(config->conf);84 int size = xmlHashSize(config->conf); 90 85 91 86 if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) … … 96 91 } 97 92 98 xmlHashFree(config->conf, (xmlHashDeallocator) free_config1); 93 xmlHashFree(config->conf, (xmlHashDeallocator)free_string); 94 xmlHashFree(config->properties, (xmlHashDeallocator)free_props); 95 xmlHashFree(config->metanames, (xmlHashDeallocator)free_metas); 96 xmlHashFree(config->tag_aliases, (xmlHashDeallocator)free_string); 97 xmlHashFree(config->parsers, (xmlHashDeallocator)free_string); 98 xmlHashFree(config->mimes, (xmlHashDeallocator)free_string); 99 xmlHashFree(config->index, (xmlHashDeallocator)free_string); 99 100 swish_xfree(config->flags); 100 101 … … 121 122 swish_Config *config; 122 123 swish_ConfigFlags *flags; 123 xmlHashTablePtr c, metas, parsers, index, prop, alias, parsewords; 124 xmlHashTablePtr c, metas, parsers, index, prop, alias; 125 swish_Property *tmpprop; 126 swish_MetaName *tmpmeta; 124 127 125 128 if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) … … 139 142 /* default metanames */ 140 143 metas = xmlHashCreate(8); 141 swish_hash_add(metas, 142 (xmlChar *) SWISH_DEFAULT_METANAME, 143 swish_xstrdup((xmlChar *) SWISH_DEFAULT_VALUE)); 144 swish_hash_add(metas, 145 (xmlChar *) SWISH_TITLE_METANAME, 146 swish_xstrdup((xmlChar *) SWISH_DEFAULT_VALUE)); 147 swish_hash_add(c, (xmlChar *) SWISH_META, metas); 144 swish_hash_add( 145 metas, 146 (xmlChar*)SWISH_DEFAULT_METANAME, 147 swish_init_metaname( swish_xstrdup((xmlChar*)SWISH_DEFAULT_METANAME) ) 148 ); 149 swish_hash_add( 150 metas, 151 (xmlChar*)SWISH_TITLE_METANAME, 152 swish_init_metaname( swish_xstrdup((xmlChar*)SWISH_TITLE_METANAME) ) 153 ); 154 155 /* increm ref counts after they've been stashed. a little awkward, but saves var names... */ 156 tmpmeta = xmlHashLookup(metas, (xmlChar*)SWISH_DEFAULT_METANAME); 157 tmpmeta->ref_cnt++; 158 tmpmeta = xmlHashLookup(metas, (xmlChar*)SWISH_TITLE_METANAME); 159 tmpmeta->ref_cnt++; 160 161 config->metanames = metas; 148 162 149 163 150 164 /* default MIME types */ 151 swish_hash_add(c, (xmlChar *) SWISH_MIME, swish_mime_hash());165 config->mimes = swish_mime_hash(); 152 166 153 167 … … 167 181 swish_xstrdup((xmlChar *) SWISH_DEFAULT_PARSER_TYPE)); 168 182 169 swish_hash_add(c, (xmlChar *) SWISH_PARSERS, parsers);183 config->parsers = parsers; 170 184 171 185 … … 183 197 swish_xstrdup((xmlChar *) setlocale(LC_ALL, NULL))); 184 198 185 swish_hash_add(c, (xmlChar *) SWISH_INDEX, index);199 config->index = index; 186 200 187 201 /* properties hash: each property is "propertyname" => type these match tag 188 202 * (meta) names and are aggregated for each doc, in propHash */ 189 203 prop = xmlHashCreate(8); 190 swish_hash_add(prop, 191 (xmlChar *) SWISH_PROP_DESCRIPTION, 192 swish_xstrdup((xmlChar *) SWISH_DEFAULT_VALUE)); 193 swish_hash_add(prop, 194 (xmlChar *) SWISH_PROP_TITLE, 195 swish_xstrdup((xmlChar *) SWISH_DEFAULT_VALUE)); 196 197 swish_hash_add(c, (xmlChar *) SWISH_PROP, prop); 204 swish_hash_add( 205 prop, 206 (xmlChar*)SWISH_PROP_DESCRIPTION, 207 swish_init_property(swish_xstrdup((xmlChar*)SWISH_PROP_DESCRIPTION)) 208 ); 209 swish_hash_add( 210 prop, 211 (xmlChar*)SWISH_PROP_TITLE, 212 swish_init_property(swish_xstrdup((xmlChar*)SWISH_PROP_TITLE)) 213 ); 214 215 /* same deal as metanames above */ 216 tmpprop = xmlHashLookup(prop, (xmlChar*)SWISH_PROP_DESCRIPTION); 217 tmpprop->ref_cnt++; 218 tmpprop = xmlHashLookup(prop, (xmlChar*)SWISH_PROP_TITLE); 219 tmpprop->ref_cnt++; 220 221 config->properties = prop; 198 222 199 223 … … 209 233 swish_xstrdup((xmlChar *) SWISH_PROP_DESCRIPTION)); 210 234 211 swish_hash_add(c, (xmlChar *) SWISH_ALIAS, alias); 212 213 /* word parsing settings */ 214 parsewords = xmlHashCreate(4); 215 swish_hash_add(parsewords, 216 (xmlChar *) SWISH_PARSE_WORDS, 217 swish_xstrdup((xmlChar *) SWISH_DEFAULT_VALUE)); 218 219 swish_hash_add(c, (xmlChar *) SWISH_WORDS, parsewords); 220 235 config->tag_aliases = alias; 236 237 /* misc default flags */ 238 flags->tokenize = 1; 239 221 240 config->conf = c; 222 241 config->ref_cnt = 0; … … 244 263 return config; 245 264 246 }247 248 swish_ConfigValue *249 swish_init_ConfigValue()250 {251 swish_ConfigValue *cv;252 cv = swish_xmalloc(sizeof(swish_ConfigValue));253 cv->ref_cnt = 1;254 cv->multi = 0;255 cv->equal = 0;256 cv->key = NULL;257 cv->value = NULL;258 return cv;259 }260 261 void262 swish_free_ConfigValue(swish_ConfigValue * cv)263 {264 if (cv->key != NULL)265 swish_xfree(cv->key);266 267 if (cv->value != NULL)268 swish_xfree(cv->value);269 270 swish_xfree(cv);271 }272 273 swish_ConfigValue *274 swish_keys(swish_Config * config,...)275 {276 va_list args;277 swish_ConfigValue *cv = swish_init_ConfigValue();278 279 va_start(args, config);280 281 282 va_end(args);283 return cv;284 }285 286 swish_ConfigValue *287 swish_value(swish_Config * config, xmlChar * key,...)288 {289 va_list args;290 swish_ConfigValue *cv = swish_init_ConfigValue();291 292 va_start(args, key);293 294 295 va_end(args);296 return cv;297 }298 299 300 /* a xml node is multi if: - it is a predefined top-level key (MetaNames, PropertyNames,301 * etc.) - it has the multi attribute present (value is ignored) - has one or more spaces302 * in the value */303 static int304 is_multi(xmlNode * node)305 {306 xmlChar *v;307 308 if (xmlHasProp(node, (const xmlChar *) "multi") != NULL)309 return 1;310 311 if (is_top_level(node))312 return 1;313 314 v = get_node_value(node);315 if (v != NULL && (xmlStrchr(v, ' ') || xmlStrchr(v, '\n')))316 {317 xmlFree(v);318 return 1;319 }320 321 return 0;322 }323 324 static int325 is_top_level(xmlNode * node)326 {327 if (xmlStrEqual(node->name, (xmlChar *) SWISH_META))328 return 1;329 330 if (xmlStrEqual(node->name, (xmlChar *) SWISH_PROP))331 return 1;332 333 if (xmlStrEqual(node->name, (xmlChar *) SWISH_PROP_MAX))334 return 1;335 336 if (xmlStrEqual(node->name, (xmlChar *) SWISH_PROP_SORT))337 return 1;338 339 return 0;340 }341 342 343 /* a xml node is equal if: - no attributes are present, just content - 'key' attr is344 * present and xmlStrEqual() with content - 'key' and 'value' attrs are both present and345 * xmlStrEqual() */346 static int347 is_equal(xmlNode * node)348 {349 xmlChar *v, *k;350 int e;351 352 if (!node_has_key(node) && !node_has_value(node))353 return 1;354 355 v = get_node_value(node);356 k = xmlGetProp(node, (const xmlChar *) "key");357 e = xmlStrEqual(k, v);358 xmlFree(v);359 xmlFree(k);360 361 if (e)362 return 1;363 364 365 if (node_has_value(node) && !node_has_key(node))366 {367 SWISH_CROAK("config node with value but no key: %s", node->name);368 return 0;369 }370 371 return 0;372 }373 374 static int375 node_has_key(xmlNode * node)376 {377 return node_has_attr(node, (const xmlChar *) "key");378 }379 380 static int381 node_has_value(xmlNode * node)382 {383 return node_has_attr(node, (const xmlChar *) "value");384 }385 386 static int387 node_has_type(xmlNode * node)388 {389 return node_has_attr(node, (const xmlChar *) "type");390 }391 392 static int393 node_has_attr(xmlNode * node, const xmlChar * att)394 {395 if (xmlHasProp(node, att))396 return 1;397 else398 return 0;399 }400 401 402 403 /* key is attr value if present, otherwise get_node_value() */404 static xmlChar *405 get_node_key(xmlNode * node)406 {407 xmlChar *k;408 k = xmlGetProp(node, (const xmlChar *) "key");409 return k; /* MUST be freed */410 }411 412 static xmlChar *413 get_node_type(xmlNode * node)414 {415 xmlChar *k;416 k = xmlGetProp(node, (const xmlChar *) "type");417 return k; /* MUST be freed */418 }419 420 /* get node content and remove and leading or trailing spaces */421 static xmlChar *422 get_node_value(xmlNode * node)423 {424 xmlChar *str;425 str = xmlNodeGetContent(node);426 if (str == NULL)427 {428 str = xmlGetProp(node, (const xmlChar *) "value");429 if (str == NULL)430 {431 SWISH_WARN("no value for config opt '%s'", node->name);432 return NULL;433 }434 }435 436 437 /* TODO strip spaces */438 439 return str; /* MUST be freed */440 265 } 441 266 … … 473 298 } 474 299 475 static void476 add_multi_node_to_cv(xmlNode * node, swish_ConfigValue * cv)477 {478 xmlChar *key, *tmp, *type;479 swish_StringList *value;480 int i;481 482 /* if node has an explicit key, use that with entire value else split up value483 * into tokens on whitespace. if node has a 'type' attr, use that as hash value,484 * else use str as both key/value. */485 486 if (node_has_key(node))487 {488 key = get_node_key(node);489 tmp = get_node_value(node);490 if (xmlHashLookup(cv->value, key))491 swish_hash_replace(cv->value, key, tmp);492 else493 swish_hash_add(cv->value, key, tmp);494 495 }496 else497 {498 tmp = get_node_value(node);499 value = swish_make_StringList(tmp);500 xmlFree(tmp);501 502 if (node_has_type(node))503 type = get_node_type(node);504 505 506 for (i = 0; i < value->n; i++)507 {508 key = swish_xstrdup(value->word[i]);509 if (type == NULL)510 tmp = swish_xstrdup(key);511 else512 tmp = type;513 514 if (xmlHashLookup(cv->value, key))515 swish_hash_replace(cv->value, key, tmp);516 else517 swish_hash_add(cv->value, key, tmp);518 }519 }520 521 }522 300 523 301 static xmlNode * … … 544 322 } 545 323 546 547 /* this is too complicated right now. might be easier to just plunge in and define548 * different config opt types (MetaNames, etc.) rather than try and remain agnostic and549 * extensible about attribute names, etc. */550 swish_Config *551 swish_parse_config_new(xmlChar * conf, swish_Config * config)552 {553 554 xmlNode *node, *root;555 xmlDocPtr doc;556 swish_ConfigValue *cv;557 558 doc = parse_xml_config(conf);559 root = get_dom_root(doc);560 561 /* -------------------------------------------------------------------------- get562 * options/values format is:563 *564 * <directive type="someval">some arg</directive>565 *566 * where type="someval" attr is optional -- defaults to whatever 'some arg' is567 * -------------------------------------------------------------------------- */568 569 for (node = root->children; node != NULL; node = node->next)570 {571 if (node->type == XML_ELEMENT_NODE)572 {573 574 /* is this opt already in our config? if yes, and multi, append575 * it if yes, and !multi, replace it if no, create it */576 577 if (xmlHashLookup(config->conf, node->name))578 {579 cv = xmlHashLookup(config->conf, node->name);580 581 if (cv->multi) /* already flagged as multi */582 {583 SWISH_DEBUG_MSG("%s is an existing multi-config", node->name);584 585 add_multi_node_to_cv(node, cv);586 587 }588 else589 {590 SWISH_DEBUG_MSG("%s exists but is not a multi-config", node->name);591 592 /* free the existing one and replace it with new593 * one */594 swish_free_ConfigValue(cv);595 596 cv = swish_init_ConfigValue();597 cv->key = get_node_name(node);598 cv->value = get_node_value(node);599 600 }601 }602 else603 {604 /* TODO - split all these if/else into separate functions */605 cv = swish_init_ConfigValue();606 607 if (is_multi(node))608 {609 SWISH_DEBUG_MSG("%s is a new multi-config", node->name);610 cv->value = swish_new_hash(16);611 add_multi_node_to_cv(node, cv);612 613 }614 615 if (is_equal(node))616 {617 SWISH_DEBUG_MSG("%s is an equal node", node->name);618 cv->equal = 1;619 }620 621 622 }623 624 }625 626 }627 628 xmlFreeDoc(doc);629 xmlCleanupParser();630 return config;631 }632 324 633 325 swish_Config * … … 722 414 723 415 724 arg_list = swish_make_ StringList(opt_arg);416 arg_list = swish_make_stringlist(opt_arg); 725 417 726 418 for (i = 0; i < arg_list->n; i++) … … 750 442 SWISH_DEBUG_MSG("tolower str: >%s<", tmp_arg); 751 443 752 tmp_arg = swish_str_tolower(tmp_arg); 444 tmp_arg = swish_str_tolower(tmp_arg); // TODO mem leak !! ?? 753 445 754 446 } … … 768 460 } 769 461 770 swish_free_ StringList(arg_list);462 swish_free_stringlist(arg_list); 771 463 772 464 /* don't use our swish_xfree since it throws off memcount */ … … 802 494 803 495 static void 804 config_ val_printer(xmlChar * val, xmlChar * str, xmlChar *key)805 { 806 SWISH_DEBUG_MSG(" %s => %s", key, val);496 config_printer(xmlChar *val, xmlChar *str, xmlChar *key) 497 { 498 SWISH_DEBUG_MSG(" %s: %s => %s", str, key, val); 807 499 } 808 500 809 501 static void 810 config_printer(xmlHashTablePtr vhash, xmlChar * str, xmlChar * key) 811 { 812 SWISH_DEBUG_MSG(" Config %s:", key); 813 814 xmlHashScan(vhash, (xmlHashScanner) config_val_printer, "vhash"); 815 816 return; 502 property_printer(swish_Property *prop, xmlChar *str, xmlChar *propname) 503 { 504 SWISH_DEBUG_MSG(" %s: %s =>", str, propname); 505 swish_debug_property(prop); 506 } 507 508 static void 509 metaname_printer(swish_MetaName *meta, xmlChar *str, xmlChar *metaname) 510 { 511 SWISH_DEBUG_MSG(" %s: %s =>", str, metaname); 512 swish_debug_metaname(meta); 817 513 } 818 514 … … 821 517 swish_debug_config(swish_Config * config) 822 518 { 823 int size = xmlHashSize(config->conf);519 int size = xmlHashSize(config->conf); 824 520 825 521 SWISH_DEBUG_MSG("config->ref_cnt = %d", config->ref_cnt); … … 828 524 SWISH_DEBUG_MSG("ptr addr: 0x%x %d", (int) config->conf, (int) config->conf); 829 525 830 xmlHashScan(config->conf, (xmlHashScanner) config_printer, "opt name"); 831 832 return 1; 833 834 } 835 836 /* PUBLIC */ 837 xmlHashTablePtr 838 swish_subconfig_hash(swish_Config * config, xmlChar * key) 839 { 840 xmlHashTablePtr v = xmlHashLookup(config->conf, key); 841 842 if (v == NULL) 843 { 844 /* why does this happen when value is a hashptr ? */ 845 SWISH_DEBUG_MSG("Config option '%s' has NULL value", key); 846 } 847 848 return v; 849 } 850 851 /* PUBLIC */ 852 /* returns true/false if 'value' is a valid key in the subconfig hash for 'key' */ 853 /* example might be looking up a specific metaname in the MetaNames hash */ 854 int 855 swish_config_value_exists(swish_Config * config, xmlChar * key, xmlChar * value) 856 { 857 xmlHashTablePtr v = swish_subconfig_hash(config, key); 858 return ((int) xmlHashLookup(v, value)); 859 } 860 861 xmlChar * 862 swish_get_config_value(swish_Config * config, xmlChar * key, xmlChar * value) 863 { 864 xmlHashTablePtr v = swish_subconfig_hash(config, key); 865 return (xmlChar *) xmlHashLookup(v, value); 866 } 526 xmlHashScan(config->conf, (xmlHashScanner)config_printer, "misc conf"); 527 xmlHashScan(config->properties, (xmlHashScanner)property_printer, "properties"); 528 xmlHashScan(config->metanames, (xmlHashScanner)metaname_printer, "metanames"); 529 xmlHashScan(config->parsers, (xmlHashScanner)config_printer, "parsers"); 530 xmlHashScan(config->mimes, (xmlHashScanner)config_printer, "mimes"); 531 xmlHashScan(config->index, (xmlHashScanner)config_printer, "index"); 532 533 return size; 534 535 } 536 libswish3/trunk/src/libswish3/hash.c
r1952 r2041 69 69 } 70 70 71 boolean 72 swish_hash_exists( xmlHashTablePtr hash, xmlChar *key ) 73 { 74 return xmlHashLookup(hash, key) ? 1 : 0; 75 } 76 71 77 xmlHashTablePtr swish_new_hash(int size) 72 78 { libswish3/trunk/src/libswish3/libswish3.h
r2030 r2041 70 70 #define SWISH_INDEX_LOCALE "Locale" 71 71 #define SWISH_DEFAULT_VALUE "1" 72 #define SWISH_ PARSE_WORDS"Tokenize"72 #define SWISH_TOKENIZE "Tokenize" 73 73 74 74 /* tags */ … … 146 146 #endif 147 147 148 typedef char boolean; 148 149 typedef struct swish_3 swish_3; 149 150 typedef struct swish_Token swish_Token; … … 203 204 struct swish_Config 204 205 { 205 int ref_cnt; /* for bindings */206 int ref_cnt; 206 207 void *stash; /* for bindings */ 207 xmlHashTablePtr conf; /* the meat */ 208 xmlHashTablePtr conf; /* misc settings */ 209 xmlHashTablePtr properties; 210 xmlHashTablePtr metanames; 211 xmlHashTablePtr tag_aliases; 212 xmlHashTablePtr parsers; 213 xmlHashTablePtr mimes; 214 xmlHashTablePtr index; 208 215 struct swish_ConfigFlags *flags; /* shortcuts for parsing */ 209 216 }; … … 211 218 struct swish_ConfigFlags 212 219 { 220 boolean tokenize; 213 221 214 215 }; 216 217 struct swish_ConfigValue 218 { 219 int ref_cnt; 220 unsigned int multi; /* indicates whether value is a string or hashref */ 221 unsigned int equal; /* indicates whether key/value pairs are equal */ 222 void *value; /* xmlHashTablePtr or xmlChar *str */ 223 xmlChar *key; /* should be same as the key that points at this object */ 224 }; 225 222 }; 226 223 227 224 struct swish_NamedBuffer … … 248 245 struct swish_MetaName 249 246 { 247 int ref_cnt; 250 248 unsigned int id; 251 249 xmlChar *name; 252 250 int bias; 251 xmlChar *alias_for; 253 252 }; 254 253 255 254 struct swish_Property 256 255 { 256 int ref_cnt; 257 257 unsigned int id; 258 258 xmlChar *name; 259 boolean ignore_case; 260 boolean type; 261 boolean verbatim; 262 xmlChar *alias_for; 263 unsigned int max; 264 boolean sort; 259 265 }; 260 266 … … 316 322 }; 317 323 318 // TODO maybe store swish_Parser * here instead of separate config and analyzer319 324 struct swish_ParserData 320 325 { … … 368 373 int swish_hash_replace( xmlHashTablePtr hash, xmlChar *key, void *value ); 369 374 int swish_hash_delete( xmlHashTablePtr hash, xmlChar *key ); 375 boolean swish_hash_exists( xmlHashTablePtr hash, xmlChar *key ); 370 376 xmlHashTablePtr swish_new_hash(int size); 371 377 /* … … 421 427 xmlChar * swish_str_skip_ws(xmlChar *s); 422 428 void swish_str_trim_ws(xmlChar *string); 429 int swish_str_all_ws(xmlChar * s); 423 430 void swish_debug_wchars( const wchar_t * widechars ); 424 431 int swish_wchar_t_comp(const void *s1, const void *s2); 425 432 int swish_sort_wchar(wchar_t *s); 426 swish_StringList * swish_make_ StringList(xmlChar * line);427 swish_StringList * swish_init_ StringList();428 void swish_free_ StringList(swish_StringList * sl);433 swish_StringList * swish_make_stringlist(xmlChar * line); 434 swish_StringList * swish_init_stringlist(); 435 void swish_free_stringlist(swish_StringList * sl); 429 436 /* 430 437 =cut … … 438 445 swish_Config * swish_add_config( xmlChar * conf, swish_Config * config ); 439 446 swish_Config * swish_parse_config( xmlChar * conf, swish_Config * config ); 440 swish_Config * swish_parse_config_new( xmlChar * conf, swish_Config * config );441 447 int swish_debug_config( swish_Config * config ); 442 xmlHashTablePtr swish_subconfig_hash( swish_Config * config, xmlChar *key);443 int swish_config_value_exists( swish_Config * config, xmlChar *key, xmlChar *value );444 xmlChar * swish_get_config_value(swish_Config * config, xmlChar * key, xmlChar * value);445 448 void swish_free_config(swish_Config * config); 446 swish_ConfigValue * swish_keys( swish_Config * config, ... );447 swish_ConfigValue * swish_value( swish_Config * config, xmlChar * key, ... );448 swish_ConfigValue * swish_init_ConfigValue();449 void swish_free_ConfigValue( swish_ConfigValue * cv );450 449 xmlHashTablePtr swish_mime_hash(); 451 450 xmlChar * swish_get_mime_type( swish_Config * config, xmlChar * fileext ); … … 553 552 =head2 Buffer Functions 554 553 */ 555 swish_NamedBuffer * swish_init_nb( swish_Config * config, xmlChar * configKey);554 swish_NamedBuffer * swish_init_nb( xmlHashTablePtr confhash ); 556 555 void swish_free_nb( swish_NamedBuffer * nb ); 557 556 void swish_debug_nb( swish_NamedBuffer * nb, xmlChar * label ); … … 574 573 */ 575 574 575 /* 576 =head2 Property Functions 577 */ 578 swish_Property * swish_init_property( xmlChar *name ); 579 void swish_free_property( swish_Property *prop ); 580 void swish_debug_property( swish_Property *prop ); 581 /* 582 =cut 583 */ 584 585 /* 586 =head2 MetaName Functions 587 */ 588 swish_MetaName * swish_init_metaname( xmlChar *name); 589 void swish_free_metaname( swish_MetaName *m ); 590 void swish_debug_metaname( swish_MetaName *m ); 591 /* 592 =cut 593 */ 594 576 595 577 596 #ifdef __cplusplus libswish3/trunk/src/libswish3/mime_types.c
r1952 r2041 220 220 { 221 221 xmlChar * mime; 222 xmlHashTablePtr mimes = swish_subconfig_hash( config, (xmlChar *)SWISH_MIME ); 223 mime = xmlHashLookup( mimes, fileext ); 222 mime = xmlHashLookup( config->mimes, fileext ); 224 223 if ( mime == NULL ) 225 224 { … … 236 235 xmlChar *parser; 237 236 xmlChar *deftype; 238 xmlHashTablePtr parsers; 239 240 parsers = swish_subconfig_hash( config, (xmlChar *)SWISH_PARSERS ); 241 parser = xmlHashLookup( parsers, mime ); 237 238 parser = xmlHashLookup( config->parsers, mime ); 242 239 243 240 if (SWISH_DEBUG > 9) 244 241 SWISH_DEBUG_MSG("using parser '%s' based on MIME '%s'", parser, mime ); 245 242 246 deftype = xmlHashLookup( parsers, (xmlChar *)SWISH_DEFAULT_PARSER ); /* error check?? */243 deftype = xmlHashLookup( config->parsers, (xmlChar *)SWISH_DEFAULT_PARSER ); /* error check?? */ 247 244 248 245 if ( parser == NULL ) libswish3/trunk/src/libswish3/namedbuffer.c
r2028 r2041 35 35 36 36 static void free_name_from_hash(void *buffer, xmlChar * name); 37 static void add_name_to_hash( xmlChar * val, xmlHashTablePtr hash, xmlChar *name);38 static void print_buffer(xmlBufferPtr buffer, xmlChar * label, xmlChar *name);37 static void add_name_to_hash(void *ignored, xmlHashTablePtr nbhash, xmlChar *name); 38 static void print_buffer(xmlBufferPtr buffer, xmlChar *label, xmlChar *name); 39 39 40 40 static void 41 add_name_to_hash( xmlChar * val, xmlHashTablePtrhash, xmlChar * name)41 add_name_to_hash(void *ignored, xmlHashTablePtr nbhash, xmlChar * name) 42 42 { 43 43 /* make sure we don't already have it */ 44 if ( xmlHashLookup(hash, name))44 if (swish_hash_exists(nbhash, name)) 45 45 { 46 46 SWISH_WARN("%s is already in NamedBuffer hash -- ignoring", name); … … 52 52 SWISH_DEBUG_MSG(" adding %s to NamedBuffer\n", name); 53 53 54 swish_hash_add( hash, name, xmlBufferCreateSize((size_t)SWISH_BUFFER_CHUNK_SIZE));54 swish_hash_add(nbhash, name, xmlBufferCreateSize((size_t)SWISH_BUFFER_CHUNK_SIZE)); 55 55 } 56 56 … … 65 65 66 66 swish_NamedBuffer * 67 swish_init_nb( swish_Config * config, xmlChar * confKey)67 swish_init_nb( xmlHashTablePtr confhash ) 68 68 { 69 69 swish_NamedBuffer * nb = swish_xmalloc(sizeof(swish_NamedBuffer)); … … 72 72 nb->hash = xmlHashCreate(8); /* will grow as needed */ 73 73 74 xmlHashTablePtr confHash = swish_subconfig_hash( config, confKey ); 75 76 /* add each name to our hash */ 77 xmlHashScan(confHash, (xmlHashScanner)add_name_to_hash, nb->hash); 74 /* init a buffer for each key in confhash */ 75 xmlHashScan(confhash, (xmlHashScanner)add_name_to_hash, nb->hash); 78 76 79 77 return nb; libswish3/trunk/src/libswish3/parser.c
r2030 r2041 293 293 294 294 /* change our internal name for this tag if it is aliased in config */ 295 alias = swish_get_config_value(parser_data->s3->config, (xmlChar*)SWISH_ALIAS, swishtag);295 alias = xmlHashLookup(parser_data->s3->config->tag_aliases, swishtag); 296 296 if (alias) 297 297 { … … 447 447 448 448 /* set property if this tag is configured for it */ 449 if (swish_ config_value_exists(parser_data->s3->config, (xmlChar*)SWISH_PROP, parser_data->tag))449 if (swish_hash_exists(parser_data->s3->config->properties, parser_data->tag)) 450 450 { 451 451 if (SWISH_DEBUG >= SWISH_DEBUG_PARSER) 452 452 SWISH_DEBUG_MSG(" %s = new property", parser_data->tag); 453 453 454 add_stack_to_prop_buf(NULL, parser_data); 454 add_stack_to_prop_buf(NULL, parser_data); //TODO why NULL here ?? 455 455 xmlBufferEmpty(parser_data->prop_buf); 456 456 457 457 parser_data->propstack = push_tag_stack(parser_data->propstack, parser_data->tag); 458 458 459 /* SWISH_DEBUG_MSG("%s pushed ok unto propstack", parser_data->tag); */ 459 if (SWISH_DEBUG >= SWISH_DEBUG_PARSER) 460 SWISH_DEBUG_MSG("%s pushed ok unto propstack", parser_data->tag); 460 461 } 461 462 462 463 /* likewise for metastack */ 463 if (swish_ config_value_exists(parser_data->s3->config, (xmlChar*)SWISH_META, parser_data->tag))464 if (swish_hash_exists(parser_data->s3->config->metanames, parser_data->tag)) 464 465 { 465 466 if (SWISH_DEBUG >= SWISH_DEBUG_PARSER) … … 750 751 ptr->wordlist = swish_init_wordlist(); 751 752 ptr->wordlist->ref_cnt++; 752 ptr->properties = swish_init_nb(s3->config , (xmlChar*)SWISH_PROP);753 ptr->properties = swish_init_nb(s3->config->properties); 753 754 ptr->properties->ref_cnt++; 754 ptr->metanames = swish_init_nb(s3->config , (xmlChar*)SWISH_META);755 ptr->metanames = swish_init_nb(s3->config->metanames); 755 756 ptr->metanames->ref_cnt++; 756 757 … … 18
