|
diff --git a/html.c b/html.c index 5780dc1..bf1490f 100644 --- a/ html.c+++ b/ html.c |
|
@@ -1,100 +1,102 @@ |
1 | #include "cgit.h" |
1 | #include "cgit.h" |
2 | |
2 | |
3 | char *fmt(const char *format, ...) |
3 | char *fmt(const char *format, ...) |
4 | { |
4 | { |
5 | static char buf[8][1024]; |
5 | static char buf[8][1024]; |
6 | static int bufidx; |
6 | static int bufidx; |
7 | int len; |
7 | int len; |
8 | va_list args; |
8 | va_list args; |
9 | |
9 | |
10 | bufidx++; |
10 | bufidx++; |
11 | bufidx &= 7; |
11 | bufidx &= 7; |
12 | |
12 | |
13 | va_start(args, format); |
13 | va_start(args, format); |
14 | len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args); |
14 | len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args); |
15 | va_end(args); |
15 | va_end(args); |
16 | if (len>sizeof(buf[bufidx])) |
16 | if (len>sizeof(buf[bufidx])) |
17 | die("[html.c] string truncated: %s", format); |
17 | die("[html.c] string truncated: %s", format); |
18 | return buf[bufidx]; |
18 | return buf[bufidx]; |
19 | } |
19 | } |
20 | |
20 | |
21 | void html(const char *txt) |
21 | void html(const char *txt) |
22 | { |
22 | { |
23 | fputs(txt, stdout); |
23 | write(htmlfd, txt, strlen(txt)); |
24 | } |
24 | } |
25 | |
25 | |
26 | void htmlf(const char *format, ...) |
26 | void htmlf(const char *format, ...) |
27 | { |
27 | { |
| |
28 | static char buf[65536]; |
28 | va_list args; |
29 | va_list args; |
29 | |
30 | |
30 | va_start(args, format); |
31 | va_start(args, format); |
31 | vprintf(format, args); |
32 | vsnprintf(buf, sizeof(buf), format, args); |
32 | va_end(args); |
33 | va_end(args); |
| |
34 | html(buf); |
33 | } |
35 | } |
34 | |
36 | |
35 | void html_txt(char *txt) |
37 | void html_txt(char *txt) |
36 | { |
38 | { |
37 | char *t = txt; |
39 | char *t = txt; |
38 | while(*t){ |
40 | while(*t){ |
39 | int c = *t; |
41 | int c = *t; |
40 | if (c=='<' || c=='>' || c=='&') { |
42 | if (c=='<' || c=='>' || c=='&') { |
41 | *t = '\0'; |
43 | *t = '\0'; |
42 | html(txt); |
44 | html(txt); |
43 | *t = c; |
45 | *t = c; |
44 | if (c=='>') |
46 | if (c=='>') |
45 | html(">"); |
47 | html(">"); |
46 | else if (c=='<') |
48 | else if (c=='<') |
47 | html("<"); |
49 | html("<"); |
48 | else if (c=='&') |
50 | else if (c=='&') |
49 | html("&"); |
51 | html("&"); |
50 | txt = t+1; |
52 | txt = t+1; |
51 | } |
53 | } |
52 | t++; |
54 | t++; |
53 | } |
55 | } |
54 | if (t!=txt) |
56 | if (t!=txt) |
55 | html(txt); |
57 | html(txt); |
56 | } |
58 | } |
57 | |
59 | |
58 | |
60 | |
59 | void html_attr(char *txt) |
61 | void html_attr(char *txt) |
60 | { |
62 | { |
61 | char *t = txt; |
63 | char *t = txt; |
62 | while(*t){ |
64 | while(*t){ |
63 | int c = *t; |
65 | int c = *t; |
64 | if (c=='<' || c=='>' || c=='\'') { |
66 | if (c=='<' || c=='>' || c=='\'') { |
65 | *t = '\0'; |
67 | *t = '\0'; |
66 | html(txt); |
68 | html(txt); |
67 | *t = c; |
69 | *t = c; |
68 | if (c=='>') |
70 | if (c=='>') |
69 | html(">"); |
71 | html(">"); |
70 | else if (c=='<') |
72 | else if (c=='<') |
71 | html("<"); |
73 | html("<"); |
72 | else if (c=='\'') |
74 | else if (c=='\'') |
73 | html(""e;"); |
75 | html(""e;"); |
74 | txt = t+1; |
76 | txt = t+1; |
75 | } |
77 | } |
76 | t++; |
78 | t++; |
77 | } |
79 | } |
78 | if (t!=txt) |
80 | if (t!=txt) |
79 | html(txt); |
81 | html(txt); |
80 | } |
82 | } |
81 | |
83 | |
82 | void html_link_open(char *url, char *title, char *class) |
84 | void html_link_open(char *url, char *title, char *class) |
83 | { |
85 | { |
84 | html("<a href='"); |
86 | html("<a href='"); |
85 | html_attr(url); |
87 | html_attr(url); |
86 | if (title) { |
88 | if (title) { |
87 | html("' title='"); |
89 | html("' title='"); |
88 | html_attr(title); |
90 | html_attr(title); |
89 | } |
91 | } |
90 | if (class) { |
92 | if (class) { |
91 | html("' class='"); |
93 | html("' class='"); |
92 | html_attr(class); |
94 | html_attr(class); |
93 | } |
95 | } |
94 | html("'>"); |
96 | html("'>"); |
95 | } |
97 | } |
96 | |
98 | |
97 | void html_link_close(void) |
99 | void html_link_close(void) |
98 | { |
100 | { |
99 | html("</a>"); |
101 | html("</a>"); |
100 | } |
102 | } |
|