Lars Hjemli | df63119 | 2006-12-11 17:12:26 +0100 | [diff] [blame] | 1 | /* ui-view.c: functions to output _any_ object, given it's sha1 |
| 2 | * |
| 3 | * Copyright (C) 2006 Lars Hjemli |
| 4 | * |
| 5 | * Licensed under GNU General Public License v2 |
| 6 | * (see COPYING for full license text) |
| 7 | */ |
| 8 | |
| 9 | #include "cgit.h" |
| 10 | |
Lars Hjemli | 9a8f886 | 2006-12-16 00:19:56 +0100 | [diff] [blame] | 11 | void cgit_print_view(const char *hex) |
Lars Hjemli | df63119 | 2006-12-11 17:12:26 +0100 | [diff] [blame] | 12 | { |
| 13 | unsigned char sha1[20]; |
| 14 | char type[20]; |
| 15 | unsigned char *buf; |
| 16 | unsigned long size; |
| 17 | |
| 18 | if (get_sha1_hex(hex, sha1)){ |
| 19 | cgit_print_error(fmt("Bad hex value: %s", hex)); |
| 20 | return; |
| 21 | } |
| 22 | |
Lars Hjemli | 06fe0c2 | 2006-12-13 00:13:27 +0100 | [diff] [blame] | 23 | if (sha1_object_info(sha1, type, &size)){ |
Lars Hjemli | df63119 | 2006-12-11 17:12:26 +0100 | [diff] [blame] | 24 | cgit_print_error("Bad object name"); |
| 25 | return; |
| 26 | } |
| 27 | |
| 28 | buf = read_sha1_file(sha1, type, &size); |
| 29 | if (!buf) { |
| 30 | cgit_print_error("Error reading object"); |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | buf[size] = '\0'; |
Lars Hjemli | 9c2e863 | 2006-12-13 00:36:22 +0100 | [diff] [blame] | 35 | html("<table class='list'>\n"); |
Lars Hjemli | 777faf7 | 2007-01-28 00:39:26 +0100 | [diff] [blame] | 36 | htmlf("<tr class='nohover'><th class='left'>%s %s, %li bytes</th></tr>\n", type, hex, size); |
Lars Hjemli | 9c2e863 | 2006-12-13 00:36:22 +0100 | [diff] [blame] | 37 | html("<tr><td class='blob'>\n"); |
Lars Hjemli | df63119 | 2006-12-11 17:12:26 +0100 | [diff] [blame] | 38 | html_txt(buf); |
Lars Hjemli | 9c2e863 | 2006-12-13 00:36:22 +0100 | [diff] [blame] | 39 | html("\n</td></tr>\n"); |
| 40 | html("</table>\n"); |
Lars Hjemli | df63119 | 2006-12-11 17:12:26 +0100 | [diff] [blame] | 41 | } |