Changeset 12441
- Timestamp:
- Mar 14, 2007, 4:19:09 PM (19 years ago)
- Location:
- trunk/psLib
- Files:
-
- 4 edited
-
src/types/psMetadataConfig.c (modified) (40 diffs)
-
test/types/metaconf.in (modified) (4 diffs)
-
test/types/table3.dat (modified) (1 diff)
-
test/types/tap_psMetadataConfig_input.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/types/psMetadataConfig.c
r12435 r12441 10 10 * @author Eric Van Alst, MHPCC 11 11 * 12 * @version $Revision: 1.13 0$ $Name: not supported by cvs2svn $13 * @date $Date: 2007-03-1 4 02:37:34$12 * @version $Revision: 1.131 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2007-03-15 02:19:09 $ 14 14 * 15 15 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 67 67 static psMetadata* setMetadataItem(psMetadata* template, char* linePtr) 68 68 ; 69 static bool parseLine(psArray* levelArray, char* linePtr, 70 psS32 lineCount, bool overwrite); 69 static bool parseLine(psArray* levelArray, 70 char* linePtr, 71 bool overwrite, 72 bool *notBlank); 71 73 static bool parseMetadataItem(char* keyName, psArray* levelArray, 72 char* linePtr, ps S32 lineCount, psMetadataFlags flags);74 char* linePtr, psMetadataFlags flags); 73 75 static psString formatMetadataItem(psMetadataItem *item); 74 76 static psArray *p_psMetadataKeyArray(psMetadata *md); … … 76 78 psArray* levelArray, 77 79 char* linePtr, 78 psS32 lineCount,79 80 psMetadataFlags flags); 80 81 static bool parseType(char* keyName, 81 82 psArray* levelArray, 82 83 char* linePtr, 83 psS32 lineCount,84 84 psMetadataFlags flags); 85 85 static bool parseMetadataEnd(char* keyName, 86 86 psArray* levelArray, 87 87 char* linePtr, 88 psS32 lineCount,89 88 psMetadataFlags flags); 90 89 … … 672 671 psArray* levelArray, 673 672 char* linePtr, 674 psS32 lineCount,675 673 psMetadataFlags flags) 676 674 { … … 679 677 psDataType mdType = PS_DATA_UNKNOWN; 680 678 psElemType vectorType = PS_TYPE_S8; 681 char* strType = NULL;682 679 char* strValue = NULL; 683 680 char* strComment = NULL; … … 699 696 psTimeType timeType = PS_TIME_TAI; 700 697 698 long level = psArrayLength(levelArray) - 1; 699 701 700 // Get the metadata item type 702 strType = getToken(&linePtr, " ", &status,true); 703 704 long level = psArrayLength(levelArray) - 1; 701 char *strType = getToken(&linePtr, " ", &status,true); 705 702 706 703 // Check for no type 707 if(strType==NULL) { 708 psError(PS_ERR_IO, true, 709 _("Failed to read a metadata %s on line %u."), "type",lineCount); 710 returnValue = false; 704 if (strType == NULL) { 705 psError(PS_ERR_IO, true, _("Failed to read a metadata type.")); 706 return false; 707 } 708 709 // Set metadata type based on type token 710 // Check if the keyName specifies a vector and if so use strType token to 711 // find vector type 712 if (*keyName == '@') { 713 mdType = PS_DATA_VECTOR; 714 // Get the type of vector 715 if(!strncmp(strType, "U8", 2)) { 716 vectorType = PS_TYPE_U8; 717 } else if (!strncmp(strType,"U16",3)) { 718 vectorType = PS_TYPE_U16; 719 } else if (!strncmp(strType,"U32",3)) { 720 vectorType = PS_TYPE_U32; 721 } else if (!strncmp(strType,"U64",3)) { 722 vectorType = PS_TYPE_U64; 723 } else if (!strncmp(strType,"S8",2)) { 724 vectorType = PS_TYPE_S8; 725 } else if (!strncmp(strType,"S16",3)) { 726 vectorType = PS_TYPE_S16; 727 } else if (!strncmp(strType,"S32",3)) { 728 vectorType = PS_TYPE_S32; 729 } else if (!strncmp(strType,"S64",3)) { 730 vectorType = PS_TYPE_S64; 731 } else if (!strncmp(strType,"F32",3)) { 732 vectorType = PS_TYPE_F32; 733 } else if (!strncmp(strType,"F64",3)) { 734 vectorType = PS_TYPE_F64; 735 } else { 736 psError(PS_ERR_IO, true, 737 _("Failed to parse the value '%s' of metadata item %s, type %s, "), 738 "", keyName, strType); 739 psFree(strType); 740 return false; 741 } 742 } else if(!strncmp(strType, "STR", 3)) { 743 mdType = PS_DATA_STRING; 744 } else if(!strncmp(strType, "BOOL", 4)) { 745 mdType = PS_DATA_BOOL; 746 } else if(!strncmp(strType, "S8", 2)) { 747 mdType = PS_DATA_S8; 748 } else if(!strncmp(strType, "S16", 3)) { 749 mdType = PS_DATA_S16; 750 } else if(!strncmp(strType, "S32", 3)) { 751 mdType = PS_DATA_S32; 752 } else if(!strncmp(strType, "S64", 3)) { 753 mdType = PS_DATA_S64; 754 } else if(!strncmp(strType, "U8", 2)) { 755 mdType = PS_DATA_U8; 756 } else if(!strncmp(strType, "U16", 3)) { 757 mdType = PS_DATA_U16; 758 } else if(!strncmp(strType, "U32", 3)) { 759 mdType = PS_DATA_U32; 760 } else if(!strncmp(strType, "U64", 3)) { 761 mdType = PS_DATA_U64; 762 } else if(!strncmp(strType, "F32", 3)) { 763 mdType = PS_DATA_F32; 764 } else if(!strncmp(strType, "F64", 3)) { 765 mdType = PS_DATA_F64; 766 } else if(!strncmp(strType, "MULTI", 5)) { 767 mdType = PS_DATA_METADATA_MULTI; 768 } else if(!strncmp(strType, "METADATA", 8)) { 769 mdType = PS_DATA_METADATA; 770 } else if( !strncmp(strType, "UTC", 3) || !strncmp(strType, "TAI", 3) 771 || !strncmp(strType, "UT1", 3) || !strncmp(strType, "TT", 3)) { 772 mdType = PS_DATA_TIME; 711 773 } else { 712 713 // Set metadata type based on type token 714 715 // Check if the keyName specifies a vector and if so use strType token to find vector type 716 if(*keyName == '@') { 717 mdType = PS_DATA_VECTOR; 718 // Get the type of vector 719 if(!strncmp(strType, "U8", 2)) { 720 vectorType = PS_TYPE_U8; 721 } else if (!strncmp(strType,"U16",3)) { 722 vectorType = PS_TYPE_U16; 723 } else if (!strncmp(strType,"U32",3)) { 724 vectorType = PS_TYPE_U32; 725 } else if (!strncmp(strType,"U64",3)) { 726 vectorType = PS_TYPE_U64; 727 } else if (!strncmp(strType,"S8",2)) { 728 vectorType = PS_TYPE_S8; 729 } else if (!strncmp(strType,"S16",3)) { 730 vectorType = PS_TYPE_S16; 731 } else if (!strncmp(strType,"S32",3)) { 732 vectorType = PS_TYPE_S32; 733 } else if (!strncmp(strType,"S64",3)) { 734 vectorType = PS_TYPE_S64; 735 } else if (!strncmp(strType,"F32",3)) { 736 vectorType = PS_TYPE_F32; 737 } else if (!strncmp(strType,"F64",3)) { 738 vectorType = PS_TYPE_F64; 739 } else { 740 psError(PS_ERR_IO, true, 741 _("Failed to parse the value '%s' of metadata item %s, type %s, " 742 "on line %u."), "", keyName, strType, lineCount); 743 psFree(strType); 744 return false; 745 } 746 } else if(!strncmp(strType, "STR", 3)) { 747 mdType = PS_DATA_STRING; 748 } else if(!strncmp(strType, "BOOL", 4)) { 749 mdType = PS_DATA_BOOL; 750 } else if(!strncmp(strType, "S8", 2)) { 751 mdType = PS_DATA_S8; 752 } else if(!strncmp(strType, "S16", 3)) { 753 mdType = PS_DATA_S16; 754 } else if(!strncmp(strType, "S32", 3)) { 755 mdType = PS_DATA_S32; 756 } else if(!strncmp(strType, "S64", 3)) { 757 mdType = PS_DATA_S64; 758 } else if(!strncmp(strType, "U8", 2)) { 759 mdType = PS_DATA_U8; 760 } else if(!strncmp(strType, "U16", 3)) { 761 mdType = PS_DATA_U16; 762 } else if(!strncmp(strType, "U32", 3)) { 763 mdType = PS_DATA_U32; 764 } else if(!strncmp(strType, "U64", 3)) { 765 mdType = PS_DATA_U64; 766 } else if(!strncmp(strType, "F32", 3)) { 767 mdType = PS_DATA_F32; 768 } else if(!strncmp(strType, "F64", 3)) { 769 mdType = PS_DATA_F64; 770 } else if(!strncmp(strType, "MULTI", 5)) { 771 mdType = PS_DATA_METADATA_MULTI; 772 } else if(!strncmp(strType, "METADATA", 8)) { 773 mdType = PS_DATA_METADATA; 774 } else if( !strncmp(strType, "UTC", 3) || !strncmp(strType, "TAI", 3) 775 || !strncmp(strType, "UT1", 3) || !strncmp(strType, "TT", 3)) { 776 mdType = PS_DATA_TIME; 777 } else { 778 // Search through user types 779 typeArray = ((p_psParseLevelInfo*)(levelArray->data[level]))->typeArray; 780 templateArray = ((p_psParseLevelInfo*)(levelArray->data[level]))->templateArray; 781 for(psS32 k = 0; k < typeArray->n; k++) { 782 if(strcmp(strType,(char*)typeArray->data[k]) == 0) { 783 tempMeta = setMetadataItem((psMetadata*)templateArray->data[k],linePtr); 784 if(tempMeta != NULL) { 785 // Add metadata item 786 md = ((p_psParseLevelInfo*)(levelArray->data[level]))->metadata; 787 addStatus = psMetadataAdd(md,PS_LIST_TAIL,keyName, 788 PS_DATA_METADATA | flags,"",tempMeta); 789 // Check for add failure 790 if (! addStatus) { 791 psError(PS_ERR_IO, true, 792 _("Duplicate Metadata item, %s, found on line %u. " 793 "Overwrite not allowed."), 794 keyName, lineCount); 795 psFree(strType); 796 psFree(tempMeta); 797 return false; 798 } 774 // 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); 799 792 psFree(tempMeta); 800 } else {801 // Metadata type read error802 psError(PS_ERR_IO,true,803 _("Failed to read a metadata %s on line %u."),804 keyName, lineCount);805 psFree(strType);806 793 return false; 807 794 } 808 typeFound = true; 809 break; 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; 810 802 } 811 } 812 if(!typeFound) { 813 psError(PS_ERR_IO, true, 814 _("Metadata type '%s', found on line %u, is invalid."), 815 strType, lineCount); 816 psFree(strType); 817 return false; 818 } else { 819 psFree(strType); 820 return true; 821 } 803 typeFound = true; 804 break; 805 } 806 } 807 if(!typeFound) { 808 psError(PS_ERR_IO, true, 809 _("Metadata type '%s' is invalid."), strType); 810 psFree(strType); 811 return false; 812 } else { 813 psFree(strType); 814 return true; 822 815 } 823 816 } … … 830 823 831 824 if(status) { 832 psError(PS_ERR_IO, true, 833 _("Failed to read a metadata %s on line %u."), "value", lineCount); 825 psError(PS_ERR_IO, true, _("Failed to read a metadata value.")); 834 826 psFree(strType); 835 827 psFree(strValue); … … 838 830 839 831 if(strValue==NULL) { 840 psError(PS_ERR_IO, true, 841 _("Failed to read a metadata %s on line %u."), "value", lineCount); 832 psError(PS_ERR_IO, true, _("Failed to read a metadata value.")); 842 833 psFree(strType); 843 834 psFree(strValue); … … 850 841 strComment = getToken(&linePtr, "", &status, true); 851 842 if(status) { 852 psError(PS_ERR_IO, true, 853 _("Failed to read a metadata %s on line %u."), "comment", lineCount); 843 psError(PS_ERR_IO, true, _("Failed to read a metadata comment")); 854 844 psFree(strType); 855 845 psFree(strValue); … … 876 866 } else { 877 867 psError(PS_ERR_IO, true, 878 _("Failed to parse the value '%s' of metadata item %s, type %s , "879 "on line %u."), strValue, keyName, strType, lineCount);868 _("Failed to parse the value '%s' of metadata item %s, type %s."), 869 strValue, keyName, strType); 880 870 returnValue = false; 881 871 } … … 890 880 } else { 891 881 psError(PS_ERR_IO, true, 892 _("Failed to parse the value '%s' of metadata item %s, type %s , "893 "on line %u."), strValue, keyName, strType, lineCount);882 _("Failed to parse the value '%s' of metadata item %s, type %s."), 883 strValue, keyName, strType); 894 884 returnValue = false; 895 885 } … … 902 892 } else { 903 893 psError(PS_ERR_IO, true, 904 _("Failed to parse the value '%s' of metadata item %s, type %s , on line %u."),905 strValue, keyName, strType , lineCount);894 _("Failed to parse the value '%s' of metadata item %s, type %s."), 895 strValue, keyName, strType); 906 896 returnValue = false; 907 897 } … … 914 904 } else { 915 905 psError(PS_ERR_IO, true, 916 _("Failed to parse the value '%s' of metadata item %s, type %s , on line %u."),917 strValue, keyName, strType , lineCount);906 _("Failed to parse the value '%s' of metadata item %s, type %s."), 907 strValue, keyName, strType); 918 908 returnValue = false; 919 909 } … … 926 916 } else { 927 917 psError(PS_ERR_IO, true, 928 _("Failed to parse the value '%s' of metadata item %s, type %s , on line %u."),929 strValue, keyName, strType , lineCount);918 _("Failed to parse the value '%s' of metadata item %s, type %s."), 919 strValue, keyName, strType); 930 920 returnValue = false; 931 921 } … … 938 928 } else { 939 929 psError(PS_ERR_IO, true, 940 _("Failed to parse the value '%s' of metadata item %s, type %s , on line %u."),941 strValue, keyName, strType , lineCount);930 _("Failed to parse the value '%s' of metadata item %s, type %s."), 931 strValue, keyName, strType); 942 932 returnValue = false; 943 933 } … … 950 940 } else { 951 941 psError(PS_ERR_IO, true, 952 _("Failed to parse the value '%s' of metadata item %s, type %s , on line %u."),953 strValue, keyName, strType , lineCount);942 _("Failed to parse the value '%s' of metadata item %s, type %s."), 943 strValue, keyName, strType); 954 944 returnValue = false; 955 945 } … … 962 952 } else { 963 953 psError(PS_ERR_IO, true, 964 _("Failed to parse the value '%s' of metadata item %s, type %s , on line %u."),965 strValue, keyName, strType , lineCount);954 _("Failed to parse the value '%s' of metadata item %s, type %s."), 955 strValue, keyName, strType); 966 956 returnValue = false; 967 957 } … … 974 964 } else { 975 965 psError(PS_ERR_IO, true, 976 _("Failed to parse the value '%s' of metadata item %s, type %s , on line %u."),977 strValue, keyName, strType , lineCount);966 _("Failed to parse the value '%s' of metadata item %s, type %s."), 967 strValue, keyName, strType); 978 968 returnValue = false; 979 969 } … … 986 976 } else { 987 977 psError(PS_ERR_IO, true, 988 _("Failed to parse the value '%s' of metadata item %s, type %s , on line %u."),989 strValue, keyName, strType , lineCount);978 _("Failed to parse the value '%s' of metadata item %s, type %s."), 979 strValue, keyName, strType); 990 980 returnValue = false; 991 981 } … … 1009 999 } else { 1010 1000 psError(PS_ERR_IO, true, 1011 _("Failed to parse the value '%s' of metadata item %s, type %s , on line %u."),1012 strValue, keyName, strType , lineCount);1001 _("Failed to parse the value '%s' of metadata item %s, type %s."), 1002 strValue, keyName, strType); 1013 1003 returnValue = false; 1014 1004 } … … 1023 1013 } else { 1024 1014 psError(PS_ERR_IO, true, 1025 _("Failed to parse the value '%s' of metadata item %s, type %s , on line %u."),1026 strValue, keyName, strType , lineCount);1015 _("Failed to parse the value '%s' of metadata item %s, type %s."), 1016 strValue, keyName, strType); 1027 1017 returnValue = false; 1028 1018 } … … 1035 1025 for(psS32 k=0; k < nonUniqueKeys->n; k++) { 1036 1026 if(strcmp(keyName,(char*)nonUniqueKeys->data[k]) == 0) { 1037 psError(PS_ERR_IO,true,_("Duplicate MULTI specifier on line %u."), 1038 lineCount); 1027 psError(PS_ERR_IO,true,_("Duplicate MULTI specifier.")); 1039 1028 psFree(strType); 1040 1029 return false; … … 1047 1036 break; 1048 1037 case PS_DATA_METADATA: { 1038 // check to see if this keyname already exists and is allowed as a 1039 // MULTI. If we don't do this check first, it's possible that we 1040 // can create a new "scope" yet fail to add the new metdata. 1041 psMetadataItem *item = psMetadataLookup (md, keyName); 1042 if ((item != NULL) && 1043 ((item->type != PS_DATA_METADATA_MULTI) && 1044 ((flags & PS_META_REPLACE) == 0)) 1045 ) { 1046 psError(PS_ERR_IO, true, _("Duplicate Metadata declaration: %s is not allowed without 'overwrite' or MULTI specifier."), keyName); 1047 break; 1048 } 1049 1049 1050 // create the nested metadata 1050 1051 psMetadata *newScope = psMetadataAlloc(); … … 1053 1054 nextLevelInfo = p_psParseLevelInfoAlloc(); 1054 1055 1055 // switch to the scope to the new metadata 1056 nextLevelInfo->metadata = newScope; 1057 1058 // Add next level to levelArray 1059 levelArray = psArrayAdd(levelArray, 0, nextLevelInfo); 1060 psFree(nextLevelInfo); 1061 1056 1057 // try to add the new metdata to the current one 1062 1058 addStatus = psMetadataAdd(md, PS_LIST_TAIL, keyName, 1063 1059 mdType | flags, 1064 1060 strComment, newScope); 1061 1062 if (addStatus) { 1063 // switch to the scope to the new metadata 1064 nextLevelInfo->metadata = psMemIncrRefCounter(newScope); 1065 1066 // Add next level to levelArray 1067 levelArray = psArrayAdd(levelArray, 0, nextLevelInfo); 1068 } 1069 1070 psFree(nextLevelInfo); 1071 psFree(newScope); 1072 1065 1073 break; 1066 1074 } 1067 1075 default: 1068 1076 psError(PS_ERR_IO, true, 1069 _("Metadata of unknown type found on line %u."), lineCount);1077 _("Metadata of unknown type found.")); 1070 1078 break; 1071 1079 } … … 1083 1091 } 1084 1092 1085 bool parseLine(psArray* levelArray,1086 char* linePtr,1087 psS32 lineCount,1088 bool overwrite)1093 static bool parseLine(psArray* levelArray, 1094 char* linePtr, 1095 bool overwrite, 1096 bool *notBlank) 1089 1097 { 1090 1098 psMetadataFlags flags = PS_META_DEFAULT; … … 1098 1106 if (ignoreLine(linePtr)) { 1099 1107 // do nothing and return 1108 if (notBlank) { 1109 *notBlank = false; 1110 } 1100 1111 return true; 1101 1112 } 1113 1114 // even if it's a "bad line" we know it can't be "blank" after this point 1115 *notBlank = true; 1102 1116 1103 1117 // Check for more than one '@' in a line … … 1106 1120 if (repeatedChars(linePtr, '@') > 1) { 1107 1121 psError(PS_ERR_IO, true, 1108 _("More than one '@' character not allowed. Found on line %u."), lineCount);1122 _("More than one '@' character is not allowed")); 1109 1123 return false; 1110 1124 } … … 1114 1128 char *keyName = getToken(&linePtr, " ", &status, true); 1115 1129 if (status) { 1116 psError(PS_ERR_IO, true, 1117 _("Failed to read item key name on line %u."), lineCount); 1130 psError(PS_ERR_IO, true, _("Failed to read item key name on line")); 1118 1131 psFree(keyName); 1119 1132 return false; … … 1122 1135 // Check for special keyName values "TYPE", "END" 1123 1136 if (strcmp(keyName, "END") == 0) { 1124 if (!parseMetadataEnd(keyName, levelArray, linePtr, lineCount,flags)) {1137 if (!parseMetadataEnd(keyName, levelArray, linePtr, flags)) { 1125 1138 goto FAIL; 1126 1139 } 1127 1140 } else if (strcmp(keyName,"TYPE") == 0 ) { 1128 if (!parseType(keyName, levelArray, linePtr, lineCount,flags)) {1141 if (!parseType(keyName, levelArray, linePtr, flags)) { 1129 1142 goto FAIL; 1130 1143 } 1131 1144 } else { 1132 if (!parseGeneric(keyName, levelArray, linePtr, lineCount,flags)) {1145 if (!parseGeneric(keyName, levelArray, linePtr, flags)) { 1133 1146 goto FAIL; 1134 1147 } … … 1140 1153 1141 1154 FAIL: 1142 psError(PS_ERR_UNKNOWN, false, 1143 _("Failed to parse line %u: %s."), lineCount, linePtr); 1155 psError(PS_ERR_UNKNOWN, false, _("Failed to parse line")); 1144 1156 psFree(keyName); 1145 1157 return false; … … 1149 1161 psArray* levelArray, 1150 1162 char* linePtr, 1151 psS32 lineCount,1152 1163 psMetadataFlags flags) 1153 1164 { … … 1169 1180 1170 1181 // Parse metadataItem 1171 if (!parseMetadataItem(keyName, levelArray, linePtr, lineCount,flags)) {1182 if (!parseMetadataItem(keyName, levelArray, linePtr, flags)) { 1172 1183 return false; 1173 1184 } … … 1179 1190 psArray* levelArray, 1180 1191 char* linePtr, 1181 psS32 lineCount,1182 1192 psMetadataFlags flags) 1183 1193 { … … 1192 1202 char *strType = getToken(&linePtr, " ", &status, true); 1193 1203 if(!strType) { 1194 psError(PS_ERR_IO,true, 1195 _("Failed to read item type on line %u."), lineCount); 1204 psError(PS_ERR_IO,true, _("Failed to read item type.")); 1196 1205 return false; 1197 1206 } 1198 1207 if (status) { 1199 psError(PS_ERR_IO, true, 1200 _("Failed to read item type on line %u."), lineCount); 1208 psError(PS_ERR_IO, true, _("Failed to read item type.")); 1201 1209 psFree(strType); 1202 1210 return false; … … 1206 1214 psMetadata *tempTemplate = getMetadataType(linePtr); 1207 1215 if (!tempTemplate) { 1208 psError(PS_ERR_IO,true, 1209 _("Metadata type '%s', found on line %u, is invalid."), 1210 strType,lineCount); 1216 psError(PS_ERR_IO,true, _("Metadata type '%s' is invalid."), strType); 1211 1217 psFree(strType); 1212 1218 return false; … … 1221 1227 if (strcmp(strType, (char*)typeArray->data[k]) == 0) { 1222 1228 psError(PS_ERR_IO,true, 1223 _("Specified type, %s, on line %u is already defined."), 1224 strType, lineCount); 1229 _("Specified type %s is already defined."), strType); 1225 1230 psFree(tempTemplate); 1226 1231 psFree(strType); … … 1244 1249 psArray* levelArray, 1245 1250 char* linePtr, 1246 psS32 lineCount,1247 1251 psMetadataFlags flags) 1248 1252 { … … 1379 1383 return NULL; 1380 1384 } 1385 1386 // accept completely empty strings 1387 // nFail == 0 / nPass == 0 - OK 1381 1388 if (psListLength(doc) == 0) { 1382 ps Error(PS_ERR_UNKNOWN, false, "string contained no lines");1389 psTrace("psLib.types", PS_LOG_INFO, "string contained no lines"); 1383 1390 psFree(doc); 1384 if (allocedMD) { 1385 psFree(md); 1386 } 1387 return NULL; 1391 return md; 1388 1392 } 1389 1393 … … 1401 1405 psErrorClear(); 1402 1406 1407 // line type counts 1408 long nLines = 0; // all lines 1409 long nGood = 0; // valid lines excluding blank/comment 1410 long nBad = 0; // invalid lines 1411 1403 1412 // While loop to parse the file 1404 long lineCount = 0;1405 1413 char *line = NULL; 1406 1414 psListIterator *iter = psListIteratorAlloc(doc, 0, false); 1407 1415 while ((line = psListGetAndIncrement(iter))) { 1408 lineCount++; // indexed from 1 1409 1410 if (!parseLine(parseLevelInfoArray, line, lineCount, 1411 overwrite)) { 1412 if (nFail != NULL) { 1413 (*nFail)++; 1414 } else { 1415 psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Error parsing line: %s", line); 1416 } 1417 psTrace("psLib.types", 4, "Error parsing line: %s", line); 1416 nLines++; // indexed from 1 1417 1418 bool notBlank = false; 1419 if (!parseLine(parseLevelInfoArray, line, overwrite, ¬Blank)) { 1420 nBad++; 1421 psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Error parsing line #%lu : %s", nLines, line); 1422 } else if (notBlank) { 1423 // do not count blank/comment lines as "good" lines 1424 nGood++; 1418 1425 } 1419 1426 } … … 1425 1432 psFree(parseLevelInfoArray); 1426 1433 1434 // nFail > 0 / nPass == 0 - NULL 1435 if ((nBad > 0) && (nGood == 0)) { 1436 psError(PS_ERR_UNKNOWN, false, "string contained no data lines and %ld bad lines", nBad); 1437 psFree(md); 1438 return NULL; 1439 } 1440 1441 // pass back the number of failed lines 1442 if (nFail) { 1443 *nFail = nBad; 1444 } 1445 1446 // nFail == 0 / nPass > 0 1447 // nFail > 0 / nPass > 0 1427 1448 return md; 1428 1449 } -
trunk/psLib/test/types/metaconf.in
r9895 r12441 1 # 2 # Good lines 3 # 4 1 5 item1 BOOL T # I am a boolean 2 item1 BOOL F # I am a boolean23 6 item2 S32 55 # I am int 4 7 item3 F32 3.14 5 8 item4 F64 6.28 # I am float 6 item4-1 F64 6.28 1 # I am float7 9 item5 STR GNIRTS # I am a string 8 item6 S32 10 19 item6-1 S32 ~10 10 item7 S64 555 11 item7-1 S64 555 x12 11 item8 S8 3 13 item8 S8 514 item8-1 S8 5 115 12 itemu1 U16 2 16 itemu1-1 U16 2 117 13 itemu2 U32 55 18 itemu2-1 U32 55 119 itemu3-1 U8 1 220 14 itemu3 U8 1 21 15 itemu4 U64 1634 22 itemu4-1 U64 1634 123 16 item9 BOOL F # I am a boolean2 24 17 item10 S16 16 25 item10-1 S16 16 1626 18 @vector1 S8 1 2 3 4 5 # I am a vector 27 @vector1-1 S8 % #28 19 @vector2 S16 1 2 3 4 5 29 20 @vector3 S32 1 2 3 4 5 … … 35 26 @vector9 F32 1.0 2.3 3.1 4.5 5.0 # I am a vector 36 27 @vector10 F64 1.0 2.0 3.0 4.0 5.0 37 @vector11 C64 1.0 2.0 3.0 4.0 5.038 @@@vector12 F64 1.0 2.0 3.0 4.0 5.039 28 time01 TT 1970-01-01T00:16:39Z # I am time 40 29 time02 UTC NULL # I am time2 41 42 ps1 S32 NAN43 30 44 31 f32 MULTI 45 32 f32 S32 666 # f32_1 46 33 f32 S32 665 # f32_2 47 f32 MULTI48 34 49 35 f32 METADATA … … 54 40 meta1 METADATA 55 41 itemS32 S32 666 # f32_1 56 END57 meta1 METADATA58 M2 S32 66659 42 END 60 43 … … 68 51 ITEM03 F64 666.666 # I AM DOUBLE 69 52 END 70 71 TYPE C32 372 TYPE C32 373 TYPE PS_TYPE_C32 2 #74 newC32 C32 7i+575 newC32 PS_TYPE_C32 7i+576 53 #item11 C32 16+2i # I am Complex 77 54 78 55 TYPE PS_TYPE_DD D 56 DD2 PS_TYPE_DD "" 57 TYPE C32 3 58 newC32 C32 7i+5 59 60 # 61 # Bad lines : 28 (-1 for the GOOD line in meta1) & 3 valid duplicates 62 # 63 item1 BOOL F # duplicate 64 item8 S8 5 # duplicate 65 item4-1 F64 6.28 1 # I am float 66 item6 S32 10 1 67 item6-1 S32 ~ 68 item7-1 S64 555 x 69 item8-1 S8 5 1 70 itemu1-1 U16 2 1 71 itemu2-1 U32 55 1 72 itemu3-1 U8 1 2 73 itemu4-1 U64 1634 1 74 item10-1 S16 16 16 75 @vector1-1 S8 % # 76 @@@vector12 F64 1.0 2.0 3.0 4.0 5.0 77 @vector11 C64 1.0 2.0 3.0 4.0 5.0 78 meta1 METADATA # duplicate 79 M2 S32 666 # this line is "GOOD" but parsed in the top level 80 END 79 81 newDD PS_TYPE_DD 80 DD2 PS_TYPE_DD ""81 82 82 TYPE 1 83 83 TYPE 84 84 TYPE # # 1 85 TYPE C32 3 86 TYPE PS_TYPE_C32 2 # 87 newC32 PS_TYPE_C32 7i+5 # duplicate but with borken type 88 ps1 S32 NAN 89 f32 MULTI 85 90 \n -
trunk/psLib/test/types/table3.dat
r9746 r12441 1 # Table with valid types and index-values 1 # 2 # This file is not valid metdataconfig syntax 2 3 # 3 4 #psF32 psU16 psU32 psU64 psS8 psS16 psS32 psS64 psU8 psF64 -
trunk/psLib/test/types/tap_psMetadataConfig_input.c
r12408 r12441 19 19 #include "pstap.h" 20 20 21 static void testMetaConfigRead(void);22 static void testMetaConfigParse(void);23 24 25 21 int main(void) 26 22 { 23 plan_tests(42); 24 27 25 psLogSetFormat("HLNM"); 28 plan_tests(39); 29 30 note("Tests for psMetadataConfig Input Functions"); 31 testMetaConfigRead(); 32 testMetaConfigParse(); 33 } 34 35 void testMetaConfigRead(void) 36 { 37 note(" >>>Test 1: psMetadataConfigRead"); 38 39 //Return NULL for NULL filename input 26 // psTraceSetLevel("err", 10); 27 28 29 // Return NULL for NULL filename input 40 30 { 41 31 unsigned int nfail = 0; 42 32 psMetadata *out = psMetadataConfigRead(NULL, &nfail, NULL, false); 43 ok( out == NULL, 44 "psMetadataConfigRead: return NULL for NULL filename input."); 45 } 46 //Return NULL for invalid filename input 33 34 ok(out == NULL, "return NULL for NULL filename input."); 35 } 36 37 // Return NULL for invalid filename input 47 38 { 48 39 unsigned int nfail = 0; 49 40 psMetadata *out = psMetadataConfigRead(NULL, &nfail, ".", false); 50 ok( out == NULL, 51 "psMetadataConfigRead: return NULL for invalid filename input."); 52 } 53 //Return NULL for missing file input 41 42 ok(out == NULL, "return NULL for invalid filename input."); 43 } 44 45 // Return NULL for missing file input 54 46 { 55 47 unsigned int nfail = 0; 56 48 psMetadata *out = psMetadataConfigRead(NULL, &nfail, "table4.dat", false); 57 ok( out == NULL, 58 "psMetadataConfigRead: return NULL for missing file input."); 59 } 60 //Return empty metadata for read-only file with invalid syntax 49 ok(out == NULL, "return NULL for missing file input."); 50 } 51 52 // Return NULL for read-only file with comments, bad syntax, and no good 53 // lines 61 54 { 62 55 unsigned int nfail = 0; 63 56 psMetadata *out = psMetadataConfigRead(NULL, &nfail, "table3.dat", false); 64 ok( out != NULL && out->list->n == 0, 65 "psMetadataConfigRead: return empty metadata for file" 66 " with invalid syntax."); 67 psFree(out); 68 } 69 //Return true for valid inputs - overwrite = false 57 ok(out == NULL, "return NULL for all bad syntax"); 58 is_int(nfail, 0, "correct nfail"); 59 60 psFree(out); 61 } 62 63 // Return true for valid inputs - overwrite = false 70 64 { 71 65 unsigned int nfail = 0; 72 66 psMetadata *out = psMetadataConfigRead(NULL, &nfail, "metaconf.in", false); 73 psMetadataItem *tempItem = psMetadataGet(out, PS_LIST_HEAD); 74 75 //XXX: Josh, please review the "metaconf.in" in this directory and ensure that 76 //the number of failed lines, which we test next, should indeed be 26. 77 ok(out != NULL && nfail == 26, 78 "psMetadataConfigRead: return correct metadata for valid inputs (nfail was %d)", nfail); 79 skip_start(tempItem == NULL, 6, 80 "Skipping 1 tests because metadata container is empty!"); 81 ok_str(tempItem->name, "item1", 82 "psMetadataConfigRead: return correct metadataItem name from " 83 "returned metadata."); 84 ok(tempItem->type == PS_DATA_BOOL && tempItem->data.B == true, 85 "psMetadataConfigRead: return correct metadataItem data from " 86 "returned metadata."); 87 ok_str(tempItem->comment, "I am a boolean", 88 "psMetadataConfigRead: return correct metadataItem comment from " 89 "returned metadata."); 67 68 ok(out != NULL, "return metadata for valid input"); 69 is_int(nfail, 27, "return correct nFail count"); 70 71 skip_start(out == NULL, 8, 72 "Skipping 1 tests because metadata container is empty!"); 73 74 // look at the first item 75 psMetadataItem *tempItem = psMetadataGet(out, PS_LIST_HEAD); 76 // XXX shouldn't assume tempItem isn't NULL 77 ok_str(tempItem->name, "item1", "metadataItem name"); 78 ok(tempItem->type == PS_DATA_BOOL, "metadataItem type"); 79 is_bool(tempItem->data.B, true, "metdataItem value"); 80 ok_str(tempItem->comment, "I am a boolean", "metadataItem comment."); 81 82 // look at the last item 90 83 tempItem = psMetadataGet(out, PS_LIST_TAIL); 91 ok_str(tempItem->name, "DD2", 92 "psMetadataConfigRead: return correct metadataItem name from returned metadata"); 93 ok(tempItem->type == PS_DATA_METADATA && 94 ((psMetadata*)(tempItem->data.V))->list->n == 1 95 && strlen(tempItem->comment) == 0, 96 "psMetadataConfigRead: return correct metadataItem data from " 97 "returned metadata."); 98 skip_end(); 99 // psMetadataConfigWrite(out, "mdc-overwrite_false.txt"); 100 psFree(out); 101 } 102 103 //Return true for valid inputs - overwrite = true 84 // XXX shouldn't assume tempItem isn't NULL 85 ok_str(tempItem->name, "M2", "metadataItem name"); 86 ok(tempItem->type == PS_DATA_S32, "metdataItem type"); 87 is_int(tempItem->data.S32, 666, "metdataItem value"); 88 ok_str(tempItem->comment, "this line is \"GOOD\" but parsed in the top level", "metadataItem comment."); 89 90 skip_end(); 91 psFree(out); 92 } 93 94 // Return true for valid inputs - overwrite = true 104 95 { 105 96 unsigned int nfail = 0; 106 97 psMetadata *out = psMetadataConfigRead(NULL, &nfail, "metaconf.in", true); 107 psMetadataItem *tempItem = psMetadataGet(out, PS_LIST_HEAD); 108 //XXX: Josh, please review the "metaconf.in" in this directory and ensure that 109 //the number of failed lines, which we test next, should indeed be 23. 110 ok( out != NULL && nfail == 23, 111 "psMetadataConfigRead: return correct metadata for valid inputs (nfail was %d).", nfail); 112 skip_start( tempItem == NULL, 6, 113 "Skipping 1 tests because metadata container is empty!"); 114 ok_str( tempItem->name, "item1", 115 "psMetadataConfigRead: return correct metadataItem name from " 116 "returned metadata."); 117 ok( tempItem->type == PS_DATA_BOOL && tempItem->data.B == false, 118 "psMetadataConfigRead: return correct metadataItem data from " 119 "returned metadata."); 120 ok_str( tempItem->comment, "I am a boolean2", 121 "psMetadataConfigRead: return correct metadataItem comment from " 122 "returned metadata."); 98 // psMetadataConfigPrint(stdout, out); 99 100 ok(out != NULL, "return metadata for valid input"); 101 is_int(nfail, 23, "return correct nFail count"); 102 103 skip_start(out == NULL, 7, 104 "Skipping 1 tests because metadata container is empty!"); 105 106 // look at the first item 107 psMetadataItem *tempItem = psMetadataGet(out, PS_LIST_HEAD); 108 // XXX shouldn't assume tempItem isn't NULL 109 // note that item1 gets added to the "tail" of the metdata was it's 110 // replaced 111 ok_str(tempItem->name, "item2", "metadataItem name"); 112 ok(tempItem->type == PS_DATA_S32, "metdataItem type"); 113 is_bool(tempItem->data.S32, 55, "metadataItem value"); 114 ok_str(tempItem->comment, "I am int", "metadataItem value"); 115 116 // look at the last item 123 117 tempItem = psMetadataGet(out, PS_LIST_TAIL); 124 ok_str( tempItem->name, "DD2", 125 "psMetadataConfigRead: return correct metadataItem name from " 126 "returned metadata."); 127 ok( tempItem->type == PS_DATA_METADATA && 128 ((psMetadata*)(tempItem->data.V))->list->n == 1 129 && strlen(tempItem->comment) == 0, 130 "psMetadataConfigRead: return correct metadataItem data from " 131 "returned metadata."); 132 skip_end(); 133 // psMetadataConfigWrite(out, "mdc-overwrite_true.txt"); 134 psFree(out); 135 } 136 137 //Check for Memory leaks 118 // XXX shouldn't assume tempItem isn't NULL 119 // meta1 is from "the bad section" 120 ok_str(tempItem->name, "meta1", "metadataItem name"); 121 ok(tempItem->type == PS_DATA_METADATA, "metadataItem type"); 122 123 ok_str(tempItem->comment, "", "metadataItem comment"); 124 125 skip_end(); 126 psFree(out); 127 } 128 129 // Check for Memory leaks 138 130 checkMem(); 139 } 140 141 void testMetaConfigParse(void) 142 { 143 note(" >>>Test 2: psMetadataConfigParse"); 144 145 //Return NULL for NULL string input 131 132 // Return NULL for NULL string input 146 133 { 147 134 psMemId id = psMemGetId(); 148 135 unsigned int nfail = 0; 149 136 psMetadata *out = psMetadataConfigParse(NULL, &nfail, NULL, false); 150 ok(out == NULL, 151 "psMetadataConfigParse: return NULL for NULL string input."); 152 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 153 } 154 155 //Return empty metadata for incorrect string input 137 138 ok(out == NULL, "psMetadataConfigParse: return NULL for NULL string input."); 139 140 ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks"); 141 } 142 143 // Return empty metadata for incorrect string input 156 144 { 157 145 psMemId id = psMemGetId(); … … 167 155 } 168 156 169 // Return correct metadata for correct string input - S32157 // Return correct metadata for correct string input - S32 170 158 { 171 159 psMemId id = psMemGetId(); … … 188 176 } 189 177 190 // Return correct metadata for correct string input - F64178 // Return correct metadata for correct string input - F64 191 179 { 192 180 psMemId id = psMemGetId(); … … 213 201 } 214 202 215 // Return correct metadata for string with duplicate entry - S8203 // Return correct metadata for string with duplicate entry - S8 216 204 { 217 205 psMemId id = psMemGetId();
Note:
See TracChangeset
for help on using the changeset viewer.
