aboutsummaryrefslogtreecommitdiffstats
path: root/ui-tree.c
diff options
context:
space:
mode:
authorLars Hjemli2009-02-12 11:26:14 +0100
committerLars Hjemli2009-02-12 11:26:14 +0100
commit6063e7b5532481ffaa7a6f080de28547983bbeb7 (patch)
treebd99ed1e42982e2c7ead156918b3c0e03ef54d1f /ui-tree.c
parent8cc02871230aef457006ac775dd1cca5623516a9 (diff)
downloadcgit-6063e7b5532481ffaa7a6f080de28547983bbeb7.tar.gz
cgit-6063e7b5532481ffaa7a6f080de28547983bbeb7.tar.bz2
cgit-6063e7b5532481ffaa7a6f080de28547983bbeb7.zip
ui-tree: escape ascii-text properly in hexdump view
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'ui-tree.c')
-rw-r--r--ui-tree.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/ui-tree.c b/ui-tree.c
index a37a4e5..c6159ec 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -37,21 +37,26 @@ static void print_text_buffer(char *buf, unsigned long size)
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
40static void print_binary_buffer(char *buf, unsigned long size) 42static 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");