Changeset 12453 for trunk/psLib
- Timestamp:
- Mar 15, 2007, 2:07:35 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/types/psMetadataConfig.c (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/types/psMetadataConfig.c
r12441 r12453 9 9 * @author Ross Harman, MHPCC 10 10 * @author Eric Van Alst, MHPCC 11 * @author Joshua Hoblitt, University of Hawaii 2006-2007 11 12 * 12 * @version $Revision: 1.13 1$ $Name: not supported by cvs2svn $13 * @date $Date: 2007-03-1 5 02:19:09$13 * @version $Revision: 1.132 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2007-03-16 00:07:35 $ 14 15 * 15 16 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 64 65 /*****************************************************************************/ 65 66 66 static psMetadata* ge tMetadataType(char *linePtr);67 static psMetadata* setMetadataItem(psMetadata* template, char* linePtr)67 static psMetadata* genTypeTemplate(char *linePtr); 68 static psMetadata* parseTypeValues(psMetadata* template, char* linePtr) 68 69 ; 69 70 static bool parseLine(psArray* levelArray, … … 93 94 typedef struct 94 95 { 95 psArray* nonUniqueKeyArray; ///< non-unique key names 96 psArray* typeArray; ///< array of user defined types 97 psArray* templateArray; ///< array of user type templates 98 psMetadata* metadata; ///< metadata container 96 psArray* nonUniqueKeyArray; ///< non-unique key names 97 psHash* typeTemplates; ///< hash of user type templates 98 psMetadata* metadata; ///< metadata container 99 99 } 100 100 p_psParseLevelInfo; … … 103 103 { 104 104 psFree(info->nonUniqueKeyArray); 105 psFree(info->typeArray); 106 psFree(info->templateArray); 105 psFree(info->typeTemplates); 107 106 psFree(info->metadata); 108 107 } … … 115 114 116 115 info->nonUniqueKeyArray = psArrayAllocEmpty(INITIAL_LENGTH); 117 info->typeArray = psArrayAllocEmpty(INITIAL_LENGTH); 118 info->templateArray = psArrayAllocEmpty(INITIAL_LENGTH); 116 info->typeTemplates = psHashAlloc(10); 119 117 info->metadata = NULL; 120 118 … … 553 551 } 554 552 555 static psMetadata* ge tMetadataType(char* linePtr)553 static psMetadata* genTypeTemplate(char* linePtr) 556 554 { 557 555 psMetadata* metadataTemplate = NULL; … … 561 559 562 560 // Loop through line and generate metadata items for each token found 563 while ((token = getToken(&linePtr, " ", &status, false)) != NULL) {561 while ((token = getToken(&linePtr, " ", &status, false)) != NULL) { 564 562 565 563 // If not allocated then allocate new metadata … … 570 568 // Look for comment indicator # 571 569 if (strstr(token, "#") != 0) { 570 psFree(metadataTemplate); 572 571 psFree(token); 573 572 return NULL; … … 581 580 return NULL; 582 581 } 582 psFree(token); 583 583 584 584 // Add item to template … … 586 586 psFree(metadataTemplate); 587 587 psFree(tempItem); 588 psFree(token);589 588 return NULL; 590 589 } 591 592 590 psFree(tempItem); 593 psFree(token);594 591 } 595 592 … … 597 594 } 598 595 599 static psMetadata* setMetadataItem(psMetadata* template, 596 597 static psMetadata* parseTypeValues(psMetadata* template, 600 598 char* linePtr) 601 599 { 602 600 psMetadata* md = NULL; 603 psS32 items = 0;604 601 char* token = NULL; 605 602 psS32 status = 0; … … 608 605 psListIterator* iter = NULL; 609 606 607 // Allocate metadata to return 608 md = psMetadataAlloc(); 609 610 610 // Determine the number of items in template 611 items = template->list->n; 612 if(items > 0 ) { 613 // Allocate metadata 614 md = psMetadataAlloc() 615 ; 611 long items = psListLength(template->list); 612 613 if (items > 0 ) { 616 614 // Point to first item in template 617 iter = psListIteratorAlloc(template-> 618 list, PS_LIST_HEAD, true); 615 iter = psListIteratorAlloc(template->list, PS_LIST_HEAD, true); 619 616 // For each item in template parse line string for values 620 for(psS32 i = 0; 621 i < items; 622 i++) { 617 for (long i = 0; i < items; i++) { 623 618 // Get template item 624 templateItem = psListGetAndIncrement(iter) 625 ; 626 if(templateItem == NULL) { 619 templateItem = psListGetAndIncrement(iter); 620 if (templateItem == NULL) { 627 621 psFree(md); 628 622 psFree(iter); … … 630 624 break; 631 625 } 626 632 627 // Get the next token on the line 633 628 token = getToken(&linePtr, " ", &status, false); 634 if (token != NULL) {629 if (token != NULL) { 635 630 // Allocate metadata item 636 631 mdItem = psMetadataItemAllocStr(templateItem->name, 637 632 templateItem->comment, token); 638 if (mdItem == NULL) {633 if (mdItem == NULL) { 639 634 psFree(md); 640 635 md = NULL; … … 643 638 break; 644 639 } 640 psFree(token); 645 641 646 642 // Add item to metadata 647 if (!psMetadataAddItem(md, mdItem, PS_LIST_TAIL, PS_META_DEFAULT)) {643 if (!psMetadataAddItem(md, mdItem, PS_LIST_TAIL, PS_META_DEFAULT)) { 648 644 psFree(md); 649 645 md = NULL; 650 646 psFree(mdItem); 651 psFree(token);652 647 psFree(iter); 653 648 break; … … 661 656 break; 662 657 } 663 664 psFree(token); 665 } 666 } 658 } 659 } 660 667 661 return md; 668 662 } … … 688 682 char* tempStr = NULL; 689 683 psArray* nonUniqueKeys = NULL; 690 bool typeFound = false;691 psArray* typeArray = NULL;692 psArray* templateArray = NULL;693 684 psMetadata* tempMeta = NULL; 694 685 p_psParseLevelInfo* nextLevelInfo = NULL; … … 773 764 } else { 774 765 // Search through user types 775 typeArray = ((p_psParseLevelInfo*)(levelArray->data[level]))->typeArray; 776 templateArray = ((p_psParseLevelInfo*)(levelArray->data[level]))->templateArray; 777 for(psS32 k = 0; k < typeArray->n; k++) { 778 if(strcmp(strType,(char*)typeArray->data[k]) == 0) { 779 tempMeta = setMetadataItem((psMetadata*)templateArray->data[k],linePtr); 780 if(tempMeta != NULL) { 781 // Add metadata item 782 md = ((p_psParseLevelInfo*)(levelArray->data[level]))->metadata; 783 addStatus = psMetadataAdd(md,PS_LIST_TAIL,keyName, 784 PS_DATA_METADATA | flags,"",tempMeta); 785 // Check for add failure 786 if (! addStatus) { 787 psError(PS_ERR_IO, true, 788 _("Duplicate Metadata item, %s, found. " 789 "Overwrite not allowed."), 790 keyName); 791 psFree(strType); 792 psFree(tempMeta); 793 return false; 794 } 795 psFree(tempMeta); 796 } else { 797 // Metadata type read error 798 psError(PS_ERR_IO,true, 799 _("Failed to read a metadata %s."), keyName); 800 psFree(strType); 801 return false; 802 } 803 typeFound = true; 804 break; 805 } 806 } 807 if(!typeFound) { 766 // Check if type already exists in typeTempaltes 767 psHash *typeTemplates = ((p_psParseLevelInfo*)(levelArray->data[level]))->typeTemplates; 768 769 psMetadata *template = psHashLookup(typeTemplates, strType); 770 if (!template) { 808 771 psError(PS_ERR_IO, true, 809 _("Metadata type'%s' is invalid."), strType);772 _("Metadata TYPE '%s' is invalid."), strType); 810 773 psFree(strType); 811 774 return false; 812 } else { 775 } 776 777 // covert the template, and the rest of the line, into a metadata 778 tempMeta = parseTypeValues(template, linePtr); 779 if (!tempMeta) { 780 // Metadata type read error 781 psError(PS_ERR_IO,true, 782 _("Failed to read Metadata TYPE %s."), keyName); 813 783 psFree(strType); 814 return true; 784 return false; 785 } 786 787 // get the current level's metadata 788 md = ((p_psParseLevelInfo*)(levelArray->data[level]))->metadata; 789 790 // add the parsed TYPE to it 791 addStatus = psMetadataAdd(md,PS_LIST_TAIL,keyName, 792 PS_DATA_METADATA | flags,"",tempMeta); 793 psFree(tempMeta); 794 795 // Check for add failure 796 if (! addStatus) { 797 psError(PS_ERR_IO, true, 798 _("Duplicate Metadata item, %s, found. " 799 "Overwrite not allowed."), keyName); 800 psFree(strType); 801 return false; 815 802 } 816 803 } … … 845 832 psFree(strValue); 846 833 psFree(strComment); 834 return false; 847 835 } 848 836 } … … 1211 1199 } 1212 1200 1201 // Access typeTypes for this level/scope 1202 psHash *typeTemplates = ((p_psParseLevelInfo*)(levelArray->data[level]))->typeTemplates; 1203 1204 // Check if type already exists in typeTempaltes 1205 if (psHashLookup(typeTemplates, strType)) { 1206 psError(PS_ERR_IO, true, 1207 _("Specified type %s is already defined."), strType); 1208 psFree(strType); 1209 return false; 1210 } 1211 1213 1212 // attempt to parse the TYPE line into a template metadata 1214 psMetadata *tempTemplate = ge tMetadataType(linePtr);1213 psMetadata *tempTemplate = genTypeTemplate(linePtr); 1215 1214 if (!tempTemplate) { 1216 psError(PS_ERR_IO, true, _("Metadata type '%s' is invalid."), strType);1215 psError(PS_ERR_IO, true, _("Metadata type '%s' is invalid."), strType); 1217 1216 psFree(strType); 1218 1217 return false; 1219 1218 } 1220 1219 1221 // Access type array1222 psArray *typeArray = ((p_psParseLevelInfo*)(levelArray->data[level]))->typeArray;1223 1224 // Check if type already exists in array1225 for (psS32 k = 0; k < psArrayLength(typeArray); k++) {1226 // Compare type name with the list of current types1227 if (strcmp(strType, (char*)typeArray->data[k]) == 0) {1228 psError(PS_ERR_IO,true,1229 _("Specified type %s is already defined."), strType);1230 psFree(tempTemplate);1231 psFree(strType);1232 return false;1233 }1234 }1235 1236 1220 // Add key name to array of type 1237 typeArray = psArrayAdd(typeArray, 0, strType); 1221 // Add template to hash of templates 1222 if (!psHashAdd(typeTemplates, strType, tempTemplate)) { 1223 psError(PS_ERR_UNKNOWN, false, _("failed to add template for '%s' to hash"), strType); 1224 psFree(tempTemplate); 1225 psFree(strType); 1226 return false; 1227 } 1228 1229 psFree(tempTemplate); 1238 1230 psFree(strType); 1239 1240 // Add template to array of templates1241 psArray *templateArray = ((p_psParseLevelInfo*)(levelArray->data[level]))->templateArray;1242 psArrayAdd(templateArray, 0, tempTemplate);1243 psFree(tempTemplate);1244 1231 1245 1232 return true;
Note:
See TracChangeset
for help on using the changeset viewer.
