|
diff --git a/html.c b/html.c index bf1490f..fab67bd 100644 --- a/ html.c+++ b/ html.c |
|
@@ -1,48 +1,56 @@ |
| |
1 | /* html.c: helper functions for html output |
| |
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 | |
1 | #include "cgit.h" |
9 | #include "cgit.h" |
2 | |
10 | |
3 | char *fmt(const char *format, ...) |
11 | char *fmt(const char *format, ...) |
4 | { |
12 | { |
5 | static char buf[8][1024]; |
13 | static char buf[8][1024]; |
6 | static int bufidx; |
14 | static int bufidx; |
7 | int len; |
15 | int len; |
8 | va_list args; |
16 | va_list args; |
9 | |
17 | |
10 | bufidx++; |
18 | bufidx++; |
11 | bufidx &= 7; |
19 | bufidx &= 7; |
12 | |
20 | |
13 | va_start(args, format); |
21 | va_start(args, format); |
14 | len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args); |
22 | len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args); |
15 | va_end(args); |
23 | va_end(args); |
16 | if (len>sizeof(buf[bufidx])) |
24 | if (len>sizeof(buf[bufidx])) |
17 | die("[html.c] string truncated: %s", format); |
25 | die("[html.c] string truncated: %s", format); |
18 | return buf[bufidx]; |
26 | return buf[bufidx]; |
19 | } |
27 | } |
20 | |
28 | |
21 | void html(const char *txt) |
29 | void html(const char *txt) |
22 | { |
30 | { |
23 | write(htmlfd, txt, strlen(txt)); |
31 | write(htmlfd, txt, strlen(txt)); |
24 | } |
32 | } |
25 | |
33 | |
26 | void htmlf(const char *format, ...) |
34 | void htmlf(const char *format, ...) |
27 | { |
35 | { |
28 | static char buf[65536]; |
36 | static char buf[65536]; |
29 | va_list args; |
37 | va_list args; |
30 | |
38 | |
31 | va_start(args, format); |
39 | va_start(args, format); |
32 | vsnprintf(buf, sizeof(buf), format, args); |
40 | vsnprintf(buf, sizeof(buf), format, args); |
33 | va_end(args); |
41 | va_end(args); |
34 | html(buf); |
42 | html(buf); |
35 | } |
43 | } |
36 | |
44 | |
37 | void html_txt(char *txt) |
45 | void html_txt(char *txt) |
38 | { |
46 | { |
39 | char *t = txt; |
47 | char *t = txt; |
40 | while(*t){ |
48 | while(*t){ |
41 | int c = *t; |
49 | int c = *t; |
42 | if (c=='<' || c=='>' || c=='&') { |
50 | if (c=='<' || c=='>' || c=='&') { |
43 | *t = '\0'; |
51 | *t = '\0'; |
44 | html(txt); |
52 | html(txt); |
45 | *t = c; |
53 | *t = c; |
46 | if (c=='>') |
54 | if (c=='>') |
47 | html(">"); |
55 | html(">"); |
48 | else if (c=='<') |
56 | else if (c=='<') |
|