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 | |
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-- | cgit.h | 1 | ||||
-rw-r--r-- | html.c | 14 |
2 files changed, 15 insertions, 0 deletions
@@ -135,24 +135,25 @@ extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); | |||
135 | 135 | ||
136 | extern char *fmt(const char *format,...); | 136 | extern char *fmt(const char *format,...); |
137 | 137 | ||
138 | extern void html(const char *txt); | 138 | extern void html(const char *txt); |
139 | extern void htmlf(const char *format,...); | 139 | extern void htmlf(const char *format,...); |
140 | extern void html_txt(char *txt); | 140 | extern void html_txt(char *txt); |
141 | extern void html_ntxt(int len, char *txt); | 141 | extern void html_ntxt(int len, char *txt); |
142 | extern void html_attr(char *txt); | 142 | extern void html_attr(char *txt); |
143 | extern void html_hidden(char *name, char *value); | 143 | extern void html_hidden(char *name, char *value); |
144 | extern void html_link_open(char *url, char *title, char *class); | 144 | extern void html_link_open(char *url, char *title, char *class); |
145 | extern void html_link_close(void); | 145 | extern void html_link_close(void); |
146 | extern void html_filemode(unsigned short mode); | 146 | extern void html_filemode(unsigned short mode); |
147 | extern int html_include(const char *filename); | ||
147 | 148 | ||
148 | extern int cgit_read_config(const char *filename, configfn fn); | 149 | extern int cgit_read_config(const char *filename, configfn fn); |
149 | extern int cgit_parse_query(char *txt, configfn fn); | 150 | extern int cgit_parse_query(char *txt, configfn fn); |
150 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); | 151 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); |
151 | extern struct taginfo *cgit_parse_tag(struct tag *tag); | 152 | extern struct taginfo *cgit_parse_tag(struct tag *tag); |
152 | 153 | ||
153 | extern char *cache_safe_filename(const char *unsafe); | 154 | extern char *cache_safe_filename(const char *unsafe); |
154 | extern int cache_lock(struct cacheitem *item); | 155 | extern int cache_lock(struct cacheitem *item); |
155 | extern int cache_unlock(struct cacheitem *item); | 156 | extern int cache_unlock(struct cacheitem *item); |
156 | extern int cache_cancel_lock(struct cacheitem *item); | 157 | extern int cache_cancel_lock(struct cacheitem *item); |
157 | extern int cache_exist(struct cacheitem *item); | 158 | extern int cache_exist(struct cacheitem *item); |
158 | extern int cache_expired(struct cacheitem *item); | 159 | extern int cache_expired(struct cacheitem *item); |
@@ -157,12 +157,26 @@ void html_filemode(unsigned short mode) | |||
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 | } | ||