Fossil SCM

Enhance the "ln=" text highlighter to support multiple blocks of code.

drh 2015-03-07 12:34 trunk merge
Commit 259e3a0fd6c7ac69ddb5d2eca351bcf459d1bd79
1 file changed +37 -9
+37 -9
--- src/info.c
+++ src/info.c
@@ -1701,35 +1701,62 @@
17011701
** file. This routine appends that text to the HTTP reply with line numbering.
17021702
**
17031703
** zLn is the ?ln= parameter for the HTTP query. If there is an argument,
17041704
** then highlight that line number and scroll to it once the page loads.
17051705
** 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 [-,.]).
17061708
*/
17071709
void output_text_with_line_numbers(
17081710
const char *z,
17091711
const char *zLn
17101712
){
17111713
int iStart, iEnd; /* Start and end of region to highlight */
17121714
int n = 0; /* Current line number */
1713
- int i; /* Loop index */
1715
+ int i = 0; /* Loop index */
17141716
int iTop = 0; /* Scroll so that this line is on top of screen. */
1717
+ Stmt q;
17151718
17161719
iStart = iEnd = atoi(zLn);
1720
+ db_multi_exec(
1721
+ "CREATE TEMP TABLE lnos(iStart INTEGER PRIMARY KEY, iEnd INTEGER)");
17171722
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);
17251743
iTop = iStart - 15 + (iEnd-iStart)/4;
17261744
if( iTop>iStart - 2 ) iTop = iStart-2;
17271745
}
1746
+ db_finalize(&q);
17281747
@ <pre>
17291748
while( z[0] ){
17301749
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);
17311758
for(i=0; z[i] && z[i]!='\n'; i++){}
17321759
if( n==iTop ) cgi_append_content("<span id=\"topln\">", -1);
17331760
if( n==iStart ){
17341761
cgi_append_content("<div class=\"selectedText\">",-1);
17351762
}
@@ -1745,11 +1772,11 @@
17451772
z += i;
17461773
if( z[0]=='\n' ) z++;
17471774
}
17481775
if( n<iEnd ) cgi_printf("</div>");
17491776
@ </pre>
1750
- if( iStart ){
1777
+ if( db_int(0, "SELECT EXISTS(SELECT 1 FROM lnos)") ){
17511778
@ <script>gebi('topln').scrollIntoView(true);</script>
17521779
}
17531780
}
17541781
17551782
@@ -1764,10 +1791,11 @@
17641791
** Additional query parameters:
17651792
**
17661793
** ln - show line numbers
17671794
** ln=N - highlight line number N
17681795
** 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)
17691797
** verbose - show more detail in the description
17701798
**
17711799
** The /artifact page show the complete content of a file
17721800
** identified by SHA1HASH as preformatted text. The
17731801
** /whatis page shows only a description of the file.
17741802
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button