summaryrefslogtreecommitdiffabout
path: root/ui-tree.c
Unidiff
Diffstat (limited to 'ui-tree.c') (more/less context) (ignore whitespace changes)
-rw-r--r--ui-tree.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/ui-tree.c b/ui-tree.c
index 7bf2ad2..f64e6e0 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -1,134 +1,139 @@
1/* ui-tree.c: functions for tree output 1/* ui-tree.c: functions for tree output
2 * 2 *
3 * Copyright (C) 2006 Lars Hjemli 3 * Copyright (C) 2006 Lars Hjemli
4 * 4 *
5 * Licensed under GNU General Public License v2 5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text) 6 * (see COPYING for full license text)
7 */ 7 */
8 8
9#include <ctype.h> 9#include <ctype.h>
10#include "cgit.h" 10#include "cgit.h"
11#include "html.h" 11#include "html.h"
12#include "ui-shared.h" 12#include "ui-shared.h"
13 13
14char *curr_rev; 14char *curr_rev;
15char *match_path; 15char *match_path;
16int header = 0; 16int header = 0;
17 17
18static void print_text_buffer(const char *name, char *buf, unsigned long size) 18static void print_text_buffer(const char *name, 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 25
26 html("<tr><td class='linenumbers'><pre>"); 26 if (ctx.cfg.linenumbers) {
27 idx = 0; 27 html("<tr><td class='linenumbers'><pre>");
28 lineno = 0; 28 idx = 0;
29 29 lineno = 0;
30 if (size) { 30
31 htmlf(numberfmt, ++lineno); 31 if (size) {
32 while(idx < size - 1) { // skip absolute last newline 32 htmlf(numberfmt, ++lineno);
33 if (buf[idx] == '\n') 33 while(idx < size - 1) { // skip absolute last newline
34 htmlf(numberfmt, ++lineno); 34 if (buf[idx] == '\n')
35 idx++; 35 htmlf(numberfmt, ++lineno);
36 idx++;
37 }
36 } 38 }
39 html("</pre></td>\n");
40 }
41 else {
42 html("<tr>\n");
37 } 43 }
38 html("</pre></td>\n");
39 44
40 if (ctx.repo->source_filter) { 45 if (ctx.repo->source_filter) {
41 html("<td class='lines'><pre><code>"); 46 html("<td class='lines'><pre><code>");
42 ctx.repo->source_filter->argv[1] = xstrdup(name); 47 ctx.repo->source_filter->argv[1] = xstrdup(name);
43 cgit_open_filter(ctx.repo->source_filter); 48 cgit_open_filter(ctx.repo->source_filter);
44 write(STDOUT_FILENO, buf, size); 49 write(STDOUT_FILENO, buf, size);
45 cgit_close_filter(ctx.repo->source_filter); 50 cgit_close_filter(ctx.repo->source_filter);
46 html("</code></pre></td></tr></table>\n"); 51 html("</code></pre></td></tr></table>\n");
47 return; 52 return;
48 } 53 }
49 54
50 html("<td class='lines'><pre><code>"); 55 html("<td class='lines'><pre><code>");
51 html_txt(buf); 56 html_txt(buf);
52 html("</code></pre></td></tr></table>\n"); 57 html("</code></pre></td></tr></table>\n");
53} 58}
54 59
55#define ROWLEN 32 60#define ROWLEN 32
56 61
57static void print_binary_buffer(char *buf, unsigned long size) 62static void print_binary_buffer(char *buf, unsigned long size)
58{ 63{
59 unsigned long ofs, idx; 64 unsigned long ofs, idx;
60 static char ascii[ROWLEN + 1]; 65 static char ascii[ROWLEN + 1];
61 66
62 html("<table summary='blob content' class='bin-blob'>\n"); 67 html("<table summary='blob content' class='bin-blob'>\n");
63 html("<tr><th>ofs</th><th>hex dump</th><th>ascii</th></tr>"); 68 html("<tr><th>ofs</th><th>hex dump</th><th>ascii</th></tr>");
64 for (ofs = 0; ofs < size; ofs += ROWLEN, buf += ROWLEN) { 69 for (ofs = 0; ofs < size; ofs += ROWLEN, buf += ROWLEN) {
65 htmlf("<tr><td class='right'>%04x</td><td class='hex'>", ofs); 70 htmlf("<tr><td class='right'>%04x</td><td class='hex'>", ofs);
66 for (idx = 0; idx < ROWLEN && ofs + idx < size; idx++) 71 for (idx = 0; idx < ROWLEN && ofs + idx < size; idx++)
67 htmlf("%*s%02x", 72 htmlf("%*s%02x",
68 idx == 16 ? 4 : 1, "", 73 idx == 16 ? 4 : 1, "",
69 buf[idx] & 0xff); 74 buf[idx] & 0xff);
70 html(" </td><td class='hex'>"); 75 html(" </td><td class='hex'>");
71 for (idx = 0; idx < ROWLEN && ofs + idx < size; idx++) 76 for (idx = 0; idx < ROWLEN && ofs + idx < size; idx++)
72 ascii[idx] = isgraph(buf[idx]) ? buf[idx] : '.'; 77 ascii[idx] = isgraph(buf[idx]) ? buf[idx] : '.';
73 ascii[idx] = '\0'; 78 ascii[idx] = '\0';
74 html_txt(ascii); 79 html_txt(ascii);
75 html("</td></tr>\n"); 80 html("</td></tr>\n");
76 } 81 }
77 html("</table>\n"); 82 html("</table>\n");
78} 83}
79 84
80static void print_object(const unsigned char *sha1, char *path, const char *basename) 85static void print_object(const unsigned char *sha1, char *path, const char *basename)
81{ 86{
82 enum object_type type; 87 enum object_type type;
83 char *buf; 88 char *buf;
84 unsigned long size; 89 unsigned long size;
85 90
86 type = sha1_object_info(sha1, &size); 91 type = sha1_object_info(sha1, &size);
87 if (type == OBJ_BAD) { 92 if (type == OBJ_BAD) {
88 cgit_print_error(fmt("Bad object name: %s", 93 cgit_print_error(fmt("Bad object name: %s",
89 sha1_to_hex(sha1))); 94 sha1_to_hex(sha1)));
90 return; 95 return;
91 } 96 }
92 97
93 buf = read_sha1_file(sha1, &type, &size); 98 buf = read_sha1_file(sha1, &type, &size);
94 if (!buf) { 99 if (!buf) {
95 cgit_print_error(fmt("Error reading object %s", 100 cgit_print_error(fmt("Error reading object %s",
96 sha1_to_hex(sha1))); 101 sha1_to_hex(sha1)));
97 return; 102 return;
98 } 103 }
99 104
100 html(" ("); 105 html(" (");
101 cgit_plain_link("plain", NULL, NULL, ctx.qry.head, 106 cgit_plain_link("plain", NULL, NULL, ctx.qry.head,
102 curr_rev, path); 107 curr_rev, path);
103 htmlf(")<br/>blob: %s\n", sha1_to_hex(sha1)); 108 htmlf(")<br/>blob: %s\n", sha1_to_hex(sha1));
104 109
105 if (buffer_is_binary(buf, size)) 110 if (buffer_is_binary(buf, size))
106 print_binary_buffer(buf, size); 111 print_binary_buffer(buf, size);
107 else 112 else
108 print_text_buffer(basename, buf, size); 113 print_text_buffer(basename, buf, size);
109} 114}
110 115
111 116
112static int ls_item(const unsigned char *sha1, const char *base, int baselen, 117static int ls_item(const unsigned char *sha1, const char *base, int baselen,
113 const char *pathname, unsigned int mode, int stage, 118 const char *pathname, unsigned int mode, int stage,
114 void *cbdata) 119 void *cbdata)
115{ 120{
116 char *name; 121 char *name;
117 char *fullpath; 122 char *fullpath;
118 char *class; 123 char *class;
119 enum object_type type; 124 enum object_type type;
120 unsigned long size = 0; 125 unsigned long size = 0;
121 126
122 name = xstrdup(pathname); 127 name = xstrdup(pathname);
123 fullpath = fmt("%s%s%s", ctx.qry.path ? ctx.qry.path : "", 128 fullpath = fmt("%s%s%s", ctx.qry.path ? ctx.qry.path : "",
124 ctx.qry.path ? "/" : "", name); 129 ctx.qry.path ? "/" : "", name);
125 130
126 if (!S_ISGITLINK(mode)) { 131 if (!S_ISGITLINK(mode)) {
127 type = sha1_object_info(sha1, &size); 132 type = sha1_object_info(sha1, &size);
128 if (type == OBJ_BAD) { 133 if (type == OBJ_BAD) {
129 htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", 134 htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>",
130 name, 135 name,
131 sha1_to_hex(sha1)); 136 sha1_to_hex(sha1));
132 return 0; 137 return 0;
133 } 138 }
134 } 139 }