Changeset 106747 in vbox
- Timestamp:
- Oct 28, 2024 1:55:40 PM (5 months ago)
- svn:sync-xref-src-repo-rev:
- 165631
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bldprogs/scmrw-kmk.cpp
r106061 r106747 666 666 static bool scmKmkHandleIfParentheses(KMKPARSER *pParser, size_t offToken, KMKTOKEN enmToken, size_t cchToken, bool fElse) 667 667 { 668 const char * constpchLine = pParser->pchLine;669 size_t constcchLine = pParser->cchLine;668 const char *pchLine = pParser->pchLine; 669 size_t cchLine = pParser->cchLine; 670 670 uint32_t const cchIndent = pParser->iActualDepth 671 671 - (fElse && pParser->iActualDepth > 0 && !pParser->aDepth[pParser->iDepth - 1].fIgnoreNesting); 672 const char * const pchToken = &pchLine[offToken]; 672 673 673 674 /* … … 688 689 * We do not allow line continuation for these. 689 690 */ 691 uint32_t cLines = 1; 692 size_t cchMaxLeadWord = 0; 693 size_t cchTotalLine = cchLine; 690 694 if (scmKmkIsLineWithContinuation(pchLine, cchLine)) 691 return scmKmkGiveUp(pParser, "Line continuation not allowed with '%.*s' directive.", cchToken, &pchLine[offToken]); 695 { 696 if (enmToken != kKmkToken_if1of && enmToken != kKmkToken_ifn1of) 697 return scmKmkGiveUp(pParser, "Line continuation not allowed with '%.*s' directive.", cchToken, pchToken); 698 cchTotalLine = scmKmkLineContinuationPeek(pParser, &cLines, &cchMaxLeadWord); 699 } 692 700 693 701 /* … … 695 703 * too long (it seriously should be). 696 704 */ 697 if (cch Line + cchIndent + 32 > sizeof(pParser->szBuf))698 return scmKmkGiveUp(pParser, "Line too long for a '%.*s' directive: %u chars", cchToken, &pchLine[offToken], cchLine);705 if (cchTotalLine + cchIndent + 32 > sizeof(pParser->szBuf)) 706 return scmKmkGiveUp(pParser, "Line too long for a '%.*s' directive: %u chars", cchToken, pchToken, cchTotalLine); 699 707 char *pszDst = pParser->szBuf; 700 708 … … 708 716 pszDst = (char *)mempcpy(pszDst, RT_STR_TUPLE("else ")); 709 717 710 memcpy(pszDst, &pchLine[offToken], cchToken);718 memcpy(pszDst, pchToken, cchToken); 711 719 pszDst += cchToken; 712 720 … … 723 731 offSrc++; 724 732 if (pchLine[offSrc] != '(') 725 return scmKmkGiveUp(pParser, "Expected '(' to follow '%.*s'", cchToken, &pchLine[offToken]);733 return scmKmkGiveUp(pParser, "Expected '(' to follow '%.*s'", cchToken, pchToken); 726 734 offSrc++; 727 735 } 728 736 *pszDst++ = ' '; 729 737 *pszDst++ = '('; 730 731 /* 732 * Skip spaces after the opening parenthesis. 738 size_t const offContIndent = pszDst - pParser->szBuf; 739 740 /* 741 * Skip spaces after the opening parenthesis. 742 * 743 * Note! We don't support/grok any line continuation stuff here. 733 744 */ 734 745 while (offSrc < cchLine && RT_C_IS_BLANK(pchLine[offSrc])) … … 737 748 /* 738 749 * Work up to the ',' separator. It shall likewise not be preceeded by any spaces. 739 * Need to take $(func 1,2,3) calls into account here, so we trac () and {} while 740 * skipping ahead. 750 * Need to take $(func 1,2,3) calls into account here, so we trac () and {} while 751 * skipping ahead. 752 * 753 * Note! We don't support/grok any line continuation stuff here. 741 754 */ 742 755 if (pchLine[offSrc] != ',') … … 745 758 offSrc = scmKmkSkipExpString(pchLine, cchLine, offSrc, ','); 746 759 if (pchLine[offSrc] != ',') 747 return scmKmkGiveUp(pParser, "Expected ',' somewhere after '%.*s('", cchToken, &pchLine[offToken]);760 return scmKmkGiveUp(pParser, "Expected ',' somewhere after '%.*s('", cchToken, pchToken); 748 761 749 762 size_t cchCopy = offSrc - offSrcStart; … … 755 768 /* 'if1of(, stuff)' does not make sense in committed code: */ 756 769 else if (enmToken == kKmkToken_if1of || enmToken == kKmkToken_ifn1of) 757 return scmKmkGiveUp(pParser, "Left set cannot be empty for '%.*s'", cchToken, &pchLine[offToken]);770 return scmKmkGiveUp(pParser, "Left set cannot be empty for '%.*s'", cchToken, pchToken); 758 771 offSrc++; 759 772 *pszDst++ = ','; … … 764 777 */ 765 778 if (enmToken == kKmkToken_if1of || enmToken == kKmkToken_ifn1of) 766 {767 779 *pszDst++ = ' '; 768 if (pchLine[offSrc] == ' ')769 offSrc++;770 }771 780 while (offSrc < cchLine && RT_C_IS_BLANK(pchLine[offSrc])) 772 781 offSrc++; … … 774 783 if (pchLine[offSrc] != ')') 775 784 { 776 size_t const offSrcStart = offSrc; 777 offSrc = scmKmkSkipExpString(pchLine, cchLine, offSrc, ')'); 778 if (pchLine[offSrc] != ')') 779 return scmKmkGiveUp(pParser, "No closing parenthesis for '%.*s'?", cchToken, &pchLine[offToken]); 780 781 size_t cchCopy = offSrc - offSrcStart; 782 while (cchCopy > 0 && RT_C_IS_BLANK(pchLine[offSrcStart + cchCopy - 1])) 783 cchCopy--; 784 785 pszDst = (char *)mempcpy(pszDst, &pchLine[offSrcStart], cchCopy); 785 do 786 { 787 if (pchLine[offSrc] == '\\' && offSrc + 1 == cchLine) 788 { 789 *pszDst++ = ' '; 790 *pszDst++ = '\\'; 791 *pszDst = '\0'; 792 ScmStreamPutLine(pParser->pOut, pParser->szBuf, pszDst - pParser->szBuf, pParser->enmEol); 793 pszDst = pParser->szBuf; 794 795 memset(pszDst, ' ', offContIndent); 796 pszDst += offContIndent; 797 798 pParser->pchLine = pchLine = ScmStreamGetLine(pParser->pIn, &pParser->cchLine, &pParser->enmEol); 799 cchLine = pParser->cchLine; 800 offSrc = 0; 801 while (offSrc < cchLine && RT_C_IS_BLANK(pchLine[offSrc])) 802 offSrc++; 803 cLines -= 1; 804 } 805 806 size_t const offSrcStart = offSrc; 807 offSrc = scmKmkSkipExpString(pchLine, cLines <= 1 ? cchLine : cchLine - 1, offSrc, ')'); 808 if (pchLine[offSrc] != ')' && cLines <= 1) 809 return scmKmkGiveUp(pParser, "No closing parenthesis for '%.*s'?", cchToken, pchToken); 810 811 size_t cchCopy = offSrc - offSrcStart; 812 while (cchCopy > 0 && RT_C_IS_BLANK(pchLine[offSrcStart + cchCopy - 1])) 813 cchCopy--; 814 815 pszDst = (char *)mempcpy(pszDst, &pchLine[offSrcStart], cchCopy); 816 } while (offSrc + 1 == cchLine && pchLine[offSrc] == '\\'); 786 817 } 787 818 /* 'if1of(stuff, )' does not make sense in committed code: */ 788 819 else if ( (enmToken == kKmkToken_if1of || enmToken == kKmkToken_ifn1of) 789 820 && !scmKmkHasCommentMarker(pchLine, cchLine, offSrc, RT_STR_TUPLE("scm:ignore-empty-if1of-set"))) 790 return scmKmkGiveUp(pParser, "Right set cannot be empty for '%.*s'", cchToken, &pchLine[offToken]);821 return scmKmkGiveUp(pParser, "Right set cannot be empty for '%.*s'", cchToken, pchToken); 791 822 offSrc++; 792 823 *pszDst++ = ')'; … … 842 873 843 874 /* 844 * We do not allow line continuation for these.875 * We do not allow line continuation for ifdef and ifndef, only if. 845 876 */ 846 877 uint32_t cLines = 1;
Note:
See TracChangeset
for help on using the changeset viewer.