author | Lars Hjemli <hjemli@gmail.com> | 2007-05-20 12:33:59 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-05-20 12:33:59 (UTC) |
commit | 977a0b173df6fe1a4d362fe4c70f9badff1fd46c (patch) (side-by-side diff) | |
tree | 8bd383fff396bb1790c03ab5b461d899af997568 /html.c | |
parent | d4dbfdfbaea3aa93e824ea484787de10e73eae65 (diff) | |
parent | de69ce020c4ccd7146d6ac72bbd8f417088e8c03 (diff) | |
download | cgit-977a0b173df6fe1a4d362fe4c70f9badff1fd46c.zip cgit-977a0b173df6fe1a4d362fe4c70f9badff1fd46c.tar.gz cgit-977a0b173df6fe1a4d362fe4c70f9badff1fd46c.tar.bz2 |
Merge branch 'index-header'
* index-header:
Teach cgit howto include an external file on index page.
Add html_include()
-rw-r--r-- | html.c | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -73,96 +73,110 @@ void html_ntxt(int len, char *txt) if (c=='<' || c=='>' || c=='&') { *t = '\0'; html(txt); *t = c; if (c=='>') html(">"); else if (c=='<') html("<"); else if (c=='&') html("&"); txt = t+1; } t++; } if (t!=txt) { char c = *t; *t = '\0'; html(txt); *t = c; } if (len<0) html("..."); } void html_attr(char *txt) { char *t = txt; while(t && *t){ int c = *t; if (c=='<' || c=='>' || c=='\'') { *t = '\0'; html(txt); *t = c; if (c=='>') html(">"); else if (c=='<') html("<"); else if (c=='\'') html(""e;"); txt = t+1; } t++; } if (t!=txt) html(txt); } void html_hidden(char *name, char *value) { html("<input type='hidden' name='"); html_attr(name); html("' value='"); html_attr(value); html("'/>"); } void html_link_open(char *url, char *title, char *class) { html("<a href='"); html_attr(url); if (title) { html("' title='"); html_attr(title); } if (class) { html("' class='"); html_attr(class); } html("'>"); } void html_link_close(void) { html("</a>"); } void html_fileperm(unsigned short mode) { htmlf("%c%c%c", (mode & 4 ? 'r' : '-'), (mode & 2 ? 'w' : '-'), (mode & 1 ? 'x' : '-')); } void html_filemode(unsigned short mode) { if (S_ISDIR(mode)) html("d"); else if (S_ISLNK(mode)) html("l"); else if (S_ISDIRLNK(mode)) html("m"); else html("-"); html_fileperm(mode >> 6); html_fileperm(mode >> 3); html_fileperm(mode); } + +int html_include(const char *filename) +{ + FILE *f; + char buf[4096]; + size_t len; + + if (!(f = fopen(filename, "r"))) + return -1; + while((len = fread(buf, 1, 4096, f)) > 0) + write(htmlfd, buf, len); + fclose(f); + return 0; +} |