about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJeff Smith2017-10-01 23:39:05 -0500
committerJohn Keeping2017-10-03 19:19:34 +0100
commit70787254b270b1505aa8427813f64131be5df86c (patch)
tree5a6d23b8186d4d9d7e2bd5b84d3c3d092edd4e30
parentcache: flush stdio before restoring FDs (diff)
downloadcgit-70787254b270b1505aa8427813f64131be5df86c.tar.gz
cgit-70787254b270b1505aa8427813f64131be5df86c.zip
html: html_ntxt with no ellipsis
For implementing a ui-blame page, there is need for a function that
outputs a selection from a block of text, transformed for HTML output,
but with no further modifications or additions.

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Reviewed-by: John Keeping <john@keeping.me.uk>
-rw-r--r--html.c32
-rw-r--r--html.h2
-rw-r--r--ui-repolist.c3
3 files changed, 14 insertions, 23 deletions
diff --git a/html.c b/html.c index e7e6e07..7f81965 100644 --- a/html.c +++ b/html.c
@@ -124,29 +124,20 @@ void html_vtxtf(const char *format, va_list ap)
124 124
125void html_txt(const char *txt) 125void html_txt(const char *txt)
126{ 126{
127 const char *t = txt; 127 if (txt)
128 while (t && *t) { 128 html_ntxt(txt, strlen(txt));
129 int c = *t;
130 if (c == '<' || c == '>' || c == '&') {
131 html_raw(txt, t - txt);
132 if (c == '>')
133 html("&gt;");
134 else if (c == '<')
135 html("&lt;");
136 else if (c == '&')
137 html("&amp;");
138 txt = t + 1;
139 }
140 t++;
141 }
142 if (t != txt)
143 html(txt);
144} 129}
145 130
146void html_ntxt(int len, const char *txt) 131ssize_t html_ntxt(const char *txt, size_t len)
147{ 132{
148 const char *t = txt; 133 const char *t = txt;
149 while (t && *t && len--) { 134 ssize_t slen;
135
136 if (len > SSIZE_MAX)
137 return -1;
138
139 slen = (ssize_t) len;
140 while (t && *t && slen--) {
150 int c = *t; 141 int c = *t;
151 if (c == '<' || c == '>' || c == '&') { 142 if (c == '<' || c == '>' || c == '&') {
152 html_raw(txt, t - txt); 143 html_raw(txt, t - txt);
@@ -162,8 +153,7 @@ void html_ntxt(int len, const char *txt)
162 } 153 }
163 if (t != txt) 154 if (t != txt)
164 html_raw(txt, t - txt); 155 html_raw(txt, t - txt);
165 if (len < 0) 156 return slen;
166 html("...");
167} 157}
168 158
169void html_attrf(const char *fmt, ...) 159void html_attrf(const char *fmt, ...)
diff --git a/html.h b/html.h index 1b24e55..fa4de77 100644 --- a/html.h +++ b/html.h
@@ -19,7 +19,7 @@ __attribute__((format (printf,1,2)))
19extern void html_attrf(const char *format,...); 19extern void html_attrf(const char *format,...);
20 20
21extern void html_txt(const char *txt); 21extern void html_txt(const char *txt);
22extern void html_ntxt(int len, const char *txt); 22extern ssize_t html_ntxt(const char *txt, size_t len);
23extern void html_attr(const char *txt); 23extern void html_attr(const char *txt);
24extern void html_url_path(const char *txt); 24extern void html_url_path(const char *txt);
25extern void html_url_arg(const char *txt); 25extern void html_url_arg(const char *txt);
diff --git a/ui-repolist.c b/ui-repolist.c index 7272e87..af52f9b 100644 --- a/ui-repolist.c +++ b/ui-repolist.c
@@ -329,7 +329,8 @@ void cgit_print_repolist(void)
329 repourl = cgit_repourl(ctx.repo->url); 329 repourl = cgit_repourl(ctx.repo->url);
330 html_link_open(repourl, NULL, NULL); 330 html_link_open(repourl, NULL, NULL);
331 free(repourl); 331 free(repourl);
332 html_ntxt(ctx.cfg.max_repodesc_len, ctx.repo->desc); 332 if (html_ntxt(ctx.repo->desc, ctx.cfg.max_repodesc_len) < 0)
333 html("...");
333 html_link_close(); 334 html_link_close();
334 html("</td><td>"); 335 html("</td><td>");
335 if (ctx.cfg.enable_index_owner) { 336 if (ctx.cfg.enable_index_owner) {