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) (ignore 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,105 +1,106 @@
/* 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);
}
}
char *cgit_fileurl(const char *reponame, const char *pagename,
const char *filename, const char *query)
{
char *tmp;
char *delim;
if (ctx.cfg.virtual_root) {
tmp = fmt("%s/%s/%s/%s", ctx.cfg.virtual_root, reponame,
pagename, (filename ? filename:""));
delim = "?";
} else {
tmp = fmt("?url=%s/%s/%s", reponame, pagename,
(filename ? filename : ""));
delim = "&";
}
if (query)
tmp = fmt("%s%s%s", tmp, delim, query);
return tmp;
}
char *cgit_pageurl(const char *reponame, const char *pagename,
const char *query)
{
return cgit_fileurl(reponame,pagename,0,query);
}
const char *cgit_repobasename(const char *reponame)
{
/* I assume we don't need to store more than one repo basename */
static char rvbuf[1024];
int p;
const char *rv;
strncpy(rvbuf,reponame,sizeof(rvbuf));
if(rvbuf[sizeof(rvbuf)-1])
die("cgit_repobasename: truncated repository name '%s'", reponame);
p = strlen(rvbuf)-1;
/* strip trailing slashes */
while(p && rvbuf[p]=='/') rvbuf[p--]=0;
/* strip trailing .git */
if(p>=3 && !strncmp(&rvbuf[p-3],".git",4)) {
p -= 3; rvbuf[p--] = 0;
}
/* strip more trailing slashes if any */
while( p && rvbuf[p]=='/') rvbuf[p--]=0;
/* find last slash in the remaining string */
rv = strrchr(rvbuf,'/');
@@ -474,97 +475,112 @@ void cgit_print_pageheader(char *title, int show_search)
html("<tr><td class='sidebar'>\n<a href='");
html_attr(cgit_rooturl());
htmlf("'><img src='%s' alt='cgit'/></a>\n",
ctx.cfg.logo);
html("</td></tr>\n<tr><td class='sidebar'>\n");
if (ctx.repo) {
html("<h1 class='first'>");
html_txt(strrpart(ctx.repo->name, 20));
html("</h1>\n");
html_txt(ctx.repo->desc);
if (ctx.repo->owner) {
html("<h1>owner</h1>\n");
html_txt(ctx.repo->owner);
}
html("<h1>navigate</h1>\n");
reporevlink(NULL, "summary", NULL, "menu", ctx.qry.head,
NULL, NULL);
cgit_log_link("log", NULL, "menu", ctx.qry.head, NULL, NULL,
0, NULL, NULL);
cgit_tree_link("tree", NULL, "menu", ctx.qry.head,
ctx.qry.sha1, NULL);
cgit_commit_link("commit", NULL, "menu", ctx.qry.head,
ctx.qry.sha1);
cgit_diff_link("diff", NULL, "menu", ctx.qry.head,
ctx.qry.sha1, ctx.qry.sha2, NULL);
cgit_patch_link("patch", NULL, "menu", ctx.qry.head,
ctx.qry.sha1);
for_each_ref(print_archive_ref, &header);
if (ctx.repo->clone_url || ctx.cfg.clone_prefix) {
html("<h1>clone</h1>\n");
if (ctx.repo->clone_url)
url = ctx.repo->clone_url;
else
url = fmt("%s%s", ctx.cfg.clone_prefix,
ctx.repo->url);
html("<a class='menu' href='");
html_attr(url);
html("' title='");
html_attr(url);
html("'>\n");
html_txt(strrpart(url, 20));
html("</a>\n");
}
html("<h1>branch</h1>\n");
html("<form method='get' action=''>\n");
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: */