author | Florian Pritz <bluewind@xssn.at> | 2009-08-09 13:43:18 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2009-08-21 12:14:21 (UTC) |
commit | 03389d6e67bfda5cb3ff1504db815f09715ec6f4 (patch) (unidiff) | |
tree | c3424f2206c8b577becb35038e45e6f5cf2b40a5 | |
parent | 6445a3ad0987ba66eef555c9caa3fc378f99ee22 (diff) | |
download | cgit-03389d6e67bfda5cb3ff1504db815f09715ec6f4.zip cgit-03389d6e67bfda5cb3ff1504db815f09715ec6f4.tar.gz cgit-03389d6e67bfda5cb3ff1504db815f09715ec6f4.tar.bz2 |
ui-tree.c: show line numbers when highlighting
When source-filter is enabled, cgit currently will not display
linenumbers in the tree view. This patch restores the linenumber
function.
Signed-off-by: Florian Pritz <bluewind@xssn.at>
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | ui-tree.c | 20 |
1 files changed, 11 insertions, 9 deletions
@@ -1,79 +1,81 @@ | |||
1 | /* ui-tree.c: functions for tree output | 1 | /* ui-tree.c: functions for tree output |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include <ctype.h> | 9 | #include <ctype.h> |
10 | #include "cgit.h" | 10 | #include "cgit.h" |
11 | #include "html.h" | 11 | #include "html.h" |
12 | #include "ui-shared.h" | 12 | #include "ui-shared.h" |
13 | 13 | ||
14 | char *curr_rev; | 14 | char *curr_rev; |
15 | char *match_path; | 15 | char *match_path; |
16 | int header = 0; | 16 | int header = 0; |
17 | 17 | ||
18 | static void print_text_buffer(const char *name, char *buf, unsigned long size) | 18 | static void print_text_buffer(const char *name, char *buf, unsigned long size) |
19 | { | 19 | { |
20 | unsigned long lineno, idx; | 20 | unsigned long lineno, idx; |
21 | const char *numberfmt = | 21 | const char *numberfmt = |
22 | "<a class='no' id='n%1$d' name='n%1$d' href='#n%1$d'>%1$d</a>\n"; | 22 | "<a class='no' id='n%1$d' name='n%1$d' href='#n%1$d'>%1$d</a>\n"; |
23 | 23 | ||
24 | html("<table summary='blob content' class='blob'>\n"); | 24 | html("<table summary='blob content' class='blob'>\n"); |
25 | if (ctx.repo->source_filter) { | ||
26 | html("<tr><td class='lines'><pre><code>"); | ||
27 | ctx.repo->source_filter->argv[1] = xstrdup(name); | ||
28 | cgit_open_filter(ctx.repo->source_filter); | ||
29 | write(STDOUT_FILENO, buf, size); | ||
30 | cgit_close_filter(ctx.repo->source_filter); | ||
31 | html("</code></pre></td></tr></table>\n"); | ||
32 | return; | ||
33 | } | ||
34 | 25 | ||
35 | html("<tr><td class='linenumbers'><pre>"); | 26 | html("<tr><td class='linenumbers'><pre>"); |
36 | idx = 0; | 27 | idx = 0; |
37 | lineno = 0; | 28 | lineno = 0; |
38 | 29 | ||
39 | if (size) { | 30 | if (size) { |
40 | htmlf(numberfmt, ++lineno); | 31 | htmlf(numberfmt, ++lineno); |
41 | while(idx < size - 1) { // skip absolute last newline | 32 | while(idx < size - 1) { // skip absolute last newline |
42 | if (buf[idx] == '\n') | 33 | if (buf[idx] == '\n') |
43 | htmlf(numberfmt, ++lineno); | 34 | htmlf(numberfmt, ++lineno); |
44 | idx++; | 35 | idx++; |
45 | } | 36 | } |
46 | } | 37 | } |
47 | html("</pre></td>\n"); | 38 | html("</pre></td>\n"); |
39 | |||
40 | if (ctx.repo->source_filter) { | ||
41 | html("<td class='lines'><pre><code>"); | ||
42 | ctx.repo->source_filter->argv[1] = xstrdup(name); | ||
43 | cgit_open_filter(ctx.repo->source_filter); | ||
44 | write(STDOUT_FILENO, buf, size); | ||
45 | cgit_close_filter(ctx.repo->source_filter); | ||
46 | html("</code></pre></td></tr></table>\n"); | ||
47 | return; | ||
48 | } | ||
49 | |||
48 | html("<td class='lines'><pre><code>"); | 50 | html("<td class='lines'><pre><code>"); |
49 | html_txt(buf); | 51 | html_txt(buf); |
50 | html("</code></pre></td></tr></table>\n"); | 52 | html("</code></pre></td></tr></table>\n"); |
51 | } | 53 | } |
52 | 54 | ||
53 | #define ROWLEN 32 | 55 | #define ROWLEN 32 |
54 | 56 | ||
55 | static void print_binary_buffer(char *buf, unsigned long size) | 57 | static void print_binary_buffer(char *buf, unsigned long size) |
56 | { | 58 | { |
57 | unsigned long ofs, idx; | 59 | unsigned long ofs, idx; |
58 | static char ascii[ROWLEN + 1]; | 60 | static char ascii[ROWLEN + 1]; |
59 | 61 | ||
60 | html("<table summary='blob content' class='bin-blob'>\n"); | 62 | html("<table summary='blob content' class='bin-blob'>\n"); |
61 | html("<tr><th>ofs</th><th>hex dump</th><th>ascii</th></tr>"); | 63 | html("<tr><th>ofs</th><th>hex dump</th><th>ascii</th></tr>"); |
62 | for (ofs = 0; ofs < size; ofs += ROWLEN, buf += ROWLEN) { | 64 | for (ofs = 0; ofs < size; ofs += ROWLEN, buf += ROWLEN) { |
63 | htmlf("<tr><td class='right'>%04x</td><td class='hex'>", ofs); | 65 | htmlf("<tr><td class='right'>%04x</td><td class='hex'>", ofs); |
64 | for (idx = 0; idx < ROWLEN && ofs + idx < size; idx++) | 66 | for (idx = 0; idx < ROWLEN && ofs + idx < size; idx++) |
65 | htmlf("%*s%02x", | 67 | htmlf("%*s%02x", |
66 | idx == 16 ? 4 : 1, "", | 68 | idx == 16 ? 4 : 1, "", |
67 | buf[idx] & 0xff); | 69 | buf[idx] & 0xff); |
68 | html(" </td><td class='hex'>"); | 70 | html(" </td><td class='hex'>"); |
69 | for (idx = 0; idx < ROWLEN && ofs + idx < size; idx++) | 71 | for (idx = 0; idx < ROWLEN && ofs + idx < size; idx++) |
70 | ascii[idx] = isgraph(buf[idx]) ? buf[idx] : '.'; | 72 | ascii[idx] = isgraph(buf[idx]) ? buf[idx] : '.'; |
71 | ascii[idx] = '\0'; | 73 | ascii[idx] = '\0'; |
72 | html_txt(ascii); | 74 | html_txt(ascii); |
73 | html("</td></tr>\n"); | 75 | html("</td></tr>\n"); |
74 | } | 76 | } |
75 | html("</table>\n"); | 77 | html("</table>\n"); |
76 | } | 78 | } |
77 | 79 | ||
78 | static void print_object(const unsigned char *sha1, char *path, const char *basename) | 80 | static void print_object(const unsigned char *sha1, char *path, const char *basename) |
79 | { | 81 | { |