Changeset 2125
- Timestamp:
- 04/15/08 10:02:40 (1 month ago)
- Files:
-
- libswish3/trunk/src/libswish3/config.c (modified) (11 diffs)
- libswish3/trunk/src/libswish3/header.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
libswish3/trunk/src/libswish3/config.c
r2110 r2125 54 54 xmlChar *key 55 55 ); 56 static void stringlist_printer( 57 swish_StringList *strlist, 58 xmlChar *str, 59 xmlChar *key 60 ); 56 61 static void property_printer( 57 62 swish_Property *prop, … … 82 87 xmlHashTablePtr metas2 83 88 ); 89 static void 90 free_stringlist( 91 swish_StringList *strlist, 92 xmlChar *key 93 ); 84 94 85 95 static void … … 93 103 94 104 swish_xfree(payload); 105 } 106 107 static void 108 free_stringlist( 109 swish_StringList *strlist, 110 xmlChar *key 111 ) 112 { 113 int i; 114 if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { 115 SWISH_DEBUG_MSG(" freeing config->stringlists %s [%d strings]", key, strlist->n); 116 for(i=0; i<strlist->n; i++) { 117 SWISH_DEBUG_MSG(" string: %s", strlist->word[i]); 118 } 119 } 120 121 swish_free_stringlist(strlist); 95 122 } 96 123 … … 145 172 xmlHashFree(config->mimes, (xmlHashDeallocator)free_string); 146 173 xmlHashFree(config->index, (xmlHashDeallocator)free_string); 174 xmlHashFree(config->stringlists, (xmlHashDeallocator)free_stringlist); 147 175 swish_free_config_flags(config->flags); 148 176 … … 165 193 flags = swish_xmalloc(sizeof(swish_ConfigFlags)); 166 194 flags->tokenize = 1; 195 flags->context_as_meta = 0; 167 196 flags->meta_ids = swish_init_hash(8); 168 197 flags->prop_ids = swish_init_hash(8); … … 204 233 config->index = swish_init_hash(8); 205 234 config->tag_aliases = swish_init_hash(8); 235 config->stringlists = swish_init_hash(8); 206 236 config->mimes = NULL; 207 237 config->ref_cnt = 0; … … 338 368 } 339 369 370 static void 371 stringlist_printer( 372 swish_StringList *strlist, 373 xmlChar *str, 374 xmlChar *key 375 ) 376 { 377 int i; 378 for(i=0; i<strlist->n; i++) { 379 SWISH_DEBUG_MSG(" %s: %s => %s", str, key, strlist->word[i]); 380 } 381 } 382 340 383 static void 341 384 property_printer( … … 372 415 373 416 xmlHashScan(config->misc, (xmlHashScanner)config_printer, "misc conf"); 417 xmlHashScan(config->stringlists, (xmlHashScanner)stringlist_printer, "stringlists"); 374 418 xmlHashScan(config->properties, (xmlHashScanner)property_printer, "properties"); 375 419 xmlHashScan(config->metanames, (xmlHashScanner)metaname_printer, "metanames"); … … 475 519 } 476 520 521 static void 522 copy_strlist( 523 swish_StringList *strlist2, 524 xmlHashTablePtr strlists1, 525 xmlChar *key 526 ) 527 { 528 swish_StringList *strlist1; 529 if (swish_hash_exists(strlists1, key)) { 530 strlist1 = swish_hash_fetch(strlists1, key); 531 swish_merge_stringlists(strlist2, strlist1); 532 } 533 else { 534 strlist1 = swish_copy_stringlist(strlist2); 535 swish_hash_add(strlists1, key, strlist1); 536 } 537 } 538 539 static void 540 merge_stringlists( 541 xmlHashTablePtr strlists1, 542 xmlHashTablePtr strlists2 543 ) 544 { 545 xmlHashScan(strlists2, (xmlHashScanner)copy_strlist, strlists1); 546 } 547 477 548 void 478 549 swish_config_merge( … … 517 588 } 518 589 swish_hash_merge(config1->misc, config2->misc); 590 591 if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { 592 SWISH_DEBUG_MSG("merge stringlists"); 593 } 594 merge_stringlists(config1->stringlists, config2->stringlists); 519 595 520 596 if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { … … 523 599 524 600 /* set flags */ 601 /* TODO pull these settings from config proper. but where in process? */ 525 602 config1->flags->tokenize = config2->flags->tokenize; 603 config1->flags->context_as_meta = config2->flags->context_as_meta; 526 604 527 605 if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { libswish3/trunk/src/libswish3/header.c
r2110 r2125 94 94 xmlChar *name 95 95 ); 96 static void 97 read_key_value_stringlist( 98 xmlTextReaderPtr reader, 99 xmlHashTablePtr hash, 100 xmlChar *name 101 ); 96 102 static void read_header( 97 103 char *filename, … … 497 503 && xmlStrEqual(name, (xmlChar *)"#text")) { 498 504 return; 499 } 505 } 500 506 501 507 if (type == XML_READER_TYPE_END_ELEMENT) { … … 531 537 } 532 538 else { 533 if (xmlStrEqual(name, (const xmlChar *)SWISH_PROP)) { 539 540 541 /* the special include directive means we stop and process 542 * that config file immediately instead of storing the value 543 * in the hash. 544 */ 545 if (xmlStrEqual(name, (xmlChar *)SWISH_INCLUDE_FILE)) { 546 swish_merge_config_with_header((char*)value, h->config); 547 return; 548 } 549 else if (xmlStrEqual(name, (const xmlChar *)SWISH_PROP)) { 534 550 h->isprops = 1; 535 551 return; … … 583 599 else if (h->isalias) { 584 600 read_key_values_pair(reader, h->config->tag_aliases, (xmlChar *)name); 601 return; 602 } 603 else if (xmlStrEqual((xmlChar *)SWISH_CLASS_ATTRIBUTES, (xmlChar *)name)) { 604 read_key_value_stringlist(reader, h->config->stringlists, (xmlChar *)name); 585 605 return; 586 606 } … … 596 616 } 597 617 618 } 619 620 static void 621 read_key_value_stringlist( 622 xmlTextReaderPtr reader, 623 xmlHashTablePtr hash, 624 xmlChar *name 625 ) 626 { 627 swish_StringList *strlist; 628 xmlChar *str; 629 const xmlChar *value; 630 631 /* element. get text and add to misc */ 632 if (xmlTextReaderRead(reader) == 1) { 633 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_TEXT) { 634 635 value = xmlTextReaderConstValue(reader); 636 str = swish_str_tolower((xmlChar *)value); 637 strlist = swish_make_stringlist(str); 638 if (swish_hash_exists(hash, name)) { 639 swish_merge_stringlists(strlist, swish_hash_fetch(hash, name)); 640 } 641 else { 642 swish_hash_add(hash, name, strlist); 643 } 644 swish_xfree(str); 645 } 646 else { 647 SWISH_CROAK("header line missing value: %s", name); 648 } 649 } 650 else { 651 SWISH_CROAK("error reading value for header element %s", name); 652 } 598 653 } 599 654 … … 654 709 if (xmlTextReaderRead(reader) == 1) { 655 710 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_TEXT) { 656 value = xmlTextReaderConstValue(reader); 711 value = xmlTextReaderConstValue(reader); 657 712 /* SWISH_DEBUG_MSG("read key %s for value %s", name, value); */ 658 713 if (swish_hash_exists(hash, name)) {
