Changeset 649 for trunk/gsdl/src/recpt/formattools.cpp
- Timestamp:
- 1999-10-10T21:14:12+13:00 (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/src/recpt/formattools.cpp
r636 r649 28 28 /* 29 29 $Log$ 30 Revision 1.12 1999/10/10 08:14:07 sjboddie 31 - metadata now returns mp rather than array 32 - redesigned browsing support (although it's not finished so 33 won't currently work ;-) 34 30 35 Revision 1.11 1999/09/28 20:38:19 rjmcnab 31 36 fixed a couple of bugs … … 73 78 74 79 // a few function prototypes 75 static text_t format_string ( constResultDocInfo_t &docinfo, format_t *formatlistptr,80 static text_t format_string (ResultDocInfo_t &docinfo, format_t *formatlistptr, 76 81 const text_t &link, const text_t &icon, const text_t &text); 77 82 78 83 static bool parse_action (text_t::const_iterator &here, const text_t::const_iterator &end, 79 format_t *formatlistptr, text_tarray &metadata, bool &getParents, 80 text_tmap &metamap, int &metacount); 84 format_t *formatlistptr, text_tset &metadata, bool &getParents); 81 85 82 86 void metadata_t::clear() { 83 87 metaname.clear(); 84 metaindex = 0;85 88 metacommand = mNone; 86 89 parentcommand = pNone; 87 parentindex = 0;88 90 parentoptions.clear(); 89 91 }; … … 120 122 DocumentButtons.push_back ("Expand Contents"); 121 123 DocumentText = "[Text]"; 124 formatstrings.erase (formatstrings.begin(), formatstrings.end()); 125 } 126 127 // returns false if key isn't in formatstringmap 128 bool get_formatstring (const text_t &key, const text_tmap &formatstringmap, 129 text_t &formatstring) { 130 131 formatstring.clear(); 132 text_tmap::const_iterator it = formatstringmap.find(key); 133 if (it == formatstringmap.end()) return false; 134 formatstring = (*it).second; 135 return true; 136 } 137 // tries to find "key1key2" then "key1" then "key2" 138 bool get_formatstring (const text_t &key1, const text_t &key2, 139 const text_tmap &formatstringmap, 140 text_t &formatstring) { 141 142 formatstring.clear(); 143 text_tmap::const_iterator it = formatstringmap.find(key1 + key2); 144 if (it != formatstringmap.end()) { 145 formatstring = (*it).second; 146 return true; 147 } 148 it = formatstringmap.find(key1); 149 if (it != formatstringmap.end()) { 150 formatstring = (*it).second; 151 return true; 152 } 153 it = formatstringmap.find(key2); 154 if (it != formatstringmap.end()) { 155 formatstring = (*it).second; 156 return true; 157 } 158 return false; 122 159 } 123 160 … … 152 189 static void get_parent_options (text_t &instring, metadata_t &metaoption) { 153 190 154 metaoption.clear();155 191 text_t meta, com, op; 156 192 bool inbraces = false; … … 175 211 else if (com == "Top") 176 212 metaoption.parentcommand = pTop; 177 else if (is_number(com)) { 178 metaoption.parentcommand = pIndex; 179 metaoption.metaindex = com.getint(); 180 } else if (com == "All") { 213 else if (com == "All") { 181 214 metaoption.parentcommand = pAll; 182 215 metaoption.parentoptions = op; … … 184 217 } 185 218 186 static bool parse_meta (text_t &meta, int &count, decision_t &decision, 187 text_tarray &metadata, bool &getParents, text_tmap &metamap) { 219 static void parse_meta (text_t &meta, metadata_t &metaoption, 220 text_tset &metadata, bool &getParents) { 221 222 if (meta.size() > 8 && (substr(meta.begin(), meta.begin()+8) == "cgisafe:")) { 223 metaoption.metacommand = mCgiSafe; 224 meta = substr (meta.begin()+8, meta.end()); 225 } 188 226 189 227 if (meta.size() > 7 && (substr (meta.begin(), meta.begin()+6) == "parent")) { 190 228 getParents = true; 191 metadata_t metaoption;192 229 get_parent_options (meta, metaoption); 193 decision.meta = metaoption; 194 } 195 text_tmap::const_iterator it; 196 if ((it = metamap.find(meta)) != metamap.end()) { 197 decision.meta.metaindex = (*it).second.getint(); 198 } else { 199 metamap[meta] = count; 200 metadata.push_back (meta); 201 decision.meta.metaindex = count; 202 count ++; 203 } 204 return true; 205 } 206 207 static bool parse_meta (text_t &meta, int &count, format_t *formatlistptr, 208 text_tarray &metadata, bool &getParents, text_tmap &metamap) { 230 } 231 232 metadata.insert (meta); 233 metaoption.metaname = meta; 234 } 235 236 static void parse_meta (text_t &meta, format_t *formatlistptr, 237 text_tset &metadata, bool &getParents) { 209 238 210 239 if (meta == "link") … … 224 253 else { 225 254 formatlistptr->command = comMeta; 226 227 if (meta.size() > 8 && (substr(meta.begin(), meta.begin()+8) == "cgisafe:")) { 228 formatlistptr->meta.metacommand = mCgiSafe; 229 meta = substr (meta.begin()+8, meta.end()); 230 } 231 232 if (meta.size() > 7 && (substr (meta.begin(), meta.begin()+6) == "parent")) { 233 getParents = true; 234 metadata_t metaoption; 235 get_parent_options (meta, metaoption); 236 formatlistptr->meta = metaoption; 237 } 238 239 text_tmap::const_iterator it; 240 if ((it = metamap.find(meta)) != metamap.end()) { 241 formatlistptr->meta.metaindex = (*it).second.getint(); 242 } else { 243 metamap[meta] = count; 244 metadata.push_back (meta); 245 formatlistptr->meta.metaindex = count; 246 count ++; 247 } 248 formatlistptr->meta.metaname = meta; 249 } 250 return true; 255 parse_meta (meta, formatlistptr->meta, metadata, getParents); 256 } 251 257 } 252 258 253 259 static bool parse_string (const text_t &formatstring, format_t *formatlistptr, 254 text_tarray &metadata, bool &getParents, 255 text_tmap &metamap, int &metacount) { 260 text_tset &metadata, bool &getParents) { 256 261 257 262 text_t text; … … 273 278 text.clear(); 274 279 } 275 if (parse_action (++here, end, formatlistptr, metadata, 276 getParents, metamap, metacount)) { 280 if (parse_action (++here, end, formatlistptr, metadata, getParents)) { 277 281 formatlistptr->nextptr = new format_t(); 278 282 formatlistptr = formatlistptr->nextptr; … … 295 299 here ++; 296 300 } 297 if (parse_meta (meta, metacount, formatlistptr, metadata, getParents, metamap)) { 298 formatlistptr->nextptr = new format_t(); 299 formatlistptr = formatlistptr->nextptr; 300 } 301 parse_meta (meta, formatlistptr, metadata, getParents); 302 formatlistptr->nextptr = new format_t(); 303 formatlistptr = formatlistptr->nextptr; 301 304 302 305 } else … … 317 320 318 321 static bool parse_action (text_t::const_iterator &here, const text_t::const_iterator &end, 319 format_t *formatlistptr, text_tarray &metadata, bool &getParents, 320 text_tmap &metamap, int &metacount) { 322 format_t *formatlistptr, text_tset &metadata, bool &getParents) { 321 323 322 324 text_t::const_iterator it = findchar (here, end, '}'); … … 371 373 // it's metadata 372 374 text_t meta = substr (beginbracket+1, endbracket); 373 parse_meta (meta, metacount, or_ptr, metadata, getParents, metamap);375 parse_meta (meta, or_ptr, metadata, getParents); 374 376 375 377 } else { … … 390 392 if ((*beginbracket == '[') && (*endbracket == ']')) { 391 393 text_t meta = substr (beginbracket+1, endbracket); 392 decision_t decision; 393 parse_meta (meta, metacount, formatlistptr->decision, 394 metadata, getParents, metamap); 394 parse_meta (meta, formatlistptr->decision.meta, metadata, getParents); 395 395 commacount ++; 396 396 text.clear(); … … 399 399 } else if (commacount == 1) { 400 400 formatlistptr->ifptr = new format_t(); 401 parse_string (text, formatlistptr->ifptr, metadata, 402 getParents, metamap, metacount); 401 parse_string (text, formatlistptr->ifptr, metadata, getParents); 403 402 commacount ++; 404 403 text.clear(); … … 406 405 } else if (commacount == 2) { 407 406 formatlistptr->elseptr = new format_t(); 408 parse_string (text, formatlistptr->elseptr, metadata, 409 getParents, metamap, metacount); 407 parse_string (text, formatlistptr->elseptr, metadata, getParents); 410 408 commacount ++; 411 409 text.clear(); … … 424 422 425 423 bool parse_formatstring (const text_t &formatstring, format_t *formatlistptr, 426 text_t array&metadata, bool &getParents) {424 text_tset &metadata, bool &getParents) { 427 425 428 426 formatlistptr->clear(); 429 metadata.erase (metadata.begin(), metadata.end());430 427 getParents = false; 431 428 432 text_tmap metamap; 433 int metacount = 0; 434 return (parse_string (formatstring, formatlistptr, metadata, 435 getParents, metamap, metacount)); 429 return (parse_string (formatstring, formatlistptr, metadata, getParents)); 436 430 } 437 431 … … 440 434 // be of the form yyyymmdd, this is of course, crap ;) 441 435 442 static text_t get_meta (const ResultDocInfo_t &docinfo, const metadata_t &meta) { 443 int metasize = docinfo.metadata.size(); 444 int mindex = meta.metaindex; 445 if (metasize < 1 || metasize <= mindex) return ""; 446 int valuesize = docinfo.metadata[mindex].values.size(); 436 static text_t get_meta (ResultDocInfo_t &docinfo, const metadata_t &meta) { 437 438 // make sure we have the requested metadata 439 MetadataInfo_tmap::iterator it = docinfo.metadata.find (meta.metaname); 440 if (it == docinfo.metadata.end()) return ""; 441 442 MetadataInfo_t *parent = docinfo.metadata[meta.metaname].parent; 447 443 448 444 switch (meta.parentcommand) { 449 445 case pNone: 450 446 if (meta.metaname == "Date") 451 return format_date (docinfo.metadata[m index].values.back());447 return format_date (docinfo.metadata[meta.metaname].values[0]); 452 448 if (meta.metacommand == mCgiSafe) 453 return cgi_safe (docinfo.metadata[m index].values.back());454 else return docinfo.metadata[m index].values.back();449 return cgi_safe (docinfo.metadata[meta.metaname].values[0]); 450 else return docinfo.metadata[meta.metaname].values[0]; 455 451 456 452 case pImmediate: 457 if ( valuesize > 1) {453 if (parent != NULL) { 458 454 if (meta.metaname == "Date") 459 return format_date ( docinfo.metadata[mindex].values[metasize-2]);460 if (meta.metacommand == mCgiSafe)461 return cgi_safe (docinfo.metadata[mindex].values[metasize-2]);462 else return docinfo.metadata[mindex].values[metasize-2];455 return format_date (parent->values[0]); 456 if (meta.metacommand == mCgiSafe) 457 return cgi_safe (parent->values[0]); 458 else return parent->values[0]; 463 459 } 464 460 break; 465 461 466 462 case pTop: 467 if (valuesize > 1) { 463 if (parent != NULL) { 464 while (parent->parent != NULL) parent = parent->parent; 465 468 466 if (meta.metaname == "Date") 469 return format_date ( docinfo.metadata[mindex].values[0]);470 if (meta.metacommand == mCgiSafe)471 return cgi_safe (docinfo.metadata[mindex].values[0]);472 else return docinfo.metadata[mindex].values[0];467 return format_date (parent->values[0]); 468 if (meta.metacommand == mCgiSafe) 469 return cgi_safe (parent->values[0]); 470 else return parent->values[0]; 473 471 } 474 472 break; 475 473 476 case pIndex:477 if (valuesize > meta.parentindex) {478 if (meta.metaname == "Date")479 return format_date (docinfo.metadata[mindex].values[meta.parentindex]);480 if (meta.metacommand == mCgiSafe)481 return cgi_safe (docinfo.metadata[mindex].values[meta.parentindex]);482 else return docinfo.metadata[mindex].values[meta.parentindex];483 }484 break;485 486 474 case pAll: 487 bool first = true; 488 text_t tmp; 489 if (valuesize > 1) { 490 text_tarray::const_iterator here = docinfo.metadata[mindex].values.begin(); 491 // don't want last value as that's the value of the current level (i.e. it's 492 // not a parent 493 text_tarray::const_iterator end = docinfo.metadata[mindex].values.end() - 1; 475 MetadataInfo_t *parent = docinfo.metadata[meta.metaname].parent; 476 if (parent != NULL) { 477 text_tarray tmparray; 478 while (parent != NULL) { 479 tmparray.push_back (parent->values[0]); 480 parent = parent->parent; 481 } 482 bool first = true; 483 text_t tmp; 484 text_tarray::reverse_iterator here = tmparray.rbegin(); 485 text_tarray::reverse_iterator end = tmparray.rend(); 494 486 while (here != end) { 495 487 if (!first) tmp += meta.parentoptions; … … 499 491 here ++; 500 492 } 493 if (meta.metacommand == mCgiSafe) return cgi_safe (tmp); 494 else return tmp; 501 495 } 502 if (meta.metacommand == mCgiSafe) return cgi_safe (tmp);503 else return tmp;504 496 } 505 497 return ""; 506 498 } 507 499 508 static text_t get_or ( constResultDocInfo_t &docinfo, format_t *orptr,500 static text_t get_or (ResultDocInfo_t &docinfo, format_t *orptr, 509 501 const text_t &link, const text_t &icon, const text_t &text) { 510 502 … … 520 512 } 521 513 522 static text_t get_if ( constResultDocInfo_t &docinfo, const decision_t &decision,514 static text_t get_if (ResultDocInfo_t &docinfo, const decision_t &decision, 523 515 format_t *ifptr, format_t *elseptr, const text_t &link, 524 516 const text_t &icon, const text_t &text) { … … 538 530 } 539 531 540 text_t format_string ( constResultDocInfo_t &docinfo, format_t *formatlistptr,532 text_t format_string (ResultDocInfo_t &docinfo, format_t *formatlistptr, 541 533 const text_t &link, const text_t &icon, const text_t &text) { 542 534 … … 569 561 570 562 571 text_t get_formatted_string ( constResultDocInfo_t &docinfo, format_t *formatlistptr,563 text_t get_formatted_string (ResultDocInfo_t &docinfo, format_t *formatlistptr, 572 564 const text_t &link, const text_t &icon) { 573 565 … … 583 575 584 576 585 text_t get_formatted_string ( constResultDocInfo_t &docinfo, format_t *formatlistptr) {577 text_t get_formatted_string (ResultDocInfo_t &docinfo, format_t *formatlistptr) { 586 578 587 579 text_t link = "<a href=\"_httpdocument_&cl=search&d=" + docinfo.OID + "\">"; … … 598 590 599 591 600 text_t get_formatted_string ( constResultDocInfo_t &docinfo, format_t *formatlistptr,592 text_t get_formatted_string (ResultDocInfo_t &docinfo, format_t *formatlistptr, 601 593 const text_t &text) { 602 594 … … 613 605 614 606 615 text_t get_formatted_string ( constResultDocInfo_t &docinfo, format_t *formatlistptr,607 text_t get_formatted_string (ResultDocInfo_t &docinfo, format_t *formatlistptr, 616 608 const text_t &link, const text_t &icon, const text_t &text) { 617 609
Note:
See TracChangeset
for help on using the changeset viewer.