]>
git.cameronkatri.com Git - cgit.git/blob - html.c
1 /* html.c: helper functions for html output
3 * Copyright (C) 2006 Lars Hjemli
5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text)
11 char *fmt(const char *format
, ...)
13 static char buf
[8][1024];
21 va_start(args
, format
);
22 len
= vsnprintf(buf
[bufidx
], sizeof(buf
[bufidx
]), format
, args
);
24 if (len
>sizeof(buf
[bufidx
]))
25 die("[html.c] string truncated: %s", format
);
29 void html(const char *txt
)
31 write(htmlfd
, txt
, strlen(txt
));
34 void htmlf(const char *format
, ...)
36 static char buf
[65536];
39 va_start(args
, format
);
40 vsnprintf(buf
, sizeof(buf
), format
, args
);
45 void html_txt(char *txt
)
50 if (c
=='<' || c
=='>' || c
=='&') {
51 write(htmlfd
, txt
, t
- txt
);
66 void html_ntxt(int len
, char *txt
)
69 while(t
&& *t
&& len
--){
71 if (c
=='<' || c
=='>' || c
=='&') {
72 write(htmlfd
, txt
, t
- txt
);
84 write(htmlfd
, txt
, t
- txt
);
89 void html_attr(char *txt
)
94 if (c
=='<' || c
=='>' || c
=='\'') {
95 write(htmlfd
, txt
, t
- txt
);
110 void html_hidden(char *name
, char *value
)
112 html("<input type='hidden' name='");
119 void html_option(char *value
, char *text
, char *selected_value
)
121 html("<option value='");
124 if (selected_value
&& !strcmp(selected_value
, value
))
125 html(" selected='selected'");
131 void html_link_open(char *url
, char *title
, char *class)
146 void html_link_close(void)
151 void html_fileperm(unsigned short mode
)
153 htmlf("%c%c%c", (mode
& 4 ? 'r' : '-'),
154 (mode
& 2 ? 'w' : '-'), (mode
& 1 ? 'x' : '-'));
157 void html_filemode(unsigned short mode
)
161 else if (S_ISLNK(mode
))
163 else if (S_ISGITLINK(mode
))
167 html_fileperm(mode
>> 6);
168 html_fileperm(mode
>> 3);
172 int html_include(const char *filename
)
178 if (!(f
= fopen(filename
, "r")))
180 while((len
= fread(buf
, 1, 4096, f
)) > 0)
181 write(htmlfd
, buf
, len
);