summaryrefslogtreecommitdiffabout
path: root/ui-shared.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) (side-by-side diff)
tree05796a741faef90c12aadd3a5c92b702ec870c48 /ui-shared.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 'ui-shared.c') (more/less context) (show whitespace changes)
-rw-r--r--ui-shared.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/ui-shared.c b/ui-shared.c
index cc1ab8b..2eff79d 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -1,57 +1,58 @@
/* ui-shared.c: common web output functions
*
* Copyright (C) 2006 Lars Hjemli
*
* Licensed under GNU General Public License v2
* (see COPYING for full license text)
*/
#include "cgit.h"
+#include "html.h"
const char cgit_doctype[] =
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n"
" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
static char *http_date(time_t t)
{
static char day[][4] =
{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
static char month[][4] =
{"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Now", "Dec"};
struct tm *tm = gmtime(&t);
return fmt("%s, %02d %s %04d %02d:%02d:%02d GMT", day[tm->tm_wday],
tm->tm_mday, month[tm->tm_mon], 1900+tm->tm_year,
tm->tm_hour, tm->tm_min, tm->tm_sec);
}
static long ttl_seconds(long ttl)
{
if (ttl<0)
return 60 * 60 * 24 * 365;
else
return ttl * 60;
}
void cgit_print_error(char *msg)
{
html("<div class='error'>");
html_txt(msg);
html("</div>\n");
}
char *cgit_rooturl()
{
if (ctx.cfg.virtual_root)
return fmt("%s/", ctx.cfg.virtual_root);
else
return ctx.cfg.script_name;
}
char *cgit_repourl(const char *reponame)
{
if (ctx.cfg.virtual_root) {
return fmt("%s/%s/", ctx.cfg.virtual_root, reponame);
} else {
return fmt("?r=%s", reponame);
}
@@ -522,49 +523,64 @@ void cgit_print_pageheader(char *title, int show_search)
add_hidden_formfields(0, 1, ctx.qry.page);
// html("<table summary='branch selector' class='grid'><tr><td id='branch-dropdown-cell'>");
html("<select name='h' onchange='this.form.submit();'>\n");
for_each_branch_ref(print_branch_option, ctx.qry.head);
html("</select>\n");
// html("</td><td>");
html("<noscript><input type='submit' id='switch-btn' value='switch'/></noscript>\n");
// html("</td></tr></table>");
html("</form>\n");
html("<h1>search</h1>\n");
html("<form method='get' action='");
if (ctx.cfg.virtual_root)
html_attr(cgit_fileurl(ctx.qry.repo, "log",
ctx.qry.path, NULL));
html("'>\n");
add_hidden_formfields(1, 0, "log");
html("<select name='qt'>\n");
html_option("grep", "log msg", ctx.qry.grep);
html_option("author", "author", ctx.qry.grep);
html_option("committer", "committer", ctx.qry.grep);
html("</select>\n");
html("<input class='txt' type='text' name='q' value='");
html_attr(ctx.qry.search);
html("'/>\n");
html("</form>\n");
} else {
if (!ctx.cfg.index_info || html_include(ctx.cfg.index_info))
html(default_info);
}
html("</td></tr></table></td>\n");
html("<td id='content'>\n");
}
void cgit_print_snapshot_start(const char *mimetype, const char *filename,
struct cacheitem *item)
{
htmlf("Content-Type: %s\n", mimetype);
htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename);
htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime));
htmlf("Expires: %s\n", http_date(item->st.st_mtime +
ttl_seconds(item->ttl)));
html("\n");
}
+void cgit_print_filemode(unsigned short mode)
+{
+ if (S_ISDIR(mode))
+ html("d");
+ else if (S_ISLNK(mode))
+ html("l");
+ else if (S_ISGITLINK(mode))
+ html("m");
+ else
+ html("-");
+ html_fileperm(mode >> 6);
+ html_fileperm(mode >> 3);
+ html_fileperm(mode);
+}
+
/* vim:set sw=8: */