summaryrefslogtreecommitdiffabout
path: root/ui-shared.c
authorJohan Herland <johan@herland.net>2010-06-09 23:09:24 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2010-06-19 08:40:21 (UTC)
commitc3f23d4571c06c979eddbd4c973163ba76c7e50f (patch) (side-by-side diff)
treeef73940ab3ac1ccc3d3a8dcb0ba0279c6a2a6fa0 /ui-shared.c
parent026980c270354c59b8a192f5e6db7efe9c66dd62 (diff)
downloadcgit-c3f23d4571c06c979eddbd4c973163ba76c7e50f.zip
cgit-c3f23d4571c06c979eddbd4c973163ba76c7e50f.tar.gz
cgit-c3f23d4571c06c979eddbd4c973163ba76c7e50f.tar.bz2
ui-shared: Improve const-ness in API
This is needed to prevent const-related warnings in later patches. Signed-off-by: Johan Herland <johan@herland.net> 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.c76
1 files changed, 40 insertions, 36 deletions
diff --git a/ui-shared.c b/ui-shared.c
index 8827fff..7d7fff0 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -18,25 +18,25 @@ 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", "Nov", "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);
}
-void cgit_print_error(char *msg)
+void cgit_print_error(const char *msg)
{
html("<div class='error'>");
html_txt(msg);
html("</div>\n");
}
char *cgit_httpscheme()
{
if (ctx.env.https && !strcmp(ctx.env.https, "on"))
return "https://";
else
return "http://";
@@ -124,25 +124,25 @@ const char *cgit_repobasename(const char *reponame)
char *cgit_currurl()
{
if (!ctx.cfg.virtual_root)
return ctx.cfg.script_name;
else if (ctx.qry.page)
return fmt("%s/%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo, ctx.qry.page);
else if (ctx.qry.repo)
return fmt("%s/%s/", ctx.cfg.virtual_root, ctx.qry.repo);
else
return fmt("%s/", ctx.cfg.virtual_root);
}
-static void site_url(char *page, char *search, int ofs)
+static void site_url(const char *page, const char *search, int ofs)
{
char *delim = "?";
if (ctx.cfg.virtual_root) {
html_attr(ctx.cfg.virtual_root);
if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/')
html("/");
} else
html(ctx.cfg.script_name);
if (page) {
htmlf("?p=%s", page);
@@ -151,53 +151,53 @@ static void site_url(char *page, char *search, int ofs)
if (search) {
html(delim);
html("q=");
html_attr(search);
delim = "&";
}
if (ofs) {
html(delim);
htmlf("ofs=%d", ofs);
}
}
-static void site_link(char *page, char *name, char *title, char *class,
- char *search, int ofs)
+static void site_link(const char *page, const char *name, const char *title,
+ const char *class, const char *search, int ofs)
{
html("<a");
if (title) {
html(" title='");
html_attr(title);
html("'");
}
if (class) {
html(" class='");
html_attr(class);
html("'");
}
html(" href='");
site_url(page, search, ofs);
html("'>");
html_txt(name);
html("</a>");
}
-void cgit_index_link(char *name, char *title, char *class, char *pattern,
- int ofs)
+void cgit_index_link(const char *name, const char *title, const char *class,
+ const char *pattern, int ofs)
{
site_link(NULL, name, title, class, pattern, ofs);
}
-static char *repolink(char *title, char *class, char *page, char *head,
- char *path)
+static char *repolink(const char *title, const char *class, const char *page,
+ const char *head, const char *path)
{
char *delim = "?";
html("<a");
if (title) {
html(" title='");
html_attr(title);
html("'");
}
if (class) {
html(" class='");
html_attr(class);
@@ -231,66 +231,68 @@ static char *repolink(char *title, char *class, char *page, char *head,
}
delim = "&amp;";
}
if (head && strcmp(head, ctx.repo->defbranch)) {
html(delim);
html("h=");
html_url_arg(head);
delim = "&amp;";
}
return fmt("%s", delim);
}
-static void reporevlink(char *page, char *name, char *title, char *class,
- char *head, char *rev, char *path)
+static void reporevlink(const char *page, const char *name, const char *title,
+ const char *class, const char *head, const char *rev,
+ const char *path)
{
char *delim;
delim = repolink(title, class, page, head, path);
if (rev && ctx.qry.head != NULL && strcmp(rev, ctx.qry.head)) {
html(delim);
html("id=");
html_url_arg(rev);
}
html("'>");
html_txt(name);
html("</a>");
}
-void cgit_summary_link(char *name, char *title, char *class, char *head)
+void cgit_summary_link(const char *name, const char *title, const char *class,
+ const char *head)
{
reporevlink(NULL, name, title, class, head, NULL, NULL);
}
-void cgit_tag_link(char *name, char *title, char *class, char *head,
- char *rev)
+void cgit_tag_link(const char *name, const char *title, const char *class,
+ const char *head, const char *rev)
{
reporevlink("tag", name, title, class, head, rev, NULL);
}
-void cgit_tree_link(char *name, char *title, char *class, char *head,
- char *rev, char *path)
+void cgit_tree_link(const char *name, const char *title, const char *class,
+ const char *head, const char *rev, const char *path)
{
reporevlink("tree", name, title, class, head, rev, path);
}
-void cgit_plain_link(char *name, char *title, char *class, char *head,
- char *rev, char *path)
+void cgit_plain_link(const char *name, const char *title, const char *class,
+ const char *head, const char *rev, const char *path)
{
reporevlink("plain", name, title, class, head, rev, path);
}
-void cgit_log_link(char *name, char *title, char *class, char *head,
- char *rev, char *path, int ofs, char *grep, char *pattern,
- int showmsg)
+void cgit_log_link(const char *name, const char *title, const char *class,
+ const char *head, const char *rev, const char *path,
+ int ofs, const char *grep, const char *pattern, int showmsg)
{
char *delim;
delim = repolink(title, class, "log", head, path);
if (rev && strcmp(rev, ctx.qry.head)) {
html(delim);
html("id=");
html_url_arg(rev);
delim = "&";
}
if (grep && pattern) {
html(delim);
@@ -307,26 +309,26 @@ void cgit_log_link(char *name, char *title, char *class, char *head,
htmlf("%d", ofs);
delim = "&";
}
if (showmsg) {
html(delim);
html("showmsg=1");
}
html("'>");
html_txt(name);
html("</a>");
}
-void cgit_commit_link(char *name, char *title, char *class, char *head,
- char *rev, int toggle_ssdiff)
+void cgit_commit_link(char *name, const char *title, const char *class,
+ const char *head, const char *rev, int toggle_ssdiff)
{
if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) {
name[ctx.cfg.max_msg_len] = '\0';
name[ctx.cfg.max_msg_len - 1] = '.';
name[ctx.cfg.max_msg_len - 2] = '.';
name[ctx.cfg.max_msg_len - 3] = '.';
}
char *delim;
delim = repolink(title, class, "commit", head, NULL);
if (rev && strcmp(rev, ctx.qry.head)) {
@@ -335,39 +337,40 @@ void cgit_commit_link(char *name, char *title, char *class, char *head,
html_url_arg(rev);
delim = "&amp;";
}
if ((ctx.qry.ssdiff && !toggle_ssdiff) || (!ctx.qry.ssdiff && toggle_ssdiff)) {
html(delim);
html("ss=1");
}
html("'>");
html_txt(name);
html("</a>");
}
-void cgit_refs_link(char *name, char *title, char *class, char *head,
- char *rev, char *path)
+void cgit_refs_link(const char *name, const char *title, const char *class,
+ const char *head, const char *rev, const char *path)
{
reporevlink("refs", name, title, class, head, rev, path);
}
-void cgit_snapshot_link(char *name, char *title, char *class, char *head,
- char *rev, char *archivename)
+void cgit_snapshot_link(const char *name, const char *title, const char *class,
+ const char *head, const char *rev,
+ const char *archivename)
{
reporevlink("snapshot", name, title, class, head, rev, archivename);
}
-void cgit_diff_link(char *name, char *title, char *class, char *head,
- char *new_rev, char *old_rev, char *path,
- int toggle_ssdiff)
+void cgit_diff_link(const char *name, const char *title, const char *class,
+ const char *head, const char *new_rev, const char *old_rev,
+ const char *path, int toggle_ssdiff)
{
char *delim;
delim = repolink(title, class, "diff", head, path);
if (new_rev && ctx.qry.head != NULL && strcmp(new_rev, ctx.qry.head)) {
html(delim);
html("id=");
html_url_arg(new_rev);
delim = "&amp;";
}
if (old_rev) {
html(delim);
@@ -375,32 +378,32 @@ void cgit_diff_link(char *name, char *title, char *class, char *head,
html_url_arg(old_rev);
delim = "&amp;";
}
if ((ctx.qry.ssdiff && !toggle_ssdiff) || (!ctx.qry.ssdiff && toggle_ssdiff)) {
html(delim);
html("ss=1");
}
html("'>");
html_txt(name);
html("</a>");
}
-void cgit_patch_link(char *name, char *title, char *class, char *head,
- char *rev)
+void cgit_patch_link(const char *name, const char *title, const char *class,
+ const char *head, const char *rev)
{
reporevlink("patch", name, title, class, head, rev, NULL);
}
-void cgit_stats_link(char *name, char *title, char *class, char *head,
- char *path)
+void cgit_stats_link(const char *name, const char *title, const char *class,
+ const char *head, const char *path)
{
reporevlink("stats", name, title, class, head, NULL, path);
}
void cgit_object_link(struct object *obj)
{
char *page, *shortrev, *fullrev, *name;
fullrev = sha1_to_hex(obj->sha1);
shortrev = xstrdup(fullrev);
shortrev[10] = '\0';
if (obj->type == OBJ_COMMIT) {
@@ -408,40 +411,40 @@ void cgit_object_link(struct object *obj)
ctx.qry.head, fullrev, 0);
return;
} else if (obj->type == OBJ_TREE)
page = "tree";
else if (obj->type == OBJ_TAG)
page = "tag";
else
page = "blob";
name = fmt("%s %s...", typename(obj->type), shortrev);
reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL);
}
-void cgit_print_date(time_t secs, char *format, int local_time)
+void cgit_print_date(time_t secs, const char *format, int local_time)
{
char buf[64];
struct tm *time;
if (!secs)
return;
if(local_time)
time = localtime(&secs);
else
time = gmtime(&secs);
strftime(buf, sizeof(buf)-1, format, time);
html_txt(buf);
}
-void cgit_print_age(time_t t, time_t max_relative, char *format)
+void cgit_print_age(time_t t, time_t max_relative, const char *format)
{
time_t now, secs;
if (!t)
return;
time(&now);
secs = now - t;
if (secs > max_relative && max_relative >= 0) {
cgit_print_date(t, format, ctx.cfg.local_time);
return;
}
@@ -602,25 +605,26 @@ int print_archive_ref(const char *refname, const unsigned char *sha1,
html("<h1>download</h1>\n");
*header = 1;
}
url = cgit_pageurl(ctx.qry.repo, "blob",
fmt("id=%s&amp;path=%s", sha1_to_hex(fileid),
buf));
html_link_open(url, NULL, "menu");
html_txt(strlpart(buf, 20));
html_link_close();
return 0;
}
-void cgit_add_hidden_formfields(int incl_head, int incl_search, char *page)
+void cgit_add_hidden_formfields(int incl_head, int incl_search,
+ const char *page)
{
char *url;
if (!ctx.cfg.virtual_root) {
url = fmt("%s/%s", ctx.qry.repo, page);
if (ctx.qry.path)
url = fmt("%s/%s", url, ctx.qry.path);
html_hidden("url", url);
}
if (incl_head && ctx.qry.head && ctx.repo->defbranch &&
strcmp(ctx.qry.head, ctx.repo->defbranch))