Changeset 69253 in vbox for trunk/src/bldprogs
- Timestamp:
- Oct 24, 2017 7:32:58 PM (8 years ago)
- svn:sync-xref-src-repo-rev:
- 118568
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bldprogs/scm.cpp
r69244 r69253 943 943 * @returns IPRT status code. 944 944 * @param pSettings Where to load the settings file. 945 * @param pszFilename The file to load. ASSUMED to be absolute. 946 * @param offName The offset of the name part in pszFilename. 947 */ 948 static int scmSettingsLoadFile(PSCMSETTINGS pSettings, const char *pszFilename, size_t offName) 945 * @param pszFilename The file to load. 946 */ 947 static int scmSettingsLoadFile(PSCMSETTINGS pSettings, const char *pszFilename) 949 948 { 950 949 ScmVerbose(NULL, 3, "Loading settings file '%s'...\n", pszFilename); 951 950 952 #ifdef RT_STRICT 953 /* Check absolute path assumption. */ 954 char szTmp[RTPATH_MAX]; 955 int rcTmp = RTPathAbs(pszFilename, szTmp, sizeof(szTmp)); 956 AssertMsg(RT_SUCCESS(rcTmp) && RTPathCompare(szTmp, pszFilename) == 0, ("rcTmp=%Rrc pszFilename='%s'\n", rcTmp, pszFilename)); 957 #endif 958 951 /* Turn filename into an absolute path and drop the filename. */ 952 char szAbsPath[RTPATH_MAX]; 953 int rc = RTPathAbs(pszFilename, szAbsPath, sizeof(szAbsPath)); 954 if (RT_FAILURE(rc)) 955 { 956 RTMsgError("%s: RTPathAbs -> %Rrc\n", pszFilename, rc); 957 return rc; 958 } 959 RTPathChangeToUnixSlashes(szAbsPath, true); 960 size_t cchDir = RTPathFilename(szAbsPath) - &szAbsPath[0]; 961 962 /* Try open it.*/ 959 963 SCMSTREAM Stream; 960 int rc = ScmStreamInitForReading(&Stream, pszFilename); 961 if (RT_FAILURE(rc)) 962 { 964 rc = ScmStreamInitForReading(&Stream, pszFilename); 965 if (RT_SUCCESS(rc)) 966 { 967 SCMEOL enmEol; 968 const char *pchLine; 969 size_t cchLine; 970 while ((pchLine = ScmStreamGetLine(&Stream, &cchLine, &enmEol)) != NULL) 971 { 972 /* Ignore leading spaces. */ 973 while (cchLine > 0 && RT_C_IS_SPACE(*pchLine)) 974 pchLine++, cchLine--; 975 976 /* Ignore empty lines and comment lines. */ 977 if (cchLine < 1 || *pchLine == '#') 978 continue; 979 980 /* What kind of line is it? */ 981 const char *pchColon = (const char *)memchr(pchLine, ':', cchLine); 982 if (pchColon) 983 rc = scmSettingsAddPair(pSettings, pchLine, cchLine, pchColon - pchLine, szAbsPath, cchDir); 984 else 985 rc = scmSettingsBaseParseStringN(&pSettings->Base, pchLine, cchLine, szAbsPath, cchDir); 986 if (RT_FAILURE(rc)) 987 { 988 RTMsgError("%s:%d: %Rrc\n", pszFilename, ScmStreamTellLine(&Stream), rc); 989 break; 990 } 991 } 992 993 if (RT_SUCCESS(rc)) 994 { 995 rc = ScmStreamGetStatus(&Stream); 996 if (RT_FAILURE(rc)) 997 RTMsgError("%s: ScmStreamGetStatus- > %Rrc\n", pszFilename, rc); 998 } 999 ScmStreamDelete(&Stream); 1000 } 1001 else 963 1002 RTMsgError("%s: ScmStreamInitForReading -> %Rrc\n", pszFilename, rc); 964 return rc;965 }966 967 SCMEOL enmEol;968 const char *pchLine;969 size_t cchLine;970 while ((pchLine = ScmStreamGetLine(&Stream, &cchLine, &enmEol)) != NULL)971 {972 /* Ignore leading spaces. */973 while (cchLine > 0 && RT_C_IS_SPACE(*pchLine))974 pchLine++, cchLine--;975 976 /* Ignore empty lines and comment lines. */977 if (cchLine < 1 || *pchLine == '#')978 continue;979 980 /* What kind of line is it? */981 const char *pchColon = (const char *)memchr(pchLine, ':', cchLine);982 if (pchColon)983 rc = scmSettingsAddPair(pSettings, pchLine, cchLine, pchColon - pchLine, pszFilename, offName);984 else985 rc = scmSettingsBaseParseStringN(&pSettings->Base, pchLine, cchLine, pszFilename, offName);986 if (RT_FAILURE(rc))987 {988 RTMsgError("%s:%d: %Rrc\n", pszFilename, ScmStreamTellLine(&Stream), rc);989 break;990 }991 }992 993 if (RT_SUCCESS(rc))994 {995 rc = ScmStreamGetStatus(&Stream);996 if (RT_FAILURE(rc))997 RTMsgError("%s: ScmStreamGetStatus- > %Rrc\n", pszFilename, rc);998 }999 1000 ScmStreamDelete(&Stream);1001 1003 return rc; 1002 1004 } … … 1082 1084 if (RTFileExists(szFile)) 1083 1085 { 1084 rc = scmSettingsLoadFile(pSettings, szFile , RTPathFilename(szFile) - &szFile[0]);1086 rc = scmSettingsLoadFile(pSettings, szFile); 1085 1087 if (RT_FAILURE(rc)) 1086 1088 break; … … 1136 1138 { 1137 1139 if (RTFileExists(szFile)) 1138 rc = scmSettingsLoadFile(pSettings, szFile , RTPathFilename(szFile) - &szFile[0]);1140 rc = scmSettingsLoadFile(pSettings, szFile); 1139 1141 if (RT_SUCCESS(rc)) 1140 1142 {
Note:
See TracChangeset
for help on using the changeset viewer.