Fossil SCM

Enhance the /artifact method so that the ln=M,N argument shows linenumbers and highlights lines between M and N.

drh 2011-02-18 19:31 trunk
Commit 6e0dd3bab7c3cd6321319b4f1925bfc284c917a0
1 file changed +42 -3
+42 -3
--- src/info.c
+++ src/info.c
@@ -1162,13 +1162,52 @@
11621162
}else{
11631163
style_submenu_element("Hex","Hex", "%s/hexdump?name=%s", g.zTop, zUuid);
11641164
zMime = mimetype_from_content(&content);
11651165
@ <blockquote>
11661166
if( zMime==0 ){
1167
- @ <pre>
1168
- @ %h(blob_str(&content))
1169
- @ </pre>
1167
+ const char *zLn = P("ln");
1168
+ const char *z = blob_str(&content);
1169
+ if( zLn ){
1170
+ int iStart, iEnd;
1171
+ int n = 0;
1172
+ int i;
1173
+ iStart = iEnd = atoi(zLn);
1174
+ if( iStart>0 ){
1175
+ for(i=0; zLn[i] && zLn[i]!=','; i++){}
1176
+ if( zLn[i] ) iEnd = atoi(&zLn[i+1]);
1177
+ if( iEnd<iStart ) iEnd = iStart;
1178
+ }
1179
+ @ <pre>
1180
+ while( z[0] ){
1181
+ n++;
1182
+ for(i=0; z[i] && z[i]!='\n'; i++){}
1183
+ if( n==iStart ) cgi_append_content("<b id=\"dln\">", -1);
1184
+ cgi_printf("%06d ", n);
1185
+ if( i>0 ){
1186
+ char *zHtml = htmlize(z, i);
1187
+ cgi_append_content(zHtml, -1);
1188
+ fossil_free(zHtml);
1189
+ }
1190
+ if( n==iEnd ) cgi_append_content("</b>", -1);
1191
+ cgi_append_content("\n", 1);
1192
+ z += i;
1193
+ if( z[0]=='\n' ) z++;
1194
+ }
1195
+ if( n<iEnd ) cgi_printf("</b>");
1196
+ @ </pre>
1197
+ if( iStart ){
1198
+ @ <script type="text/JavaScript">
1199
+ @ /* <![CDATA[ */
1200
+ @ document.getElementById('dln').scrollIntoView(true);
1201
+ @ /* ]]> */
1202
+ @ </script>
1203
+ }
1204
+ }else{
1205
+ @ <pre>
1206
+ @ %h(z);
1207
+ @ </pre>
1208
+ }
11701209
}else if( strncmp(zMime, "image/", 6)==0 ){
11711210
@ <img src="%s(g.zTop)/raw?name=%s(zUuid)&amp;m=%s(zMime)"></img>
11721211
}else{
11731212
@ <i>(file is %d(blob_size(&content)) bytes of binary data)</i>
11741213
}
11751214
--- src/info.c
+++ src/info.c
@@ -1162,13 +1162,52 @@
1162 }else{
1163 style_submenu_element("Hex","Hex", "%s/hexdump?name=%s", g.zTop, zUuid);
1164 zMime = mimetype_from_content(&content);
1165 @ <blockquote>
1166 if( zMime==0 ){
1167 @ <pre>
1168 @ %h(blob_str(&content))
1169 @ </pre>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1170 }else if( strncmp(zMime, "image/", 6)==0 ){
1171 @ <img src="%s(g.zTop)/raw?name=%s(zUuid)&amp;m=%s(zMime)"></img>
1172 }else{
1173 @ <i>(file is %d(blob_size(&content)) bytes of binary data)</i>
1174 }
1175
--- src/info.c
+++ src/info.c
@@ -1162,13 +1162,52 @@
1162 }else{
1163 style_submenu_element("Hex","Hex", "%s/hexdump?name=%s", g.zTop, zUuid);
1164 zMime = mimetype_from_content(&content);
1165 @ <blockquote>
1166 if( zMime==0 ){
1167 const char *zLn = P("ln");
1168 const char *z = blob_str(&content);
1169 if( zLn ){
1170 int iStart, iEnd;
1171 int n = 0;
1172 int i;
1173 iStart = iEnd = atoi(zLn);
1174 if( iStart>0 ){
1175 for(i=0; zLn[i] && zLn[i]!=','; i++){}
1176 if( zLn[i] ) iEnd = atoi(&zLn[i+1]);
1177 if( iEnd<iStart ) iEnd = iStart;
1178 }
1179 @ <pre>
1180 while( z[0] ){
1181 n++;
1182 for(i=0; z[i] && z[i]!='\n'; i++){}
1183 if( n==iStart ) cgi_append_content("<b id=\"dln\">", -1);
1184 cgi_printf("%06d ", n);
1185 if( i>0 ){
1186 char *zHtml = htmlize(z, i);
1187 cgi_append_content(zHtml, -1);
1188 fossil_free(zHtml);
1189 }
1190 if( n==iEnd ) cgi_append_content("</b>", -1);
1191 cgi_append_content("\n", 1);
1192 z += i;
1193 if( z[0]=='\n' ) z++;
1194 }
1195 if( n<iEnd ) cgi_printf("</b>");
1196 @ </pre>
1197 if( iStart ){
1198 @ <script type="text/JavaScript">
1199 @ /* <![CDATA[ */
1200 @ document.getElementById('dln').scrollIntoView(true);
1201 @ /* ]]> */
1202 @ </script>
1203 }
1204 }else{
1205 @ <pre>
1206 @ %h(z);
1207 @ </pre>
1208 }
1209 }else if( strncmp(zMime, "image/", 6)==0 ){
1210 @ <img src="%s(g.zTop)/raw?name=%s(zUuid)&amp;m=%s(zMime)"></img>
1211 }else{
1212 @ <i>(file is %d(blob_size(&content)) bytes of binary data)</i>
1213 }
1214

Keyboard Shortcuts

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