summaryrefslogtreecommitdiff
path: root/ui-tree.c
diff options
context:
space:
mode:
authorLars Hjemli <hjemli@gmail.com>2009-01-31 17:45:48 +0100
committerLars Hjemli <hjemli@gmail.com>2009-01-31 17:45:48 +0100
commitae1d4d75b2a2eb3534ff4b3685cc5c0b80007ef7 (patch)
tree89b745555c6c47b63868bc6aa15d5e5d5d294b34 /ui-tree.c
parentc495cf02bac16e459f7c9e1740798646f12c00c5 (diff)
downloadcgit-ae1d4d75b2a2eb3534ff4b3685cc5c0b80007ef7.tar.gz
cgit-ae1d4d75b2a2eb3534ff4b3685cc5c0b80007ef7.tar.bz2
cgit-ae1d4d75b2a2eb3534ff4b3685cc5c0b80007ef7.zip
ui-tree: show hexdump of binary blobs
This teaches ui-tree to detect binary blobs and display them similar to `hexdump -C` (only wider). Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'ui-tree.c')
-rw-r--r--ui-tree.c71
1 files changed, 48 insertions, 23 deletions
diff --git a/ui-tree.c b/ui-tree.c
index c26ba4c..a37a4e5 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -6,6 +6,7 @@
* (see COPYING for full license text)
*/
+#include <ctype.h>
#include "cgit.h"
#include "html.h"
#include "ui-shared.h"
@@ -14,12 +15,53 @@ char *curr_rev;
char *match_path;
int header = 0;
+static void print_text_buffer(char *buf, unsigned long size)
+{
+ unsigned long lineno, idx;
+ const char *numberfmt =
+ "<a class='no' id='n%1$d' name='n%1$d' href='#n%1$d'>%1$d</a>\n";
+
+ html("<table summary='blob content' class='blob'>\n");
+ html("<tr><td class='linenumbers'><pre>");
+ idx = 0;
+ lineno = 0;
+ htmlf(numberfmt, ++lineno);
+ while(idx < size - 1) { // skip absolute last newline
+ if (buf[idx] == '\n')
+ htmlf(numberfmt, ++lineno);
+ idx++;
+ }
+ html("</pre></td>\n");
+ html("<td class='lines'><pre><code>");
+ html_txt(buf);
+ html("</code></pre></td></tr></table>\n");
+}
+
+static void print_binary_buffer(char *buf, unsigned long size)
+{
+ unsigned long ofs, idx;
+
+ html("<table summary='blob content' class='bin-blob'>\n");
+ html("<tr><th>ofs</th><th>hex dump</th><th>ascii</th></tr>");
+ for (ofs = 0; ofs < size; ofs += 32, buf += 32) {
+ htmlf("<tr><td class='right'>%04x</td><td class='hex'>", ofs);
+ for (idx = 0; idx < 32 && ofs + idx < size; idx++)
+ htmlf("%*s%02x",
+ idx == 16 ? 4 : 1, "",
+ buf[idx] & 0xff);
+ html(" </td><td class='hex'>");
+ for (idx = 0; idx < 32 && ofs + idx < size; idx++)
+ htmlf("%c", isgraph(buf[idx]) ? buf[idx] : '.');
+ html("</td></tr>\n");
+ }
+ html("</table>\n");
+}
+
static void print_object(const unsigned char *sha1, char *path)
{
enum object_type type;
char *buf;
- unsigned long size, lineno, idx;
- const char *numberfmt = "<a class='no' id='n%1$d' name='n%1$d' href='#n%1$d'>%1$d</a>\n";
+ unsigned long size;
type = sha1_object_info(sha1, &size);
if (type == OBJ_BAD) {
@@ -40,27 +82,10 @@ static void print_object(const unsigned char *sha1, char *path)
curr_rev, path);
htmlf(")<br/>blob: %s\n", sha1_to_hex(sha1));
- html("<table summary='blob content' class='blob'>\n");
- html("<tr>\n");
-
- html("<td class='linenumbers'><pre>");
- idx = 0;
- lineno = 0;
- htmlf(numberfmt, ++lineno);
- while(idx < size - 1) { // skip absolute last newline
- if (buf[idx] == '\n') {
- htmlf(numberfmt, ++lineno);
- }
- idx++;
- }
- html("</pre></td>\n");
-
- html("<td class='lines'><pre><code>");
- html_txt(buf);
- html("</code></pre></td>\n");
-
- html("</tr>\n");
- html("</table>\n");
+ if (buffer_is_binary(buf, size))
+ print_binary_buffer(buf, size);
+ else
+ print_text_buffer(buf, size);
}
ass='logsubject'> r703@Devoty: necoro | 2008-01-22 12:32:39 +0100Necoro3-185/+1072 Added polish translation 2008-01-20 r694@Devoty: necoro | 2008-01-20 16:28:55 +0100Necoro1-184/+186 Made notebooks scrollable 2008-01-20 r691@Devoty: necoro | 2008-01-20 15:19:45 +0100Necoro1-7/+9 Changed etc-proposals plugin so only root can launch it 2008-01-20 r690@Devoty: necoro | 2008-01-20 15:15:16 +0100Necoro4-527/+525 Translation work 2008-01-20 r687@Devoty: necoro | 2008-01-20 13:56:53 +0100Necoro1-2/+2 Better default position for HPaned 2008-01-20 r686@Devoty: necoro | 2008-01-20 04:50:27 +0100Necoro1-2/+3 Handle browser commands with spaces correctly 2008-01-20 r682@Devoty: necoro | 2008-01-20 03:23:02 +0100Necoro2-5/+5 remove package at the _end_ of the merge 2008-01-20 r680@Devoty: necoro | 2008-01-20 02:53:30 +0100Necoro7-55/+100 Fixed flag handling 2008-01-19 r675@Devoty: necoro | 2008-01-19 23:33:38 +0100Necoro2-366/+396 don't hide the package tab at the beginning; added the generalScroll r678@Devoty: necoro | 2008-01-20 00:14:19 +0100 Some session loading/saving 2008-01-18 r669@Devoty: necoro | 2008-01-18 22:49:33 +0100Necoro1-6/+6 Made it really work 2008-01-18 r664@Devoty: necoro | 2008-01-18 21:40:29 +0100Necoro5-26/+181 First support for 'delete on demand' r665@Devoty: necoro | 2008-01-18 22:18:05 +0100 Finished the 'on demand removal' 2008-01-18 r661@Devoty: necoro | 2008-01-18 14:16:59 +0100Necoro8-211/+293 First support for interactive emerges r662@Devoty: necoro | 2008-01-18 20:22:58 +0100 Now finished interactive emerges 2008-01-18 r655@Devoty: necoro | 2008-01-18 03:04:53 +0100Necoro1-1/+1 Small bugfix 2008-01-18 r651@Devoty: necoro | 2008-01-18 02:41:51 +0100Necoro3-393/+513 adjust changelog and translation 2008-01-18 r643@Devoty: necoro | 2008-01-16 18:55:49 +0100Necoro14-249/+525 Fixed small bug in PackageTable.cb_package_revert_clicked r646@Devoty: necoro | 2008-01-18 00:12:30 +0100 Make tabpositions being configurable by the user r647@Devoty: necoro | 2008-01-18 01:38:19 +0100 Renamed 'shm' to '_shm' to not hide the global one r648@Devoty: necoro | 2008-01-18 01:38:29 +0100 Renamed 'shm' to '_shm' to not hide the global one r649@Devoty: necoro | 2008-01-18 02:34:43 +0100 Added update queues; general UI improvement 2008-01-14 r634@Devoty: necoro | 2008-01-14 23:48:24 +0100Necoro3-1/+4 Removed the broken plugins until they get replaced 2008-01-14 r632@Devoty: necoro | 2008-01-14 23:44:52 +0100Necoro3-175/+181 small changes 2008-01-14(no commit message)Necoro10-758/+1014 2008-01-14 r621@Devoty: necoro | 2008-01-14 20:21:40 +0100Necoro2-21/+61 adjust changelog r622@Devoty: necoro | 2008-01-14 21:01:11 +0100 Some new views 2008-01-14 r618@Devoty: necoro | 2008-01-14 20:19:05 +0100Necoro2-35/+57 An ALL category 2008-01-14 r617@Devoty: necoro | 2008-01-14 19:12:59 +0100Necoro2-10/+10 Remove unnecessairy loads of the shm module 2008-01-14 r609@Devoty: necoro | 2008-01-14 17:04:38 +0100Necoro9-394/+477 Allowed '-' and '_' in key names. Also use group names instead of their number. r610@Devoty: necoro | 2008-01-14 17:05:42 +0100 Disabled saving of the queues r611@Devoty: necoro | 2008-01-14 17:08:53 +0100 Added the possibility to permanently en-/disable plugins r612@Devoty: necoro | 2008-01-14 17:14:09 +0100 adjust changelog and translations r613@Devoty: necoro | 2008-01-14 17:40:53 +0100 Dropdown should be localized too 2008-01-14 r605@Devoty: necoro | 2008-01-14 11:43:34 +0100Necoro2-26/+129 Updated shm module to version 1.1.4 2008-01-14 r603@Devoty: necoro | 2008-01-14 11:30:26 +0100Necoro4-26/+38 Improved 'update world'; really support new use defaults 2008-01-11 r598@Devoty: necoro | 2008-01-10 16:36:29 +0100Necoro4-10/+50 Handle the new useflag format correctly 2008-01-11 r597@Devoty: necoro | 2008-01-10 14:12:35 +0100Necoro1-3/+3 updated todo 2008-01-10 r595@Devoty: necoro | 2008-01-10 04:04:15 +0100Necoro1-52/+3 Re-Introduced etc-proposals 2008-01-09 r586@Devoty: necoro | 2008-01-09 14:54:18 +0100Necoro1-1/+1 Disabled catapult till it is really usable 2007-12-06 r577@Devoty: necoro | 2007-12-06 20:37:36 +0100Necoro1-1/+1 Fixed desktop file 2007-12-06 r572@Devoty: necoro | 2007-11-28 08:48:15 +0100Necoro1-0/+1 2007-11-27 r570@Devoty: necoro | 2007-11-27 02:08:21 +0100Necoro3-84/+108 Added scrollbars to update window