Changeset 99039 in vbox
- Timestamp:
- Mar 18, 2023 9:03:37 PM (21 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bldprogs/scmrw-kmk.cpp
r99030 r99039 1305 1305 return false; 1306 1306 } 1307 1308 1309 /** 1310 * Scans the given line segment for variable expansion and updates the state 1311 * accordingly. 1312 * 1313 * @returns New cExpandNesting value. 1314 * @param cExpandNesting Current variable expansion nesting 1315 * level. 1316 * @param achExpandingNestingClose String with the closing character for 1317 * each expansion level. 256 chars. 1318 * @param pchLine The string to scan. 1319 * @param cchLine Length to scan. 1320 */ 1321 static unsigned scmKmkScanStringForExpansions(unsigned cExpandNesting, char achExpandNestingClose[256], 1322 const char *pchLine, size_t cchLine) 1323 { 1324 while (cchLine-- > 0) 1325 { 1326 char ch = *pchLine++; 1327 switch (ch) 1328 { 1329 case '$': 1330 { 1331 size_t cDollars = 1; 1332 while (cchLine > 0 && (ch = *pchLine) == '$') 1333 cDollars++, pchLine++, cchLine--; 1334 if ((cDollars & 1) && cchLine > 0 && (ch == '{' || ch == '(')) 1335 { 1336 if (cExpandNesting < 256) 1337 achExpandNestingClose[cExpandNesting] = ch == '(' ? ')' : '}'; 1338 cExpandNesting++; 1339 pchLine++; 1340 cchLine--; 1341 } 1342 break; 1343 } 1344 1345 case ')': 1346 case '}': 1347 if (cExpandNesting > 0 && (cExpandNesting > 256 || ch == achExpandNestingClose[cExpandNesting - 1])) 1348 cExpandNesting--; 1349 break; 1350 } 1351 } 1352 return cExpandNesting; 1353 } 1354 1307 1355 1308 1356 /** … … 1438 1486 1439 1487 /** @todo this block can probably be merged into the final loop below. */ 1440 unsigned cPendingEols = 0;1488 unsigned cPendingEols = 0; 1441 1489 while (iSubLine + 1 < cLines && offLine + 1 == cchLine && pchLine[offLine] == '\\') 1442 1490 { … … 1464 1512 * Okay, we've gotten to the value / comment part. 1465 1513 */ 1514 char achExpandNestingClose[256]; 1515 unsigned cExpandNesting = 0; 1466 1516 for (;;) 1467 1517 { … … 1503 1553 memset(pszDst, ' ', cchIndent); 1504 1554 pszDst += cchIndent; 1505 *pszDst++ = '\t'; 1555 1556 size_t cTabIndent = cExpandNesting + 1; 1557 while (cTabIndent-- > 0) 1558 *pszDst++ = '\t'; 1559 1506 1560 cPendingEols--; 1507 1561 } while (cPendingEols > 0); … … 1517 1571 /* Append the value part we found. */ 1518 1572 pszDst = (char *)mempcpy(pszDst, &pchLine[offLine], offValueEnd - offLine); 1573 cExpandNesting = scmKmkScanStringForExpansions(cExpandNesting, achExpandNestingClose, 1574 &pchLine[offLine], offValueEnd - offLine); 1519 1575 offLine = offValueEnd2; 1520 1576 }
Note:
See TracChangeset
for help on using the changeset viewer.