Fossil SCM
Rework the command-line arguments to the "fossil test-comment-format" command.
Commit
2b2bc057f6a8ce7847e40d8213ed0586bbdff28d0370bf33dc66eb10875b2eeb
Parent
9813e6f85d5d51e…
1 file changed
+62
-45
+62
-45
| --- src/comformat.c | ||
| +++ src/comformat.c | ||
| @@ -729,59 +729,70 @@ | ||
| 729 | 729 | |
| 730 | 730 | /* |
| 731 | 731 | ** |
| 732 | 732 | ** COMMAND: test-comment-format |
| 733 | 733 | ** |
| 734 | -** Usage: %fossil test-comment-format ?OPTIONS? PREFIX TEXT ?ORIGTEXT? | |
| 734 | +** Usage: %fossil test-comment-format [OPTIONS] TEXT [PREFIX] [ORIGTEXT] | |
| 735 | 735 | ** |
| 736 | 736 | ** Test comment formatting and printing. Use for testing only. |
| 737 | 737 | ** |
| 738 | +** The default (canonical) formatting algorithm is: | |
| 739 | +** | |
| 740 | +** * Omit leading/trailing whitespace | |
| 741 | +** * Collapse internal whitespace into a single space character. | |
| 742 | +** * Attempt to break lines at whitespace or at a hyphen. | |
| 743 | +** | |
| 744 | +** Use --whitespace, --origbreak, --trimcrlf, --trimspace, | |
| 745 | +** and/or --wordbreak to disable the canonical processing and do | |
| 746 | +** the special processing specified by those other options. | |
| 747 | +** | |
| 738 | 748 | ** Options: |
| 739 | -** --canonical Use the canonical comment printing algorithm: | |
| 740 | -** * Omit leading/trailing whitespace | |
| 741 | -** * Collapse internal whitespace into a single | |
| 742 | -** space character. | |
| 743 | -** * Attempt to break lines at whitespace or at | |
| 744 | -** a hyphen. | |
| 745 | -** --file The comment text is really just a file name to | |
| 746 | -** read it from | |
| 747 | -** --decode Decode the text using the same method used when | |
| 748 | -** handling the value of a C-card from a manifest. | |
| 749 | -** --indent Number of spaces to indent (default (-1) is to | |
| 750 | -** auto-detect). Zero means no indent. | |
| 751 | -** --origbreak Attempt to break when the original comment text | |
| 752 | -** is detected | |
| 753 | -** --trimcrlf Enable trimming of leading/trailing CR/LF | |
| 754 | -** --trimspace Enable trimming of leading/trailing spaces | |
| 755 | -** --wordbreak Attempt to break lines on word boundaries | |
| 756 | -** -W|--width NUM Width of lines (default (-1) is to auto-detect). | |
| 757 | -** Zero means no limit. | |
| 749 | +** --decode Decode the text using the same method used when | |
| 750 | +** handling the value of a C-card from a manifest. | |
| 751 | +** --file FILE Omit the TEXT argument and read the comment text | |
| 752 | +** from FILE. | |
| 753 | +** --indent Number of spaces to indent (default (-1) is to | |
| 754 | +** auto-detect). Zero means no indent. | |
| 755 | +** --orig FILE Take the value for the ORIGTEXT argumetn from FILE. | |
| 756 | +** --origbreak Attempt to break when the original comment text | |
| 757 | +** is detected. | |
| 758 | +** --trimcrlf Enable trimming of leading/trailing CR/LF. | |
| 759 | +** --trimspace Enable trimming of leading/trailing spaces. | |
| 760 | +** --whitespace Keep all internal whitespace. | |
| 761 | +** --wordbreak Attempt to break lines on word boundaries. | |
| 762 | +** -W|--width NUM Width of lines (default (-1) is to auto-detect). | |
| 763 | +** Zero means no limit. | |
| 758 | 764 | */ |
| 759 | 765 | void test_comment_format(void){ |
| 760 | 766 | const char *zWidth; |
| 761 | 767 | const char *zIndent; |
| 762 | - const char *zPrefix; | |
| 763 | - char *zText; | |
| 764 | - char *zOrigText; | |
| 768 | + const char *zPrefix = 0; | |
| 769 | + char *zText = 0; | |
| 770 | + char *zOrigText = 0; | |
| 765 | 771 | int indent, width; |
| 766 | - int fromFile = find_option("file", 0, 0)!=0; | |
| 772 | + int i; | |
| 773 | + const char *fromFile = find_option("file", 0, 1); | |
| 767 | 774 | int decode = find_option("decode", 0, 0)!=0; |
| 768 | - int flags = COMMENT_PRINT_NONE; | |
| 769 | - if( find_option("canonical",0,0) ){ | |
| 770 | - flags |= COMMENT_PRINT_CANONICAL; | |
| 775 | + int flags = COMMENT_PRINT_CANONICAL; | |
| 776 | + const char *fromOrig = find_option("orig", 0, 1); | |
| 777 | + if( find_option("whitespace",0,0) ){ | |
| 778 | + flags = 0; | |
| 771 | 779 | } |
| 772 | 780 | if( find_option("trimcrlf", 0, 0) ){ |
| 773 | - flags |= COMMENT_PRINT_TRIM_CRLF; | |
| 781 | + flags = COMMENT_PRINT_TRIM_CRLF; | |
| 774 | 782 | } |
| 775 | 783 | if( find_option("trimspace", 0, 0) ){ |
| 776 | 784 | flags |= COMMENT_PRINT_TRIM_SPACE; |
| 785 | + flags &= COMMENT_PRINT_CANONICAL; | |
| 777 | 786 | } |
| 778 | 787 | if( find_option("wordbreak", 0, 0) ){ |
| 779 | 788 | flags |= COMMENT_PRINT_WORD_BREAK; |
| 789 | + flags &= COMMENT_PRINT_CANONICAL; | |
| 780 | 790 | } |
| 781 | 791 | if( find_option("origbreak", 0, 0) ){ |
| 782 | 792 | flags |= COMMENT_PRINT_ORIG_BREAK; |
| 793 | + flags &= COMMENT_PRINT_CANONICAL; | |
| 783 | 794 | } |
| 784 | 795 | zWidth = find_option("width","W",1); |
| 785 | 796 | if( zWidth ){ |
| 786 | 797 | width = atoi(zWidth); |
| 787 | 798 | }else{ |
| @@ -792,45 +803,51 @@ | ||
| 792 | 803 | indent = atoi(zIndent); |
| 793 | 804 | }else{ |
| 794 | 805 | indent = -1; /* automatic */ |
| 795 | 806 | } |
| 796 | 807 | verify_all_options(); |
| 797 | - if( g.argc!=4 && g.argc!=5 ){ | |
| 798 | - usage("?OPTIONS? PREFIX TEXT ?ORIGTEXT?"); | |
| 799 | - } | |
| 800 | - zPrefix = g.argv[2]; | |
| 801 | - zText = g.argv[3]; | |
| 802 | - if( g.argc==5 ){ | |
| 803 | - zOrigText = g.argv[4]; | |
| 804 | - }else{ | |
| 805 | - zOrigText = 0; | |
| 806 | - } | |
| 808 | + zPrefix = zText = zOrigText = 0; | |
| 807 | 809 | if( fromFile ){ |
| 808 | 810 | Blob fileData; |
| 809 | - blob_read_from_file(&fileData, zText, ExtFILE); | |
| 811 | + blob_read_from_file(&fileData, fromFile, ExtFILE); | |
| 810 | 812 | zText = mprintf("%s", blob_str(&fileData)); |
| 811 | 813 | blob_reset(&fileData); |
| 812 | - if( zOrigText ){ | |
| 813 | - blob_read_from_file(&fileData, zOrigText, ExtFILE); | |
| 814 | - zOrigText = mprintf("%s", blob_str(&fileData)); | |
| 815 | - blob_reset(&fileData); | |
| 814 | + } | |
| 815 | + if( fromOrig ){ | |
| 816 | + Blob fileData; | |
| 817 | + blob_read_from_file(&fileData, fromOrig, ExtFILE); | |
| 818 | + zOrigText = mprintf("%s", blob_str(&fileData)); | |
| 819 | + blob_reset(&fileData); | |
| 820 | + } | |
| 821 | + for(i=2; i<g.argc; i++){ | |
| 822 | + if( zText==0 ){ | |
| 823 | + zText = g.argv[i]; | |
| 824 | + continue; | |
| 825 | + } | |
| 826 | + if( zPrefix==0 ){ | |
| 827 | + zPrefix = g.argv[i]; | |
| 828 | + continue; | |
| 829 | + } | |
| 830 | + if( zOrigText==0 ){ | |
| 831 | + zOrigText = g.argv[i]; | |
| 832 | + continue; | |
| 816 | 833 | } |
| 834 | + usage("[OPTIONS] TEXT [PREFIX] [ORIGTEXT]"); | |
| 817 | 835 | } |
| 818 | 836 | if( decode ){ |
| 819 | 837 | zText = mprintf(fromFile?"%z":"%s" /*works-like:"%s"*/, zText); |
| 820 | 838 | defossilize(zText); |
| 821 | 839 | if( zOrigText ){ |
| 822 | 840 | zOrigText = mprintf(fromFile?"%z":"%s" /*works-like:"%s"*/, zOrigText); |
| 823 | 841 | defossilize(zOrigText); |
| 824 | 842 | } |
| 825 | 843 | } |
| 844 | + if( zPrefix==0 ) zPrefix = "00:00:00 "; | |
| 826 | 845 | if( indent<0 ){ |
| 827 | 846 | indent = strlen(zPrefix); |
| 828 | 847 | } |
| 829 | 848 | if( zPrefix && *zPrefix ){ |
| 830 | 849 | fossil_print("%s", zPrefix); |
| 831 | 850 | } |
| 832 | 851 | fossil_print("(%d lines output)\n", |
| 833 | 852 | comment_print(zText, zOrigText, indent, width, flags)); |
| 834 | - if( zOrigText && zOrigText!=g.argv[4] ) fossil_free(zOrigText); | |
| 835 | - if( zText && zText!=g.argv[3] ) fossil_free(zText); | |
| 836 | 853 | } |
| 837 | 854 |
| --- src/comformat.c | |
| +++ src/comformat.c | |
| @@ -729,59 +729,70 @@ | |
| 729 | |
| 730 | /* |
| 731 | ** |
| 732 | ** COMMAND: test-comment-format |
| 733 | ** |
| 734 | ** Usage: %fossil test-comment-format ?OPTIONS? PREFIX TEXT ?ORIGTEXT? |
| 735 | ** |
| 736 | ** Test comment formatting and printing. Use for testing only. |
| 737 | ** |
| 738 | ** Options: |
| 739 | ** --canonical Use the canonical comment printing algorithm: |
| 740 | ** * Omit leading/trailing whitespace |
| 741 | ** * Collapse internal whitespace into a single |
| 742 | ** space character. |
| 743 | ** * Attempt to break lines at whitespace or at |
| 744 | ** a hyphen. |
| 745 | ** --file The comment text is really just a file name to |
| 746 | ** read it from |
| 747 | ** --decode Decode the text using the same method used when |
| 748 | ** handling the value of a C-card from a manifest. |
| 749 | ** --indent Number of spaces to indent (default (-1) is to |
| 750 | ** auto-detect). Zero means no indent. |
| 751 | ** --origbreak Attempt to break when the original comment text |
| 752 | ** is detected |
| 753 | ** --trimcrlf Enable trimming of leading/trailing CR/LF |
| 754 | ** --trimspace Enable trimming of leading/trailing spaces |
| 755 | ** --wordbreak Attempt to break lines on word boundaries |
| 756 | ** -W|--width NUM Width of lines (default (-1) is to auto-detect). |
| 757 | ** Zero means no limit. |
| 758 | */ |
| 759 | void test_comment_format(void){ |
| 760 | const char *zWidth; |
| 761 | const char *zIndent; |
| 762 | const char *zPrefix; |
| 763 | char *zText; |
| 764 | char *zOrigText; |
| 765 | int indent, width; |
| 766 | int fromFile = find_option("file", 0, 0)!=0; |
| 767 | int decode = find_option("decode", 0, 0)!=0; |
| 768 | int flags = COMMENT_PRINT_NONE; |
| 769 | if( find_option("canonical",0,0) ){ |
| 770 | flags |= COMMENT_PRINT_CANONICAL; |
| 771 | } |
| 772 | if( find_option("trimcrlf", 0, 0) ){ |
| 773 | flags |= COMMENT_PRINT_TRIM_CRLF; |
| 774 | } |
| 775 | if( find_option("trimspace", 0, 0) ){ |
| 776 | flags |= COMMENT_PRINT_TRIM_SPACE; |
| 777 | } |
| 778 | if( find_option("wordbreak", 0, 0) ){ |
| 779 | flags |= COMMENT_PRINT_WORD_BREAK; |
| 780 | } |
| 781 | if( find_option("origbreak", 0, 0) ){ |
| 782 | flags |= COMMENT_PRINT_ORIG_BREAK; |
| 783 | } |
| 784 | zWidth = find_option("width","W",1); |
| 785 | if( zWidth ){ |
| 786 | width = atoi(zWidth); |
| 787 | }else{ |
| @@ -792,45 +803,51 @@ | |
| 792 | indent = atoi(zIndent); |
| 793 | }else{ |
| 794 | indent = -1; /* automatic */ |
| 795 | } |
| 796 | verify_all_options(); |
| 797 | if( g.argc!=4 && g.argc!=5 ){ |
| 798 | usage("?OPTIONS? PREFIX TEXT ?ORIGTEXT?"); |
| 799 | } |
| 800 | zPrefix = g.argv[2]; |
| 801 | zText = g.argv[3]; |
| 802 | if( g.argc==5 ){ |
| 803 | zOrigText = g.argv[4]; |
| 804 | }else{ |
| 805 | zOrigText = 0; |
| 806 | } |
| 807 | if( fromFile ){ |
| 808 | Blob fileData; |
| 809 | blob_read_from_file(&fileData, zText, ExtFILE); |
| 810 | zText = mprintf("%s", blob_str(&fileData)); |
| 811 | blob_reset(&fileData); |
| 812 | if( zOrigText ){ |
| 813 | blob_read_from_file(&fileData, zOrigText, ExtFILE); |
| 814 | zOrigText = mprintf("%s", blob_str(&fileData)); |
| 815 | blob_reset(&fileData); |
| 816 | } |
| 817 | } |
| 818 | if( decode ){ |
| 819 | zText = mprintf(fromFile?"%z":"%s" /*works-like:"%s"*/, zText); |
| 820 | defossilize(zText); |
| 821 | if( zOrigText ){ |
| 822 | zOrigText = mprintf(fromFile?"%z":"%s" /*works-like:"%s"*/, zOrigText); |
| 823 | defossilize(zOrigText); |
| 824 | } |
| 825 | } |
| 826 | if( indent<0 ){ |
| 827 | indent = strlen(zPrefix); |
| 828 | } |
| 829 | if( zPrefix && *zPrefix ){ |
| 830 | fossil_print("%s", zPrefix); |
| 831 | } |
| 832 | fossil_print("(%d lines output)\n", |
| 833 | comment_print(zText, zOrigText, indent, width, flags)); |
| 834 | if( zOrigText && zOrigText!=g.argv[4] ) fossil_free(zOrigText); |
| 835 | if( zText && zText!=g.argv[3] ) fossil_free(zText); |
| 836 | } |
| 837 |
| --- src/comformat.c | |
| +++ src/comformat.c | |
| @@ -729,59 +729,70 @@ | |
| 729 | |
| 730 | /* |
| 731 | ** |
| 732 | ** COMMAND: test-comment-format |
| 733 | ** |
| 734 | ** Usage: %fossil test-comment-format [OPTIONS] TEXT [PREFIX] [ORIGTEXT] |
| 735 | ** |
| 736 | ** Test comment formatting and printing. Use for testing only. |
| 737 | ** |
| 738 | ** The default (canonical) formatting algorithm is: |
| 739 | ** |
| 740 | ** * Omit leading/trailing whitespace |
| 741 | ** * Collapse internal whitespace into a single space character. |
| 742 | ** * Attempt to break lines at whitespace or at a hyphen. |
| 743 | ** |
| 744 | ** Use --whitespace, --origbreak, --trimcrlf, --trimspace, |
| 745 | ** and/or --wordbreak to disable the canonical processing and do |
| 746 | ** the special processing specified by those other options. |
| 747 | ** |
| 748 | ** Options: |
| 749 | ** --decode Decode the text using the same method used when |
| 750 | ** handling the value of a C-card from a manifest. |
| 751 | ** --file FILE Omit the TEXT argument and read the comment text |
| 752 | ** from FILE. |
| 753 | ** --indent Number of spaces to indent (default (-1) is to |
| 754 | ** auto-detect). Zero means no indent. |
| 755 | ** --orig FILE Take the value for the ORIGTEXT argumetn from FILE. |
| 756 | ** --origbreak Attempt to break when the original comment text |
| 757 | ** is detected. |
| 758 | ** --trimcrlf Enable trimming of leading/trailing CR/LF. |
| 759 | ** --trimspace Enable trimming of leading/trailing spaces. |
| 760 | ** --whitespace Keep all internal whitespace. |
| 761 | ** --wordbreak Attempt to break lines on word boundaries. |
| 762 | ** -W|--width NUM Width of lines (default (-1) is to auto-detect). |
| 763 | ** Zero means no limit. |
| 764 | */ |
| 765 | void test_comment_format(void){ |
| 766 | const char *zWidth; |
| 767 | const char *zIndent; |
| 768 | const char *zPrefix = 0; |
| 769 | char *zText = 0; |
| 770 | char *zOrigText = 0; |
| 771 | int indent, width; |
| 772 | int i; |
| 773 | const char *fromFile = find_option("file", 0, 1); |
| 774 | int decode = find_option("decode", 0, 0)!=0; |
| 775 | int flags = COMMENT_PRINT_CANONICAL; |
| 776 | const char *fromOrig = find_option("orig", 0, 1); |
| 777 | if( find_option("whitespace",0,0) ){ |
| 778 | flags = 0; |
| 779 | } |
| 780 | if( find_option("trimcrlf", 0, 0) ){ |
| 781 | flags = COMMENT_PRINT_TRIM_CRLF; |
| 782 | } |
| 783 | if( find_option("trimspace", 0, 0) ){ |
| 784 | flags |= COMMENT_PRINT_TRIM_SPACE; |
| 785 | flags &= COMMENT_PRINT_CANONICAL; |
| 786 | } |
| 787 | if( find_option("wordbreak", 0, 0) ){ |
| 788 | flags |= COMMENT_PRINT_WORD_BREAK; |
| 789 | flags &= COMMENT_PRINT_CANONICAL; |
| 790 | } |
| 791 | if( find_option("origbreak", 0, 0) ){ |
| 792 | flags |= COMMENT_PRINT_ORIG_BREAK; |
| 793 | flags &= COMMENT_PRINT_CANONICAL; |
| 794 | } |
| 795 | zWidth = find_option("width","W",1); |
| 796 | if( zWidth ){ |
| 797 | width = atoi(zWidth); |
| 798 | }else{ |
| @@ -792,45 +803,51 @@ | |
| 803 | indent = atoi(zIndent); |
| 804 | }else{ |
| 805 | indent = -1; /* automatic */ |
| 806 | } |
| 807 | verify_all_options(); |
| 808 | zPrefix = zText = zOrigText = 0; |
| 809 | if( fromFile ){ |
| 810 | Blob fileData; |
| 811 | blob_read_from_file(&fileData, fromFile, ExtFILE); |
| 812 | zText = mprintf("%s", blob_str(&fileData)); |
| 813 | blob_reset(&fileData); |
| 814 | } |
| 815 | if( fromOrig ){ |
| 816 | Blob fileData; |
| 817 | blob_read_from_file(&fileData, fromOrig, ExtFILE); |
| 818 | zOrigText = mprintf("%s", blob_str(&fileData)); |
| 819 | blob_reset(&fileData); |
| 820 | } |
| 821 | for(i=2; i<g.argc; i++){ |
| 822 | if( zText==0 ){ |
| 823 | zText = g.argv[i]; |
| 824 | continue; |
| 825 | } |
| 826 | if( zPrefix==0 ){ |
| 827 | zPrefix = g.argv[i]; |
| 828 | continue; |
| 829 | } |
| 830 | if( zOrigText==0 ){ |
| 831 | zOrigText = g.argv[i]; |
| 832 | continue; |
| 833 | } |
| 834 | usage("[OPTIONS] TEXT [PREFIX] [ORIGTEXT]"); |
| 835 | } |
| 836 | if( decode ){ |
| 837 | zText = mprintf(fromFile?"%z":"%s" /*works-like:"%s"*/, zText); |
| 838 | defossilize(zText); |
| 839 | if( zOrigText ){ |
| 840 | zOrigText = mprintf(fromFile?"%z":"%s" /*works-like:"%s"*/, zOrigText); |
| 841 | defossilize(zOrigText); |
| 842 | } |
| 843 | } |
| 844 | if( zPrefix==0 ) zPrefix = "00:00:00 "; |
| 845 | if( indent<0 ){ |
| 846 | indent = strlen(zPrefix); |
| 847 | } |
| 848 | if( zPrefix && *zPrefix ){ |
| 849 | fossil_print("%s", zPrefix); |
| 850 | } |
| 851 | fossil_print("(%d lines output)\n", |
| 852 | comment_print(zText, zOrigText, indent, width, flags)); |
| 853 | } |
| 854 |