Fossil SCM
Enhance the "ln=" text highlighter to support multiple blocks of code.
Commit
259e3a0fd6c7ac69ddb5d2eca351bcf459d1bd79
Parent
8fa54638c2eea27…
1 file changed
+37
-9
+37
-9
| --- src/info.c | ||
| +++ src/info.c | ||
| @@ -1701,35 +1701,62 @@ | ||
| 1701 | 1701 | ** file. This routine appends that text to the HTTP reply with line numbering. |
| 1702 | 1702 | ** |
| 1703 | 1703 | ** zLn is the ?ln= parameter for the HTTP query. If there is an argument, |
| 1704 | 1704 | ** then highlight that line number and scroll to it once the page loads. |
| 1705 | 1705 | ** If there are two line numbers, highlight the range of lines. |
| 1706 | +** Multiple ranges can be highlighed by adding additional line numbers | |
| 1707 | +** separated by a non-digit character (also not one of [-,.]). | |
| 1706 | 1708 | */ |
| 1707 | 1709 | void output_text_with_line_numbers( |
| 1708 | 1710 | const char *z, |
| 1709 | 1711 | const char *zLn |
| 1710 | 1712 | ){ |
| 1711 | 1713 | int iStart, iEnd; /* Start and end of region to highlight */ |
| 1712 | 1714 | int n = 0; /* Current line number */ |
| 1713 | - int i; /* Loop index */ | |
| 1715 | + int i = 0; /* Loop index */ | |
| 1714 | 1716 | int iTop = 0; /* Scroll so that this line is on top of screen. */ |
| 1717 | + Stmt q; | |
| 1715 | 1718 | |
| 1716 | 1719 | iStart = iEnd = atoi(zLn); |
| 1720 | + db_multi_exec( | |
| 1721 | + "CREATE TEMP TABLE lnos(iStart INTEGER PRIMARY KEY, iEnd INTEGER)"); | |
| 1717 | 1722 | if( iStart>0 ){ |
| 1718 | - for(i=0; fossil_isdigit(zLn[i]); i++){} | |
| 1719 | - if( zLn[i]==',' || zLn[i]=='-' || zLn[i]=='.' ){ | |
| 1720 | - i++; | |
| 1721 | - while( zLn[i]=='.' ){ i++; } | |
| 1722 | - iEnd = atoi(&zLn[i]); | |
| 1723 | - } | |
| 1724 | - if( iEnd<iStart ) iEnd = iStart; | |
| 1723 | + do{ | |
| 1724 | + while( fossil_isdigit(zLn[i]) ) i++; | |
| 1725 | + if( zLn[i]==',' || zLn[i]=='-' || zLn[i]=='.' ){ | |
| 1726 | + i++; | |
| 1727 | + while( zLn[i]=='.' ){ i++; } | |
| 1728 | + iEnd = atoi(&zLn[i]); | |
| 1729 | + while( fossil_isdigit(zLn[i]) ) i++; | |
| 1730 | + } | |
| 1731 | + while( fossil_isdigit(zLn[i]) ) i++; | |
| 1732 | + if( iEnd<iStart ) iEnd = iStart; | |
| 1733 | + db_multi_exec( | |
| 1734 | + "INSERT OR REPLACE INTO lnos VALUES(%d,%d)", iStart, iEnd | |
| 1735 | + ); | |
| 1736 | + iStart = iEnd = atoi(&zLn[i++]); | |
| 1737 | + }while( zLn[i] && iStart && iEnd ); | |
| 1738 | + } | |
| 1739 | + db_prepare(&q, "SELECT min(iStart), iEnd FROM lnos"); | |
| 1740 | + if( db_step(&q)==SQLITE_ROW ){ | |
| 1741 | + iStart = db_column_int(&q, 0); | |
| 1742 | + iEnd = db_column_int(&q, 1); | |
| 1725 | 1743 | iTop = iStart - 15 + (iEnd-iStart)/4; |
| 1726 | 1744 | if( iTop>iStart - 2 ) iTop = iStart-2; |
| 1727 | 1745 | } |
| 1746 | + db_finalize(&q); | |
| 1728 | 1747 | @ <pre> |
| 1729 | 1748 | while( z[0] ){ |
| 1730 | 1749 | n++; |
| 1750 | + db_prepare(&q, | |
| 1751 | + "SELECT min(iStart), max(iEnd) FROM lnos" | |
| 1752 | + " WHERE iStart <= %d AND iEnd >= %d", n, n); | |
| 1753 | + if( db_step(&q)==SQLITE_ROW ){ | |
| 1754 | + iStart = db_column_int(&q, 0); | |
| 1755 | + iEnd = db_column_int(&q, 1); | |
| 1756 | + } | |
| 1757 | + db_finalize(&q); | |
| 1731 | 1758 | for(i=0; z[i] && z[i]!='\n'; i++){} |
| 1732 | 1759 | if( n==iTop ) cgi_append_content("<span id=\"topln\">", -1); |
| 1733 | 1760 | if( n==iStart ){ |
| 1734 | 1761 | cgi_append_content("<div class=\"selectedText\">",-1); |
| 1735 | 1762 | } |
| @@ -1745,11 +1772,11 @@ | ||
| 1745 | 1772 | z += i; |
| 1746 | 1773 | if( z[0]=='\n' ) z++; |
| 1747 | 1774 | } |
| 1748 | 1775 | if( n<iEnd ) cgi_printf("</div>"); |
| 1749 | 1776 | @ </pre> |
| 1750 | - if( iStart ){ | |
| 1777 | + if( db_int(0, "SELECT EXISTS(SELECT 1 FROM lnos)") ){ | |
| 1751 | 1778 | @ <script>gebi('topln').scrollIntoView(true);</script> |
| 1752 | 1779 | } |
| 1753 | 1780 | } |
| 1754 | 1781 | |
| 1755 | 1782 | |
| @@ -1764,10 +1791,11 @@ | ||
| 1764 | 1791 | ** Additional query parameters: |
| 1765 | 1792 | ** |
| 1766 | 1793 | ** ln - show line numbers |
| 1767 | 1794 | ** ln=N - highlight line number N |
| 1768 | 1795 | ** ln=M-N - highlight lines M through N inclusive |
| 1796 | +** ln=M-N+Y-Z - higllight lines M through N and Y through Z (inclusive) | |
| 1769 | 1797 | ** verbose - show more detail in the description |
| 1770 | 1798 | ** |
| 1771 | 1799 | ** The /artifact page show the complete content of a file |
| 1772 | 1800 | ** identified by SHA1HASH as preformatted text. The |
| 1773 | 1801 | ** /whatis page shows only a description of the file. |
| 1774 | 1802 |
| --- src/info.c | |
| +++ src/info.c | |
| @@ -1701,35 +1701,62 @@ | |
| 1701 | ** file. This routine appends that text to the HTTP reply with line numbering. |
| 1702 | ** |
| 1703 | ** zLn is the ?ln= parameter for the HTTP query. If there is an argument, |
| 1704 | ** then highlight that line number and scroll to it once the page loads. |
| 1705 | ** If there are two line numbers, highlight the range of lines. |
| 1706 | */ |
| 1707 | void output_text_with_line_numbers( |
| 1708 | const char *z, |
| 1709 | const char *zLn |
| 1710 | ){ |
| 1711 | int iStart, iEnd; /* Start and end of region to highlight */ |
| 1712 | int n = 0; /* Current line number */ |
| 1713 | int i; /* Loop index */ |
| 1714 | int iTop = 0; /* Scroll so that this line is on top of screen. */ |
| 1715 | |
| 1716 | iStart = iEnd = atoi(zLn); |
| 1717 | if( iStart>0 ){ |
| 1718 | for(i=0; fossil_isdigit(zLn[i]); i++){} |
| 1719 | if( zLn[i]==',' || zLn[i]=='-' || zLn[i]=='.' ){ |
| 1720 | i++; |
| 1721 | while( zLn[i]=='.' ){ i++; } |
| 1722 | iEnd = atoi(&zLn[i]); |
| 1723 | } |
| 1724 | if( iEnd<iStart ) iEnd = iStart; |
| 1725 | iTop = iStart - 15 + (iEnd-iStart)/4; |
| 1726 | if( iTop>iStart - 2 ) iTop = iStart-2; |
| 1727 | } |
| 1728 | @ <pre> |
| 1729 | while( z[0] ){ |
| 1730 | n++; |
| 1731 | for(i=0; z[i] && z[i]!='\n'; i++){} |
| 1732 | if( n==iTop ) cgi_append_content("<span id=\"topln\">", -1); |
| 1733 | if( n==iStart ){ |
| 1734 | cgi_append_content("<div class=\"selectedText\">",-1); |
| 1735 | } |
| @@ -1745,11 +1772,11 @@ | |
| 1745 | z += i; |
| 1746 | if( z[0]=='\n' ) z++; |
| 1747 | } |
| 1748 | if( n<iEnd ) cgi_printf("</div>"); |
| 1749 | @ </pre> |
| 1750 | if( iStart ){ |
| 1751 | @ <script>gebi('topln').scrollIntoView(true);</script> |
| 1752 | } |
| 1753 | } |
| 1754 | |
| 1755 | |
| @@ -1764,10 +1791,11 @@ | |
| 1764 | ** Additional query parameters: |
| 1765 | ** |
| 1766 | ** ln - show line numbers |
| 1767 | ** ln=N - highlight line number N |
| 1768 | ** ln=M-N - highlight lines M through N inclusive |
| 1769 | ** verbose - show more detail in the description |
| 1770 | ** |
| 1771 | ** The /artifact page show the complete content of a file |
| 1772 | ** identified by SHA1HASH as preformatted text. The |
| 1773 | ** /whatis page shows only a description of the file. |
| 1774 |
| --- src/info.c | |
| +++ src/info.c | |
| @@ -1701,35 +1701,62 @@ | |
| 1701 | ** file. This routine appends that text to the HTTP reply with line numbering. |
| 1702 | ** |
| 1703 | ** zLn is the ?ln= parameter for the HTTP query. If there is an argument, |
| 1704 | ** then highlight that line number and scroll to it once the page loads. |
| 1705 | ** If there are two line numbers, highlight the range of lines. |
| 1706 | ** Multiple ranges can be highlighed by adding additional line numbers |
| 1707 | ** separated by a non-digit character (also not one of [-,.]). |
| 1708 | */ |
| 1709 | void output_text_with_line_numbers( |
| 1710 | const char *z, |
| 1711 | const char *zLn |
| 1712 | ){ |
| 1713 | int iStart, iEnd; /* Start and end of region to highlight */ |
| 1714 | int n = 0; /* Current line number */ |
| 1715 | int i = 0; /* Loop index */ |
| 1716 | int iTop = 0; /* Scroll so that this line is on top of screen. */ |
| 1717 | Stmt q; |
| 1718 | |
| 1719 | iStart = iEnd = atoi(zLn); |
| 1720 | db_multi_exec( |
| 1721 | "CREATE TEMP TABLE lnos(iStart INTEGER PRIMARY KEY, iEnd INTEGER)"); |
| 1722 | if( iStart>0 ){ |
| 1723 | do{ |
| 1724 | while( fossil_isdigit(zLn[i]) ) i++; |
| 1725 | if( zLn[i]==',' || zLn[i]=='-' || zLn[i]=='.' ){ |
| 1726 | i++; |
| 1727 | while( zLn[i]=='.' ){ i++; } |
| 1728 | iEnd = atoi(&zLn[i]); |
| 1729 | while( fossil_isdigit(zLn[i]) ) i++; |
| 1730 | } |
| 1731 | while( fossil_isdigit(zLn[i]) ) i++; |
| 1732 | if( iEnd<iStart ) iEnd = iStart; |
| 1733 | db_multi_exec( |
| 1734 | "INSERT OR REPLACE INTO lnos VALUES(%d,%d)", iStart, iEnd |
| 1735 | ); |
| 1736 | iStart = iEnd = atoi(&zLn[i++]); |
| 1737 | }while( zLn[i] && iStart && iEnd ); |
| 1738 | } |
| 1739 | db_prepare(&q, "SELECT min(iStart), iEnd FROM lnos"); |
| 1740 | if( db_step(&q)==SQLITE_ROW ){ |
| 1741 | iStart = db_column_int(&q, 0); |
| 1742 | iEnd = db_column_int(&q, 1); |
| 1743 | iTop = iStart - 15 + (iEnd-iStart)/4; |
| 1744 | if( iTop>iStart - 2 ) iTop = iStart-2; |
| 1745 | } |
| 1746 | db_finalize(&q); |
| 1747 | @ <pre> |
| 1748 | while( z[0] ){ |
| 1749 | n++; |
| 1750 | db_prepare(&q, |
| 1751 | "SELECT min(iStart), max(iEnd) FROM lnos" |
| 1752 | " WHERE iStart <= %d AND iEnd >= %d", n, n); |
| 1753 | if( db_step(&q)==SQLITE_ROW ){ |
| 1754 | iStart = db_column_int(&q, 0); |
| 1755 | iEnd = db_column_int(&q, 1); |
| 1756 | } |
| 1757 | db_finalize(&q); |
| 1758 | for(i=0; z[i] && z[i]!='\n'; i++){} |
| 1759 | if( n==iTop ) cgi_append_content("<span id=\"topln\">", -1); |
| 1760 | if( n==iStart ){ |
| 1761 | cgi_append_content("<div class=\"selectedText\">",-1); |
| 1762 | } |
| @@ -1745,11 +1772,11 @@ | |
| 1772 | z += i; |
| 1773 | if( z[0]=='\n' ) z++; |
| 1774 | } |
| 1775 | if( n<iEnd ) cgi_printf("</div>"); |
| 1776 | @ </pre> |
| 1777 | if( db_int(0, "SELECT EXISTS(SELECT 1 FROM lnos)") ){ |
| 1778 | @ <script>gebi('topln').scrollIntoView(true);</script> |
| 1779 | } |
| 1780 | } |
| 1781 | |
| 1782 | |
| @@ -1764,10 +1791,11 @@ | |
| 1791 | ** Additional query parameters: |
| 1792 | ** |
| 1793 | ** ln - show line numbers |
| 1794 | ** ln=N - highlight line number N |
| 1795 | ** ln=M-N - highlight lines M through N inclusive |
| 1796 | ** ln=M-N+Y-Z - higllight lines M through N and Y through Z (inclusive) |
| 1797 | ** verbose - show more detail in the description |
| 1798 | ** |
| 1799 | ** The /artifact page show the complete content of a file |
| 1800 | ** identified by SHA1HASH as preformatted text. The |
| 1801 | ** /whatis page shows only a description of the file. |
| 1802 |