Changeset 2110
- Timestamp:
- 04/03/08 22:44:09 (1 month ago)
- Files:
-
- libswish3/trunk/src/libswish3/config.c (modified) (13 diffs)
- libswish3/trunk/src/libswish3/header.c (modified) (14 diffs)
- libswish3/trunk/src/libswish3/libswish3.h (modified) (6 diffs)
- libswish3/trunk/src/libswish3/metaname.c (modified) (1 diff)
- libswish3/trunk/src/libswish3/property.c (modified) (1 diff)
- libswish3/trunk/src/libswish3/string.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
libswish3/trunk/src/libswish3/config.c
r2108 r2110 138 138 } 139 139 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); 148 148 149 149 if (config->ref_cnt != 0) { … … 162 162 ) 163 163 { 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 178 170 return flags; 179 171 } 180 172 181 173 void 174 swish_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 } 182 185 183 186 /* init config object */ … … 204 207 config->ref_cnt = 0; 205 208 config->stash = NULL; 206 209 207 210 if (SWISH_DEBUG & SWISH_DEBUG_MEMORY) { 208 211 SWISH_DEBUG_MSG("config ptr 0x%x", (int)config); … … 220 223 swish_Property *tmpprop; 221 224 swish_MetaName *tmpmeta; 225 xmlChar *tmpbuf; 222 226 223 227 if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) … … 230 234 231 235 /* 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)); 246 238 tmpmeta->ref_cnt++; 247 239 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)); 250 247 tmpmeta->ref_cnt++; 251 248 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); 252 272 253 273 /* parsers */ … … 269 289 swish_xstrdup((xmlChar *)setlocale(LC_ALL, ""))); 270 290 271 /* properties */272 swish_hash_add(config->properties, (xmlChar *)SWISH_PROP_DESCRIPTION,273 swish_init_property(swish_xstrdup274 ((xmlChar *)SWISH_PROP_DESCRIPTION))275 );276 swish_hash_add(config->properties, (xmlChar *)SWISH_PROP_TITLE,277 swish_init_property(swish_xstrdup278 ((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 290 291 /* aliases: other names a tag might be known as, for matching properties and 291 292 * metanames */ … … 370 371 SWISH_DEBUG_MSG("ptr addr: 0x%x %d", (int)config, (int)config); 371 372 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"); 382 380 } 383 381 … … 390 388 { 391 389 swish_Property *prop1; 392 boolean in_hash;393 390 394 391 if (swish_hash_exists(props1, prop2name)) { 395 392 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 } 397 397 } 398 398 else { 399 399 prop1 = swish_init_property(swish_xstrdup(prop2name)); 400 400 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; 409 408 prop1->ignore_case = prop2->ignore_case; 410 409 prop1->type = prop2->type; … … 419 418 prop1->sort = prop2->sort; 420 419 421 if (!in_hash) {422 swish_hash_add(props1, prop1->name, prop1);423 }424 425 420 } 426 421 … … 431 426 ) 432 427 { 433 xmlHashScan(props2, (xmlHashScanner) copy_property, props1);428 xmlHashScan(props2, (xmlHashScanner)copy_property, props1); 434 429 } 435 430 … … 442 437 { 443 438 swish_MetaName *meta1; 444 boolean in_hash; 445 439 446 440 if (swish_hash_exists(metas1, meta2name)) { 447 441 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 } 449 446 } 450 447 else { 451 448 meta1 = swish_init_metaname(swish_xstrdup(meta2name)); 452 449 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. 456 457 meta1->id = meta2->id; 457 if (in_hash && meta1->name != NULL) {458 swish_xfree(meta1->name);459 meta1->name = swish_xstrdup(meta2->name);460 }461 458 meta1->bias = meta2->bias; 462 459 if (meta1->alias_for != NULL) { … … 467 464 } 468 465 469 if (!in_hash) {470 swish_hash_add(metas1, meta1->name, meta1);471 }472 466 } 473 467 … … 478 472 ) 479 473 { 480 xmlHashScan(metas2, (xmlHashScanner) copy_metaname, metas1);474 xmlHashScan(metas2, (xmlHashScanner)copy_metaname, metas1); 481 475 } 482 476 libswish3/trunk/src/libswish3/header.c
r2108 r2110 108 108 xmlChar *name 109 109 ); 110 static void test_meta_unique_ids(111 swish_MetaName *meta,112 swish_Config *c,113 xmlChar *name114 );115 static void test_prop_unique_ids(116 swish_Property *prop,117 swish_Config *c,118 xmlChar *name119 );120 110 static headmaker *init_headmaker( 121 111 ); … … 212 202 newmeta = swish_hash_fetch(h->config->metanames, newname); 213 203 } 204 /* else new metaname */ 214 205 else { 215 206 newmeta = swish_init_metaname(newname); … … 243 234 ) 244 235 { 236 swish_MetaName *dupe; 245 237 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); 247 239 } 248 240 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); 250 250 } 251 251 else if (xmlStrEqual(attr, (xmlChar *)"alias_for")) { … … 292 292 293 293 /* must have an id */ 294 if ( !meta->id) {294 if (meta->id == -1) { 295 295 meta->id = h->meta_id++; 296 296 } … … 364 364 ) 365 365 { 366 366 swish_Property *dupe; 367 367 368 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); 369 370 } 370 371 else if (xmlStrEqual(attr, (xmlChar *)"max")) { … … 372 373 } 373 374 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); 375 376 } 376 377 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); 378 379 } 379 380 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); 381 390 } 382 391 else if (xmlStrEqual(attr, (xmlChar *)"type")) { … … 434 443 } 435 444 436 if ( !prop->id) {445 if (prop->id == -1) { 437 446 prop->id = h->prop_id++; 438 447 } … … 754 763 } 755 764 756 static void757 test_meta_unique_ids(758 swish_MetaName *meta,759 swish_Config *c,760 xmlChar *name761 )762 {763 c->flags->meta_ids[meta->id]++;764 }765 766 static void767 test_prop_unique_ids(768 swish_Property *prop,769 swish_Config *c,770 xmlChar *name771 )772 {773 c->flags->prop_ids[prop->id]++;774 }775 776 void777 swish_config_test_unique_ids(778 swish_Config *c779 )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 again794 */795 c->flags->prop_ids[i] = 0;796 c->flags->meta_ids[i] = 0;797 }798 }799 765 800 766 static headmaker * … … 831 797 swish_config_test_alias_fors(h->config); 832 798 833 /* make sure ids are all unique */834 swish_config_test_unique_ids(h->config);835 836 799 swish_debug_config(h->config); 837 800 swish_free_config(h->config); … … 861 824 /* test that all the alias_for links resolve ok */ 862 825 swish_config_test_alias_fors(c); 863 864 /* make sure ids are all unique */865 swish_config_test_unique_ids(c);866 826 867 827 return 1; … … 930 890 { 931 891 int rc; 932 boolean is_alias;933 892 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 936 898 if (meta->alias_for != NULL) { 937 899 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 { 945 906 rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "bias", "%d", meta->bias); 946 907 if (rc < 0) { 947 908 SWISH_CROAK("Error writing metaname bias attribute for %s", name); 948 909 } 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 956 912 write_close_tag(writer); 957 913 } … … 984 940 { 985 941 int rc; 986 boolean is_alias;987 942 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 }997 943 rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "id", "%d", prop->id); 998 944 if (rc < 0) { … … 1000 946 } 1001 947 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 1002 956 /* all other attrs are irrelevant if this is an alias */ 1003 if (!is_alias) {1004 957 rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "ignore_case", "%d", 1005 958 prop->ignore_case); … … 1087 1040 things->thing3 = writer; 1088 1041 xmlHashScan(mimes, (xmlHashScanner)write_mime, things); 1089 swish_hash_free( things->thing1);1042 swish_hash_free(things->thing1); 1090 1043 swish_xfree(things); 1091 1044 } libswish3/trunk/src/libswish3/libswish3.h
r2108 r2110 41 41 42 42 #define SWISH_CONTRACTIONS 1 43 44 #define SWISH_MAX_IDS 102445 43 #define SWISH_SPECIAL_ARG 1 46 44 #define SWISH_MAX_SORT_STRING_LEN 100 … … 246 244 { 247 245 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; 251 248 }; 252 249 … … 275 272 { 276 273 int ref_cnt; 277 unsigned intid;274 int id; 278 275 xmlChar *name; 279 276 int bias; … … 284 281 { 285 282 int ref_cnt; 286 unsigned intid;283 int id; 287 284 xmlChar *name; 288 285 boolean ignore_case; … … 475 472 swish_StringList * swish_init_stringlist(); 476 473 void swish_free_stringlist(swish_StringList * sl); 474 int swish_string_to_int( char *buf ); 475 xmlChar * swish_int_to_string( int val ); 476 xmlChar * swish_long_to_string( long val ); 477 xmlChar * swish_double_to_string( double val ); 478 xmlChar * swish_date_to_string( int y, int m, int d ); 477 479 /* 478 480 =cut … … 493 495 xmlChar * swish_get_mime_type( swish_Config * config, xmlChar * fileext ); 494 496 xmlChar * swish_get_parser( swish_Config * config, xmlChar *mime ); 495 void swish_config_test_unique_ids( swish_Config *c );496 497 void swish_config_test_alias_fors( swish_Config *c ); 497 498 swish_ConfigFlags * swish_init_config_flags(); 498 499 void swish_free_config_flags( swish_ConfigFlags *flags ); 499 500 /* 500 501 =cut libswish3/trunk/src/libswish3/metaname.c
r2103 r2110 30 30 m = swish_xmalloc(sizeof(swish_MetaName)); 31 31 m->ref_cnt = 0; 32 m->id = 0;32 m->id = -1; 33 33 m->name = name; 34 34 m->bias = 0; libswish3/trunk/src/libswish3/property.c
r2103 r2110 30 30 p = swish_xmalloc(sizeof(swish_Property)); 31 31 p->ref_cnt = 0; 32 p->id = 0;32 p->id = -1; 33 33 p->name = name; 34 34 p->ignore_case = 1; libswish3/trunk/src/libswish3/string.c
r2103 r2110 54 54 ); 55 55 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 75 int swish_string_to_int( 76 char *buf 77 ) 78 { 79 return (int)strtol(buf, (char **)NULL, 10); 80 } 81 82 xmlChar * 83 swish_int_to_string( 84 int val 85 ) 86 { 87 CONVERT_TO_STRING("%d") 88 } 89 90 xmlChar * 91 swish_long_to_string( 92 long val 93 ) 94 { 95 CONVERT_TO_STRING("%ld") 96 } 97 98 xmlChar * 99 swish_double_to_string( 100 double val 101 ) 102 { 103 CONVERT_TO_STRING("%f") 104 } 105 106 xmlChar * 107 swish_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 ?? 140 inline uint32_t 141 binary_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 153 inline 154 std::string 155 int_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 56 165 /* returns length of a UTF8 character, based on first byte (see below) */ 57 166 int … … 121 230 else { 122 231 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); 125 233 126 234 enc = (xmlChar *)SWISH_DEFAULT_ENCODING; … … 141 249 if (SWISH_DEBUG) 142 250 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); 145 253 146 254 setlocale(LC_CTYPE, SWISH_LOCALE); … … 321 429 int i; 322 430 for (i = 0; widechars[i] != 0; i++) { 323 printf(" >%lc< %ld %#lx \n", (wint_t) widechars[i], 324 (long int)widechars[i], (longunsigned int)widechars[i]);431 printf(" >%lc< %ld %#lx \n", (wint_t) widechars[i], (long int)widechars[i], 432 (long unsigned int)widechars[i]); 325 433 } 326 434 } … … 451 559 if (cursize == maxsize) { 452 560 sl->word = 453 (xmlChar **)swish_xrealloc(sl->word, 454 (maxsize *= 2) * sizeof(xmlChar *)); 561 (xmlChar **)swish_xrealloc(sl->word, (maxsize *= 2) * sizeof(xmlChar *)); 455 562 } 456 563 … … 462 569 if (cursize == maxsize) { 463 570 sl->word = 464 (xmlChar **)swish_xrealloc(sl->word, 465 (maxsize += 1) * sizeof(xmlChar *)); 571 (xmlChar **)swish_xrealloc(sl->word, (maxsize += 1) * sizeof(xmlChar *)); 466 572 } 467 573
