Diff options
| -rw-r--r-- | source/ui-shared.c | 79 |
1 file changed, 30 insertions, 49 deletions
diff --git a/source/ui-shared.c b/source/ui-shared.c index c0c4079..afdf991 100644 --- a/source/ui-shared.c +++ b/source/ui-shared.c @@ -34,6 +34,19 @@ // into a tab title while it still leaves room to spare in that buffer. #define MAX_TITLE_PATH_LEN 256 +/* + * Write one argument of a query string after delim, and return the delimiter + * for the next one. + */ +static const char *url_arg(const char *delim, const char *name, const char *value) +{ + html(delim); + html(name); + html("="); + html_url_arg(value); + return "&"; +} + static void site_url(const char *page, const char *search, const char *sort, int ofs, int always_root) { const char *delim = "?"; @@ -50,22 +63,12 @@ static void site_url(const char *page, const char *search, const char *sort, int htmlf("?p=%s", page); delim = "&"; } - if (search) { - html(delim); - html("q="); - html_url_arg(search); - delim = "&"; - } - if (sort) { - html(delim); - html("s="); - html_url_arg(sort); - delim = "&"; - } - if (ofs) { - html(delim); - htmlf("ofs=%d", ofs); - } + if (search) + delim = url_arg(delim, "q", search); + if (sort) + delim = url_arg(delim, "s", sort); + if (ofs) + htmlf("%sofs=%d", delim, ofs); } /* @@ -146,23 +149,15 @@ static const char *repolink(const char *title, const char *class, const char *pa link_class(class); html(" href='"); write_page_url(page, path); - if (head_is_named(head)) { - html(delim); - html("h="); - html_url_arg(head); - delim = "&"; - } + if (head_is_named(head)) + delim = url_arg(delim, "h", head); return delim; } static const char *emit_rev_arg(const char *delim, const char *rev) { - if (rev && ctx.qry.head && strcmp(rev, ctx.qry.head)) { - html(delim); - html("id="); - html_url_arg(rev); - return "&"; - } + if (rev && ctx.qry.head && strcmp(rev, ctx.qry.head)) + return url_arg(delim, "id", rev); return delim; } @@ -181,14 +176,11 @@ static void reporevlink(const char *page, const char *name, const char *title, static void emit_diff_args(const char *delim) { if (ctx.qry.difftype) { - html(delim); - htmlf("dt=%d", (int)ctx.qry.difftype); + htmlf("%sdt=%d", delim, (int)ctx.qry.difftype); delim = "&"; } if (ctx.qry.context > 0 && ctx.qry.context != DEFAULT_DIFF_CONTEXT) { - html(delim); - html("context="); - htmlf("%d", ctx.qry.context); + htmlf("%scontext=%d", delim, ctx.qry.context); delim = "&"; } if (ctx.qry.ignorews) { @@ -943,18 +935,11 @@ void cgit_log_link(const char *name, const char *title, const char *class, delim = repolink(title, class, "log", head, path); delim = emit_rev_arg(delim, rev); if (grep && pattern) { - html(delim); - html("qt="); - html_url_arg(grep); - delim = "&"; - html(delim); - html("q="); - html_url_arg(pattern); + delim = url_arg(delim, "qt", grep); + delim = url_arg(delim, "q", pattern); } if (ofs > 0) { - html(delim); - html("ofs="); - htmlf("%d", ofs); + htmlf("%sofs=%d", delim, ofs); delim = "&"; } if (showmsg) { @@ -1006,12 +991,8 @@ void cgit_diff_link(const char *name, const char *title, const char *class, delim = repolink(title, class, "diff", head, path); delim = emit_rev_arg(delim, new_rev); - if (old_rev) { - html(delim); - html("id2="); - html_url_arg(old_rev); - delim = "&"; - } + if (old_rev) + delim = url_arg(delim, "id2", old_rev); emit_diff_args(delim); html("'>"); html_txt(name); |
