Changeset 76551 in vbox
- Timestamp:
- Dec 31, 2018 5:09:06 AM (6 years ago)
- Location:
- trunk/src/bldprogs
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bldprogs/scm.cpp
r76547 r76551 79 79 SCMOPT_PRAGMA_ONCE, 80 80 SCMOPT_NO_PRAGMA_ONCE, 81 SCMOPT_ENDIF_GUARD_COMMENT, 82 SCMOPT_NO_ENDIF_GUARD_COMMENT, 83 SCMOPT_GUARD_PREFIX, 84 SCMOPT_GUARD_RELATIVE_TO_DIR, 81 85 SCMOPT_FIX_TODOS, 82 86 SCMOPT_NO_FIX_TODOS, … … 181 185 /* .fFixHeaderGuards = */ true, 182 186 /* .fPragmaOnce = */ true, 187 /* .fEndifGuardComment = */ true, 188 /* .pszGuardPrefix = */ (char *)"VBOX_INCLUDED_", 189 /* .pszGuardRelativeToDir = */ NULL, 183 190 /* .fFixTodos = */ true, 184 191 /* .fFixErrH = */ true, … … 225 232 { "--pragma-once", SCMOPT_PRAGMA_ONCE, RTGETOPT_REQ_NOTHING }, 226 233 { "--no-pragma-once", SCMOPT_NO_PRAGMA_ONCE, RTGETOPT_REQ_NOTHING }, 234 { "--endif-guard-comment", SCMOPT_ENDIF_GUARD_COMMENT, RTGETOPT_REQ_NOTHING }, 235 { "--no-endif-guard-comment", SCMOPT_NO_ENDIF_GUARD_COMMENT, RTGETOPT_REQ_NOTHING }, 236 { "--guard-prefix", SCMOPT_GUARD_PREFIX, RTGETOPT_REQ_STRING }, 237 { "--guard-relative-to-dir", SCMOPT_GUARD_RELATIVE_TO_DIR, RTGETOPT_REQ_STRING }, 227 238 { "--fix-todos", SCMOPT_FIX_TODOS, RTGETOPT_REQ_NOTHING }, 228 239 { "--no-fix-todos", SCMOPT_NO_FIX_TODOS, RTGETOPT_REQ_NOTHING }, … … 886 897 if (RT_SUCCESS(rc)) 887 898 { 888 if (!pSrc->fFreeTreatAs) 889 return VINF_SUCCESS; 890 891 pSettings->pTreatAs = scmCfgEntryDup(pSrc->pTreatAs); 892 if (pSettings->pTreatAs) 893 return VINF_SUCCESS; 894 895 RTStrFree(pSettings->pszFilterOutDirs); 899 rc = RTStrDupEx(&pSettings->pszGuardPrefix, pSrc->pszGuardPrefix); 900 if (RT_SUCCESS(rc)) 901 { 902 if (pSrc->pszGuardRelativeToDir) 903 rc = RTStrDupEx(&pSettings->pszGuardRelativeToDir, pSrc->pszGuardRelativeToDir); 904 if (RT_SUCCESS(rc)) 905 { 906 907 if (!pSrc->fFreeTreatAs) 908 return VINF_SUCCESS; 909 910 pSettings->pTreatAs = scmCfgEntryDup(pSrc->pTreatAs); 911 if (pSettings->pTreatAs) 912 return VINF_SUCCESS; 913 914 RTStrFree(pSettings->pszGuardRelativeToDir); 915 } 916 RTStrFree(pSettings->pszGuardPrefix); 917 } 896 918 } 897 919 RTStrFree(pSettings->pszFilterOutFiles); … … 900 922 } 901 923 924 pSettings->pszGuardRelativeToDir = NULL; 925 pSettings->pszGuardPrefix = NULL; 902 926 pSettings->pszFilterFiles = NULL; 903 927 pSettings->pszFilterOutFiles = NULL; … … 930 954 pSettings->cchTab = UINT8_MAX; 931 955 956 RTStrFree(pSettings->pszGuardPrefix); 957 RTStrFree(pSettings->pszGuardRelativeToDir); 932 958 RTStrFree(pSettings->pszFilterFiles); 933 959 RTStrFree(pSettings->pszFilterOutFiles); … … 936 962 scmCfgEntryDelete((PSCMCFGENTRY)pSettings->pTreatAs); 937 963 964 pSettings->pszGuardPrefix = NULL; 965 pSettings->pszGuardRelativeToDir = NULL; 938 966 pSettings->pszFilterOutDirs = NULL; 939 967 pSettings->pszFilterOutFiles = NULL; … … 1032 1060 case SCMOPT_NO_PRAGMA_ONCE: 1033 1061 pSettings->fPragmaOnce = false; 1062 return VINF_SUCCESS; 1063 1064 case SCMOPT_ENDIF_GUARD_COMMENT: 1065 pSettings->fEndifGuardComment = true; 1066 return VINF_SUCCESS; 1067 case SCMOPT_NO_ENDIF_GUARD_COMMENT: 1068 pSettings->fEndifGuardComment = false; 1069 return VINF_SUCCESS; 1070 1071 case SCMOPT_GUARD_PREFIX: 1072 RTStrFree(pSettings->pszGuardPrefix); 1073 pSettings->pszGuardPrefix = NULL; 1074 return RTStrDupEx(&pSettings->pszGuardPrefix, pValueUnion->psz); 1075 1076 case SCMOPT_GUARD_RELATIVE_TO_DIR: 1077 RTStrFree(pSettings->pszGuardRelativeToDir); 1078 pSettings->pszGuardRelativeToDir = NULL; 1079 if (*pValueUnion->psz != '\0') 1080 { 1081 if (cchDir == 1 && *pchDir == '/') 1082 { 1083 pSettings->pszGuardRelativeToDir = RTPathAbsDup(pValueUnion->psz); 1084 if (pSettings->pszGuardRelativeToDir) 1085 return VINF_SUCCESS; 1086 } 1087 else 1088 { 1089 char *pszDir = RTStrDupN(pchDir, cchDir); 1090 if (pszDir) 1091 { 1092 pSettings->pszGuardRelativeToDir = RTPathAbsExDup(pszDir, pValueUnion->psz); 1093 RTStrFree(pszDir); 1094 if (pSettings->pszGuardRelativeToDir) 1095 return VINF_SUCCESS; 1096 } 1097 } 1098 RTMsgError("Failed to abspath --guard-relative-to-dir value '%s' - probably out of memory\n", pValueUnion->psz); 1099 return VERR_NO_STR_MEMORY; 1100 } 1034 1101 return VINF_SUCCESS; 1035 1102 … … 2708 2775 RTPrintf(" Whether to include #pragma once with the header guard. Default: %RTbool\n", g_Defaults.fPragmaOnce); 2709 2776 break; 2777 case SCMOPT_ENDIF_GUARD_COMMENT: 2778 RTPrintf(" Put a comment on the header guard #endif or not. Default: %RTbool\n", g_Defaults.fEndifGuardComment); 2779 break; 2780 case SCMOPT_GUARD_RELATIVE_TO_DIR: 2781 RTPrintf(" Header guard should be normalized relative to given dir.\n" 2782 " If empty no normalization takes place. Default: '%s'\n", g_Defaults.pszGuardRelativeToDir); 2783 break; 2784 case SCMOPT_GUARD_PREFIX: 2785 RTPrintf(" Prefix to use with --guard-relative-to-dir. Default: %s\n", g_Defaults.pszGuardPrefix); 2786 break; 2710 2787 case SCMOPT_FIX_TODOS: 2711 2788 RTPrintf(" Fix @todo statements so doxygen sees them. Default: %RTbool\n", g_Defaults.fFixTodos); -
trunk/src/bldprogs/scm.h
r76546 r76551 338 338 /** Whether to include a pragma once statement with the header guard. */ 339 339 bool fPragmaOnce; 340 /** Whether to add a comment on the \#endif part of the header guard. */ 341 bool fEndifGuardComment; 342 /** The guard name prefix. */ 343 char *pszGuardPrefix; 344 /** Header guards should be normalized using prefix and this directory. 345 * When NULL the guard identifiers found in the header is preserved. */ 346 char *pszGuardRelativeToDir; 340 347 341 348 /** Whether to fix C/C++ todos. */ -
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; -
trunk/src/bldprogs/scmstream.cpp
r76506 r76551 629 629 int ScmStreamSeekByLine(PSCMSTREAM pStream, size_t iLine) 630 630 { 631 AssertReturn(!pStream->fWriteOrRead, VERR_ACCESS_DENIED);632 631 if (RT_FAILURE(pStream->rc)) 633 632 return pStream->rc; … … 636 635 if (RT_UNLIKELY(!pStream->fFullyLineated)) 637 636 { 637 AssertReturn(!pStream->fWriteOrRead, VERR_ACCESS_DENIED); 638 638 int rc = scmStreamLineate(pStream); 639 639 if (RT_FAILURE(rc)) … … 644 644 if (iLine < pStream->cLines) 645 645 { 646 pStream->iLine = iLine; 646 647 pStream->off = pStream->paLines[iLine].off; 647 pStream->iLine = iLine; 648 if (pStream->fWriteOrRead) 649 { 650 pStream->cb = pStream->paLines[iLine].off; 651 pStream->cLines = iLine; 652 pStream->paLines[iLine].cch = 0; 653 pStream->paLines[iLine].enmEol = SCMEOL_NONE; 654 } 648 655 } 649 656 else 650 657 { 658 AssertReturn(!pStream->fWriteOrRead, VERR_ACCESS_DENIED); 651 659 pStream->off = pStream->cb; 652 660 pStream->iLine = pStream->cLines;
Note:
See TracChangeset
for help on using the changeset viewer.