|
diff --git a/html.c b/html.c index 6c9cc8b..d531c20 100644 --- a/ html.c+++ b/ html.c |
|
@@ -27,103 +27,93 @@ char *fmt(const char *format, ...) |
27 | } |
27 | } |
28 | |
28 | |
29 | void html(const char *txt) |
29 | void html(const char *txt) |
30 | { |
30 | { |
31 | write(htmlfd, txt, strlen(txt)); |
31 | write(htmlfd, txt, strlen(txt)); |
32 | } |
32 | } |
33 | |
33 | |
34 | void htmlf(const char *format, ...) |
34 | void htmlf(const char *format, ...) |
35 | { |
35 | { |
36 | static char buf[65536]; |
36 | static char buf[65536]; |
37 | va_list args; |
37 | va_list args; |
38 | |
38 | |
39 | va_start(args, format); |
39 | va_start(args, format); |
40 | vsnprintf(buf, sizeof(buf), format, args); |
40 | vsnprintf(buf, sizeof(buf), format, args); |
41 | va_end(args); |
41 | va_end(args); |
42 | html(buf); |
42 | html(buf); |
43 | } |
43 | } |
44 | |
44 | |
45 | void html_txt(char *txt) |
45 | void html_txt(char *txt) |
46 | { |
46 | { |
47 | char *t = txt; |
47 | char *t = txt; |
48 | while(t && *t){ |
48 | while(t && *t){ |
49 | int c = *t; |
49 | int c = *t; |
50 | if (c=='<' || c=='>' || c=='&') { |
50 | if (c=='<' || c=='>' || c=='&') { |
51 | *t = '\0'; |
51 | write(htmlfd, txt, t - txt); |
52 | html(txt); |
| |
53 | *t = c; |
| |
54 | if (c=='>') |
52 | if (c=='>') |
55 | html(">"); |
53 | html(">"); |
56 | else if (c=='<') |
54 | else if (c=='<') |
57 | html("<"); |
55 | html("<"); |
58 | else if (c=='&') |
56 | else if (c=='&') |
59 | html("&"); |
57 | html("&"); |
60 | txt = t+1; |
58 | txt = t+1; |
61 | } |
59 | } |
62 | t++; |
60 | t++; |
63 | } |
61 | } |
64 | if (t!=txt) |
62 | if (t!=txt) |
65 | html(txt); |
63 | html(txt); |
66 | } |
64 | } |
67 | |
65 | |
68 | void html_ntxt(int len, char *txt) |
66 | void html_ntxt(int len, char *txt) |
69 | { |
67 | { |
70 | char *t = txt; |
68 | char *t = txt; |
71 | while(t && *t && len--){ |
69 | while(t && *t && len--){ |
72 | int c = *t; |
70 | int c = *t; |
73 | if (c=='<' || c=='>' || c=='&') { |
71 | if (c=='<' || c=='>' || c=='&') { |
74 | *t = '\0'; |
72 | write(htmlfd, txt, t - txt); |
75 | html(txt); |
| |
76 | *t = c; |
| |
77 | if (c=='>') |
73 | if (c=='>') |
78 | html(">"); |
74 | html(">"); |
79 | else if (c=='<') |
75 | else if (c=='<') |
80 | html("<"); |
76 | html("<"); |
81 | else if (c=='&') |
77 | else if (c=='&') |
82 | html("&"); |
78 | html("&"); |
83 | txt = t+1; |
79 | txt = t+1; |
84 | } |
80 | } |
85 | t++; |
81 | t++; |
86 | } |
82 | } |
87 | if (t!=txt) { |
83 | if (t!=txt) |
88 | char c = *t; |
84 | write(htmlfd, txt, t - txt); |
89 | *t = '\0'; |
| |
90 | html(txt); |
| |
91 | *t = c; |
| |
92 | } |
| |
93 | if (len<0) |
85 | if (len<0) |
94 | html("..."); |
86 | html("..."); |
95 | } |
87 | } |
96 | |
88 | |
97 | void html_attr(char *txt) |
89 | void html_attr(char *txt) |
98 | { |
90 | { |
99 | char *t = txt; |
91 | char *t = txt; |
100 | while(t && *t){ |
92 | while(t && *t){ |
101 | int c = *t; |
93 | int c = *t; |
102 | if (c=='<' || c=='>' || c=='\'') { |
94 | if (c=='<' || c=='>' || c=='\'') { |
103 | *t = '\0'; |
95 | write(htmlfd, txt, t - txt); |
104 | html(txt); |
| |
105 | *t = c; |
| |
106 | if (c=='>') |
96 | if (c=='>') |
107 | html(">"); |
97 | html(">"); |
108 | else if (c=='<') |
98 | else if (c=='<') |
109 | html("<"); |
99 | html("<"); |
110 | else if (c=='\'') |
100 | else if (c=='\'') |
111 | html(""e;"); |
101 | html(""e;"); |
112 | txt = t+1; |
102 | txt = t+1; |
113 | } |
103 | } |
114 | t++; |
104 | t++; |
115 | } |
105 | } |
116 | if (t!=txt) |
106 | if (t!=txt) |
117 | html(txt); |
107 | html(txt); |
118 | } |
108 | } |
119 | |
109 | |
120 | void html_hidden(char *name, char *value) |
110 | void html_hidden(char *name, char *value) |
121 | { |
111 | { |
122 | html("<input type='hidden' name='"); |
112 | html("<input type='hidden' name='"); |
123 | html_attr(name); |
113 | html_attr(name); |
124 | html("' value='"); |
114 | html("' value='"); |
125 | html_attr(value); |
115 | html_attr(value); |
126 | html("'/>"); |
116 | html("'/>"); |
127 | } |
117 | } |
128 | |
118 | |
129 | void html_option(char *value, char *text, char *selected_value) |
119 | void html_option(char *value, char *text, char *selected_value) |
|