summaryrefslogtreecommitdiffabout
path: root/html.c
authorLars Hjemli <hjemli@gmail.com>2008-02-23 21:45:33 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2008-03-18 07:13:10 (UTC)
commitb1f9b9c1459cb9a30ebf80721aff6ef788d1f891 (patch) (unidiff)
tree05796a741faef90c12aadd3a5c92b702ec870c48 /html.c
parentb88fb016d0209f7041ac7d3b4d2c077318407a4d (diff)
downloadcgit-b1f9b9c1459cb9a30ebf80721aff6ef788d1f891.zip
cgit-b1f9b9c1459cb9a30ebf80721aff6ef788d1f891.tar.gz
cgit-b1f9b9c1459cb9a30ebf80721aff6ef788d1f891.tar.bz2
Introduce html.h
All html-functions can be quite easily separated from the rest of cgit, so lets do it; the only issue was html_filemode which uses some git-defined macros so the function is moved into ui-shared.c::cgit_print_filemode(). Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'html.c') (more/less context) (ignore whitespace changes)
-rw-r--r--html.c31
1 files changed, 12 insertions, 19 deletions
diff --git a/html.c b/html.c
index eb163d9..0962e71 100644
--- a/html.c
+++ b/html.c
@@ -3,13 +3,19 @@
3 * Copyright (C) 2006 Lars Hjemli 3 * Copyright (C) 2006 Lars Hjemli
4 * 4 *
5 * Licensed under GNU General Public License v2 5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text) 6 * (see COPYING for full license text)
7 */ 7 */
8 8
9#include "cgit.h" 9#include <unistd.h>
10#include <stdio.h>
11#include <stdlib.h>
12#include <stdarg.h>
13#include <string.h>
14
15int htmlfd = STDOUT_FILENO;
10 16
11char *fmt(const char *format, ...) 17char *fmt(const char *format, ...)
12{ 18{
13 static char buf[8][1024]; 19 static char buf[8][1024];
14 static int bufidx; 20 static int bufidx;
15 int len; 21 int len;
@@ -18,14 +24,16 @@ char *fmt(const char *format, ...)
18 bufidx++; 24 bufidx++;
19 bufidx &= 7; 25 bufidx &= 7;
20 26
21 va_start(args, format); 27 va_start(args, format);
22 len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args); 28 len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args);
23 va_end(args); 29 va_end(args);
24 if (len>sizeof(buf[bufidx])) 30 if (len>sizeof(buf[bufidx])) {
25 die("[html.c] string truncated: %s", format); 31 fprintf(stderr, "[html.c] string truncated: %s\n", format);
32 exit(1);
33 }
26 return buf[bufidx]; 34 return buf[bufidx];
27} 35}
28 36
29void html(const char *txt) 37void html(const char *txt)
30{ 38{
31 write(htmlfd, txt, strlen(txt)); 39 write(htmlfd, txt, strlen(txt));
@@ -157,31 +165,16 @@ void html_link_close(void)
157{ 165{
158 html("</a>"); 166 html("</a>");
159} 167}
160 168
161void html_fileperm(unsigned short mode) 169void html_fileperm(unsigned short mode)
162{ 170{
163 htmlf("%c%c%c", (mode & 4 ? 'r' : '-'), 171 htmlf("%c%c%c", (mode & 4 ? 'r' : '-'),
164 (mode & 2 ? 'w' : '-'), (mode & 1 ? 'x' : '-')); 172 (mode & 2 ? 'w' : '-'), (mode & 1 ? 'x' : '-'));
165} 173}
166 174
167void html_filemode(unsigned short mode)
168{
169 if (S_ISDIR(mode))
170 html("d");
171 else if (S_ISLNK(mode))
172 html("l");
173 else if (S_ISGITLINK(mode))
174 html("m");
175 else
176 html("-");
177 html_fileperm(mode >> 6);
178 html_fileperm(mode >> 3);
179 html_fileperm(mode);
180}
181
182int html_include(const char *filename) 175int html_include(const char *filename)
183{ 176{
184 FILE *f; 177 FILE *f;
185 char buf[4096]; 178 char buf[4096];
186 size_t len; 179 size_t len;
187 180