Changeset 7918 for trunk/psLib/src/types
- Timestamp:
- Jul 17, 2006, 12:41:38 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/types/psMetadata.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/types/psMetadata.c
r7914 r7918 12 12 * @author Ross Harman, MHPCC 13 13 * 14 * @version $Revision: 1.11 7$ $Name: not supported by cvs2svn $15 * @date $Date: 2006-07-1 5 02:57:12$14 * @version $Revision: 1.118 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2006-07-17 22:41:38 $ 16 16 * 17 17 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 919 919 920 920 psMetadataIterator* newIter = psAlloc(sizeof(psMetadataIterator)); 921 newIter->regex = NULL;922 newIter->iter = NULL;923 924 // Set deallocator925 921 psMemSetDeallocator(newIter, (psFreeFunc) metadataIteratorFree); 926 922 … … 929 925 if (regex) { 930 926 newIter->regex = psAlloc(sizeof(regex_t)); 931 int regRtn = regcomp(newIter->regex, regex,0);927 int regRtn = regcomp(newIter->regex, regex, 0); 932 928 if (regRtn != 0) { 933 929 char errMsg[256]; 934 930 regerror(regRtn, newIter->regex, errMsg, 256); 935 regfree(newIter->regex);936 931 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 937 932 PS_ERRORTEXT_psMetadata_REGEX_INVALID, … … 940 935 return NULL; 941 936 } 937 if (!psMetadataIteratorSet(newIter, location)) { 938 psError(PS_ERR_UNKNOWN, false, "Unable to set location=%d for metadata iterator.\n", location); 939 psFree(newIter); 940 return NULL; 941 } 942 } else { 943 newIter->regex = NULL; 942 944 } 943 945 … … 948 950 long location) 949 951 { 950 int match; 951 psMetadataItem* cursor; 952 953 PS_ASSERT_PTR_NON_NULL(iterator,NULL); 954 955 psListIterator* iter = iterator->iter; 956 PS_ASSERT_PTR_NON_NULL(iterator->iter,NULL); 957 958 regex_t* regex = iterator->regex; 952 PS_ASSERT_PTR_NON_NULL(iterator, NULL); 953 psListIterator *listIter = iterator->iter; 954 PS_ASSERT_PTR_NON_NULL(listIter, NULL); 955 956 regex_t *regex = iterator->regex; 959 957 960 958 // handle trivial case where no regex subsetting is required. 961 959 if (regex == NULL) { 962 return psListIteratorSet(iter,location); 963 } 964 960 return psListIteratorSet(listIter, location); 961 } 962 963 // If there's a regex, then we need to count into the list. 964 // We count ONLY those entries that match the regex 965 966 // Here we count in from the tail 965 967 if (location < 0) { 966 // match from the tail967 match = 0;968 psListIteratorSet(iter,PS_LIST_TAIL);969 while ( (cursor=(psMetadataItem*)iter->cursor) != NULL) {970 if (regexec(regex, cursor->name, 0, NULL, 0) == 0) {968 psListIteratorSet(listIter, PS_LIST_TAIL); 969 psMetadataItem *item; // Item from iteration 970 int match = 0; // Match number 971 while (listIter->cursor && (item = listIter->cursor->data)) { 972 if (regexec(regex, item->name, 0, NULL, 0) == 0) { 971 973 // this key is a match 972 974 match--; … … 975 977 } 976 978 } 977 (void)psListGetAndDecrement( iter);979 (void)psListGetAndDecrement(listIter); 978 980 } 979 981 return (match == location); 980 982 } 981 983 982 // find the n-th match from the head 983 match = -1; 984 psListIteratorSet(iter,PS_LIST_HEAD); 985 while ( (cursor=(psMetadataItem*)iter->cursor) != NULL) { 986 if (regexec(regex, cursor->name, 0, NULL, 0) == 0) { 984 // Here we count in from the head 985 psListIteratorSet(listIter, PS_LIST_HEAD); 986 psMetadataItem *item; // Item from iteration 987 int match = -1; // Match number 988 while (listIter->cursor && (item = listIter->cursor->data)) { 989 if (regexec(regex, item->name, 0, NULL, 0) == 0) { 987 990 // this key is a match 988 991 match++; … … 991 994 } 992 995 } 993 (void)psListGetAndIncrement( iter);996 (void)psListGetAndIncrement(listIter); 994 997 } 995 998 return (match == location); … … 998 1001 psMetadataItem* psMetadataGetAndIncrement(psMetadataIterator* iterator) 999 1002 { 1000 psMetadataItem* oldValue;1001 1002 1003 PS_ASSERT_PTR_NON_NULL(iterator,NULL); 1003 1004 psListIterator* iter = iterator->iter; 1005 PS_ASSERT_PTR_NON_NULL(iterator->iter,NULL); 1004 psListIterator* listIter = iterator->iter; 1005 PS_ASSERT_PTR_NON_NULL(listIter,NULL); 1006 1006 1007 1007 regex_t* regex = iterator->regex; … … 1009 1009 // handle trivial case where no regex subsetting is required. 1010 1010 if (regex == NULL) { 1011 return (psMetadataItem*)psListGetAndIncrement(iter); 1012 } 1013 1014 oldValue = (psMetadataItem*)iter->cursor; 1015 1016 while (psListGetAndIncrement(iter) != NULL) { 1017 if (iter->cursor != NULL && 1018 regexec(regex, ((psMetadataItem*)iter->cursor->data)->name, 0, NULL, 0) == 0) { 1011 return (psMetadataItem*)psListGetAndIncrement(listIter); 1012 } 1013 1014 // Iterate until we find something matching the regex 1015 psMetadataItem *newItem; // New MD item from iteration 1016 while ((newItem = psListGetAndIncrement(listIter))) { 1017 if (regexec(regex, newItem->name, 0, NULL, 0) == 0) { 1019 1018 // this key is a match 1020 1019 break; 1021 1020 } 1022 1021 } 1023 return oldValue;1022 return newItem; 1024 1023 } 1025 1024 1026 1025 psMetadataItem* psMetadataGetAndDecrement(psMetadataIterator* iterator) 1027 1026 { 1028 psMetadataItem* oldValue; 1029 1030 PS_ASSERT_PTR_NON_NULL(iterator,NULL); 1031 1032 psListIterator* iter = iterator->iter; 1033 PS_ASSERT_PTR_NON_NULL(iterator->iter,NULL); 1027 PS_ASSERT_PTR_NON_NULL(iterator, NULL); 1028 psListIterator* listIter = iterator->iter; 1029 PS_ASSERT_PTR_NON_NULL(listIter, NULL); 1034 1030 1035 1031 regex_t* regex = iterator->regex; … … 1037 1033 // handle trivial case where no regex subsetting is required. 1038 1034 if (regex == NULL) { 1039 return (psMetadataItem*)psListGetAndDecrement(iter); 1040 } 1041 1042 oldValue = (psMetadataItem*)iter->cursor; 1043 1044 while (psListGetAndDecrement(iter) != NULL) { 1045 if (iter->cursor != NULL && 1046 regexec(regex, ((psMetadataItem*)iter->cursor)->name, 0, NULL, 0) == 0) { 1035 return (psMetadataItem*)psListGetAndDecrement(listIter); 1036 } 1037 1038 // Iterate until we find something matching the regex 1039 psMetadataItem *newItem; // New MD item from iteration 1040 while ((newItem = psListGetAndDecrement(listIter))) { 1041 if (regexec(regex, newItem->name, 0, NULL, 0) == 0) { 1047 1042 // this key is a match 1048 1043 break; 1049 1044 } 1050 1045 } 1051 return oldValue;1046 return newItem; 1052 1047 } 1053 1048
Note:
See TracChangeset
for help on using the changeset viewer.
