author | Lars Hjemli <hjemli@gmail.com> | 2007-05-18 21:56:10 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-05-18 21:56:10 (UTC) |
commit | 5e75128a8bee885d83563d8c521172328d511d12 (patch) (unidiff) | |
tree | 39e32199b06b6e68782040d5c2a46162fb0cf771 /html.c | |
parent | 08cc2e5f0e24773dad81d38bd6b689e36afe9dda (diff) | |
download | cgit-5e75128a8bee885d83563d8c521172328d511d12.zip cgit-5e75128a8bee885d83563d8c521172328d511d12.tar.gz cgit-5e75128a8bee885d83563d8c521172328d511d12.tar.bz2 |
Add html_include()
This is a function used to include external htmlfiles in cgit-
generated pages.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | html.c | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -145,24 +145,38 @@ void html_link_close(void) | |||
145 | { | 145 | { |
146 | html("</a>"); | 146 | html("</a>"); |
147 | } | 147 | } |
148 | 148 | ||
149 | void html_fileperm(unsigned short mode) | 149 | void html_fileperm(unsigned short mode) |
150 | { | 150 | { |
151 | htmlf("%c%c%c", (mode & 4 ? 'r' : '-'), | 151 | htmlf("%c%c%c", (mode & 4 ? 'r' : '-'), |
152 | (mode & 2 ? 'w' : '-'), (mode & 1 ? 'x' : '-')); | 152 | (mode & 2 ? 'w' : '-'), (mode & 1 ? 'x' : '-')); |
153 | } | 153 | } |
154 | 154 | ||
155 | void html_filemode(unsigned short mode) | 155 | void html_filemode(unsigned short mode) |
156 | { | 156 | { |
157 | if (S_ISDIR(mode)) | 157 | if (S_ISDIR(mode)) |
158 | html("d"); | 158 | html("d"); |
159 | else if (S_ISLNK(mode)) | 159 | else if (S_ISLNK(mode)) |
160 | html("l"); | 160 | html("l"); |
161 | else if (S_ISDIRLNK(mode)) | 161 | else if (S_ISDIRLNK(mode)) |
162 | html("m"); | 162 | html("m"); |
163 | else | 163 | else |
164 | html("-"); | 164 | html("-"); |
165 | html_fileperm(mode >> 6); | 165 | html_fileperm(mode >> 6); |
166 | html_fileperm(mode >> 3); | 166 | html_fileperm(mode >> 3); |
167 | html_fileperm(mode); | 167 | html_fileperm(mode); |
168 | } | 168 | } |
169 | |||
170 | int html_include(const char *filename) | ||
171 | { | ||
172 | FILE *f; | ||
173 | char buf[4096]; | ||
174 | size_t len; | ||
175 | |||
176 | if (!(f = fopen(filename, "r"))) | ||
177 | return -1; | ||
178 | while((len = fread(buf, 1, 4096, f)) > 0) | ||
179 | write(htmlfd, buf, len); | ||
180 | fclose(f); | ||
181 | return 0; | ||
182 | } | ||