Changeset 2110

Show
Ignore:
Timestamp:
04/03/08 22:44:09 (1 month ago)
Author:
karpet
Message:

Refactor duplicate id checks to use hash instead of array. Fixes bug with merging configs. Default ->id is now -1 (invalid value)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • libswish3/trunk/src/libswish3/config.c

    r2108 r2110  
    138138    } 
    139139 
    140     xmlHashFree(config->misc, (xmlHashDeallocator) free_string); 
    141     xmlHashFree(config->properties, (xmlHashDeallocator) free_props); 
    142     xmlHashFree(config->metanames, (xmlHashDeallocator) free_metas); 
    143     xmlHashFree(config->tag_aliases, (xmlHashDeallocator) free_string); 
    144     xmlHashFree(config->parsers, (xmlHashDeallocator) free_string); 
    145     xmlHashFree(config->mimes, (xmlHashDeallocator) free_string); 
    146     xmlHashFree(config->index, (xmlHashDeallocator) free_string); 
    147     swish_xfree(config->flags); 
     140    xmlHashFree(config->misc, (xmlHashDeallocator)free_string); 
     141    xmlHashFree(config->properties, (xmlHashDeallocator)free_props); 
     142    xmlHashFree(config->metanames, (xmlHashDeallocator)free_metas); 
     143    xmlHashFree(config->tag_aliases, (xmlHashDeallocator)free_string); 
     144    xmlHashFree(config->parsers, (xmlHashDeallocator)free_string); 
     145    xmlHashFree(config->mimes, (xmlHashDeallocator)free_string); 
     146    xmlHashFree(config->index, (xmlHashDeallocator)free_string); 
     147    swish_free_config_flags(config->flags); 
    148148 
    149149    if (config->ref_cnt != 0) { 
     
    162162) 
    163163{ 
    164     swish_ConfigFlags   *flags; 
    165     int                  i; 
    166      
    167     flags               = swish_xmalloc(sizeof(swish_ConfigFlags)); 
    168     flags->tokenize     = 1; 
    169         
    170     /* set all defaults to 0 */ 
    171     for(i=0; i<SWISH_MAX_IDS; i++) { 
    172         flags->meta_ids[i] = 0; 
    173     } 
    174     for(i=0; i<SWISH_MAX_IDS; i++) { 
    175         flags->prop_ids[i] = 0; 
    176     } 
    177      
     164    swish_ConfigFlags *flags; 
     165    flags = swish_xmalloc(sizeof(swish_ConfigFlags)); 
     166    flags->tokenize = 1; 
     167    flags->meta_ids = swish_init_hash(8); 
     168    flags->prop_ids = swish_init_hash(8); 
     169 
    178170    return flags; 
    179171} 
    180172 
    181      
     173void 
     174swish_free_config_flags( 
     175    swish_ConfigFlags * flags 
     176
     177
     178    /* 
     179       these hashes are for convenience and are really freed in swish_free_config()  
     180     */ 
     181    xmlHashFree(flags->meta_ids, NULL); 
     182    xmlHashFree(flags->prop_ids, NULL); 
     183    swish_xfree(flags); 
     184
    182185 
    183186/* init config object */ 
     
    204207    config->ref_cnt = 0; 
    205208    config->stash = NULL; 
    206      
     209 
    207210    if (SWISH_DEBUG & SWISH_DEBUG_MEMORY) { 
    208211        SWISH_DEBUG_MSG("config ptr 0x%x", (int)config); 
     
    220223    swish_Property *tmpprop; 
    221224    swish_MetaName *tmpmeta; 
     225    xmlChar *tmpbuf; 
    222226 
    223227    if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) 
     
    230234 
    231235/* metanames */ 
    232     swish_hash_add(config->metanames, (xmlChar *)SWISH_DEFAULT_METANAME, 
    233                    swish_init_metaname(swish_xstrdup 
    234                                        ((xmlChar *)SWISH_DEFAULT_METANAME)) 
    235         ); 
    236     swish_hash_add(config->metanames, (xmlChar *)SWISH_TITLE_METANAME, 
    237                    swish_init_metaname(swish_xstrdup 
    238                                        ((xmlChar *)SWISH_TITLE_METANAME)) 
    239         ); 
    240  
    241 /* alter swish_MetaName objects after they've been stashed. 
    242        a little awkward, but saves var names. 
    243 */ 
    244     tmpmeta = 
    245         swish_hash_fetch(config->metanames, (xmlChar *)SWISH_DEFAULT_METANAME); 
     236    // default 
     237    tmpmeta = swish_init_metaname(swish_xstrdup((xmlChar *)SWISH_DEFAULT_METANAME)); 
    246238    tmpmeta->ref_cnt++; 
    247239    tmpmeta->id = SWISH_META_DEFAULT_ID; 
    248     tmpmeta = 
    249         swish_hash_fetch(config->metanames, (xmlChar *)SWISH_TITLE_METANAME); 
     240    tmpbuf = swish_int_to_string(SWISH_META_DEFAULT_ID); 
     241    swish_hash_add(config->flags->meta_ids, tmpbuf, tmpmeta); 
     242    swish_hash_add(config->metanames, (xmlChar *)SWISH_DEFAULT_METANAME, tmpmeta); 
     243    swish_xfree(tmpbuf); 
     244 
     245    // title 
     246    tmpmeta = swish_init_metaname(swish_xstrdup((xmlChar *)SWISH_TITLE_METANAME)); 
    250247    tmpmeta->ref_cnt++; 
    251248    tmpmeta->id = SWISH_META_TITLE_ID; 
     249    tmpbuf = swish_int_to_string(SWISH_META_TITLE_ID); 
     250    swish_hash_add(config->flags->meta_ids, tmpbuf, tmpmeta); 
     251    swish_hash_add(config->metanames, (xmlChar *)SWISH_TITLE_METANAME, tmpmeta); 
     252    swish_xfree(tmpbuf); 
     253 
     254/* properties */ 
     255    // description 
     256    tmpprop = swish_init_property(swish_xstrdup((xmlChar *)SWISH_PROP_DESCRIPTION)); 
     257    tmpprop->ref_cnt++; 
     258    tmpprop->id = SWISH_PROP_DESCRIPTION_ID; 
     259    swish_hash_add(config->properties, (xmlChar *)SWISH_PROP_DESCRIPTION, tmpprop); 
     260    tmpbuf = swish_int_to_string(SWISH_PROP_DESCRIPTION_ID); 
     261    swish_hash_add(config->flags->prop_ids, tmpbuf, tmpprop); 
     262    swish_xfree(tmpbuf); 
     263 
     264    // title 
     265    tmpprop = swish_init_property(swish_xstrdup((xmlChar *)SWISH_PROP_TITLE)); 
     266    tmpprop->ref_cnt++; 
     267    tmpprop->id = SWISH_PROP_TITLE_ID; 
     268    swish_hash_add(config->properties, (xmlChar *)SWISH_PROP_TITLE, tmpprop); 
     269    tmpbuf = swish_int_to_string(SWISH_PROP_TITLE_ID); 
     270    swish_hash_add(config->flags->prop_ids, tmpbuf, tmpprop); 
     271    swish_xfree(tmpbuf); 
    252272 
    253273/* parsers */ 
     
    269289                   swish_xstrdup((xmlChar *)setlocale(LC_ALL, ""))); 
    270290 
    271 /* properties */ 
    272     swish_hash_add(config->properties, (xmlChar *)SWISH_PROP_DESCRIPTION, 
    273                    swish_init_property(swish_xstrdup 
    274                                        ((xmlChar *)SWISH_PROP_DESCRIPTION)) 
    275         ); 
    276     swish_hash_add(config->properties, (xmlChar *)SWISH_PROP_TITLE, 
    277                    swish_init_property(swish_xstrdup 
    278                                        ((xmlChar *)SWISH_PROP_TITLE)) 
    279         ); 
    280  
    281 /* same deal as metanames above */ 
    282     tmpprop = 
    283         swish_hash_fetch(config->properties, (xmlChar *)SWISH_PROP_DESCRIPTION); 
    284     tmpprop->ref_cnt++; 
    285     tmpprop->id = SWISH_PROP_DESCRIPTION_ID; 
    286     tmpprop = swish_hash_fetch(config->properties, (xmlChar *)SWISH_PROP_TITLE); 
    287     tmpprop->ref_cnt++; 
    288     tmpprop->id = SWISH_PROP_TITLE_ID; 
    289  
    290291/* aliases: other names a tag might be known as, for matching properties and 
    291292     * metanames */ 
     
    370371    SWISH_DEBUG_MSG("ptr addr: 0x%x  %d", (int)config, (int)config); 
    371372 
    372     xmlHashScan(config->misc, (xmlHashScanner) config_printer, "misc conf"); 
    373     xmlHashScan(config->properties, (xmlHashScanner) property_printer, 
    374                 "properties"); 
    375     xmlHashScan(config->metanames, (xmlHashScanner) metaname_printer, 
    376                 "metanames"); 
    377     xmlHashScan(config->parsers, (xmlHashScanner) config_printer, "parsers"); 
    378     xmlHashScan(config->mimes, (xmlHashScanner) config_printer, "mimes"); 
    379     xmlHashScan(config->index, (xmlHashScanner) config_printer, "index"); 
    380     xmlHashScan(config->tag_aliases, (xmlHashScanner) config_printer, 
    381                 "tag_aliases"); 
     373    xmlHashScan(config->misc, (xmlHashScanner)config_printer, "misc conf"); 
     374    xmlHashScan(config->properties, (xmlHashScanner)property_printer, "properties"); 
     375    xmlHashScan(config->metanames, (xmlHashScanner)metaname_printer, "metanames"); 
     376    xmlHashScan(config->parsers, (xmlHashScanner)config_printer, "parsers"); 
     377    xmlHashScan(config->mimes, (xmlHashScanner)config_printer, "mimes"); 
     378    xmlHashScan(config->index, (xmlHashScanner)config_printer, "index"); 
     379    xmlHashScan(config->tag_aliases, (xmlHashScanner)config_printer, "tag_aliases"); 
    382380} 
    383381 
     
    390388{ 
    391389    swish_Property *prop1; 
    392     boolean in_hash; 
    393390 
    394391    if (swish_hash_exists(props1, prop2name)) { 
    395392        prop1 = swish_hash_fetch(props1, prop2name); 
    396         in_hash = 1; 
     393        if (prop1->name != NULL) { 
     394            swish_xfree(prop1->name); 
     395            prop1->name = swish_xstrdup(prop2->name); 
     396        } 
    397397    } 
    398398    else { 
    399399        prop1 = swish_init_property(swish_xstrdup(prop2name)); 
    400400        prop1->ref_cnt++; 
    401         in_hash = 0; 
    402     } 
    403  
    404     prop1->id = prop2->id; 
    405     if (in_hash && prop1->name != NULL) { 
    406         swish_xfree(prop1->name); 
    407         prop1->name = swish_xstrdup(prop2->name); 
    408     } 
     401        swish_hash_add(props1, prop1->name, prop1); 
     402    } 
     403/*  
     404    SWISH_DEBUG_MSG("%s prop1->id = %d    %s prop2->id = %d", 
     405                    prop1->name, prop1->id, prop2->name, prop2->id); 
     406 */ 
     407    prop1->id = prop2->id;         
    409408    prop1->ignore_case = prop2->ignore_case; 
    410409    prop1->type = prop2->type; 
     
    419418    prop1->sort = prop2->sort; 
    420419 
    421     if (!in_hash) { 
    422         swish_hash_add(props1, prop1->name, prop1); 
    423     } 
    424  
    425420} 
    426421 
     
    431426) 
    432427{ 
    433     xmlHashScan(props2, (xmlHashScanner) copy_property, props1); 
     428    xmlHashScan(props2, (xmlHashScanner)copy_property, props1); 
    434429} 
    435430 
     
    442437{ 
    443438    swish_MetaName *meta1; 
    444     boolean in_hash; 
    445  
     439     
    446440    if (swish_hash_exists(metas1, meta2name)) { 
    447441        meta1 = swish_hash_fetch(metas1, meta2name); 
    448         in_hash = 1; 
     442        if (meta1->name != NULL) { 
     443            swish_xfree(meta1->name); 
     444            meta1->name = swish_xstrdup(meta2->name); 
     445        }     
    449446    } 
    450447    else { 
    451448        meta1 = swish_init_metaname(swish_xstrdup(meta2name)); 
    452449        meta1->ref_cnt++; 
    453         in_hash = 0; 
    454     } 
    455  
     450        swish_hash_add(metas1, meta1->name, meta1); 
     451    } 
     452/*      
     453    SWISH_DEBUG_MSG("%s meta1->id = %d    %s meta2->id = %d", 
     454                    meta1->name, meta1->id, meta2->name, meta2->id); 
     455 */ 
     456    // only change id if meta2->id is not already spoken for. 
    456457    meta1->id = meta2->id; 
    457     if (in_hash && meta1->name != NULL) { 
    458         swish_xfree(meta1->name); 
    459         meta1->name = swish_xstrdup(meta2->name); 
    460     } 
    461458    meta1->bias = meta2->bias; 
    462459    if (meta1->alias_for != NULL) { 
     
    467464    } 
    468465 
    469     if (!in_hash) { 
    470         swish_hash_add(metas1, meta1->name, meta1); 
    471     } 
    472466} 
    473467 
     
    478472) 
    479473{ 
    480     xmlHashScan(metas2, (xmlHashScanner) copy_metaname, metas1); 
     474    xmlHashScan(metas2, (xmlHashScanner)copy_metaname, metas1); 
    481475} 
    482476 
  • libswish3/trunk/src/libswish3/header.c

    r2108 r2110  
    108108    xmlChar *name 
    109109); 
    110 static void test_meta_unique_ids( 
    111     swish_MetaName *meta, 
    112     swish_Config *c, 
    113     xmlChar *name 
    114 ); 
    115 static void test_prop_unique_ids( 
    116     swish_Property *prop, 
    117     swish_Config *c, 
    118     xmlChar *name 
    119 ); 
    120110static headmaker *init_headmaker( 
    121111); 
     
    212202                newmeta = swish_hash_fetch(h->config->metanames, newname); 
    213203            } 
     204/* else new metaname */ 
    214205            else { 
    215206                newmeta = swish_init_metaname(newname); 
     
    243234) 
    244235{ 
     236    swish_MetaName *dupe; 
    245237    if (xmlStrEqual(attr, (xmlChar *)"bias")) { 
    246         meta->bias = (boolean) strtol((char *)attr_val, (char **)NULL, 10); 
     238        meta->bias = swish_string_to_int((char*)attr_val); 
    247239    } 
    248240    else if (xmlStrEqual(attr, (xmlChar *)"id")) { 
    249         meta->id = (int)strtol((char *)attr_val, (char **)NULL, 10); 
     241        // make sure id is not already assigned 
     242        if (swish_hash_exists(h->config->flags->meta_ids, (xmlChar*)attr_val)) { 
     243            dupe = swish_hash_fetch(h->config->flags->meta_ids, (xmlChar*)attr_val); 
     244            SWISH_CROAK("duplicate id %s on MetaName %s (already assigned to %s)", 
     245                attr_val, meta->name, dupe->name); 
     246        } 
     247        meta->id = swish_string_to_int((char*)attr_val); 
     248        // cache for id lookup 
     249        swish_hash_add(h->config->flags->meta_ids, (xmlChar*)attr_val, meta); 
    250250    } 
    251251    else if (xmlStrEqual(attr, (xmlChar *)"alias_for")) { 
     
    292292 
    293293/*  must have an id */ 
    294     if (!meta->id) { 
     294    if (meta->id == -1) { 
    295295        meta->id = h->meta_id++; 
    296296    } 
     
    364364) 
    365365{ 
    366  
     366    swish_Property *dupe; 
     367     
    367368    if (xmlStrEqual(attr, (xmlChar *)"ignore_case")) { 
    368         prop->ignore_case = (boolean) strtol((char *)attr_val, (char **)NULL, 10); 
     369        prop->ignore_case = (boolean)strtol((char *)attr_val, (char **)NULL, 10); 
    369370    } 
    370371    else if (xmlStrEqual(attr, (xmlChar *)"max")) { 
     
    372373    } 
    373374    else if (xmlStrEqual(attr, (xmlChar *)"verbatim")) { 
    374         prop->verbatim = (boolean) strtol((char *)attr_val, (char **)NULL, 10); 
     375        prop->verbatim = (boolean)strtol((char *)attr_val, (char **)NULL, 10); 
    375376    } 
    376377    else if (xmlStrEqual(attr, (xmlChar *)"sort")) { 
    377         prop->sort = (boolean) strtol((char *)attr_val, (char **)NULL, 10); 
     378        prop->sort = (boolean)strtol((char *)attr_val, (char **)NULL, 10); 
    378379    } 
    379380    else if (xmlStrEqual(attr, (xmlChar *)"id")) { 
    380         prop->id = (boolean) strtol((char *)attr_val, (char **)NULL, 10); 
     381        // make sure id is not already assigned 
     382        if (swish_hash_exists(h->config->flags->prop_ids, (xmlChar*)attr_val)) { 
     383            dupe = swish_hash_fetch(h->config->flags->prop_ids, (xmlChar*)attr_val); 
     384            SWISH_CROAK("duplicate id %s on MetaName %s (already assigned to %s)", 
     385                attr_val, prop->name, dupe->name); 
     386        } 
     387        prop->id = swish_string_to_int((char*)attr_val); 
     388        // cache for id lookup 
     389        swish_hash_add(h->config->flags->prop_ids, (xmlChar*)attr_val, prop); 
    381390    } 
    382391    else if (xmlStrEqual(attr, (xmlChar *)"type")) { 
     
    434443    } 
    435444 
    436     if (!prop->id) { 
     445    if (prop->id == -1) { 
    437446        prop->id = h->prop_id++; 
    438447    } 
     
    754763} 
    755764 
    756 static void 
    757 test_meta_unique_ids( 
    758     swish_MetaName *meta, 
    759     swish_Config *c, 
    760     xmlChar *name 
    761 ) 
    762 { 
    763     c->flags->meta_ids[meta->id]++; 
    764 } 
    765  
    766 static void 
    767 test_prop_unique_ids( 
    768     swish_Property *prop, 
    769     swish_Config *c, 
    770     xmlChar *name 
    771 ) 
    772 { 
    773     c->flags->prop_ids[prop->id]++; 
    774 } 
    775  
    776 void 
    777 swish_config_test_unique_ids( 
    778     swish_Config *c 
    779 ) 
    780 { 
    781     int i; 
    782     xmlHashScan(c->metanames, (xmlHashScanner)test_meta_unique_ids, c); 
    783     xmlHashScan(c->properties, (xmlHashScanner)test_prop_unique_ids, c); 
    784     for (i = 0; i < SWISH_MAX_IDS; i++) { 
    785         if (c->flags->meta_ids[i] > 1) { 
    786             SWISH_WARN("meta id %d == %d", i, c->flags->meta_ids[i]); 
    787         } 
    788         if (c->flags->prop_ids[i] > 1) { 
    789             SWISH_WARN("prop id %d == %d", i, c->flags->prop_ids[i]); 
    790         } 
    791  
    792         /* 
    793            set back to 0 in case we are called again  
    794          */ 
    795         c->flags->prop_ids[i] = 0; 
    796         c->flags->meta_ids[i] = 0; 
    797     } 
    798 } 
    799765 
    800766static headmaker * 
     
    831797    swish_config_test_alias_fors(h->config); 
    832798 
    833 /*  make sure ids are all unique */ 
    834     swish_config_test_unique_ids(h->config); 
    835  
    836799    swish_debug_config(h->config); 
    837800    swish_free_config(h->config); 
     
    861824/*  test that all the alias_for links resolve ok */ 
    862825    swish_config_test_alias_fors(c); 
    863  
    864 /*  make sure ids are all unique */ 
    865     swish_config_test_unique_ids(c); 
    866826 
    867827    return 1; 
     
    930890{ 
    931891    int rc; 
    932     boolean is_alias; 
    933892    write_open_tag(writer, name); 
    934     is_alias = 0; 
    935     rc = 0; 
     893    rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "id", "%d", meta->id); 
     894    if (rc < 0) { 
     895        SWISH_CROAK("Error writing metaname id attribute for %s", name); 
     896    } 
     897 
    936898    if (meta->alias_for != NULL) { 
    937899        rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "alias_for", meta->alias_for); 
    938         is_alias = 1; 
    939     } 
    940     if (rc < 0) { 
    941         SWISH_CROAK("Error writing metaname alias_for attribute for %s", name); 
    942     } 
    943  
    944     if (!is_alias) { 
     900        if (rc < 0) { 
     901            SWISH_CROAK("Error writing metaname alias_for attribute for %s", name); 
     902        } 
     903 
     904    } 
     905    else { 
    945906        rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "bias", "%d", meta->bias); 
    946907        if (rc < 0) { 
    947908            SWISH_CROAK("Error writing metaname bias attribute for %s", name); 
    948909        } 
    949  
    950     } 
    951  
    952     rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "id", "%d", meta->id); 
    953     if (rc < 0) { 
    954         SWISH_CROAK("Error writing metaname id attribute for %s", name); 
    955     } 
     910    } 
     911 
    956912    write_close_tag(writer); 
    957913} 
     
    984940{ 
    985941    int rc; 
    986     boolean is_alias; 
    987942    write_open_tag(writer, name); 
    988     rc = 0; 
    989     is_alias = 0; 
    990     if (prop->alias_for != NULL) { 
    991         rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "alias_for", prop->alias_for); 
    992         is_alias = 1; 
    993     } 
    994     if (rc < 0) { 
    995         SWISH_CROAK("Error writing property alias_for attribute for %s", name); 
    996     } 
    997943    rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "id", "%d", prop->id); 
    998944    if (rc < 0) { 
     
    1000946    } 
    1001947 
     948    if (prop->alias_for != NULL) { 
     949        rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "alias_for", prop->alias_for); 
     950        if (rc < 0) { 
     951            SWISH_CROAK("Error writing property alias_for attribute for %s", name); 
     952        } 
     953    } 
     954    else { 
     955 
    1002956/* all other attrs are irrelevant if this is an alias */ 
    1003     if (!is_alias) { 
    1004957        rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "ignore_case", "%d", 
    1005958                                               prop->ignore_case); 
     
    10871040    things->thing3 = writer; 
    10881041    xmlHashScan(mimes, (xmlHashScanner)write_mime, things); 
    1089     swish_hash_free( things->thing1 ); 
     1042    swish_hash_free(things->thing1); 
    10901043    swish_xfree(things); 
    10911044} 
  • libswish3/trunk/src/libswish3/libswish3.h

    r2108 r2110  
    4141 
    4242#define SWISH_CONTRACTIONS          1 
    43  
    44 #define SWISH_MAX_IDS               1024 
    4543#define SWISH_SPECIAL_ARG           1 
    4644#define SWISH_MAX_SORT_STRING_LEN   100 
     
    246244{ 
    247245    boolean         tokenize; 
    248     boolean         meta_ids[SWISH_MAX_IDS]; 
    249     boolean         prop_ids[SWISH_MAX_IDS]; 
    250      
     246    xmlHashTablePtr meta_ids; 
     247    xmlHashTablePtr prop_ids; 
    251248}; 
    252249 
     
    275272{ 
    276273    int                 ref_cnt; 
    277     unsigned int        id; 
     274    int                 id; 
    278275    xmlChar            *name; 
    279276    int                 bias; 
     
    284281{ 
    285282    int                 ref_cnt; 
    286     unsigned int        id; 
     283    int                 id; 
    287284    xmlChar            *name; 
    288285    boolean             ignore_case; 
     
    475472swish_StringList *  swish_init_stringlist(); 
    476473void                swish_free_stringlist(swish_StringList * sl); 
     474int                 swish_string_to_int( char *buf ); 
     475xmlChar *           swish_int_to_string( int val ); 
     476xmlChar *           swish_long_to_string( long val ); 
     477xmlChar *           swish_double_to_string( double val ); 
     478xmlChar *           swish_date_to_string( int y, int m, int d ); 
    477479/* 
    478480=cut 
     
    493495xmlChar *       swish_get_mime_type( swish_Config * config, xmlChar * fileext ); 
    494496xmlChar *       swish_get_parser( swish_Config * config, xmlChar *mime ); 
    495 void            swish_config_test_unique_ids( swish_Config *c ); 
    496497void            swish_config_test_alias_fors( swish_Config *c ); 
    497498swish_ConfigFlags * swish_init_config_flags(); 
    498  
     499void            swish_free_config_flags( swish_ConfigFlags *flags ); 
    499500/* 
    500501=cut 
  • libswish3/trunk/src/libswish3/metaname.c

    r2103 r2110  
    3030    m = swish_xmalloc(sizeof(swish_MetaName)); 
    3131    m->ref_cnt = 0; 
    32     m->id = 0
     32    m->id = -1
    3333    m->name = name; 
    3434    m->bias = 0; 
  • libswish3/trunk/src/libswish3/property.c

    r2103 r2110  
    3030    p = swish_xmalloc(sizeof(swish_Property)); 
    3131    p->ref_cnt = 0; 
    32     p->id = 0
     32    p->id = -1
    3333    p->name = name; 
    3434    p->ignore_case = 1; 
  • libswish3/trunk/src/libswish3/string.c

    r2103 r2110  
    5454); 
    5555 
     56/* these string conversion functions based on code from xapian-omega */ 
     57#define BUFSIZE 100 
     58 
     59#ifdef SNPRINTF 
     60#define CONVERT_TO_STRING(FMT) \ 
     61    char buf[BUFSIZE+1];\ 
     62    int len = SNPRINTF(buf, BUFSIZE, (FMT), val);\ 
     63    if (len == -1 || len > BUFSIZE) buf[BUFSIZE+1] = '\0';\ 
     64    else buf[len+1] = '\0';\ 
     65    return swish_xstrdup((xmlChar*)buf); 
     66#else 
     67#define CONVERT_TO_STRING(FMT) \ 
     68    char buf[BUFSIZE+1];\ 
     69    buf[BUFSIZE+1] = '\0';\ 
     70    sprintf(buf, (FMT), val);\ 
     71    if (buf[BUFSIZE]) abort();\ 
     72    return swish_xstrdup((xmlChar*)buf); 
     73#endif 
     74 
     75int swish_string_to_int( 
     76    char *buf 
     77)  
     78{ 
     79    return (int)strtol(buf, (char **)NULL, 10); 
     80} 
     81 
     82xmlChar * 
     83swish_int_to_string( 
     84    int val 
     85) 
     86{ 
     87    CONVERT_TO_STRING("%d") 
     88} 
     89 
     90xmlChar * 
     91swish_long_to_string( 
     92    long val 
     93) 
     94{ 
     95    CONVERT_TO_STRING("%ld") 
     96} 
     97 
     98xmlChar * 
     99swish_double_to_string( 
     100    double val 
     101) 
     102{ 
     103    CONVERT_TO_STRING("%f") 
     104} 
     105 
     106xmlChar * 
     107swish_date_to_string( 
     108    int y, 
     109    int m, 
     110    int d 
     111) 
     112{ 
     113    char buf[11]; 
     114    if (y < 0) 
     115        y = 0; 
     116    else if (y > 9999) 
     117        y = 9999; 
     118    if (m < 1) 
     119        m = 1; 
     120    else if (m > 12) 
     121        m = 12; 
     122    if (d < 1) 
     123        d = 1; 
     124    else if (d > 31) 
     125        d = 31; 
     126#ifdef SNPRINTF 
     127    int len = SNPRINTF(buf, sizeof(buf), "%04d%02d%02d", y, m, d); 
     128    if (len == -1 || len > BUFSIZE) 
     129        buf[BUFSIZE + 1] = '\0'; 
     130#else 
     131    buf[BUFSIZE + 1] = '\0'; 
     132    sprintf(buf, "%04d%02d%02d", y, m, d); 
     133    if (buf[BUFSIZE + 1]) 
     134        abort();                /* Uh-oh, buffer overrun */ 
     135#endif 
     136    return swish_xstrdup((xmlChar*)buf); 
     137} 
     138 
     139/* TODO need these ?? 
     140inline uint32_t 
     141binary_string_to_int( 
     142    const std::string & s 
     143) 
     144{ 
     145    if (s.size() != 4) 
     146        return (uint32_t) - 1; 
     147    uint32_t 
     148        v; 
     149    memcpy(&v, s.data(), 4); 
     150    return ntohl(v); 
     151} 
     152 
     153inline 
     154    std::string 
     155int_to_binary_string( 
     156    uint32_t v 
     157) 
     158{ 
     159    v = htonl(v); 
     160    return std::string(reinterpret_cast < const char *>(&v), 4); 
     161} 
     162 
     163*/ 
     164 
    56165/* returns length of a UTF8 character, based on first byte (see below) */ 
    57166int 
     
    121230    else { 
    122231        if (SWISH_DEBUG) 
    123             SWISH_DEBUG_MSG("no encoding in %s, using %s", loc, 
    124                             SWISH_DEFAULT_ENCODING); 
     232            SWISH_DEBUG_MSG("no encoding in %s, using %s", loc, SWISH_DEFAULT_ENCODING); 
    125233 
    126234        enc = (xmlChar *)SWISH_DEFAULT_ENCODING; 
     
    141249        if (SWISH_DEBUG) 
    142250            SWISH_DEBUG_MSG 
    143                 ("Your locale (%s) was not UTF-8 so internally we are using %s", 
    144                  loc, SWISH_LOCALE); 
     251                ("Your locale (%s) was not UTF-8 so internally we are using %s", loc, 
     252                 SWISH_LOCALE); 
    145253 
    146254        setlocale(LC_CTYPE, SWISH_LOCALE); 
     
    321429    int i; 
    322430    for (i = 0; widechars[i] != 0; i++) { 
    323         printf(" >%lc< %ld %#lx \n", (wint_t) widechars[i], 
    324                (long int)widechars[i], (long unsigned int)widechars[i]); 
     431        printf(" >%lc< %ld %#lx \n", (wint_t) widechars[i], (long int)widechars[i], 
     432               (long unsigned int)widechars[i]); 
    325433    } 
    326434} 
     
    451559        if (cursize == maxsize) { 
    452560            sl->word = 
    453                 (xmlChar **)swish_xrealloc(sl->word, 
    454                                            (maxsize *= 2) * sizeof(xmlChar *)); 
     561                (xmlChar **)swish_xrealloc(sl->word, (maxsize *= 2) * sizeof(xmlChar *)); 
    455562        } 
    456563 
     
    462569    if (cursize == maxsize) { 
    463570        sl->word = 
    464             (xmlChar **)swish_xrealloc(sl->word, 
    465                                        (maxsize += 1) * sizeof(xmlChar *)); 
     571            (xmlChar **)swish_xrealloc(sl->word, (maxsize += 1) * sizeof(xmlChar *)); 
    466572    } 
    467573