author | Florian Pritz <bluewind@xssn.at> | 2009-08-09 20:42:45 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2009-08-21 12:17:49 (UTC) |
commit | d67cc7f9d556650438e421cdcda37bc52710bffd (patch) (unidiff) | |
tree | df131c58de7c712550f124f8fb15aef303ff6054 /ui-tree.c | |
parent | 03389d6e67bfda5cb3ff1504db815f09715ec6f4 (diff) | |
download | cgit-d67cc7f9d556650438e421cdcda37bc52710bffd.zip cgit-d67cc7f9d556650438e421cdcda37bc52710bffd.tar.gz cgit-d67cc7f9d556650438e421cdcda37bc52710bffd.tar.bz2 |
Add 'linenumbers' config option
Signed-off-by: Florian Pritz <bluewind@xssn.at>
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | ui-tree.c | 27 |
1 files changed, 16 insertions, 11 deletions
@@ -1,70 +1,75 @@ | |||
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 | ||
14 | char *curr_rev; | 14 | char *curr_rev; |
15 | char *match_path; | 15 | char *match_path; |
16 | int header = 0; | 16 | int header = 0; |
17 | 17 | ||
18 | static void print_text_buffer(const char *name, char *buf, unsigned long size) | 18 | static 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 | ||
57 | static void print_binary_buffer(char *buf, unsigned long size) | 62 | static 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'>"); |