Changeset 76551 in vbox for trunk/src/bldprogs/scmrw.cpp
- Timestamp:
- Dec 31, 2018 5:09:06 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bldprogs/scmrw.cpp
r76512 r76551 2862 2862 return false; 2863 2863 2864 int rc;2865 bool fRet = false;2866 2864 RTERRINFOSTATIC ErrInfo; 2865 char szNormalized[168]; 2866 size_t cchNormalized; 2867 int rc; 2868 bool fRet = false; 2869 2870 /* 2871 * Calculate the expected guard for this file, if so tasked. 2872 * ASSUMES pState->pszFilename is absolute as is pSettings->pszGuardRelativeToDir. 2873 */ 2874 szNormalized[0] = '\0'; 2875 if (pSettings->pszGuardRelativeToDir) 2876 { 2877 rc = RTStrCopy(szNormalized, sizeof(szNormalized), pSettings->pszGuardPrefix); 2878 if (RT_FAILURE(rc)) 2879 return ScmError(pState, rc, "Guard prefix too long (or something): %s\n", pSettings->pszGuardPrefix); 2880 cchNormalized = strlen(szNormalized); 2881 rc = RTPathCalcRelative(&szNormalized[cchNormalized], sizeof(szNormalized) - cchNormalized, 2882 pSettings->pszGuardRelativeToDir, pState->pszFilename); 2883 if (RT_FAILURE(rc)) 2884 return ScmError(pState, rc, "Error calculating guard prefix (RTPathCalcRelative): %Rrc\n", rc); 2885 char ch; 2886 while ((ch = szNormalized[cchNormalized]) != '\0') 2887 { 2888 if (!ScmIsCIdentifierChar(ch)) 2889 szNormalized[cchNormalized] = '_'; 2890 cchNormalized++; 2891 } 2892 } 2867 2893 2868 2894 /* … … 2872 2898 * and will be upset if this isn't the case. 2873 2899 */ 2900 RTSTRTUPLE Guard = { NULL, 0 }; 2874 2901 uint32_t cBlankLines = 0; 2875 2902 SCMEOL enmEol; … … 2895 2922 { RT_STR_TUPLE(""), 0, true, false }, 2896 2923 }; 2897 RTSTRTUPLE Guard;2898 2924 rc = ScmMatchWords(pchLine, cchLine, s_aIfndefGuard, RT_ELEMENTS(s_aIfndefGuard), 2899 2925 NULL /*poffNext*/, &Guard, RTErrInfoInitStatic(&ErrInfo)); … … 2902 2928 ScmStreamTellLine(pIn) - 1, ErrInfo.Core.pszMsg, cchLine, pchLine); 2903 2929 fRet |= rc != VINF_SUCCESS; 2904 ScmVerbose(pState, 2, "line %u: #ifndef %.*s\n", ScmStreamTellLine(pIn) - 1, Guard.cch, Guard.psz); 2930 ScmVerbose(pState, 3, "line %u in %s: #ifndef %.*s\n", 2931 ScmStreamTellLine(pIn) - 1, pState->pszFilename, Guard.cch, Guard.psz); 2905 2932 2906 2933 /* #define xxxx */ … … 2924 2951 fRet |= rc != VINF_SUCCESS; 2925 2952 2953 if (Guard.cch >= sizeof(szNormalized)) 2954 return ScmError(pState, VERR_BUFFER_OVERFLOW, "%u: Guard macro too long! %.*s\n", 2955 ScmStreamTellLine(pIn) - 2, Guard.cch, Guard.psz); 2956 2957 if (szNormalized[0] != '\0') 2958 { 2959 fRet = Guard.cch != cchNormalized || memcmp(Guard.psz, szNormalized, cchNormalized) != 0; 2960 Guard.psz = szNormalized; 2961 Guard.cch = cchNormalized; 2962 } 2963 2926 2964 /* 2927 2965 * Write guard, making sure we've got a single blank line preceeding it. … … 3046 3084 * looking for the last #endif in the file. 3047 3085 */ 3048 size_t iEndIf = 0; 3086 size_t iEndIfIn = 0; 3087 size_t iEndIfOut = 0; 3049 3088 while ((pchLine = ScmStreamGetLine(pIn, &cchLine, &enmEol)) != NULL) 3050 3089 { … … 3059 3098 off++; 3060 3099 /* #pragma once */ 3061 if (off + sizeof("pragma") < cchLine && !memcmp(&pchLine[off], RT_STR_TUPLE("pragma"))) 3100 if ( off + sizeof("pragma") - 1 <= cchLine 3101 && !memcmp(&pchLine[off], RT_STR_TUPLE("pragma"))) 3062 3102 { 3063 3103 rc = ScmMatchWords(pchLine, cchLine, s_aPragmaOnce, RT_ELEMENTS(s_aPragmaOnce), … … 3070 3110 } 3071 3111 /* #endif */ 3072 else if (off + sizeof("endif") < cchLine && !memcmp(&pchLine[off], RT_STR_TUPLE("endif"))) 3073 iEndIf = ScmStreamTellLine(pOut); 3112 else if ( off + sizeof("endif") - 1 <= cchLine 3113 && !memcmp(&pchLine[off], RT_STR_TUPLE("endif"))) 3114 { 3115 iEndIfIn = ScmStreamTellLine(pIn) - 1; 3116 iEndIfOut = ScmStreamTellLine(pOut); 3117 } 3074 3118 } 3075 3119 } … … 3084 3128 * right kind of comment following it. 3085 3129 */ 3086 /** @todo \#endif */ 3130 #if 0 3131 if (iEndIfOut == 0) 3132 return ScmError(pState, VERR_PARSE_ERROR, "Expected '#endif' at the end of the file...\n"); 3133 rc = ScmStreamSeekByLine(pIn, iEndIfIn); 3134 if (RT_FAILURE(rc)) 3135 return false; 3136 rc = ScmStreamSeekByLine(pOut, iEndIfOut); 3137 if (RT_FAILURE(rc)) 3138 return false; 3139 3140 pchLine = ScmStreamGetLine(pIn, &cchLine, &enmEol); 3141 if (!pchLine) 3142 return ScmError(pState, VERR_INTERNAL_ERROR, "ScmStreamGetLine failed re-reading #endif!\n"); 3143 3144 char szTmp[64 + sizeof(szNormalized)]; 3145 size_t cchTmp; 3146 if (pSettings->fEndifGuardComment) 3147 cchTmp = RTStrPrintf(szTmp, sizeof(szTmp), "#endif /* !%.*s */", Guard.cch, Guard.psz); 3148 else 3149 cchTmp = RTStrPrintf(szTmp, sizeof(szTmp), "#endif"); /* lazy bird */ 3150 fRet |= cchTmp != cchLine || memcmp(szTmp, pchLine, cchTmp) != 0; 3151 rc = ScmStreamPutLine(pOut, szTmp, cchTmp, enmEol); 3152 if (RT_FAILURE(rc)) 3153 return false; 3154 3155 /* Copy out the remaining lines (assumes no #pragma once here). */ 3156 while ((pchLine = ScmStreamGetLine(pIn, &cchLine, &enmEol)) != NULL) 3157 { 3158 rc = ScmStreamPutLine(pOut, pchLine, cchLine, enmEol); 3159 if (RT_FAILURE(rc)) 3160 return false; 3161 } 3162 #else 3163 RT_NOREF(iEndIfOut, iEndIfIn); 3164 #endif 3087 3165 3088 3166 return fRet;
Note:
See TracChangeset
for help on using the changeset viewer.