X-Git-Url: https://gitweb.ps.run/ps-cgit/blobdiff_plain/9043b46f85eb43c918a172663af34c084587bd1a..4b4a62d507adc61e20e75e2748301ef307a6c95f:/html.c diff --git a/html.c b/html.c index 1305910..8c45ba6 100644 --- a/html.c +++ b/html.c @@ -6,6 +6,8 @@ * (see COPYING for full license text) */ +#include "cgit.h" +#include "html.h" #include #include #include @@ -39,7 +41,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 +56,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); } @@ -63,12 +65,13 @@ char *fmt(const char *format, ...) void html_raw(const char *data, size_t size) { - write(htmlfd, data, size); + if (write(htmlfd, data, size) != size) + fprintf(stderr, "[html.c] html output truncated.\n"); } void html(const char *txt) { - write(htmlfd, txt, strlen(txt)); + html_raw(txt, strlen(txt)); } void htmlf(const char *format, ...) @@ -92,101 +95,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=='&') { + if (c == '<' || c == '>' || c == '&') { html_raw(txt, t - txt); - if (c=='>') + 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=='&') { + if (c == '<' || c == '>' || c == '&') { html_raw(txt, t - txt); - if (c=='>') + 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_raw(txt, t - txt); - if (len<0) + 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=='\"') { + if (c == '<' || c == '>' || c == '\'' || c == '\"' || c == '&') { html_raw(txt, t - txt); - if (c=='>') + 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!='+') { + if (e && c != '+' && c != '&') { html_raw(txt, t - txt); - html_raw(e, 3); - txt = t+1; + 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) { html_raw(txt, t - txt); - html_raw(e, 3); - txt = t+1; + html(e); + txt = t + 1; } t++; } - if (t!=txt) + if (t != txt) html(txt); } @@ -211,6 +218,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("