author | Lars Hjemli <hjemli@gmail.com> | 2006-12-10 21:41:14 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2006-12-10 21:41:14 (UTC) |
commit | 7640d90b73c01b16bb04ce4c541f52cbaae5f82a (patch) (unidiff) | |
tree | a0ec3e5222dbb0cff965487def39f5781e5cb231 /html.c | |
parent | 25105d7ecaba474d4b7c364ebb586aac3dfc5abb (diff) | |
download | cgit-7640d90b73c01b16bb04ce4c541f52cbaae5f82a.zip cgit-7640d90b73c01b16bb04ce4c541f52cbaae5f82a.tar.gz cgit-7640d90b73c01b16bb04ce4c541f52cbaae5f82a.tar.bz2 |
Add license file and copyright notices
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | html.c | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -1,102 +1,110 @@ | |||
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=='<') |
49 | html("<"); | 57 | html("<"); |
50 | else if (c=='&') | 58 | else if (c=='&') |
51 | html("&"); | 59 | html("&"); |
52 | txt = t+1; | 60 | txt = t+1; |
53 | } | 61 | } |
54 | t++; | 62 | t++; |
55 | } | 63 | } |
56 | if (t!=txt) | 64 | if (t!=txt) |
57 | html(txt); | 65 | html(txt); |
58 | } | 66 | } |
59 | 67 | ||
60 | 68 | ||
61 | void html_attr(char *txt) | 69 | void html_attr(char *txt) |
62 | { | 70 | { |
63 | char *t = txt; | 71 | char *t = txt; |
64 | while(*t){ | 72 | while(*t){ |
65 | int c = *t; | 73 | int c = *t; |
66 | if (c=='<' || c=='>' || c=='\'') { | 74 | if (c=='<' || c=='>' || c=='\'') { |
67 | *t = '\0'; | 75 | *t = '\0'; |
68 | html(txt); | 76 | html(txt); |
69 | *t = c; | 77 | *t = c; |
70 | if (c=='>') | 78 | if (c=='>') |
71 | html(">"); | 79 | html(">"); |
72 | else if (c=='<') | 80 | else if (c=='<') |
73 | html("<"); | 81 | html("<"); |
74 | else if (c=='\'') | 82 | else if (c=='\'') |
75 | html(""e;"); | 83 | html(""e;"); |
76 | txt = t+1; | 84 | txt = t+1; |
77 | } | 85 | } |
78 | t++; | 86 | t++; |
79 | } | 87 | } |
80 | if (t!=txt) | 88 | if (t!=txt) |
81 | html(txt); | 89 | html(txt); |
82 | } | 90 | } |
83 | 91 | ||
84 | void html_link_open(char *url, char *title, char *class) | 92 | void html_link_open(char *url, char *title, char *class) |
85 | { | 93 | { |
86 | html("<a href='"); | 94 | html("<a href='"); |
87 | html_attr(url); | 95 | html_attr(url); |
88 | if (title) { | 96 | if (title) { |
89 | html("' title='"); | 97 | html("' title='"); |
90 | html_attr(title); | 98 | html_attr(title); |
91 | } | 99 | } |
92 | if (class) { | 100 | if (class) { |
93 | html("' class='"); | 101 | html("' class='"); |
94 | html_attr(class); | 102 | html_attr(class); |
95 | } | 103 | } |
96 | html("'>"); | 104 | html("'>"); |
97 | } | 105 | } |
98 | 106 | ||
99 | void html_link_close(void) | 107 | void html_link_close(void) |
100 | { | 108 | { |
101 | html("</a>"); | 109 | html("</a>"); |
102 | } | 110 | } |