X-Git-Url: https://gitweb.ps.run/ps-cgit/blobdiff_plain/bf8293d3196d49d6c4a48b254a04415183ca2762..bafab423f20bc1448b293842c235965e1681f07e:/html.c
diff --git a/html.c b/html.c
index eaabf72..b5c6903 100644
--- a/html.c
+++ b/html.c
@@ -39,7 +39,7 @@ static const char* url_escape_table[256] = {
"%fe", "%ff"
};
-int htmlfd = STDOUT_FILENO;
+static int htmlfd = STDOUT_FILENO;
char *fmt(const char *format, ...)
{
@@ -54,7 +54,7 @@ char *fmt(const char *format, ...)
va_start(args, format);
len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args);
va_end(args);
- if (len>sizeof(buf[bufidx])) {
+ if (len > sizeof(buf[bufidx])) {
fprintf(stderr, "[html.c] string truncated: %s\n", format);
exit(1);
}
@@ -92,101 +92,105 @@ void html_status(int code, const char *msg, int more_headers)
void html_txt(const char *txt)
{
const char *t = txt;
- while(t && *t){
+ while (t && *t) {
int c = *t;
- if (c=='<' || c=='>' || c=='&') {
- write(htmlfd, txt, t - txt);
- if (c=='>')
+ if (c == '<' || c == '>' || c == '&') {
+ html_raw(txt, t - txt);
+ if (c == '>')
html(">");
- else if (c=='<')
+ else if (c == '<')
html("<");
- else if (c=='&')
+ else if (c == '&')
html("&");
- txt = t+1;
+ txt = t + 1;
}
t++;
}
- if (t!=txt)
+ if (t != txt)
html(txt);
}
void html_ntxt(int len, const char *txt)
{
const char *t = txt;
- while(t && *t && len--){
+ while (t && *t && len--) {
int c = *t;
- if (c=='<' || c=='>' || c=='&') {
- write(htmlfd, txt, t - txt);
- if (c=='>')
+ if (c == '<' || c == '>' || c == '&') {
+ html_raw(txt, t - txt);
+ if (c == '>')
html(">");
- else if (c=='<')
+ else if (c == '<')
html("<");
- else if (c=='&')
+ else if (c == '&')
html("&");
- txt = t+1;
+ txt = t + 1;
}
t++;
}
- if (t!=txt)
- write(htmlfd, txt, t - txt);
- if (len<0)
+ if (t != txt)
+ html_raw(txt, t - txt);
+ if (len < 0)
html("...");
}
void html_attr(const char *txt)
{
const char *t = txt;
- while(t && *t){
+ while (t && *t) {
int c = *t;
- if (c=='<' || c=='>' || c=='\'' || c=='\"') {
- write(htmlfd, txt, t - txt);
- if (c=='>')
+ if (c == '<' || c == '>' || c == '\'' || c == '\"' || c == '&') {
+ html_raw(txt, t - txt);
+ if (c == '>')
html(">");
- else if (c=='<')
+ else if (c == '<')
html("<");
- else if (c=='\'')
+ else if (c == '\'')
html("'");
- else if (c=='"')
+ else if (c == '"')
html(""");
- txt = t+1;
+ else if (c == '&')
+ html("&");
+ txt = t + 1;
}
t++;
}
- if (t!=txt)
+ if (t != txt)
html(txt);
}
void html_url_path(const char *txt)
{
const char *t = txt;
- while(t && *t){
- int c = *t;
+ while (t && *t) {
+ unsigned char c = *t;
const char *e = url_escape_table[c];
- if (e && c!='+' && c!='&' && c!='+') {
- write(htmlfd, txt, t - txt);
- write(htmlfd, e, 3);
- txt = t+1;
+ if (e && c != '+' && c != '&') {
+ html_raw(txt, t - txt);
+ html(e);
+ txt = t + 1;
}
t++;
}
- if (t!=txt)
+ if (t != txt)
html(txt);
}
void html_url_arg(const char *txt)
{
const char *t = txt;
- while(t && *t){
- int c = *t;
+ while (t && *t) {
+ unsigned char c = *t;
const char *e = url_escape_table[c];
+ if (c == ' ')
+ e = "+";
if (e) {
- write(htmlfd, txt, t - txt);
- write(htmlfd, e, 3);
- txt = t+1;
+ html_raw(txt, t - txt);
+ html(e);
+ txt = t + 1;
}
t++;
}
- if (t!=txt)
+ if (t != txt)
html(txt);
}
@@ -211,6 +215,14 @@ void html_option(const char *value, const char *text, const char *selected_value
html("\n");
}
+void html_intoption(int value, const char *text, int selected_value)
+{
+ htmlf("");
+}
+
void html_link_open(const char *url, const char *title, const char *class)
{
html("