|
diff --git a/ui-tree.c b/ui-tree.c index a37a4e5..c6159ec 100644 --- a/ ui-tree.c+++ b/ ui-tree.c |
|
@@ -16,63 +16,68 @@ char *match_path; |
16 | int header = 0; |
16 | int header = 0; |
17 | |
17 | |
18 | static void print_text_buffer(char *buf, unsigned long size) |
18 | static void print_text_buffer(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 | html("<tr><td class='linenumbers'><pre>"); |
25 | html("<tr><td class='linenumbers'><pre>"); |
26 | idx = 0; |
26 | idx = 0; |
27 | lineno = 0; |
27 | lineno = 0; |
28 | htmlf(numberfmt, ++lineno); |
28 | htmlf(numberfmt, ++lineno); |
29 | while(idx < size - 1) { // skip absolute last newline |
29 | while(idx < size - 1) { // skip absolute last newline |
30 | if (buf[idx] == '\n') |
30 | if (buf[idx] == '\n') |
31 | htmlf(numberfmt, ++lineno); |
31 | htmlf(numberfmt, ++lineno); |
32 | idx++; |
32 | idx++; |
33 | } |
33 | } |
34 | html("</pre></td>\n"); |
34 | html("</pre></td>\n"); |
35 | html("<td class='lines'><pre><code>"); |
35 | html("<td class='lines'><pre><code>"); |
36 | html_txt(buf); |
36 | html_txt(buf); |
37 | html("</code></pre></td></tr></table>\n"); |
37 | html("</code></pre></td></tr></table>\n"); |
38 | } |
38 | } |
39 | |
39 | |
| |
40 | #define ROWLEN 32 |
| |
41 | |
40 | static void print_binary_buffer(char *buf, unsigned long size) |
42 | static void print_binary_buffer(char *buf, unsigned long size) |
41 | { |
43 | { |
42 | unsigned long ofs, idx; |
44 | unsigned long ofs, idx; |
| |
45 | static char ascii[ROWLEN + 1]; |
43 | |
46 | |
44 | html("<table summary='blob content' class='bin-blob'>\n"); |
47 | html("<table summary='blob content' class='bin-blob'>\n"); |
45 | html("<tr><th>ofs</th><th>hex dump</th><th>ascii</th></tr>"); |
48 | html("<tr><th>ofs</th><th>hex dump</th><th>ascii</th></tr>"); |
46 | for (ofs = 0; ofs < size; ofs += 32, buf += 32) { |
49 | for (ofs = 0; ofs < size; ofs += ROWLEN, buf += ROWLEN) { |
47 | htmlf("<tr><td class='right'>%04x</td><td class='hex'>", ofs); |
50 | htmlf("<tr><td class='right'>%04x</td><td class='hex'>", ofs); |
48 | for (idx = 0; idx < 32 && ofs + idx < size; idx++) |
51 | for (idx = 0; idx < ROWLEN && ofs + idx < size; idx++) |
49 | htmlf("%*s%02x", |
52 | htmlf("%*s%02x", |
50 | idx == 16 ? 4 : 1, "", |
53 | idx == 16 ? 4 : 1, "", |
51 | buf[idx] & 0xff); |
54 | buf[idx] & 0xff); |
52 | html(" </td><td class='hex'>"); |
55 | html(" </td><td class='hex'>"); |
53 | for (idx = 0; idx < 32 && ofs + idx < size; idx++) |
56 | for (idx = 0; idx < ROWLEN && ofs + idx < size; idx++) |
54 | htmlf("%c", isgraph(buf[idx]) ? buf[idx] : '.'); |
57 | ascii[idx] = isgraph(buf[idx]) ? buf[idx] : '.'; |
| |
58 | ascii[idx] = '\0'; |
| |
59 | html_txt(ascii); |
55 | html("</td></tr>\n"); |
60 | html("</td></tr>\n"); |
56 | } |
61 | } |
57 | html("</table>\n"); |
62 | html("</table>\n"); |
58 | } |
63 | } |
59 | |
64 | |
60 | static void print_object(const unsigned char *sha1, char *path) |
65 | static void print_object(const unsigned char *sha1, char *path) |
61 | { |
66 | { |
62 | enum object_type type; |
67 | enum object_type type; |
63 | char *buf; |
68 | char *buf; |
64 | unsigned long size; |
69 | unsigned long size; |
65 | |
70 | |
66 | type = sha1_object_info(sha1, &size); |
71 | type = sha1_object_info(sha1, &size); |
67 | if (type == OBJ_BAD) { |
72 | if (type == OBJ_BAD) { |
68 | cgit_print_error(fmt("Bad object name: %s", |
73 | cgit_print_error(fmt("Bad object name: %s", |
69 | sha1_to_hex(sha1))); |
74 | sha1_to_hex(sha1))); |
70 | return; |
75 | return; |
71 | } |
76 | } |
72 | |
77 | |
73 | buf = read_sha1_file(sha1, &type, &size); |
78 | buf = read_sha1_file(sha1, &type, &size); |
74 | if (!buf) { |
79 | if (!buf) { |
75 | cgit_print_error(fmt("Error reading object %s", |
80 | cgit_print_error(fmt("Error reading object %s", |
76 | sha1_to_hex(sha1))); |
81 | sha1_to_hex(sha1))); |
77 | return; |
82 | return; |
78 | } |
83 | } |
|