diff options
Diffstat (limited to 'ui-shared.c')
-rw-r--r-- | ui-shared.c | 216 |
1 files changed, 150 insertions, 66 deletions
diff --git a/ui-shared.c b/ui-shared.c index 8827fff..e991799 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -27,7 +27,7 @@ static char *http_date(time_t t) | |||
27 | tm->tm_hour, tm->tm_min, tm->tm_sec); | 27 | tm->tm_hour, tm->tm_min, tm->tm_sec); |
28 | } | 28 | } |
29 | 29 | ||
30 | void cgit_print_error(char *msg) | 30 | void cgit_print_error(const char *msg) |
31 | { | 31 | { |
32 | html("<div class='error'>"); | 32 | html("<div class='error'>"); |
33 | html_txt(msg); | 33 | html_txt(msg); |
@@ -133,7 +133,7 @@ char *cgit_currurl() | |||
133 | return fmt("%s/", ctx.cfg.virtual_root); | 133 | return fmt("%s/", ctx.cfg.virtual_root); |
134 | } | 134 | } |
135 | 135 | ||
136 | static void site_url(char *page, char *search, int ofs) | 136 | static void site_url(const char *page, const char *search, int ofs) |
137 | { | 137 | { |
138 | char *delim = "?"; | 138 | char *delim = "?"; |
139 | 139 | ||
@@ -160,8 +160,8 @@ static void site_url(char *page, char *search, int ofs) | |||
160 | } | 160 | } |
161 | } | 161 | } |
162 | 162 | ||
163 | static void site_link(char *page, char *name, char *title, char *class, | 163 | static void site_link(const char *page, const char *name, const char *title, |
164 | char *search, int ofs) | 164 | const char *class, const char *search, int ofs) |
165 | { | 165 | { |
166 | html("<a"); | 166 | html("<a"); |
167 | if (title) { | 167 | if (title) { |
@@ -181,14 +181,14 @@ static void site_link(char *page, char *name, char *title, char *class, | |||
181 | html("</a>"); | 181 | html("</a>"); |
182 | } | 182 | } |
183 | 183 | ||
184 | void cgit_index_link(char *name, char *title, char *class, char *pattern, | 184 | void cgit_index_link(const char *name, const char *title, const char *class, |
185 | int ofs) | 185 | const char *pattern, int ofs) |
186 | { | 186 | { |
187 | site_link(NULL, name, title, class, pattern, ofs); | 187 | site_link(NULL, name, title, class, pattern, ofs); |
188 | } | 188 | } |
189 | 189 | ||
190 | static char *repolink(char *title, char *class, char *page, char *head, | 190 | static char *repolink(const char *title, const char *class, const char *page, |
191 | char *path) | 191 | const char *head, const char *path) |
192 | { | 192 | { |
193 | char *delim = "?"; | 193 | char *delim = "?"; |
194 | 194 | ||
@@ -240,8 +240,9 @@ static char *repolink(char *title, char *class, char *page, char *head, | |||
240 | return fmt("%s", delim); | 240 | return fmt("%s", delim); |
241 | } | 241 | } |
242 | 242 | ||
243 | static void reporevlink(char *page, char *name, char *title, char *class, | 243 | static void reporevlink(const char *page, const char *name, const char *title, |
244 | char *head, char *rev, char *path) | 244 | const char *class, const char *head, const char *rev, |
245 | const char *path) | ||
245 | { | 246 | { |
246 | char *delim; | 247 | char *delim; |
247 | 248 | ||
@@ -256,32 +257,33 @@ static void reporevlink(char *page, char *name, char *title, char *class, | |||
256 | html("</a>"); | 257 | html("</a>"); |
257 | } | 258 | } |
258 | 259 | ||
259 | void cgit_summary_link(char *name, char *title, char *class, char *head) | 260 | void cgit_summary_link(const char *name, const char *title, const char *class, |
261 | const char *head) | ||
260 | { | 262 | { |
261 | reporevlink(NULL, name, title, class, head, NULL, NULL); | 263 | reporevlink(NULL, name, title, class, head, NULL, NULL); |
262 | } | 264 | } |
263 | 265 | ||
264 | void cgit_tag_link(char *name, char *title, char *class, char *head, | 266 | void cgit_tag_link(const char *name, const char *title, const char *class, |
265 | char *rev) | 267 | const char *head, const char *rev) |
266 | { | 268 | { |
267 | reporevlink("tag", name, title, class, head, rev, NULL); | 269 | reporevlink("tag", name, title, class, head, rev, NULL); |
268 | } | 270 | } |
269 | 271 | ||
270 | void cgit_tree_link(char *name, char *title, char *class, char *head, | 272 | void cgit_tree_link(const char *name, const char *title, const char *class, |
271 | char *rev, char *path) | 273 | const char *head, const char *rev, const char *path) |
272 | { | 274 | { |
273 | reporevlink("tree", name, title, class, head, rev, path); | 275 | reporevlink("tree", name, title, class, head, rev, path); |
274 | } | 276 | } |
275 | 277 | ||
276 | void cgit_plain_link(char *name, char *title, char *class, char *head, | 278 | void cgit_plain_link(const char *name, const char *title, const char *class, |
277 | char *rev, char *path) | 279 | const char *head, const char *rev, const char *path) |
278 | { | 280 | { |
279 | reporevlink("plain", name, title, class, head, rev, path); | 281 | reporevlink("plain", name, title, class, head, rev, path); |
280 | } | 282 | } |
281 | 283 | ||
282 | void cgit_log_link(char *name, char *title, char *class, char *head, | 284 | void cgit_log_link(const char *name, const char *title, const char *class, |
283 | char *rev, char *path, int ofs, char *grep, char *pattern, | 285 | const char *head, const char *rev, const char *path, |
284 | int showmsg) | 286 | int ofs, const char *grep, const char *pattern, int showmsg) |
285 | { | 287 | { |
286 | char *delim; | 288 | char *delim; |
287 | 289 | ||
@@ -316,8 +318,9 @@ void cgit_log_link(char *name, char *title, char *class, char *head, | |||
316 | html("</a>"); | 318 | html("</a>"); |
317 | } | 319 | } |
318 | 320 | ||
319 | void cgit_commit_link(char *name, char *title, char *class, char *head, | 321 | void cgit_commit_link(char *name, const char *title, const char *class, |
320 | char *rev, int toggle_ssdiff) | 322 | const char *head, const char *rev, const char *path, |
323 | int toggle_ssdiff) | ||
321 | { | 324 | { |
322 | if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) { | 325 | if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) { |
323 | name[ctx.cfg.max_msg_len] = '\0'; | 326 | name[ctx.cfg.max_msg_len] = '\0'; |
@@ -328,7 +331,7 @@ void cgit_commit_link(char *name, char *title, char *class, char *head, | |||
328 | 331 | ||
329 | char *delim; | 332 | char *delim; |
330 | 333 | ||
331 | delim = repolink(title, class, "commit", head, NULL); | 334 | delim = repolink(title, class, "commit", head, path); |
332 | if (rev && strcmp(rev, ctx.qry.head)) { | 335 | if (rev && strcmp(rev, ctx.qry.head)) { |
333 | html(delim); | 336 | html(delim); |
334 | html("id="); | 337 | html("id="); |
@@ -344,21 +347,22 @@ void cgit_commit_link(char *name, char *title, char *class, char *head, | |||
344 | html("</a>"); | 347 | html("</a>"); |
345 | } | 348 | } |
346 | 349 | ||
347 | void cgit_refs_link(char *name, char *title, char *class, char *head, | 350 | void cgit_refs_link(const char *name, const char *title, const char *class, |
348 | char *rev, char *path) | 351 | const char *head, const char *rev, const char *path) |
349 | { | 352 | { |
350 | reporevlink("refs", name, title, class, head, rev, path); | 353 | reporevlink("refs", name, title, class, head, rev, path); |
351 | } | 354 | } |
352 | 355 | ||
353 | void cgit_snapshot_link(char *name, char *title, char *class, char *head, | 356 | void cgit_snapshot_link(const char *name, const char *title, const char *class, |
354 | char *rev, char *archivename) | 357 | const char *head, const char *rev, |
358 | const char *archivename) | ||
355 | { | 359 | { |
356 | reporevlink("snapshot", name, title, class, head, rev, archivename); | 360 | reporevlink("snapshot", name, title, class, head, rev, archivename); |
357 | } | 361 | } |
358 | 362 | ||
359 | void cgit_diff_link(char *name, char *title, char *class, char *head, | 363 | void cgit_diff_link(const char *name, const char *title, const char *class, |
360 | char *new_rev, char *old_rev, char *path, | 364 | const char *head, const char *new_rev, const char *old_rev, |
361 | int toggle_ssdiff) | 365 | const char *path, int toggle_ssdiff) |
362 | { | 366 | { |
363 | char *delim; | 367 | char *delim; |
364 | 368 | ||
@@ -384,18 +388,76 @@ void cgit_diff_link(char *name, char *title, char *class, char *head, | |||
384 | html("</a>"); | 388 | html("</a>"); |
385 | } | 389 | } |
386 | 390 | ||
387 | void cgit_patch_link(char *name, char *title, char *class, char *head, | 391 | void cgit_patch_link(const char *name, const char *title, const char *class, |
388 | char *rev) | 392 | const char *head, const char *rev, const char *path) |
389 | { | 393 | { |
390 | reporevlink("patch", name, title, class, head, rev, NULL); | 394 | reporevlink("patch", name, title, class, head, rev, path); |
391 | } | 395 | } |
392 | 396 | ||
393 | void cgit_stats_link(char *name, char *title, char *class, char *head, | 397 | void cgit_stats_link(const char *name, const char *title, const char *class, |
394 | char *path) | 398 | const char *head, const char *path) |
395 | { | 399 | { |
396 | reporevlink("stats", name, title, class, head, NULL, path); | 400 | reporevlink("stats", name, title, class, head, NULL, path); |
397 | } | 401 | } |
398 | 402 | ||
403 | void cgit_self_link(char *name, const char *title, const char *class, | ||
404 | struct cgit_context *ctx) | ||
405 | { | ||
406 | if (!strcmp(ctx->qry.page, "repolist")) | ||
407 | return cgit_index_link(name, title, class, ctx->qry.search, | ||
408 | ctx->qry.ofs); | ||
409 | else if (!strcmp(ctx->qry.page, "summary")) | ||
410 | return cgit_summary_link(name, title, class, ctx->qry.head); | ||
411 | else if (!strcmp(ctx->qry.page, "tag")) | ||
412 | return cgit_tag_link(name, title, class, ctx->qry.head, | ||
413 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL); | ||
414 | else if (!strcmp(ctx->qry.page, "tree")) | ||
415 | return cgit_tree_link(name, title, class, ctx->qry.head, | ||
416 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, | ||
417 | ctx->qry.path); | ||
418 | else if (!strcmp(ctx->qry.page, "plain")) | ||
419 | return cgit_plain_link(name, title, class, ctx->qry.head, | ||
420 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, | ||
421 | ctx->qry.path); | ||
422 | else if (!strcmp(ctx->qry.page, "log")) | ||
423 | return cgit_log_link(name, title, class, ctx->qry.head, | ||
424 | ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, | ||
425 | ctx->qry.path, ctx->qry.ofs, | ||
426 | ctx->qry.grep, ctx->qry.search, | ||
427 | ctx->qry.showmsg); | ||
428 | else if (!strcmp(ctx->qry.page, "commit")) | ||