diff options
author | Jeff Smith | 2017-10-01 23:39:06 -0500 |
---|---|---|
committer | John Keeping | 2017-10-03 19:19:34 +0100 |
commit | 9337c7ee83221d48d02c3c7b5c9dcbaca23ad92f (patch) | |
tree | d78c2311f4cffe8870e3966d09b5045c6166c4a7 /ui-shared.c | |
parent | 70787254b270b1505aa8427813f64131be5df86c (diff) | |
download | cgit-9337c7ee83221d48d02c3c7b5c9dcbaca23ad92f.tar.gz cgit-9337c7ee83221d48d02c3c7b5c9dcbaca23ad92f.tar.bz2 cgit-9337c7ee83221d48d02c3c7b5c9dcbaca23ad92f.zip |
ui-tree: move set_title_from_path to ui-shared
The ui-blame code will also need to call set_title_from_path, so go
ahead and move it to ui-shared.
Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Reviewed-by: John Keeping <john@keeping.me.uk>
Diffstat (limited to 'ui-shared.c')
-rw-r--r-- | ui-shared.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/ui-shared.c b/ui-shared.c index e5c9a02..2547e43 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -1111,3 +1111,34 @@ void cgit_print_snapshot_links(const char *repo, const char *head, | |||
1111 | } | 1111 | } |
1112 | strbuf_release(&filename); | 1112 | strbuf_release(&filename); |
1113 | } | 1113 | } |
1114 | |||
1115 | void cgit_set_title_from_path(const char *path) | ||
1116 | { | ||
1117 | size_t path_len, path_index, path_last_end; | ||
1118 | char *new_title; | ||
1119 | |||
1120 | if (!path) | ||
1121 | return; | ||
1122 | |||
1123 | path_len = strlen(path); | ||
1124 | new_title = xmalloc(path_len + 3 + strlen(ctx.page.title) + 1); | ||
1125 | new_title[0] = '\0'; | ||
1126 | |||
1127 | for (path_index = path_len, path_last_end = path_len; path_index-- > 0;) { | ||
1128 | if (path[path_index] == '/') { | ||
1129 | if (path_index == path_len - 1) { | ||
1130 | path_last_end = path_index - 1; | ||
1131 | continue; | ||
1132 | } | ||
1133 | strncat(new_title, &path[path_index + 1], path_last_end - path_index - 1); | ||
1134 | strcat(new_title, "\\"); | ||
1135 | path_last_end = path_index; | ||
1136 | } | ||
1137 | } | ||
1138 | if (path_last_end) | ||
1139 | strncat(new_title, path, path_last_end); | ||
1140 | |||
1141 | strcat(new_title, " - "); | ||
1142 | strcat(new_title, ctx.page.title); | ||
1143 | ctx.page.title = new_title; | ||
1144 | } | ||