Changeset 2103
- Timestamp:
- 03/27/08 23:35:21 (2 months ago)
- Files:
-
- libswish3/trunk/src/libswish3/analyzer.c (modified) (2 diffs)
- libswish3/trunk/src/libswish3/config.c (modified) (18 diffs)
- libswish3/trunk/src/libswish3/docinfo.c (modified) (13 diffs)
- libswish3/trunk/src/libswish3/error.c (modified) (3 diffs)
- libswish3/trunk/src/libswish3/getruntime.c (modified) (6 diffs)
- libswish3/trunk/src/libswish3/hash.c (modified) (8 diffs)
- libswish3/trunk/src/libswish3/header.c (modified) (48 diffs)
- libswish3/trunk/src/libswish3/io.c (modified) (8 diffs)
- libswish3/trunk/src/libswish3/mem.c (modified) (8 diffs)
- libswish3/trunk/src/libswish3/metaname.c (modified) (3 diffs)
- libswish3/trunk/src/libswish3/mime_types.c (modified) (6 diffs)
- libswish3/trunk/src/libswish3/namedbuffer.c (modified) (10 diffs)
- libswish3/trunk/src/libswish3/parser.c (modified) (112 diffs)
- libswish3/trunk/src/libswish3/property.c (modified) (3 diffs)
- libswish3/trunk/src/libswish3/string.c (modified) (39 diffs)
- libswish3/trunk/src/libswish3/swish.c (modified) (5 diffs)
- libswish3/trunk/src/libswish3/times.c (modified) (6 diffs)
- libswish3/trunk/src/libswish3/utf8.c (modified) (25 diffs)
- libswish3/trunk/src/libswish3/words.c (modified) (33 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
libswish3/trunk/src/libswish3/analyzer.c
r2101 r2103 25 25 #include "libswish3.h" 26 26 27 extern int SWISH_DEBUG;27 extern int SWISH_DEBUG; 28 28 29 29 swish_Analyzer * 30 swish_init_analyzer(swish_Config *config) 30 swish_init_analyzer( 31 swish_Config *config 32 ) 31 33 { 32 34 swish_Analyzer *a; … … 64 66 65 67 void 66 swish_free_analyzer(swish_Analyzer *a) 68 swish_free_analyzer( 69 swish_Analyzer *a 70 ) 67 71 { 68 72 if (a->ref_cnt != 0) { libswish3/trunk/src/libswish3/config.c
r2101 r2103 1 1 2 /* 2 3 * This file is part of libswish3 … … 34 35 #include "libswish3.h" 35 36 36 extern int SWISH_DEBUG; 37 38 void 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); 64 static void 65 copy_property( 66 swish_Property * prop2, 67 xmlHashTablePtr props1, 68 xmlChar *prop2name 69 ); 70 static void 71 merge_properties(xmlHashTablePtr props1, xmlHashTablePtr props2); 72 static void 73 copy_metaname( 74 swish_MetaName * meta2, 75 xmlHashTablePtr metas1, 76 xmlChar *meta2name 77 ); 78 static void 79 merge_metanames(xmlHashTablePtr metas1, xmlHashTablePtr metas2); 80 81 static void 82 free_string(xmlChar *payload, xmlChar *key) 37 extern int SWISH_DEBUG; 38 39 void swish_free_config( 40 swish_Config *config 41 ); 42 swish_Config *swish_init_config( 43 ); 44 void swish_config_set_default( 45 swish_Config *config 46 ); 47 swish_Config *swish_add_config( 48 xmlChar *conf, 49 swish_Config *config 50 ); 51 swish_Config *swish_parse_config( 52 xmlChar *conf, 53 swish_Config *config 54 ); 55 void swish_debug_config( 56 swish_Config *config 57 ); 58 void swish_config_merge( 59 swish_Config *config1, 60 swish_Config *config2 61 ); 62 static void free_string( 63 xmlChar *payload, 64 xmlChar *key 65 ); 66 static void free_props( 67 swish_Property *prop, 68 xmlChar *propname 69 ); 70 static void free_metas( 71 swish_MetaName *meta, 72 xmlChar *metaname 73 ); 74 static void config_printer( 75 xmlChar *val, 76 xmlChar *str, 77 xmlChar *key 78 ); 79 static void property_printer( 80 swish_Property *prop, 81 xmlChar *str, 82 xmlChar *propname 83 ); 84 static void metaname_printer( 85 swish_MetaName *meta, 86 xmlChar *str, 87 xmlChar *metaname 88 ); 89 static void copy_property( 90 swish_Property *prop2, 91 xmlHashTablePtr props1, 92 xmlChar *prop2name 93 ); 94 static void merge_properties( 95 xmlHashTablePtr props1, 96 xmlHashTablePtr props2 97 ); 98 static void copy_metaname( 99 swish_MetaName *meta2, 100 xmlHashTablePtr metas1, 101 xmlChar *meta2name 102 ); 103 static void merge_metanames( 104 xmlHashTablePtr metas1, 105 xmlHashTablePtr metas2 106 ); 107 108 static void 109 free_string( 110 xmlChar *payload, 111 xmlChar *key 112 ) 83 113 { 84 114 if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) … … 89 119 90 120 static void 91 free_props(swish_Property * prop, xmlChar *propname) 121 free_props( 122 swish_Property *prop, 123 xmlChar *propname 124 ) 92 125 { 93 126 if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { 94 127 SWISH_DEBUG_MSG(" freeing config->prop %s", propname); 95 swish_debug_property((swish_Property *) prop);128 swish_debug_property((swish_Property *)prop); 96 129 } 97 130 prop->ref_cnt--; … … 102 135 103 136 static void 104 free_metas(swish_MetaName * meta, xmlChar *metaname) 137 free_metas( 138 swish_MetaName *meta, 139 xmlChar *metaname 140 ) 105 141 { 106 142 if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { 107 143 SWISH_DEBUG_MSG(" freeing config->meta %s", metaname); 108 swish_debug_metaname((swish_MetaName *) meta);144 swish_debug_metaname((swish_MetaName *)meta); 109 145 } 110 146 meta->ref_cnt--; … … 115 151 116 152 void 117 swish_free_config(swish_Config *config) 153 swish_free_config( 154 swish_Config *config 155 ) 118 156 { 119 157 if (SWISH_DEBUG & SWISH_DEBUG_MEMORY) { 120 158 SWISH_DEBUG_MSG("freeing config"); 121 SWISH_DEBUG_MSG("ptr addr: 0x%x %d", (int) config, (int)config);159 SWISH_DEBUG_MSG("ptr addr: 0x%x %d", (int)config, (int)config); 122 160 } 123 161 … … 142 180 } 143 181 144 145 146 182 /* init config object */ 147 183 148 swish_Config * 149 swish_init_config() 150 { 151 swish_Config *config; 184 swish_Config * 185 swish_init_config( 186 ) 187 { 188 swish_Config *config; 152 189 153 190 if (SWISH_DEBUG & SWISH_DEBUG_MEMORY) { … … 176 213 177 214 void 178 swish_config_set_default(swish_Config *config) 215 swish_config_set_default( 216 swish_Config *config 217 ) 179 218 { 180 219 swish_Property *tmpprop; … … 190 229 191 230 /* metanames */ 192 swish_hash_add( 193 config->metanames, 194 (xmlChar *) SWISH_DEFAULT_METANAME, 195 swish_init_metaname(swish_xstrdup((xmlChar *) SWISH_DEFAULT_METANAME)) 231 swish_hash_add(config->metanames, (xmlChar *)SWISH_DEFAULT_METANAME, 232 swish_init_metaname(swish_xstrdup 233 ((xmlChar *)SWISH_DEFAULT_METANAME)) 196 234 ); 197 swish_hash_add( 198 config->metanames, 199 (xmlChar *) SWISH_TITLE_METANAME, 200 swish_init_metaname(swish_xstrdup((xmlChar *) SWISH_TITLE_METANAME)) 235 swish_hash_add(config->metanames, (xmlChar *)SWISH_TITLE_METANAME, 236 swish_init_metaname(swish_xstrdup 237 ((xmlChar *)SWISH_TITLE_METANAME)) 201 238 ); 202 239 … … 204 241 a little awkward, but saves var names. 205 242 */ 206 tmpmeta = swish_hash_fetch(config->metanames, (xmlChar *) SWISH_DEFAULT_METANAME); 243 tmpmeta = 244 swish_hash_fetch(config->metanames, (xmlChar *)SWISH_DEFAULT_METANAME); 207 245 tmpmeta->ref_cnt++; 208 246 tmpmeta->id = SWISH_META_DEFAULT_ID; 209 tmpmeta = swish_hash_fetch(config->metanames, (xmlChar *) SWISH_TITLE_METANAME); 247 tmpmeta = 248 swish_hash_fetch(config->metanames, (xmlChar *)SWISH_TITLE_METANAME); 210 249 tmpmeta->ref_cnt++; 211 250 tmpmeta->id = SWISH_META_TITLE_ID; 212 251 213 214 252 /* 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 253 swish_hash_add(config->parsers, (xmlChar *)"text/plain", 254 swish_xstrdup((xmlChar *)SWISH_PARSER_TXT)); 255 swish_hash_add(config->parsers, (xmlChar *)"text/xml", 256 swish_xstrdup((xmlChar *)SWISH_PARSER_XML)); 257 swish_hash_add(config->parsers, (xmlChar *)"text/html", 258 swish_xstrdup((xmlChar *)SWISH_PARSER_HTML)); 259 swish_hash_add(config->parsers, (xmlChar *)SWISH_DEFAULT_PARSER, 260 swish_xstrdup((xmlChar *)SWISH_DEFAULT_PARSER_TYPE)); 232 261 233 262 /* 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 263 swish_hash_add(config->index, (xmlChar *)SWISH_INDEX_FORMAT, 264 swish_xstrdup((xmlChar *)SWISH_INDEX_FILEFORMAT)); 265 swish_hash_add(config->index, (xmlChar *)SWISH_INDEX_NAME, 266 swish_xstrdup((xmlChar *)SWISH_INDEX_FILENAME)); 267 swish_hash_add(config->index, (xmlChar *)SWISH_INDEX_LOCALE, 268 swish_xstrdup((xmlChar *)setlocale(LC_ALL, ""))); 247 269 248 270 /* properties */ 249 swish_hash_add( 250 config->properties, 251 (xmlChar *) SWISH_PROP_DESCRIPTION, 252 swish_init_property(swish_xstrdup((xmlChar *) SWISH_PROP_DESCRIPTION)) 271 swish_hash_add(config->properties, (xmlChar *)SWISH_PROP_DESCRIPTION, 272 swish_init_property(swish_xstrdup 273 ((xmlChar *)SWISH_PROP_DESCRIPTION)) 253 274 ); 254 swish_hash_add( 255 config->properties, 256 (xmlChar *) SWISH_PROP_TITLE, 257 swish_init_property(swish_xstrdup((xmlChar *) SWISH_PROP_TITLE)) 275 swish_hash_add(config->properties, (xmlChar *)SWISH_PROP_TITLE, 276 swish_init_property(swish_xstrdup 277 ((xmlChar *)SWISH_PROP_TITLE)) 258 278 ); 259 279 260 280 /* same deal as metanames above */ 261 tmpprop = swish_hash_fetch(config->properties, (xmlChar *) SWISH_PROP_DESCRIPTION); 281 tmpprop = 282 swish_hash_fetch(config->properties, (xmlChar *)SWISH_PROP_DESCRIPTION); 262 283 tmpprop->ref_cnt++; 263 284 tmpprop->id = SWISH_PROP_DESCRIPTION_ID; 264 tmpprop = swish_hash_fetch(config->properties, (xmlChar *) SWISH_PROP_TITLE);285 tmpprop = swish_hash_fetch(config->properties, (xmlChar *)SWISH_PROP_TITLE); 265 286 tmpprop->ref_cnt++; 266 287 tmpprop->id = SWISH_PROP_TITLE_ID; 267 288 268 269 289 /* aliases: other names a tag might be known as, for matching properties and 270 290 * metanames */ 271 swish_hash_add( 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 291 swish_hash_add(config->tag_aliases, (xmlChar *)SWISH_TITLE_TAG, 292 swish_xstrdup((xmlChar *)SWISH_TITLE_METANAME)); 293 swish_hash_add(config->tag_aliases, (xmlChar *)SWISH_BODY_TAG, 294 swish_xstrdup((xmlChar *)SWISH_PROP_DESCRIPTION)); 280 295 281 296 if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { … … 286 301 } 287 302 288 swish_Config * 289 swish_add_config(xmlChar *conf, swish_Config *config) 303 swish_Config * 304 swish_add_config( 305 xmlChar *conf, 306 swish_Config *config 307 ) 290 308 { 291 309 … … 298 316 } 299 317 300 swish_Config * 301 swish_parse_config(xmlChar *conf, swish_Config *config) 302 { 303 swish_merge_config_with_header((char *) conf, config); 318 swish_Config * 319 swish_parse_config( 320 xmlChar *conf, 321 swish_Config *config 322 ) 323 { 324 swish_merge_config_with_header((char *)conf, config); 304 325 return config; 305 326 } 306 327 307 308 static void 309 config_printer(xmlChar *val, xmlChar *str, xmlChar *key) 328 static void 329 config_printer( 330 xmlChar *val, 331 xmlChar *str, 332 xmlChar *key 333 ) 310 334 { 311 335 SWISH_DEBUG_MSG(" %s: %s => %s", str, key, val); … … 313 337 314 338 static void 315 property_printer(swish_Property * prop, xmlChar *str, xmlChar *propname) 339 property_printer( 340 swish_Property *prop, 341 xmlChar *str, 342 xmlChar *propname 343 ) 316 344 { 317 345 SWISH_DEBUG_MSG(" %s: %s =>", str, propname); … … 320 348 321 349 static void 322 metaname_printer(swish_MetaName * meta, xmlChar *str, xmlChar *metaname) 350 metaname_printer( 351 swish_MetaName *meta, 352 xmlChar *str, 353 xmlChar *metaname 354 ) 323 355 { 324 356 SWISH_DEBUG_MSG(" %s: %s =>", str, metaname); … … 328 360 /* PUBLIC */ 329 361 void 330 swish_debug_config(swish_Config *config) 362 swish_debug_config( 363 swish_Config *config 364 ) 331 365 { 332 366 SWISH_DEBUG_MSG("config->ref_cnt = %d", config->ref_cnt); 333 SWISH_DEBUG_MSG("config->stash address = 0x%x %d", (int) config->stash, (int) config->stash); 334 SWISH_DEBUG_MSG("ptr addr: 0x%x %d", (int) config, (int) config); 367 SWISH_DEBUG_MSG("config->stash address = 0x%x %d", (int)config->stash, 368 (int)config->stash); 369 SWISH_DEBUG_MSG("ptr addr: 0x%x %d", (int)config, (int)config); 335 370 336 371 xmlHashScan(config->misc, (xmlHashScanner) config_printer, "misc conf"); 337 xmlHashScan(config->properties, (xmlHashScanner) property_printer, "properties"); 338 xmlHashScan(config->metanames, (xmlHashScanner) metaname_printer, "metanames"); 372 xmlHashScan(config->properties, (xmlHashScanner) property_printer, 373 "properties"); 374 xmlHashScan(config->metanames, (xmlHashScanner) metaname_printer, 375 "metanames"); 339 376 xmlHashScan(config->parsers, (xmlHashScanner) config_printer, "parsers"); 340 377 xmlHashScan(config->mimes, (xmlHashScanner) config_printer, "mimes"); 341 378 xmlHashScan(config->index, (xmlHashScanner) config_printer, "index"); 342 xmlHashScan(config->tag_aliases, (xmlHashScanner) config_printer, "tag_aliases"); 379 xmlHashScan(config->tag_aliases, (xmlHashScanner) config_printer, 380 "tag_aliases"); 343 381 } 344 382 345 383 static void 346 384 copy_property( 347 swish_Property *prop2,348 xmlHashTablePtr props1,349 xmlChar *prop2name385 swish_Property *prop2, 386 xmlHashTablePtr props1, 387 xmlChar *prop2name 350 388 ) 351 389 { 352 390 swish_Property *prop1; 353 boolean in_hash;391 boolean in_hash; 354 392 355 393 if (swish_hash_exists(props1, prop2name)) { … … 387 425 388 426 static void 389 merge_properties(xmlHashTablePtr props1, xmlHashTablePtr props2) 427 merge_properties( 428 xmlHashTablePtr props1, 429 xmlHashTablePtr props2 430 ) 390 431 { 391 432 xmlHashScan(props2, (xmlHashScanner) copy_property, props1); … … 394 435 static void 395 436 copy_metaname( 396 swish_MetaName *meta2,397 xmlHashTablePtr metas1,398 xmlChar *meta2name437 swish_MetaName *meta2, 438 xmlHashTablePtr metas1, 439 xmlChar *meta2name 399 440 ) 400 441 { 401 442 swish_MetaName *meta1; 402 boolean in_hash; 443 boolean in_hash; 444 403 445 if (swish_hash_exists(metas1, meta2name)) { 404 446 meta1 = swish_hash_fetch(metas1, meta2name); … … 430 472 431 473 static void 432 merge_metanames(xmlHashTablePtr metas1, xmlHashTablePtr metas2) 474 merge_metanames( 475 xmlHashTablePtr metas1, 476 xmlHashTablePtr metas2 477 ) 433 478 { 434 479 xmlHashScan(metas2, (xmlHashScanner) copy_metaname, metas1); … … 436 481 437 482 void 438 swish_config_merge(swish_Config *config1, swish_Config *config2) 483 swish_config_merge( 484 swish_Config *config1, 485 swish_Config *config2 486 ) 439 487 { 440 488 libswish3/trunk/src/libswish3/docinfo.c
r2101 r2103 28 28 #include <stdlib.h> 29 29 30 extern int errno;30 extern int errno; 31 31 32 32 #include "libswish3.h" 33 33 34 extern int SWISH_DEBUG; 35 36 /* PUBLIC */ 37 swish_DocInfo * 38 swish_init_docinfo() 34 extern int SWISH_DEBUG; 35 36 /* PUBLIC */ 37 swish_DocInfo * 38 swish_init_docinfo( 39 ) 39 40 { 40 41 … … 42 43 SWISH_DEBUG_MSG("init'ing docinfo"); 43 44 44 swish_DocInfo *docinfo = swish_xmalloc(sizeof(swish_DocInfo));45 swish_DocInfo *docinfo = swish_xmalloc(sizeof(swish_DocInfo)); 45 46 docinfo->ref_cnt = 0; 46 47 docinfo->nwords = 0; 47 48 docinfo->mtime = 0; 48 49 docinfo->size = 0; 49 docinfo->encoding = swish_xstrdup((xmlChar *) SWISH_DEFAULT_ENCODING);50 docinfo->encoding = swish_xstrdup((xmlChar *)SWISH_DEFAULT_ENCODING); 50 51 docinfo->uri = NULL; 51 52 docinfo->mime = NULL; … … 64 65 /* PUBLIC */ 65 66 void 66 swish_free_docinfo(swish_DocInfo *ptr) 67 swish_free_docinfo( 68 swish_DocInfo *ptr 69 ) 67 70 { 68 71 if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO) … … 71 74 if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO) 72 75 swish_debug_docinfo(ptr); 73 74 76 75 77 if (ptr->ref_cnt != 0) { … … 77 79 } 78 80 79 ptr->nwords = 0; /* why is this required? */81 ptr->nwords = 0; /* why is this required? */ 80 82 ptr->mtime = 0; 81 83 ptr->size = 0; … … 115 117 116 118 int 117 swish_check_docinfo(swish_DocInfo *docinfo, swish_Config *config) 118 { 119 int ok; 120 xmlChar *ext; 119 swish_check_docinfo( 120 swish_DocInfo *docinfo, 121 swish_Config *config 122 ) 123 { 124 int ok; 125 xmlChar *ext; 121 126 122 127 ok = 1; … … 129 134 130 135 if (docinfo->size == -1) 131 SWISH_CROAK("Failed to return required header Content-Length: for doc '%s'", 132 docinfo->uri); 136 SWISH_CROAK 137 ("Failed to return required header Content-Length: for doc '%s'", 138 docinfo->uri); 133 139 134 140 /* might make this conditional on verbose level */ … … 143 149 docinfo->ext = swish_xstrdup(ext); 144 150 else 145 docinfo->ext = swish_xstrdup((xmlChar *) "none");151 docinfo->ext = swish_xstrdup((xmlChar *)"none"); 146 152 147 153 } … … 151 157 if (!docinfo->mime) { 152 158 if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO) 153 SWISH_DEBUG_MSG("no MIME known. guessing based on uri extension '%s'", docinfo->ext); 159 SWISH_DEBUG_MSG 160 ("no MIME known. guessing based on uri extension '%s'", 161 docinfo->ext); 154 162 docinfo->mime = swish_get_mime_type(config, docinfo->ext); 155 163 } … … 162 170 if (!docinfo->parser) { 163 171 if (SWISH_DEBUG & SWISH_DEBUG_DOCINFO) 164 SWISH_DEBUG_MSG("no parser defined in headers -- deducing from content type '%s'", docinfo->mime); 172 SWISH_DEBUG_MSG 173 ("no parser defined in headers -- deducing from content type '%s'", 174 docinfo->mime); 165 175 166 176 docinfo->parser = swish_get_parser(config, docinfo->mime); … … 181 191 /* PUBLIC */ 182 192 int 183 swish_docinfo_from_filesystem(xmlChar *filename, swish_DocInfo *i, swish_ParserData *parser_data) 184 { 185 struct stat info; 186 int stat_res; 193 swish_docinfo_from_filesystem( 194 xmlChar *filename, 195 swish_DocInfo *i, 196 swish_ParserData *parser_data 197 ) 198 { 199 struct stat info; 200 int stat_res; 187 201 188 202 if (i->ext != NULL) … … 191 205 i->ext = swish_get_file_ext(filename); 192 206 193 stat_res = stat((char *) filename, &info);207 stat_res = stat((char *)filename, &info); 194 208 195 209 if (stat_res == -1) { … … 230 244 /* PUBLIC */ 231 245 void 232 swish_debug_docinfo( swish_DocInfo *docinfo)233 { 234 xmlChar *h_mtime = swish_xmalloc(30); 235 strftime((char *) h_mtime, 236 (unsigned long) 30,237 SWISH_DATE_FORMAT_STRING,238 (struct tm *)localtime((time_t *) & (docinfo->mtime)));246 swish_debug_docinfo( 247 swish_DocInfo *docinfo 248 ) 249 { 250 xmlChar *h_mtime = swish_xmalloc(30); 251 strftime((char *)h_mtime, (unsigned long)30, SWISH_DATE_FORMAT_STRING, 252 (struct tm *)localtime((time_t *) & (docinfo->mtime))); 239 253 240 254 SWISH_DEBUG_MSG("DocInfo"); 241 SWISH_DEBUG_MSG(" docinfo ptr: %lu", (unsigned long) docinfo);255 SWISH_DEBUG_MSG(" docinfo ptr: %lu", (unsigned long)docinfo); 242 256 /* SWISH_DEBUG_MSG(" size of swish_DocInfo struct: %d", (int)sizeof(swish_DocInfo)); */ 243 257 /* SWISH_DEBUG_MSG(" size of docinfo ptr: %d", (int)sizeof(*docinfo)); */ 244 SWISH_DEBUG_MSG(" uri: %s (%d)", docinfo->uri, (int) sizeof(docinfo->uri)); 245 SWISH_DEBUG_MSG(" doc size: %lu bytes (%d)", (unsigned long) docinfo->size, (int) sizeof(docinfo->size)); 246 SWISH_DEBUG_MSG(" doc mtime: %lu (%d)", (unsigned long) docinfo->mtime, (int) sizeof(docinfo->mtime)); 258 SWISH_DEBUG_MSG(" uri: %s (%d)", docinfo->uri, (int)sizeof(docinfo->uri)); 259 SWISH_DEBUG_MSG(" doc size: %lu bytes (%d)", (unsigned long)docinfo->size, 260 (int)sizeof(docinfo->size)); 261 SWISH_DEBUG_MSG(" doc mtime: %lu (%d)", (unsigned long)docinfo->mtime, 262 (int)sizeof(docinfo->mtime)); 247 263 /* SWISH_DEBUG_MSG(" size of mime: %d", (int)sizeof(docinfo->mime)); */ 248 264 /* SWISH_DEBUG_MSG(" size of encoding: %d", (int)sizeof(docinfo->encoding)); */ 249 265 SWISH_DEBUG_MSG(" mtime str: %s", h_mtime); 250 266 SWISH_DEBUG_MSG(" mime type: %s", docinfo->mime); 251 SWISH_DEBUG_MSG(" encoding: %s", docinfo->encoding); /* only known after parsing has252 started ... */267 SWISH_DEBUG_MSG(" encoding: %s", docinfo->encoding); /* only known after parsing has 268 started ... */ 253 269 SWISH_DEBUG_MSG(" file ext: %s", docinfo->ext); 254 270 SWISH_DEBUG_MSG(" parser: %s", docinfo->parser); libswish3/trunk/src/libswish3/error.c
r2101 r2103 30 30 #include "libswish3.h" 31 31 32 extern int SWISH_DEBUG;32 extern int SWISH_DEBUG; 33 33 34 static FILE *error_handle = NULL; 34 35 35 static FILE *error_handle = NULL; 36 37 void 38 swish_set_error_handle(FILE * where)36 void 37 swish_set_error_handle( 38 FILE * where 39 ) 39 40 { 40 41 error_handle = where; 41 42 } 42 43 43 void 44 swish_croak(const char *file, int line, const char *func, char *msgfmt,...) 44 void 45 swish_croak( 46 const char *file, 47 int line, 48 const char *func, 49 char *msgfmt, 50 ... 51 ) 45 52 { 46 va_list args;53 va_list args; 47 54 48 55 if (!error_handle) … … 61 68 } 62 69 63 void 64 swish_warn(const char *file, int line, const char *func, char *msgfmt,...) 70 void 71 swish_warn( 72 const char *file, 73 int line, 74 const char *func, 75 char *msgfmt, 76 ... 77 ) 65 78 { 66 va_list args;79 va_list args; 67 80 68 81 if (!error_handle) … … 76 89 } 77 90 78 void 79 swish_debug(const char *file, int line, const char *func, char *msgfmt,...) 91 void 92 swish_debug( 93 const char *file, 94 int line, 95 const char *func, 96 char *msgfmt, 97 ... 98 ) 80 99 { 81 va_list args;100 va_list args; 82 101 83 102 if (!error_handle) libswish3/trunk/src/libswish3/getruntime.c
r2101 r2103 18 18 Boston, MA 02111-1307, USA. 19 19 */ 20 21 20 22 21 #include "acconfig.h" … … 73 72 74 73 cpu_seconds 75 get_cpu_secs() 74 get_cpu_secs( 75 ) 76 76 { 77 77 #if defined (HAVE_GETRUSAGE) && defined (HAVE_SYS_RESOURCE_H) 78 struct rusage rusage;79 cpu_seconds secs;78 struct rusage rusage; 79 cpu_seconds secs; 80 80 81 81 getrusage(0, &rusage); … … 89 89 return secs; 90 90 91 92 #else /* ! HAVE_GETRUSAGE */ 91 #else /* ! HAVE_GETRUSAGE */ 93 92 #ifdef HAVE_TIMES 94 93 … … 97 96 /* Again, these are clock_t, which may overflow, but under linux it's 1/100 second so about 6000 hours */ 98 97 99 struct tms tms;98 struct tms tms; 100 99 101 100 times(&tms); … … 103 102 return (cpu_seconds) ((tms.tms_utime + tms.tms_stime) / GNU_HZ); 104 103 105 106 #else /* ! HAVE_TIMES */ 104 #else /* ! HAVE_TIMES */ 107 105 /* Fall back on clock and hope it's correctly implemented. */ 108 106 /* clock() returns clock_t, which seems to be a long. On Linux CLOCKS_PER_SEC is 10^6 */ 109 107 /* so expect an overflow at about 35 minutes. */ 110 108 111 clock_t t = clock();109 clock_t t = clock(); 112 110 if (t < 0) 113 111 t = 0; … … 115 113 return (cpu_seconds) (t / CLOCKS_PER_SEC); 116 114 117 #endif /* HAVE_TIMES */118 #endif /* HAVE_GETRUSAGE */115 #endif /* HAVE_TIMES */ 116 #endif /* HAVE_GETRUSAGE */ 119 117 } libswish3/trunk/src/libswish3/hash.c
r2101 r2103 18 18 */ 19 19 20 21 20 /* wrappers to common functions in libxml2 hash */ 22 21 … … 25 24 #include "libswish3.h" 26 25 27 extern int SWISH_DEBUG;26 extern int SWISH_DEBUG; 28 27 29 int swish_hash_add(xmlHashTablePtr hash, xmlChar *key, void *value); 30 int 31 swish_hash_replace(xmlHashTablePtr hash, xmlChar *key, void *value); 32 int 33 swish_hash_delete(xmlHashTablePtr hash, xmlChar *key); 34 boolean 35 swish_hash_exists(xmlHashTablePtr hash, xmlChar *key); 36 void * 37 swish_hash_fetch(xmlHashTablePtr hash, xmlChar *key); 38 xmlHashTablePtr 39 swish_init_hash(int size); 40 void 41 swish_hash_merge(xmlHashTablePtr hash1, xmlHashTablePtr hash2); 42 static void free_hashval(void *val, xmlChar *key); 28 int swish_hash_add( 29 xmlHashTablePtr hash, 30 xmlChar *key, 31 void *value 32 ); 33 int swish_hash_replace( 34 xmlHashTablePtr hash, 35 xmlChar *key, 36 void *value 37 ); 38 int swish_hash_delete( 39 xmlHashTablePtr hash, 40 xmlChar *key 41 ); 42 boolean swish_hash_exists( 43 xmlHashTablePtr hash, 44 xmlChar *key 45 ); 46 void *swish_hash_fetch( 47 xmlHashTablePtr hash, 48 xmlChar *key 49 ); 50 xmlHashTablePtr swish_init_hash( 51 int size 52 ); 53 void swish_hash_merge( 54 xmlHashTablePtr hash1, 55 xmlHashTablePtr hash2 56 ); 57 static void free_hashval( 58 void *val, 59 xmlChar *key 60 ); 61 static void merge_hashes( 62 xmlChar *value, 63 xmlHashTablePtr hash1, 64 xmlChar *key 65 ); 66 43 67 static void 44 merge_hashes(xmlChar *value, xmlHashTablePtr hash1, xmlChar *key); 45 46 47 static void 48 free_hashval(void *val, xmlChar *key) 68 free_hashval( 69 void *val, 70 xmlChar *key 71 ) 49 72 { 50 73 if (SWISH_DEBUG > 10) 51 printf("freeing %s from hash key %s\n", (xmlChar *) val, key);74 printf("freeing %s from hash key %s\n", (xmlChar *)val, key); 52 75 53 76 swish_xfree(val); 54 77 } 55 78 56 57 int 58 swish_hash_add(xmlHashTablePtr hash, xmlChar *key, void *value) 79 int 80 swish_hash_add( 81 xmlHashTablePtr hash, 82 xmlChar *key, 83 void *value 84 ) 59 85 { 60 int ret;86 int ret; 61 87 ret = xmlHashAddEntry(hash, key, value); 62 88 if (ret == -1) … … 67 93 68 94 int 69 swish_hash_replace(xmlHashTablePtr hash, xmlChar *key, void *value) 95 swish_hash_replace( 96 xmlHashTablePtr hash, 97 xmlChar *key, 98 void *value 99 ) 70 100 { 71 int ret; 72 ret = xmlHashUpdateEntry(hash, key, value, (xmlHashDeallocator) free_hashval); 101 int ret; 102 ret = 103 xmlHashUpdateEntry(hash, key, value, (xmlHashDeallocator) free_hashval); 73 104 if (ret == -1) 74 105 SWISH_CROAK("xmlHashUpdateEntry for %s failed", key); … … 78 109 79 110 int 80 swish_hash_delete(xmlHashTablePtr hash, xmlChar *key) 111 swish_hash_delete( 112 xmlHashTablePtr hash, 113 xmlChar *key 114 ) 81 115 { 82 int ret;116 int ret; 83 117 ret = xmlHashRemoveEntry(hash, key, (xmlHashDeallocator) free_hashval); 84 118 if (ret == -1) … … 89 123 90 124 boolean 91 swish_hash_exists(xmlHashTablePtr hash, xmlChar *key) 125 swish_hash_exists( 126 xmlHashTablePtr hash, 127 xmlChar *key 128 ) 92 129 { 93 130 return xmlHashLookup(hash, key) ? 1 : 0; 94 131 } 95 132 96 void * 97 swish_hash_fetch(xmlHashTablePtr hash, xmlChar *key) 133 void * 134 swish_hash_fetch( 135 xmlHashTablePtr hash, 136 xmlChar *key 137 ) 98 138 { 99 139 return xmlHashLookup(hash, key); … … 101 141 102 142 xmlHashTablePtr 103 swish_init_hash(int size) 143 swish_init_hash( 144 int size 145 ) 104 146 { 105 147 xmlHashTablePtr h; … … 115 157 116 158 static void 117 merge_hashes(xmlChar *value, xmlHashTablePtr hash1, xmlChar *key) 159 merge_hashes( 160 xmlChar *value, 161 xmlHashTablePtr hash1, 162 xmlChar *key 163 ) 118 164 { 119 165 if (swish_hash_exists(hash1, key)) { … … 126 172 127 173 void 128 swish_hash_merge(xmlHashTablePtr hash1, xmlHashTablePtr hash2) 174 swish_hash_merge( 175 xmlHashTablePtr hash1, 176 xmlHashTablePtr hash2 177 ) 129 178 { 130 179 xmlHashScan(hash2, (xmlHashScanner) merge_hashes, hash1); libswish3/trunk/src/libswish3/header.c
r2101 r2103 25 25 #include "libswish3.h" 26 26 27 extern int SWISH_DEBUG;27 extern int SWISH_DEBUG; 28 28 29 29 /* local struct to ease passing around flags/state */ 30 typedef struct { 31 boolean isprops; 32 boolean ismetas; 33 boolean isindex; 34 boolean isparser; 35 boolean isalias; 36 boolean ismime; 37 const xmlChar *parent_name; 38 swish_Config *config; 39 boolean is_valid; 40 unsigned int prop_id; 41 unsigned int meta_id; 42 } headmaker; 43 44 typedef struct { 45 void *thing1; 46 void *thing2; 47 void *thing3; 48 } things; 30 typedef struct 31 { 32 boolean isprops; 33 boolean ismetas; 34 boolean isindex; 35 boolean isparser; 36 boolean isalias; 37 boolean ismime; 38 const xmlChar *parent_name; 39 swish_Config *config; 40 boolean is_valid; 41 unsigned int prop_id; 42 unsigned int meta_id; 43 } headmaker; 44 45 typedef struct 46 { 47 void *thing1; 48 void *thing2; 49 void *thing3; 50 } things; 51 52 static void read_metaname_aliases( 53 xmlChar *str, 54 headmaker * h, 55 swish_MetaName *meta 56 ); 57 static void read_metaname_attr( 58 const xmlChar *attr, 59 const xmlChar *attr_val, 60 swish_MetaName *meta, 61 headmaker * h 62 ); 63 static void read_metaname( 64 xmlTextReaderPtr reader, 65 &
