Changeset 23587 in vbox for trunk/src/VBox/VMM
- Timestamp:
- Oct 6, 2009 5:10:52 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 53253
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/CFGM.cpp
r23586 r23587 340 340 341 341 /** 342 * Compares two names.343 *344 * @returns Similar to memcpy.345 * @param pszName1 The first name.346 * @param cchName1 The length of the first name.347 * @param pszName2 The second name.348 * @param cchName2 The length of the second name.349 */350 DECLINLINE(int) cfgmR3CompareNames(const char *pszName1, size_t cchName1, const char *pszName2, size_t cchName2)351 {352 int iDiff;353 if (cchName1 <= cchName2)354 {355 iDiff = memcmp(pszName1, pszName2, cchName1);356 if (!iDiff && cchName1 < cchName2)357 iDiff = -1;358 }359 else360 {361 iDiff = memcmp(pszName1, pszName2, cchName2);362 if (!iDiff)363 iDiff = 1;364 }365 return iDiff;366 }367 368 369 /**370 342 * Validates that the child nodes are within a set of valid names. 371 343 * … … 1035 1007 static int cfgmR3ResolveNode(PCFGMNODE pNode, const char *pszPath, PCFGMNODE *ppChild) 1036 1008 { 1037 if (pNode) 1038 { 1039 PCFGMNODE pChild = NULL; 1040 for (;;) 1009 if (!pNode) 1010 return VERR_CFGM_NO_PARENT; 1011 PCFGMNODE pChild = NULL; 1012 for (;;) 1013 { 1014 /* skip leading slashes. */ 1015 while (*pszPath == '/') 1016 pszPath++; 1017 1018 /* End of path? */ 1019 if (!*pszPath) 1041 1020 { 1042 /* skip leading slashes. */ 1043 while (*pszPath == '/') 1044 pszPath++; 1045 1046 /* End of path? */ 1047 if (!*pszPath) 1021 if (!pChild) 1022 return VERR_CFGM_INVALID_CHILD_PATH; 1023 *ppChild = pChild; 1024 return VINF_SUCCESS; 1025 } 1026 1027 /* find end of component. */ 1028 const char *pszNext = strchr(pszPath, '/'); 1029 if (!pszNext) 1030 pszNext = strchr(pszPath, '\0'); 1031 RTUINT cchName = pszNext - pszPath; 1032 1033 /* search child list. */ 1034 pChild = pNode->pFirstChild; 1035 for ( ; pChild; pChild = pChild->pNext) 1036 if (pChild->cchName == cchName) 1048 1037 { 1049 if (!pChild) 1050 return VERR_CFGM_INVALID_CHILD_PATH; 1051 *ppChild = pChild; 1052 return VINF_SUCCESS; 1038 int iDiff = memcmp(pszPath, pChild->szName, cchName); 1039 if (iDiff <= 0) 1040 { 1041 if (iDiff != 0) 1042 pChild = NULL; 1043 break; 1044 } 1053 1045 } 1054 1055 /* find end of component. */ 1056 const char *pszNext = strchr(pszPath, '/'); 1057 if (!pszNext) 1058 pszNext = strchr(pszPath, '\0'); 1059 RTUINT cchName = pszNext - pszPath; 1060 1061 /* search child list. */ /** @todo the list is ordered now, consider optimizing the search. */ 1062 pChild = pNode->pFirstChild; 1063 for ( ; pChild; pChild = pChild->pNext) 1064 if ( pChild->cchName == cchName 1065 && !memcmp(pszPath, pChild->szName, cchName) ) 1066 break; 1067 1068 /* if not found, we're done. */ 1069 if (!pChild) 1070 return VERR_CFGM_CHILD_NOT_FOUND; 1071 1072 /* next iteration */ 1073 pNode = pChild; 1074 pszPath = pszNext; 1075 } 1076 1077 /* won't get here */ 1078 } 1079 else 1080 return VERR_CFGM_NO_PARENT; 1046 if (!pChild) 1047 return VERR_CFGM_CHILD_NOT_FOUND; 1048 1049 /* next iteration */ 1050 pNode = pChild; 1051 pszPath = pszNext; 1052 } 1053 1054 /* won't get here */ 1081 1055 } 1082 1056 … … 1092 1066 static int cfgmR3ResolveLeaf(PCFGMNODE pNode, const char *pszName, PCFGMLEAF *ppLeaf) 1093 1067 { 1094 int rc; 1095 if (pNode) 1096 { 1097 size_t cchName = strlen(pszName); 1098 PCFGMLEAF pLeaf = pNode->pFirstLeaf; 1099 while (pLeaf) 1068 if (!pNode) 1069 return VERR_CFGM_NO_PARENT; 1070 1071 size_t cchName = strlen(pszName); 1072 PCFGMLEAF pLeaf = pNode->pFirstLeaf; 1073 while (pLeaf) 1074 { 1075 if (cchName == pLeaf->cchName) 1100 1076 { 1101 /** @todo the list is ordered now, consider optimizing the search. */ 1102 if ( cchName == pLeaf->cchName 1103 && !memcmp(pszName, pLeaf->szName, cchName) ) 1077 int iDiff = memcmp(pszName, pLeaf->szName, cchName); 1078 if (iDiff <= 0) 1104 1079 { 1080 if (iDiff != 0) 1081 break; 1105 1082 *ppLeaf = pLeaf; 1106 1083 return VINF_SUCCESS; 1107 1084 } 1108 1109 /* next */1110 pLeaf = pLeaf->pNext;1111 1085 } 1112 rc = VERR_CFGM_VALUE_NOT_FOUND; 1113 }1114 else1115 rc = VERR_CFGM_NO_PARENT;1116 return rc;1086 1087 /* next */ 1088 pLeaf = pLeaf->pNext; 1089 } 1090 return VERR_CFGM_VALUE_NOT_FOUND; 1117 1091 } 1118 1092 … … 1200 1174 } 1201 1175 return rc; 1176 } 1177 1178 1179 /** 1180 * Compares two names. 1181 * 1182 * @returns Similar to memcpy. 1183 * @param pszName1 The first name. 1184 * @param cchName1 The length of the first name. 1185 * @param pszName2 The second name. 1186 * @param cchName2 The length of the second name. 1187 */ 1188 DECLINLINE(int) cfgmR3CompareNames(const char *pszName1, size_t cchName1, const char *pszName2, size_t cchName2) 1189 { 1190 int iDiff; 1191 if (cchName1 <= cchName2) 1192 { 1193 iDiff = memcmp(pszName1, pszName2, cchName1); 1194 if (!iDiff && cchName1 < cchName2) 1195 iDiff = -1; 1196 } 1197 else 1198 { 1199 iDiff = memcmp(pszName1, pszName2, cchName2); 1200 if (!iDiff) 1201 iDiff = 1; 1202 } 1203 return iDiff; 1202 1204 } 1203 1205 … … 1286 1288 if (pNext) 1287 1289 { 1288 for ( ; pNext; pPrev = pNext, pNext = pNext->pNext)1290 for ( ; pNext; pPrev = pNext, pNext = pNext->pNext) 1289 1291 { 1290 1292 int iDiff = cfgmR3CompareNames(pszName, cchName, pNext->szName, pNext->cchName); … … 1428 1430 if (pNext) 1429 1431 { 1430 for ( ; pNext; pPrev = pNext, pNext = pNext->pNext)1432 for ( ; pNext; pPrev = pNext, pNext = pNext->pNext) 1431 1433 { 1432 1434 int iDiff = cfgmR3CompareNames(pszName, cchName, pNext->szName, pNext->cchName);
Note:
See TracChangeset
for help on using the changeset viewer.