summaryrefslogtreecommitdiffabout
path: root/html.c
authorLars Hjemli <hjemli@gmail.com>2008-08-06 08:53:50 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2008-08-06 09:21:30 (UTC)
commite5da4bca54574522b28f88cab0dc8ebad9e35a73 (patch) (side-by-side diff)
tree08e02b9e0962a12040faab27e7841a74a800ddf2 /html.c
parent02a545e63454530c1639014d3239c14ced2022c6 (diff)
downloadcgit-e5da4bca54574522b28f88cab0dc8ebad9e35a73.zip
cgit-e5da4bca54574522b28f88cab0dc8ebad9e35a73.tar.gz
cgit-e5da4bca54574522b28f88cab0dc8ebad9e35a73.tar.bz2
Implement plain view
This implements a way to access plain blobs by path (similar to the tree view) instead of by sha1. Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'html.c') (more/less context) (show whitespace changes)
-rw-r--r--html.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/html.c b/html.c
index 1237076..83fc7a9 100644
--- a/html.c
+++ b/html.c
@@ -1,85 +1,90 @@
/* 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 <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
int htmlfd = STDOUT_FILENO;
char *fmt(const char *format, ...)
{
static char buf[8][1024];
static int bufidx;
int len;
va_list args;
bufidx++;
bufidx &= 7;
va_start(args, format);
len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args);
va_end(args);
if (len>sizeof(buf[bufidx])) {
fprintf(stderr, "[html.c] string truncated: %s\n", format);
exit(1);
}
return buf[bufidx];
}
+void html_raw(const char *data, size_t size)
+{
+ write(htmlfd, data, size);
+}
+
void html(const char *txt)
{
write(htmlfd, txt, strlen(txt));
}
void htmlf(const char *format, ...)
{
static char buf[65536];
va_list args;
va_start(args, format);
vsnprintf(buf, sizeof(buf), format, args);
va_end(args);
html(buf);
}
void html_status(int code, int more_headers)
{
htmlf("Status: %d\n", code);
if (!more_headers)
html("\n");
}
void html_txt(char *txt)
{
char *t = txt;
while(t && *t){
int c = *t;
if (c=='<' || c=='>' || c=='&') {
write(htmlfd, txt, t - txt);
if (c=='>')
html("&gt;");
else if (c=='<')
html("&lt;");
else if (c=='&')
html("&amp;");
txt = t+1;
}
t++;
}
if (t!=txt)
html(txt);
}
void html_ntxt(int len, char *txt)
{
char *t = txt;
while(t && *t && len--){