Changeset 63559 in vbox for trunk/src/bldprogs
- Timestamp:
- Aug 16, 2016 2:00:43 PM (8 years ago)
- Location:
- trunk/src/bldprogs
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bldprogs/scm.cpp
r62884 r63559 75 75 SCMOPT_FIX_FLOWER_BOX_MARKERS, 76 76 SCMOPT_NO_FIX_FLOWER_BOX_MARKERS, 77 SCMOPT_FIX_TODOS, 78 SCMOPT_NO_FIX_TODOS, 77 79 SCMOPT_MIN_BLANK_LINES_BEFORE_FLOWER_BOX_MARKERS, 78 80 SCMOPT_ONLY_SVN_DIRS, … … 139 141 /* .fFixFlowerBoxMarkers = */ true, 140 142 /* .cMinBlankLinesBeforeFlowerBoxMakers = */ 2, 143 /* .fFixTodos = */ true, 141 144 /* .fOnlySvnFiles = */ false, 142 145 /* .fOnlySvnDirs = */ false, … … 169 172 { "--fix-flower-box-markers", SCMOPT_FIX_FLOWER_BOX_MARKERS, RTGETOPT_REQ_NOTHING }, 170 173 { "--no-fix-flower-box-markers", SCMOPT_NO_FIX_FLOWER_BOX_MARKERS, RTGETOPT_REQ_NOTHING }, 174 { "--fix-todos", SCMOPT_FIX_TODOS, RTGETOPT_REQ_NOTHING }, 175 { "--no-fix-todos", SCMOPT_NO_FIX_TODOS, RTGETOPT_REQ_NOTHING }, 171 176 { "--only-svn-dirs", SCMOPT_ONLY_SVN_DIRS, RTGETOPT_REQ_NOTHING }, 172 177 { "--not-only-svn-dirs", SCMOPT_NOT_ONLY_SVN_DIRS, RTGETOPT_REQ_NOTHING }, … … 214 219 rewrite_SvnKeywords, 215 220 rewrite_FixFlowerBoxMarkers, 221 rewrite_Fix_C_and_CPP_Todos, 216 222 rewrite_C_and_CPP 217 223 }; -
trunk/src/bldprogs/scm.h
r62537 r63559 107 107 FNSCMREWRITER rewrite_Makefile_kmk; 108 108 FNSCMREWRITER rewrite_FixFlowerBoxMarkers; 109 FNSCMREWRITER rewrite_Fix_C_and_CPP_Todos; 109 110 FNSCMREWRITER rewrite_C_and_CPP; 110 111 … … 147 148 /** The minimum number of blank lines we want before flowerbox markers. */ 148 149 uint8_t cMinBlankLinesBeforeFlowerBoxMakers; 150 151 /** Whether to fix C/C++ todos. */ 152 bool fFixTodos; 149 153 150 154 /** Only process files that are part of a SVN working copy. */ -
trunk/src/bldprogs/scmrw.cpp
r62854 r63559 651 651 return cChanges != 0; 652 652 } 653 654 655 /** 656 * Looks for the start of a todo comment. 657 * 658 * @returns Offset into the line of the comment start sequence. 659 * @param pchLine The line to search. 660 * @param cchLineBeforeTodo The length of the line before the todo. 661 * @param pfSameLine Indicates whether it's refering to a statemtn on 662 * the same line comment (true), or the next 663 * statement (false). 664 */ 665 static size_t findTodoCommentStart(char const *pchLine, size_t cchLineBeforeTodo, bool *pfSameLine) 666 { 667 *pfSameLine = false; 668 669 /* Skip one '@' or '\\'. */ 670 char ch; 671 if ( cchLineBeforeTodo > 2 672 && ( (ch = pchLine[cchLineBeforeTodo - 1] == '@') 673 || ch == '\\' ) ) 674 cchLineBeforeTodo--; 675 676 /* Skip blanks. */ 677 while ( cchLineBeforeTodo > 2 678 && RT_C_IS_BLANK(pchLine[cchLineBeforeTodo - 1])) 679 cchLineBeforeTodo--; 680 681 /* Look for same line indicator. */ 682 if ( cchLineBeforeTodo > 0 683 && pchLine[cchLineBeforeTodo - 1] == '<') 684 { 685 *pfSameLine = true; 686 cchLineBeforeTodo--; 687 } 688 689 /* Skip *s */ 690 while ( cchLineBeforeTodo > 1 691 && pchLine[cchLineBeforeTodo - 1] == '*') 692 cchLineBeforeTodo--; 693 694 /* Do we have a comment opening sequence. */ 695 if ( cchLineBeforeTodo > 0 696 && pchLine[cchLineBeforeTodo - 1] == '/' 697 && ( ( cchLineBeforeTodo >= 2 698 && pchLine[cchLineBeforeTodo - 2] == '/') 699 || pchLine[cchLineBeforeTodo] == '*')) 700 { 701 /* Skip slashes at the start. */ 702 while ( cchLineBeforeTodo > 0 703 && pchLine[cchLineBeforeTodo - 1] == '/') 704 cchLineBeforeTodo--; 705 706 return cchLineBeforeTodo; 707 } 708 709 return ~(size_t)0; 710 } 711 712 713 /** 714 * Looks for a TODO or todo in the given line. 715 * 716 * @returns Offset into the line of found, ~(size_t)0 if not. 717 * @param pchLine The line to search. 718 * @param cchLine The length of the line. 719 */ 720 static size_t findTodo(char const *pchLine, size_t cchLine) 721 { 722 if (cchLine >= 4 + 2) 723 { 724 /* We don't search the first to chars because we need the start of a comment. 725 Also, skip the last three chars since we need at least four for a match. */ 726 size_t const cchLineT = cchLine - 3; 727 if ( memchr(pchLine + 2, 't', cchLineT - 2) != NULL 728 || memchr(pchLine + 2, 'T', cchLineT - 2) != NULL) 729 { 730 for (size_t off = 2; off < cchLineT; off++) 731 { 732 char ch = pchLine[off]; 733 if ( ( ch != 't' 734 && ch != 'T') 735 || ( (ch = pchLine[off + 1]) != 'o' 736 && ch != 'O') 737 || ( (ch = pchLine[off + 2]) != 'd' 738 && ch != 'D') 739 || ( (ch = pchLine[off + 3]) != 'o' 740 && ch != 'O') 741 || ( off + 4 != cchLine 742 && (ch = pchLine[off + 4]) != ' ' 743 && ch != '\t' 744 && ch != ':' /* todo: */ 745 && (ch != '*' || off + 5 > cchLine || pchLine[off + 5] != '/') /*todo*/ 746 ) ) 747 { /* not a hit - likely */ } 748 else 749 return off; 750 } 751 } 752 } 753 return ~(size_t)0; 754 } 755 756 757 /** 758 * Flower box marker comments in C and C++ code. 759 * 760 * @returns true if modifications were made, false if not. 761 * @param pIn The input stream. 762 * @param pOut The output stream. 763 * @param pSettings The settings. 764 */ 765 bool rewrite_Fix_C_and_CPP_Todos(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings) 766 { 767 if (!pSettings->fFixTodos) 768 return false; 769 770 /* 771 * Work thru the file line by line looking for the start of todo comments. 772 */ 773 size_t cChanges = 0; 774 SCMEOL enmEol; 775 size_t cchLine; 776 const char *pchLine; 777 while ((pchLine = ScmStreamGetLine(pIn, &cchLine, &enmEol)) != NULL) 778 { 779 /* 780 * Look for the word 'todo' in the line. We're currently only trying 781 * to catch comments starting with the word todo and adjust the start of 782 * the doxygen statement. 783 */ 784 size_t offTodo = findTodo(pchLine, cchLine); 785 if ( offTodo != ~(size_t)0 786 && offTodo >= 2) 787 { 788 /* Work backwards to find the start of the comment. */ 789 bool fSameLine = false; 790 size_t offCommentStart = findTodoCommentStart(pchLine, offTodo, &fSameLine); 791 if (offCommentStart != ~(size_t)0) 792 { 793 char szNew[64]; 794 size_t cchNew = 0; 795 szNew[cchNew++] = '/'; 796 szNew[cchNew++] = pchLine[offCommentStart + 1]; 797 szNew[cchNew++] = pchLine[offCommentStart + 1]; 798 if (fSameLine) 799 szNew[cchNew++] = '<'; 800 szNew[cchNew++] = ' '; 801 szNew[cchNew++] = '@'; 802 szNew[cchNew++] = 't'; 803 szNew[cchNew++] = 'o'; 804 szNew[cchNew++] = 'd'; 805 szNew[cchNew++] = 'o'; 806 807 /* Figure out wheter to continue after the @todo statement opening, we'll strip ':' 808 but need to take into account that we might be at the end of the line before 809 adding the space. */ 810 size_t offTodoAfter = offTodo + 4; 811 if ( offTodoAfter < cchLine 812 && pchLine[offTodoAfter] == ':') 813 offTodoAfter++; 814 if ( offTodoAfter < cchLine 815 && RT_C_IS_BLANK(pchLine[offTodoAfter])) 816 offTodoAfter++; 817 if (offTodoAfter < cchLine) 818 szNew[cchNew++] = ' '; 819 820 /* Write it out. */ 821 ScmStreamWrite(pOut, pchLine, offCommentStart); 822 ScmStreamWrite(pOut, szNew, cchNew); 823 if (offTodoAfter < cchLine) 824 ScmStreamWrite(pOut, &pchLine[offTodoAfter], cchLine - offTodoAfter); 825 ScmStreamPutEol(pOut, enmEol); 826 827 /* Check whether we actually made any changes. */ 828 if ( cchNew != offTodoAfter - offCommentStart 829 || memcmp(szNew, &pchLine[offCommentStart], cchNew)) 830 cChanges++; 831 continue; 832 } 833 } 834 835 int rc = ScmStreamPutLine(pOut, pchLine, cchLine, enmEol); 836 if (RT_FAILURE(rc)) 837 return false; 838 } 839 if (cChanges > 0) 840 ScmVerbose(pState, 2, " * Converted %zu todo statements.\n", cChanges); 841 return cChanges != 0; 842 } 843 653 844 654 845 /**
Note:
See TracChangeset
for help on using the changeset viewer.