|
diff --git a/ui-tree.c b/ui-tree.c index 0b1b531..442b6be 100644 --- a/ ui-tree.c+++ b/ ui-tree.c |
|
@@ -3,96 +3,98 @@ |
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 | |
25 | |
26 | if (ctx.cfg.enable_tree_linenumbers) { |
26 | if (ctx.cfg.enable_tree_linenumbers) { |
27 | html("<tr><td class='linenumbers'><pre>"); |
27 | html("<tr><td class='linenumbers'><pre>"); |
28 | idx = 0; |
28 | idx = 0; |
29 | lineno = 0; |
29 | lineno = 0; |
30 | |
30 | |
31 | if (size) { |
31 | if (size) { |
32 | htmlf(numberfmt, ++lineno); |
32 | htmlf(numberfmt, ++lineno); |
33 | while(idx < size - 1) { // skip absolute last newline |
33 | while(idx < size - 1) { // skip absolute last newline |
34 | if (buf[idx] == '\n') |
34 | if (buf[idx] == '\n') |
35 | htmlf(numberfmt, ++lineno); |
35 | htmlf(numberfmt, ++lineno); |
36 | idx++; |
36 | idx++; |
37 | } |
37 | } |
38 | } |
38 | } |
39 | html("</pre></td>\n"); |
39 | html("</pre></td>\n"); |
40 | } |
40 | } |
41 | else { |
41 | else { |
42 | html("<tr>\n"); |
42 | html("<tr>\n"); |
43 | } |
43 | } |
44 | |
44 | |
45 | if (ctx.repo->source_filter) { |
45 | if (ctx.repo->source_filter) { |
46 | html("<td class='lines'><pre><code>"); |
46 | html("<td class='lines'><pre><code>"); |
47 | ctx.repo->source_filter->argv[1] = xstrdup(name); |
47 | ctx.repo->source_filter->argv[1] = xstrdup(name); |
48 | cgit_open_filter(ctx.repo->source_filter); |
48 | cgit_open_filter(ctx.repo->source_filter); |
49 | html_raw(buf, size); |
49 | html_raw(buf, size); |
50 | cgit_close_filter(ctx.repo->source_filter); |
50 | cgit_close_filter(ctx.repo->source_filter); |
| |
51 | free(ctx.repo->source_filter->argv[1]); |
| |
52 | ctx.repo->source_filter->argv[1] = NULL; |
51 | html("</code></pre></td></tr></table>\n"); |
53 | html("</code></pre></td></tr></table>\n"); |
52 | return; |
54 | return; |
53 | } |
55 | } |
54 | |
56 | |
55 | html("<td class='lines'><pre><code>"); |
57 | html("<td class='lines'><pre><code>"); |
56 | html_txt(buf); |
58 | html_txt(buf); |
57 | html("</code></pre></td></tr></table>\n"); |
59 | html("</code></pre></td></tr></table>\n"); |
58 | } |
60 | } |
59 | |
61 | |
60 | #define ROWLEN 32 |
62 | #define ROWLEN 32 |
61 | |
63 | |
62 | static void print_binary_buffer(char *buf, unsigned long size) |
64 | static void print_binary_buffer(char *buf, unsigned long size) |
63 | { |
65 | { |
64 | unsigned long ofs, idx; |
66 | unsigned long ofs, idx; |
65 | static char ascii[ROWLEN + 1]; |
67 | static char ascii[ROWLEN + 1]; |
66 | |
68 | |
67 | html("<table summary='blob content' class='bin-blob'>\n"); |
69 | html("<table summary='blob content' class='bin-blob'>\n"); |
68 | html("<tr><th>ofs</th><th>hex dump</th><th>ascii</th></tr>"); |
70 | html("<tr><th>ofs</th><th>hex dump</th><th>ascii</th></tr>"); |
69 | for (ofs = 0; ofs < size; ofs += ROWLEN, buf += ROWLEN) { |
71 | for (ofs = 0; ofs < size; ofs += ROWLEN, buf += ROWLEN) { |
70 | htmlf("<tr><td class='right'>%04lx</td><td class='hex'>", ofs); |
72 | htmlf("<tr><td class='right'>%04lx</td><td class='hex'>", ofs); |
71 | for (idx = 0; idx < ROWLEN && ofs + idx < size; idx++) |
73 | for (idx = 0; idx < ROWLEN && ofs + idx < size; idx++) |
72 | htmlf("%*s%02x", |
74 | htmlf("%*s%02x", |
73 | idx == 16 ? 4 : 1, "", |
75 | idx == 16 ? 4 : 1, "", |
74 | buf[idx] & 0xff); |
76 | buf[idx] & 0xff); |
75 | html(" </td><td class='hex'>"); |
77 | html(" </td><td class='hex'>"); |
76 | for (idx = 0; idx < ROWLEN && ofs + idx < size; idx++) |
78 | for (idx = 0; idx < ROWLEN && ofs + idx < size; idx++) |
77 | ascii[idx] = isgraph(buf[idx]) ? buf[idx] : '.'; |
79 | ascii[idx] = isgraph(buf[idx]) ? buf[idx] : '.'; |
78 | ascii[idx] = '\0'; |
80 | ascii[idx] = '\0'; |
79 | html_txt(ascii); |
81 | html_txt(ascii); |
80 | html("</td></tr>\n"); |
82 | html("</td></tr>\n"); |
81 | } |
83 | } |
82 | html("</table>\n"); |
84 | html("</table>\n"); |
83 | } |
85 | } |
84 | |
86 | |
85 | static void print_object(const unsigned char *sha1, char *path, const char *basename) |
87 | static void print_object(const unsigned char *sha1, char *path, const char *basename) |
86 | { |
88 | { |
87 | enum object_type type; |
89 | enum object_type type; |
88 | char *buf; |
90 | char *buf; |
89 | unsigned long size; |
91 | unsigned long size; |
90 | |
92 | |
91 | type = sha1_object_info(sha1, &size); |
93 | type = sha1_object_info(sha1, &size); |
92 | if (type == OBJ_BAD) { |
94 | if (type == OBJ_BAD) { |
93 | cgit_print_error(fmt("Bad object name: %s", |
95 | cgit_print_error(fmt("Bad object name: %s", |
94 | sha1_to_hex(sha1))); |
96 | sha1_to_hex(sha1))); |
95 | return; |
97 | return; |
96 | } |
98 | } |
97 | |
99 | |
98 | buf = read_sha1_file(sha1, &type, &size); |
100 | buf = read_sha1_file(sha1, &type, &size); |
|