Changeset 2101

Show
Ignore:
Timestamp:
03/26/08 23:47:21 (2 months ago)
Author:
karpet
Message:

whitespace only

Files:

Legend:

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

    r2096 r2101  
    1616 *  along with libswish3; if not, write to the Free Software 
    1717 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
    18  */ 
    19   
     18*/ 
     19 
    2020/* text analyzer 
    2121   tokenize strings, stemming 
    22     
     22 
    2323*/ 
    2424 
     
    2828 
    2929swish_Analyzer * 
    30 swish_init_analyzer( swish_Config * config
     30swish_init_analyzer(swish_Config *config
    3131{ 
    3232    swish_Analyzer *a; 
    3333    a = swish_xmalloc(sizeof(swish_Analyzer)); 
    34      
    35     /* TODO get these all from config */ 
     34 
     35/* TODO get these all from config */ 
    3636    a->maxwordlen = SWISH_MAX_WORD_LEN; 
    3737    a->minwordlen = SWISH_MIN_WORD_LEN; 
    38     a->lc         = 1; 
    39     a->ref_cnt    = 0; 
    40     a->tokenize   = config->flags->tokenize; 
    41          
     38    a->lc = 1; 
     39    a->ref_cnt = 0; 
     40    a->tokenize = config->flags->tokenize; 
     41 
    4242    if (!a->tokenize && SWISH_DEBUG) 
    4343        SWISH_DEBUG_MSG("skipping WordList"); 
    4444 
    45     /* tokenizer set in the parse* function */ 
     45/* tokenizer set in the parse* function */ 
    4646    a->tokenizer = NULL; 
    47      
    48     /* TODO get stemmer via config */ 
    49     a->stemmer   = NULL; 
    50      
    51     /* TODO standalone regex lib */ 
    52     a->regex     = NULL; 
    53      
    54     a->stash     = NULL; 
    55      
     47 
     48/* TODO get stemmer via config */ 
     49    a->stemmer = NULL; 
     50 
     51/* TODO standalone regex lib */ 
     52    a->regex = NULL; 
     53 
     54    a->stash = NULL; 
     55 
    5656    return a; 
    5757} 
     
    6161   do that prior to calling this function. 
    6262   stemmer, for example, or regex 
    63  */ 
    64   
    65 void  
    66 swish_free_analyzer( swish_Analyzer * a
     63*/ 
     64 
     65void 
     66swish_free_analyzer(swish_Analyzer *a
    6767{ 
    6868    if (a->ref_cnt != 0) { 
     
    7272        SWISH_DEBUG_MSG("free analyzer"); 
    7373    } 
    74     swish_xfree(a);    
     74    swish_xfree(a); 
    7575} 
    76  
  • libswish3/trunk/src/libswish3/config.c

    r2100 r2101  
    1616 *  along with libswish3; if not, write to the Free Software 
    1717 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
    18  */ 
     18*/ 
    1919 
    2020/* parse XML-style config files 
    21  *  
     21 * 
    2222 * based on http://www.yolinux.com/TUTORIALS/GnomeLibXml2.html 
    23  *  
    24  */ 
     23 * 
     24*/ 
    2525 
    2626#include <sys/param.h> 
     
    3737 
    3838void 
    39 swish_free_config(swish_Config * config); 
    40 swish_Config 
    41 swish_init_config(); 
    42 void 
    43 swish_config_set_default( swish_Config *config ); 
    44 swish_Config
    45 swish_add_config(xmlChar *conf, swish_Config *config); 
    46 swish_Config 
    47 swish_parse_config(xmlChar *conf, swish_Config *config); 
    48 void 
    49 swish_debug_config(swish_Config * config); 
    50 void 
    51 swish_config_merge(swish_Config *config1, swish_Config *config2); 
    52 static void 
    53 free_string(xmlChar *payload, xmlChar * key); 
    54 static void 
    55 free_props(swish_Property *prop, xmlChar *propname); 
    56 static void 
    57 free_metas(swish_MetaName *meta, xmlChar *metaname); 
    58 static void 
    59 config_printer(xmlChar *val, xmlChar *str, xmlChar *key); 
    60 static void 
    61 property_printer(swish_Property *prop, xmlChar *str, xmlChar *propname); 
    62 static void 
    63 metaname_printer(swish_MetaName *meta, xmlChar *str, xmlChar *metaname); 
     39                swish_free_config(swish_Config *config); 
     40swish_Config 
     41                swish_init_config(); 
     42void 
     43                swish_config_set_default(swish_Config *config); 
     44swish_Config  
     45                swish_add_config(xmlChar *conf, swish_Config *config); 
     46swish_Config 
     47                swish_parse_config(xmlChar *conf, swish_Config *config); 
     48void 
     49                swish_debug_config(swish_Config *config); 
     50void 
     51                swish_config_merge(swish_Config *config1, swish_Config *config2); 
     52static void 
     53                free_string(xmlChar *payload, xmlChar *key); 
     54static void 
     55                free_props(swish_Property * prop, xmlChar *propname); 
     56static void 
     57                free_metas(swish_MetaName * meta, xmlChar *metaname); 
     58static void 
     59                config_printer(xmlChar *val, xmlChar *str, xmlChar *key); 
     60static void 
     61                property_printer(swish_Property * prop, xmlChar *str, xmlChar *propname); 
     62static void 
     63                metaname_printer(swish_MetaName * meta, xmlChar *str, xmlChar *metaname); 
    6464static void 
    6565copy_property( 
    66     swish_Property *prop2, 
    67     xmlHashTablePtr props1, 
    68     xmlChar *prop2name 
     66          swish_Property * prop2, 
     67          xmlHashTablePtr props1, 
     68          xmlChar *prop2name 
    6969); 
    7070static void 
    71 merge_properties(xmlHashTablePtr props1, xmlHashTablePtr props2); 
     71                merge_properties(xmlHashTablePtr props1, xmlHashTablePtr props2); 
    7272static void 
    7373copy_metaname( 
    74     swish_MetaName *meta2, 
    75     xmlHashTablePtr metas1, 
    76     xmlChar *meta2name  
     74          swish_MetaName * meta2, 
     75          xmlHashTablePtr metas1, 
     76          xmlChar *meta2name 
    7777); 
    7878static void 
    79 merge_metanames(xmlHashTablePtr metas1, xmlHashTablePtr metas2); 
    80  
    81 static void 
    82 free_string(xmlChar *payload, xmlChar * key) 
     79                merge_metanames(xmlHashTablePtr metas1, xmlHashTablePtr metas2); 
     80 
     81static void 
     82free_string(xmlChar *payload, xmlChar *key) 
    8383{ 
    8484    if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) 
     
    8989 
    9090static void 
    91 free_props(swish_Property *prop, xmlChar *propname) 
     91free_props(swish_Property * prop, xmlChar *propname) 
    9292{ 
    9393    if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { 
    9494        SWISH_DEBUG_MSG("   freeing config->prop %s", propname); 
    95         swish_debug_property((swish_Property*)prop); 
     95        swish_debug_property((swish_Property *) prop); 
    9696    } 
    9797    prop->ref_cnt--; 
     
    102102 
    103103static void 
    104 free_metas(swish_MetaName *meta, xmlChar *metaname) 
     104free_metas(swish_MetaName * meta, xmlChar *metaname) 
    105105{ 
    106106    if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { 
    107107        SWISH_DEBUG_MSG("   freeing config->meta %s", metaname); 
    108         swish_debug_metaname((swish_MetaName*)meta); 
     108        swish_debug_metaname((swish_MetaName *) meta); 
    109109    } 
    110110    meta->ref_cnt--; 
     
    115115 
    116116void 
    117 swish_free_config(swish_Config * config) 
    118 
    119     if (SWISH_DEBUG & SWISH_DEBUG_MEMORY) 
    120     { 
     117swish_free_config(swish_Config *config) 
     118
     119    if (SWISH_DEBUG & SWISH_DEBUG_MEMORY) { 
    121120        SWISH_DEBUG_MSG("freeing config"); 
    122121        SWISH_DEBUG_MSG("ptr addr: 0x%x  %d", (int) config, (int) config); 
    123122    } 
    124123 
    125     xmlHashFree(config->misc,           (xmlHashDeallocator)free_string); 
    126     xmlHashFree(config->properties,     (xmlHashDeallocator)free_props); 
    127     xmlHashFree(config->metanames,      (xmlHashDeallocator)free_metas); 
    128     xmlHashFree(config->tag_aliases,    (xmlHashDeallocator)free_string); 
    129     xmlHashFree(config->parsers,        (xmlHashDeallocator)free_string); 
    130     xmlHashFree(config->mimes,          (xmlHashDeallocator)free_string); 
    131     xmlHashFree(config->index,          (xmlHashDeallocator)free_string); 
     124    xmlHashFree(config->misc, (xmlHashDeallocator) free_string); 
     125    xmlHashFree(config->properties, (xmlHashDeallocator) free_props); 
     126    xmlHashFree(config->metanames, (xmlHashDeallocator) free_metas); 
     127    xmlHashFree(config->tag_aliases, (xmlHashDeallocator) free_string); 
     128    xmlHashFree(config->parsers, (xmlHashDeallocator) free_string); 
     129    xmlHashFree(config->mimes, (xmlHashDeallocator) free_string); 
     130    xmlHashFree(config->index, (xmlHashDeallocator) free_string); 
    132131    swish_xfree(config->flags); 
    133132 
     
    147146/* init config object */ 
    148147 
    149 swish_Config 
     148swish_Config 
    150149swish_init_config() 
    151150{ 
    152     swish_Config  *config; 
    153      
     151    swish_Config  *config; 
     152 
    154153    if (SWISH_DEBUG & SWISH_DEBUG_MEMORY) { 
    155154        SWISH_DEBUG_MSG("init config"); 
    156155    } 
    157      
    158     /* the hashes will automatically grow as needed so we init with sane starting size */ 
    159     config              = swish_xmalloc(sizeof(swish_Config)); 
    160     config->flags       = swish_xmalloc(sizeof(swish_ConfigFlags)); 
    161     config->misc        = swish_init_hash(8); 
    162     config->metanames   = swish_init_hash(8); 
    163     config->properties = swish_init_hash(8); 
    164     config->parsers     = swish_init_hash(8); 
    165     config->index       = swish_init_hash(8); 
     156 
     157/* the hashes will automatically grow as needed so we init with sane starting size */ 
     158    config = swish_xmalloc(sizeof(swish_Config)); 
     159    config->flags = swish_xmalloc(sizeof(swish_ConfigFlags)); 
     160    config->misc = swish_init_hash(8); 
     161    config->metanames = swish_init_hash(8); 
     162    config->properties = swish_init_hash(8); 
     163    config->parsers = swish_init_hash(8); 
     164    config->index = swish_init_hash(8); 
    166165    config->tag_aliases = swish_init_hash(8); 
    167     config->mimes       = NULL; 
    168     config->ref_cnt     = 0; 
    169     config->stash       = NULL; 
    170      
    171     /* misc default flags */ 
     166    config->mimes = NULL; 
     167    config->ref_cnt = 0; 
     168    config->stash = NULL; 
     169 
     170/* misc default flags */ 
    172171    config->flags->tokenize = 1; 
    173      
     172 
    174173    return config; 
    175174 
     
    177176 
    178177void 
    179 swish_config_set_default( swish_Config *config
     178swish_config_set_default(swish_Config *config
    180179{ 
    181180    swish_Property *tmpprop; 
     
    184183    if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) 
    185184        SWISH_DEBUG_MSG("setting default config"); 
    186          
    187     /* we xstrdup a lot in order to consistently free in swish_free_config() */ 
    188  
    189     /* MIME types */ 
     185 
     186/* we xstrdup a lot in order to consistently free in swish_free_config() */ 
     187 
     188/* MIME types */ 
    190189    config->mimes = swish_mime_hash(); 
    191190 
    192     /* metanames */ 
    193     swish_hash_add( 
    194             config->metanames,  
    195             (xmlChar*)SWISH_DEFAULT_METANAME, 
    196             swish_init_metaname( swish_xstrdup((xmlChar*)SWISH_DEFAULT_METANAME) )  
    197             ); 
    198     swish_hash_add( 
    199             config->metanames, 
    200             (xmlChar*)SWISH_TITLE_METANAME, 
    201             swish_init_metaname( swish_xstrdup((xmlChar*)SWISH_TITLE_METANAME)
    202             ); 
    203              
    204     /* alter swish_MetaName objects after they've been stashed.  
    205        a little awkward, but saves var names.  
    206     */ 
    207     tmpmeta = swish_hash_fetch(config->metanames, (xmlChar*)SWISH_DEFAULT_METANAME); 
     191/* metanames */ 
     192    swish_hash_add( 
     193               config->metanames, 
     194               (xmlChar *) SWISH_DEFAULT_METANAME, 
     195               swish_init_metaname(swish_xstrdup((xmlChar *) SWISH_DEFAULT_METANAME)) 
     196        ); 
     197    swish_hash_add( 
     198               config->metanames, 
     199               (xmlChar *) SWISH_TITLE_METANAME, 
     200               swish_init_metaname(swish_xstrdup((xmlChar *) SWISH_TITLE_METANAME)
     201        ); 
     202 
     203/* alter swish_MetaName objects after they've been stashed. 
     204       a little awkward, but saves var names. 
     205*/ 
     206    tmpmeta = swish_hash_fetch(config->metanames, (xmlChar *) SWISH_DEFAULT_METANAME); 
    208207    tmpmeta->ref_cnt++; 
    209208    tmpmeta->id = SWISH_META_DEFAULT_ID; 
    210     tmpmeta = swish_hash_fetch(config->metanames, (xmlChar*)SWISH_TITLE_METANAME); 
     209    tmpmeta = swish_hash_fetch(config->metanames, (xmlChar *) SWISH_TITLE_METANAME); 
    211210    tmpmeta->ref_cnt++; 
    212211    tmpmeta->id = SWISH_META_TITLE_ID; 
    213      
    214  
    215     /* parsers */ 
    216     swish_hash_add( 
    217             config->parsers, 
    218             (xmlChar *) "text/plain", 
    219             swish_xstrdup((xmlChar *) SWISH_PARSER_TXT)); 
    220     swish_hash_add( 
    221             config->parsers, 
    222             (xmlChar *) "text/xml", 
    223             swish_xstrdup((xmlChar *) SWISH_PARSER_XML)); 
    224     swish_hash_add( 
    225             config->parsers, 
    226             (xmlChar *) "text/html", 
    227             swish_xstrdup((xmlChar *) SWISH_PARSER_HTML)); 
    228     swish_hash_add( 
    229             config->parsers, 
    230             (xmlChar *) SWISH_DEFAULT_PARSER, 
    231             swish_xstrdup((xmlChar *) SWISH_DEFAULT_PARSER_TYPE)); 
    232  
    233  
    234     /* index */ 
    235     swish_hash_add( 
    236             config->index, 
    237             (xmlChar *) SWISH_INDEX_FORMAT, 
    238             swish_xstrdup((xmlChar *) SWISH_INDEX_FILEFORMAT)); 
    239     swish_hash_add( 
    240             config->index, 
    241             (xmlChar *) SWISH_INDEX_NAME, 
    242             swish_xstrdup((xmlChar *) SWISH_INDEX_FILENAME)); 
    243     swish_hash_add( 
    244             config->index, 
    245             (xmlChar *) SWISH_INDEX_LOCALE, 
    246             swish_xstrdup((xmlChar *) setlocale(LC_ALL, ""))); 
    247  
    248  
    249     /* properties */ 
    250     swish_hash_add( 
    251             config->properties, 
    252             (xmlChar*)SWISH_PROP_DESCRIPTION, 
    253             swish_init_property(swish_xstrdup((xmlChar*)SWISH_PROP_DESCRIPTION)) 
    254             ); 
    255     swish_hash_add( 
    256             config->properties, 
    257             (xmlChar*)SWISH_PROP_TITLE, 
    258             swish_init_property(swish_xstrdup((xmlChar*)SWISH_PROP_TITLE)) 
    259             ); 
    260  
    261     /* same deal as metanames above */ 
    262     tmpprop = swish_hash_fetch(config->properties, (xmlChar*)SWISH_PROP_DESCRIPTION); 
     212 
     213 
     214/* parsers */ 
     215    swish_hash_add( 
     216               config->parsers, 
     217               (xmlChar *) "text/plain", 
     218               swish_xstrdup((xmlChar *) SWISH_PARSER_TXT)); 
     219    swish_hash_add( 
     220               config->parsers, 
     221               (xmlChar *) "text/xml", 
     222               swish_xstrdup((xmlChar *) SWISH_PARSER_XML)); 
     223    swish_hash_add( 
     224               config->parsers, 
     225               (xmlChar *) "text/html", 
     226               swish_xstrdup((xmlChar *) SWISH_PARSER_HTML)); 
     227    swish_hash_add( 
     228               config->parsers, 
     229               (xmlChar *) SWISH_DEFAULT_PARSER, 
     230               swish_xstrdup((xmlChar *) SWISH_DEFAULT_PARSER_TYPE)); 
     231 
     232 
     233/* index */ 
     234    swish_hash_add( 
     235               config->index, 
     236               (xmlChar *) SWISH_INDEX_FORMAT, 
     237               swish_xstrdup((xmlChar *) SWISH_INDEX_FILEFORMAT)); 
     238    swish_hash_add( 
     239               config->index, 
     240               (xmlChar *) SWISH_INDEX_NAME, 
     241               swish_xstrdup((xmlChar *) SWISH_INDEX_FILENAME)); 
     242    swish_hash_add( 
     243               config->index, 
     244               (xmlChar *) SWISH_INDEX_LOCALE, 
     245               swish_xstrdup((xmlChar *) setlocale(LC_ALL, ""))); 
     246 
     247 
     248/* properties */ 
     249    swish_hash_add( 
     250               config->properties, 
     251               (xmlChar *) SWISH_PROP_DESCRIPTION, 
     252               swish_init_property(swish_xstrdup((xmlChar *) SWISH_PROP_DESCRIPTION)) 
     253        ); 
     254    swish_hash_add( 
     255               config->properties, 
     256               (xmlChar *) SWISH_PROP_TITLE, 
     257               swish_init_property(swish_xstrdup((xmlChar *) SWISH_PROP_TITLE)) 
     258        ); 
     259 
     260/* same deal as metanames above */ 
     261    tmpprop = swish_hash_fetch(config->properties, (xmlChar *) SWISH_PROP_DESCRIPTION); 
    263262    tmpprop->ref_cnt++; 
    264263    tmpprop->id = SWISH_PROP_DESCRIPTION_ID; 
    265     tmpprop = swish_hash_fetch(config->properties, (xmlChar*)SWISH_PROP_TITLE); 
     264    tmpprop = swish_hash_fetch(config->properties, (xmlChar *) SWISH_PROP_TITLE); 
    266265    tmpprop->ref_cnt++; 
    267266    tmpprop->id = SWISH_PROP_TITLE_ID; 
    268      
    269  
    270     /* aliases: other names a tag might be known as, for matching properties and 
     267 
     268 
     269/* aliases: other names a tag might be known as, for matching properties and 
    271270     * metanames */ 
    272271    swish_hash_add( 
    273             config->tag_aliases, 
    274             (xmlChar *) SWISH_TITLE_TAG, 
    275             swish_xstrdup((xmlChar *) SWISH_TITLE_METANAME)); 
    276     swish_hash_add( 
    277             config->tag_aliases, 
    278             (xmlChar *) SWISH_BODY_TAG, 
    279             swish_xstrdup((xmlChar *) SWISH_PROP_DESCRIPTION)); 
    280  
    281      
     272               config->tag_aliases, 
     273               (xmlChar *) SWISH_TITLE_TAG, 
     274               swish_xstrdup((xmlChar *) SWISH_TITLE_METANAME)); 
     275    swish_hash_add( 
     276               config->tag_aliases, 
     277               (xmlChar *) SWISH_BODY_TAG, 
     278               swish_xstrdup((xmlChar *) SWISH_PROP_DESCRIPTION)); 
     279 
     280 
    282281    if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { 
    283282        SWISH_DEBUG_MSG("config_set_default done"); 
     
    287286} 
    288287 
    289 swish_Config
     288swish_Config  
    290289swish_add_config(xmlChar *conf, swish_Config *config) 
    291290{ 
     
    299298} 
    300299 
    301 swish_Config 
     300swish_Config 
    302301swish_parse_config(xmlChar *conf, swish_Config *config) 
    303302{ 
    304     swish_merge_config_with_header((char*)conf, config); 
     303    swish_merge_config_with_header((char *) conf, config); 
    305304    return config; 
    306305} 
     
    314313 
    315314static void 
    316 property_printer(swish_Property *prop, xmlChar *str, xmlChar *propname) 
     315property_printer(swish_Property * prop, xmlChar *str, xmlChar *propname) 
    317316{ 
    318317    SWISH_DEBUG_MSG(" %s:  %s =>", str, propname); 
     
    321320 
    322321static void 
    323 metaname_printer(swish_MetaName *meta, xmlChar *str, xmlChar *metaname) 
     322metaname_printer(swish_MetaName * meta, xmlChar *str, xmlChar *metaname) 
    324323{ 
    325324    SWISH_DEBUG_MSG(" %s:  %s =>", str, metaname); 
     
    329328/* PUBLIC */ 
    330329void 
    331 swish_debug_config(swish_Config * config) 
     330swish_debug_config(swish_Config *config) 
    332331{ 
    333332    SWISH_DEBUG_MSG("config->ref_cnt = %d", config->ref_cnt); 
     
    335334    SWISH_DEBUG_MSG("ptr addr: 0x%x  %d", (int) config, (int) config); 
    336335 
    337     xmlHashScan(config->misc,       (xmlHashScanner)config_printer,    "misc conf"); 
    338     xmlHashScan(config->properties, (xmlHashScanner)property_printer,  "properties"); 
    339     xmlHashScan(config->metanames, (xmlHashScanner)metaname_printer,  "metanames"); 
    340     xmlHashScan(config->parsers,    (xmlHashScanner)config_printer,    "parsers"); 
    341     xmlHashScan(config->mimes,      (xmlHashScanner)config_printer,    "mimes"); 
    342     xmlHashScan(config->index,      (xmlHashScanner)config_printer,    "index"); 
    343     xmlHashScan(config->tag_aliases,(xmlHashScanner)config_printer,    "tag_aliases"); 
     336    xmlHashScan(config->misc, (xmlHashScanner) config_printer, "misc conf"); 
     337    xmlHashScan(config->properties, (xmlHashScanner) property_printer, "properties"); 
     338    xmlHashScan(config->metanames, (xmlHashScanner) metaname_printer, "metanames"); 
     339    xmlHashScan(config->parsers, (xmlHashScanner) config_printer, "parsers"); 
     340    xmlHashScan(config->mimes, (xmlHashScanner) config_printer, "mimes"); 
     341    xmlHashScan(config->index, (xmlHashScanner) config_printer, "index"); 
     342    xmlHashScan(config->tag_aliases, (xmlHashScanner) config_printer, "tag_aliases"); 
    344343} 
    345344 
    346345static void 
    347346copy_property( 
    348     swish_Property *prop2, 
    349     xmlHashTablePtr props1, 
    350     xmlChar *prop2name 
     347          swish_Property * prop2, 
     348          xmlHashTablePtr props1, 
     349          xmlChar *prop2name 
    351350) 
    352351{ 
    353352    swish_Property *prop1; 
    354     boolean in_hash; 
    355          
     353    boolean         in_hash; 
     354 
    356355    if (swish_hash_exists(props1, prop2name)) { 
    357356        prop1 = swish_hash_fetch(props1, prop2name); 
     
    363362        in_hash = 0; 
    364363    } 
    365      
    366     prop1->id            = prop2->id; 
     364 
     365    prop1->id = prop2->id; 
    367366    if (in_hash && prop1->name != NULL) { 
    368         swish_xfree( prop1->name ); 
    369         prop1->name = swish_xstrdup( prop2->name ); 
    370     } 
    371     prop1->ignore_case   = prop2->ignore_case; 
    372     prop1->type          = prop2->type; 
    373     prop1->verbatim      = prop2->verbatim; 
     367        swish_xfree(prop1->name); 
     368        prop1->name = swish_xstrdup(prop2->name); 
     369    } 
     370    prop1->ignore_case = prop2->ignore_case; 
     371    prop1->type = prop2->type; 
     372    prop1->verbatim = prop2->verbatim; 
    374373    if (prop1->alias_for != NULL) { 
    375         swish_xfree( prop2->alias_for ); 
     374        swish_xfree(prop2->alias_for); 
    376375    } 
    377376    if (prop2->alias_for != NULL) { 
    378         prop1->alias_for     = swish_xstrdup( prop2->alias_for ); 
    379     } 
    380     prop1->max           = prop2->max; 
    381     prop1->sort          = prop2->sort; 
    382      
     377        prop1->alias_for = swish_xstrdup(prop2->alias_for); 
     378    } 
     379    prop1->max = prop2->max; 
     380    prop1->sort = prop2->sort; 
     381 
    383382    if (!in_hash) { 
    384383        swish_hash_add(props1, prop1->name, prop1); 
    385384    } 
    386      
     385 
    387386} 
    388387 
     
    390389merge_properties(xmlHashTablePtr props1, xmlHashTablePtr props2) 
    391390{ 
    392     xmlHashScan(props2, (xmlHashScanner)copy_property, props1); 
     391    xmlHashScan(props2, (xmlHashScanner) copy_property, props1); 
    393392} 
    394393 
    395394static void 
    396395copy_metaname( 
    397     swish_MetaName *meta2, 
    398     xmlHashTablePtr metas1, 
    399     xmlChar *meta2name  
     396          swish_MetaName * meta2, 
     397          xmlHashTablePtr metas1, 
     398          xmlChar *meta2name 
    400399) 
    401400{ 
    402401    swish_MetaName *meta1; 
    403     boolean in_hash; 
     402    boolean         in_hash; 
    404403    if (swish_hash_exists(metas1, meta2name)) { 
    405404        meta1 = swish_hash_fetch(metas1, meta2name); 
     
    412411    } 
    413412 
    414     meta1->id           = meta2->id; 
     413    meta1->id = meta2->id; 
    415414    if (in_hash && meta1->name != NULL) { 
    416415        swish_xfree(meta1->name); 
    417         meta1->name = swish_xstrdup( meta2->name ); 
    418     } 
    419     meta1->bias         = meta2->bias; 
     416        meta1->name = swish_xstrdup(meta2->name); 
     417    } 
     418    meta1->bias = meta2->bias; 
    420419    if (meta1->alias_for != NULL) { 
    421420        swish_xfree(meta1->alias_for); 
    422421    } 
    423422    if (meta2->alias_for != NULL) { 
    424         meta1->alias_for    = swish_xstrdup( meta2->alias_for ); 
    425     } 
    426      
     423        meta1->alias_for = swish_xstrdup(meta2->alias_for); 
     424    } 
     425 
    427426    if (!in_hash) { 
    428427        swish_hash_add(metas1, meta1->name, meta1); 
     
    433432merge_metanames(xmlHashTablePtr metas1, xmlHashTablePtr metas2) 
    434433{ 
    435     xmlHashScan(metas2, (xmlHashScanner)copy_metaname, metas1); 
     434    xmlHashScan(metas2, (xmlHashScanner) copy_metaname, metas1); 
    436435} 
    437436 
     
    440439{ 
    441440 
    442     /* values in config2 override and are set in config1 */ 
     441/* values in config2 override and are set in config1 */ 
    443442    if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { 
    444443        SWISH_DEBUG_MSG("merge properties"); 
    445444    } 
    446     merge_properties(config1->properties,   config2->properties); 
    447      
     445    merge_properties(config1->properties, config2->properties); 
     446 
    448447    if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { 
    449448        SWISH_DEBUG_MSG("merge metanames"); 
    450449    } 
    451     merge_metanames(config1->metanames,     config2->metanames); 
    452      
     450    merge_metanames(config1->metanames, config2->metanames); 
     451 
    453452    if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { 
    454453        SWISH_DEBUG_MSG("merge parsers"); 
    455454    } 
    456     swish_hash_merge(config1->parsers,      config2->parsers); 
    457      
     455    swish_hash_merge(config1->parsers, config2->parsers); 
     456 
    458457    if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { 
    459458        SWISH_DEBUG_MSG("merge mimes"); 
    460459    } 
    461     swish_hash_merge(config1->mimes,        config2->mimes); 
    462      
     460    swish_hash_merge(config1->mimes, config2->mimes); 
     461 
    463462    if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { 
    464463        SWISH_DEBUG_MSG("merge index"); 
    465464    } 
    466     swish_hash_merge(config1->index,        config2->index); 
    467      
     465    swish_hash_merge(config1->index, config2->index); 
     466 
    468467    if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { 
    469468        SWISH_DEBUG_MSG("merge tag_aliases"); 
    470469    } 
    471     swish_hash_merge(config1->tag_aliases, config2->tag_aliases); 
    472      
     470    swish_hash_merge(config1->tag_aliases, config2->tag_aliases); 
     471 
    473472    if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { 
    474473        SWISH_DEBUG_MSG("merge misc"); 
    475474    } 
    476     swish_hash_merge(config1->misc,         config2->misc); 
    477      
     475    swish_hash_merge(config1->misc, config2->misc); 
     476 
    478477    if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { 
    479478        SWISH_DEBUG_MSG("merge complete"); 
    480479    } 
    481480 
    482     /* set flags */ 
     481/* set flags */ 
    483482    config1->flags->tokenize = config2->flags->tokenize; 
    484      
     483 
    485484    if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { 
    486485        SWISH_DEBUG_MSG("flags set"); 
    487486    } 
    488      
    489 
    490  
     487 
     488
  • libswish3/trunk/src/libswish3/docinfo.c

    r2098 r2101  
    1616 *  along with libswish3; if not, write to the Free Software 
    1717 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
    18  */ 
     18*/ 
    1919 
    2020/* docinfo.c -- stat and time of files */ 
     
    2828#include <stdlib.h> 
    2929 
    30 extern int errno; 
     30extern int      errno; 
    3131 
    3232#include "libswish3.h" 
    3333 
    34 extern int SWISH_DEBUG; 
    35  
    36 /* PUBLIC */ 
    37 swish_DocInfo
     34extern int      SWISH_DEBUG; 
     35 
     36/* PUBLIC */ 
     37swish_DocInfo
    3838swish_init_docinfo() 
    3939{ 
     
    4141    if (SWISH_DEBUG > 9) 
    4242        SWISH_DEBUG_MSG("init'ing docinfo"); 
    43      
    44     swish_DocInfo *docinfo = swish_xmalloc( sizeof(swish_DocInfo) ); 
    45     docinfo->ref_cnt        = 0; 
    46     docinfo->nwords         = 0; 
    47     docinfo->mtime          = 0; 
    48     docinfo->size           = 0; 
    49     docinfo->encoding       = swish_xstrdup( (xmlChar*)SWISH_DEFAULT_ENCODING ); 
    50     docinfo->uri            = NULL; 
    51     docinfo->mime           = NULL; 
    52     docinfo->parser         = NULL; 
    53     docinfo->ext            = NULL; 
    54     docinfo->update         = NULL; 
    55     
    56     if (SWISH_DEBUG > 9) 
    57     { 
     43 
     44    swish_DocInfo  *docinfo = swish_xmalloc(sizeof(swish_DocInfo)); 
     45    docinfo->ref_cnt = 0; 
     46    docinfo->nwords = 0; 
     47    docinfo->mtime = 0; 
     48    docinfo->size = 0; 
     49    docinfo->encoding = swish_xstrdup((xmlChar *) SWISH_DEFAULT_ENCODING); 
     50    docinfo->uri = NULL; 
     51    docinfo->mime = NULL; 
     52    docinfo->parser = NULL; 
     53    docinfo->ext = NULL; 
     54    docinfo->update = NULL; 
     55 
     56    if (SWISH_DEBUG > 9) { 
    5857        SWISH_DEBUG_MSG("docinfo all ready"); 
    59         swish_debug_docinfo( docinfo ); 
     58        swish_debug_docinfo(docinfo); 
    6059    } 
    6160 
     
    6564/* PUBLIC */ 
    6665void 
    67 swish_free_docinfo( swish_DocInfo * ptr
    68 {     
     66swish_free_docinfo(swish_DocInfo *ptr
     67{ 
    6968    if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO) 
    7069        SWISH_DEBUG_MSG("freeing swish_DocInfo"); 
    7170 
    7271    if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO) 
    73         swish_debug_docinfo( ptr ); 
     72        swish_debug_docinfo(ptr); 
    7473 
    7574 
     
    7877    } 
    7978 
    80     ptr->nwords = 0; /* why is this required? */ 
    81     ptr->mtime = 0; 
    82     ptr->size   = 0; 
    83      
    84     /* encoding and mime are malloced via xmlstrdup elsewhere */ 
     79    ptr->nwords = 0;    /* why is this required? */ 
     80    ptr->mtime = 0; 
     81    ptr->size = 0; 
     82 
     83/* encoding and mime are malloced via xmlstrdup elsewhere */ 
    8584    if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO) 
    8685        SWISH_DEBUG_MSG("freeing docinfo->encoding"); 
    8786    swish_xfree(ptr->encoding); 
    88      
     87 
    8988    if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO) 
    9089        SWISH_DEBUG_MSG("freeing docinfo->mime"); 
    9190    if (ptr->mime != NULL) 
    9291        swish_xfree(ptr->mime); 
    93          
     92 
    9493    if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO) 
    9594        SWISH_DEBUG_MSG("freeing docinfo->uri"); 
    9695    if (ptr->uri != NULL) 
    9796        swish_xfree(ptr->uri); 
    98          
     97 
    9998    if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO) 
    10099        SWISH_DEBUG_MSG("freeing docinfo->ext"); 
    101100    if (ptr->ext != NULL) 
    102101        swish_xfree(ptr->ext); 
    103          
     102 
    104103    if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO) 
    105104        SWISH_DEBUG_MSG("freeing docinfo->parser"); 
    106105    if (ptr->parser != NULL) 
    107106        swish_xfree(ptr->parser); 
    108          
     107 
    109108    if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO) 
    110109        SWISH_DEBUG_MSG("freeing docinfo ptr"); 
    111110    swish_xfree(ptr); 
    112      
     111 
    113112    if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO) 
    114113        SWISH_DEBUG_MSG("swish_DocInfo all freed"); 
     
    116115 
    117116int 
    118 swish_check_docinfo(swish_DocInfo * docinfo, swish_Config * config) 
    119 { 
    120     int     ok; 
    121     xmlChar *ext; 
    122      
     117swish_check_docinfo(swish_DocInfo *docinfo, swish_Config *config) 
     118{ 
     119    int             ok; 
     120    xmlChar        *ext; 
     121 
    123122    ok = 1; 
    124123 
     
    131130    if (docinfo->size == -1) 
    132131        SWISH_CROAK("Failed to return required header Content-Length: for doc '%s'", 
    133                          docinfo->uri); 
     132                docinfo->uri); 
    134133 
    135134/* might make this conditional on verbose level */ 
    136     if (docinfo->size == 0)     
     135    if (docinfo->size == 0) 
    137136        SWISH_CROAK("Found zero Content-Length for doc '%s'", docinfo->uri); 
    138137 
    139138    ext = swish_get_file_ext(docinfo->uri); 
    140     /* this fails with non-filenames like db ids, etc. */ 
    141  
    142     if (docinfo->ext == NULL) 
    143     { 
     139/* this fails with non-filenames like db ids, etc. */ 
     140 
     141    if (docinfo->ext == NULL) { 
    144142        if (ext != NULL) 
    145             docinfo->ext = swish_xstrdup( ext ); 
     143            docinfo->ext = swish_xstrdup(ext); 
    146144        else 
    147             docinfo->ext = swish_xstrdup((xmlChar*)"none"); 
    148              
     145            docinfo->ext = swish_xstrdup((xmlChar *) "none"); 
     146 
    149147    } 
    150148 
     
    153151    if (!docinfo->mime) { 
    154152        if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO) 
    155             SWISH_DEBUG_MSG( "no MIME known. guessing based on uri extension '%s'", docinfo->ext); 
    156         docinfo->mime = swish_get_mime_type( config, docinfo->ext ); 
    157     } 
    158     else 
    159     { 
    160         if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO) 
    161             SWISH_DEBUG_MSG( "found MIME type in headers: '%s'", docinfo->mime); 
    162              
    163     } 
    164      
     153            SWISH_DEBUG_MSG("no MIME known. guessing based on uri extension '%s'", docinfo->ext); 
     154        docinfo->mime = swish_get_mime_type(config, docinfo->ext); 
     155    } 
     156    else { 
     157        if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO) 
     158            SWISH_DEBUG_MSG("found MIME type in headers: '%s'", docinfo->mime); 
     159 
     160    } 
     161 
    165162    if (!docinfo->parser) { 
    166163        if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO) 
    167             SWISH_DEBUG_MSG( "no parser defined in headers -- deducing from content type '%s'", docinfo->mime); 
    168              
    169         docinfo->parser = swish_get_parser( config, docinfo->mime ); 
    170     } 
    171     else 
    172     { 
    173         if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO) 
    174             SWISH_DEBUG_MSG( "found parser in headers: '%s'", docinfo->parser); 
    175              
    176     } 
    177      
     164            SWISH_DEBUG_MSG("no parser defined in headers -- deducing from content type '%s'", docinfo->mime); 
     165 
     166        docinfo->parser = swish_get_parser(config, docinfo->mime); 
     167    } 
     168    else { 
     169        if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO) 
     170            SWISH_DEBUG_MSG("found parser in headers: '%s'", docinfo->parser); 
     171 
     172    } 
     173 
    178174    if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO) 
    179175        swish_debug_docinfo(docinfo); 
     
    185181/* PUBLIC */ 
    186182int 
    187 swish_docinfo_from_filesystem( xmlChar *filename, swish_DocInfo * i, swish_ParserData *parser_data
    188 { 
    189     struct stat info; 
    190     int     stat_res; 
    191      
     183swish_docinfo_from_filesystem(xmlChar *filename, swish_DocInfo *i, swish_ParserData *parser_data
     184{ 
     185    struct stat    info; 
     186    int             stat_res; 
     187 
    192188    if (i->ext != NULL) 
    193         swish_xfree( i->ext ); 
    194          
    195     i->ext = swish_get_file_ext( filename ); 
    196              
    197     stat_res = stat((char *)filename, &info); 
    198          
    199     if ( stat_res == -1) 
    200     { 
     189        swish_xfree(i->ext); 
     190 
     191    i->ext = swish_get_file_ext(filename); 
     192 
     193    stat_res = stat((char *) filename, &info); 
     194 
     195    if (stat_res == -1) { 
    201196        SWISH_WARN("Can't stat '%s': %s", filename, strerror(errno)); 
    202197        return 0; 
    203198    } 
    204                         
     199 
    205200    if (SWISH_DEBUG > 9) 
    206201        SWISH_DEBUG_MSG("handling url %s", filename); 
    207          
    208     if(i->uri != NULL) 
     202 
     203    if (i->uri != NULL) 
    209204        swish_xfree(i->uri); 
    210              
    211     i->uri = swish_xstrdup( filename );        
     205 
     206    i->uri = swish_xstrdup(filename); 
    212207    i->mtime = info.st_mtime; 
    213     i->size = info.st_size; 
    214      
     208    i->size = info.st_size; 
     209 
    215210    if (SWISH_DEBUG > 9) 
    216211        SWISH_DEBUG_MSG("handling mime"); 
    217          
    218     if(i->mime != NULL) 
     212 
     213    if (i->mime != NULL) 
    219214        swish_xfree(i->mime); 
    220          
    221     i->mime = swish_get_mime_type( parser_data->s3->config, i->ext ); 
    222          
     215 
     216    i->mime = swish_get_mime_type(parser_data->s3->config, i->ext); 
     217 
    223</