From mboxrd@z Thu Jan 1 00:00:00 1970 From: whydoubt at gmail.com (Jeff Smith) Date: Fri, 22 Sep 2017 22:38:45 -0500 Subject: [RFCv2 PATCH 4/7] ui-blame: html_ntxt with no ellipsis In-Reply-To: <20170923033848.5922-1-whydoubt@gmail.com> References: <20170608021810.12964-1-whydoubt@gmail.com> <20170923033848.5922-1-whydoubt@gmail.com> Message-ID: <20170923033848.5922-5-whydoubt@gmail.com> 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 --- html.c | 37 ++++++++++++++++--------------------- html.h | 1 + ui-repolist.c | 2 +- 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/html.c b/html.c index e7e6e07..345300e 100644 --- a/html.c +++ b/html.c @@ -122,10 +122,10 @@ void html_vtxtf(const char *format, va_list ap) strbuf_release(&buf); } -void html_txt(const char *txt) +static int _html_txt(int len, const char *txt) { const char *t = txt; - while (t && *t) { + while (t && *t && len--) { int c = *t; if (c == '<' || c == '>' || c == '&') { html_raw(txt, t - txt); @@ -140,29 +140,24 @@ void html_txt(const char *txt) t++; } if (t != txt) - html(txt); + html_raw(txt, t - txt); + return len; +} + +void html_txt(const char *txt) +{ + if (txt) + _html_txt(strlen(txt), txt); } void html_ntxt(int len, const char *txt) { - const char *t = txt; - while (t && *t && len--) { - int c = *t; - if (c == '<' || c == '>' || c == '&') { - html_raw(txt, t - txt); - if (c == '>') - html(">"); - else if (c == '<') - html("<"); - else if (c == '&') - html("&"); - txt = t + 1; - } - t++; - } - if (t != txt) - html_raw(txt, t - txt); - if (len < 0) + _html_txt(len, txt); +} + +void html_ntxt_ellipsis(int len, const char *txt) +{ + if (_html_txt(len, txt) < 0) html("..."); } diff --git a/html.h b/html.h index 1b24e55..de53430 100644 --- a/html.h +++ b/html.h @@ -20,6 +20,7 @@ extern void html_attrf(const char *format,...); extern void html_txt(const char *txt); extern void html_ntxt(int len, const char *txt); +extern void html_ntxt_ellipsis(int len, const char *txt); extern void html_attr(const char *txt); extern void html_url_path(const char *txt); extern void html_url_arg(const char *txt); diff --git a/ui-repolist.c b/ui-repolist.c index 7272e87..77c33fd 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -329,7 +329,7 @@ void cgit_print_repolist(void) repourl = cgit_repourl(ctx.repo->url); html_link_open(repourl, NULL, NULL); free(repourl); - html_ntxt(ctx.cfg.max_repodesc_len, ctx.repo->desc); + html_ntxt_ellipsis(ctx.cfg.max_repodesc_len, ctx.repo->desc); html_link_close(); html(""); if (ctx.cfg.enable_index_owner) { -- 2.9.4