author | Lars Hjemli <hjemli@gmail.com> | 2008-09-01 20:40:24 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2008-09-01 20:40:24 (UTC) |
commit | 288d502b3d8e7fa916104b486bbb146521e5c716 (patch) (unidiff) | |
tree | afa132f6c973ab30e0b8ed1201fb691fe91103c0 /html.c | |
parent | 2cecf839a06ce951db0d5d95abf79004eff33ca7 (diff) | |
parent | 02a545e63454530c1639014d3239c14ced2022c6 (diff) | |
download | cgit-288d502b3d8e7fa916104b486bbb146521e5c716.zip cgit-288d502b3d8e7fa916104b486bbb146521e5c716.tar.gz cgit-288d502b3d8e7fa916104b486bbb146521e5c716.tar.bz2 |
Merge branch 'lh/clone'
* lh/clone:
Add support for cloning over http
Conflicts:
cmd.c
-rw-r--r-- | html.c | 7 |
1 files changed, 7 insertions, 0 deletions
@@ -6,96 +6,103 @@ | |||
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include <unistd.h> | 9 | #include <unistd.h> |
10 | #include <stdio.h> | 10 | #include <stdio.h> |
11 | #include <stdlib.h> | 11 | #include <stdlib.h> |
12 | #include <stdarg.h> | 12 | #include <stdarg.h> |
13 | #include <string.h> | 13 | #include <string.h> |
14 | #include <errno.h> | 14 | #include <errno.h> |
15 | 15 | ||
16 | int htmlfd = STDOUT_FILENO; | 16 | int htmlfd = STDOUT_FILENO; |
17 | 17 | ||
18 | char *fmt(const char *format, ...) | 18 | char *fmt(const char *format, ...) |
19 | { | 19 | { |
20 | static char buf[8][1024]; | 20 | static char buf[8][1024]; |
21 | static int bufidx; | 21 | static int bufidx; |
22 | int len; | 22 | int len; |
23 | va_list args; | 23 | va_list args; |
24 | 24 | ||
25 | bufidx++; | 25 | bufidx++; |
26 | bufidx &= 7; | 26 | bufidx &= 7; |
27 | 27 | ||
28 | va_start(args, format); | 28 | va_start(args, format); |
29 | len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args); | 29 | len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args); |
30 | va_end(args); | 30 | va_end(args); |
31 | if (len>sizeof(buf[bufidx])) { | 31 | if (len>sizeof(buf[bufidx])) { |
32 | fprintf(stderr, "[html.c] string truncated: %s\n", format); | 32 | fprintf(stderr, "[html.c] string truncated: %s\n", format); |
33 | exit(1); | 33 | exit(1); |
34 | } | 34 | } |
35 | return buf[bufidx]; | 35 | return buf[bufidx]; |
36 | } | 36 | } |
37 | 37 | ||
38 | void html(const char *txt) | 38 | void html(const char *txt) |
39 | { | 39 | { |
40 | write(htmlfd, txt, strlen(txt)); | 40 | write(htmlfd, txt, strlen(txt)); |
41 | } | 41 | } |
42 | 42 | ||
43 | void htmlf(const char *format, ...) | 43 | void htmlf(const char *format, ...) |
44 | { | 44 | { |
45 | static char buf[65536]; | 45 | static char buf[65536]; |
46 | va_list args; | 46 | va_list args; |
47 | 47 | ||
48 | va_start(args, format); | 48 | va_start(args, format); |
49 | vsnprintf(buf, sizeof(buf), format, args); | 49 | vsnprintf(buf, sizeof(buf), format, args); |
50 | va_end(args); | 50 | va_end(args); |
51 | html(buf); | 51 | html(buf); |
52 | } | 52 | } |
53 | 53 | ||
54 | void html_status(int code, int more_headers) | ||
55 | { | ||
56 | htmlf("Status: %d\n", code); | ||
57 | if (!more_headers) | ||
58 | html("\n"); | ||
59 | } | ||
60 | |||
54 | void html_txt(char *txt) | 61 | void html_txt(char *txt) |
55 | { | 62 | { |
56 | char *t = txt; | 63 | char *t = txt; |
57 | while(t && *t){ | 64 | while(t && *t){ |
58 | int c = *t; | 65 | int c = *t; |
59 | if (c=='<' || c=='>' || c=='&') { | 66 | if (c=='<' || c=='>' || c=='&') { |
60 | write(htmlfd, txt, t - txt); | 67 | write(htmlfd, txt, t - txt); |
61 | if (c=='>') | 68 | if (c=='>') |
62 | html(">"); | 69 | html(">"); |
63 | else if (c=='<') | 70 | else if (c=='<') |
64 | html("<"); | 71 | html("<"); |
65 | else if (c=='&') | 72 | else if (c=='&') |
66 | html("&"); | 73 | html("&"); |
67 | txt = t+1; | 74 | txt = t+1; |
68 | } | 75 | } |
69 | t++; | 76 | t++; |
70 | } | 77 | } |
71 | if (t!=txt) | 78 | if (t!=txt) |
72 | html(txt); | 79 | html(txt); |
73 | } | 80 | } |
74 | 81 | ||
75 | void html_ntxt(int len, char *txt) | 82 | void html_ntxt(int len, char *txt) |
76 | { | 83 | { |
77 | char *t = txt; | 84 | char *t = txt; |
78 | while(t && *t && len--){ | 85 | while(t && *t && len--){ |
79 | int c = *t; | 86 | int c = *t; |
80 | if (c=='<' || c=='>' || c=='&') { | 87 | if (c=='<' || c=='>' || c=='&') { |
81 | write(htmlfd, txt, t - txt); | 88 | write(htmlfd, txt, t - txt); |
82 | if (c=='>') | 89 | if (c=='>') |
83 | html(">"); | 90 | html(">"); |
84 | else if (c=='<') | 91 | else if (c=='<') |
85 | html("<"); | 92 | html("<"); |
86 | else if (c=='&') | 93 | else if (c=='&') |
87 | html("&"); | 94 | html("&"); |
88 | txt = t+1; | 95 | txt = t+1; |
89 | } | 96 | } |
90 | t++; | 97 | t++; |
91 | } | 98 | } |
92 | if (t!=txt) | 99 | if (t!=txt) |
93 | write(htmlfd, txt, t - txt); | 100 | write(htmlfd, txt, t - txt); |
94 | if (len<0) | 101 | if (len<0) |
95 | html("..."); | 102 | html("..."); |
96 | } | 103 | } |
97 | 104 | ||
98 | void html_attr(char *txt) | 105 | void html_attr(char *txt) |
99 | { | 106 | { |
100 | char *t = txt; | 107 | char *t = txt; |
101 | while(t && *t){ | 108 | while(t && *t){ |