Changeset 41186 in vbox for trunk/src/bldprogs/scmstream.cpp
- Timestamp:
- May 7, 2012 1:42:20 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bldprogs/scmstream.cpp
r41180 r41186 706 706 } 707 707 708 /** 709 * Get the current buffer pointer. 710 * 711 * @returns Buffer pointer on success, NULL on failure (asserted). 712 * @param pStream The stream. Must be in read mode. 713 */ 714 const char *ScmStreamGetCur(PSCMSTREAM pStream) 715 { 716 AssertReturn(!pStream->fWriteOrRead, NULL); 717 return pStream->pch + pStream->off; 718 } 708 719 709 720 /** … … 1109 1120 1110 1121 /** 1122 * Formats a string and writes it to the SCM stream. 1123 * 1124 * @returns The number of bytes written (>= 0). Negative value are IPRT error 1125 * status codes. 1126 * @param pStream The stream to write to. 1127 * @param pszFormat The format string. 1128 * @param va The arguments to format. 1129 */ 1130 ssize_t ScmStreamPrintfV(PSCMSTREAM pStream, const char *pszFormat, va_list va) 1131 { 1132 char *psz; 1133 ssize_t cch = RTStrAPrintfV(&psz, pszFormat, va); 1134 if (cch) 1135 { 1136 int rc = ScmStreamWrite(pStream, psz, cch); 1137 RTStrFree(psz); 1138 if (RT_FAILURE(rc)) 1139 cch = rc; 1140 } 1141 return cch; 1142 } 1143 1144 /** 1145 * Formats a string and writes it to the SCM stream. 1146 * 1147 * @returns The number of bytes written (>= 0). Negative value are IPRT error 1148 * status codes. 1149 * @param pStream The stream to write to. 1150 * @param pszFormat The format string. 1151 * @param ... The arguments to format. 1152 */ 1153 ssize_t ScmStreamPrintf(PSCMSTREAM pStream, const char *pszFormat, ...) 1154 { 1155 va_list va; 1156 va_start(va, pszFormat); 1157 ssize_t cch = ScmStreamPrintfV(pStream, pszFormat, va); 1158 va_end(va); 1159 return cch; 1160 } 1161 1162 /** 1111 1163 * Copies @a cLines from the @a pSrc stream onto the @a pDst stream. 1112 1164 * … … 1144 1196 } 1145 1197 1198 1199 /** 1200 * If the given C word is at off - 1, return @c true and skip beyond it, 1201 * otherwise return @c false. 1202 * 1203 * @retval true if the given C-word is at the current position minus one char. 1204 * The stream position changes. 1205 * @retval false if not. The stream position is unchanged. 1206 * 1207 * @param pStream The stream. 1208 * @param cchWord The length of the word. 1209 * @param pszWord The word. 1210 */ 1211 bool ScmStreamCMatchingWordM1(PSCMSTREAM pStream, const char *pszWord, size_t cchWord) 1212 { 1213 /* Check stream state. */ 1214 AssertReturn(!pStream->fWriteOrRead, false); 1215 AssertReturn(RT_SUCCESS(pStream->rc), false); 1216 AssertReturn(pStream->fFullyLineated, false); 1217 1218 /* Sufficient chars left on the line? */ 1219 size_t const iLine = pStream->iLine; 1220 AssertReturn(pStream->off > pStream->paLines[iLine].off, false); 1221 size_t const cchLeft = pStream->paLines[iLine].cch + pStream->paLines[iLine].off - (pStream->off - 1); 1222 if (cchWord > cchLeft) 1223 return false; 1224 1225 /* Do they match? */ 1226 const char *psz = &pStream->pch[pStream->off - 1]; 1227 if (memcmp(psz, pszWord, cchWord)) 1228 return false; 1229 1230 /* Is it the end of a C word? */ 1231 if (cchWord < cchLeft) 1232 { 1233 psz += cchWord; 1234 if (RT_C_IS_ALNUM(*psz) || *psz == '_') 1235 return false; 1236 } 1237 1238 /* Skip ahead. */ 1239 pStream->off += cchWord - 1; 1240 return true; 1241 } 1242 1243 /** 1244 * Get's the C word starting at the current position. 1245 * 1246 * @returns Pointer to the word on success and the stream position advanced to 1247 * the end of it. 1248 * NULL on failure, stream position normally unchanged. 1249 * @param pStream The stream to get the C word from. 1250 * @param pcchWord Where to return the word length. 1251 */ 1252 const char *ScmStreamCGetWord(PSCMSTREAM pStream, size_t *pcchWord) 1253 { 1254 /* Check stream state. */ 1255 AssertReturn(!pStream->fWriteOrRead, NULL); 1256 AssertReturn(RT_SUCCESS(pStream->rc), NULL); 1257 AssertReturn(pStream->fFullyLineated, NULL); 1258 1259 /* Get the number of chars left on the line and locate the current char. */ 1260 size_t const iLine = pStream->iLine; 1261 size_t const cchLeft = pStream->paLines[iLine].cch + pStream->paLines[iLine].off - pStream->off; 1262 const char *psz = &pStream->pch[pStream->off]; 1263 1264 /* Is it a leading C character. */ 1265 if (!RT_C_IS_ALPHA(*psz) && *psz == '_') 1266 return NULL; 1267 1268 /* Find the end of the word. */ 1269 char ch; 1270 size_t off = 1; 1271 while ( off < cchLeft 1272 && ( (ch = psz[off]) == '_' 1273 || RT_C_IS_ALNUM(ch))) 1274 off++; 1275 1276 pStream->off += off; 1277 *pcchWord = off; 1278 return psz; 1279 } 1280 1281 1282 /** 1283 * Get's the C word starting at the current position minus one. 1284 * 1285 * @returns Pointer to the word on success and the stream position advanced to 1286 * the end of it. 1287 * NULL on failure, stream position normally unchanged. 1288 * @param pStream The stream to get the C word from. 1289 * @param pcchWord Where to return the word length. 1290 */ 1291 const char *ScmStreamCGetWordM1(PSCMSTREAM pStream, size_t *pcchWord) 1292 { 1293 /* Check stream state. */ 1294 AssertReturn(!pStream->fWriteOrRead, NULL); 1295 AssertReturn(RT_SUCCESS(pStream->rc), NULL); 1296 AssertReturn(pStream->fFullyLineated, NULL); 1297 1298 /* Get the number of chars left on the line and locate the current char. */ 1299 size_t const iLine = pStream->iLine; 1300 size_t const cchLeft = pStream->paLines[iLine].cch + pStream->paLines[iLine].off - (pStream->off - 1); 1301 const char *psz = &pStream->pch[pStream->off - 1]; 1302 1303 /* Is it a leading C character. */ 1304 if (!RT_C_IS_ALPHA(*psz) && *psz == '_') 1305 return NULL; 1306 1307 /* Find the end of the word. */ 1308 char ch; 1309 size_t off = 1; 1310 while ( off < cchLeft 1311 && ( (ch = psz[off]) == '_' 1312 || RT_C_IS_ALNUM(ch))) 1313 off++; 1314 1315 pStream->off += off - 1; 1316 *pcchWord = off; 1317 return psz; 1318 } 1319 1320 1321
Note:
See TracChangeset
for help on using the changeset viewer.