- Timestamp:
- Feb 2, 2023 12:03:20 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bldprogs/scmrw-kmk.cpp
r98407 r98428 76 76 /** Dependency file. 77 77 * Separators: space, '|' */ 78 kKmkWordCtx_DepFile 78 kKmkWordCtx_DepFile, 79 /** Last context which may do double expansion. */ 80 kKmkWordCtx_LastDoubleExpansion = kKmkWordCtx_DepFile 79 81 } KMKWORDCTX; 80 82 … … 158 160 } KMKPARSER; 159 161 162 163 /********************************************************************************************************************************* 164 * Global Variables * 165 *********************************************************************************************************************************/ 166 static char const g_szTabs[] = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"; 160 167 161 168 … … 472 479 { 473 480 /* 474 * Skip variable expansion. 481 * Skip variable expansion. ASSUMING double expansion being enabled 482 * for rules, we respond to both $() and $$() here, $$$$() 475 483 */ 476 if (off + 2 >= cchLine) 477 return cchLine - offStart; 478 char const chOpen = pchLine[++off]; 479 if (chOpen == '(' || chOpen == '{') 484 size_t cDollars = 0; 485 do 480 486 { 481 char const chClose = chOpen == '(' ? ')' : '}';482 unsigned uDepth = 1;483 487 off++; 484 for (;;) 488 if (off >= cchLine) 489 return cchLine - offStart; 490 cDollars++; 491 ch = pchLine[off]; 492 } while (ch == '$'); 493 if ((cDollars & 1) || (cDollars == 2 && enmCtx <= kKmkWordCtx_LastDoubleExpansion)) 494 { 495 char const chOpen = ch; 496 if (ch == '(' || ch == '{') 485 497 { 486 if (off < cchLine) 487 ch = pchLine[off++]; 488 else /* Reached the end while inside the expansion. */ 498 char const chClose = chOpen == '(' ? ')' : '}'; 499 unsigned uDepth = 1; 500 off++; 501 for (;;) 489 502 { 490 pState->chOpen = chOpen; 491 pState->uDepth = (uint16_t)uDepth; 492 return cchLine - offStart; 503 if (off < cchLine) 504 ch = pchLine[off++]; 505 else /* Reached the end while inside the expansion. */ 506 { 507 pState->chOpen = chOpen; 508 pState->uDepth = (uint16_t)uDepth; 509 return cchLine - offStart; 510 } 511 if (ch == chOpen) 512 uDepth++; 513 else if (ch == chClose && --uDepth == 0) 514 break; 493 515 } 494 if (ch == chOpen)495 uDepth++;496 else if (ch == chClose && --uDepth == 0)497 break;498 516 } 499 continue; 517 else if (cDollars & 1) 518 off++; /* $X */ 500 519 } 501 /* else: $X */520 continue; 502 521 } 503 522 else if (ch == ':') … … 1581 1600 * Process word by word past the colon, taking new lines into account. 1582 1601 */ 1583 KMKWORDSTATE WordState = { 0, 0 };1584 KMKWORDCTX enmCtx = kKmkWordCtx_TargetFileOrAssignment;1585 bool fPendingEol = false;1602 KMKWORDSTATE WordState = { 0, 0 }; 1603 KMKWORDCTX enmCtx = kKmkWordCtx_TargetFileOrAssignment; 1604 unsigned cPendingEols = 0; 1586 1605 for (;;) 1587 1606 { … … 1650 1669 ScmStreamPutCh(pOut, ':'); 1651 1670 1652 fPendingEol = true;1671 cPendingEols = 1; 1653 1672 } 1654 1673 else … … 1657 1676 ScmStreamPutEol(pOut, pParser->enmEol); 1658 1677 ScmStreamWrite(pOut, g_szSpaces, cchIndent); 1678 if (WordState.uDepth > 0) 1679 ScmStreamWrite(pOut, g_szTabs, RT_MIN(WordState.uDepth, sizeof(g_szTabs) - 1)); 1659 1680 } 1660 1681 break; … … 1679 1700 while (offLine + 1 == cchLine && pchLine[offLine] == '\\') 1680 1701 { 1681 fPendingEol = true;1702 cPendingEols = 1; 1682 1703 1683 1704 Assert(iSubLine + 1 < cLines); … … 1716 1737 { 1717 1738 /* Indent the next word. */ 1718 if ( !fPendingEol)1739 if (cPendingEols == 0) 1719 1740 ScmStreamPutCh(pOut, ' '); 1720 1741 else … … 1724 1745 ScmStreamWrite(pOut, g_szSpaces, cchIndent); 1725 1746 ScmStreamWrite(pOut, RT_STR_TUPLE("\t\t")); 1726 fPendingEol = false; 1727 } 1747 if (cPendingEols > 1) 1748 { 1749 ScmStreamWrite(pOut, RT_STR_TUPLE("\\")); 1750 ScmStreamPutEol(pOut, pParser->enmEol); 1751 ScmStreamWrite(pOut, g_szSpaces, cchIndent); 1752 ScmStreamWrite(pOut, RT_STR_TUPLE("\t\t")); 1753 } 1754 cPendingEols = 0; 1755 } 1756 if (WordState.uDepth > 0) 1757 ScmStreamWrite(pOut, g_szTabs, RT_MIN(WordState.uDepth, sizeof(g_szTabs) - 1)); 1728 1758 1729 1759 /* Get the next word and output it. */ … … 1742 1772 { 1743 1773 /* Get the next input line. */ 1744 unsigned cEmptyLines = 0;1745 1774 for (;;) 1746 1775 { … … 1759 1788 1760 1789 /* Just drop empty lines, we'll re-add one of them afterward if we find more dependencies. */ 1790 cPendingEols++; 1761 1791 if (offLine + 1 == cchLine && pchLine[offLine] == '\\') 1762 {1763 cEmptyLines++;1764 1792 continue; 1765 }1766 1767 fPendingEol = true;1768 1793 break; 1769 1794 } … … 2160 2185 2161 2186 /* 2162 * Indent comment lines, unless the comment is too far into the line and such.2187 * Indent comment lines, unless the comment is too far too the right. 2163 2188 */ 2164 2189 size_t const offEffLine = ScmCalcSpacesForSrcSpan(pchLine, 0, offLine, pSettings);
Note:
See TracChangeset
for help on using the changeset viewer.