summaryrefslogtreecommitdiffabout
path: root/ui-tree.c
Unidiff
Diffstat (limited to 'ui-tree.c') (more/less context) (show whitespace changes)
-rw-r--r--ui-tree.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/ui-tree.c b/ui-tree.c
index c608754..f53ab64 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -1,143 +1,150 @@
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 if (ctx.repo->source_filter) {
26 html("<tr><td class='lines'><pre><code>");
27 ctx.repo->source_filter->argv[1] = xstrdup(name);
28 cgit_open_filter(ctx.repo->source_filter);
29 write(STDOUT_FILENO, buf, size);
30 cgit_close_filter(ctx.repo->source_filter);
31 html("</code></pre></td></tr></table>\n");
32 return;
33 }
34 25
26 if (ctx.cfg.enable_tree_linenumbers) {
35 html("<tr><td class='linenumbers'><pre>"); 27 html("<tr><td class='linenumbers'><pre>");
36 idx = 0; 28 idx = 0;
37 lineno = 0; 29 lineno = 0;
38 30
39 if (size) { 31 if (size) {
40 htmlf(numberfmt, ++lineno); 32 htmlf(numberfmt, ++lineno);
41 while(idx < size - 1) { // skip absolute last newline 33 while(idx < size - 1) { // skip absolute last newline
42 if (buf[idx] == '\n') 34 if (buf[idx] == '\n')
43 htmlf(numberfmt, ++lineno); 35 htmlf(numberfmt, ++lineno);
44 idx++; 36 idx++;
45 } 37 }
46 } 38 }
47 html("</pre></td>\n"); 39 html("</pre></td>\n");
40 }
41 else {
42 html("<tr>\n");
43 }
44
45 if (ctx.repo->source_filter) {
46 html("<td class='lines'><pre><code>");
47 ctx.repo->source_filter->argv[1] = xstrdup(name);
48 cgit_open_filter(ctx.repo->source_filter);
49 write(STDOUT_FILENO, buf, size);
50 cgit_close_filter(ctx.repo->source_filter);
51 html("</code></pre></td></tr></table>\n");
52 return;
53 }
54
48 html("<td class='lines'><pre><code>"); 55 html("<td class='lines'><pre><code>");
49 html_txt(buf); 56 html_txt(buf);
50 html("</code></pre></td></tr></table>\n"); 57 html("</code></pre></td></tr></table>\n");
51} 58}
52 59
53#define ROWLEN 32 60#define ROWLEN 32
54 61
55static void print_binary_buffer(char *buf, unsigned long size) 62static void print_binary_buffer(char *buf, unsigned long size)
56{ 63{
57 unsigned long ofs, idx; 64 unsigned long ofs, idx;
58 static char ascii[ROWLEN + 1]; 65 static char ascii[ROWLEN + 1];
59 66
60 html("<table summary='blob content' class='bin-blob'>\n"); 67 html("<table summary='blob content' class='bin-blob'>\n");
61 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>");
62 for (ofs = 0; ofs < size; ofs += ROWLEN, buf += ROWLEN) { 69 for (ofs = 0; ofs < size; ofs += ROWLEN, buf += ROWLEN) {
63 htmlf("<tr><td class='right'>%04x</td><td class='hex'>", ofs); 70 htmlf("<tr><td class='right'>%04x</td><td class='hex'>", ofs);
64 for (idx = 0; idx < ROWLEN && ofs + idx < size; idx++) 71 for (idx = 0; idx < ROWLEN && ofs + idx < size; idx++)
65 htmlf("%*s%02x", 72 htmlf("%*s%02x",
66 idx == 16 ? 4 : 1, "", 73 idx == 16 ? 4 : 1, "",
67 buf[idx] & 0xff); 74 buf[idx] & 0xff);
68 html(" </td><td class='hex'>"); 75 html(" </td><td class='hex'>");
69 for (idx = 0; idx < ROWLEN && ofs + idx < size; idx++) 76 for (idx = 0; idx < ROWLEN && ofs + idx < size; idx++)
70 ascii[idx] = isgraph(buf[idx]) ? buf[idx] : '.'; 77 ascii[idx] = isgraph(buf[idx]) ? buf[idx] : '.';
71 ascii[idx] = '\0'; 78 ascii[idx] = '\0';
72 html_txt(ascii); 79 html_txt(ascii);
73 html("</td></tr>\n"); 80 html("</td></tr>\n");
74 } 81 }
75 html("</table>\n"); 82 html("</table>\n");
76} 83}
77 84
78static 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)
79{ 86{
80 enum object_type type; 87 enum object_type type;
81 char *buf; 88 char *buf;
82 unsigned long size; 89 unsigned long size;
83 90
84 type = sha1_object_info(sha1, &size); 91 type = sha1_object_info(sha1, &size);
85 if (type == OBJ_BAD) { 92 if (type == OBJ_BAD) {
86 cgit_print_error(fmt("Bad object name: %s", 93 cgit_print_error(fmt("Bad object name: %s",
87 sha1_to_hex(sha1))); 94 sha1_to_hex(sha1)));
88 return; 95 return;
89 } 96 }
90 97
91 buf = read_sha1_file(sha1, &type, &size); 98 buf = read_sha1_file(sha1, &type, &size);
92 if (!buf) { 99 if (!buf) {
93 cgit_print_error(fmt("Error reading object %s", 100 cgit_print_error(fmt("Error reading object %s",
94 sha1_to_hex(sha1))); 101 sha1_to_hex(sha1)));
95 return; 102 return;
96 } 103 }
97 104
98 html(" ("); 105 html(" (");
99 cgit_plain_link("plain", NULL, NULL, ctx.qry.head, 106 cgit_plain_link("plain", NULL, NULL, ctx.qry.head,
100 curr_rev, path); 107 curr_rev, path);
101 htmlf(")<br/>blob: %s\n", sha1_to_hex(sha1)); 108 htmlf(")<br/>blob: %s\n", sha1_to_hex(sha1));
102 109
103 if (buffer_is_binary(buf, size)) 110 if (buffer_is_binary(buf, size))
104 print_binary_buffer(buf, size); 111 print_binary_buffer(buf, size);
105 else 112 else
106 print_text_buffer(basename, buf, size); 113 print_text_buffer(basename, buf, size);
107} 114}
108 115
109 116
110static 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,
111 const char *pathname, unsigned int mode, int stage, 118 const char *pathname, unsigned int mode, int stage,
112 void *cbdata) 119 void *cbdata)
113{ 120{
114 char *name; 121 char *name;
115 char *fullpath; 122 char *fullpath;
116 char *class; 123 char *class;
117 enum object_type type; 124 enum object_type type;
118 unsigned long size = 0; 125 unsigned long size = 0;
119 126
120 name = xstrdup(pathname); 127 name = xstrdup(pathname);
121 fullpath = fmt("%s%s%s", ctx.qry.path ? ctx.qry.path : "", 128 fullpath = fmt("%s%s%s", ctx.qry.path ? ctx.qry.path : "",
122 ctx.qry.path ? "/" : "", name); 129 ctx.qry.path ? "/" : "", name);
123 130
124 if (!S_ISGITLINK(mode)) { 131 if (!S_ISGITLINK(mode)) {
125 type = sha1_object_info(sha1, &size); 132 type = sha1_object_info(sha1, &size);
126 if (type == OBJ_BAD) { 133 if (type == OBJ_BAD) {
127 htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>", 134 htmlf("<tr><td colspan='3'>Bad object: %s %s</td></tr>",
128 name, 135 name,
129 sha1_to_hex(sha1)); 136 sha1_to_hex(sha1));
130 return 0; 137 return 0;
131 } 138 }
132 } 139 }
133 140
134 html("<tr><td class='ls-mode'>"); 141 html("<tr><td class='ls-mode'>");
135 cgit_print_filemode(mode); 142 cgit_print_filemode(mode);
136 html("</td><td>"); 143 html("</td><td>");
137 if (S_ISGITLINK(mode)) { 144 if (S_ISGITLINK(mode)) {
138 htmlf("<a class='ls-mod' href='"); 145 htmlf("<a class='ls-mod' href='");
139 html_attr(fmt(ctx.repo->module_link, 146 html_attr(fmt(ctx.repo->module_link,
140 name, 147 name,
141 sha1_to_hex(sha1))); 148 sha1_to_hex(sha1)));
142 html("'>"); 149 html("'>");
143 html_txt(name); 150 html_txt(name);