X-Git-Url: https://gitweb.ps.run/ps-cgit/blobdiff_plain/0d169ada2ba81210ab1191a5f2212662e90db77e..7dd50c98d73bf6c579b8ce5893739a2d0ffc00d5:/html.c diff --git a/html.c b/html.c index 5780dc1..c0b2ed4 100644 --- a/html.c +++ b/html.c @@ -1,3 +1,11 @@ +/* html.c: helper functions for html output + * + * Copyright (C) 2006 Lars Hjemli + * + * Licensed under GNU General Public License v2 + * (see COPYING for full license text) + */ + #include "cgit.h" char *fmt(const char *format, ...) @@ -20,22 +28,24 @@ char *fmt(const char *format, ...) void html(const char *txt) { - fputs(txt, stdout); + write(htmlfd, txt, strlen(txt)); } void htmlf(const char *format, ...) { + static char buf[65536]; va_list args; va_start(args, format); - vprintf(format, args); + vsnprintf(buf, sizeof(buf), format, args); va_end(args); + html(buf); } void html_txt(char *txt) { char *t = txt; - while(*t){ + while(t && *t){ int c = *t; if (c=='<' || c=='>' || c=='&') { *t = '\0'; @@ -55,11 +65,39 @@ void html_txt(char *txt) html(txt); } +void html_ntxt(int len, char *txt) +{ + char *t = txt; + while(t && *t && len--){ + int c = *t; + if (c=='<' || c=='>' || c=='&') { + *t = '\0'; + html(txt); + *t = c; + if (c=='>') + html(">"); + else if (c=='<') + html("<"); + else if (c=='&') + html("&"); + txt = t+1; + } + t++; + } + if (t!=txt) { + char c = *t; + *t = '\0'; + html(txt); + *t = c; + } + if (len<0) + html("..."); +} void html_attr(char *txt) { char *t = txt; - while(*t){ + while(t && *t){ int c = *t; if (c=='<' || c=='>' || c=='\'') { *t = '\0'; @@ -79,6 +117,15 @@ void html_attr(char *txt) html(txt); } +void html_hidden(char *name, char *value) +{ + html(""); +} + void html_link_open(char *url, char *title, char *class) { html("> 6); + html_fileperm(mode >> 3); + html_fileperm(mode); +} +