author | Lars Hjemli <hjemli@gmail.com> | 2009-02-12 10:26:14 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2009-02-12 10:26:14 (UTC) |
commit | 6063e7b5532481ffaa7a6f080de28547983bbeb7 (patch) (unidiff) | |
tree | bd99ed1e42982e2c7ead156918b3c0e03ef54d1f | |
parent | 8cc02871230aef457006ac775dd1cca5623516a9 (diff) | |
download | cgit-6063e7b5532481ffaa7a6f080de28547983bbeb7.zip cgit-6063e7b5532481ffaa7a6f080de28547983bbeb7.tar.gz cgit-6063e7b5532481ffaa7a6f080de28547983bbeb7.tar.bz2 |
ui-tree: escape ascii-text properly in hexdump view
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | ui-tree.c | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -32,31 +32,36 @@ static void print_text_buffer(char *buf, unsigned long size) | |||
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; |